Last active
January 20, 2017 13:51
-
-
Save fatmatto/6f3f7953ea2c89856a214c7972c955e4 to your computer and use it in GitHub Desktop.
How to receive a razorpay event and update a Marketcloud order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// You need to install the Marketcloud SDK, you will find information on GitHub | |
// https://www.marketcloud.it/documentation/reference/php | |
/* | |
* Here you can find the data structure sent as a POST request | |
* The reference event is order.paid | |
https://docs.razorpay.com/v1/page/webhooks | |
* | |
*/ | |
//Remember to use your marketcloud app's credentials | |
Marketcloud\Marketcloud::setCredentials(array( | |
'secret_key' => 'your-secret-key', | |
'public_key' => 'your-public-key' | |
)); | |
// Retrieve the request's body and parse it as JSON | |
$input = @file_get_contents("php://input"); | |
//Here you have razorpay's webhook data | |
$event_json = json_decode($input); | |
// Do something with $event_json | |
// This requires that, when creating an order from the Android SDK | |
// you add a value marketcloud_order_id inside the order.notes object. | |
$marketcloud_order_id = $event_json->payload->order->entity->notes->marketcloud_order_id; | |
// If $marketcloud_order_id is a string (maybe because thats how you saved it from Android) | |
// remember to convert it to a number. | |
$response = Marketcloud\Orders::update($marketcloud_order_id,array( | |
"status" => "paid" | |
)) | |
if ($response->body->status == true) { | |
// Update successful | |
} | |
http_response_code(200); // PHP 5.4 or greater | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment