From e3fcb972c6163860c3905c94980a7338a0f5fc9b Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Sat, 4 Jul 2020 11:20:26 +0100 Subject: [PATCH] + Update method of Agent - Retrait en cash --- app/Http/Controllers/HelperController.php | 23 +++++ .../iLinkTransactionController.php | 97 ++++++++++++------- app/Models/WalletIlinkTransaction.php | 3 +- resources/lang/en/errors.php | 1 + resources/lang/en/messages.php | 2 +- resources/lang/fr/errors.php | 1 + routes/web.php | 1 + 7 files changed, 89 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/HelperController.php b/app/Http/Controllers/HelperController.php index 530398c..4022db9 100755 --- a/app/Http/Controllers/HelperController.php +++ b/app/Http/Controllers/HelperController.php @@ -65,6 +65,29 @@ class HelperController extends Controller return $this->successResponse($networks); } + public function other_paying_networks(Request $request) + { + $this->validate($request,[ + 'id_country' => 'required|integer|min:0|not_in:0', + 'id_wallet_user' => 'required|integer|min:0|not_in:0', + ]); + + $walletUser = WalletsUser::findOrFail($request->id_wallet_user); + $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(); + if ($result) { + $config = ConfigWallet::findOrFail($result->id); + } else { + return $this->errorResponse(trans('errors.no_ilink_network')); + } + $networks = DB::select('SELECT n.id , n.name , c.type FROM networks n INNER JOIN configWallet c ON c.id_network = n.id WHERE n.id + IN ( SELECT distinct id_network FROM paying_networks WHERE id_configWallet = :id_config) + AND status = 1 AND c.type <> \'ilink\' country_id = :id_country;',['id_country'=>$request->id_country, 'id_config'=> $config->id]); + return $this->successResponse($networks); + } + public function country($code_dial){ return $this->successResponse(Country::where('code_dial',$code_dial)->firstOrFail()); } diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index f4cc0ed..53ccf51 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -129,17 +129,22 @@ class iLinkTransactionController extends Controller $transaction->frais = $frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_wallet, $request->montant) : $this->calculateFees($plr_user_wallet_wallet_national, $request->montant); $transaction->taxe = $taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais); $transaction->montant_net = $montantDepot = $transaction->montant - $frais - $taxe; + $transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $request->final_country); $configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail(); - $reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->firstOrFail(); - $transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100; - $transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur; - - $transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $request->final_country); - $transaction->commission_hyp = $transaction->part_reseau_emetteur; - $transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country); - if (isset($reseauPayeur)) + $reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->first(); + if (isset($reseauPayeur)) { + $transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100; + $transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country); + $transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur; $reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country; + } else { + $transaction->part_reseau_payeur = 0; + $transaction->part_reseau_payeur_final_country = 0; + $transaction->part_reseau_emetteur = $frais; + } + + $transaction->commission_hyp = $transaction->part_reseau_emetteur; if ($configPayeur->type == 'ilink') { $destinataire = User::where('user_code', $request->id_destinataire)->first(); if ($destinataire) { // Si c'est un wallet ilink @@ -157,7 +162,6 @@ class iLinkTransactionController extends Controller //Hyperviseur payeur $hyperviseurPayeur = AgentPlus::where('category', 'hyper')->where('network_id', $request->network_destinataire)->firstOrFail(); if ($hyperviseurPayeur->id == $hyperviseur->id) { //Si c'est le reseau payeur est aussi emetteur - $walletHyperviseur->balance_com += $transaction->part_reseau_payeur; $transaction->id_wallet_hyp_payeur = $walletHyperviseur->id; } else { $wallet_agent_hypPayeur = WalletAgent::where('agent_id', $hyperviseurPayeur->id)->firstOrFail(); @@ -256,23 +260,28 @@ class iLinkTransactionController extends Controller $transaction->frais = $frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_cash, $request->montant) : $this->calculateFees($plr_user_wallet_cash_national, $request->montant); $transaction->taxe = $taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais); $transaction->montant_net = $montantRetrait = $transaction->montant - $frais - $taxe; + $transaction->montant_net_final_country = $this->toMoneyAmount($montantRetrait, $init_country, $request->final_country); $configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail(); - $reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->firstOrFail(); - $transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100; - $transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur; + $reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->first(); + if (isset($reseauPayeur)) { + $transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100; + $transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country); + $transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur; + $reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country; + } else { + $transaction->part_reseau_payeur = 0; + $transaction->part_reseau_payeur_final_country = 0; + $transaction->part_reseau_emetteur = $frais; + } - $transaction->montant_net_final_country = $this->toMoneyAmount($montantRetrait, $init_country, $request->final_country); $transaction->commission_hyp = $transaction->part_reseau_emetteur; $transaction->commission_hyp_final_country = $this->toMoneyAmount($transaction->commission_hyp, $init_country, $request->final_country); - $transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country); - if (isset($reseauPayeur)) - $reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country; + if ($configPayeur->type == 'ilink') { //Hyperviseur payeur $hyperviseurPayeur = AgentPlus::where('category', 'hyper')->where('network_id', $request->network_destinataire)->firstOrFail(); if ($hyperviseurPayeur->id == $hyperviseur->id) { //Si c'est le reseau payeur est aussi emetteur - $walletHyperviseur->balance_com += $transaction->part_reseau_payeur; $transaction->id_wallet_hyp_payeur = $walletHyperviseur->id; } else { $wallet_agent_hypPayeur = WalletAgent::where('agent_id', $hyperviseurPayeur->id)->firstOrFail(); @@ -428,6 +437,7 @@ class iLinkTransactionController extends Controller $transaction->expiration_date = $user->expiration_date; $transaction->numero_carte = $user->numero_carte; + $transaction->final_country = $init_country; $frais = $request->montant * $config->taux_com_user_carte_cash / 100; $transaction->montant_net = $montantRetrait = $transaction->montant - $frais; @@ -478,11 +488,16 @@ class iLinkTransactionController extends Controller if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) { $transaction = WalletIlinkTransaction::where('id_transaction', $request->id_transaction)->first(); if ($transaction) { + //Verifier que le reseau payeur est de type iLink + if (in_array($transaction->type, [3, 17])){ + $configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail(); + if($configPayeur->type != 'ilink') + return $this->errorResponse(trans('errors.withdrawal_network_unauthorized')); + } if ($transaction->status_retrait == 0) { //Verifier que le pays de destinatation correspond au pays de retrait - if ($transaction->type != 11) - if ($init_country != $transaction->final_country) - return $this->errorResponse(trans('errors.operation_cannot_performed_in_country')); + if ($init_country != $transaction->final_country) + return $this->errorResponse(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; $commissionHyp = $transaction->type == 11 ? $transaction->commission_hyp : $transaction->commission_hyp_final_country; @@ -647,7 +662,9 @@ class iLinkTransactionController extends Controller } break; case 15: // Agent - Envoi de cash vers autre wallet - $this->validate($request, $transaction->cash_cash_rules()); + $this->validate($request, array_merge($transaction->cash_cash_rules(), [ + 'id_destinataire' => 'required' + ])); $agent = AgentPlus::findOrFail($network_agent->agent_id); if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) { if ($request->montant > $walletAgent->balance_princ) @@ -780,20 +797,26 @@ class iLinkTransactionController extends Controller $configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail(); - $reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->firstOrFail(); - $transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100; - $transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur; - - - $transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country); - if (isset($reseauPayeur)) + $reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->first(); + if (isset($reseauPayeur)) { + $transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100; + $transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country); + $transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur; $reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country; + } else { + $transaction->part_reseau_payeur = 0; + $transaction->part_reseau_payeur_final_country = 0; + $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); if ($configPayeur->type == 'ilink') { //Hyperviseur payeur $hyperviseurPayeur = AgentPlus::where('category', 'hyper')->where('network_id', $request->network_destinataire)->firstOrFail(); if ($hyperviseurPayeur->id == $hyperviseur->id) { //Si c'est le reseau payeur est aussi emetteur - $walletHyperviseur->balance_com += $transaction->part_reseau_payeur; $transaction->id_wallet_hyp_payeur = $walletHyperviseur->id; } else { $wallet_agent_hypPayeur = WalletAgent::where('agent_id', $hyperviseurPayeur->id)->firstOrFail(); @@ -809,9 +832,6 @@ class iLinkTransactionController extends Controller // $montantDepot; } - $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); $walletAgent->balance_com += $commisionAgent; $transaction->commission_ag = $commisionAgent; @@ -1057,16 +1077,21 @@ class iLinkTransactionController extends Controller if (!$transaction) return $this->errorResponse(trans('errors.transaction_not_exist'), Response::HTTP_NOT_FOUND); + //Verifier que le reseau payeur est de type iLink + if (in_array($transaction->type, [3, 17])){ + $configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail(); + if($configPayeur->type != 'ilink') + return $this->errorResponse(trans('errors.withdrawal_network_unauthorized')); + } + if ($transaction->status_retrait != 0) return $this->errorResponse(trans('errors.withdrawal_already_made')); $walletAgent = Wallet::findOrFail($request->get('id_wallet_agent')); $network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent); $agent_country = $network_agent->network->country->id; - if ($transaction->type != 11) - if ($agent_country != $transaction->final_country) - return $this->errorResponse(trans('errors.operation_cannot_performed_in_country')); - + if ($agent_country != $transaction->final_country) + return $this->errorResponse(trans('errors.operation_cannot_performed_in_country')); $data = $transaction->replicate(); if (in_array($transaction->type, [9, 11])) { diff --git a/app/Models/WalletIlinkTransaction.php b/app/Models/WalletIlinkTransaction.php index 3212e27..7cb03d6 100644 --- a/app/Models/WalletIlinkTransaction.php +++ b/app/Models/WalletIlinkTransaction.php @@ -215,8 +215,7 @@ class WalletIlinkTransaction extends Model 'nom_destinataire'=>'required', 'prenom_destinataire'=>'required', 'type_document_destinataire'=>'required', - 'id_document_destinataire'=>'required', - 'id_destinataire' => 'required', + 'id_document_destinataire'=>'required' ]; } diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index a3732d2..4184d47 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -19,4 +19,5 @@ return [ 'invalid_withdrawal_code' => 'Invalid withdrawal code', 'incorrect_withdrawal_amount'=> 'Incorrect withdrawal amount', 'operation_cannot_performed_in_country' => 'This operation cannot be performed in this country', + 'withdrawal_network_unauthorized' => 'This withdrawal cannot be made at an iLink agent', ]; diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index a388471..b5c15e6 100755 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -39,7 +39,7 @@ Transaction information : - Country of destination : :final_country - Net amount : :net_final - Recipient account : :user_code', - 'successful_agent_deposit_other_wallet' => 'Deposit money to another account + 'successful_agent_deposit_other_wallet' => 'Depositing money to a different network account Transaction information : - Transaction ID : :id_transaction - Amount : :amount diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index 74df4f5..ce66fec 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -19,4 +19,5 @@ return [ 'invalid_withdrawal_code' => 'Code de retrait invalide', 'incorrect_withdrawal_amount'=> 'Montant de retrait incorrect', 'operation_cannot_performed_in_country' => 'Cette operation ne peut pas etre effectuée dans ce pays', + 'withdrawal_network_unauthorized' => 'Ce retrait ne peut pas etre effectué chez un agent iLink', ]; diff --git a/routes/web.php b/routes/web.php index 7f2936e..56d8d44 100755 --- a/routes/web.php +++ b/routes/web.php @@ -18,6 +18,7 @@ $router->get('countries','HelperController@countries'); $router->get('countries/{dial_code}','HelperController@country'); $router->post('paying_networks','HelperController@paying_networks'); +$router->post('other_paying_networks','HelperController@other_paying_networks'); $router->get('init','HelperController@init'); // Transactions routes