diff --git a/README.md b/README.md index c4b6f2a..8a297cf 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,18 @@ if ($verify->status === 'Aborted') { dd($verify); ``` +# get support id (live project) + +```php +use NagadPayment; + +$sid = NagadPayment::tnxID($id) + ->amount($amount) + ->getSupportID(); +return $sid; +``` + + # Note: @@ -90,6 +102,7 @@ dd($verify); * Need a merchant account (live server) * Contact with Nagad and provide your live server ip address. +* provide support id ($sid) the nagad office # Demo diff --git a/src/Nagad.php b/src/Nagad.php index 304e625..0b925d8 100644 --- a/src/Nagad.php +++ b/src/Nagad.php @@ -151,4 +151,40 @@ public function verify(){ $arr = json_decode($json, true); return $arr; } + + + /** + * Get support id for live project + * @author code4mk + * @since v1.0.0 + * @version 1.0.0 + */ + public function getSupportID() + { + $DateTime = Date('YmdHis'); + $MerchantID = config('nagad.merchant_id'); + $invoiceNo = $this->tnxStatus ? $this->tnxID : 'Inv'.Date('YmdH').rand(1000, 10000); + $merchantCallbackURL = config('nagad.callback_url'); + + $SensitiveData = [ + 'merchantId' => $MerchantID, + 'datetime' => $DateTime, + 'orderId' => $invoiceNo, + 'challenge' => Utility::generateRandomString() + ]; + + $PostData = array( + 'accountNumber' => config('nagad.merchant_number'), + 'dateTime' => $DateTime, + 'sensitiveData' => Utility::EncryptDataWithPublicKey(json_encode($SensitiveData)), + 'signature' => Utility::SignatureGenerate(json_encode($SensitiveData)) + ); + + $initializeUrl = $this->nagadHost."/check-out/initialize/" . $MerchantID . "/" . $invoiceNo; + + $Result_Data = Utility::HttpPostMethodSupportID($initializeUrl,$PostData); + + return $Result_Data; + + } } diff --git a/src/Utility.php b/src/Utility.php index 549083c..9bd3679 100644 --- a/src/Utility.php +++ b/src/Utility.php @@ -82,6 +82,32 @@ public static function DecryptDataWithPrivateKey($crypttext) return $plain_text; } + public static function HttpPostMethodSupportID($PostURL, $PostData) + { + $url = curl_init($PostURL); + $posttoken = json_encode($PostData); + $header = array( + 'Content-Type:application/json', + 'X-KM-Api-Version:v-0.2.0', + 'X-KM-IP-V4:' . self::get_client_ip(), + 'X-KM-Client-Type:PC_WEB' + ); + + curl_setopt($url, CURLOPT_HTTPHEADER, $header); + curl_setopt($url, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($url, CURLOPT_RETURNTRANSFER, true); + curl_setopt($url, CURLOPT_POSTFIELDS, $posttoken); + curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($url, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($url, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($url, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + + + $resultdata = curl_exec($url); + curl_close($url); + return $resultdata; + } + public static function HttpPostMethod($PostURL, $PostData) { $url = curl_init($PostURL);