'Paytabs php integration
Im trying to get Payments working using the PayTabs gateway in native php. It works, for the most part. the main issue im having is the callback file, I've made one according to the documentation:
<?php
// Profile Key (ServerKey)
$serverKey = "server key"; // Example
// Request body include a signature post Form URL encoded field
// 'signature' (hexadecimal encoding for hmac of sorted post form fields)
$signature_fields = filter_input_array(INPUT_POST);
$requestSignature = $signature_fields["signature"];
unset($signature_fields["signature"]);
// Ignore empty values fields
$signature_fields = array_filter($signature_fields);
// Sort form fields
ksort($signature_fields);
// Generate URL-encoded query string of Post fields except signature field.
$query = http_build_query($signature_fields);
$requestCustomer = $signature_fields["customerEmail"];
$mail = "payer: $requestCustomer";
$signature = hash_hmac('sha256', $query, $serverKey);
if (hash_equals($signature,$requestSignature) === TRUE) {
mail("log@site","payment works",$mail);
}else{
mail("log@site","payment failed",$mail);
}
?>
(of course log@site is in reality a real email, and the server key is present in the actual file.)
Now I've set this file as the callback for the transaction, but whenever i test the payment, it send a "payment failed" Even though the transaction came through.
Is there maybe some kind of GitHub repo i can refer to for some sample code or the likes?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
