+ Fix bug

This commit is contained in:
Djery-Tom 2020-07-03 19:24:41 +01:00
parent 0a10771c11
commit 6189c78de8
1 changed files with 36 additions and 38 deletions

View File

@ -223,9 +223,9 @@ class iLinkTransactionController extends Controller
if ($code == 200) {
$walletUser->balance -= $transaction->montant;
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
$transaction->commission_banque = $frais * $config->taux_com_banque_envoi_wallet_carte_ilink / 100 ;
$transaction->commission_banque = $frais * $config->taux_com_banque_envoi_wallet_carte_ilink / 100;
$transaction->commission_hyp = $frais * $config->taux_com_hyp_envoi_wallet_carte_ilink / 100 ;
$transaction->commission_hyp = $frais * $config->taux_com_hyp_envoi_wallet_carte_ilink / 100;
$walletHyperviseur->balance_com += $transaction->commission_hyp;
$transaction->id_wallet_hyp = $walletHyperviseur->id;
$transaction->frais = $frais;
@ -270,7 +270,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->commission_hyp_final_country = $this->toMoneyAmount($transaction->commission_hyp, $init_country, $request->final_country);
$transaction->commission_hyp_final_country = $this->toMoneyAmount($transaction->commission_hyp, $init_country, $request->final_country);
$transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country);
if (isset($reseauPayeur))
$reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country;
@ -363,7 +363,7 @@ class iLinkTransactionController extends Controller
$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),
'sender_code' => $user->user_code , 'init_country' => $this->getCountryName($init_country),]);
'sender_code' => $user->user_code, 'init_country' => $this->getCountryName($init_country),]);
$this->sendMail($user->email, trans('messages.successful_transaction'), $message);
return $this->successResponse($message . trans('messages.sent_by_mail'));
}
@ -482,12 +482,12 @@ class iLinkTransactionController extends Controller
$this->validate($request, $transaction->remove_cash_rules());
$agent = AgentPlus::findOrFail($network_agent->agent_id);
if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) {
$transaction = WalletIlinkTransaction::where('id_transaction',$request->id_transaction)->first();
$transaction = WalletIlinkTransaction::where('id_transaction', $request->id_transaction)->first();
if ($transaction) {
if ($transaction->status_retrait == 0) {
//Verifier que le pays de destinatation correspond au pays de retrait
if($transaction->type != 11)
if($init_country != $transaction->final_country)
if ($transaction->type != 11)
if ($init_country != $transaction->final_country)
return $this->errorResponse(trans('errors.operation_cannot_performed_in_country'));
if ($this->checkPassword($request->code_retrait, $transaction->encrypted_code_retrait, $transaction->code_retrait_salt)) {
$montantNet = $transaction->type == 11 ? $transaction->montant_net : $transaction->montant_net_final_country;
@ -501,12 +501,12 @@ class iLinkTransactionController extends Controller
$emailEmetteur = $transaction->wallet_user ? $transaction->wallet_user->user->email : $transaction->email_emetteur;
$transactionRetrait->commission_ag = floatval($commissionHyp * $config->taux_com_ag_retrait_cash / 100);
$transactionRetrait->commission_sup = floatval($commissionHyp * $config->taux_com_sup_retrait_cash / 100);
$transactionRetrait->commission_sup = floatval($commissionHyp * $config->taux_com_sup_retrait_cash / 100);
$transactionRetrait->commission_hyp = $commissionHyp - $transactionRetrait->commission_ag - $transactionRetrait->commission_sup;
$walletAgent->balance_princ += $montantNet;
$walletAgent->balance_com += $transactionRetrait->commission_ag;
$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->id_wallet_ag = $walletAgent->id;
$transactionRetrait->id_wallet_sup = $walletSuperviseur->id;
$transactionRetrait->id_wallet_hyp = $walletHyperviseur->id;
@ -523,7 +523,7 @@ 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),
'code' => wordwrap($request->code_retrait, 4, ' ', true), 'id_transaction_retrait' => $transaction->id_transaction]);
'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 {
@ -607,14 +607,14 @@ class iLinkTransactionController extends Controller
$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)->first();
if(!$user)
if (!$user)
return $this->errorResponse(trans('errors.wallet_not_defined'));
$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);
$taxe = ($init_country != $final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
$montantDepot = $request->montant - $frais - $taxe;
$transaction->montant_net = $montantDepot;
$transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $final_country);
@ -653,27 +653,23 @@ class iLinkTransactionController extends Controller
}
break;
case 15: // Agent - Envoi de cash vers autre wallet
$this->validate($request, array_merge($transaction->cash_cash_rules(),[
'network_destinataire'=>'required|integer|min:0|not_in:0'
$this->validate($request, array_merge($transaction->cash_cash_rules(), [
'network_destinataire' => 'required|integer|min:0|not_in:0'
]));
$agent = AgentPlus::findOrFail($network_agent->agent_id);
if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) {
if ($request->montant > $walletAgent->balance_princ)
return $this->errorResponse(trans('errors.insufficient_balance'));
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_agent_depot_autre_wallet, $request->montant) : $this->calculateFees($plr_agent_depot_autre_wallet_national, $request->montant);
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
$montantDepot = $request->montant - $frais - $taxe;
$transaction->montant_net = $montantDepot;
$transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $request->final_country);
if ($init_country != $request->final_country) {
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->firstOrFail();
$transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100;
$transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur;
} else {
$transaction->part_reseau_payeur = 0;
$transaction->part_reseau_emetteur = $frais;
}
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->firstOrFail();
$transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100;
$transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur;
$transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country);
if (isset($reseauPayeur))
$reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country;
@ -819,12 +815,12 @@ class iLinkTransactionController extends Controller
$walletHyperviseur->save();
$transaction->id_transaction = $this->getTransactionID();
$transaction->save();
$message = trans('messages.successful_agent_send_cash',
$message = trans('messages.successful_agent_send_cash',
['sender_name' => $request->prenom_emetteur . ' ' . $request->nom_emetteur, 'receiver_name' => $request->prenom_destinataire . ' ' . $request->nom_destinataire,
'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)]);
$this->sendMail($request->email_emetteur, trans('messages.successful_transaction'),$message);
'final_country' => $this->getCountryName($request->final_country), 'code' => wordwrap($code_retrait, 4, ' ', true)]);
$this->sendMail($request->email_emetteur, trans('messages.successful_transaction'), $message);
return $this->successResponse($message . trans('messages.sent_by_mail'));
} else {
return $this->errorResponse(trans('messages.incorrect_user_password'));
@ -981,12 +977,12 @@ class iLinkTransactionController extends Controller
'user_code' => 'required',
]);
$user = User::where('user_code', $request->user_code)->first();
if(!$user)
if (!$user)
return $this->errorResponse(trans('errors.wallet_not_defined'));
$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);
$data['frais'] = $frais +$taxe;
$taxe = ($init_country != $final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
$data['frais'] = $frais + $taxe;
$data['montant_net_init'] = $request->montant - $frais - $taxe;
$data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $final_country);
return $this->successResponse($data);
@ -996,7 +992,7 @@ class iLinkTransactionController extends Controller
'final_country' => 'required|integer|min:0|not_in:0',
]);
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_agent_depot_autre_wallet, $request->montant) : $this->calculateFees($plr_agent_depot_autre_wallet_national, $request->montant);
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
$data['frais'] = $frais + $taxe;
$data['montant_net_init'] = $request->montant - $frais - $taxe;
$data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $request->final_country);
@ -1023,15 +1019,16 @@ class iLinkTransactionController extends Controller
}
public function getTransactionRetrait(Request $request){
public function getTransactionRetrait(Request $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',
'id_wallet_user','init_country' , 'final_country')->where('id_transaction',$request->id_transaction)->first();
$transaction = WalletIlinkTransaction::select('nom_destinataire', 'prenom_destinataire', 'type_document_destinataire', 'id_document_destinataire', 'type',
'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);
if ($transaction->status_retrait != 0)
@ -1040,17 +1037,18 @@ class iLinkTransactionController extends Controller
$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)
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){
if (in_array($transaction->type, [9, 11])) {
$data->nom_destinataire = $transaction->wallet_user->user->lastname;
$data->prenom_destinataire = $transaction->wallet_user->user->firstname;
$data->user_code = $transaction->wallet_user->user->user_code;
}
unset($data->type, $data->init_country, $data->final_country, $data->id_wallet_user);
return $this->successResponse($data);
}