Skip to content

Instantly share code, notes, and snippets.

@adejorosam
Created November 29, 2024 09:28
Show Gist options
  • Save adejorosam/8577a5a929fd82bf45d8993075ec4d0b to your computer and use it in GitHub Desktop.
Save adejorosam/8577a5a929fd82bf45d8993075ec4d0b to your computer and use it in GitHub Desktop.
paystack method
<?php
namespace CardinalstoneRestServer\services;
use CardinalstoneRestServer\models\WebServiceModel;
use function GuzzleHttp\json_decode;
/*
* This Class handles the API calls to paystack
* @author [email protected]
*/
class PaystackRequest
{
/*
* Instance of guzzle
*/
private $guzzle;
/*
* Instance of webServiceModel
*/
private $webService;
/*
* Inject the container when resolving this object
* @param Psr\Container\ContainerInterfac $container
*/
public function __construct(\GuzzleHttp\Client $guzzle, WebServiceModel $webService )
{
$this->guzzle = $guzzle;
$this->webService = $webService;
}
/*
* Method to make paystack' resolve BVN
* @param string $phone
* @param string $bvn
*/
public function validateBVN($phone, $bvn,$product)
{
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer '. $_ENV['PAYSTACK_KEY_MUTUALFUND'],
"Cache-Control: no-cache"
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer '. $_ENV['PAYSTACK_KEY_CSWALLET'],
"Cache-Control: no-cache"
]
];
}
try {
$response = $this->guzzle->request('GET', $_ENV['PAYSTACK_BASE_URL']."/identity/bvn/resolve/".$bvn, $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
public function verifyPayment($payload)
{
/* if(strtoupper($product) == "CSPFIFUND")
{ */
$options = [
'headers' => [
'Authorization' => 'Bearer '. $payload['key'],
"Cache-Control: no-cache"
]
];
/* }elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer '. $_ENV['PAYSTACK_KEY_CSWALLET'],
"Cache-Control: no-cache"
]
];
} */
try {
$response = $this->guzzle->request('GET', "https://api.paystack.co/transaction/verify/".$payload["reference"], $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
public function getClientNubanFromPaystack($nubanAccountID,$product)
{
//check if user has nuban,if yes, return the nuban, if no , create it
//$nubanAccountID = "22";//(int)$data['nuban_account_id'];
try {
if(strtoupper($product) == "CSPFIFUND")
{
$response = container('guzzle')->get('https://api.paystack.co/dedicated_account/'.$nubanAccountID, ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')]]);
}elseif(strtoupper($product) == "CSWALLET")
{
$response = container('guzzle')->get('https://api.paystack.co/dedicated_account/'.$nubanAccountID, ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')]]);
}
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
public function resolveBankAccount($payload)
{
$accountNumber = $payload["accountNumber"];
$bankCode = $payload["bankCode"];
$url = 'https://api.paystack.co/bank/resolve?account_number='. $accountNumber .'&bank_code='.$bankCode;
$options = ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')]];
// var_dump($url);
// var_dump($options);
try {
//https://api.paystack.co/bank/resolve?account_number=0022728151&bank_code=063
$response = container('guzzle')->get("{$url}", $options);
// $response = container('guzzle')->get('https://api.paystack.co/bank/resolve?account_number='. $accountNumber .'&bank_code='.$bankCode, ['headers' => ['Authorization' => 'Bearer sk_live_aab80cd474cf43bdb84d1ca78d5f0071a4fc74f6']]);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
public function createTransferRecipient($payload)
{
$accountNumber = $payload["accountNumber"];
$bankCode = $payload["bankCode"];
$name = $payload["fullName"];
$options = [
// 'headers' => ['Authorization' => 'Bearer sk_test_6f9779b6a1b9dc899810a229ff0f31ac990970fb'],
'headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')],
'json' => [
"type"=> "nuban",
"name"=> $name,
"description"=> "Transfer Client for Wallet Payout",
"account_number"=> $accountNumber,
"bank_code"=> $bankCode,
"currency"=>"NGN"
]
];
$url = "https://api.paystack.co/transferrecipient";
try {
$response = container('guzzle')->post("{$url}", $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
//log Infoware response
$message1 = "Account Number: " . $accountNumber .", Bnk Code: " . $bankCode;
$message2 = (string) $options;
$message3 = "Name: " . $name;
$message4 = (string) $response->getBody();
$message5 = "Transfer Recipient Creation";
container('mutualFundModel')->activity_log($message1, $message2, $message3, $message4, $message5);
return $result;
}
public function withdrawFromWallet($payload)
{
$amount = $payload["amount"] * 100;
$recipientCode = $payload["recipientCode"];
/*
$options = [
'headers' => ['Authorization' => 'Bearer sk_live_aab80cd474cf43bdb84d1ca78d5f0071a4fc74f6'],
'json' => [
"source"=> "balance",
"amount"=> $amount,
"reason"=> "Transfer to bank from CS Wallet",
"recipient"=> $recipientCode,
]
]; */
$options = [
'headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')],
'json' => [
"source"=> "balance",
"amount"=> $amount,
"reason"=> "Transfer to bank from CS Wallet",
"recipient"=> $recipientCode,
]
];
$url = "https://api.paystack.co/transfer";
try {
$response = container('guzzle')->post("{$url}", $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
$message1 = $response->getStatusCode() ." and " .$response->getReasonPhrase();
$message2 = "Transfer Amount: ". number_format($amount/100, 2, '.', ',');
$message3 = "Name: ".$payload['lastName']. ", " .$payload['firstName'] .", Account Number: " . $payload['accountNumber']. ", Bank: " .$payload['bankName'];
$message4 = (string) $response->getBody();
$message5 = "Withdraw from Wallet to Bank Failed";
container('mutualFundModel')->activity_log($message1,$message2,$message3,$message4,$message5);
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
public function getNubanAccount($nubanAccountID, $product)
{
//check if user has nuban,if yes, return the nuban, if no , create it
//$nubanAccountID = "22";//(int)$data['nuban_account_id'];
try {
if(strtoupper($product) == "CSPFIFUND")
{
$response = container('guzzle')->get('https://api.paystack.co/dedicated_account/'.$nubanAccountID, ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')]]);
}elseif(strtoupper($product) == "CSWALLET")
{
$response = container('guzzle')->get('https://api.paystack.co/dedicated_account/'.$nubanAccountID, ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')]]);
}
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
public function getPaymentAccessCode($payload)
{
//check if user has nuban,if yes, return the nuban, if no , create it
//$nubanAccountID = "22";//(int)$data['nuban_account_id'];
$url = "https://api.paystack.co/transaction/initialize";
$options = [
'headers' => ['Authorization' => 'Bearer ' . $payload['key']],
'json' => [
'email' => $payload['emailAddress'],
'amount' => $payload['amount'],
'reference' => $payload['reference'],
'callback_url' => $payload['callBack'],
'channels' => [$payload['channel']],
'currency' => "NGN",
]
];
// var_dump($options);
try {
$response = container('guzzle')->post("{$url}", $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
/* public function getPaymentAccessCode($payload)
{
//check if user has nuban,if yes, return the nuban, if no , create it
//$nubanAccountID = "22";//(int)$data['nuban_account_id'];
$call_back = $payload['callBack'];
$url = "https://api.paystack.co/checkout/request_inline?key={$payload['pkey']}&ref={$payload['reference']}&email={$payload['emailAddress']}&amount={$payload['amount']}&currency=NGN&metadata={'referrer':$call_back}&channels[]={$payload['channel']}&mode=popup&hasTLSFallback=true";
//https://api.paystack.co/checkout/request_inline?id=paystackJKxBd&key=pk_test_31ff86856cda70b592c5cc858b2eba333bd3828c&ref=MF9561706554142&[email protected]&amount=10100000&currency=NGN&metadata={"referrer":"https://mf-staging.cardinalstone.com/subscribe"}&channels[]=card&mode=popup&hasTLSFallback=true&device=76b884a4b80350a1ebe11a4d8d7903cf
$options = [
'headers' => ['Authorization' => 'Bearer ' . $payload['key']],
];
try {
$response = container('guzzle')->get("{$url}");
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
} */
public function getNubanCustomer($customerID, $product)
{
//check if user has nuban,if yes, return the nuban, if no , create it
//$nubanAccountID = "22";//(int)$data['nuban_account_id'];
try {
if(strtoupper($product) == "CSPFIFUND")
{
$response = container('guzzle')->get('https://api.paystack.co/customer/' .$customerID, ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')]]);
}elseif(strtoupper($product) == "CSWALLET")
{
$response = container('guzzle')->get('https://api.paystack.co/customer/' .$customerID, ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')]]);
}
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
public function listNubanCustomers($product)
{
//check if user has nuban,if yes, return the nuban, if no , create it
try {
if(strtoupper($product) == "CSPFIFUND")
{
$response = container('guzzle')->get('https://api.paystack.co/customer/', ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')]]);
}elseif(strtoupper($product) == "CSWALLET")
{
$response = container('guzzle')->get('https://api.paystack.co/customer/', ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')]]);
}
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
public function listNubanAccounts($product)
{
//check if user has nuban,if yes, return the nuban, if no , create it
try {
if(strtoupper($product) == "CSPFIFUND")
{
$response = container('guzzle')->get('https://api.paystack.co/dedicated_account/', ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')]]);
}elseif(strtoupper($product) == "CSWALLET")
{
$response = container('guzzle')->get('https://api.paystack.co/dedicated_account/', ['headers' => ['Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')]]);
}
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
public function createNubanAccount($customer_code, $product)
{
/* curl https://api.paystack.co/dedicated_account
-H "Authorization: Bearer YOUR_SECRET_KEY"
-H "Content-Type: application/json"
-d '{ "customer": "CUS_358xertt55", "preferred_bank": "access-bank"}'
-X POST
*/
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')
],
'json' => [
"customer"=> $customer_code,
"preferred_bank"=>"wema-bank"
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')
],
'json' => [
"customer"=> $customer_code,
"preferred_bank"=>"wema-bank"
]
];
}
try {
$response = container('guzzle')->post('https://api.paystack.co/dedicated_account', $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$message1 = $response->getStatusCode();
$message2 = $response->getReasonPhrase();
$message3 = $customer_code . " - " . $product;
$message4 = (string) $response->getBody();
$message5 = "Create NUBAN Account";
container('mutualFundModel')->activity_log($message1,$message2,$message3,$message4,$message5);
$result = json_decode($response->getBody(), true);
return $result;
}
public function createNubanCustomer($data, $product)
{
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')
],
'json' => [
"email"=> $data['emailAddress'],
"phone"=> $data['phoneNumber'],
"first_name" => $data['firstName'],
"last_name" => $data['lastName'],
"metadata" => [
"userid" => $data["CustID"]
]
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')
],
'json' => [
"email"=> $data['emailAddress'],
"phone"=> $data['phoneNumber'],
"first_name" => $data['firstName'],
"last_name" => $data['lastName'],
"metadata" => [
"userid" => $data["CustID"]
]
]
];
}
try {
$response = container('guzzle')->post('https://api.paystack.co/customer', $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$message1 = $response->getStatusCode() ." and " .$response->getReasonPhrase();
$message2 = "First Name: " . $data['firstName'] . ", Last Name: " . $data['lastName'];
$message3 = "CustID: " . $data['CustID']. ", Product: " .$product;
$message4 = (string) $response->getBody();
$message5 = "Create NUBAN Customer";
container('mutualFundModel')->activity_log($message1,$message2,$message3,$message4,$message5);
$result = json_decode($response->getBody(), true);
return $result;
}
public function updateNubanCustomer($data, $product)
{
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')
],
'json' => [
"email"=> $data['emailAddress'],
"phone"=> $data['phoneNumber'],
"first_name" => $data['firstName'],
"last_name" => $data['lastName'],
"metadata" => [
"userid" => $data["CustID"]
]
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')
],
'json' => [
"email"=> $data['emailAddress'],
"phone"=> $data['phoneNumber'],
"first_name" => $data['firstName'],
"last_name" => $data['lastName'],
"metadata" => [
"userid" => $data["CustID"]
]
]
];
}
try {
$response = container('guzzle')->post('https://api.paystack.co/customer/{$data["CustID"]}', $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody(), true);
return $result;
}
public function validateNubanCustomer($data, $product)
{
/* "country": "NG",
"type": "bank_account",
"account_number": "0123456789",
"bvn": "200123456677",
"bank_code": "007",
"first_name": "Asta",
"last_name": "Lavista" */
/**************************Using first_name -> firstName*******************************************/
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn" => $data['BVN'],
"bank_code" => $data['bankCode'],
"first_name" => $data['firstName'],
"last_name" => $data['lastName']
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn" => $data['BVN'],
"bank_code" => $data['bankCode'],
"first_name" => $data['firstName'],
"last_name" => $data['lastName']
]
];
}
try {
$response = container('guzzle')->post('https://api.paystack.co/customer/'.$data['customerCode'].'/identification', $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$message1 = $response->getStatusCode();
$message2 = $response->getReasonPhrase();
$message3 = $data['customerCode']." - ".$data['lastName']." - ".$data['firstName']." - ".$data['idType']." - ".$data['idValue'];
$message4 = (string) $response->getBody();
$message5 = "Validate NUBAN Customer";
container('mutualFundModel')->activity_log($message1,$message2,$message3,$message4,$message5);
/**************************Using first_name -> middleName*******************************************/
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn" => $data['BVN'],
"bank_code" => $data['bankCode'],
"first_name" => $data['middleName'],
"last_name" => $data['lastName']
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn" => $data['BVN'],
"bank_code" => $data['bankCode'],
"first_name" => $data['middleName'],
"last_name" => $data['lastName']
]
];
}
try {
$response = container('guzzle')->post('https://api.paystack.co/customer/'.$data['customerCode'].'/identification', $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$message1 = $response->getStatusCode();
$message2 = $response->getReasonPhrase();
$message3 = $data['customerCode']." - ".$data['lastName']." - ".$data['middleName']." - ".$data['idType']." - ".$data['idValue'];
$message4 = (string) $response->getBody();
$message5 = "Validate NUBAN Customer";
container('mutualFundModel')->activity_log($message1,$message2,$message3,$message4,$message5);
/**************************Using first_name -> BVNFirstName*******************************************/
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn" => $data['BVN'],
"bank_code" => $data['bankCode'],
"first_name" => $data['BVNFirstName'],
// "last_name" => $data['BVNLastName'],
"last_name" => $data['lastName'],
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn" => $data['BVN'],
"bank_code" => $data['bankCode'],
"first_name" => $data['BVNFirstName'],
// "last_name" => $data['BVNLastName'],
"last_name" => $data['lastName']
]
];
}
try {
$response = container('guzzle')->post('https://api.paystack.co/customer/'.$data['customerCode'].'/identification', $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$message1 = $response->getStatusCode();
$message2 = $response->getReasonPhrase();
// $message3 = $data['customerCode']." - ".$data['BVNLastName']." - ".$data['BVNFirstName']." - ".$data['idType']." - ".$data['idValue'];
$message3 = $data['customerCode']." - ".$data['lastName']." - ".$data['BVNFirstName']." - ".$data['idType']." - ".$data['idValue'];
$message4 = (string) $response->getBody();
$message5 = "Validate NUBAN Customer";
container('mutualFundModel')->activity_log($message1,$message2,$message3,$message4,$message5);
/**************************Using first_name -> BVNMiddleName*******************************************/
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn" => $data['BVN'],
"bank_code" => $data['bankCode'],
"first_name" => $data['BVNMiddleName'],
// "last_name" => $data['BVNLastName'],
"last_name" => $data['lastName'],
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn" => $data['BVN'],
"bank_code" => $data['bankCode'],
"first_name" => $data['BVNMiddleName'],
// "last_name" => $data['BVNLastName'],
"last_name" => $data['lastName'],
]
];
}
try {
$response = container('guzzle')->post('https://api.paystack.co/customer/'.$data['customerCode'].'/identification', $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$message1 = $response->getStatusCode();
$message2 = $response->getReasonPhrase();
// $message3 = $data['customerCode']." - ".$data['BVNLastName']." - ".$data['BVNMiddleName']." - ".$data['idType']." - ".$data['idValue'];
$message3 = $data['customerCode']." - ".$data['lastName']." - ".$data['BVNMiddleName']." - ".$data['idType']." - ".$data['idValue'];
$message4 = (string) $response->getBody();
$message5 = "Validate NUBAN Customer";
container('mutualFundModel')->activity_log($message1,$message2,$message3,$message4,$message5);
$result = json_decode($response->getBody(), true);
return $result;
}
public function validateNubanCustomer__($data, $product)
{
/* "country": "NG",
"type": "bank_account",
"account_number": "0123456789",
"bvn": "200123456677",
"bank_code": "007",
"first_name": "Asta",
"last_name": "Lavista" */
/**************************Using fist_name -> firstName*******************************************/
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn"=> $data['BVN'],
"bank_code"=> $data['bankCode'],
"first_name" => $data['firstName'],
"last_name" => $data['lastName']
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn"=> $data['BVN'],
"bank_code"=> $data['bankCode'],
"first_name" => $data['firstName'],
"last_name" => $data['lastName']
]
];
}
try {
$response = container('guzzle')->post('https://api.paystack.co/customer/'.$data['customerCode'].'/identification', $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$message1 = $response->getStatusCode();
$message2 = $response->getReasonPhrase();
$message3 = $data['customerCode']." - ".$data['lastName']." - ".$data['firstName']." - ".$data['idType']." - ".$data['idValue'];
$message4 = (string) $response->getBody();
$message5 = "Validate NUBAN Customer- FirstName";
container('mutualFundModel')->activity_log($message1,$message2,$message3,$message4,$message5);
/**************************Using fist_name -> middleName*******************************************/
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn"=> $data['BVN'],
"bank_code"=> $data['bankCode'],
"first_name" => $data['firstName'],
"last_name" => $data['lastName']
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')
],
'json' => [
"country" => "NG",
"type" => "bank_account",
"account_number" => $data['accountNumber'],
"bvn" => $data['BVN'],
"bank_code" => $data['bankCode'],
"first_name" => $data['firstName'],
"last_name" => $data['lastName']
]
];
}
try {
$response = container('guzzle')->post('https://api.paystack.co/customer/'.$data['customerCode'].'/identification', $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$message1 = $response->getStatusCode();
$message2 = $response->getReasonPhrase();
$message3 = $data['customerCode']." - ".$data['lastName']." - ".$data['firstName']." - ".$data['idType']." - ".$data['idValue'];
$message4 = (string) $response->getBody();
$message5 = "Validate NUBAN Customer- MiddleName";
container('mutualFundModel')->activity_log($message1,$message2,$message3,$message4,$message5);
$result = json_decode($response->getBody(), true);
return $result;
}
public function checkNubanPaymentTransaction($data, $product)
{
if(strtoupper($product) == "CSPFIFUND")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_MUTUALFUND')
],
'query' => [
"channel" => "dedicated_nuban",
"status" => "success",
"customer" => $data['paystack_customer_id'],
"from" => $data['date'],
"to" => $data['date'],
"amount" => ((float)($data['amount'])) * 100,
]
];
}elseif(strtoupper($product) == "CSWALLET")
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . env('PAYSTACK_KEY_CSWALLET')
],
'query' => [
"channel" => "dedicated_nuban",
"status" => "success",
"customer" => $data['paystack_customer_id'],
"from" => $data['date'],
"to" => $data['date'],
"amount" => ((float)($data['amount'])) * 100,
]
];
}
try {
$response = container('guzzle')->get('https://api.paystack.co/transaction', $options);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
}
$result = json_decode($response->getBody());
if(empty($result->data)){
return [
"payment" => [
"status" => "01",
"comments" => "No Transaction found",
],
"data" => []
];
}
foreach($result->data as $eachData){
if($eachData->status == "success"){
return [
"payment" => [
"status" => "00",
"comments" => "success",
],
"data" => $eachData
];
}elseif($eachData->status == "failed"){
$response = [
"payment" => [
"status" => "02",
"comments" => "Transaction failed",
],
"data" => $eachData
];
}
elseif($eachData->status == "abandoned"){
$response = [
"payment" => [
"status" => "03",
"comments" => " Transaction abandoned",
],
"data" => $eachData
];
}else{
$response = [
"payment" => [
"status" => "01",
"comments" => "No Transaction found",
],
"data" => []
];
}
}
// $result = json_decode($response, true);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment