From f208af131ae7f5cada2dcba8bc256c279ea2c2a5 Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Tue, 30 Jun 2020 14:09:00 +0100 Subject: [PATCH] + Fix bug --- .../iLinkTransactionController.php | 214 +++++++++--------- 1 file changed, 104 insertions(+), 110 deletions(-) diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 7eeac7b..327faf5 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -139,7 +139,7 @@ class iLinkTransactionController extends Controller $transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $request->final_country); $transaction->commission_hyp = $transaction->part_reseau_emetteur; $transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country); - if(isset($reseauPayeur)) + if (isset($reseauPayeur)) $reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country; if ($configPayeur->type == 'ilink') { $destinataire = User::where('user_code', $request->id_destinataire)->first(); @@ -180,7 +180,7 @@ class iLinkTransactionController extends Controller $walletHyperviseur->save(); $walletUser->save(); - if(isset($reseauPayeur)) + if (isset($reseauPayeur)) $reseauPayeur->save(); $transaction->save(); $message = trans('messages.successful_user_send_to_wallet', @@ -189,7 +189,7 @@ class iLinkTransactionController extends Controller 'init_country' => $this->getCountryName($init_country), 'final_country' => $this->getCountryName($request->final_country), 'sender_code' => $user->user_code, 'receiver_code' => $transaction->id_destinataire]); $this->sendMail($user->email, trans('messages.successful_transaction'), $message); - return $this->successResponse($message.trans('messages.sent_by_mail')); + return $this->successResponse($message . trans('messages.sent_by_mail')); } } else { return $this->errorResponse(trans('messages.incorrect_user_password')); @@ -202,7 +202,7 @@ class iLinkTransactionController extends Controller if ($request->montant > $walletUser->balance) { return $this->errorResponse(trans('errors.insufficient_balance')); } else { - if(!(isset($user->numero_carte) && isset($user->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; @@ -210,7 +210,7 @@ class iLinkTransactionController extends Controller $frais = $request->montant * $config->taux_com_user_wallet_carte / 100; $transaction->montant_net = $montantDepot = $transaction->montant - $frais; - $body['amount'] = $this->toUSDAmount($montantDepot,$init_country);; + $body['amount'] = $this->toUSDAmount($montantDepot, $init_country);; $body['card_number'] = $user->numero_carte; $body['cvv'] = $request->cvv; $body['expiry_date'] = $user->expiration_date->format('Y-m'); @@ -235,7 +235,7 @@ class iLinkTransactionController extends Controller 'net' => $this->toMoney($montantDepot, $init_country), 'fees' => $this->toMoney($frais, $init_country), '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')); + return $this->successResponse($message . trans('messages.sent_by_mail')); } else { return $this->errorResponse(trans('errors.visa_api_failed'), Response::HTTP_INTERNAL_SERVER_ERROR); @@ -267,7 +267,7 @@ class iLinkTransactionController extends Controller $transaction->montant_net_final_country = $this->toMoneyAmount($montantRetrait, $init_country, $request->final_country); $transaction->commission_hyp = $transaction->part_reseau_emetteur; $transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country); - if(isset($reseauPayeur)) + if (isset($reseauPayeur)) $reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country; if ($configPayeur->type == 'ilink') { //Hyperviseur payeur @@ -282,7 +282,7 @@ class iLinkTransactionController extends Controller $transaction->id_wallet_hyp_payeur = $walletHyperviseurPayeur->id; $walletHyperviseurPayeur->save(); } - }else{ + } else { //Emettre requete SSL vers wallet extene correspondant pour recharger le compte dont l'id est : // $transaction->id_destinataire ; // et le montant est: @@ -297,7 +297,7 @@ class iLinkTransactionController extends Controller $transaction->id_wallet_hyp = $walletHyperviseur->id; $transaction->id_transaction = $this->getTransactionID(); - if(isset($reseauPayeur)) + if (isset($reseauPayeur)) $reseauPayeur->save(); $walletHyperviseur->save(); $walletUser->save(); @@ -307,10 +307,10 @@ class iLinkTransactionController extends Controller $message = trans('messages.successful_user_send_to_cash', ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), 'net_init' => $this->toMoney($montantRetrait, $init_country), 'net_final' => $this->toMoneyWithCurrency($montantRetrait, $init_country, $request->final_country), 'fees' => $this->toMoney($frais + $taxe, $init_country), - 'init_country' => $this->getCountryName($init_country), 'final_country' => $this->getCountryName($request->final_country),'code' => wordwrap($code_retrait, 4, ' ', true), - 'sender_code' => $user->user_code, 'receiver_code' => $transaction->id_destinataire,'receiver_name' => $request->prenom_destinataire . ' ' . $request->nom_destinataire]); - $this->sendMail($user->email, trans('messages.successful_transaction'),$message ); - return $this->successResponse($message.trans('messages.sent_by_mail')); + 'init_country' => $this->getCountryName($init_country), 'final_country' => $this->getCountryName($request->final_country), 'code' => wordwrap($code_retrait, 4, ' ', true), + 'sender_code' => $user->user_code, 'receiver_code' => $transaction->id_destinataire, 'receiver_name' => $request->prenom_destinataire . ' ' . $request->nom_destinataire]); + $this->sendMail($user->email, trans('messages.successful_transaction'), $message); + return $this->successResponse($message . trans('messages.sent_by_mail')); } } else { return $this->errorResponse(trans('messages.incorrect_user_password')); @@ -356,12 +356,12 @@ class iLinkTransactionController extends Controller $transaction->save(); $message = trans('messages.successful_user_remove_from_wallet_to_cash', ['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country), 'net' => $this->toMoney($montantRetrait, $init_country), - 'fees' => $this->toMoney($frais + $taxe, $init_country), 'code' => wordwrap($code_retrait, 4, ' ', true), + 'fees' => $this->toMoney($frais + $taxe, $init_country), 'code' => wordwrap($code_retrait, 4, ' ', true), 'sender_code' => $user->user_code]); - $this->sendMail($user->email, trans('messages.successful_transaction'),$message ); - return $this->successResponse($message.trans('messages.sent_by_mail')); + $this->sendMail($user->email, trans('messages.successful_transaction'), $message); + return $this->successResponse($message . trans('messages.sent_by_mail')); } - }else{ + } else { return $this->errorResponse(trans('messages.incorrect_user_password')); } @@ -370,51 +370,49 @@ class iLinkTransactionController extends Controller $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')); + + 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'] = $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 + + $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(); + $walletHyperviseur->save(); + $walletUser->save(); + $transaction->id_transaction = $this->getTransactionID(); + $transaction->save(); + $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($transaction->numero_carte, 4, ' ', true)]); + $this->sendMail($user->email, trans('messages.successful_transaction'), $message); + return $this->successResponse($message . trans('messages.sent_by_mail')); + } 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_wallet / 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 - - $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(); - $walletHyperviseur->save(); - $walletUser->save(); - $transaction->id_transaction = $this->getTransactionID(); - $transaction->save(); - $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($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); - } + return $this->errorResponse(trans('errors.visa_api_failed'), Response::HTTP_INTERNAL_SERVER_ERROR); } + } else { return $this->errorResponse(trans('messages.incorrect_user_password')); } @@ -423,56 +421,52 @@ class iLinkTransactionController extends Controller $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')); + + 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']; + + $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(); + $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 { - 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); - } + return $this->errorResponse(trans('errors.visa_api_failed'), Response::HTTP_INTERNAL_SERVER_ERROR); } + } else { return $this->errorResponse(trans('messages.incorrect_user_password')); } @@ -893,8 +887,8 @@ class iLinkTransactionController extends Controller 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 ; + $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;