Skip to content

Commit

Permalink
More detail exception added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariful Islam committed Jan 8, 2023
1 parent 22ccf9a commit 337c866
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
28 changes: 28 additions & 0 deletions src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


use Exception;
use Xenon\NagadApi\Exception\NagadPaymentException;
use Xenon\NagadApi\lib\Key;

/**
Expand Down Expand Up @@ -65,10 +66,12 @@ class Base
* Base constructor
* @param $config
* @param $params
* @throws NagadPaymentException
* @since v1.3.2
*/
public function __construct($config, $params)
{
$this->checkParams($config, $params);
$this->keyObject = new Key($config);
$this->amount = $params['amount'];
$this->invoice = $params['invoice'];
Expand Down Expand Up @@ -175,11 +178,36 @@ public function getBaseUrl()

/**
* Verify Payment
* @throws Exception
*/
public function verifyPayment($paymentRefId)
{
$url = $this->base_url . 'verify/payment/' . $paymentRefId;
return Helper::HttpGet($url);
}

/**
* @throws NagadPaymentException
*/
private function checkParams($config, $params)
{
if (!is_array($config)) {
throw new NagadPaymentException("Configuration should be array.");
}

if (!is_array($params)) {
throw new NagadPaymentException("Params should be array.");
}

if (!array_key_exists('amount', $params)) {
throw new NagadPaymentException("Array key amount missing. Check array format from readme file");
}
if (!array_key_exists('invoice', $params)) {
throw new NagadPaymentException("Array key invoice missing. Check array format from readme file");
}
if (!array_key_exists('merchantCallback', $params)) {
throw new NagadPaymentException("Array key merchantCallback missing. Check array format from readme file");
}
}

}
6 changes: 0 additions & 6 deletions src/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ class RequestHandler
*/
private $apiUrl = 'check-out/initialize/';

/**
* @var
*/
private $initUrl;

/**
* @var
*/
Expand Down Expand Up @@ -104,7 +99,6 @@ 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 from nagad api server. Please be confirm that you have whitelisted your server ip or fix other server ip related issue. Sometimes it happens if you take server from outside Bangladesh. Contact with Nagad authority for assistance with your support ticket id");
Expand Down

0 comments on commit 337c866

Please sign in to comment.