I have helped the development of e-commerce site for the client other day and Paysbuy gateway did not work as expected so I have decided to investigate about this. The platform I used was WordPress with Woocommerce plugin for e-commerce site development. My client have registered to use Paysbuy as payment gateway so I have downloaded the Paysbuy plugin that work with Woocommerce. The transaction went fine but it did not reduce the stock amount as expected. I did not know what was going on so first I went through the document and found followings…
So in the document it say that “On-Hold” status will reduce the stock amount. “Check Payment” and “Paypal” does reduce the stock amount as expected but Paysbuy did not so I compared three codes…
Payment Method: Check Payment
File: wp-content/plugins/woocommerce/includes/gateways/cheque/class-wc-gateway-cheque.php
1 2 3 4 5 6 7 8 9 10 11 |
public function process_payment( $order_id ) { $order = wc_get_order( $order_id ); // Mark as on-hold (we're awaiting the cheque) $order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) ); // Reduce stock levels $order->reduce_order_stock(); .... |
Payment Method: Paypal
File: wp-content/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-response.php
1 2 3 4 5 |
protected function payment_on_hold( $order, $reason = '' ) { $order->update_status( 'on-hold', $reason ); $order->reduce_order_stock(); WC()->cart->empty_cart(); } |
As you can see, Woocommerce default payment methods include “$order->reduce_order_stock();” which seems to me as function that reduces the stock amount. Let’s see Paysbuy code now…
Payment Method: Paysbuy
File: wp-content/plugins/woocommerce-paysbuy-payment-gateway/wc_paysbuy_payment_gateway.php
1 2 3 4 5 6 7 8 9 10 11 12 13 |
if($result == '00'){ $order->payment_complete(); $woocommerce->cart->empty_cart(); } else if ($result == '99'){ $order->update_status('failed', __('Payment Failed', 'woothemes')); $woocommerce->cart->empty_cart(); } else if ($result == '02'){ $order->update_status('on-hold', __('Awaiting Counter Service payment', 'woothemes')); $woocommerce->cart->empty_cart(); } .... |
So the code do not include “$order->reduce_order_stock();” and no wonder why the gateway plugin does not reduce the stock amount. Simple solution was just add the code.
1 2 3 4 5 6 |
else if ($result == '02'){ $order->update_status('on-hold', __('Awaiting Counter Service payment', 'woothemes')); // Reduce stock levels $order->reduce_order_stock(); $woocommerce->cart->empty_cart(); } |
Tested out the code and seems like everything is working as expected… I should inform the developer as the plugin is out on github now.
**Update**
Developer agreed that this fix is needed so I fixed it for them. Github Issue