fix: take correct country while doing "User: Envoi de carte vers autre wallet"

This commit is contained in:
Djery-Tom 2023-08-02 19:16:06 +01:00
parent a3566a6ad7
commit 6351305a5f
1 changed files with 25 additions and 4 deletions

View File

@ -181,6 +181,15 @@ class iLinkTransactionController extends Controller
$init_country = $walletUser->user->card_country_id;
}else{
$init_country = $walletUser->user->network->country->id;
if($type->id == 21){
$withLinkedCard = $request->input('with_linked_card', false);
if ($withLinkedCard) {
$init_country = $walletUser->user->card_country_id;
}else{
$init_country = Country::where('code_country', $request->input('customer_country'))->first()?->id;
}
}
}
$transaction->init_country = $init_country;
$result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network')
@ -1784,7 +1793,7 @@ class iLinkTransactionController extends Controller
if ($withLinkedCard) {
if (!(isset($user->numero_carte) && isset($user->expiration_date))) {
throw new Exception(trans('errors.no_bank_card_attached'));
throw new Exception();
}
$transaction->expiration_date = $user->expiration_date;
$transaction->numero_carte = $user->numero_carte;
@ -1863,7 +1872,7 @@ class iLinkTransactionController extends Controller
// Retirer l'argent de la carte
$identification = Identification::where('id_user', $user->id)->first();
$customer_country_code = $withLinkedCard ? Country::where('name', $identification->country)->first()?->code_country : $request->input('customer_country');
$country = CountriesCurrency::findOrFail($init_country);
$payment_transaction_id = $request->input('payment_transaction_id');
$result = $this->handlePayIn($transaction, [
@ -1872,7 +1881,7 @@ class iLinkTransactionController extends Controller
'exp_year' => date("Y", strtotime($transaction->expiration_date)),
'cvc' => $request->input('cvv'),
'amount' => $montantRetrait,
'currency' => $this->getCurrency($init_country),
'currency' => $country->currency_code,
'payment_method' => 'CARD',
'customer_id' => $user->id,
'customer_email' => $user->email,
@ -1880,7 +1889,7 @@ class iLinkTransactionController extends Controller
'customer_surname' => $withLinkedCard ? $identification->lastname : $request->input('customer_surname'),
'customer_address' => $withLinkedCard ? $identification->town : $request->input('customer_address'),
'customer_city' => $withLinkedCard ? $identification->town : $request->input('customer_city'),
'customer_country' => $customer_country_code,
'customer_country' => $country->code_country,
'reason' => "User - Retrait de carte vers autre wallet"
], $payment_transaction_id);
@ -2190,6 +2199,15 @@ class iLinkTransactionController extends Controller
$init_country = $walletUser->user->card_country_id;
}else{
$init_country = $walletUser->user->network->country->id;
if($request->id == 21){
$withLinkedCard = $request->input('with_linked_card', false);
if ($withLinkedCard) {
$init_country = $walletUser->user->card_country_id;
}else{
$init_country = Country::where('code_country', $request->input('customer_country'))->first()?->id;
}
}
}
$result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network')
->where('networks.country_id', $init_country)->where('configWallet.type', 'ilink')
@ -2255,6 +2273,9 @@ class iLinkTransactionController extends Controller
break;
case 2: //User - Envoi de wallet à carte
$final_country = $walletUser->user->card_country_id;
if(empty($final_country)){
return $this->errorResponse(trans('errors.no_bank_card_attached'));
}
$plr_user_wallet_cart_national = $this->getPaliers($paliers_commission_wallets, 'user_wallet_cart_national');
$plr_user_wallet_cart_international = $this->getPaliers($paliers_commission_wallets, 'user_wallet_cart_international');
$frais = $this->calculateFees($init_country != $final_country ? $plr_user_wallet_cart_international : $plr_user_wallet_cart_national, $request->montant);