
Have you created your own payment gateway plugin for WooCommerce and it redirects customers to the gateway’s site for checkout? And you’re looking for a way to get a response from the payment gateway?
For example, you’re extending the WooCommerce payment gateway like this:
class WC_Gateway_HBL_Payment extends WC_Payment_Gateway {
In this case, you should send the notify URL or redirection URL or similar to the payment gateway as a request, which will be something like:
WC()->api_request_url( 'WC_Gateway_HBL_Payment' )
Once you send the notify URL, you can get the response from the gateway site once the customer redirects back to your site after completing the purchase, by using the WooCommerce hook:
add_action( 'woocommerce_api_wc_gateway_hbl_payment', [ $this, 'handle' ] );
In this handle method, you can handle the responses coming with GET parameters.
private function handle() {
$orderId = ! empty( $_GET['orderNo'] ) ? wc_clean( wp_unslash( $_GET['orderNo'] ) ) : '';
$order = new \WC_Order( $orderId );
if ( ! empty( $order ) ) {
$order->update_status( 'processing' );
}
wp_safe_redirect( $gateway->get_return_url( wc_get_order( $orderId ) ) );
exit();
}
Note: The above handle() method is only an example. You should validate the order and transaction with Payment Gateways, TransactionCheck API.
I hope you found this helpful. 🙂