From b1a6d7d7867ccc3213d64a6407e71bc9af06e901 Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Sat, 25 Jul 2020 19:02:54 +0100 Subject: [PATCH] + Add Balance compensation in paying networks --- app/Http/Controllers/WalletController.php | 14 +++++++------- .../Controllers/iLinkTransactionController.php | 18 ++++++++++++++++++ app/Models/PayingNetwork.php | 7 +++++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/WalletController.php b/app/Http/Controllers/WalletController.php index e306af4..f309721 100755 --- a/app/Http/Controllers/WalletController.php +++ b/app/Http/Controllers/WalletController.php @@ -100,14 +100,14 @@ class WalletController extends Controller // Wallets users iLink public function showWalletUser($id_user){ - $wallet = collect(DB::select('SELECT wu.* , u.user_code , u.numero_carte , u.expiration_date from wallets_users wu - INNER JOIN users u ON u.id = wu.idUser WHERE wu.idUser = :id_user',['id_user' => $id_user]))->first(); + $wallet = collect(DB::select('SELECT wu.*, u.user_code , u.numero_carte , u.expiration_date ,n2.name as network , cc.name as country, cc.currency_code from wallets_users wu + INNER JOIN users u ON u.id = wu.idUser + INNER JOIN networks n1 ON n1.id = u.network_id + INNER JOIN networks n2 ON n2.country_id = n1.country_id + INNER JOIN configWallet cw ON cw.id_network = n2.id + INNER JOIN countries_currencies cc ON cc.id = n2.country_id + WHERE wu.idUser = :id_user AND cw.type = \'ilink\' LIMIT 1',['id_user' => $id_user]))->first(); if($wallet){ - $wallet->country = 'Gabon'; - $wallet->network = 'iLink World'; - $walletUser = WalletsUser::findOrFail($wallet->id); - $init_country = $walletUser->user->network->country->id; - $wallet->currency_code = $this->getCurrency($init_country); return $this->successResponse($wallet); } else return $this->errorResponse(trans('errors.model_not_found',['model'=>'wallet']),Response::HTTP_BAD_REQUEST); diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 837a827..15d44af 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -124,6 +124,8 @@ class iLinkTransactionController extends Controller $this->validate($request, $transaction->send_wallet_wallet_rules()); $user = $walletUser->user; if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) { + if($init_country != $request->final_country) + return $this->checkUserIdentification($user->id); if ($request->montant > $walletUser->balance) { return $this->errorResponse(trans('errors.insufficient_balance')); } else { @@ -139,6 +141,7 @@ class iLinkTransactionController extends Controller $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; + $reseauPayeur->balance_compensation += $transaction->montant_net_final_country; } else { $transaction->part_reseau_payeur = 0; $transaction->part_reseau_payeur_final_country = 0; @@ -255,6 +258,8 @@ class iLinkTransactionController extends Controller $this->validate($request, $transaction->send_wallet_cash_rules()); $user = $walletUser->user; if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) { + if($init_country != $request->final_country) + return $this->checkUserIdentification($user->id);; if ($request->montant > $walletUser->balance) { return $this->errorResponse(trans('errors.insufficient_balance')); } else { @@ -270,6 +275,7 @@ class iLinkTransactionController extends Controller $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; + $reseauPayeur->balance_compensation += $transaction->montant_net_final_country; } else { $transaction->part_reseau_payeur = 0; $transaction->part_reseau_payeur_final_country = 0; @@ -344,6 +350,7 @@ class iLinkTransactionController extends Controller if ($request->montant > $walletUser->balance) { return $this->errorResponse(trans('errors.insufficient_balance')); } else { + return $this->checkUserIdentification($user->id);; $transaction->final_country = $init_country; $transaction->frais = $frais = $this->calculateFees($plr_user_wallet_cash_national, $request->montant); $transaction->taxe = $taxe = $this->calculateTax($taxesNationales, $frais); @@ -433,6 +440,7 @@ class iLinkTransactionController extends Controller $this->validate($request, $transaction->user_card_rules()); $user = $walletUser->user; if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) { + return $this->checkUserIdentification($user->id);; if (!(isset($user->numero_carte) && isset($user->expiration_date))) return $this->errorResponse(trans('errors.no_bank_card_attached')); @@ -822,6 +830,7 @@ class iLinkTransactionController extends Controller $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; + $reseauPayeur->balance_compensation += $transaction->montant_net_final_country; } else { $transaction->part_reseau_payeur = 0; $transaction->part_reseau_payeur_final_country = 0; @@ -1260,6 +1269,15 @@ class iLinkTransactionController extends Controller return $randomString; } + private function checkUserIdentification($id_user){ + $identification = Identification::where('id_user', $id_user)->first(); + if(isset($identification)) { + if ($identification->status == 0) + return $this->errorResponse(trans('errors.validation_user_identification_required')); + }else { + return $this->errorResponse(trans('errors.user_identification_required')); + } + } // public function index(Request $request){ // // $notices = DB::select('select notices.id,notices.title,notices.body,notices.created_at,notices.updated_at, diff --git a/app/Models/PayingNetwork.php b/app/Models/PayingNetwork.php index 345ea50..e531289 100644 --- a/app/Models/PayingNetwork.php +++ b/app/Models/PayingNetwork.php @@ -10,13 +10,14 @@ use Illuminate\Database\Eloquent\Model; /** * Class PayingNetwork - * + * * @property int $id * @property int $id_network * @property float $taux_partage * @property float $balance_com + * @property float balance_compensation * @property int $id_configWallet - * + * * @property Network $network * @property ConfigWallet $config_wallet * @@ -31,6 +32,7 @@ class PayingNetwork extends Model 'id_network' => 'int', 'taux_partage' => 'float', 'balance_com' => 'float', + 'balance_compensation'=>'float', 'id_configWallet' => 'int' ]; @@ -38,6 +40,7 @@ class PayingNetwork extends Model 'id_network', 'taux_partage', 'balance_com', + 'balance_compensation', 'id_configWallet' ];