Skip to content

Commit

Permalink
add new exception of no response returned nagad in server
Browse files Browse the repository at this point in the history
  • Loading branch information
arif98741 committed Aug 16, 2022
1 parent 7f66c01 commit cd95ba1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,18 @@ public function sendRequest(bool $redirection = true)
$resultData = $this->helper->HttpPostMethod($postUrl, $postData);
$this->initUrl = $postUrl;

if (!is_array($resultData)) {
throw new ExceptionHandler("Failed to generate nagad payment url as it is returning null response. Please be confirm you have whitelisted your server ip or server fix other server related issue");
}


if (is_array($resultData) && array_key_exists('reason', $resultData)) {
if (array_key_exists('reason', $resultData)) {

throw new ExceptionHandler($resultData['reason'] . ', ' . $resultData['message']);

} else if (is_array($resultData) && array_key_exists('error', $resultData)) {
}

if (array_key_exists('error', $resultData)) {

$this->showResponse($resultData, $sensitiveData, $postData);
return $this->response;
Expand All @@ -120,7 +126,7 @@ public function sendRequest(bool $redirection = true)

if (!empty($resultData['sensitiveData']) && !empty($resultData['signature'])) {
$plainResponse = json_decode($this->helper->DecryptDataWithPrivateKey($resultData['sensitiveData']), true);
if (isset($plainResponse['paymentReferenceId']) && isset($plainResponse['challenge'])) {
if (isset($plainResponse['paymentReferenceId'], $plainResponse['challenge'])) {

$paymentReferenceId = $plainResponse['paymentReferenceId'];
$challenge = $plainResponse['challenge'];
Expand Down Expand Up @@ -150,13 +156,15 @@ public function sendRequest(bool $redirection = true)
$url = json_encode($resultDataOrder['callBackUrl']);
echo "<script>window.open($url, '_self')</script>";
exit;
} elseif ($resultDataOrder['status'] == "Success" && !$redirection) {
}

if ($resultDataOrder['status'] == "Success" && !$redirection) {

return $resultDataOrder['callBackUrl'];
} else {
echo json_encode($resultDataOrder);
}

echo json_encode($resultDataOrder);

} else {
return $resultDataOrder;
}
Expand Down

0 comments on commit cd95ba1

Please sign in to comment.