【问题标题】:How to get the payment response url in woocommerce?如何在 woocommerce 中获取付款响应网址?
【发布时间】:2016-09-14 13:38:04
【问题描述】:

我在我的 wordpress 中集成了 pay4later api。付款成功后,我需要显示付款响应详细信息。

我的插件文件:

class WC_Pay4later extends WC_Payment_Gateway{
      add_action('woocommerce_api_' . strtolower( get_class( $this ) ), array($this, 'check_response' ) );

       function check_response()
       {
            /* Update Process*/ 
       }

    }

我设置我的返回响应网址是:

www.mysite/pay4later/?wc-api=WC_Payment_GatewayPay4later_check_response. 

当我调用它时,它只显示 1。

我该如何解决这个问题?

【问题讨论】:

  • This could be interesting for you 即使不是特定于 pay4later。还有this 一个。
  • 我引用了这个。但我不清楚。我在 check_response() 中更新了订单详情。那么我可以通过 url 实现这个功能吗?
  • 对不起,如何通过url调用这个函数?
  • 它特定于您的源代码。每个支付网关都有自己的行为。没有源代码访问权限,就不可能提供帮助。在任何事务服务器网关返回数据期间。响应取决于该数据。我没有 Pay4later 网关的技术文档……而且我不知道交易后返回什么。
  • 我需要获取网关返回数据。

标签: php wordpress woocommerce payment checkout


【解决方案1】:

这是 woocommerce 的 Pay4later 支付网关的骨架结构。

if ( ! defined( 'ABSPATH' ) ) { exit; }

add_action( 'plugins_loaded', 'wc_pay4later_init', 0 );

function wc_pay4later_init() {

    class WCPay4later extends WC_Payment_Gateway{

        public function __construct() {
            // Put your initialization scripts here
            // Which would be initializing merchan account info, secret keys, from this plugin's settings screen

            /* This would be your gateway return url */
            $this->callback = str_replace( 'https:', 'http:', home_url( '/wc-api/WCPay4later' )  );
            /* This action will redirect the gateway response to your 'check_pay_4_later_response' function */
            add_action( 'woocommerce_api_wcpay4later', array( $this, 'check_pay_4_later_response' ) );          
            /* This is the action where you prepare your digital form and submit to the gateway server */
            add_action('woocommerce_receipt_wcpay4later', array( $this, 'receipt_page') );          
        }

        function receipt_page( $order ) {
            echo '<p>'.__('Thank you for your order, please click the button below to pay with Pay 4 Later Gateway Service.', 'sark').'</p>';
            // prepare your digital form    
            echo $this -> generate_digital_form( $order );
        }

        function generate_digital_form( $order ) {
            // prepare and redirect to gateway server
        }

        function check_pay_4_later_response() {
            /* Update Process*/
        }

    }

    function woocommerce_add_pay_4_later_gateway( $methods ) {
        $methods[] = 'WCPay4later';
        return $methods;
    }   
    add_filter('woocommerce_payment_gateways', 'woocommerce_add_pay_4_later_gateway' );

}

【讨论】:

    猜你喜欢
    • 2019-06-17
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 2018-02-25
    • 2019-09-26
    相关资源
    最近更新 更多