From 029249f3af55fcb7875d1f8b424d805d2bdc0f2e Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Sun, 9 Aug 2020 23:13:21 +0100 Subject: [PATCH] + Add Adyen API cash-in/cash-out --- app/Exceptions/Handler.php | 8 +- .../iLinkTransactionController.php | 82 +++++++++++++++---- app/Models/WalletIlinkTransaction.php | 24 +++--- 3 files changed, 83 insertions(+), 31 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 8c58178..f8dea05 100755 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -113,11 +113,11 @@ class Handler extends ExceptionHandler $code = $exception->getCode(); if($error){ - if($error->message){ + if (isset($error->message)) { $message = json_decode($error->message); - if(isset($message->errorMessage)) - return $this->errorResponse($message->errorMessage,$code); - return $this->errorResponse($error->message,$code); + if (isset($message->errorMessage)) + return $this->errorResponse($message->errorMessage, $code); + return $this->errorResponse($error->message, $code); } return $this->errorResponse($error,$code); } else diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 15d44af..1169886 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -30,6 +30,10 @@ class iLinkTransactionController extends Controller use ApiResponser; use Helper; + private $PAYMENT_URL = "/adyen-api/v1/transaction/payement"; + private $PAYOUT_URL = "/adyen-api/v1/transaction/payout"; + private $REFUND_URL = "/adyen-api/v1/transaction/refund"; + /** * Create a new controller instance. * @@ -217,15 +221,25 @@ class iLinkTransactionController extends Controller $frais = $request->montant * $config->taux_com_user_wallet_carte / 100; $transaction->montant_net = $montantDepot = $transaction->montant - $frais; - $body['amount'] = $this->toUSDAmount($montantDepot, $init_country); +// $body['amount'] = $this->toUSDAmount($montantDepot, $init_country); $body['card_number'] = $user->numero_carte; $body['cvv'] = $request->cvv; - $body['expiry_date'] = $user->expiration_date->format('Y-m'); +// $body['expiry_date'] = $user->expiration_date->format('Y-m'); + $body['expiry_date'] = $user->expiration_date->format('m/y'); + $body['amount'] = $montantDepot; + $identification = Identification::where('id_user', $user->id)->first(); + $body['cardholder_name'] = $identification ? $identification->lastname . ' ' . $identification->firstname : $user->lastname . ' ' . $user->firstname; //"John Smith" ; + $body['currency'] = $this->getCurrency($init_country); + $body['ref'] = date("Y-m-d H:i:s.u"); + + $response = $client->post($this->PAYOUT_URL, ['json' => $body]); - $response = $client->post('fund-transfer-api/v1/transaction/push', ['json' => $body]); $code = $response->getStatusCode(); if ($code == 200) { + $response = json_decode($response->getBody()->getContents(), true)["response"]; + $transaction->pspReference = $response["pspReference"]; + $walletUser->balance -= $transaction->montant; //Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission $transaction->commission_banque = $frais * $config->taux_com_banque_envoi_wallet_carte_ilink / 100; @@ -243,7 +257,7 @@ class iLinkTransactionController extends Controller ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), 'net' => $this->toMoney($montantDepot, $init_country), 'fees' => $this->toMoney($frais, $init_country), 'sender_code' => $user->user_code, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]); - $this->sendMail($user->email, trans('messages.successful_transaction'), $message); +// $this->sendMail($user->email, trans('messages.successful_transaction'), $message); return $this->successResponse($message . trans('messages.sent_by_mail')); } else { @@ -398,16 +412,26 @@ class iLinkTransactionController extends Controller $frais = $request->montant * $config->taux_com_user_carte_wallet / 100; $transaction->montant_net = $montantRetrait = $transaction->montant - $frais; - $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country); +// $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country); $body['card_number'] = $user->numero_carte; $body['cvv'] = $request->cvv; - $body['expiry_date'] = $user->expiration_date->format('Y-m'); +// $body['expiry_date'] = $user->expiration_date->format('Y-m'); + $body['expiry_date'] = $user->expiration_date->format('m/y'); + $body['amount'] = $montantRetrait; + $identification = Identification::where('id_user', $user->id)->first(); + $body['cardholder_name'] = $identification ? $identification->lastname . ' ' . $identification->firstname : $user->lastname . ' ' . $user->firstname; //"John Smith" ; + $body['currency'] = $this->getCurrency($init_country); + $body['cardholder_name'] = "John Smith"; + $body['ref'] = date("Y-m-d H:i:s.u"); // dd($body); - $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); + $response = $client->post($this->PAYMENT_URL, ['json' => $body]); $code = $response->getStatusCode(); if ($code == 200) { + $response = json_decode($response->getBody()->getContents(), true)["response"]; + $transaction->pspReference = $response["pspReference"]; + $transaction->commission_banque = $commissionBanque = $frais * $config->taux_com_banque_retrait_carte_cash_ilink / 100; //Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission @@ -451,15 +475,24 @@ class iLinkTransactionController extends Controller $frais = $request->montant * $config->taux_com_user_carte_cash / 100; $transaction->montant_net_final_country = $transaction->montant_net = $montantRetrait = $transaction->montant - $frais; - $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country); +// $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country); $body['card_number'] = $user->numero_carte; $body['cvv'] = $request->cvv; - $body['expiry_date'] = $user->expiration_date->format('Y-m'); +// $body['expiry_date'] = $user->expiration_date->format('Y-m'); + $body['expiry_date'] = $user->expiration_date->format('m/y'); + $body['amount'] = $montantDepot; + $identification = Identification::where('id_user', $user->id)->first(); + $body['cardholder_name'] = $identification ? $identification->lastname . ' ' . $identification->firstname : $user->lastname . ' ' . $user->firstname; //"John Smith" ; + $body['currency'] = $this->getCurrency($init_country); + $body['ref'] = date("Y-m-d H:i:s.u"); - $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); + $response = $client->post($this->PAYMENT_URL, ['json' => $body]); $code = $response->getStatusCode(); if ($code == 200) { + $response = json_decode($response->getBody()->getContents(), true)["response"]; + $transaction->pspReference = $response["pspReference"]; + $transaction->commission_banque = $commissionBanque = $frais * $config->taux_com_banque_retrait_carte_cash_ilink / 100; //Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission @@ -588,15 +621,23 @@ class iLinkTransactionController extends Controller $frais = floatval($request->montant * $config->taux_com_wallet_ag_carte_cash / 100); $montantRetrait = $transaction->montant - $frais; $transaction->montant_net = $montantRetrait; - $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country); +// $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country); $body['card_number'] = $request->numero_carte; $body['cvv'] = $request->cvv; - $body['expiry_date'] = $expiration_date->format('Y-m'); +// $body['expiry_date'] = $expiration_date->format('Y-m'); + $body['expiry_date'] = $expiration_date->format('m/y'); + $body['amount'] = $montantRetrait; + $body['cardholder_name'] = $request->lastname . ' ' . $request->firstname; //"John Smith" ; + $body['currency'] = $this->getCurrency($init_country); + $body['ref'] = date("Y-m-d H:i:s.u"); - $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); + $response = $client->post($this->PAYMENT_URL, ['json' => $body]); $code = $response->getStatusCode(); if ($code == 200) { + $response = json_decode($response->getBody()->getContents(), true)["response"]; + $transaction->pspReference = $response["pspReference"]; + $banqueCommission = floatval($frais * $config->taux_com_banque_retrait_carte_cash / 100); $transaction->commission_banque = $banqueCommission; // 2---> Emmètre via API sécurisé SSL une requête de débit de notre @@ -762,15 +803,24 @@ class iLinkTransactionController extends Controller $frais = $request->montant * $config->taux_com_wallet_ag_envoi_cash_carte / 100; $montantDepot = $transaction->montant - $frais; $transaction->montant_net = $montantDepot; - $body['amount'] = $this->toUSDAmount($montantDepot, $init_country);; +// $body['amount'] = $this->toUSDAmount($montantDepot, $init_country);; $body['card_number'] = $request->numero_carte; $body['cvv'] = $request->cvv; - $body['expiry_date'] = $expiration_date->format('Y-m'); +// $body['expiry_date'] = $expiration_date->format('Y-m'); + $body['expiry_date'] = $expiration_date->format('m/y'); + $body['amount'] = $montantDepot; - $response = $client->post('fund-transfer-api/v1/transaction/push', ['json' => $body]); + $body['cardholder_name'] = $request->lastname . ' ' . $request->firstname; //"John Smith" ; + $body['currency'] = $this->getCurrency($init_country); + $body['ref'] = date("Y-m-d H:i:s.u"); + + $response = $client->post($this->PAYOUT_URL, ['json' => $body]); $code = $response->getStatusCode(); if ($code == 200) { + $response = json_decode($response->getBody()->getContents(), true)["response"]; + $transaction->pspReference = $response["pspReference"]; + $banqueCommission = floatval($frais * $config->taux_com_banque_depot_cash_carte / 100); $transaction->commission_banque = $banqueCommission; // 2---> Emmètre via API sécurisé SSL une requête de débit de notre diff --git a/app/Models/WalletIlinkTransaction.php b/app/Models/WalletIlinkTransaction.php index 7cb03d6..2fed62e 100644 --- a/app/Models/WalletIlinkTransaction.php +++ b/app/Models/WalletIlinkTransaction.php @@ -56,6 +56,7 @@ use Illuminate\Database\Eloquent\Model; * @property int $canceled * @property int $type * @property Carbon $date + * @property string pspReference * * @property Country $country * @property Wallet $wallet @@ -137,18 +138,19 @@ class WalletIlinkTransaction extends Model 'final_country', 'commission_banque', 'commission_ag', - 'commission_sup', - 'commission_hyp', + 'commission_sup', + 'commission_hyp', 'commission_hyp_final_country', - 'id_wallet_user', - 'id_wallet_ag', - 'id_wallet_sup', - 'id_wallet_hyp', - 'id_wallet_hyp_payeur', - 'canceled', - 'type', - 'date' - ]; + 'id_wallet_user', + 'id_wallet_ag', + 'id_wallet_sup', + 'id_wallet_hyp', + 'id_wallet_hyp_payeur', + 'canceled', + 'type', + 'date', + 'pspReference' + ]; public function country() {