如何通过instamojo成功付款后在数据库中插入数据

时间:2016-12-20 06:39:21

标签: instamojo

我已将instamojo payment api与我的PHP网站集成。 我也可以在调用pay api之前将数据插入我的数据库。 现在,如何在付款成功后将数据插入我的数据库!

由于

1 个答案:

答案 0 :(得分:1)

您必须将此代码作为php文件保存在主机中,然后将此文件URL设置为Instamojo中产品/付款链接的Web挂钩URL。您还可以检查它是否适用于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";
}
?>