From d954a2b43eb63efb0922ca90c7a4a541a630c8ed Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Wed, 26 Jul 2023 13:52:32 +0100 Subject: [PATCH] feat(ilink transaction): use card country id in each card operation and commission calculation --- app/Http/Controllers/WalletController.php | 3 +- .../iLinkTransactionController.php | 172 ++++++++++-------- app/Models/User.php | 1 + resources/lang/en/messages.php | 57 +++--- resources/lang/fr/messages.php | 49 ++--- 5 files changed, 163 insertions(+), 119 deletions(-) diff --git a/app/Http/Controllers/WalletController.php b/app/Http/Controllers/WalletController.php index 8d79712..76912af 100755 --- a/app/Http/Controllers/WalletController.php +++ b/app/Http/Controllers/WalletController.php @@ -109,12 +109,13 @@ class WalletController extends Controller // Wallets users iLink public function showWalletUser($id_user) { - $wallet = collect(DB::select('SELECT wu.*, u.user_code , u.numero_carte , u.expiration_date ,n2.id as id_wallet_network, n2.name as network , cc.name as country, cc.currency_code , cw.has_nano_credit from wallets_users wu + $wallet = collect(DB::select('SELECT wu.*, u.user_code , u.numero_carte , u.expiration_date ,n2.id as id_wallet_network, n2.name as network , cc.name as country, cc.currency_code , card_cc.currency_code as card_currency_code, cw.has_nano_credit from wallets_users wu INNER JOIN users u ON u.id = wu.idUser INNER JOIN networks n1 ON n1.id = u.network_id INNER JOIN networks n2 ON n2.country_id = n1.country_id INNER JOIN configWallet cw ON cw.id_network = n2.id INNER JOIN countries_currencies cc ON cc.id = n2.country_id + LEFT JOIN countries_currencies card_cc ON card_cc.id = u.card_country_id WHERE wu.idUser = :id_user AND cw.type = \'ilink\' LIMIT 1', ['id_user' => $id_user]))->first(); if ($wallet) { return $this->successResponse($wallet); diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 12c93f9..77bb771 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -176,7 +176,13 @@ class iLinkTransactionController extends Controller $walletSuperviseur = Wallet::findOrFail($wallet_agent_sup->wallet_id); } else { $walletUser = WalletsUser::findOrFail($id_wallet_user); - $transaction->init_country = $init_country = $walletUser->user->network->country->id; + // Pour les operations à cartes, le pays initial c'est le pays de la carte + if(in_array($type->id, [10, 11])){ + $init_country = $walletUser->user->card_country_id; + }else{ + $init_country = $walletUser->user->network->country->id; + } + $transaction->init_country = $init_country; $result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network') ->where('networks.country_id', $init_country)->where('configWallet.type', 'ilink') ->select('configWallet.id')->first(); @@ -340,7 +346,7 @@ class iLinkTransactionController extends Controller $transaction->save(); $message = trans('messages.successful_user_send_to_wallet', ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), 'net_init' => $this->toMoney($montantDepot, $init_country), - 'net_final' => $this->toMoneyWithCurrency($montantDepot, $init_country, $request->final_country), 'fees' => $this->toMoney($frais + $taxe, $init_country), + 'net_final' => $this->toMoney($transaction->montant_net_final_country, $request->final_country), 'fees' => $this->toMoney($frais + $taxe, $init_country), 'init_country' => $this->getCountryName($init_country), 'final_country' => $this->getCountryName($request->final_country), 'sender_code' => $user->user_code, 'receiver_code' => $transaction->id_destinataire, 'network' => $this->getNetworkName($transaction->network_destinataire)]); $this->sendMail($user->email, trans('messages.successful_transaction'), $message); @@ -361,39 +367,42 @@ class iLinkTransactionController extends Controller $transaction->expiration_date = $user->expiration_date; $transaction->numero_carte = $user->numero_carte; -// $final_country = $request->input('final_country'); - $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'); - $plr_hyp_user_wallet_cart_national = $this->getPaliers($paliers_commission_wallets, 'hyp_user_wallet_cart_national'); -// $plr_hyp_user_wallet_cart_international = $this->getPaliers($paliers_commission_wallets, 'hyp_user_wallet_cart_international'); - $plr_bank_user_wallet_cart_national = $this->getPaliers($paliers_commission_wallets, 'bank_user_wallet_cart_national'); -// $plr_bank_user_wallet_cart_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_wallet_cart_international'); + $final_country = $user->card_country_id; + $transaction->final_country = $final_country; - $frais = $this->calculateFees($plr_user_wallet_cart_national, $request->montant); + $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'); + $plr_hyp_user_wallet_cart_national = $this->getPaliers($paliers_commission_wallets, 'hyp_user_wallet_cart_national'); + $plr_hyp_user_wallet_cart_international = $this->getPaliers($paliers_commission_wallets, 'hyp_user_wallet_cart_international'); + $plr_bank_user_wallet_cart_national = $this->getPaliers($paliers_commission_wallets, 'bank_user_wallet_cart_national'); + $plr_bank_user_wallet_cart_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_wallet_cart_international'); + + $frais = $this->calculateFees($init_country != $final_country ? $plr_user_wallet_cart_international : $plr_user_wallet_cart_national, $request->montant); $fees = $this->getBasicTransactionFees([ 'amount' => $request->montant, - 'country_id' => $init_country, + 'country_id' => $final_country, 'payment_type' => PaymentType::CASH_IN, 'payment_method' => PaymentMethod::CARD ]); $frais += $fees; - $taxe = $this->calculateTax($taxesNationales, $frais); + $taxe = $this->calculateTax($init_country != $final_country ? $taxesInternationales : $taxesNationales, $frais); $transaction->taxe = $taxe; - + $transaction->frais = $frais; $transaction->montant_net = $montantDepot = $transaction->montant - $frais - $taxe; - $identification = Identification::with(['country'])->where('id_user', $user->id)->first(); - $customer_country_code = $identification ? Country::where('name', $identification->country)->first()?->code_country : $user->network->country->code_country; + $transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $request->final_country); + $identification = Identification::with(['country'])->where('id_user', $user->id)->first(); + $countryCurrency = CountriesCurrency::findOrFail($final_country); // PayOut through payment service $this->handlePayOut($transaction, [ 'card_no' => $user->numero_carte, 'exp_month' => date("m", strtotime($user->expiration_date)), 'exp_year' => date("Y", strtotime($user->expiration_date)), 'cvc' => $request->input('cvv'), - 'amount' => $montantDepot, - 'currency' => $this->getCurrency($init_country), + 'amount' => $transaction->montant_net_final_country, + 'currency' => $countryCurrency->currency_code, 'payment_method' => 'CARD', 'customer_id' => $user->id, 'customer_email' => $user->email, @@ -402,18 +411,17 @@ class iLinkTransactionController extends Controller 'customer_phone_number' => $user->phone, 'customer_address' => $identification ? $identification->town : $user->adresse, 'customer_city' => $identification ? $identification->town : $user->adresse, - 'customer_country' => $customer_country_code, + 'customer_country' => $countryCurrency->code_country, 'reason' => "User - Envoi de wallet à carte" ]); $walletUser->balance -= $transaction->montant; //Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission - $transaction->commission_banque = $this->calculateFees($plr_bank_user_wallet_cart_national, $request->montant, $frais); - $transaction->commission_hyp = $this->calculateFees($plr_hyp_user_wallet_cart_national, $request->montant, $frais); + $transaction->commission_banque = $this->calculateFees($init_country != $final_country ? $plr_bank_user_wallet_cart_international : $plr_bank_user_wallet_cart_national, $request->montant, $frais); + $transaction->commission_hyp = $this->calculateFees($init_country != $final_country ? $plr_hyp_user_wallet_cart_international : $plr_hyp_user_wallet_cart_national, $request->montant, $frais); $walletHyperviseur->balance_com += $transaction->commission_hyp; $transaction->id_wallet_hyp = $walletHyperviseur->id; - $transaction->frais = $frais; $walletHyperviseur->save(); $walletUser->save(); $transaction->id_transaction = $this->getTransactionID(); @@ -421,7 +429,8 @@ class iLinkTransactionController extends Controller $transaction->save(); $message = trans('messages.successful_user_send_to_cart', ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), - 'net' => $this->toMoney($montantDepot, $init_country), 'fees' => $this->toMoney($frais, $init_country), + 'net_init' => $this->toMoney($montantDepot, $init_country), 'net_final' => $this->toMoney($transaction->montant_net_final_country, $final_country), 'fees' => $this->toMoney($frais + $taxe, $init_country), + 'init_country' => $this->getCountryName($init_country), 'final_country' => $this->getCountryName($final_country), 'sender_code' => $user->user_code, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]); $this->sendMail($user->email, trans('messages.successful_transaction'), $message); $response_message = $message . trans('messages.sent_by_mail'); @@ -697,16 +706,16 @@ class iLinkTransactionController extends Controller $transaction->expiration_date = $user->expiration_date; $transaction->numero_carte = $user->numero_carte; -// $final_country = $request->input('final_country'); -// $transaction->final_country = $final_country; + $final_country = $walletUser->user->network->country->id; + $transaction->final_country = $final_country; $plr_user_cart_wallet_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_wallet_national'); -// $plr_user_cart_wallet_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_wallet_international'); + $plr_user_cart_wallet_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_wallet_international'); $plr_hyp_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'hyp_user_cart_cash_national'); -// $plr_hyp_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'hyp_user_cart_cash_international'); + $plr_hyp_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'hyp_user_cart_cash_international'); $plr_bank_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_national'); -// $plr_bank_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_international'); + $plr_bank_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_international'); - $frais = $this->calculateFees($plr_user_cart_wallet_national, $request->montant); + $frais = $this->calculateFees($init_country != $final_country ? $plr_user_cart_wallet_international : $plr_user_cart_wallet_national, $request->montant); $fees = $this->getBasicTransactionFees([ 'amount' => $request->montant, 'country_id' => $init_country, @@ -714,12 +723,14 @@ class iLinkTransactionController extends Controller 'payment_method' => PaymentMethod::CARD ]); $frais += $fees; - $taxe = $this->calculateTax($taxesNationales, $frais); + $taxe = $this->calculateTax($init_country != $final_country ? $taxesInternationales : $taxesNationales, $frais); $transaction->taxe = $taxe; - + $transaction->frais = $frais; $transaction->montant_net = $montantRetrait = $transaction->montant + ($frais + $taxe); + $transaction->montant_net_final_country = $this->toMoneyAmount($montantRetrait, $init_country, $final_country); + $identification = Identification::where('id_user', $user->id)->first(); - $customer_country_code = $identification ? Country::where('name', $identification->country)->first()?->code_country : $user->network->country->code_country; + $countryCurrency = CountriesCurrency::findOrFail($init_country); $payment_transaction_id = $request->input('payment_transaction_id'); $result = $this->handlePayIn($transaction, [ @@ -728,7 +739,7 @@ class iLinkTransactionController extends Controller 'exp_year' => date("Y", strtotime($user->expiration_date)), 'cvc' => $request->input('cvv'), 'amount' => $montantRetrait, - 'currency' => $this->getCurrency($init_country), + 'currency' => $countryCurrency->currency_code, 'payment_method' => 'CARD', 'customer_id' => $user->id, 'customer_email' => $user->email, @@ -736,7 +747,7 @@ class iLinkTransactionController extends Controller 'customer_surname' => $identification ? $identification->lastname : $user->lastname, 'customer_address' => $identification ? $identification->town : $user->adresse, 'customer_city' => $identification ? $identification->town : $user->adresse, - 'customer_country' => $customer_country_code, + 'customer_country' => $countryCurrency->code_country, 'reason' => "User - Retrait de carte vers wallet" ], $payment_transaction_id); @@ -744,14 +755,13 @@ class iLinkTransactionController extends Controller return $result; } - $transaction->commission_banque = $this->calculateFees($plr_bank_user_cart_cash_national, $request->montant, $frais); + $transaction->commission_banque = $this->calculateFees($init_country != $final_country ? $plr_bank_user_cart_cash_international : $plr_bank_user_cart_cash_national, $request->montant, $frais); //Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission - $walletUser->balance += $transaction->montant; - $transaction->commission_hyp = $this->calculateFees($plr_hyp_user_cart_cash_national, $request->montant, $frais); + $walletUser->balance += $transaction->montant_net_final_country; + $transaction->commission_hyp = $this->calculateFees($init_country != $final_country ? $plr_hyp_user_cart_cash_international : $plr_hyp_user_cart_cash_national, $request->montant, $frais); $walletHyperviseur->balance_com += $transaction->commission_hyp; $transaction->id_wallet_hyp = $walletHyperviseur->id; - $transaction->frais = $frais; $walletHyperviseur->save(); $walletUser->save(); $transaction->id_transaction = $this->getTransactionID(); @@ -759,7 +769,8 @@ class iLinkTransactionController extends Controller $transaction->save(); $message = trans('messages.successful_user_remove_from_cart_to_wallet', ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), - 'total' => $this->toMoney($montantRetrait, $init_country), 'fees' => $this->toMoney($frais, $init_country), + 'net_init' => $this->toMoney($montantRetrait, $init_country),'net_final' => $this->toMoney($transaction->montant_net_final_country, $final_country), + 'fees' => $this->toMoney($frais + $taxe, $init_country), 'init_country' => $this->getCountryName($init_country), 'final_country' => $this->getCountryName($final_country), 'sender_code' => $user->user_code, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]); $this->sendMail($user->email, trans('messages.successful_transaction'), $message); $response_message = ($message . trans('messages.sent_by_mail')); @@ -776,17 +787,17 @@ class iLinkTransactionController extends Controller $transaction->expiration_date = $user->expiration_date; $transaction->numero_carte = $user->numero_carte; - $transaction->final_country = $init_country; -// $final_country = $request->input('final_country'); -// $transaction->final_country = $final_country; - $plr_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_national'); -// $plr_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_international'); - $plr_hyp_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'hyp_user_cart_cash_national'); -// $plr_hyp_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'hyp_user_cart_cash_international'); - $plr_bank_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_national'); -// $plr_bank_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_international'); - $frais = $this->calculateFees($plr_user_cart_cash_national, $request->montant); + $final_country = $walletUser->user->network->country->id; + $transaction->final_country = $final_country; + $plr_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_national'); + $plr_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_international'); + $plr_hyp_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'hyp_user_cart_cash_national'); + $plr_hyp_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'hyp_user_cart_cash_international'); + $plr_bank_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_national'); + $plr_bank_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_international'); + + $frais = $this->calculateFees($init_country != $final_country ? $plr_user_cart_cash_international : $plr_user_cart_cash_national, $request->montant); $fees = $this->getBasicTransactionFees([ 'amount' => $request->montant, 'country_id' => $init_country, @@ -794,13 +805,14 @@ class iLinkTransactionController extends Controller 'payment_method' => PaymentMethod::CARD ]); $frais += $fees; - $taxe = $this->calculateTax($taxesNationales, $frais); + $taxe = $this->calculateTax($init_country != $final_country ? $taxesInternationales : $taxesNationales, $frais); $transaction->taxe = $taxe; + $transaction->frais = $frais; $transaction->montant_net = $montantRetrait = $transaction->montant + ($frais + $taxe); - $transaction->montant_net_final_country = $transaction->montant; + $transaction->montant_net_final_country = $this->toMoneyAmount($montantRetrait, $init_country, $final_country); + $countryCurrency = CountriesCurrency::findOrFail($init_country); $identification = Identification::where('id_user', $user->id)->first(); - $customer_country_code = $identification ? Country::where('name', $identification->country)->first()?->code_country : $user->network->country->code_country; $payment_transaction_id = $request->input('payment_transaction_id'); @@ -810,7 +822,7 @@ class iLinkTransactionController extends Controller 'exp_year' => date("Y", strtotime($user->expiration_date)), 'cvc' => $request->input('cvv'), 'amount' => $montantRetrait, - 'currency' => $this->getCurrency($init_country), + 'currency' => $countryCurrency->currency_code, 'payment_method' => 'CARD', 'customer_id' => $user->id, 'customer_email' => $user->email, @@ -818,7 +830,7 @@ class iLinkTransactionController extends Controller 'customer_surname' => $identification ? $identification->lastname : $user->lastname, 'customer_address' => $identification ? $identification->town : $user->adresse, 'customer_city' => $identification ? $identification->town : $user->adresse, - 'customer_country' => $customer_country_code, + 'customer_country' => $countryCurrency->code_country, 'reason' => "User - Retrait de carte vers cash" ], $payment_transaction_id); @@ -826,7 +838,7 @@ class iLinkTransactionController extends Controller return $result; } - $transaction->commission_banque = $this->calculateFees($plr_bank_user_cart_cash_national, $request->montant, $frais); + $transaction->commission_banque = $this->calculateFees($init_country != $final_country ? $plr_bank_user_cart_cash_international : $plr_bank_user_cart_cash_national, $request->montant, $frais); //Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission $code_retrait = $this->random_string(); @@ -834,10 +846,9 @@ class iLinkTransactionController extends Controller $transaction->encrypted_code_retrait = $hash['encrypted']; $transaction->code_retrait_salt = $hash['salt']; - $transaction->commission_hyp = $this->calculateFees($plr_hyp_user_cart_cash_national, $request->montant, $frais); + $transaction->commission_hyp = $this->calculateFees($init_country != $final_country ? $plr_hyp_user_cart_cash_international : $plr_hyp_user_cart_cash_national, $request->montant, $frais); $walletHyperviseur->balance_com += $transaction->commission_hyp; $transaction->id_wallet_hyp = $walletHyperviseur->id; - $transaction->frais = $frais; $transaction->date = $this->getCurrentTime($init_country); $transaction->status_retrait = 0; $walletHyperviseur->save(); @@ -845,8 +856,9 @@ class iLinkTransactionController extends Controller $transaction->save(); $message = trans('messages.successful_user_remove_from_cart_to_cash', ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), - 'final_country' => $this->getCountryName($init_country), 'init_country' => $this->getCountryName($init_country), - 'total' => $this->toMoney($transaction->montant, $init_country), 'fees' => $this->toMoney($frais, $init_country), 'code' => wordwrap($code_retrait, 4, ' ', true), + 'net_init' => $this->toMoney($montantRetrait, $init_country),'net_final' => $this->toMoney($transaction->montant_net_final_country, $final_country), + 'fees' => $this->toMoney($frais + $taxe, $init_country), 'init_country' => $this->getCountryName($init_country), 'final_country' => $this->getCountryName($final_country), + 'code' => wordwrap($code_retrait, 4, ' ', true), 'sender_code' => $user->user_code, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]); $this->sendMail($user->email, trans('messages.successful_transaction'), $message); $response_message = $message . trans('messages.sent_by_mail'); @@ -2134,7 +2146,12 @@ class iLinkTransactionController extends Controller } else { $walletUser = WalletsUser::findOrFail($request->id_wallet_user); - $init_country = $walletUser->user->network->country->id; + // Pour les operations à cartes, le pays initial c'est le pays de la carte + if(in_array($request->type, [10, 11])){ + $init_country = $walletUser->user->card_country_id; + }else{ + $init_country = $walletUser->user->network->country->id; + } $result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network') ->where('networks.country_id', $init_country)->where('configWallet.type', 'ilink') ->select('configWallet.id')->first(); @@ -2198,19 +2215,22 @@ class iLinkTransactionController extends Controller $data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $request->final_country); break; case 2: //User - Envoi de wallet à carte + $final_country = $walletUser->user->card_country_id; $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($plr_user_wallet_cart_national, $request->montant); + $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); $fees = $this->getBasicTransactionFees([ 'amount' => $request->montant, - 'country_id' => $init_country, + 'country_id' => $final_country, 'payment_type' => PaymentType::CASH_IN, 'payment_method' => PaymentMethod::CARD ]); $frais += $fees; - $taxe = $this->calculateTax($taxesNationales, $frais); + $taxe = $this->calculateTax($init_country != $final_country ? $taxesInternationales : $taxesNationales, $frais); $data['frais'] = round($frais + $taxe, 2); - $data['montant_net'] = round($request->montant - $data['frais'], 2); + $data['montant_net_init'] = round($request->montant - $data['frais'], 2); + $data['exchange_rate'] = $this->getExchangeRate($init_country, $final_country); + $data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $final_country); break; case 3: // User - Envoi wallet à cash $this->validate($request, [ @@ -2242,9 +2262,11 @@ class iLinkTransactionController extends Controller $data['montant_net'] = round($request->montant - $data['frais'], 2); break; case 10: //User - Retrait de carte vers wallet + $final_country = $walletUser->user->network->country->id; + $plr_user_cart_wallet_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_wallet_national'); -// $plr_user_cart_wallet_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_wallet_international'); - $frais = $this->calculateFees($plr_user_cart_wallet_national, $request->montant); + $plr_user_cart_wallet_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_wallet_international'); + $frais = $this->calculateFees($init_country != $final_country ? $plr_user_cart_wallet_international : $plr_user_cart_wallet_national, $request->montant); $fees = $this->getBasicTransactionFees([ 'amount' => $request->montant, 'country_id' => $init_country, @@ -2252,14 +2274,18 @@ class iLinkTransactionController extends Controller 'payment_method' => PaymentMethod::CARD ]); $frais += $fees; - $taxe = $this->calculateTax($taxesNationales, $frais); + $taxe = $this->calculateTax($init_country != $final_country ? $taxesInternationales : $taxesNationales, $frais); $data['frais'] = round($frais + $taxe, 2); - $data['montant_net'] = round($request->montant + $data['frais'], 2); + $data['montant_net_init'] = round($request->montant + $data['frais'], 2); + $data['exchange_rate'] = $this->getExchangeRate($init_country, $final_country); + $data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $final_country); break; case 11: // User - Retrait de carte vers cash + $final_country = $walletUser->user->network->country->id; + $plr_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_national'); -// $plr_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_international'); - $frais = $this->calculateFees($plr_user_cart_cash_national, $request->montant); + $plr_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_international'); + $frais = $this->calculateFees($init_country != $final_country ? $plr_user_cart_cash_international : $plr_user_cart_cash_national, $request->montant); $fees = $this->getBasicTransactionFees([ 'amount' => $request->montant, 'country_id' => $init_country, @@ -2267,9 +2293,11 @@ class iLinkTransactionController extends Controller 'payment_method' => PaymentMethod::CARD ]); $frais += $fees; - $taxe = $this->calculateTax($taxesNationales, $frais); + $taxe = $this->calculateTax($init_country != $final_country ? $taxesInternationales : $taxesNationales, $frais); $data['frais'] = round($frais + $taxe, 2); - $data['montant_net'] = round($request->montant + $data['frais'], 2); + $data['montant_net_init'] = round($request->montant + $data['frais'], 2); + $data['exchange_rate'] = $this->getExchangeRate($init_country, $final_country); + $data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $final_country); break; case 13: // Agent - Retrait de la carte vers cash $plr_customer_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_national'); diff --git a/app/Models/User.php b/app/Models/User.php index 2376b46..0478a91 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -22,6 +22,7 @@ use Illuminate\Database\Eloquent\Model; * @property string $user_code * @property string $numero_carte * @property Carbon $expiration_date + * * @property int|null $card_country_id * @property string $adresse * @property float $solde * @property string $encrypted_password diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index fed0ff8..256f93c 100755 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -83,14 +83,17 @@ This message was sent to the sender\'s email', 'sent_by_mail_to_recipient' => " This message was sent to the recipient's email", - 'successful_user_send_to_cart' => 'Sending money to a visa card made. -Transaction information : - - ID : :id_transaction - - Amount of the transaction : :amount - - Fees : :fees - - Net shipping amount : :net - - Issuer account :sender_code - - Card number: :cart_number', + 'successful_user_send_to_cart' => "Sending money from your account to your card +Transaction information: + - Number: :id_transaction + - Transaction amount: :amount + - Fees and taxes: :fees + - Departure country: :init_country + - Net amount: :net_init + - Sender account:: sender_code + - Country of destination: :final_country + - Recipient card number:: cart_number + - Net amount: :net_final", 'successful_user_send_to_cash' => 'Sending money from account to cash Transaction information : - Number: :id_transaction @@ -115,25 +118,29 @@ Transaction information: - Country of destination: :init_country - Issuer account : :sender_code - Withdrawal code : :code', - 'successful_user_remove_from_cart_to_wallet'=>'Withdrawing money from your card to your account + 'successful_user_remove_from_cart_to_wallet' => "Withdrawing money from your card to your account Transaction information: - - Number : :id_transaction - - Amount of the transaction : :amount - - Fees : :fees - - Total withdrawal amount : :total - - Recipient account : :sender_code - - Card number : :cart_number', - 'successful_user_remove_from_cart_to_cash' => 'Withdrawing money from your card to cash -Transaction information : - Number: :id_transaction - - Amount of the transaction: :amount - - Fees: :fees - - Country of departure: :init_country - - Total withdrawal amount: :total - - Country of destination: :init_country - - User code : :sender_code - - Card number : :cart_number - - Withdrawal code : :code', + - Amount: :amount + - Fees and taxes: :fees + - Departure country: :init_country + - Net amount: :net_init + - Card number: :cart_number + - Country of destination: :final_country + - Recipient account:: sender_code + - Net amount: :net_final", + 'successful_user_remove_from_cart_to_cash' => "Withdrawing money from your card to cash +Transaction information: + - Number: :id_transaction + - Transaction amount: :amount + - Fees and taxes: :fees + - Departure country: :init_country + - Net amount: :net_init + - Card number: :cart_number + - Country of destination: :final_country + - Net amount: :net_final, + - User code: :sender_code + - Withdrawal code: :code", 'successful_agent_remove_cash' => 'Withdrawal of money from a geolocated agent Transaction information : - Number : :id_transaction diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index 52b71e1..b922556 100755 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -65,32 +65,35 @@ Informations de la transaction : - Noms du destinataire : :receiver_name - Montant net : :net_final - Code de retrait : :code', - 'successful_user_send_to_wallet' => 'Envoi d\'argent compte à compte + 'successful_user_send_to_wallet' => "Envoi d'argent compte à compte Informations de la transaction : - Numéro : :id_transaction - Montant : :amount - - Frais et Taxes : :fees + - Frais et taxes : :fees - Pays de départ : :init_country - Compte émetteur : :sender_code - Montant net : :net_init - Pays de destination : :final_country - Réseau payeur : :network :final_country - Compte destinataire : :receiver_code - - Montant net : :net_final', + - Montant net : :net_final", 'sent_by_mail' => ' Ce message a été envoyé dans le mail de l\'émetteur', 'sent_by_mail_to_recipient' => " Ce message a été envoyé dans le mail du destinataire", - 'successful_user_send_to_cart' => 'Envoi d\'argent de votre compte vers votre carte visa + 'successful_user_send_to_cart' => "Envoi d'argent de votre compte vers votre carte Informations de la transaction : - Numéro : :id_transaction - Montant de la transaction : :amount - - Frais : :fees - - Montant net d\'envoi: :net + - Frais et taxes : :fees + - Pays de départ : :init_country + - Montant net : :net_init - Compte émetteur : :sender_code - - N︒ carte destinataire : :cart_number', + - Pays de destination : :final_country + - N︒ carte destinataire : :cart_number + - Montant net : :net_final", 'successful_user_send_to_cash' => 'Envoi d\'argent compte à cash Informations de la transaction : - Numéro : :id_transaction @@ -115,25 +118,29 @@ Informations de la transaction : - Pays de destination : :init_country - Compte émetteur : :sender_code - Code de retrait : :code', - 'successful_user_remove_from_cart_to_wallet' => 'Retrait d\'argent de votre carte vers votre compte + 'successful_user_remove_from_cart_to_wallet' => "Retrait d'argent de votre carte vers votre compte Informations de la transaction : - Numéro : :id_transaction - - Montant de la transaction : :amount - - Frais : :fees - - Montant total de retrait: :total - - Compte destinataire : :sender_code - - Numero de la carte : :cart_number', - 'successful_user_remove_from_cart_to_cash' => 'Retrait d\'argent de votre carte vers cash -Informations de la transaction : - - Numéro : :id_transaction - - Montant de la transaction : :amount - - Frais : :fees + - Montant : :amount + - Frais et taxes : :fees - Pays de départ : :init_country - - Montant total de retrait: :total + - Montant net : :net_init + - Numéro de la carte : :cart_number - Pays de destination : :final_country + - Compte destinataire : :sender_code + - Montant net : :net_final", + 'successful_user_remove_from_cart_to_cash' => "Retrait d'argent de votre carte vers cash +Informations de la transaction : + - Numéro : :id_transaction + - Montant de la transaction : :amount + - Frais et taxes : :fees + - Pays de départ : :init_country + - Montant net : :net_init + - Numéro de la carte : :cart_number + - Pays de destination : :final_country + - Montant net : :net_final, - Code utilisateur : :sender_code - - Numero de la carte : :cart_number - - Code de retrait : :code', + - Code de retrait : :code", 'successful_agent_remove_cash' => 'Retrait d\'argent chez un agent géolocalisé Informations de la transaction : - Numéro : :id_transaction