From 29e6282bc1fe08c933669ab11976ab854c088b6e Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Tue, 30 Jun 2020 12:06:56 +0100 Subject: [PATCH] + Add methods of User - Retrait --- .../iLinkTransactionController.php | 114 +++++++++++++++--- app/Models/WalletIlinkTransaction.php | 7 ++ resources/lang/en/errors.php | 3 +- resources/lang/en/messages.php | 13 +- resources/lang/fr/errors.php | 3 +- resources/lang/fr/messages.php | 13 +- 6 files changed, 128 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 0124a4c..7eeac7b 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -196,23 +196,24 @@ class iLinkTransactionController extends Controller } break; case 2: //User - Envoi de wallet à carte - $this->validate($request, $transaction->card_rules()); + $this->validate($request, $transaction->user_card_rules()); $user = $walletUser->user; if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) { if ($request->montant > $walletUser->balance) { return $this->errorResponse(trans('errors.insufficient_balance')); } else { - $expiration_date = \DateTime::createFromFormat('m/y', $request->expiration_date); - if (!$expiration_date) - $expiration_date = new \DateTime(); - $transaction->expiration_date = $expiration_date; + if(!(isset($user->numero_carte) && isset($user->expiration_date))) + return $this->errorResponse(trans('errors.no_bank_card_attached')); + + $transaction->expiration_date = $user->expiration_date; + $transaction->numero_carte = $user->numero_carte; $frais = $request->montant * $config->taux_com_user_wallet_carte / 100; $transaction->montant_net = $montantDepot = $transaction->montant - $frais; - $body['amount'] = $montantDepot; - $body['card_number'] = $request->numero_carte; + $body['amount'] = $this->toUSDAmount($montantDepot,$init_country);; + $body['card_number'] = $user->numero_carte; $body['cvv'] = $request->cvv; - $body['expiry_date'] = $expiration_date->format('Y-m'); + $body['expiry_date'] = $user->expiration_date->format('Y-m'); $response = $client->post('fund-transfer-api/v1/transaction/push', ['json' => $body]); $code = $response->getStatusCode(); @@ -232,7 +233,7 @@ class iLinkTransactionController extends Controller $message = trans('messages.successful_user_send_to_cart', ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), 'net' => $this->toMoney($montantDepot, $init_country), 'fees' => $this->toMoney($frais, $init_country), - 'sender_code' => $user->user_code, 'cart_number' => wordwrap($request->numero_carte, 4, ' ', true)]); + 'sender_code' => $user->user_code, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]); $this->sendMail($user->email, trans('messages.successful_transaction'), $message); return $this->successResponse($message.trans('messages.sent_by_mail')); @@ -366,35 +367,36 @@ class iLinkTransactionController extends Controller } break; case 10: //User - Retrait de carte vers wallet - $this->validate($request, $transaction->card_rules()); + $this->validate($request, $transaction->user_card_rules()); $user = $walletUser->user; if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) { if ($request->montant > $walletUser->balance) { return $this->errorResponse(trans('errors.insufficient_balance')); } else { - $expiration_date = \DateTime::createFromFormat('m/y', $request->expiration_date); - if (!$expiration_date) - $expiration_date = new \DateTime(); - $transaction->expiration_date = $expiration_date; + if(!(isset($user->numero_carte) && isset($user->expiration_date))) + return $this->errorResponse(trans('errors.no_bank_card_attached')); + + $transaction->expiration_date = $user->expiration_date; + $transaction->numero_carte = $user->numero_carte; $frais = $request->montant * $config->taux_com_user_carte_wallet / 100; $transaction->montant_net = $montantRetrait = $transaction->montant - $frais; $body['amount'] = $this->toUSDAmount($montantRetrait,$init_country); - $body['card_number'] = $request->numero_carte; + $body['card_number'] = $user->numero_carte; $body['cvv'] = $request->cvv; - $body['expiry_date'] = $expiration_date->format('Y-m'); + $body['expiry_date'] = $user->expiration_date->format('Y-m'); $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); $code = $response->getStatusCode(); if ($code == 200) { - $walletUser->balance -= $transaction->montant; $transaction->commission_banque = $commissionBanque = $frais * $config->taux_com_banque_retrait_carte_cash_ilink / 100 ; //Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission - $walletHyperviseur->balance_com += $frais; + $walletUser->balance += $montantRetrait; $transaction->commission_hyp = $frais * $config->taux_com_hyp_retrait_carte_cash_ilink / 100 ; + $walletHyperviseur->balance_com += $transaction->commission_hyp; $transaction->id_wallet_hyp = $walletHyperviseur->id; $transaction->frais = $frais; $transaction->date = new \DateTime(); @@ -405,7 +407,7 @@ class iLinkTransactionController extends Controller $message = trans('messages.successful_user_remove_from_cart_to_wallet', ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), 'net' => $this->toMoney($montantRetrait, $init_country), 'fees' => $this->toMoney($frais, $init_country), - 'sender_code' => $user->user_code, 'cart_number' => wordwrap($request->numero_carte, 4, ' ', true)]); + 'sender_code' => $user->user_code, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]); $this->sendMail($user->email, trans('messages.successful_transaction'), $message); return $this->successResponse($message.trans('messages.sent_by_mail')); @@ -418,7 +420,62 @@ class iLinkTransactionController extends Controller } break; case 11: // User - Retrait de carte vers cash + $this->validate($request, $transaction->user_card_rules()); + $user = $walletUser->user; + if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) { + if ($request->montant > $walletUser->balance) { + return $this->errorResponse(trans('errors.insufficient_balance')); + } else { + if(!(isset($user->numero_carte) && isset($user->expiration_date))) + return $this->errorResponse(trans('errors.no_bank_card_attached')); + $transaction->expiration_date = $user->expiration_date; + $transaction->numero_carte = $user->numero_carte; + + $frais = $request->montant * $config->taux_com_user_carte_cash/ 100; + $transaction->montant_net = $montantRetrait = $transaction->montant - $frais; + $body['amount'] = $this->toUSDAmount($montantRetrait,$init_country); + $body['card_number'] = $user->numero_carte; + $body['cvv'] = $request->cvv; + $body['expiry_date'] = $user->expiration_date->format('Y-m'); + + $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); + $code = $response->getStatusCode(); + + if ($code == 200) { + $transaction->commission_banque = $commissionBanque = $frais * $config->taux_com_banque_retrait_carte_cash_ilink / 100 ; + //Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission + + $code_retrait = $this->random_string(); + $hash = $this->hashSSHA($code_retrait); + $transaction->encrypted_code_retrait = $hash['encrypted']; + $transaction->code_retrait_salt = $hash['salt']; + + $walletUser->balance -= $transaction->montant; + $transaction->commission_hyp = $frais * $config->taux_com_hyp_retrait_carte_cash_ilink / 100 ; + $walletHyperviseur->balance_com += $transaction->commission_hyp; + $transaction->id_wallet_hyp = $walletHyperviseur->id; + $transaction->frais = $frais; + $transaction->date = new \DateTime(); + $transaction->status_retrait = 0; + $walletHyperviseur->save(); + $walletUser->save(); + $transaction->id_transaction = $this->getTransactionID(); + $transaction->save(); + $message = trans('messages.successful_user_remove_from_cart_to_cash', + ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), + 'net' => $this->toMoney($montantRetrait, $init_country), 'fees' => $this->toMoney($frais, $init_country),'code' => wordwrap($code_retrait, 4, ' ', true), + 'sender_code' => $user->user_code, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]); + $this->sendMail($user->email, trans('messages.successful_transaction'), $message); + return $this->successResponse($message.trans('messages.sent_by_mail')); + + } else { + return $this->errorResponse(trans('errors.visa_api_failed'), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + } else { + return $this->errorResponse(trans('messages.incorrect_user_password')); + } break; case 12: // Agent - Retrait en cash $this->validate($request, $transaction->remove_cash_rules()); @@ -822,6 +879,25 @@ class iLinkTransactionController extends Controller $data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $request->final_country); return $this->successResponse($data); break; + case 9: // User - Retrait de wallet en cash + $frais = $this->calculateFees($plr_user_wallet_cash_national, $request->montant); + $taxe = $this->calculateTax($taxesNationales, $frais); + $data['frais'] = $frais + $taxe; + $data['montant_net_init'] = $request->montant - $frais - $taxe; + return $this->successResponse($data); + break; + case 10: //User - Retrait de carte vers wallet + $frais = $request->montant * $config->taux_com_user_carte_wallet / 100;; + $data['frais'] = $frais; + $data['montant_net_init'] = $request->montant - $frais; + return $this->successResponse($data); + break; + case 11: // User - Retrait de carte vers cash + $frais = $request->montant * $config->taux_com_user_carte_cash/ 100; + $data['frais'] = $frais ; + $data['montant_net_init'] = $request->montant - $frais; + return $this->successResponse($data); + break; } } diff --git a/app/Models/WalletIlinkTransaction.php b/app/Models/WalletIlinkTransaction.php index 21209b5..c644dc0 100644 --- a/app/Models/WalletIlinkTransaction.php +++ b/app/Models/WalletIlinkTransaction.php @@ -192,6 +192,13 @@ class WalletIlinkTransaction extends Model ]; } + public function user_card_rules() + { + return [ + 'cvv'=>'required|size:3', + ]; + } + public function cash_cash_rules() { return [ diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index 7b862b2..fd50e7e 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -12,5 +12,6 @@ return [ 'wallet_not_defined' => 'This recipient wallet code does not exist', 'insufficient_balance'=> 'The balance is insufficient to complete this transaction', 'no_ilink_network' => 'Sorry, there is no iLink World network in your country', - 'wallet_country_not_match' => 'This recipient wallet code is not registered in the country :country' + 'wallet_country_not_match' => 'This recipient wallet code is not registered in the country :country', + 'no_bank_card_attached' => 'No bank card is attached to your account' ]; diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index a88d39b..c663023 100755 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -88,12 +88,21 @@ Transaction information: - Net withdrawal amount : :net - Issuer account : :sender_code - Withdrawal code : :code', - 'successful_user_remove_from_cart_to_wallet'=>'Withdrawing money from card to account + 'successful_user_remove_from_cart_to_wallet'=>'Withdrawing money from your card to your account Transaction information: - Number : :id_transaction - Amount of the transaction : :amount - Fees : :fees - Net withdrawal amount : :net - Recipient account : :sender_code - - Recipient\'s card number : :cart_number', + - Card number : :cart_number', + 'successful_user_remove_from_cart_to_cash' => 'Withdrawing money from your card to cash +Transaction information : + - Number: :id_transaction + - Amount of the transaction: :amount + - Fees: :fees + - Net withdrawal amount: :net + - Issuer account : :sender_code + - Card number : :cart_number + - Withdrawal code : :code', ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index d738fd3..725b438 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -12,5 +12,6 @@ return [ 'wallet_not_defined' => 'Ce code wallet destinataire n\'existe pas', 'insufficient_balance'=> 'Le solde est insuffisant pour effectuer cette transaction', 'no_ilink_network' => 'Désolé , il n\'existe pas de reseau iLink World dans votre pays', - 'wallet_country_not_match' => 'Ce code wallet destinataire n\'est pas enregistré dans le pays :country' + 'wallet_country_not_match' => 'Ce code wallet destinataire n\'est pas enregistré dans le pays :country', + 'no_bank_card_attached' => 'Aucune carte bancaire n\'est rattachée à votre compte' ]; diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index a3a32a4..495e079 100755 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -88,12 +88,21 @@ Informations de la transaction : - Montant net de retrait: :net - Compte émetteur : :sender_code - Code de retrait : :code', - 'successful_user_remove_from_cart_to_wallet'=>'Retrait d\'argent de la carte vers le compte + 'successful_user_remove_from_cart_to_wallet'=>'Retrait d\'argent de votre carte vers votre compte Informations de la transaction : - Numéro : :id_transaction - Montant de la transaction : :amount - Frais : :fees - Montant net de retrait: :net - Compte destinataire : :sender_code - - Numero de la carte du destinataire : :cart_number', + - Numero de la carte : :cart_number', + 'successful_user_remove_from_cart_to_cash' => 'Retrait d\'argent de votre carte vers cash +Informations de la transaction : + - Numéro : :id_transaction + - Montant de la transaction : :amount + - Frais : :fees + - Montant net de retrait: :net + - Compte émetteur : :sender_code + - Numero de la carte : :cart_number + - Code de retrait : :code', ];