diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index a7f60e2..2318349 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -54,6 +54,7 @@ class iLinkTransactionController extends Controller if (isset($request->id_wallet_agent)) { $walletAgent = Wallet::findOrFail($request->get('id_wallet_agent')); $network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent); + $transaction->init_country = $init_country = $network_agent->network->country->id; // Configuratrion du wallet $config = ConfigWallet::where('id_network', $network_agent->network_id)->firstOrFail(); @@ -211,7 +212,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'); @@ -388,6 +389,7 @@ class iLinkTransactionController extends Controller $body['card_number'] = $user->numero_carte; $body['cvv'] = $request->cvv; $body['expiry_date'] = $user->expiration_date->format('Y-m'); +// dd($body); $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); $code = $response->getStatusCode(); @@ -486,7 +488,10 @@ class iLinkTransactionController extends Controller if ($transaction->montant_net == $request->montant) { $transactionRetrait = $transaction->replicate(); $transactionRetrait->id = null; + $transactionRetrait->type = $request->type; $transactionRetrait->id_transaction = $this->getTransactionID(); + $transactionRetrait->montant = $transaction->montant_net; + $emailEmetteur = $transaction->wallet_user ? $transaction->wallet_user->user->email : $transaction->email_emetteur; $transactionRetrait->commission_ag = floatval($transaction->frais * $config->taux_com_ag_retrait_cash / 100); $transactionRetrait->commission_sup = floatval($transaction->frais * $config->taux_com_sup_retrait_cash / 100); @@ -495,8 +500,14 @@ class iLinkTransactionController extends Controller $walletAgent->balance_com += $transactionRetrait->commission_ag; $walletSuperviseur->balance_com += $transactionRetrait->commission_sup; $walletHyperviseur->balance_com -= ( $transactionRetrait->commission_ag + $transactionRetrait->commission_sup); - $transactionRetrait->status_retrait = $transaction->status_retrait = 1; - $transactionRetrait->date_retrait = $transaction->date_retrait = new \DateTime(); + $transactionRetrait->id_wallet_ag = $walletAgent->id; + $transactionRetrait->id_wallet_sup = $walletSuperviseur->id; + $transactionRetrait->id_wallet_hyp = $walletHyperviseur->id; + + $transactionRetrait->status_retrait = $transactionRetrait->code_retrait_salt = $transactionRetrait->encrypted_code_retrait = null; + $transactionRetrait->frais = $transactionRetrait->taxe = 0; + $transaction->status_retrait = 1; + $transaction->date_retrait = new \DateTime(); $transactionRetrait->date = new \DateTime(); $walletAgent->save(); $walletSuperviseur->save(); @@ -505,9 +516,8 @@ class iLinkTransactionController extends Controller $transactionRetrait->save(); $message = trans('messages.successful_agent_remove_cash', ['id_transaction' => $transactionRetrait->id_transaction, 'amount' => $this->toMoney($request->montant, $init_country), - 'commission' => $this->toMoney($transactionRetrait->commission_ag, $init_country), 'code' => wordwrap($request->code_retrait, 4, ' ', true), - 'id_transaction_retrait' => $transaction->id_transaction]); - $this->sendMail($agent->email, trans('messages.successful_transaction'), $message); + 'code' => wordwrap($request->code_retrait, 4, ' ', true), 'id_transaction_retrait' => $transaction->id_transaction]); + $this->sendMail($emailEmetteur, trans('messages.successful_transaction'), $message); return $this->successResponse($message . trans('messages.sent_by_mail')); } else { return $this->errorResponse(trans('errors.incorrect_withdrawal_amount')); @@ -537,20 +547,20 @@ class iLinkTransactionController extends Controller $frais = floatval($request->montant * $config->taux_com_wallet_ag_carte_cash / 100); $montantRetrait = $transaction->montant + $frais; $transaction->montant_net = $montantRetrait; - $body['amount'] = $montantRetrait; + $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country); $body['card_number'] = $request->numero_carte; $body['cvv'] = $request->cvv; $body['expiry_date'] = $expiration_date->format('Y-m'); -// $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); - $code = 200; // $response->getStatusCode(); + $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); + $code = $response->getStatusCode(); if ($code == 200) { $banqueCommission = floatval($frais * $config->taux_com_banque_retrait_carte_cash / 100); $transaction->commission_banque = $banqueCommission; // 2---> Emmètre via API sécurisé SSL une requête de débit de notre //compte marchand du (Part de la banque partenaire en % - //pour le dépôtqui s’applique sur les frais minimum) et créditer + //pour le dépôt qui s’applique sur les frais minimum) et créditer //le compte des opérations défini avec notre banque //partenaire @@ -558,7 +568,7 @@ class iLinkTransactionController extends Controller $agentCommission = floatval($frais * $config->taux_com_ag_retrait_carte_cash / 100); $superviseurCommission = floatval($frais * $config->taux_com_sup_retrait_carte_cash / 100); - $hyperviseurCommission = floatval($frais * $$config->taux_com_hyp_retrait_carte_cash / 100); + $hyperviseurCommission = floatval($frais * $config->taux_com_hyp_retrait_carte_cash / 100); $walletAgent->balance_com += $agentCommission; $transaction->commission_ag = $agentCommission; @@ -574,6 +584,7 @@ class iLinkTransactionController extends Controller $walletAgent->save(); $walletSuperviseur->save(); $walletHyperviseur->save(); + $transaction->id_transaction = $this->getTransactionID(); $transaction->save(); return $this->successResponse(trans('messages.successful_transaction')); @@ -588,11 +599,15 @@ class iLinkTransactionController extends Controller $this->validate($request, $transaction->cash_wallet_rules()); $agent = AgentPlus::findOrFail($network_agent->agent_id); if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) { - $user = User::where('user_code', $request->user_code)->firstOrFail(); - $walletUser = WalletsUser::where('idUser', $user->id)->firstOrFail(); + $user = User::where('user_code', $request->user_code)->first(); + if(!$user) + return $this->errorResponse(trans('errors.wallet_not_defined')); - $frais = ($request->init_country != $request->final_country) ? $this->calculateFees($plr_agent_depot_wallet_ilink, $request->montant) : $this->calculateFees($plr_agent_depot_wallet_ilink_national, $request->montant); - $taxe = ($request->init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais); + $walletUser = WalletsUser::where('idUser', $user->id)->firstOrFail(); + $transaction->final_country = $final_country = $user->network->country->id; + + $frais = ($init_country != $final_country) ? $this->calculateFees($plr_agent_depot_wallet_ilink, $request->montant) : $this->calculateFees($plr_agent_depot_wallet_ilink_national, $request->montant); + $taxe = ($init_country!= $final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais); $montantDepot = $request->montant - $frais - $taxe; $transaction->montant_net = $montantDepot; $walletUser->balance += $montantDepot; @@ -618,11 +633,12 @@ class iLinkTransactionController extends Controller $transaction->id_wallet_sup = $walletSuperviseur->id; $transaction->id_wallet_hyp = $walletHyperviseur->id; $transaction->save(); - $this->sendMail($user->email, trans('messages.successful_transaction'), trans('messages.successful_deposit_ilink', - ['id_transaction' => $transaction->id, 'amount' => $this->toMoney($transaction->montant, $request->init_country), 'net_init' => $this->toMoney($montantDepot, $request->init_country), - 'net_final' => $this->toMoneyWithCurrency($montantDepot, $request->init_country, $request->final_country), 'fees' => $this->toMoney($frais, $request->init_country), 'tax' => $this->toMoney($taxe, $request->init_country), - 'user_code' => $request->user_code])); - return $this->successResponse(trans('messages.successful_transaction')); + $message = trans('messages.successful_deposit_ilink', + ['id_transaction' => $transaction->id, 'amount' => $this->toMoney($transaction->montant, $init_country), 'net_init' => $this->toMoney($montantDepot, $init_country), + 'net_final' => $this->toMoneyWithCurrency($montantDepot, $init_country, $final_country), 'fees' => $this->toMoney($frais, $init_country), 'tax' => $this->toMoney($taxe, $init_country), + 'user_code' => $request->user_code]); + $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')); } @@ -915,15 +931,25 @@ class iLinkTransactionController extends Controller public function getTransactionRetrait(Request $request){ $this->validate($request, [ 'id_transaction' =>'required', + 'id_wallet_agent' => 'required|integer|min:0|not_in:0', ]); $transaction = WalletIlinkTransaction::select('nom_destinataire' , 'prenom_destinataire' ,'type_document_destinataire','id_document_destinataire' ,'type', - 'id_wallet_user')->where('id_transaction',$request->id_transaction)->first(); + 'id_wallet_user','init_country' , 'final_country')->where('id_transaction',$request->id_transaction)->first(); + if(!$transaction) return $this->errorResponse(trans('errors.transaction_not_exist'), Response::HTTP_NOT_FOUND); if ($transaction->status_retrait != 0) return $this->errorResponse(trans('errors.withdrawal_already_made')); + $walletAgent = Wallet::findOrFail($request->get('id_wallet_agent')); + $network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent); + $agent_country = $network_agent->network->country->id; + if($transaction->type != 11) + if($agent_country != $transaction->final_country) + return $this->errorResponse(trans('errors.operation_cannot_performed_in_country')); + + $data = $transaction->replicate(); if($transaction->type == 9){ $data->nom_destinataire = $transaction->wallet_user->user->lastname; diff --git a/app/Models/NetworksAgent.php b/app/Models/NetworksAgent.php index 8e3d8d9..a873a67 100755 --- a/app/Models/NetworksAgent.php +++ b/app/Models/NetworksAgent.php @@ -11,7 +11,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class NetworksAgent - * + * * @property int $id * @property int $network_id * @property int $agent_id @@ -21,7 +21,7 @@ use Illuminate\Database\Eloquent\Model; * @property string $phone * @property string $transactionNumber * @property string $validation_code - * + * * @property Collection|Wallet[] $wallets * * @package App\Models @@ -54,4 +54,9 @@ class NetworksAgent extends Model { return $this->hasMany(Wallet::class, 'id_networkAgent'); } + + public function network() + { + return $this->belongsTo(Network::class, 'network_id'); + } } diff --git a/app/Models/WalletIlinkTransaction.php b/app/Models/WalletIlinkTransaction.php index 44a536d..ea0dcd3 100644 --- a/app/Models/WalletIlinkTransaction.php +++ b/app/Models/WalletIlinkTransaction.php @@ -178,8 +178,8 @@ class WalletIlinkTransaction extends Model { return [ 'user_code'=>'required', - 'init_country' =>'required|integer|min:0|not_in:0', - 'final_country' =>'required|integer|min:0|not_in:0', +// 'init_country' =>'required|integer|min:0|not_in:0', +// 'final_country' =>'required|integer|min:0|not_in:0', ]; } @@ -187,8 +187,8 @@ class WalletIlinkTransaction extends Model { return [ 'numero_carte'=>'required', - 'cvv'=>'required_if:facade,front|size:3', - 'expiration_date'=>'required_if:facade,front|date_format:m/y|after_or_equal:today', + 'cvv'=>'required|size:3', + 'expiration_date'=>'required|date_format:m/y|after_or_equal:today', ]; } diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index 2644d63..a3732d2 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -18,4 +18,5 @@ return [ 'withdrawal_already_made' => 'Withdrawal already made', 'invalid_withdrawal_code' => 'Invalid withdrawal code', 'incorrect_withdrawal_amount'=> 'Incorrect withdrawal amount', + 'operation_cannot_performed_in_country' => 'This operation cannot be performed in this country', ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index 2ced6db..74df4f5 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -18,4 +18,5 @@ return [ 'withdrawal_already_made' => 'Retrait déjà éffectuée', 'invalid_withdrawal_code' => 'Code de retrait invalide', 'incorrect_withdrawal_amount'=> 'Montant de retrait incorrect', + 'operation_cannot_performed_in_country' => 'Cette operation ne peut pas etre effectuée dans ce pays', ]; diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index cd97b6c..6a811eb 100755 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -107,11 +107,10 @@ Informations de la transaction : - Code utilisateur : :sender_code - Numero de la carte : :cart_number - Code de retrait : :code', - 'successful_agent_remove_cash'=>'Retrait d\'argent + 'successful_agent_remove_cash'=>'Retrait d\'argent chez un agent géolocalisé Informations de la transaction : - Numéro : :id_transaction - Montant de retrait : :amount - - Votre commission : :commission - Numero de transaction de retrait : :id_transaction_retrait - Code de retrait : :code' ];