Price in account of commissions during ilink transactions

This commit is contained in:
Djery-Tom 2022-04-20 17:03:13 +01:00
parent 0bc3eaf856
commit 26e7f909c9
6 changed files with 213 additions and 80 deletions

View File

@ -8,7 +8,6 @@ use App\Models\User;
use App\Models\UsersBankingAccountVerification;
use App\Models\WalletAgent;
use App\Models\WalletsUser;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
@ -526,7 +525,7 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
'iban' => 'required',
'id_bank' => 'required|integer|min:0|not_in:0',
'id_wallet_network' => 'required|integer|min:0|not_in:0',
'id_user' => 'required|integer|min:0|not_in:0',
'id_user' => 'required|integer|exists:users,id',
]);
$user = User::findOrFail($request->id_user);
@ -536,8 +535,6 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
//Verifier si l'utilisateur est identifié
$identification = $this->checkUserIdentification($user->id);
if ($identification instanceof JsonResponse)
return $identification;
//Verifier si la banque est associée au reseau
$network_bank = NetworksOperator::where('id_network', $request->id_wallet_network)->where('id_operator_country', $request->id_bank)->first();
@ -570,7 +567,9 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
// Envoyer une requete vers la banque contant ses informations personnelles pour verfication du code iban
Log::info('-------------------------- User - Rattacher le compte bancaire au wallet ------------------------------------');
Log::info(array_merge($request->toArray(), $identification->toArray(), ['id_transaction' => $user_banking_account_verif->id_transaction]));
Log::info(json_encode(
array_merge($request->toArray(), $identification->toArray(), ['id_transaction' => $user_banking_account_verif->id_transaction])
));
Log::info('------------------------------------------------------------------------------------------------');
return $this->successResponse(trans('messages.successful_bank_account_attachment_taken'));

View File

@ -175,8 +175,7 @@ class iLinkTransactionController extends Controller
$wallet_agent_sup = WalletAgent::where('agent_id', $superviseur->id)->firstOrFail();
$wallet_agent_hyp = WalletAgent::where('agent_id', $hyperviseur->id)->firstOrFail();
$walletSuperviseur = Wallet::findOrFail($wallet_agent_sup->wallet_id);
$walletHyperviseur = Wallet::findOrFail($wallet_agent_hyp->wallet_id);
} elseif (isset($id_wallet_user)) {
} else {
$walletUser = WalletsUser::findOrFail($id_wallet_user);
$transaction->init_country = $init_country = $walletUser->user->network->country->id;
$result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network')
@ -190,8 +189,8 @@ class iLinkTransactionController extends Controller
$hyperviseur = AgentPlus::where('category', 'hyper')->where('network_id', $config->id_network)->firstOrFail();
$wallet_agent_hyp = WalletAgent::where('agent_id', $hyperviseur->id)->firstOrFail();
$walletHyperviseur = Wallet::findOrFail($wallet_agent_hyp->wallet_id);
}
$walletHyperviseur = Wallet::findOrFail($wallet_agent_hyp->wallet_id);
$transaction->network_emetteur = $config->id_network;
$taxesNationales = array_values(array_filter($config->taxes->all(), function ($tax) {
@ -341,7 +340,17 @@ class iLinkTransactionController extends Controller
$transaction->expiration_date = $user->expiration_date;
$transaction->numero_carte = $user->numero_carte;
$frais = $request->montant * $config->taux_com_user_wallet_carte / 100;
$final_country = $request->input('final_country');
$transaction->final_country = $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');
$frais = ($init_country != $final_country) ? $this->calculateFees($plr_user_wallet_cart_international, $request->montant) : $this->calculateFees($plr_user_wallet_cart_national, $request->montant);
$transaction->montant_net = $montantDepot = $transaction->montant - $frais;
// $body['amount'] = $this->toUSDAmount($montantDepot, $init_country);
$body['card_number'] = $user->numero_carte;
@ -364,9 +373,9 @@ class iLinkTransactionController extends Controller
$walletUser->balance -= $transaction->montant;
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
$transaction->commission_banque = $frais * $config->taux_com_banque_envoi_wallet_carte_ilink / 100;
$transaction->commission_banque = ($init_country != $final_country) ? $this->calculateFees($plr_bank_user_wallet_cart_national, $request->montant, $frais) : $this->calculateFees($plr_bank_user_wallet_cart_international, $request->montant, $frais);
$transaction->commission_hyp = ($init_country != $final_country) ? $this->calculateFees($plr_hyp_user_wallet_cart_national, $request->montant, $frais) : $this->calculateFees($plr_hyp_user_wallet_cart_international, $request->montant, $frais);
$transaction->commission_hyp = $frais * $config->taux_com_hyp_envoi_wallet_carte_ilink / 100;
$walletHyperviseur->balance_com += $transaction->commission_hyp;
$transaction->id_wallet_hyp = $walletHyperviseur->id;
$transaction->frais = $frais;
@ -631,7 +640,16 @@ class iLinkTransactionController extends Controller
$transaction->expiration_date = $user->expiration_date;
$transaction->numero_carte = $user->numero_carte;
$frais = $request->montant * $config->taux_com_user_carte_wallet / 100;
$final_country = $request->input('final_country');
$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_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 = ($init_country != $final_country) ? $this->calculateFees($plr_user_cart_wallet_international, $request->montant) : $this->calculateFees($plr_user_cart_wallet_national, $request->montant);
$transaction->montant_net = $montantRetrait = $transaction->montant + $frais;
// $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country);
@ -653,11 +671,11 @@ class iLinkTransactionController extends Controller
$response = json_decode($response->getBody()->getContents(), true)["response"];
$transaction->pspReference = $response["pspReference"];
$transaction->commission_banque = $commissionBanque = $frais * $config->taux_com_banque_retrait_carte_cash_ilink / 100;
$transaction->commission_banque = ($init_country != $final_country) ? $this->calculateFees($plr_bank_user_cart_cash_international, $request->montant, $frais) : $this->calculateFees($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 = $frais * $config->taux_com_hyp_retrait_carte_cash_ilink / 100;
$transaction->commission_hyp = ($init_country != $final_country) ? $this->calculateFees($plr_hyp_user_cart_cash_national, $request->montant, $frais) : $this->calculateFees($plr_hyp_user_cart_cash_international, $request->montant, $frais);
$walletHyperviseur->balance_com += $transaction->commission_hyp;
$transaction->id_wallet_hyp = $walletHyperviseur->id;
$transaction->frais = $frais;
@ -688,9 +706,18 @@ class iLinkTransactionController extends Controller
$transaction->expiration_date = $user->expiration_date;
$transaction->numero_carte = $user->numero_carte;
$transaction->final_country = $init_country;
// $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 = ($init_country != $final_country) ? $this->calculateFees($plr_user_cart_cash_international, $request->montant) : $this->calculateFees($plr_user_cart_cash_national, $request->montant);
$frais = $request->montant * $config->taux_com_user_carte_cash / 100;
$transaction->montant_net = $montantRetrait = $transaction->montant + $frais;
$transaction->montant_net_final_country = $transaction->montant;
// $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country);
@ -711,7 +738,7 @@ class iLinkTransactionController extends Controller
$response = json_decode($response->getBody()->getContents(), true)["response"];
$transaction->pspReference = $response["pspReference"];
$transaction->commission_banque = $commissionBanque = $frais * $config->taux_com_banque_retrait_carte_cash_ilink / 100;
$transaction->commission_banque = ($init_country != $final_country) ? $this->calculateFees($plr_bank_user_cart_cash_international, $request->montant, $frais) : $this->calculateFees($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();
@ -719,7 +746,7 @@ class iLinkTransactionController extends Controller
$transaction->encrypted_code_retrait = $hash['encrypted'];
$transaction->code_retrait_salt = $hash['salt'];
$transaction->commission_hyp = $frais * $config->taux_com_hyp_retrait_carte_cash_ilink / 100;
$transaction->commission_hyp = ($init_country != $final_country) ? $this->calculateFees($plr_hyp_user_cart_cash_national, $request->montant, $frais) : $this->calculateFees($plr_hyp_user_cart_cash_international, $request->montant, $frais);
$walletHyperviseur->balance_com += $transaction->commission_hyp;
$transaction->id_wallet_hyp = $walletHyperviseur->id;
$transaction->frais = $frais;
@ -779,9 +806,26 @@ class iLinkTransactionController extends Controller
$emetteur = $transaction->wallet_user ? $transaction->wallet_user->user->lastname . ' ' . $transaction->wallet_user->user->firstname : $transaction->prenom_emetteur . ' ' . $transaction->nom_emetteur;
$destinataire = in_array($transaction->type, [9, 11]) ? $emetteur : $transaction->prenom_destinataire . ' ' . $transaction->nom_destinataire;
$transactionRetrait->commission_ag = floatval($commissionHyp * $config->taux_com_ag_retrait_cash / 100);
$transactionRetrait->commission_sup = floatval($commissionHyp * $config->taux_com_sup_retrait_cash / 100);
$transactionRetrait->commission_hyp = $commissionHyp - $transactionRetrait->commission_ag - $transactionRetrait->commission_sup;
// $transactionRetrait->commission_ag = floatval($commissionHyp * $config->taux_com_ag_retrait_cash / 100);
// $transactionRetrait->commission_sup = floatval($commissionHyp * $config->taux_com_sup_retrait_cash / 100);
// $transactionRetrait->commission_hyp = $commissionHyp - $transactionRetrait->commission_ag - $transactionRetrait->commission_sup;
// Commissions
$final_country = $transaction->final_country;
$plr_agent_wallet_cash_national = $this->getPaliers($paliers_commission_wallets, 'agent_wallet_cash_national');
$plr_agent_wallet_cash_international = $this->getPaliers($paliers_commission_wallets, 'agent_wallet_cash_international');
$plr_sup_wallet_cash_national = $this->getPaliers($paliers_commission_wallets, 'sup_wallet_cash_national');
$plr_sup_wallet_cash_international = $this->getPaliers($paliers_commission_wallets, 'sup_wallet_cash_international');
$plr_customer_wallet_cash_national = $this->getPaliers($paliers_commission_wallets, 'customer_wallet_cash_national');
$plr_customer_wallet_cash_international = $this->getPaliers($paliers_commission_wallets, 'customer_wallet_cash_international');
//TODO commission client
$commission_customer = ($init_country != $final_country) ? $this->calculateFees($plr_customer_wallet_cash_international, $request->montant) : $this->calculateFees($plr_customer_wallet_cash_national, $request->montant);
$transactionRetrait->commission_ag = ($init_country != $final_country) ? $this->calculateFees($plr_agent_wallet_cash_international, $request->montant) : $this->calculateFees($plr_agent_wallet_cash_national, $request->montant);
$transactionRetrait->commission_sup = ($init_country != $final_country) ? $this->calculateFees($plr_sup_wallet_cash_international, $request->montant, $transactionRetrait->commission_ag) : $this->calculateFees($plr_sup_wallet_cash_national, $request->montant, $transactionRetrait->commission_ag);
$transactionRetrait->commission_hyp = $commission_customer - $transactionRetrait->commission_ag - $transactionRetrait->commission_sup;
$montantNet -= $commission_customer;
$walletAgent->balance_princ += $montantNet;
$walletAgent->balance_com += $transactionRetrait->commission_ag;
$walletSuperviseur->balance_com += $transactionRetrait->commission_sup;
@ -831,9 +875,21 @@ class iLinkTransactionController extends Controller
if (!$expiration_date)
$expiration_date = new DateTime();
$transaction->expiration_date = $expiration_date;
$transaction->final_country = $init_country;
$transaction->final_country = $request->final_country;
$frais = floatval($request->montant * $config->taux_com_wallet_ag_carte_cash / 100);
$final_country = $request->final_country;
$plr_customer_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_national');
$plr_customer_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_international');
$plr_agent_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'agent_cart_cash_national');
$plr_agent_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'agent_cart_cash_international');
$plr_sup_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'sup_cart_cash_national');
$plr_sup_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'sup_cart_cash_international');
$plr_hyp_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'hyp_cart_cash_national');
$plr_hyp_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'hyp_cart_cash_international');
$plr_bank_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'bank_cart_cash_national');
$plr_bank_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_cart_cash_international');
$frais = ($init_country != $final_country) ? $this->calculateFees($plr_customer_cart_cash_international, $request->montant) : $this->calculateFees($plr_customer_cart_cash_national, $request->montant);
$montantRetrait = $transaction->montant + $frais;
$transaction->montant_net = $montantRetrait;
// $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country);
@ -853,7 +909,7 @@ class iLinkTransactionController extends Controller
$response = json_decode($response->getBody()->getContents(), true)["response"];
$transaction->pspReference = $response["pspReference"];
$banqueCommission = floatval($frais * $config->taux_com_banque_retrait_carte_cash / 100);
$banqueCommission = ($init_country != $final_country) ? $this->calculateFees($plr_bank_cart_cash_international, $request->montant, $frais) : $this->calculateFees($plr_bank_cart_cash_national, $request->montant, $frais);
$transaction->commission_banque = $banqueCommission;
// 2---> Emmètre via API sécurisé SSL une requête de débit de notre
//compte marchand du (Part de la banque partenaire en %
@ -863,9 +919,9 @@ class iLinkTransactionController extends Controller
$walletAgent->balance_princ += $transaction->montant;
$agentCommission = floatval($frais * $config->taux_com_ag_retrait_carte_cash / 100);
$superviseurCommission = floatval($frais * $config->taux_com_sup_retrait_carte_cash / 100);
$hyperviseurCommission = floatval($frais * $config->taux_com_hyp_retrait_carte_cash / 100);
$agentCommission = ($init_country != $final_country) ? $this->calculateFees($plr_agent_cart_cash_international, $request->montant, $frais) : $this->calculateFees($plr_agent_cart_cash_national, $request->montant, $frais);
$superviseurCommission = ($init_country != $final_country) ? $this->calculateFees($plr_sup_cart_cash_international, $request->montant, $frais) : $this->calculateFees($plr_sup_cart_cash_national, $request->montant, $frais);
$hyperviseurCommission = ($init_country != $final_country) ? $this->calculateFees($plr_hyp_cart_cash_international, $request->montant, $frais) : $this->calculateFees($plr_hyp_cart_cash_national, $request->montant, $frais);
$walletAgent->balance_com += $agentCommission;
$transaction->commission_ag = $agentCommission;
@ -913,9 +969,15 @@ class iLinkTransactionController extends Controller
$transaction->montant_net = $montantDepot;
$transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $final_country);
$walletUser->balance += $transaction->montant_net_final_country;
$commisionAgent = floatval($frais * $config->taux_com_ag_envoi_cash / 100);
$commisionSuper = floatval($frais * $config->taux_com_sup_envoi_cash / 100);
$commisionHyper = floatval($frais * $config->taux_com_hyp_envoi_cash / 100);
$plr_agent_cash_wallet_or_cash_national = $this->getPaliers($paliers_commission_wallets, 'agent_cash_wallet_or_cash_national');
$plr_agent_cash_wallet_or_cash_international = $this->getPaliers($paliers_commission_wallets, 'agent_cash_wallet_or_cash_international');
$plr_sup_cash_wallet_or_cash_national = $this->getPaliers($paliers_commission_wallets, 'sup_cash_wallet_or_cash_national');
$plr_sup_cash_wallet_or_cash_international = $this->getPaliers($paliers_commission_wallets, 'sup_cash_wallet_or_cash_international');
$commisionAgent = ($init_country != $final_country) ? $this->calculateFees($plr_agent_cash_wallet_or_cash_international, $request->montant) : $this->calculateFees($plr_agent_cash_wallet_or_cash_national, $request->montant);
$commisionSuper = ($init_country != $final_country) ? $this->calculateFees($plr_sup_cash_wallet_or_cash_international, $request->montant, $commisionAgent) : $this->calculateFees($plr_sup_cash_wallet_or_cash_national, $request->montant, $commisionAgent);
$commisionHyper = $frais - $commisionAgent - $commisionSuper;
$walletAgent->balance_princ -= $transaction->montant;
$walletAgent->balance_com += $commisionAgent;
@ -973,9 +1035,17 @@ class iLinkTransactionController extends Controller
//Emettre une trame securise pour crediter le wallet utilisateur
// $walletUser->balance += $transaction->montant_net_final_country;
// $transaction->id_destinataire = r
$commisionAgent = floatval($transaction->part_reseau_emetteur * $config->taux_com_ag_envoi_cash / 100);
$commisionSuper = floatval($transaction->part_reseau_emetteur * $config->taux_com_sup_envoi_cash / 100);
$commisionHyper = floatval($transaction->part_reseau_emetteur * $config->taux_com_hyp_envoi_cash / 100);
$final_country = $request->final_country;
$plr_agent_cash_wallet_or_cash_national = $this->getPaliers($paliers_commission_wallets, 'agent_cash_wallet_or_cash_national');
$plr_agent_cash_wallet_or_cash_international = $this->getPaliers($paliers_commission_wallets, 'agent_cash_wallet_or_cash_international');
$plr_sup_cash_wallet_or_cash_national = $this->getPaliers($paliers_commission_wallets, 'sup_cash_wallet_or_cash_national');
$plr_sup_cash_wallet_or_cash_international = $this->getPaliers($paliers_commission_wallets, 'sup_cash_wallet_or_cash_international');
$commisionAgent = ($init_country != $final_country) ? $this->calculateFees($plr_agent_cash_wallet_or_cash_international, $request->montant) : $this->calculateFees($plr_agent_cash_wallet_or_cash_national, $request->montant);
$commisionSuper = ($init_country != $final_country) ? $this->calculateFees($plr_sup_cash_wallet_or_cash_international, $request->montant, $commisionAgent) : $this->calculateFees($plr_sup_cash_wallet_or_cash_national, $request->montant, $commisionAgent);
$commisionHyper = $transaction->part_reseau_emetteur - $commisionAgent - $commisionSuper;
$walletAgent->balance_princ -= $transaction->montant;
$walletAgent->balance_com += $commisionAgent;
$transaction->commission_ag = $commisionAgent;
@ -1015,9 +1085,22 @@ class iLinkTransactionController extends Controller
if (!$expiration_date)
$expiration_date = new DateTime();
$transaction->expiration_date = $expiration_date;
$transaction->final_country = $init_country;
$transaction->final_country = $request->final_country;
$final_country = $request->final_country;
$plr_customer_cash_cart_national = $this->getPaliers($paliers_commission_wallets, 'customer_cash_cart_national');
$plr_customer_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'customer_cash_cart_international');
$plr_agent_cash_cart_national = $this->getPaliers($paliers_commission_wallets, 'agent_cash_cart_national');
$plr_agent_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'agent_cash_cart_international');
$plr_sup_cash_cart_national = $this->getPaliers($paliers_commission_wallets, 'sup_cash_cart_national');
$plr_sup_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'sup_cash_cart_international');
$plr_hyp_cash_cart_national = $this->getPaliers($paliers_commission_wallets, 'hyp_cash_cart_national');
$plr_hyp_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'hyp_cash_cart_international');
$plr_bank_cash_cart_national = $this->getPaliers($paliers_commission_wallets, 'bank_cash_cart_national');
$plr_bank_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'bank_cash_cart_international');
$frais = ($init_country != $final_country) ? $this->calculateFees($plr_customer_cash_cart_international, $request->montant) : $this->calculateFees($plr_customer_cash_cart_national, $request->montant);
$frais = $request->montant * $config->taux_com_wallet_ag_envoi_cash_carte / 100;
$montantDepot = $transaction->montant - $frais;
$transaction->montant_net = $montantDepot;
// $body['amount'] = $this->toUSDAmount($montantDepot, $init_country);;
@ -1038,7 +1121,7 @@ class iLinkTransactionController extends Controller
$response = json_decode($response->getBody()->getContents(), true)["response"];
$transaction->pspReference = $response["pspReference"];
$banqueCommission = floatval($frais * $config->taux_com_banque_depot_cash_carte / 100);
$banqueCommission = ($init_country != $final_country) ? $this->calculateFees($plr_bank_cash_cart_international, $request->montant, $frais) : $this->calculateFees($plr_bank_cash_cart_national, $request->montant, $frais);
$transaction->commission_banque = $banqueCommission;
// 2---> Emmètre via API sécurisé SSL une requête de débit de notre
//compte marchand du (Part de la banque partenaire en %
@ -1048,9 +1131,9 @@ class iLinkTransactionController extends Controller
$walletAgent->balance_princ -= $transaction->montant;
$agentCommission = floatval($frais * $config->taux_com_ag_depot_cash_carte / 100);
$superviseurCommission = floatval($frais * $config->taux_com_sup_depot_cash_carte / 100);
$hyperviseurCommission = floatval($frais * $config->taux_com_hyp_depot_cash_carte / 100);
$agentCommission = ($init_country != $final_country) ? $this->calculateFees($plr_agent_cash_cart_international, $request->montant, $frais) : $this->calculateFees($plr_agent_cash_cart_national, $request->montant, $frais);
$superviseurCommission = ($init_country != $final_country) ? $this->calculateFees($plr_sup_cash_cart_international, $request->montant, $frais) : $this->calculateFees($plr_sup_cash_cart_national, $request->montant, $frais);
$hyperviseurCommission = ($init_country != $final_country) ? $this->calculateFees($plr_hyp_cash_cart_international, $request->montant, $frais) : $this->calculateFees($plr_hyp_cash_cart_national, $request->montant, $frais);
$walletAgent->balance_com += $agentCommission;
$transaction->commission_ag = $agentCommission;
@ -1103,9 +1186,15 @@ class iLinkTransactionController extends Controller
$transaction->part_reseau_emetteur = $frais;
}
$commisionAgent = floatval($transaction->part_reseau_emetteur * $config->taux_com_ag_envoi_cash / 100);
$commisionSuper = floatval($transaction->part_reseau_emetteur * $config->taux_com_sup_envoi_cash / 100);
$commisionHyper = floatval($transaction->part_reseau_emetteur * $config->taux_com_hyp_envoi_cash / 100);
$final_country = $request->final_country;
$plr_agent_cash_wallet_or_cash_national = $this->getPaliers($paliers_commission_wallets, 'agent_cash_wallet_or_cash_national');
$plr_agent_cash_wallet_or_cash_international = $this->getPaliers($paliers_commission_wallets, 'agent_cash_wallet_or_cash_international');
$plr_sup_cash_wallet_or_cash_national = $this->getPaliers($paliers_commission_wallets, 'sup_cash_wallet_or_cash_national');
$plr_sup_cash_wallet_or_cash_international = $this->getPaliers($paliers_commission_wallets, 'sup_cash_wallet_or_cash_international');
$commisionAgent = ($init_country != $final_country) ? $this->calculateFees($plr_agent_cash_wallet_or_cash_international, $request->montant) : $this->calculateFees($plr_agent_cash_wallet_or_cash_national, $request->montant);
$commisionSuper = ($init_country != $final_country) ? $this->calculateFees($plr_sup_cash_wallet_or_cash_international, $request->montant, $commisionAgent) : $this->calculateFees($plr_sup_cash_wallet_or_cash_national, $request->montant, $commisionAgent);
$commisionHyper = $transaction->part_reseau_emetteur - $commisionAgent - $commisionSuper;
$transaction->id_transaction = $this->getTransactionID();
if ($configPayeur->type == 'ilink') {
@ -1643,22 +1732,24 @@ class iLinkTransactionController extends Controller
return $tax->destination == 'international' && $tax->categorie == 'wallet';
}));
$paliers_config_wallets = $config->paliers_config_wallets->all();
$paliers_commission_wallets = $config->paliers_commissions_wallets->all();
$plr_user_wallet_wallet = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_wallet_international");
$plr_user_wallet_cash = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_cash_international");
$plr_agent_depot_wallet_ilink = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_wallet_ilink_international");
$plr_agent_depot_autre_wallet = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_autre_wallet_international");
$plr_agent_cash_cash = $this->getPaliers($config->paliers_config_wallets->all(), "agent_cash_cash_international");
$plr_user_wallet_wallet = $this->getPaliers($paliers_config_wallets, "user_wallet_wallet_international");
$plr_user_wallet_cash = $this->getPaliers($paliers_config_wallets, "user_wallet_cash_international");
$plr_agent_depot_wallet_ilink = $this->getPaliers($paliers_config_wallets, "agent_depot_wallet_ilink_international");
$plr_agent_depot_autre_wallet = $this->getPaliers($paliers_config_wallets, "agent_depot_autre_wallet_international");
$plr_agent_cash_cash = $this->getPaliers($paliers_config_wallets, "agent_cash_cash_international");
$plr_user_wallet_wallet_national = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_wallet_national");
$plr_user_wallet_cash_national = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_cash_national");
$plr_agent_depot_wallet_ilink_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_wallet_ilink_national");
$plr_agent_depot_autre_wallet_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_autre_wallet_national");
$plr_agent_cash_cash_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_cash_cash_national");
$plr_user_wallet_wallet_national = $this->getPaliers($paliers_config_wallets, "user_wallet_wallet_national");
$plr_user_wallet_cash_national = $this->getPaliers($paliers_config_wallets, "user_wallet_cash_national");
$plr_agent_depot_wallet_ilink_national = $this->getPaliers($paliers_config_wallets, "agent_depot_wallet_ilink_national");
$plr_agent_depot_autre_wallet_national = $this->getPaliers($paliers_config_wallets, "agent_depot_autre_wallet_national");
$plr_agent_cash_cash_national = $this->getPaliers($paliers_config_wallets, "agent_cash_cash_national");
switch ($request->type) {
case 1: //User - Envoi wallet à wallet
$this->validate($request, [
'final_country' => 'required|integer|min:0|not_in:0',
'final_country' => 'required|integer|exists:countries,id',
'id_destinataire' => 'required_without:phone_destinataire',
'network_destinataire' => 'required|integer|min:0|not_in:0',
]);
@ -1677,7 +1768,13 @@ 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
$frais = $request->montant * $config->taux_com_user_wallet_carte / 100;
$this->validate($request, [
'final_country' => 'required|integer|exists:countries,id'
]);
$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');
$frais = ($init_country != $final_country) ? $this->calculateFees($plr_user_wallet_cart_international, $request->montant) : $this->calculateFees($plr_user_wallet_cart_national, $request->montant);
$data['frais'] = round($frais, 2);
$data['montant_net'] = round($request->montant - $data['frais'], 2);
break;
@ -1698,17 +1795,35 @@ class iLinkTransactionController extends Controller
$data['montant_net'] = round($request->montant - $data['frais'], 2);
break;
case 10: //User - Retrait de carte vers wallet
$frais = $request->montant * $config->taux_com_user_carte_wallet / 100;;
$this->validate($request, [
'final_country' => 'required|integer|exists:countries,id'
]);
$final_country = $request->input('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');
$frais = ($init_country != $final_country) ? $this->calculateFees($plr_user_cart_wallet_international, $request->montant) : $this->calculateFees($plr_user_cart_wallet_national, $request->montant);
$data['frais'] = round($frais, 2);
$data['montant_net'] = round($request->montant + $data['frais'], 2);
break;
case 11: // User - Retrait de carte vers cash
$frais = $request->montant * $config->taux_com_user_carte_cash / 100;
$this->validate($request, [
'final_country' => 'required|integer|exists:countries,id'
]);
$final_country = $request->input('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');
$frais = ($init_country != $final_country) ? $this->calculateFees($plr_user_cart_cash_international, $request->montant) : $this->calculateFees($plr_user_cart_cash_national, $request->montant);
$data['frais'] = round($frais, 2);
$data['montant_net'] = round($request->montant + $data['frais'], 2);
break;
case 13: // Agent - Retrait de la carte vers cash
$frais = $request->montant * $config->taux_com_wallet_ag_carte_cash / 100;
$this->validate($request, [
'final_country' => 'required|integer|exists:countries,id',
]);
$final_country = $request->input('final_country');
$plr_customer_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_national');
$plr_customer_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_international');
$frais = ($init_country != $final_country) ? $this->calculateFees($plr_customer_cart_cash_international, $request->montant) : $this->calculateFees($plr_customer_cart_cash_national, $request->montant);
$data['frais'] = round($frais, 2);
$data['montant_net'] = round($request->montant + $data['frais'], 2);
break;
@ -1728,7 +1843,7 @@ class iLinkTransactionController extends Controller
break;
case 15: // Agent - Envoi de cash vers autre wallet
$this->validate($request, [
'final_country' => 'required|integer|min:0|not_in:0',
'final_country' => 'required|integer|exists:countries,id',
]);
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_agent_depot_autre_wallet, $request->montant) : $this->calculateFees($plr_agent_depot_autre_wallet_national, $request->montant);
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
@ -1737,13 +1852,19 @@ class iLinkTransactionController extends Controller
$data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $request->final_country);
break;
case 16: // Agent - Envoi de cash vers une carte visa
$frais = $request->montant * $config->taux_com_wallet_ag_envoi_cash_carte / 100;
$this->validate($request, [
'final_country' => 'required|integer|exists:countries,id'
]);
$final_country = $request->input('final_country');
$plr_customer_cash_cart_national = $this->getPaliers($paliers_commission_wallets, 'customer_cash_cart_national');
$plr_customer_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'customer_cash_cart_international');
$frais = ($init_country != $final_country) ? $this->calculateFees($plr_customer_cash_cart_international, $request->montant) : $this->calculateFees($plr_customer_cash_cart_national, $request->montant);
$data['frais'] = round($frais, 2);
$data['montant_net'] = round($request->montant - $data['frais'], 2);
break;
case 17: // Agent - Envoi de cash vers cash
$this->validate($request, [
'final_country' => 'required|integer|min:0|not_in:0',
'final_country' => 'required|integer|exists:countries,id',
]);
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_agent_cash_cash, $request->montant) : $this->calculateFees($plr_agent_cash_cash_national, $request->montant);
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
@ -1752,7 +1873,7 @@ class iLinkTransactionController extends Controller
$data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $request->final_country);
break;
}
$net = isset($data['montant_net']) ? $data['montant_net'] : $data['montant_net_init'];
$net = $data['montant_net'] ?? $data['montant_net_init'];
if (isset($net))
if ($net < 0)
return $this->errorResponse(trans('errors.incorrect_net_amount'));
@ -1828,7 +1949,7 @@ class iLinkTransactionController extends Controller
/**
* @throws AppException
*/
private function calculateFees(array $paliers, $montant)
private function calculateFees(array $paliers, $montant, $frais = null)
{
$size = sizeof($paliers);
$fees = 0;
@ -1844,7 +1965,11 @@ class iLinkTransactionController extends Controller
}
if ($palier) {
$fees = ($montant * $palier->taux / 100);
if (isset($frais)) {
// Pour le calcul par paliers des commissions uniquement
$montant = $frais;
}
$fees = round(($montant * $palier->taux / 100), 2);
} else {
throw new AppException(trans('errors.amount_not_allowed', ['min' => floatval($min), 'max' => floatval($max)]));
}

View File

@ -201,16 +201,18 @@ class WalletIlinkTransaction extends Model
public function card_rules()
{
return [
'numero_carte'=>'required',
'cvv'=>'required|size:3',
'expiration_date'=>'required|date_format:m/y|after_or_equal:today',
'final_country' => 'required|integer|exists:countries,id',
'numero_carte' => 'required',
'cvv' => 'required|size:3',
'expiration_date' => 'required|date_format:m/y|after_or_equal:today',
];
}
public function user_card_rules()
{
return [
'cvv'=>'required|size:3',
'final_country' => 'required|integer|exists:countries,id',
'cvv' => 'required|size:3',
];
}

View File

@ -4,6 +4,7 @@
namespace App\Traits;
use App\Exceptions\AppException;
use App\Models\Agent;
use App\Models\AgentPlus;
use App\Models\CodeGenerer;
@ -44,17 +45,18 @@ trait Helper
{
public function sendMail($email, $title, $messageText)
{
try {
$recipients = [preg_replace("/\s+/", "", $email)]; // Supprimer les espaces dans le mail
Mail::mailer('smtp')->raw($messageText, function ($message) use ($recipients, $title) {
$message->subject($title);
$message->to($recipients);
});
} catch (Throwable $t) {
Log::error('-------- Mail not sent -----------');
Log::error($t->getMessage());
if (config('variables.send_email')) {
try {
$recipients = [preg_replace("/\s+/", "", $email)]; // Supprimer les espaces dans le mail
Mail::mailer('smtp')->raw($messageText, function ($message) use ($recipients, $title) {
$message->subject($title);
$message->to($recipients);
});
} catch (Throwable $t) {
Log::error('-------- Mail not sent -----------');
Log::error($t->getMessage());
}
}
// return $this->successResponse("mail envoye");
}
@ -541,11 +543,11 @@ trait Helper
$identification = Identification::where('id_user', $id_user)->first();
if (isset($identification)) {
if ($identification->status == 0)
throw new Exception(trans('errors.validation_user_identification_required'), 422);
throw new AppException(trans('errors.validation_user_identification_required'), 422);
else
return $identification;
} else {
throw new Exception(trans('errors.user_identification_required'), 422);
throw new AppException(trans('errors.user_identification_required'), 422);
}
}
@ -579,7 +581,7 @@ trait Helper
public function validatePassword($password, $encrypted_password, $salt)
{
if (!$this->checkPassword($password, $encrypted_password, $salt)) {
throw new Exception(trans('messages.incorrect_user_password'), 422);
throw new AppException(trans('messages.incorrect_user_password'), 422);
}
}

View File

@ -62,6 +62,7 @@ $app->singleton(
$app->configure('app');
$app->configure('mail');
$app->configure('queue');
$app->configure('variables');
$app->alias('mailer', Illuminate\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\MailQueue::class);

4
config/variables.php Normal file
View File

@ -0,0 +1,4 @@
<?php
return [
'send_email' => env('SEND_EMAIL', true)
];