I'm creating a payment gateway in woocommerce. After sending a request to payment processor server and return Success as a status code. The server will send a GET request to an EndPoint of my own platform with some param indicating that an amount has been deducted from the user and the transaction has been successful .
Based on the (successful param) the user will be redirected to Thank You page.
I managed to create a simple API EndPoint but I'm stuck on how to respond to the Status Code and redirect the user to Thank You Page
add_action( 'rest_api_init', function () {
register_rest_route( 'zaindob/v1', '/reqendpoint/' . 'statuscode=' . '(?P<statuscode>\d+)' , array(
'methods' => 'GET',
'callback' => 'respondfun',
) );
} );
function respondfun(){
$order = wc_get_order($order_id);
wc_add_notice('Success = true' , 'Success' );
$order->payment_complete();
$woocommerce->cart->empty_cart();
wp_redirect('https://iotkidsiq.com/thank-you');
}
After responding, the user won't be redirected. I'm sure my code is not right but i just want to show you what i have created so far