1

我已经在 PHP 上将 instamojo 支付 API 与我的网站集成。我还可以在调用支付 api 之前将数据插入到我的数据库中。现在付款成功后如何将数据插入我的数据库!

谢谢

4

1 回答 1

2

您必须将此代码保存为主机中的 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";
}
?>
于 2017-05-20T18:22:23.393 回答