diff --git a/src/Base.php b/src/Base.php index 5b45eb3..488c7b2 100644 --- a/src/Base.php +++ b/src/Base.php @@ -71,9 +71,7 @@ class Base */ public function __construct($config, $params) { - $this->keyObject = new Key($config); - $this->amount = $params['amount']; $this->invoice = $params['invoice']; $this->merchantID = $this->keyObject->getAppMerchantID(); @@ -96,11 +94,13 @@ public function __construct($config, $params) /** * Final Send Request to Nagad * @param Base $base + * @return array + * @throws \Exception */ public function payNow(Base $base) { $request = new RequestHandler($base); - $request->sendRequest(); + return $request->sendRequest(); } /** diff --git a/src/RequestHandler.php b/src/RequestHandler.php index 862275f..6a8c3e9 100644 --- a/src/RequestHandler.php +++ b/src/RequestHandler.php @@ -16,6 +16,8 @@ namespace NagadApi; +use NagadApi\Exception\ExceptionHandler; + /** * This is the main performer that means request handler for entire nagadApi * This class is doing extra-ordinary job according to request type. @@ -61,6 +63,7 @@ public function __construct(Base $base) /** * Fire request to nagad api * @return array + * @throws \Exception */ public function sendRequest() { @@ -81,11 +84,13 @@ public function sendRequest() 'sensitiveData' => $this->helper->EncryptDataWithPublicKey(json_encode($sensitiveData)), 'signature' => $this->helper->SignatureGenerate(json_encode($sensitiveData)) ); - $resultData = $this->helper->HttpPostMethod($postUrl, $postData); $this->initUrl = $postUrl; + if (is_array($resultData) && array_key_exists('reason', $resultData)) { - if ($resultData === NULL) { + return $resultData; + + } else if ($resultData === NULL) { return $this->response = [ 'status' => 'error', 'response' => [ @@ -136,7 +141,7 @@ public function sendRequest() 'merchantCallbackURL' => $this->base->merchantCallback, ); - $OrderSubmitUrl = $this->base->getBaseUrl() . "remote-payment-gateway-1.0/api/dfs/check-out/complete/" + $OrderSubmitUrl = $this->base->getBaseUrl() . "api/dfs/check-out/complete/" . $paymentReferenceId; $Result_Data_Order = $this->helper->HttpPostMethod($OrderSubmitUrl, $PostDataOrder); @@ -182,4 +187,5 @@ public function sendRequest() } } + } \ No newline at end of file