+ Add method Agent - Retrait en cash

This commit is contained in:
Djery-Tom 2020-07-02 20:18:28 +01:00
parent b74c126a84
commit a526c726b1
6 changed files with 61 additions and 29 deletions

View File

@ -54,6 +54,7 @@ class iLinkTransactionController extends Controller
if (isset($request->id_wallet_agent)) { if (isset($request->id_wallet_agent)) {
$walletAgent = Wallet::findOrFail($request->get('id_wallet_agent')); $walletAgent = Wallet::findOrFail($request->get('id_wallet_agent'));
$network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent); $network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent);
$transaction->init_country = $init_country = $network_agent->network->country->id;
// Configuratrion du wallet // Configuratrion du wallet
$config = ConfigWallet::where('id_network', $network_agent->network_id)->firstOrFail(); $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; $frais = $request->montant * $config->taux_com_user_wallet_carte / 100;
$transaction->montant_net = $montantDepot = $transaction->montant - $frais; $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['card_number'] = $user->numero_carte;
$body['cvv'] = $request->cvv; $body['cvv'] = $request->cvv;
$body['expiry_date'] = $user->expiration_date->format('Y-m'); $body['expiry_date'] = $user->expiration_date->format('Y-m');
@ -388,6 +389,7 @@ class iLinkTransactionController extends Controller
$body['card_number'] = $user->numero_carte; $body['card_number'] = $user->numero_carte;
$body['cvv'] = $request->cvv; $body['cvv'] = $request->cvv;
$body['expiry_date'] = $user->expiration_date->format('Y-m'); $body['expiry_date'] = $user->expiration_date->format('Y-m');
// dd($body);
$response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]);
$code = $response->getStatusCode(); $code = $response->getStatusCode();
@ -486,7 +488,10 @@ class iLinkTransactionController extends Controller
if ($transaction->montant_net == $request->montant) { if ($transaction->montant_net == $request->montant) {
$transactionRetrait = $transaction->replicate(); $transactionRetrait = $transaction->replicate();
$transactionRetrait->id = null; $transactionRetrait->id = null;
$transactionRetrait->type = $request->type;
$transactionRetrait->id_transaction = $this->getTransactionID(); $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_ag = floatval($transaction->frais * $config->taux_com_ag_retrait_cash / 100);
$transactionRetrait->commission_sup = floatval($transaction->frais * $config->taux_com_sup_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; $walletAgent->balance_com += $transactionRetrait->commission_ag;
$walletSuperviseur->balance_com += $transactionRetrait->commission_sup; $walletSuperviseur->balance_com += $transactionRetrait->commission_sup;
$walletHyperviseur->balance_com -= ( $transactionRetrait->commission_ag + $transactionRetrait->commission_sup); $walletHyperviseur->balance_com -= ( $transactionRetrait->commission_ag + $transactionRetrait->commission_sup);
$transactionRetrait->status_retrait = $transaction->status_retrait = 1; $transactionRetrait->id_wallet_ag = $walletAgent->id;
$transactionRetrait->date_retrait = $transaction->date_retrait = new \DateTime(); $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(); $transactionRetrait->date = new \DateTime();
$walletAgent->save(); $walletAgent->save();
$walletSuperviseur->save(); $walletSuperviseur->save();
@ -505,9 +516,8 @@ class iLinkTransactionController extends Controller
$transactionRetrait->save(); $transactionRetrait->save();
$message = trans('messages.successful_agent_remove_cash', $message = trans('messages.successful_agent_remove_cash',
['id_transaction' => $transactionRetrait->id_transaction, 'amount' => $this->toMoney($request->montant, $init_country), ['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), 'code' => wordwrap($request->code_retrait, 4, ' ', true), 'id_transaction_retrait' => $transaction->id_transaction]);
'id_transaction_retrait' => $transaction->id_transaction]); $this->sendMail($emailEmetteur, trans('messages.successful_transaction'), $message);
$this->sendMail($agent->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 { } else {
return $this->errorResponse(trans('errors.incorrect_withdrawal_amount')); return $this->errorResponse(trans('errors.incorrect_withdrawal_amount'));
@ -537,13 +547,13 @@ class iLinkTransactionController extends Controller
$frais = floatval($request->montant * $config->taux_com_wallet_ag_carte_cash / 100); $frais = floatval($request->montant * $config->taux_com_wallet_ag_carte_cash / 100);
$montantRetrait = $transaction->montant + $frais; $montantRetrait = $transaction->montant + $frais;
$transaction->montant_net = $montantRetrait; $transaction->montant_net = $montantRetrait;
$body['amount'] = $montantRetrait; $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country);
$body['card_number'] = $request->numero_carte; $body['card_number'] = $request->numero_carte;
$body['cvv'] = $request->cvv; $body['cvv'] = $request->cvv;
$body['expiry_date'] = $expiration_date->format('Y-m'); $body['expiry_date'] = $expiration_date->format('Y-m');
// $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]);
$code = 200; // $response->getStatusCode(); $code = $response->getStatusCode();
if ($code == 200) { if ($code == 200) {
$banqueCommission = floatval($frais * $config->taux_com_banque_retrait_carte_cash / 100); $banqueCommission = floatval($frais * $config->taux_com_banque_retrait_carte_cash / 100);
@ -558,7 +568,7 @@ class iLinkTransactionController extends Controller
$agentCommission = floatval($frais * $config->taux_com_ag_retrait_carte_cash / 100); $agentCommission = floatval($frais * $config->taux_com_ag_retrait_carte_cash / 100);
$superviseurCommission = floatval($frais * $config->taux_com_sup_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; $walletAgent->balance_com += $agentCommission;
$transaction->commission_ag = $agentCommission; $transaction->commission_ag = $agentCommission;
@ -574,6 +584,7 @@ class iLinkTransactionController extends Controller
$walletAgent->save(); $walletAgent->save();
$walletSuperviseur->save(); $walletSuperviseur->save();
$walletHyperviseur->save(); $walletHyperviseur->save();
$transaction->id_transaction = $this->getTransactionID();
$transaction->save(); $transaction->save();
return $this->successResponse(trans('messages.successful_transaction')); return $this->successResponse(trans('messages.successful_transaction'));
@ -588,11 +599,15 @@ class iLinkTransactionController extends Controller
$this->validate($request, $transaction->cash_wallet_rules()); $this->validate($request, $transaction->cash_wallet_rules());
$agent = AgentPlus::findOrFail($network_agent->agent_id); $agent = AgentPlus::findOrFail($network_agent->agent_id);
if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) { if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) {
$user = User::where('user_code', $request->user_code)->firstOrFail(); $user = User::where('user_code', $request->user_code)->first();
$walletUser = WalletsUser::where('idUser', $user->id)->firstOrFail(); 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); $walletUser = WalletsUser::where('idUser', $user->id)->firstOrFail();
$taxe = ($request->init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais); $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; $montantDepot = $request->montant - $frais - $taxe;
$transaction->montant_net = $montantDepot; $transaction->montant_net = $montantDepot;
$walletUser->balance += $montantDepot; $walletUser->balance += $montantDepot;
@ -618,11 +633,12 @@ class iLinkTransactionController extends Controller
$transaction->id_wallet_sup = $walletSuperviseur->id; $transaction->id_wallet_sup = $walletSuperviseur->id;
$transaction->id_wallet_hyp = $walletHyperviseur->id; $transaction->id_wallet_hyp = $walletHyperviseur->id;
$transaction->save(); $transaction->save();
$this->sendMail($user->email, trans('messages.successful_transaction'), trans('messages.successful_deposit_ilink', $message = 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), ['id_transaction' => $transaction->id, 'amount' => $this->toMoney($transaction->montant, $init_country), 'net_init' => $this->toMoney($montantDepot, $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), '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])); 'user_code' => $request->user_code]);
return $this->successResponse(trans('messages.successful_transaction')); $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')); return $this->errorResponse(trans('messages.incorrect_user_password'));
} }
@ -915,15 +931,25 @@ class iLinkTransactionController extends Controller
public function getTransactionRetrait(Request $request){ public function getTransactionRetrait(Request $request){
$this->validate($request, [ $this->validate($request, [
'id_transaction' =>'required', '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', $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) if(!$transaction)
return $this->errorResponse(trans('errors.transaction_not_exist'), Response::HTTP_NOT_FOUND); return $this->errorResponse(trans('errors.transaction_not_exist'), Response::HTTP_NOT_FOUND);
if ($transaction->status_retrait != 0) if ($transaction->status_retrait != 0)
return $this->errorResponse(trans('errors.withdrawal_already_made')); 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(); $data = $transaction->replicate();
if($transaction->type == 9){ if($transaction->type == 9){
$data->nom_destinataire = $transaction->wallet_user->user->lastname; $data->nom_destinataire = $transaction->wallet_user->user->lastname;

View File

@ -54,4 +54,9 @@ class NetworksAgent extends Model
{ {
return $this->hasMany(Wallet::class, 'id_networkAgent'); return $this->hasMany(Wallet::class, 'id_networkAgent');
} }
public function network()
{
return $this->belongsTo(Network::class, 'network_id');
}
} }

View File

@ -178,8 +178,8 @@ class WalletIlinkTransaction extends Model
{ {
return [ return [
'user_code'=>'required', 'user_code'=>'required',
'init_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', // 'final_country' =>'required|integer|min:0|not_in:0',
]; ];
} }
@ -187,8 +187,8 @@ class WalletIlinkTransaction extends Model
{ {
return [ return [
'numero_carte'=>'required', 'numero_carte'=>'required',
'cvv'=>'required_if:facade,front|size:3', 'cvv'=>'required|size:3',
'expiration_date'=>'required_if:facade,front|date_format:m/y|after_or_equal:today', 'expiration_date'=>'required|date_format:m/y|after_or_equal:today',
]; ];
} }

View File

@ -18,4 +18,5 @@ return [
'withdrawal_already_made' => 'Withdrawal already made', 'withdrawal_already_made' => 'Withdrawal already made',
'invalid_withdrawal_code' => 'Invalid withdrawal code', 'invalid_withdrawal_code' => 'Invalid withdrawal code',
'incorrect_withdrawal_amount'=> 'Incorrect withdrawal amount', 'incorrect_withdrawal_amount'=> 'Incorrect withdrawal amount',
'operation_cannot_performed_in_country' => 'This operation cannot be performed in this country',
]; ];

View File

@ -18,4 +18,5 @@ return [
'withdrawal_already_made' => 'Retrait déjà éffectuée', 'withdrawal_already_made' => 'Retrait déjà éffectuée',
'invalid_withdrawal_code' => 'Code de retrait invalide', 'invalid_withdrawal_code' => 'Code de retrait invalide',
'incorrect_withdrawal_amount'=> 'Montant de retrait incorrect', 'incorrect_withdrawal_amount'=> 'Montant de retrait incorrect',
'operation_cannot_performed_in_country' => 'Cette operation ne peut pas etre effectuée dans ce pays',
]; ];

View File

@ -107,11 +107,10 @@ Informations de la transaction :
- Code utilisateur : :sender_code - Code utilisateur : :sender_code
- Numero de la carte : :cart_number - Numero de la carte : :cart_number
- Code de retrait : :code', - 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 : Informations de la transaction :
- Numéro : :id_transaction - Numéro : :id_transaction
- Montant de retrait : :amount - Montant de retrait : :amount
- Votre commission : :commission
- Numero de transaction de retrait : :id_transaction_retrait - Numero de transaction de retrait : :id_transaction_retrait
- Code de retrait : :code' - Code de retrait : :code'
]; ];