1

I am facing error while saving data in database because webhook(instamojo) url is not working with my code.

How we redirect to webhook page and what is the webhook format for codeigniter framework.

I am using instamojo payment gateway

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://test.instamojo.com/api/1.1/payment-requests/');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER,  array("X-Api-Key:test_12345", "X-Auth-Token:test_asbcs"));
$payload = Array(
  'purpose' => $username,
  'amount' => $this->input->post('amount'), 
  'phone' => , 
  'buyer_name' => $username,
  'redirect_url' => 'url',
  'send_email' => true,
  'webhook' => 'url',
  'send_sms' => true,
  'email' => $this->input->post('email'),  
  'allow_repeated_payments' => false,
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
$response = curl_exec($ch);
curl_close($ch); 
$json_decode = json_decode($response, true);
$long_url = $json_decode['payment_request']['longurl'];
header('Location:'.$long_url);

This is webhook code which I am using in webhook page. Please help me to solve this issue. Thanks in advance

$data = $_POST;
$mac_provided = $data['mac'];
unset($data['mac']);
$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');
}
$mac_calculated = hash_hmac("sha1", implode("|", $data), "salt key");
if($mac_provided == $mac_calculated){
  if($data['status'] == "Credit"){
    database query ---
    return true;
  } else{
    return false;
  }
} else{ 
  return false;
}
Lets-c-codeigniter
  • 682
  • 2
  • 5
  • 18
  • I suggest you use https://github.com/rajeevbbqq/instamojo-codeigniter library. – Rahul Sep 10 '19 at 10:44
  • hi thanks for comment but i have code on my own codeigniter framework simple i need how we call webhook and save data in database in webhook page in codeigniter... .most of the part i have covered.. – Vaibhav Chaudhary Sep 10 '19 at 10:52

0 Answers0