Skip to content

Commit

Permalink
nagad support id
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa6765 committed Mar 25, 2021
1 parent 755b5b3 commit 7a8f1b1
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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

Expand Down
36 changes: 36 additions & 0 deletions src/Nagad.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,40 @@ public function verify(){
$arr = json_decode($json, true);
return $arr;
}


/**
* Get support id for live project <callback url>
* @author code4mk <[email protected]>
* @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;

}
}
26 changes: 26 additions & 0 deletions src/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7a8f1b1

Please sign in to comment.