Woocommerce Gateway集成付款状态未更新

时间:2014-12-16 11:32:47

标签: php wordpress woocommerce gateway

我已经设置了一个自定义的Woocommerce外线支付网关,从我的网站到网关的通信工作正常。用户被重定向到网关,并在付款后返回(通过Woocommerce)定义的返回URL。

在网关的API文档中,它表示支付网关会将一个查询字符串变量添加到返回网址。此变量可以具有以下值:

response=approved
response=declined
response=error

在文档中是这样的例子: 如果backURL = http://www.test.com/return.asp 然后回复将是http://www.test.com/return.asp?response=approved

要处理我在下面创建代码的顺序(首先只是为了response=approved的状态) 但是,当我测试时,订单状态不会更新。我希望有人能指出我找到错误的正确方向。

在网关顶部,我使用以下内容扩展了query_vars:

function add_query_vars_filter( $vars ){
$vars[] = "response";
return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );    

将用户发送到网关后,我有这个函数来处理和处理返回URL中的查询字符串:

function check_example_response(){

        global $woocommerce;

            $transaction_id = get_query_var( 'response' );

            $order          = new WC_Order( $order_id );

                // check if payment was successful
                if ($transaction_id == 'approved') {

                            //Update order status
                            $order->update_status( 'processing', 'Payment received, your order is currently being processed.' );

                            //Add admin order noote
                            $order->add_order_note('Payment Via Example Gateway<br />Transaction ID: '.$order);

                            //Add customer order note
                            $order->add_order_note('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />Transaction ID: '.$order, 1);

                            $message = 'Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.';
                            $message_type = 'success';
                        }

                        // Reduce stock levels
                        $order->reduce_order_stock();

                        // Empty cart
                        WC()->cart->empty_cart();
 }}

我还注册了这个函数:

add_action( 'woocommerce_api_wc_example', array( $this, 'check_example_response' ) );

Wordpress也没有在DEBUG模式下提供任何提示,所以我现在非常沮丧,并希望有人可以帮助我。

谢谢!

0 个答案:

没有答案
相关问题