Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
arif98741 committed May 2, 2021
2 parents 8bd1b3e + 67c4912 commit b7ffa81
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 57 deletions.
1 change: 1 addition & 0 deletions src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function __construct($config, $params)
public function payNow(Base $base)
{
$request = new RequestHandler($base);

return $request->sendRequest();
}

Expand Down
16 changes: 12 additions & 4 deletions src/Helper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace NagadApi;


Expand Down Expand Up @@ -91,11 +92,18 @@ public function HttpPostMethod($PostURL, $PostData)
curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($url, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($url, CURLOPT_SSL_VERIFYPEER, 0);

$resultData = curl_exec($url);
$response = json_decode($resultData, true, 512);
curl_close($url);
return $response;
$curl_error = curl_error($url);

if (!empty($curl_error)) {
return [
'error' => $curl_error
];
} else {
$response = json_decode($resultData, true, 512);
curl_close($url);
return $response;
}
}

/**
Expand Down
95 changes: 42 additions & 53 deletions src/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace NagadApi;

use NagadApi\Exception\ExceptionHandler;
use Exception;

/**
* This is the main performer that means request handler for entire nagadApi
Expand Down Expand Up @@ -63,7 +63,7 @@ public function __construct(Base $base)
/**
* Fire request to nagad api
* @return array
* @throws \Exception
* @throws Exception
*/
public function sendRequest()
{
Expand All @@ -84,40 +84,19 @@ 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)) {

return $resultData;

} else if ($resultData === NULL) {
return $this->response = [
'status' => 'error',
'response' => [
'code' => 102,
'message' => 'NULL Response. Check your internet connection',
],
'request' => [
'environment' => $this->base->environment,
'time' => [
'request time' => date('Y-m-d H:i:s'),
'timezone' => $this->base->getTimezone()
],
'url' => [
'base_url' => $this->base->getBaseUrl(),
'api_url' => $this->apiUrl
],
'data' => [
'sensitiveData' => $sensitiveData,
'postData' => $postData
],

],
'server' => Helper::serverDetails()
];
if (is_array($resultData) && array_key_exists('reason', $resultData)) {
$this->showResponse($resultData, $sensitiveData, $postData);
return $this->response;
} else if (is_array($resultData) && array_key_exists('error', $resultData)) {
$this->showResponse($resultData, $sensitiveData, $postData);
return $this->response;
}

//check existance of sensitiveData and signature
//check existence of sensitiveData and signature
if (array_key_exists('sensitiveData', $resultData) && array_key_exists('signature', $resultData)) {

if (!empty($resultData['sensitiveData']) && !empty($resultData['signature'])) {
Expand Down Expand Up @@ -163,31 +142,41 @@ public function sendRequest()
}
}
} else {
return $this->response = [
'status' => 'error',
'response' => [
'code' => 101,
'message' => $resultData['message'],
$this->showResponse($resultData['message'], [], []);
}

}

/**
* @param $resultData
* @param $sensitiveData
* @param $postData
* @return array
*/
private function showResponse($resultData, $sensitiveData, $postData)
{
$this->response = [
'status' => 'error',
'response' => $resultData,
'request' => [
'environment' => $this->base->environment,
'time' => [
'request time' => date('Y-m-d H:i:s'),
'timezone' => $this->base->getTimezone()
],
'request' => [
'environment' => $this->base->environment,
'time' => [
'request time' => date('Y-m-d H:i:s'),
'timezone' => $this->base->getTimezone()
],
'url' => [
'base_url' => $this->base->getBaseUrl(),
'api_url' => $this->apiUrl
],
'data' => [
'sensitiveData' => $sensitiveData,
'postData' => $postData
]
'url' => [
'base_url' => $this->base->getBaseUrl(),
'api_url' => $this->apiUrl,
'request_url' => $this->base->getBaseUrl() . $this->apiUrl,
],
'data' => [
'sensitiveData' => $sensitiveData,
'postData' => $postData
],
'server' => Helper::serverDetails()
];
}

],
'server' => Helper::serverDetails()
];
}

}

0 comments on commit b7ffa81

Please sign in to comment.