Skip to content

Instantly share code, notes, and snippets.

@rkbi
Created January 24, 2022 12:50
Show Gist options
  • Save rkbi/847507192eed96ae5a31f9ad7e7761e2 to your computer and use it in GitHub Desktop.
Save rkbi/847507192eed96ae5a31f9ad7e7761e2 to your computer and use it in GitHub Desktop.
<?php
$f = file_get_contents('response-example.json');
function getBkashURL($json_str)
// Return Bkash redirect URL from api response json string.
{
$data_array = json_decode($json_str);
$desc = $data_array->desc;
foreach ($desc as $channel) {
if ($channel->gw == 'bkash') {
$bkashURL = $channel->redirectGatewayURL;
break;
}
}
return $bkashURL;
}
function getDirectURL($json_str, $gw)
// Returns direct payment URL for $gw eg, bkash, nagad etc.
{
$data_array = json_decode($json_str);
$desc = $data_array->desc;
foreach ($desc as $channel) {
if ($channel->gw == $gw) {
$bkashURL = $channel->redirectGatewayURL;
break;
}
}
return $bkashURL;
}
function redirectUser($url)
// Redirects the user to specified $url
{
echo <<<javascript
<script type="text/javascript">
window.location.href = "$url"
</script>
javascript;
}
echo redirectUser(getBkashURL($f));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment