Created
January 24, 2022 12:50
-
-
Save rkbi/847507192eed96ae5a31f9ad7e7761e2 to your computer and use it in GitHub Desktop.
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 | |
$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