为了账号安全,请及时绑定邮箱和手机立即绑定

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条经验 获得超3个赞

我设法让它工作,我会在这里发布我的答案,以防有人需要解决这个问题。


我所做的是将响应输出到 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 关注
  • 59 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信