From 80ccf453c44bb55d639e22ea064ede8408328eef Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Fri, 6 Nov 2020 18:40:08 +0100 Subject: [PATCH] + Adding payment operators --- app/Http/Controllers/WalletController.php | 8 ++-- .../iLinkTransactionController.php | 20 ++++++--- app/Models/Bank.php | 35 --------------- ...{NetworksBank.php => NetworksOperator.php} | 18 ++++---- app/Models/Operator.php | 43 +++++++++++++++++++ ...{BanksCountry.php => OperatorsCountry.php} | 28 ++++++------ app/Models/TypeOperator.php | 39 +++++++++++++++++ resources/lang/en/errors.php | 1 + resources/lang/fr/errors.php | 1 + routes/web.php | 4 +- 10 files changed, 126 insertions(+), 71 deletions(-) delete mode 100644 app/Models/Bank.php rename app/Models/{NetworksBank.php => NetworksOperator.php} (56%) create mode 100644 app/Models/Operator.php rename app/Models/{BanksCountry.php => OperatorsCountry.php} (55%) create mode 100644 app/Models/TypeOperator.php diff --git a/app/Http/Controllers/WalletController.php b/app/Http/Controllers/WalletController.php index b5430a8..3ae79fd 100755 --- a/app/Http/Controllers/WalletController.php +++ b/app/Http/Controllers/WalletController.php @@ -348,12 +348,12 @@ class WalletController extends Controller return $this->successResponse($result); } - public function getWalletBanks($id_wallet_network) + public function getWalletOperators($id_wallet_network, $type_operator) { - $banks = DB::select("SELECT bc.id as id_bank, b.nom as bank_name , bc.adresse as bank_address, c.name as country FROM networks_banks nb INNER JOIN banks_countries bc on bc.id = nb.id_bank_country INNER JOIN banks b ON b.id = bc.id_bank -INNER JOIN countries c ON bc.id_country = c.id WHERE nb.id_network = :id_network ;", ['id_network' => $id_wallet_network]); + $operators = DB::select("SELECT oc.id as id_operator, o.nom as operator_name , oc.adresse as operator_address, c.name as country FROM networks_operators nop INNER JOIN operators_countries oc ON oc.id = nop.id_operator_country INNER JOIN operators o ON o.id = oc.id_operator +INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON o.type = top.code WHERE nop.id_network = :id_network AND o.type = :type_operator ;", ['id_network' => $id_wallet_network, 'type_operator' => $type_operator]); - return $this->successResponse($banks); + return $this->successResponse($operators); } } diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 7918990..2cf0471 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -8,7 +8,7 @@ use App\Models\ConfigWallet; use App\Models\Country; use App\Models\Identification; use App\Models\NetworksAgent; -use App\Models\NetworksBank; +use App\Models\NetworksOperator; use App\Models\PayingNetwork; use App\Models\Regulation; use App\Models\TypeIlinkTransaction; @@ -397,13 +397,16 @@ class iLinkTransactionController extends Controller // return $rep; //Verifier si la banque est associée au reseau - $network_bank = NetworksBank::where('id_network', $request->id_wallet_network)->where('id_bank_country', $request->id_bank)->first(); + $network_bank = NetworksOperator::where('id_network', $request->id_wallet_network)->where('id_operator_country', $request->id_bank)->first(); if (!$network_bank) return $this->errorResponse(trans('errors.bank_not_associated_with_network')); + if ($network_bank->operators_country->operator->type != 'bank') + return $this->errorResponse(trans('errors.not_banking_operator')); + //Verifier le code IBAN $country_code = $network_bank->network->country->code_country; - $bank_code = $network_bank->banks_country->code_banque; + $bank_code = $network_bank->operators_country->code; switch ($this->checkIBAN($request->iban, $country_code, $bank_code)) { case 0: return $this->errorResponse(trans('errors.invalid_iban')); @@ -424,7 +427,7 @@ class iLinkTransactionController extends Controller $transaction->id_wallet_hyp = $walletHyperviseur->id; $transaction->frais = $frais; $transaction->date = new \DateTime(); - $transaction->bank = $network_bank->banks_country->bank->nom; + $transaction->bank = $network_bank->operators_country->operator->nom; $transaction->country = $network_bank->network->country->name; $transaction->id_bank = $request->id_bank; $transaction->iban = $request->iban; @@ -1090,13 +1093,16 @@ class iLinkTransactionController extends Controller return $this->errorResponse(trans('errors.insufficient_balance')); //Verifier si la banque est associée au reseau - $network_bank = NetworksBank::where('id_network', $request->id_wallet_network)->where('id_bank_country', $request->id_bank)->first(); + $network_bank = NetworksOperator::where('id_network', $request->id_wallet_network)->where('id_operator_country', $request->id_bank)->first(); if (!$network_bank) return $this->errorResponse(trans('errors.bank_not_associated_with_network')); + if ($network_bank->operators_country->operator->type != 'bank') + return $this->errorResponse(trans('errors.not_banking_operator')); + //Verifier le code IBAN $country_code = $network_bank->network->country->code_country; - $bank_code = $network_bank->banks_country->code_banque; + $bank_code = $network_bank->operators_country->code; switch ($this->checkIBAN($request->iban, $country_code, $bank_code)) { case 0: return $this->errorResponse(trans('errors.invalid_iban')); @@ -1119,7 +1125,7 @@ class iLinkTransactionController extends Controller $transaction->id_wallet_sup = $walletSuperviseur->id; $transaction->frais = $frais; $transaction->date = new \DateTime(); - $transaction->bank = $network_bank->banks_country->bank->nom; + $transaction->bank = $network_bank->operators_country->operator->nom; $transaction->country = $network_bank->network->country->name; $transaction->id_bank = $request->id_bank; $transaction->iban = $request->iban; diff --git a/app/Models/Bank.php b/app/Models/Bank.php deleted file mode 100644 index 4f3c7b0..0000000 --- a/app/Models/Bank.php +++ /dev/null @@ -1,35 +0,0 @@ -hasMany(BanksCountry::class, 'id_bank'); - } -} diff --git a/app/Models/NetworksBank.php b/app/Models/NetworksOperator.php similarity index 56% rename from app/Models/NetworksBank.php rename to app/Models/NetworksOperator.php index 0a58d67..7f8dbe2 100644 --- a/app/Models/NetworksBank.php +++ b/app/Models/NetworksOperator.php @@ -9,35 +9,35 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * Class NetworksBank + * Class NetworksOperator * * @property int $id - * @property int $id_bank_country + * @property int $id_operator_country * @property int $id_network * - * @property BanksCountry $banks_country + * @property OperatorsCountry $operators_country * @property Network $network * * @package App\Models */ -class NetworksBank extends Model +class NetworksOperator extends Model { - protected $table = 'networks_banks'; + protected $table = 'networks_operators'; public $timestamps = false; protected $casts = [ - 'id_bank_country' => 'int', + 'id_operator_country' => 'int', 'id_network' => 'int' ]; protected $fillable = [ - 'id_bank_country', + 'id_operator_country', 'id_network' ]; - public function banks_country() + public function operators_country() { - return $this->belongsTo(BanksCountry::class, 'id_bank_country'); + return $this->belongsTo(OperatorsCountry::class, 'id_operator_country'); } public function network() diff --git a/app/Models/Operator.php b/app/Models/Operator.php new file mode 100644 index 0000000..3375c55 --- /dev/null +++ b/app/Models/Operator.php @@ -0,0 +1,43 @@ +belongsTo(TypeOperator::class, 'type', 'code'); + } + + public function operators_countries() + { + return $this->hasMany(OperatorsCountry::class, 'id_operator'); + } +} diff --git a/app/Models/BanksCountry.php b/app/Models/OperatorsCountry.php similarity index 55% rename from app/Models/BanksCountry.php rename to app/Models/OperatorsCountry.php index ad911dc..323f58d 100644 --- a/app/Models/BanksCountry.php +++ b/app/Models/OperatorsCountry.php @@ -10,43 +10,43 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; /** - * Class BanksCountry + * Class OperatorsCountry * * @property int $id - * @property int $id_bank + * @property int $id_operator * @property int $id_country * @property string|null $adresse - * @property string|null $code_banque + * @property string|null $code * @property bool $status * - * @property Bank $bank + * @property Operator $operator * @property Country $country - * @property Collection|NetworksBank[] $networks_banks + * @property Collection|NetworksOperator[] $networks_operators * * @package App\Models */ -class BanksCountry extends Model +class OperatorsCountry extends Model { - protected $table = 'banks_countries'; + protected $table = 'operators_countries'; public $timestamps = false; protected $casts = [ - 'id_bank' => 'int', + 'id_operator' => 'int', 'id_country' => 'int', 'status' => 'bool' ]; protected $fillable = [ - 'id_bank', + 'id_operator', 'id_country', 'adresse', - 'code_banque', + 'code', 'status' ]; - public function bank() + public function operator() { - return $this->belongsTo(Bank::class, 'id_bank'); + return $this->belongsTo(Operator::class, 'id_operator'); } public function country() @@ -54,8 +54,8 @@ class BanksCountry extends Model return $this->belongsTo(Country::class, 'id_country'); } - public function networks_banks() + public function networks_operators() { - return $this->hasMany(NetworksBank::class, 'id_bank_country'); + return $this->hasMany(NetworksOperator::class, 'id_operator_country'); } } diff --git a/app/Models/TypeOperator.php b/app/Models/TypeOperator.php new file mode 100644 index 0000000..c49cb83 --- /dev/null +++ b/app/Models/TypeOperator.php @@ -0,0 +1,39 @@ +hasMany(Operator::class, 'type', 'code'); + } +} diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index 30cbbbc..de37494 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -78,4 +78,5 @@ Paying network : :network :country', "invalid_iban" => "The IBAN code is invalid", "country_not_match_iban" => "The IBAN code does not correspond to the country of this bank", "bank_not_match_iban" => "The IBAN code does not correspond to this bank", + "not_banking_operator" => "This operator is not a banking operator", ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index 02fee13..2420195 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -78,4 +78,5 @@ Réseau payeur : :network :country', "invalid_iban" => "Le code IBAN est invalide", "country_not_match_iban" => "Le code IBAN ne correspond pas au pays cette banque", "bank_not_match_iban" => "Le code IBAN ne correspond à cette banque", + "not_banking_operator" => "Cet opérateur n'est pas un opérateur bancaire", ]; diff --git a/routes/web.php b/routes/web.php index a8465ed..cc88242 100755 --- a/routes/web.php +++ b/routes/web.php @@ -69,8 +69,8 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route // Wallets users iLink $router->group(['prefix' => '/users'], function () use ($router) { $router->get('{id_user}', 'WalletController@showWalletUser'); - //Liste des banques - $router->get('banks/{id_wallet_network}', 'WalletController@getWalletBanks'); + //Liste des operateurs + $router->get('operators/{type}/{id_wallet_network}', 'WalletController@getWalletOperators'); }); });