John Davidson

I'm trying to validate the callback send to my website in php

0 comments
Message:


I'm trying to validate the callback send to my website in php.


Please I'm trying to use this api documentation https://support.cryptapi.io/article/how-to-verify-the-callback-signature to validate the callback send to my website but my code keep showing error to the api


I don't know whether it from my code


<?php


$pubkey =
"-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3FT0Ym8b3myVxhQW7ESuuu6lo\ndGAsUJs4fq+Ey//jm27jQ7HHHDmP1YJO7XE7Jf/0DTEJgcw4EZhJFVwsk6d3+4fy\nBsn0tKeyGMiaE6cVkX0cy6Y85o8zgc/CwZKc0uw6d5siAo++xl2zl+RGMXCELQVE\nox7pp208zTvown577wIDAQAB\n-----END PUBLIC KEY-----";


$signature = base64_decode($_SERVER['HTTP_X_CA_SIGNATURE']);
$algo = OPENSSL_ALGO_SHA256;

// if request is GET
$data = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

// if request is POST
$data = file_get_contents('php://input');

if (openssl_verify($data, $signature, $pubkey, $algo) == 1) {



require "cryptapi.php";
$url = $_GET['userdata'];

$postdata = CryptAPI\CryptAPI::process_callback($_GET);
$amount = $postdata['value_coin'];
$txid_in = $postdata['txid_in'];

$data = array(
'amount' => $amount,
'txid_in' => $txid_in
);

$payload = json_encode($data);

// Prepare new cURL resource
$ch = curl_init(urldecode($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload))
);

// Submit the POST request
$result = curl_exec($ch);

// Close cURL session handle
curl_close($ch);

echo "*ok*";


} else {
echo "error";
// signature NOT valid
}
?>


My Answer:
Hello! How can I assist you today?

Rate this post

5 of 5 based on 9032 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us