fix: missing recipient while doing ilink world transaction

This commit is contained in:
Djery-Tom 2023-10-04 13:41:32 +01:00
parent 6257a00b76
commit 2463b3037a
4 changed files with 57 additions and 10 deletions

View File

@ -307,8 +307,10 @@ class iLinkTransactionController extends Controller
$transaction->nom_destinataire = $request->nom_destinataire; $transaction->nom_destinataire = $request->nom_destinataire;
$transaction->prenom_destinataire = $request->prenom_destinataire; $transaction->prenom_destinataire = $request->prenom_destinataire;
if ($configPayeur->type == 'ilink') { if ($configPayeur->type == 'ilink') {
$destinataire = User::where($transaction->type_id_destinataire, $request->id_destinataire)->first(); $destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country, $transaction->type_id_destinataire);
if ($destinataire) { // Si c'est un wallet ilink if(!($destinataire instanceof User)){
return $destinataire;
}else{
$transaction->nom_destinataire = $destinataire->lastname; $transaction->nom_destinataire = $destinataire->lastname;
$transaction->prenom_destinataire = $destinataire->firstname; $transaction->prenom_destinataire = $destinataire->firstname;
if ($destinataire->network->country->id == $request->final_country) { if ($destinataire->network->country->id == $request->final_country) {
@ -319,8 +321,6 @@ class iLinkTransactionController extends Controller
$country = Country::findOrFail($request->final_country); $country = Country::findOrFail($request->final_country);
throw new Exception(trans('errors.wallet_country_not_match', ['country' => $country->name]), 500); 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 //Mise a jour des comissions et compensation
@ -1876,6 +1876,11 @@ class iLinkTransactionController extends Controller
'payment_type' => PaymentType::CASH_IN, 'payment_type' => PaymentType::CASH_IN,
'payment_method' => PaymentMethod::WALLET 'payment_method' => PaymentMethod::WALLET
]); ]);
}else{
$destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country);
if(!($destinataire instanceof User)){
return $destinataire;
}
} }
$frais += $fees; $frais += $fees;
@ -1914,8 +1919,8 @@ class iLinkTransactionController extends Controller
'payment_method' => 'CARD', 'payment_method' => 'CARD',
'customer_id' => $user->id, 'customer_id' => $user->id,
'customer_email' => $user->email, 'customer_email' => $user->email,
'customer_name' => $withLinkedCard ? $identification->firstname : $request->input('customer_name'), 'customer_name' => $withLinkedCard ? $identification->firstname : $request->input('customer_name', $destinataire?->firstname ?? ''),
'customer_surname' => $withLinkedCard ? $identification->lastname : $request->input('customer_surname'), 'customer_surname' => $withLinkedCard ? $identification->lastname : $request->input('customer_surname', $destinataire?->lastname ?? ''),
'customer_address' => $withLinkedCard ? $identification->town : $request->input('customer_address'), 'customer_address' => $withLinkedCard ? $identification->town : $request->input('customer_address'),
'customer_city' => $withLinkedCard ? $identification->town : $request->input('customer_city'), 'customer_city' => $withLinkedCard ? $identification->town : $request->input('customer_city'),
'customer_country' => $country->code_country, 'customer_country' => $country->code_country,
@ -2290,8 +2295,11 @@ class iLinkTransactionController extends Controller
]); ]);
$frais += $fees; $frais += $fees;
} else { } else {
$destinataire = User::where('user_code', $request->id_destinataire)->orWhere('phone', $request->id_destinataire)->first(); $destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country);
$data['destinataire'] = $destinataire ? $destinataire->lastname . ' ' . $destinataire->firstname : $request->id_destinataire; 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); $taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
$data['frais'] = round($frais + $taxe, 2); $data['frais'] = round($frais + $taxe, 2);
@ -2500,8 +2508,11 @@ class iLinkTransactionController extends Controller
'payment_method' => PaymentMethod::WALLET 'payment_method' => PaymentMethod::WALLET
]); ]);
} else { } else {
$destinataire = User::where('user_code', $request->id_destinataire)->orWhere('phone', $request->id_destinataire)->first(); $destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country);
$data['destinataire'] = $destinataire ? $destinataire->lastname . ' ' . $destinataire->firstname : $request->id_destinataire; if(!($destinataire instanceof User)){
return $destinataire;
}
$data['destinataire'] = $destinataire->lastname . ' ' . $destinataire->firstname;
} }
$frais += $fees; $frais += $fees;
@ -2521,6 +2532,29 @@ class iLinkTransactionController extends Controller
return $this->successResponse($data); 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) public function getTransactionRetrait(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [

View File

@ -265,3 +265,13 @@ if (!function_exists('cookie')) {
return $cookie->make($name, $value, $minutes, $path, $domain, $secure, $httpOnly); 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);
}
}
;

View File

@ -91,4 +91,6 @@ Paying network : :network :country',
'transaction_not_supported' => "This transaction is not supported", 'transaction_not_supported' => "This transaction is not supported",
'payment_invalid' => "Invalid payment", 'payment_invalid' => "Invalid payment",
'service_unavailable_in_country' => 'Service not available in this country', 'service_unavailable_in_country' => 'Service not available in this country',
'recipient_not_found' => "This recipient does not exist"
]; ];

View File

@ -91,4 +91,5 @@ Réseau payeur : :network :country',
'transaction_not_supported' => "Cette transaction n'est pas supportée", 'transaction_not_supported' => "Cette transaction n'est pas supportée",
'payment_invalid' => "Paiement invalide", 'payment_invalid' => "Paiement invalide",
'service_unavailable_in_country' => 'Service non disponible dans ce pays', 'service_unavailable_in_country' => 'Service non disponible dans ce pays',
'recipient_not_found' => "Ce destinataire n'existe pas"
]; ];