Last active
August 11, 2016 09:26
-
-
Save gausam/5b34a5f90360a63509f1256c53f1ff33 to your computer and use it in GitHub Desktop.
Creating a new Gava checkout with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$orderId = 12; //Doesn't have to be numeric | |
$amount = 1.00; | |
$returnUrl = "http://example.com/thankyou"; | |
$cancelUrl = "http://example.com/cart"; | |
$payload = [ | |
'reference' => $orderId, | |
'amount' => $amount, | |
'return_url' => $returnUrl, | |
'cancel_url' => $cancelUrl, | |
]; | |
$payload['signature'] = $sign($payload, "examp1216"); | |
$res = Requests::post('http://example.com/checkout', [], $payload); | |
$checkoutUrl = $res->body; | |
//Then you can redirect the user to $checkoutUrl, or show it a a link | |
/** | |
* Given an iterable $payload, it signs it with the provided secret key | |
* | |
* @param mixed $payload Object or array | |
* @param string $secret Secret key | |
* @return mixed | |
*/ | |
function sign($payload, $secret) | |
{ | |
$string = ''; | |
foreach ($payload as $key => $value) { | |
if ($key === 'signature') continue; | |
$string .= $value; | |
} | |
return hash('sha512', $string . $secret); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment