HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/dmstechonline/crm.chaitanyahospitalvirar.com/application/controllers/Webhooks.php
<?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class Webhooks extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function insta_webhook()
    {
        $insta_webhook = $this->paymentsetting_model->insta_webhooksalt();

        $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), "$insta_webhook->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";
        }
    }
}