diff --git a/src/RequestHandler.php b/src/RequestHandler.php index 18207f1..351dabb 100644 --- a/src/RequestHandler.php +++ b/src/RequestHandler.php @@ -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; @@ -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']; @@ -150,13 +156,15 @@ public function sendRequest(bool $redirection = true) $url = json_encode($resultDataOrder['callBackUrl']); echo ""; 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; }