instamojo支付成功后如何在数据库中插入数据
How to insert data in database after payment successful through instamojo
我已将 instamojo 支付 api 与我在 PHP 上的网站集成。
我还可以在调用付款 api 之前将数据插入我的数据库。
现在我如何在付款成功后将数据插入我的数据库!
谢谢
您必须将此代码保存为主机中的 php 文件,然后将此文件 URL 设置为 URL 用于 Product/Payment link 的网络挂钩在 Instamojo 中。您还可以在 Instamojo 的 Web 挂钩检查页面上检查是否有效。
<?php
/*
Basic PHP script to handle Instamojo RAP webhook.
*/
$data = $_POST;
$mac_provided = $data['mac']; // Get the MAC from the POST data
unset($data['mac']); // Remove the MAC key from the data.
$ver = explode('.', phpversion());
$major = (int) $ver[0];
$minor = (int) $ver[1];
if($major >= 5 and $minor >= 4){
ksort($data, SORT_STRING | SORT_FLAG_CASE);
}
else{
uksort($data, 'strcasecmp');
}
// You can get the 'salt' from Instamojo's developers page(make sure to log in first): https://www.instamojo.com/developers
// Pass the 'salt' without <>
$mac_calculated = hash_hmac("sha1", implode("|", $data), "<YOUR_SALT>");
if($mac_provided == $mac_calculated){
if($data['status'] == "Credit"){
// Payment was successful, mark it as successful in your database.
// You can acess payment_request_id, purpose etc here.
}
else{
// Payment was unsuccessful, mark it as failed in your database.
// You can acess payment_request_id, purpose etc here.
}
}
else{
echo "MAC mismatch";
}
?>
我已将 instamojo 支付 api 与我在 PHP 上的网站集成。 我还可以在调用付款 api 之前将数据插入我的数据库。 现在我如何在付款成功后将数据插入我的数据库!
谢谢
您必须将此代码保存为主机中的 php 文件,然后将此文件 URL 设置为 URL 用于 Product/Payment link 的网络挂钩在 Instamojo 中。您还可以在 Instamojo 的 Web 挂钩检查页面上检查是否有效。
<?php
/*
Basic PHP script to handle Instamojo RAP webhook.
*/
$data = $_POST;
$mac_provided = $data['mac']; // Get the MAC from the POST data
unset($data['mac']); // Remove the MAC key from the data.
$ver = explode('.', phpversion());
$major = (int) $ver[0];
$minor = (int) $ver[1];
if($major >= 5 and $minor >= 4){
ksort($data, SORT_STRING | SORT_FLAG_CASE);
}
else{
uksort($data, 'strcasecmp');
}
// You can get the 'salt' from Instamojo's developers page(make sure to log in first): https://www.instamojo.com/developers
// Pass the 'salt' without <>
$mac_calculated = hash_hmac("sha1", implode("|", $data), "<YOUR_SALT>");
if($mac_provided == $mac_calculated){
if($data['status'] == "Credit"){
// Payment was successful, mark it as successful in your database.
// You can acess payment_request_id, purpose etc here.
}
else{
// Payment was unsuccessful, mark it as failed in your database.
// You can acess payment_request_id, purpose etc here.
}
}
else{
echo "MAC mismatch";
}
?>