diff --git a/app/Http/Controllers/HelperController.php b/app/Http/Controllers/HelperController.php index 4022db9..f13b8cb 100755 --- a/app/Http/Controllers/HelperController.php +++ b/app/Http/Controllers/HelperController.php @@ -4,7 +4,9 @@ namespace App\Http\Controllers; use App\Models\ConfigWallet; use App\Models\Country; +use App\Models\NetworksAgent; use App\Models\User; +use App\Models\Wallet; use App\Models\WalletsUser; use App\Traits\ApiResponser; use Illuminate\Http\Request; @@ -35,19 +37,29 @@ class HelperController extends Controller { $this->validate($request,[ 'id_country' => 'required|integer|min:0|not_in:0', - 'id_wallet_user' => 'required|integer|min:0|not_in:0', + 'id_wallet_agent' => 'required_without:id_wallet_user|integer|min:0|not_in:0', + 'id_wallet_user' => 'required_without:id_wallet_agent|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')); + if (isset($request->id_wallet_agent)) { + $walletAgent = Wallet::findOrFail($request->get('id_wallet_agent')); + $network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent); + $init_country = $network_agent->network->country->id; + // Configuratrion du wallet + $config = ConfigWallet::where('id_network', $network_agent->network_id)->firstOrFail(); + } elseif (isset($request->id_wallet_user)) { + $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 country_id = :id_country;',['id_country'=>$request->id_country, 'id_config'=> $config->id]); @@ -69,22 +81,17 @@ class HelperController extends Controller { $this->validate($request,[ 'id_country' => 'required|integer|min:0|not_in:0', - 'id_wallet_user' => 'required|integer|min:0|not_in:0', + 'id_wallet_agent' => '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')); - } + $walletAgent = Wallet::findOrFail($request->get('id_wallet_agent')); + $network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent); + // Configuratrion du wallet + $config = ConfigWallet::where('id_network', $network_agent->network_id)->firstOrFail(); + $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]); + AND status = 1 AND c.type <> \'ilink\' AND country_id = :id_country;',['id_country'=>$request->id_country, 'id_config'=> $config->id]); return $this->successResponse($networks); } diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 53ccf51..38b2571 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -489,9 +489,9 @@ class iLinkTransactionController extends Controller $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])){ + if (in_array($transaction->type, [3, 17])) { $configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail(); - if($configPayeur->type != 'ilink') + if ($configPayeur->type != 'ilink') return $this->errorResponse(trans('errors.withdrawal_network_unauthorized')); } if ($transaction->status_retrait == 0) { @@ -500,7 +500,12 @@ class iLinkTransactionController extends Controller 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; + 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; + } else { + $commissionHyp = $transaction->type == 11 ? $transaction->commission_hyp : $transaction->commission_hyp_final_country; + } if ($montantNet == $request->montant) { $transactionRetrait = $transaction->replicate(); $transactionRetrait->id = null; @@ -1078,9 +1083,9 @@ class iLinkTransactionController extends Controller 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])){ + if (in_array($transaction->type, [3, 17])) { $configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail(); - if($configPayeur->type != 'ilink') + if ($configPayeur->type != 'ilink') return $this->errorResponse(trans('errors.withdrawal_network_unauthorized')); }