Skip to content

Instantly share code, notes, and snippets.

@gausam
Last active August 11, 2016 09:26
Show Gist options
  • Save gausam/5b34a5f90360a63509f1256c53f1ff33 to your computer and use it in GitHub Desktop.
Save gausam/5b34a5f90360a63509f1256c53f1ff33 to your computer and use it in GitHub Desktop.
Creating a new Gava checkout with PHP
<?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