php - Woocommerce Gateway Integration Payment Status not updating -
i have set custom woocommerce off-side payment gateway, communication website gateway works fine. user gets redirected gateway , after payment gets returned (by woocommerce) defined return url.
in api documentation of gateway, says payment gateway add query string variable return url. variable can have following values:
response=approved response=declined response=error
in documentation exampple: if backurl = http://www.test.com/return.asp response http://www.test.com/return.asp?response=approved
to process order have created code below (first state of response=approved
) however, order status not updated, when test it. hope can point me in right direction find error.
on top of gateway have extended query_vars with:
function add_query_vars_filter( $vars ){ $vars[] = "response"; return $vars; } add_filter( 'query_vars', 'add_query_vars_filter' );
after sending user gateway have function handle , process query string in return url:
function check_example_response(){ global $woocommerce; $transaction_id = get_query_var( 'response' ); $order = new wc_order( $order_id ); // check if payment successful if ($transaction_id == 'approved') { //update order status $order->update_status( 'processing', 'payment received, order 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 being processed.<br />we shipping order soon.<br />transaction id: '.$order, 1); $message = 'thank shopping us.<br />your transaction successful, payment received.<br />your order being processed.'; $message_type = 'success'; } // reduce stock levels $order->reduce_order_stock(); // empty cart wc()->cart->empty_cart(); }}
i have registered function with:
add_action( 'woocommerce_api_wc_example', array( $this, 'check_example_response' ) );
wordpress not give hints in debug mode, right quite frustrated , hope can me.
thank you!
Comments
Post a Comment