From 03ea53764db953eec8bd71e458137cffeb2f160d Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Mon, 9 Oct 2023 10:12:47 +0100 Subject: [PATCH] fix: wrong displayed amounts while doing transaction User by card --- .../iLinkTransactionController.php | 32 +++--- ..._080906_set_town_id_nullable_in_agents.php | 32 ++++++ ...hange_rate_to_walleti_link_transaction.php | 32 ++++++ ...59_update_infos_ilink_transaction_view.php | 103 ++++++++++++++++++ resources/lang/en/messages.php | 8 +- resources/lang/fr/messages.php | 8 +- 6 files changed, 191 insertions(+), 24 deletions(-) create mode 100644 database/migrations/2023_10_02_080906_set_town_id_nullable_in_agents.php create mode 100644 database/migrations/2023_10_09_081356_add_exchange_rate_to_walleti_link_transaction.php create mode 100644 database/migrations/2023_10_09_090659_update_infos_ilink_transaction_view.php diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index de2ca1b..2dc98be 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -760,9 +760,9 @@ class iLinkTransactionController extends Controller $taxe = $this->calculateTax($init_country != $final_country ? $taxesInternationales : $taxesNationales, $frais); $transaction->taxe = $taxe; $transaction->frais = $frais; - $montantRetrait = $transaction->montant + ($frais + $taxe); - $transaction->montant_net = $this->toMoneyAmount($transaction->montant, $init_country, $final_country); - $transaction->montant_net_final_country = $this->toMoneyAmount($montantRetrait, $init_country, $final_country); + $transaction->montant_net = $transaction->montant + ($frais + $taxe); // Montant de retrait + $transaction->montant_net_final_country = $this->toMoneyAmount($transaction->montant, $init_country, $final_country); + $transaction->exchange_rate = $this->getExchangeRate($init_country, $final_country); $identification = Identification::where('id_user', $user->id)->first(); $countryCurrency = CountriesCurrency::findOrFail($init_country); @@ -773,7 +773,7 @@ class iLinkTransactionController extends Controller 'exp_month' => date("m", strtotime($user->expiration_date)), 'exp_year' => date("Y", strtotime($user->expiration_date)), 'cvc' => $request->input('cvv'), - 'amount' => $transaction->montant_net_final_country, + 'amount' => $this->toMoneyAmount($transaction->montant_net, $init_country, $final_country), 'currency' => $countryCurrency->currency_code, 'payment_method' => 'CARD', 'customer_id' => $user->id, @@ -804,7 +804,7 @@ 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), - 'net_init' => $this->toMoney($transaction->montant, $init_country),'net_final' => $this->toMoney($transaction->montant_net_final_country, $final_country), + 'net_init' => $this->toMoney($transaction->montant_net, $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); @@ -843,9 +843,9 @@ class iLinkTransactionController extends Controller $taxe = $this->calculateTax($init_country != $final_country ? $taxesInternationales : $taxesNationales, $frais); $transaction->taxe = $taxe; $transaction->frais = $frais; - $montantRetrait = $transaction->montant + ($frais + $taxe); - $transaction->montant_net = $this->toMoneyAmount($transaction->montant, $init_country, $final_country); - $transaction->montant_net_final_country = $this->toMoneyAmount($montantRetrait, $init_country, $final_country); + $transaction->montant_net = $transaction->montant + ($frais + $taxe); // Montant de retrait + $transaction->montant_net_final_country = $this->toMoneyAmount($transaction->montant, $init_country, $final_country); + $transaction->exchange_rate = $this->getExchangeRate($init_country, $final_country); $countryCurrency = CountriesCurrency::findOrFail($init_country); $identification = Identification::where('id_user', $user->id)->first(); @@ -857,7 +857,7 @@ class iLinkTransactionController extends Controller 'exp_month' => date("m", strtotime($user->expiration_date)), 'exp_year' => date("Y", strtotime($user->expiration_date)), 'cvc' => $request->input('cvv'), - 'amount' => $transaction->montant_net_final_country, + 'amount' => $this->toMoneyAmount($transaction->montant_net, $init_country, $final_country), 'currency' => $countryCurrency->currency_code, 'payment_method' => 'CARD', 'customer_id' => $user->id, @@ -922,7 +922,7 @@ class iLinkTransactionController extends Controller if ($init_country != $transaction->final_country) throw new Exception(trans('errors.operation_cannot_performed_in_country')); if ($this->checkPassword($request->code_retrait, $transaction->encrypted_code_retrait, $transaction->code_retrait_salt)) { - $montantNet = $transaction->type == 11 ? $transaction->montant_net : $transaction->montant_net_final_country; + $montantNet = $transaction->montant_net_final_country; if (in_array($transaction->type, [3, 17])) { $commissionHyp = ($transaction->network_emetteur != $transaction->network_destinataire) ? $transaction->part_reseau_payeur_final_country : $transaction->commission_hyp_final_country; @@ -2144,7 +2144,7 @@ class iLinkTransactionController extends Controller $wallet_user = WalletsUser::where('idUser', $user->id)->firstOrFail(); $transactions = DB::select('SELECT id_wallet_user , operation_fr , operation_en, id_transaction ,network_destinataire, init_country , final_country, date , id , montant , frais , taxe , pays_init , pays_final, - destinataire_phone , destinataire_name , nom_destinataire, prenom_destinataire, montant_net ,montant_net_final_country FROM infos_ilink_transaction WHERE id_wallet_user = :id_wallet AND type <> 12 AND type <> 14 + destinataire_phone , destinataire_name , nom_destinataire, prenom_destinataire, montant_net ,montant_net_final_country, exchange_rate FROM infos_ilink_transaction WHERE id_wallet_user = :id_wallet AND type <> 12 AND type <> 14 ORDER BY date DESC LIMIT 10;', ['id_wallet' => $wallet_user->id]); foreach ($transactions as $data) { @@ -2378,9 +2378,9 @@ class iLinkTransactionController extends Controller $frais += $fees; $taxe = $this->calculateTax($init_country != $final_country ? $taxesInternationales : $taxesNationales, $frais); $data['frais'] = round($frais + $taxe, 2); - $data['montant_net_init'] = $request->montant; + $data['montant_net_init'] = $request->montant + $data['frais']; $data['exchange_rate'] = $this->getExchangeRate($init_country, $final_country); - $data['montant_net_final'] = $this->toMoneyWithCurrency(round($request->montant + $data['frais'], 2), $init_country, $final_country); + $data['montant_net_final'] = $this->toMoneyWithCurrency(round($request->montant, 2), $init_country, $final_country); break; case 11: // User - Retrait de carte vers cash $final_country = $walletUser->user->network->country->id; @@ -2397,9 +2397,9 @@ class iLinkTransactionController extends Controller $frais += $fees; $taxe = $this->calculateTax($init_country != $final_country ? $taxesInternationales : $taxesNationales, $frais); $data['frais'] = round($frais + $taxe, 2); - $data['montant_net_init'] = $request->montant; + $data['montant_net_init'] = $request->montant + $data['frais']; $data['exchange_rate'] = $this->getExchangeRate($init_country, $final_country); - $data['montant_net_final'] = $this->toMoneyWithCurrency(round($request->montant + $data['frais'], 2), $init_country, $final_country); + $data['montant_net_final'] = $this->toMoneyWithCurrency(round($request->montant, 2), $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'); @@ -2609,7 +2609,7 @@ class iLinkTransactionController extends Controller $data->id_document_destinataire = $identification->id_identity_document; // $data->user_code = $transaction->wallet_user->user->user_code; } - $data->montant = $transaction->type == 11 ? $transaction->montant_net : $transaction->montant_net_final_country; + $data->montant = $transaction->montant_net_final_country; unset($data->type, $data->init_country, $data->final_country, $data->id_wallet_user, $data->network_destinataire, $data->code_retrait_salt, $data->encrypted_code_retrait, $data->montant_net_final_country, $data->montant_net); diff --git a/database/migrations/2023_10_02_080906_set_town_id_nullable_in_agents.php b/database/migrations/2023_10_02_080906_set_town_id_nullable_in_agents.php new file mode 100644 index 0000000..84637e4 --- /dev/null +++ b/database/migrations/2023_10_02_080906_set_town_id_nullable_in_agents.php @@ -0,0 +1,32 @@ +integer('town_id')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('agents', function (Blueprint $table) { + + }); + } +} diff --git a/database/migrations/2023_10_09_081356_add_exchange_rate_to_walleti_link_transaction.php b/database/migrations/2023_10_09_081356_add_exchange_rate_to_walleti_link_transaction.php new file mode 100644 index 0000000..066176c --- /dev/null +++ b/database/migrations/2023_10_09_081356_add_exchange_rate_to_walleti_link_transaction.php @@ -0,0 +1,32 @@ +string('exchange_rate')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('wallet_ilink_transaction', function (Blueprint $table) { + $table->dropColumn('exchange_rate'); + }); + } +} diff --git a/database/migrations/2023_10_09_090659_update_infos_ilink_transaction_view.php b/database/migrations/2023_10_09_090659_update_infos_ilink_transaction_view.php new file mode 100644 index 0000000..aa6123d --- /dev/null +++ b/database/migrations/2023_10_09_090659_update_infos_ilink_transaction_view.php @@ -0,0 +1,103 @@ +