0

This request sent to my specified url from payment gateway over http post request

POST https://mywebsite.com/checkout/?oid=12345
{
   "status":"SUCCESS",
   "notif_token":"dd497bda3b250e536186fc0663f32f40",
   "txnid": "MP150709.1341.A00073"
}

screenshot of payment gateway documentation

how to receive this request data in checkout.php file

i want to store this data into variable

// Get the JSON contents notif respone in varibale
$notif_response_body = file_get_contents('php://input');

// decode json respone
$notif_response_data = json_decode($notif_response_body, true);

switch ($notif_response_data['status']){
    case "PENDING":
        $sorder->add_order_note( __('The Transaction id ' . $notif_response_data['txnid'] . 'is in progress on Orange Money Payment Gateway ', 'orange_money'), true );
    $sorder->status = 'On hold';
    break;
    case "SUCCESS":
        $sorder->add_order_note( __('Order Paid via Orange Money Payment Gateway transaction id : ' . $notif_response_data['txnid'], 'orange_money'), true );
        $sorder->status = 'Processing';
    break;
    case "FAILED":
        $sorder->add_order_note( __('Payment Failed on Orange Money Payment Gateway transaction id : ' . $notif_response_data['txnid'], 'orange_money'), true );
        $sorder->status = 'Failed';
    break;
    case "EXPIRED":
        $sorder->add_order_note( __('Payment Expired on Orange Money Payment Gateway transaction id : ' . $notif_response_data['txnid'], 'orange_money'), true );
        $sorder->status = 'Failed';
    break;
    default:
    break;
}
  • You don't send any data with your POST request, cf. [this example](https://developer.wordpress.org/reference/functions/wp_remote_post/#comment-622) for `wp_remote_post()`. – nosurs Apr 15 '21 at 19:56
  • thanks @nosurs but i asked question in wrong way – Bhawani Singh Sodha Apr 15 '21 at 22:06
  • @nosurs Payment gateway sending POST request to my specified URL with this data i want to know how to receive this request & process in PHP – Bhawani Singh Sodha Apr 15 '21 at 22:07
  • Ah, got it, sorry. So the former piece of code was for debugging purposes, right? In that case, though, I'd issue a request from a separate script or via `curl` from the commandline (see https://stackoverflow.com/a/7173011/3323348 for an example). Anyway, you might want to rephrase your question again (also, best omit the picture, you've already included the request in code, which is much better) - because you've already solved storing the request. In other words, `$notif_response_body = file_get_contents('php://input')` is exactly how you would receive some POSTed JSON. Though it doesn't... – nosurs Apr 15 '21 at 22:37
  • ...seem to work in your context. Which why you might want to give us a bit more of this context - for example, do you do this within a plugin of yours, and if so, which hook do you use ([parse_request()](https://developer.wordpress.org/reference/hooks/parse_request/) comes to mind)? Also, you might want to consider posting this question to https://wordpress.stackexchange.com. – nosurs Apr 15 '21 at 22:40
  • thanks again @nosurs for helping me but when i try $notif_response_body = file_get_contents('php://input') this not working also i create a file to receive post request take look whats wrong with that https://codeshare.io/aygKQe – Bhawani Singh Sodha Apr 17 '21 at 22:25

0 Answers0