From 6e2908bab926c690264f33911ba0979206610d8c Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Wed, 24 Jun 2020 16:49:41 +0100 Subject: [PATCH] =?UTF-8?q?+=20Fix=20bugs=20on=20User=20-=20Envoi=20wallet?= =?UTF-8?q?=20=C3=A0=20wallet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/HelperController.php | 25 ++++++++++++++++--- .../iLinkTransactionController.php | 3 +-- routes/web.php | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/HelperController.php b/app/Http/Controllers/HelperController.php index 24d07cc..5ea12df 100755 --- a/app/Http/Controllers/HelperController.php +++ b/app/Http/Controllers/HelperController.php @@ -2,8 +2,11 @@ namespace App\Http\Controllers; +use App\Models\ConfigWallet; use App\Models\Country; +use App\Models\WalletsUser; use App\Traits\ApiResponser; +use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class HelperController extends Controller @@ -27,10 +30,26 @@ class HelperController extends Controller return $this->successResponse($countries); } - public function paying_networks($id_country) + public function paying_networks(Request $request) { - $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 ) - AND status = 1 AND country_id = :id;',['id'=>$id_country]); + $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 country_id = :id_country;',['id_country'=>$request->id_country, 'id_config'=> $config->id]); foreach ($networks as $network){ if($network->type == 'ilink') $network->type = 'ilink-world'; diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 21c7c4e..c14f65e 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -73,7 +73,6 @@ class iLinkTransactionController extends Controller ->select('configWallet.id')->first(); if ($result) { $config = ConfigWallet::findOrFail($result->id); - $transaction->network_emetteur = $config->id_network; } else { return $this->errorResponse(trans('errors.no_ilink_network')); } @@ -82,7 +81,7 @@ class iLinkTransactionController extends Controller $wallet_agent_hyp = WalletAgent::where('agent_id', $hyperviseur->id)->firstOrFail(); $walletHyperviseur = Wallet::findOrFail($wallet_agent_hyp->wallet_id); } - + $transaction->network_emetteur = $config->id_network; $taxesNationales = array_values(array_filter($config->taxes->all(), function ($tax) { return $tax->destination == 'national'; diff --git a/routes/web.php b/routes/web.php index 7ce35c2..471bae6 100755 --- a/routes/web.php +++ b/routes/web.php @@ -17,7 +17,7 @@ // Helper routes $router->get('countries','HelperController@countries'); $router->get('countries/{dial_code}','HelperController@country'); -$router->get('paying_networks/{id_country}','HelperController@paying_networks'); +$router->post('paying_networks','HelperController@paying_networks'); // Transactions routes $router->group(['prefix' => '/transactions'] , function () use ($router){