亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Woocommerce 自定義支付網關重定向

Woocommerce 自定義支付網關重定向

PHP
浮云間 2023-09-08 17:20:32
我正在嘗試創建一個自定義 Woocommerce 支付網關,將客戶重定向到支付網關頁面以完成結賬,我使用的代碼process_payment如下:    public function process_payment( $order_id )    {        global $woocommerce;        // we need it to get any order details        $order = wc_get_order( $order_id );        //setting up needed variables for POST        $moovpay = new MoovPaySDK;        $paymentURL = //payment gateway API URL;        $time = date('YmdHis');        $secretKey = $this->private_key;        $merchant_code = $this->merchant_code;        $mid = $this->mid;        $orderID = zeroise($order_id, 8);        $backend_URL = //callback_URL;        $order_amount = $order->get_total();        $order_amount_CNY = wc_format_decimal( $order_amount * 5, 2 );;        $order_amount_CNY_no_dot = str_replace(".", "", $order_amount_CNY);        //initiate payment        $response = $moovpay->purchase($secretKey, '', $backend_URL, $merchant_code, $mid, $orderID, $time, '', $order_amount_CNY_no_dot, '');如何使用響應執行到支付網關的重定向?我不確定以前是否有人問過這個問題,但我似乎找不到任何解決方案。任何幫助或指導將不勝感激。
查看完整描述

1 回答

?
守著一只汪

TA貢獻1872條經驗 獲得超4個贊

我設法讓它工作,我會在這里發布我的答案,以防有人需要解決這個問題。


我所做的是將響應輸出到 php 文件,然后使用它執行重定向。


public function process_payment( $order_id )

{

  global $woocommerce;

  

  // we need it to get any order details

  $order = wc_get_order( $order_id );

  

  //setting up needed variables for POST

  $moovpay = new MoovPaySDK;

  $paymentURL = ''; //payment gateway API URL;

  $time = date('YmdHis');

  $secretKey = $this->private_key;

  $merchant_code = $this->merchant_code;

  $mid = $this->mid;

  $orderID = zeroise($order_id, 8);

  $backend_URL = '' //callback_URL;

  $order_amount = $order->get_total();

  $order_amount_CNY = wc_format_decimal( $order_amount * 5, 2 );;

  $order_amount_CNY_no_dot = str_replace(".", "", $order_amount_CNY);

  //initiate payment

  $response = $moovpay->purchase($secretKey, '', $backend_URL, $merchant_code, $mid, $orderID, $time, '', $order_amount_CNY_no_dot, '');

  $fh = fopen(plugin_dir_path(__FILE__).'redirect.php', 'w+');

  fwrite($fh, $response);

  fclose($fh);

  $redirect_url = plugin_dir_url(__FILE__).'redirect.php';

  

  return array(

    'result' => 'success',

    'redirect' => $redirect_url

  );

}


查看完整回答
反對 回復 2023-09-08
  • 1 回答
  • 0 關注
  • 139 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號