+ 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)) {
$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 sapplique sur les frais minimum) et créditer
//pour le dépôt qui sapplique 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;

View File

@ -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');
}
}

View File

@ -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',
];
}

View File

@ -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',
];

View File

@ -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',
];

View File

@ -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'
];