From 5cbf539346887476038bf5b7c2a3e9dfcb3fffe7 Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Mon, 9 Nov 2020 19:05:04 +0100 Subject: [PATCH] + Adding route to make invoice payment to operator --- .../iLinkTransactionController.php | 64 ++++++++++++++++++- resources/lang/en/errors.php | 2 + resources/lang/en/messages.php | 11 ++++ resources/lang/fr/errors.php | 2 + resources/lang/fr/messages.php | 11 ++++ 5 files changed, 88 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 2cf0471..4c1be31 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -12,6 +12,7 @@ use App\Models\NetworksOperator; use App\Models\PayingNetwork; use App\Models\Regulation; use App\Models\TypeIlinkTransaction; +use App\Models\TypeOperator; use App\Models\User; use App\Models\Wallet; use App\Models\WalletAgent; @@ -442,7 +443,7 @@ class iLinkTransactionController extends Controller $message = trans('messages.successful_user_send_to_bank', ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), 'net' => $this->toMoney($transaction->montant, $init_country), 'iban' => $request->iban, 'fees' => $this->toMoney($frais, $init_country), - 'sender_code' => $user->user_code]); + 'sender_code' => $user->user_code, 'bank' => $transaction->bank, 'country' => $transaction->country]); $this->sendMail($user->email, trans('messages.successful_transaction'), $message); return $this->successResponse($message . trans('messages.sent_by_mail')); @@ -1140,9 +1141,68 @@ class iLinkTransactionController extends Controller $message = trans('messages.successful_user_send_to_bank', ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), 'net' => $this->toMoney($transaction->montant, $init_country), 'iban' => $request->iban, 'fees' => $this->toMoney($frais, $init_country), - 'sender_code' => $codeGenerer->code_membre]); + 'sender_code' => $codeGenerer->code_membre, 'bank' => $transaction->bank, 'country' => $transaction->country]); $this->sendMail($agent->email, trans('messages.successful_transaction'), $message); return $this->successResponse($message . trans('messages.sent_by_mail')); + + case 19: // User - Payer un operateur + $this->validate($request, [ + 'id_operator' => 'required|integer|min:0|not_in:0', + 'id_wallet_network' => 'required|integer|min:0|not_in:0', + 'type_operator' => 'required|in:water,electricity,tv,school', + 'no_facture' => 'required', + ]); + $user = $walletUser->user; + if (!$this->checkPassword($request->password, $user->encrypted_password, $user->salt)) + return $this->errorResponse(trans('messages.incorrect_user_password')); + + if ($request->montant > $walletUser->balance) + return $this->errorResponse(trans('errors.insufficient_balance')); + + //Verifier si l'operateur est associée au reseau + $network_bank = NetworksOperator::where('id_network', $request->id_wallet_network)->where('id_operator_country', $request->id_operator)->first(); + if (!$network_bank) + return $this->errorResponse(trans('errors.operator_not_associated_with_network')); + + if ($network_bank->operators_country->operator->type != $request->type_operator) { + $type_operator = TypeOperator::where('code', $request->type_operator)->firstOrFail(); + $type = app()->isLocale('en') ? $type_operator->description_en : $type_operator->description_fr; + return $this->errorResponse(trans('errors.not_matching_operator', ['type_operator' => $type])); + } + + + $transaction->frais = $frais = 0; + $transaction->taxe = $taxe = 0; +// $walletUser->balance -= $transaction->montant; + //Emettre une trame SSL pour recharger l'api de l'operateur du montant de la transaction + $transaction->commission_banque = 0; + + $transaction->commission_hyp = 0; + + $transaction->id_wallet_hyp = $walletHyperviseur->id; + $transaction->frais = $frais; + $transaction->date = new \DateTime(); + $transaction->operator = $network_bank->operators_country->operator->nom; + $type_operator = $network_bank->operators_country->operator->type_operator; + $transaction->type_operator = app()->isLocale('en') ? $type_operator->description_en : $type_operator->description_fr; + $transaction->country = $network_bank->network->country->name; + $transaction->id_operator = $request->id_operator; + $transaction->no_facture = $request->no_facture; +// $walletUser->save(); + $transaction->id_transaction = $this->getTransactionID(); +// $transaction->save(); + + Log::info('-------------------------- User - Payer une facture chez un operateur ------------------------------------'); + Log::info($transaction->toArray()); + Log::info('------------------------------------------------------------------------------------------------'); + + $message = trans('messages.successful_user_payment_of_operator', + ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), + 'net' => $this->toMoney($transaction->montant, $init_country), 'no_facture' => $request->no_facture, 'fees' => $this->toMoney($frais, $init_country), + 'sender_code' => $user->user_code, 'operator' => $transaction->operator, 'type_operator' => $transaction->type_operator]); + $this->sendMail($user->email, trans('messages.successful_transaction'), $message); + return $this->successResponse($message . trans('messages.sent_by_mail')); + } } diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index de37494..615ff1b 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -79,4 +79,6 @@ Paying network : :network :country', "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", + "operator_not_associated_with_network" => "This operator is not associated with your network", + "not_matching_operator" => "This operator is not a :type_operator", ]; diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 12915d0..0f42064 100755 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -277,5 +277,16 @@ Transaction Information: - Fees: :fees - Net shipping amount:: net - Issuer account: :sender_code + - Bank : :bank :country - IBAN: :iban', + 'successful_user_payment_of_operator' => "Payment of an invoice to an operator +Transaction Information: + - Number : :id_transaction + - Amount of the transaction : :amount + - Fees : :fees + - Net amount paid : :net + - Issuer account : :sender_code + - Operator : :operator + - Type of operator : :type_operator + - Invoice number : :invoice_number", ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index 2420195..6b89e31 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -79,4 +79,6 @@ Réseau payeur : :network :country', "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", + "operator_not_associated_with_network" => "Cette operateur n'est pas associé à votre réseau", + "not_matching_operator" => "Cet opérateur n'est pas un :type_operator", ]; diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index 188ba63..db18a59 100755 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -278,5 +278,16 @@ Informations de la transaction : - Frais : :fees - Montant net d\'envoi: :net - Compte émetteur : :sender_code + - Banque : :bank :country - IBAN : :iban', + 'successful_user_payment_of_operator' => "Paiement d'une facture chez un operateur +Informations de la transaction : + - Numéro : :id_transaction + - Montant de la transaction : :amount + - Frais : :fees + - Montant net payé: :net + - Compte émetteur : :sender_code + - Operateur : :operator + - Type d'operateur : :type_operator + - No facture : :no_facture", ];