|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|
|
|
use App\Models\AgentPlus;
|
|
|
|
use App\Models\AgentPlus;
|
|
|
|
use App\Models\CodeGenerer;
|
|
|
|
use App\Models\CodeGenerer;
|
|
|
|
use App\Models\ConfigWallet;
|
|
|
|
use App\Models\ConfigWallet;
|
|
|
|
|
|
|
|
use App\Models\Country;
|
|
|
|
use App\Models\NetworksAgent;
|
|
|
|
use App\Models\NetworksAgent;
|
|
|
|
use App\Models\PayingNetwork;
|
|
|
|
use App\Models\PayingNetwork;
|
|
|
|
use App\Models\TypeIlinkTransaction;
|
|
|
|
use App\Models\TypeIlinkTransaction;
|
|
|
@ -44,7 +45,6 @@ class iLinkTransactionController extends Controller
|
|
|
|
'type' => 'required|integer|min:0|not_in:0',
|
|
|
|
'type' => 'required|integer|min:0|not_in:0',
|
|
|
|
'id_wallet_agent' => 'required_without:id_wallet_user|integer|min:0|not_in:0',
|
|
|
|
'id_wallet_agent' => 'required_without:id_wallet_user|integer|min:0|not_in:0',
|
|
|
|
'id_wallet_user' => 'required_without:id_wallet_agent|integer|min:0|not_in:0',
|
|
|
|
'id_wallet_user' => 'required_without:id_wallet_agent|integer|min:0|not_in:0',
|
|
|
|
'id_network' => 'required_with:id_wallet_user|integer|min:0|not_in:0',
|
|
|
|
|
|
|
|
'password' => 'required',
|
|
|
|
'password' => 'required',
|
|
|
|
'montant' => 'required|numeric|min:0|not_in:0',
|
|
|
|
'montant' => 'required|numeric|min:0|not_in:0',
|
|
|
|
]);
|
|
|
|
]);
|
|
|
@ -66,9 +66,19 @@ class iLinkTransactionController extends Controller
|
|
|
|
$walletSuperviseur = Wallet::findOrFail($wallet_agent_sup->wallet_id);
|
|
|
|
$walletSuperviseur = Wallet::findOrFail($wallet_agent_sup->wallet_id);
|
|
|
|
$walletHyperviseur = Wallet::findOrFail($wallet_agent_hyp->wallet_id);
|
|
|
|
$walletHyperviseur = Wallet::findOrFail($wallet_agent_hyp->wallet_id);
|
|
|
|
} elseif (isset($request->id_wallet_user)) {
|
|
|
|
} elseif (isset($request->id_wallet_user)) {
|
|
|
|
$config = ConfigWallet::where('id_network', $request->id_network)->firstOrFail();
|
|
|
|
$walletUser = WalletsUser::findOrFail($request->id_wallet_user);
|
|
|
|
|
|
|
|
$transaction->init_country = $init_country = $walletUser->user->network->country->id;
|
|
|
|
|
|
|
|
$result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network')
|
|
|
|
|
|
|
|
->where('networks.country_id', $init_country)->where('configWallet.type', 'ilink')
|
|
|
|
|
|
|
|
->select('configWallet.id')->first();
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
|
|
|
|
$config = ConfigWallet::findOrFail($result->id);
|
|
|
|
|
|
|
|
$transaction->network_emetteur = $config->id_network;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return $this->errorResponse(trans('errors.no_ilink_network'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$hyperviseur = AgentPlus::where('category', 'hyper')->where('network_id', $request->id_network)->firstOrFail();
|
|
|
|
$hyperviseur = AgentPlus::where('category', 'hyper')->where('network_id', $config->id_network)->firstOrFail();
|
|
|
|
$wallet_agent_hyp = WalletAgent::where('agent_id', $hyperviseur->id)->firstOrFail();
|
|
|
|
$wallet_agent_hyp = WalletAgent::where('agent_id', $hyperviseur->id)->firstOrFail();
|
|
|
|
$walletHyperviseur = Wallet::findOrFail($wallet_agent_hyp->wallet_id);
|
|
|
|
$walletHyperviseur = Wallet::findOrFail($wallet_agent_hyp->wallet_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -110,43 +120,48 @@ class iLinkTransactionController extends Controller
|
|
|
|
switch ($type->id) {
|
|
|
|
switch ($type->id) {
|
|
|
|
case 1: //User - Envoi wallet à wallet
|
|
|
|
case 1: //User - Envoi wallet à wallet
|
|
|
|
$this->validate($request, $transaction->send_wallet_wallet_rules());
|
|
|
|
$this->validate($request, $transaction->send_wallet_wallet_rules());
|
|
|
|
$walletUser = WalletsUser::findOrFail($request->id_wallet_user);
|
|
|
|
$user = $walletUser->user;
|
|
|
|
$user = User::findOrFail($walletUser->idUser);
|
|
|
|
|
|
|
|
if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
|
|
|
if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
|
|
|
if($request->montant > $walletUser->balance){
|
|
|
|
if ($request->montant > $walletUser->balance) {
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
$transaction->frais = $frais = ($request->init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_wallet, $request->montant) : $this->calculateFees($plr_user_wallet_wallet_national, $request->montant);
|
|
|
|
$transaction->frais = $frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_wallet, $request->montant) : $this->calculateFees($plr_user_wallet_wallet_national, $request->montant);
|
|
|
|
$transaction->taxe = $taxe = ($request->init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
|
|
|
$transaction->taxe = $taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
|
|
|
$transaction->montant_depot = $montantDepot = $transaction->montant - $frais - $taxe;
|
|
|
|
$transaction->montant_depot = $montantDepot = $transaction->montant - $frais - $taxe;
|
|
|
|
$configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
|
|
|
|
$configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
|
|
|
|
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->firstOrFail();
|
|
|
|
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->firstOrFail();
|
|
|
|
if($request->init_country != $request->final_country){
|
|
|
|
if ($init_country != $request->final_country) {
|
|
|
|
$transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100;
|
|
|
|
$transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100;
|
|
|
|
$transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur;
|
|
|
|
$transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur;
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
$transaction->part_reseau_payeur = 0;
|
|
|
|
$transaction->part_reseau_payeur = 0;
|
|
|
|
$transaction->part_reseau_emetteur = $frais;
|
|
|
|
$transaction->part_reseau_emetteur = $frais;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$transaction->commission_hyp = $transaction->part_reseau_emetteur;
|
|
|
|
$transaction->commission_hyp = $transaction->part_reseau_emetteur;
|
|
|
|
$reseauPayeur->balance_com += $transaction->part_reseau_payeur;
|
|
|
|
$reseauPayeur->balance_com += $transaction->part_reseau_payeur;
|
|
|
|
if ($configPayeur->type == 'ilink') {
|
|
|
|
if ($configPayeur->type == 'ilink') {
|
|
|
|
$walletHyperviseur->balance_com += $transaction->part_reseau_emetteur;
|
|
|
|
|
|
|
|
$destinataire = User::where('user_code', $request->id_destinataire)->first();
|
|
|
|
$destinataire = User::where('user_code', $request->id_destinataire)->first();
|
|
|
|
if($destinataire) { // Si c'est un wallet ilink
|
|
|
|
if ($destinataire) { // Si c'est un wallet ilink
|
|
|
|
|
|
|
|
if ($destinataire->network->country->id == $request->final_country) {
|
|
|
|
$walletDestinataire = WalletsUser::where('idUser', $destinataire->id)->firstOrFail();
|
|
|
|
$walletDestinataire = WalletsUser::where('idUser', $destinataire->id)->firstOrFail();
|
|
|
|
$walletDestinataire->balance += $montantDepot;
|
|
|
|
$walletDestinataire->balance += $montantDepot;
|
|
|
|
$walletDestinataire->save();
|
|
|
|
$walletDestinataire->save();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$country = Country::findOrFail($request->final_country);
|
|
|
|
|
|
|
|
return $this->errorResponse(trans('errors.wallet_country_not_match', ['country' => $country->name]));
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return $this->errorResponse(trans('errors.wallet_not_defined'));
|
|
|
|
return $this->errorResponse(trans('errors.wallet_not_defined'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$walletHyperviseur->balance_com += $transaction->part_reseau_emetteur;
|
|
|
|
$walletUser->balance -= $transaction->montant;
|
|
|
|
$walletUser->balance -= $transaction->montant;
|
|
|
|
|
|
|
|
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
|
|
|
//Hyperviseur payeur
|
|
|
|
//Hyperviseur payeur
|
|
|
|
$hyperviseurPayeur = AgentPlus::where('category', 'hyper')->where('network_id', $request->network_destinataire)->firstOrFail();
|
|
|
|
$hyperviseurPayeur = AgentPlus::where('category', 'hyper')->where('network_id', $request->network_destinataire)->firstOrFail();
|
|
|
|
if($hyperviseurPayeur->id == $hyperviseur->id){ //Si c'est le reseau payeur est aussi emetteur
|
|
|
|
if ($hyperviseurPayeur->id == $hyperviseur->id) { //Si c'est le reseau payeur est aussi emetteur
|
|
|
|
$walletHyperviseur->balance_com += $transaction->part_reseau_payeur;
|
|
|
|
$walletHyperviseur->balance_com += $transaction->part_reseau_payeur;
|
|
|
|
$reseauPayeur->balance_com += $transaction->part_reseau_emetteur;
|
|
|
|
$reseauPayeur->balance_com += $transaction->part_reseau_emetteur;
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
$wallet_agent_hypPayeur = WalletAgent::where('agent_id', $hyperviseurPayeur->id)->firstOrFail();
|
|
|
|
$wallet_agent_hypPayeur = WalletAgent::where('agent_id', $hyperviseurPayeur->id)->firstOrFail();
|
|
|
|
$walletHyperviseurPayeur = Wallet::findOrFail($wallet_agent_hypPayeur->wallet_id);
|
|
|
|
$walletHyperviseurPayeur = Wallet::findOrFail($wallet_agent_hypPayeur->wallet_id);
|
|
|
|
$walletHyperviseurPayeur->balance_com += $transaction->part_reseau_payeur;
|
|
|
|
$walletHyperviseurPayeur->balance_com += $transaction->part_reseau_payeur;
|
|
|
@ -163,9 +178,9 @@ class iLinkTransactionController extends Controller
|
|
|
|
$reseauPayeur->save();
|
|
|
|
$reseauPayeur->save();
|
|
|
|
$transaction->save();
|
|
|
|
$transaction->save();
|
|
|
|
$this->sendMail($user->email, trans('messages.successful_transaction'), trans('messages.successful_user_send_to_wallet',
|
|
|
|
$this->sendMail($user->email, trans('messages.successful_transaction'), trans('messages.successful_user_send_to_wallet',
|
|
|
|
['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->convertMoney($montantDepot, $request->init_country, $request->final_country), 'fees' => $this->toMoney($frais + $taxe, $request->init_country),
|
|
|
|
'net_final' => $this->convertMoney($montantDepot, $init_country, $request->final_country), 'fees' => $this->toMoney($frais + $taxe, $init_country),
|
|
|
|
'init_country'=>$this->getCountryName($request->init_country) , 'final_country'=>$this->getCountryName($request->final_country),
|
|
|
|
'init_country' => $this->getCountryName($init_country), 'final_country' => $this->getCountryName($request->final_country),
|
|
|
|
'sender_code' => $user->user_code, 'receiver_code' => $transaction->id_destinataire]));
|
|
|
|
'sender_code' => $user->user_code, 'receiver_code' => $transaction->id_destinataire]));
|
|
|
|
return $this->successResponse(trans('messages.successful_transaction'));
|
|
|
|
return $this->successResponse(trans('messages.successful_transaction'));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -175,8 +190,7 @@ class iLinkTransactionController extends Controller
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 2: //User - Envoi de wallet à carte
|
|
|
|
case 2: //User - Envoi de wallet à carte
|
|
|
|
$this->validate($request, $transaction->card_rules());
|
|
|
|
$this->validate($request, $transaction->card_rules());
|
|
|
|
$walletUser = WalletsUser::findOrFail($request->id_wallet_user);
|
|
|
|
$user = $walletUser->user;
|
|
|
|
$user = User::findOrFail($walletUser->idUser);
|
|
|
|
|
|
|
|
if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
|
|
|
if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
|
|
|
if ($request->montant > $walletUser->balance) {
|
|
|
|
if ($request->montant > $walletUser->balance) {
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
|
|
@ -208,8 +222,8 @@ class iLinkTransactionController extends Controller
|
|
|
|
$walletUser->save();
|
|
|
|
$walletUser->save();
|
|
|
|
$transaction->save();
|
|
|
|
$transaction->save();
|
|
|
|
$this->sendMail($user->email, trans('messages.successful_transaction'), trans('messages.successful_user_send_to_cart',
|
|
|
|
$this->sendMail($user->email, trans('messages.successful_transaction'), trans('messages.successful_user_send_to_cart',
|
|
|
|
['id_transaction' => $transaction->id, 'amount' => $this->toMoneyWithNetwork($transaction->montant, $request->id_network),
|
|
|
|
['id_transaction' => $transaction->id, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
|
|
|
'net' => $this->toMoneyWithNetwork($montantDepot, $request->id_network), 'fees' => $this->toMoneyWithNetwork($frais, $request->id_network),
|
|
|
|
'net' => $this->toMoney($montantDepot, $init_country), 'fees' => $this->toMoney($frais, $init_country),
|
|
|
|
'sender_code' => $user->user_code, 'cart_number' => wordwrap($request->numero_carte, 4, ' ', true)]));
|
|
|
|
'sender_code' => $user->user_code, 'cart_number' => wordwrap($request->numero_carte, 4, ' ', true)]));
|
|
|
|
return $this->successResponse(trans('messages.successful_transaction'));
|
|
|
|
return $this->successResponse(trans('messages.successful_transaction'));
|
|
|
|
|
|
|
|
|
|
|
@ -217,7 +231,7 @@ class iLinkTransactionController extends Controller
|
|
|
|
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{
|
|
|
|
} else {
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -535,40 +549,108 @@ class iLinkTransactionController extends Controller
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function lastTransactions($id_wallet)
|
|
|
|
public function lastUserTransactions($id_wallet_user)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$transactions = WalletTransaction::where('id_wallet', $id_wallet)->orderBy('date', 'desc')->limit(10)
|
|
|
|
$transactions = DB::select('SELECT tit.nom as operation , tit.type ,tit.acteur as source , wit.montant ,
|
|
|
|
->get(['type', DB::raw('\'wallet\' as source'), 'montant', 'numCarte AS destinataire', 'date', 'id']);
|
|
|
|
CASE
|
|
|
|
|
|
|
|
WHEN u.lastname IS NOT NULL THEN u.lastname
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
|
|
|
|
CASE
|
|
|
|
|
|
|
|
WHEN wit.id_destinataire IS NULL THEN wit.nom_destinataire
|
|
|
|
|
|
|
|
ELSE wit.id_destinataire
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
END AS destinataire , wit.date , wit.id FROM wallet_ilink_transaction wit
|
|
|
|
|
|
|
|
INNER JOIN type_ilink_transaction tit ON wit.type = tit.id LEFT JOIN users u ON u.user_code = wit.id_destinataire WHERE wit.id_wallet_user = :id_wallet
|
|
|
|
|
|
|
|
ORDER BY wit.date DESC LIMIT 10;',['id_wallet', $id_wallet_user]);
|
|
|
|
|
|
|
|
return $this->successResponse($transactions);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function lastAgentTransactions($id_wallet_agent)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$transactions = DB::select('SELECT tit.nom as operation , tit.type ,tit.acteur as source , wit.montant ,
|
|
|
|
|
|
|
|
CASE
|
|
|
|
|
|
|
|
WHEN u.lastname IS NOT NULL THEN u.lastname
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
|
|
|
|
CASE
|
|
|
|
|
|
|
|
WHEN wit.id_destinataire IS NULL THEN wit.nom_destinataire
|
|
|
|
|
|
|
|
ELSE wit.id_destinataire
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
END AS destinataire , wit.date , wit.id FROM wallet_ilink_transaction wit
|
|
|
|
|
|
|
|
INNER JOIN type_ilink_transaction tit ON wit.type = tit.id LEFT JOIN users u ON u.user_code = wit.id_destinataire WHERE wit.id_wallet_ag = :id_wallet
|
|
|
|
|
|
|
|
ORDER BY wit.date DESC LIMIT 10;',['id_wallet', $id_wallet_agent]);
|
|
|
|
return $this->successResponse($transactions);
|
|
|
|
return $this->successResponse($transactions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function calculateCommission(Request $request)
|
|
|
|
public function calculateCommission(Request $request)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
$rules = [
|
|
|
|
'id_wallet' => 'required|integer|min:1',
|
|
|
|
'type' => 'required|integer|min:0|not_in:0',
|
|
|
|
|
|
|
|
'id_wallet_agent' => 'required_without:id_wallet_user|integer|min:0|not_in:0',
|
|
|
|
|
|
|
|
'id_wallet_user' => 'required_without:id_wallet_agent|integer|min:0|not_in:0',
|
|
|
|
'montant' => 'required|numeric|min:0|not_in:0',
|
|
|
|
'montant' => 'required|numeric|min:0|not_in:0',
|
|
|
|
'type' => 'required|in:credit,debit',
|
|
|
|
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
$this->validate($request, $rules);
|
|
|
|
$this->validate($request, $rules);
|
|
|
|
|
|
|
|
if (isset($request->id_wallet_agent)) {
|
|
|
|
$walletAgent = Wallet::findOrFail($request->get('id_wallet'));
|
|
|
|
$walletAgent = Wallet::findOrFail($request->get('id_wallet_agent'));
|
|
|
|
$network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent);
|
|
|
|
$network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent);
|
|
|
|
// 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();
|
|
|
|
$commission = null;
|
|
|
|
|
|
|
|
if ($request->type == 'credit') {
|
|
|
|
} else {
|
|
|
|
//Depot
|
|
|
|
$walletUser = WalletsUser::findOrFail($request->id_wallet_user);
|
|
|
|
$commission = ($request->montant * $config->taux_com_client_depot / 100) + $config->frais_min_banque_depot;
|
|
|
|
$init_country = $walletUser->user->network->country->id;
|
|
|
|
$data['montant_calcule'] = $request->montant - $commission;
|
|
|
|
$result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network')
|
|
|
|
} elseif ($request->type == 'debit') {
|
|
|
|
->where('networks.country_id', $init_country)->where('configWallet.type', 'ilink')
|
|
|
|
// Retrait
|
|
|
|
->select('configWallet.id')->first();
|
|
|
|
$commission = $request->montant * $config->taux_com_client_retrait / 100;
|
|
|
|
if ($result) {
|
|
|
|
$data['montant_calcule'] = $request->montant + $commission;
|
|
|
|
$config = ConfigWallet::findOrFail($result->id);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return $this->errorResponse(trans('errors.no_ilink_network'));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$data['commission'] = $commission;
|
|
|
|
$taxesNationales = array_values(array_filter($config->taxes->all(), function ($tax) {
|
|
|
|
|
|
|
|
return $tax->destination == 'national';
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$taxesInternationales = array_values(array_filter($config->taxes->all(), function ($tax) {
|
|
|
|
|
|
|
|
return $tax->destination == 'international';
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$plr_user_wallet_wallet = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_wallet_international");
|
|
|
|
|
|
|
|
$plr_user_wallet_cash = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_cash_international");
|
|
|
|
|
|
|
|
$plr_agent_depot_wallet_ilink = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_wallet_ilink_international");
|
|
|
|
|
|
|
|
$plr_agent_depot_autre_wallet = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_autre_wallet_international");
|
|
|
|
|
|
|
|
$plr_agent_cash_cash = $this->getPaliers($config->paliers_config_wallets->all(), "agent_cash_cash_international");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$plr_user_wallet_wallet_national = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_wallet_national");
|
|
|
|
|
|
|
|
$plr_user_wallet_cash_national = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_cash_national");
|
|
|
|
|
|
|
|
$plr_agent_depot_wallet_ilink_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_wallet_ilink_national");
|
|
|
|
|
|
|
|
$plr_agent_depot_autre_wallet_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_autre_wallet_national");
|
|
|
|
|
|
|
|
$plr_agent_cash_cash_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_cash_cash_national");
|
|
|
|
|
|
|
|
switch ($request->type) {
|
|
|
|
|
|
|
|
case 1: //User - Envoi wallet à wallet
|
|
|
|
|
|
|
|
$this->validate($request, [
|
|
|
|
|
|
|
|
'final_country' => 'required|integer|min:0|not_in:0',
|
|
|
|
|
|
|
|
'id_destinataire' => 'required_without:phone_destinataire'
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_wallet, $request->montant) : $this->calculateFees($plr_user_wallet_wallet_national, $request->montant);
|
|
|
|
|
|
|
|
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
|
|
|
|
|
|
|
$destinataire = User::where('user_code', $request->id_destinataire)->first();
|
|
|
|
|
|
|
|
$data['destinataire'] = $destinataire ? $destinataire->lastname . ' ' . $destinataire->firstname : 'Inconnu';
|
|
|
|
|
|
|
|
$data['frais'] = $frais + $taxe;
|
|
|
|
|
|
|
|
$data['montant_net'] = $request->montant - $frais - $taxe;
|
|
|
|
return $this->successResponse($data);
|
|
|
|
return $this->successResponse($data);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: //User - Envoi de wallet à carte
|
|
|
|
|
|
|
|
$frais = $request->montant * $config->taux_com_user_wallet_carte / 100;
|
|
|
|
|
|
|
|
$data['frais'] = $frais;
|
|
|
|
|
|
|
|
$data['montant_net'] = $request->montant - $frais;
|
|
|
|
|
|
|
|
return $this->successResponse($data);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -583,9 +665,9 @@ class iLinkTransactionController extends Controller
|
|
|
|
private function calculateFees(array $paliers, $montant)
|
|
|
|
private function calculateFees(array $paliers, $montant)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$size = sizeof($paliers);
|
|
|
|
$size = sizeof($paliers);
|
|
|
|
|
|
|
|
if ($size > 0) {
|
|
|
|
$min = $paliers[0]->min;
|
|
|
|
$min = $paliers[0]->min;
|
|
|
|
$max = $size > 0 ? $paliers[$size - 1]->max : 0;
|
|
|
|
$max = $paliers[$size - 1]->max;
|
|
|
|
$palier = null;
|
|
|
|
$palier = null;
|
|
|
|
foreach ($paliers as $p) {
|
|
|
|
foreach ($paliers as $p) {
|
|
|
|
if ($montant >= $p->min && $montant <= $p->max) {
|
|
|
|
if ($montant >= $p->min && $montant <= $p->max) {
|
|
|
@ -604,6 +686,8 @@ class iLinkTransactionController extends Controller
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Calcul des taxes
|
|
|
|
//Calcul des taxes
|
|
|
|
private function calculateTax(array $taxes, $frais)
|
|
|
|
private function calculateTax(array $taxes, $frais)
|
|
|
|