From a3566a6ad72f453316bd6f009de73dbcbe75e1a1 Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Tue, 1 Aug 2023 07:24:56 +0100 Subject: [PATCH] fix: add verification of balance while doing "User: Envoi de carte vers autre wallet" --- .../iLinkTransactionController.php | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 77bb771..317e9d2 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -282,9 +282,13 @@ class iLinkTransactionController extends Controller $transaction->commission_hyp = $transaction->part_reseau_emetteur; $transaction->id_transaction = $this->getTransactionID(); $transaction->type_id_destinataire = $request->input('type_id_destinataire'); + $transaction->nom_destinataire = $request->nom_destinataire; + $transaction->prenom_destinataire = $request->prenom_destinataire; if ($configPayeur->type == 'ilink') { $destinataire = User::where($transaction->type_id_destinataire, $request->id_destinataire)->first(); if ($destinataire) { // Si c'est un wallet ilink + $transaction->nom_destinataire = $destinataire->lastname; + $transaction->prenom_destinataire = $destinataire->firstname; if ($destinataire->network->country->id == $request->final_country) { $walletDestinataire = WalletsUser::where('idUser', $destinataire->id)->firstOrFail(); $walletDestinataire->balance += $transaction->montant_net_final_country; @@ -326,8 +330,8 @@ class iLinkTransactionController extends Controller 'currency' => $countryCurrency->currency_code, 'customer_id' => $user->id, 'customer_email' => $user->email, - 'customer_name' => $user->firstname, - 'customer_surname' => $user->lastname, + 'customer_name' => $transaction->prenom_destinataire, + 'customer_surname' => $transaction->nom_destinataire, 'customer_phone_number' => $transaction->id_destinataire, 'customer_country' => $countryCurrency->code_country, 'reason' => "User - Envoi de wallet à wallet" @@ -1807,6 +1811,15 @@ class iLinkTransactionController extends Controller //Verification des limites reglementaires $this->checkReguationsLimits($walletUser->id, $init_country, $request->final_country, $transaction->montant); + $balance = $this->checkBalance([ + 'country_id' => $request->final_country, + 'amount' => $request->montant + ]); + + if (!is_string($balance)) { + return $balance; + } + $configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail(); $reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->first(); @@ -1879,6 +1892,8 @@ class iLinkTransactionController extends Controller if ($configPayeur->type == 'ilink') { $destinataire = User::where($transaction->type_id_destinataire, $request->id_destinataire)->first(); if ($destinataire) { // Si c'est un wallet ilink + $transaction->nom_destinataire = $destinataire->lastname; + $transaction->prenom_destinataire = $destinataire->firstname; if ($destinataire->network->country->id == $request->final_country) { $walletDestinataire = WalletsUser::where('idUser', $destinataire->id)->firstOrFail(); $walletDestinataire->balance += $transaction->montant_net_final_country; @@ -2027,6 +2042,30 @@ class iLinkTransactionController extends Controller return $transaction; } + /** + * @throws Exception + */ + // Check Aggretor balance before payIn + private function checkBalance($data) + { + // Pay through payment service + $client = new Client([ + 'base_uri' => config('variable.payment_service_url'), + 'headers' => [ + 'Authorization' => config('variable.payment_service_key'), + ] + ]); + + $response = $client->get('/checkBalance', ['query' => $data , 'http_errors' => false]); + $code = $response->getStatusCode(); + + if ($code == 200) { + return "available"; + } else { + throw new Exception($content['error'] ?? __('errors.service_unavailable'), $content['status'] ?? 500); + } + } + /** * @throws Exception */