From 2463b3037ac5becb698a1efb4fbcdace17dd707c Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Wed, 4 Oct 2023 13:41:32 +0100 Subject: [PATCH] fix: missing recipient while doing ilink world transaction --- .../iLinkTransactionController.php | 54 +++++++++++++++---- app/helpers.php | 10 ++++ resources/lang/en/errors.php | 2 + resources/lang/fr/errors.php | 1 + 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index a757ccc..2dabcd8 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -307,8 +307,10 @@ class iLinkTransactionController extends Controller $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 + $destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country, $transaction->type_id_destinataire); + if(!($destinataire instanceof User)){ + return $destinataire; + }else{ $transaction->nom_destinataire = $destinataire->lastname; $transaction->prenom_destinataire = $destinataire->firstname; if ($destinataire->network->country->id == $request->final_country) { @@ -319,8 +321,6 @@ class iLinkTransactionController extends Controller $country = Country::findOrFail($request->final_country); throw new Exception(trans('errors.wallet_country_not_match', ['country' => $country->name]), 500); } - } else { - throw new Exception(trans('errors.wallet_not_defined'), 500); } //Mise a jour des comissions et compensation @@ -1876,6 +1876,11 @@ class iLinkTransactionController extends Controller 'payment_type' => PaymentType::CASH_IN, 'payment_method' => PaymentMethod::WALLET ]); + }else{ + $destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country); + if(!($destinataire instanceof User)){ + return $destinataire; + } } $frais += $fees; @@ -1914,8 +1919,8 @@ class iLinkTransactionController extends Controller 'payment_method' => 'CARD', 'customer_id' => $user->id, 'customer_email' => $user->email, - 'customer_name' => $withLinkedCard ? $identification->firstname : $request->input('customer_name'), - 'customer_surname' => $withLinkedCard ? $identification->lastname : $request->input('customer_surname'), + 'customer_name' => $withLinkedCard ? $identification->firstname : $request->input('customer_name', $destinataire?->firstname ?? ''), + 'customer_surname' => $withLinkedCard ? $identification->lastname : $request->input('customer_surname', $destinataire?->lastname ?? ''), 'customer_address' => $withLinkedCard ? $identification->town : $request->input('customer_address'), 'customer_city' => $withLinkedCard ? $identification->town : $request->input('customer_city'), 'customer_country' => $country->code_country, @@ -2290,8 +2295,11 @@ class iLinkTransactionController extends Controller ]); $frais += $fees; } else { - $destinataire = User::where('user_code', $request->id_destinataire)->orWhere('phone', $request->id_destinataire)->first(); - $data['destinataire'] = $destinataire ? $destinataire->lastname . ' ' . $destinataire->firstname : $request->id_destinataire; + $destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country); + if(!($destinataire instanceof User)){ + return $destinataire; + } + $data['destinataire'] = $destinataire->lastname . ' ' . $destinataire->firstname; } $taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais); $data['frais'] = round($frais + $taxe, 2); @@ -2500,8 +2508,11 @@ class iLinkTransactionController extends Controller 'payment_method' => PaymentMethod::WALLET ]); } else { - $destinataire = User::where('user_code', $request->id_destinataire)->orWhere('phone', $request->id_destinataire)->first(); - $data['destinataire'] = $destinataire ? $destinataire->lastname . ' ' . $destinataire->firstname : $request->id_destinataire; + $destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country); + if(!($destinataire instanceof User)){ + return $destinataire; + } + $data['destinataire'] = $destinataire->lastname . ' ' . $destinataire->firstname; } $frais += $fees; @@ -2521,6 +2532,29 @@ class iLinkTransactionController extends Controller return $this->successResponse($data); } + //Verifier l'existance du destinataire ilink + private function verifyiLinkRecipient($recipientId, $countryId, $recipientIdType = null) + { + $recipientId = remove_spaces($recipientId); + $phone = $recipientId; + if(!str_contains($phone,'+')){ + $countryDialCode = Country::find($countryId)?->code_dial ?? '' ; + $phone = $countryDialCode.$recipientId; + } + + if(empty($recipientIdType)){ + $destinataire = User::where('user_code', $recipientId)->orWhere('phone', $phone)->first(); + }else{ + $destinataire = User::where(strtolower($recipientIdType), $recipientId)->first(); + } + + if(empty($destinataire)){ + return $this->errorResponse(__('errors.recipient_not_found')); + } + + return $destinataire; + } + public function getTransactionRetrait(Request $request) { $this->validate($request, [ diff --git a/app/helpers.php b/app/helpers.php index 4292c64..1a189a5 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -265,3 +265,13 @@ if (!function_exists('cookie')) { return $cookie->make($name, $value, $minutes, $path, $domain, $secure, $httpOnly); } } + +if (!function_exists('remove_spaces')) { + function remove_spaces($string): string + { + $pattern = '/\s+/'; + return preg_replace($pattern, '', $string); + } +} + +; diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index fd88106..c68be53 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -91,4 +91,6 @@ Paying network : :network :country', 'transaction_not_supported' => "This transaction is not supported", 'payment_invalid' => "Invalid payment", 'service_unavailable_in_country' => 'Service not available in this country', + 'recipient_not_found' => "This recipient does not exist" + ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index 610e918..16b0941 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -91,4 +91,5 @@ Réseau payeur : :network :country', 'transaction_not_supported' => "Cette transaction n'est pas supportée", 'payment_invalid' => "Paiement invalide", 'service_unavailable_in_country' => 'Service non disponible dans ce pays', + 'recipient_not_found' => "Ce destinataire n'existe pas" ];