feat: improve commission route to handle simulator
This commit is contained in:
parent
454c0254f2
commit
4c5b6a4aaf
|
@ -7,11 +7,13 @@ use App\Models\Agent;
|
||||||
use App\Models\AgentPlus;
|
use App\Models\AgentPlus;
|
||||||
use App\Models\Identification;
|
use App\Models\Identification;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Traits\Helper;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
|
use Helper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new controller instance.
|
* Create a new controller instance.
|
||||||
|
@ -131,17 +133,6 @@ class UserController extends Controller
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateRandomString($length = 10)
|
|
||||||
{
|
|
||||||
$characters = '23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ';
|
|
||||||
$charactersLength = strlen($characters);
|
|
||||||
$randomString = '';
|
|
||||||
for ($i = 0; $i < $length; $i++) {
|
|
||||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
||||||
}
|
|
||||||
return $randomString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function rattachCard(Request $request, $id_user)
|
public function rattachCard(Request $request, $id_user)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
|
|
|
@ -2221,13 +2221,27 @@ class iLinkTransactionController extends Controller
|
||||||
|
|
||||||
public function calculateCommission(Request $request)
|
public function calculateCommission(Request $request)
|
||||||
{
|
{
|
||||||
$rules = [
|
$this->validate($request, [
|
||||||
'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_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',
|
||||||
];
|
]);
|
||||||
$this->validate($request, $rules);
|
|
||||||
|
$simulator = $request->input('simulator', false); // only for simulator
|
||||||
|
|
||||||
|
if($simulator){
|
||||||
|
$this->validate($request, [
|
||||||
|
'init_country' => 'required|integer|exists:countries,id',
|
||||||
|
'final_country' => 'required|integer|exists:countries,id',
|
||||||
|
]);
|
||||||
|
$init_country = $request->input('init_country');
|
||||||
|
$final_country = $request->input('final_country');
|
||||||
|
}else{
|
||||||
|
$this->validate($request, [
|
||||||
|
'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',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -2237,22 +2251,25 @@ class iLinkTransactionController extends Controller
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$walletUser = WalletsUser::findOrFail($request->id_wallet_user);
|
if(empty($init_country)){
|
||||||
// Pour les operations à cartes, le pays initial c'est le pays de la carte
|
$walletUser = WalletsUser::findOrFail($request->id_wallet_user);
|
||||||
if(in_array($request->type, [10, 11])){
|
// Pour les operations à cartes, le pays initial c'est le pays de la carte
|
||||||
$init_country = $walletUser->user->card_country_id;
|
if(in_array($request->type, [10, 11])){
|
||||||
}else{
|
$init_country = $walletUser->user->card_country_id;
|
||||||
$init_country = $walletUser->user->network->country->id;
|
}else{
|
||||||
|
$init_country = $walletUser->user->network->country->id;
|
||||||
|
|
||||||
if($request->type == 21){
|
if($request->type == 21){
|
||||||
$withLinkedCard = $request->input('with_linked_card', false);
|
$withLinkedCard = $request->input('with_linked_card', false);
|
||||||
if ($withLinkedCard) {
|
if ($withLinkedCard) {
|
||||||
$init_country = $walletUser->user->card_country_id;
|
$init_country = $walletUser->user->card_country_id;
|
||||||
}else{
|
}else{
|
||||||
$init_country = Country::where('code_country', $request->input('customer_country'))->first()?->id;
|
$init_country = Country::where('code_country', $request->input('customer_country'))->first()?->id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network')
|
$result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network')
|
||||||
->where('networks.country_id', $init_country)->where('configWallet.type', 'ilink')
|
->where('networks.country_id', $init_country)->where('configWallet.type', 'ilink')
|
||||||
->select('configWallet.id')->first();
|
->select('configWallet.id')->first();
|
||||||
|
@ -2288,10 +2305,16 @@ class iLinkTransactionController extends Controller
|
||||||
switch ($request->type) {
|
switch ($request->type) {
|
||||||
case 1: //User - Envoi wallet à wallet
|
case 1: //User - Envoi wallet à wallet
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'final_country' => 'required|integer|exists:countries,id',
|
|
||||||
'id_destinataire' => 'required_without:phone_destinataire',
|
|
||||||
'network_destinataire' => 'required|integer|min:0|not_in:0',
|
'network_destinataire' => 'required|integer|min:0|not_in:0',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if(!$simulator){
|
||||||
|
$this->validate($request, [
|
||||||
|
'final_country' => 'required|integer|exists:countries,id',
|
||||||
|
'id_destinataire' => 'required_without:phone_destinataire'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$configNetworkDestinataire = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
|
$configNetworkDestinataire = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
|
||||||
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_wallet, $request->montant) : $this->calculateFees($plr_user_wallet_wallet_national, $request->montant);
|
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_wallet, $request->montant) : $this->calculateFees($plr_user_wallet_wallet_national, $request->montant);
|
||||||
//Verifier si c'est pas un reseau ilink
|
//Verifier si c'est pas un reseau ilink
|
||||||
|
@ -2305,11 +2328,13 @@ class iLinkTransactionController extends Controller
|
||||||
]);
|
]);
|
||||||
$frais += $fees;
|
$frais += $fees;
|
||||||
} else {
|
} else {
|
||||||
$destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country);
|
if(!$simulator){
|
||||||
if(!($destinataire instanceof User)){
|
$destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country);
|
||||||
return $destinataire;
|
if(!($destinataire instanceof User)){
|
||||||
|
return $destinataire;
|
||||||
|
}
|
||||||
|
$data['destinataire'] = $destinataire->lastname . ' ' . $destinataire->firstname;
|
||||||
}
|
}
|
||||||
$data['destinataire'] = $destinataire->lastname . ' ' . $destinataire->firstname;
|
|
||||||
}
|
}
|
||||||
$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'] = round($frais + $taxe, 2);
|
$data['frais'] = round($frais + $taxe, 2);
|
||||||
|
@ -2319,9 +2344,11 @@ class iLinkTransactionController extends Controller
|
||||||
$data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $request->final_country);
|
$data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $request->final_country);
|
||||||
break;
|
break;
|
||||||
case 2: //User - Envoi de wallet à carte
|
case 2: //User - Envoi de wallet à carte
|
||||||
$final_country = $walletUser->user->card_country_id;
|
if(!$simulator){
|
||||||
if(empty($final_country)){
|
$final_country = $walletUser->user->card_country_id;
|
||||||
return $this->errorResponse(trans('errors.no_bank_card_attached'));
|
if(empty($final_country)){
|
||||||
|
return $this->errorResponse(trans('errors.no_bank_card_attached'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$plr_user_wallet_cart_national = $this->getPaliers($paliers_commission_wallets, 'user_wallet_cart_national');
|
$plr_user_wallet_cart_national = $this->getPaliers($paliers_commission_wallets, 'user_wallet_cart_national');
|
||||||
$plr_user_wallet_cart_international = $this->getPaliers($paliers_commission_wallets, 'user_wallet_cart_international');
|
$plr_user_wallet_cart_international = $this->getPaliers($paliers_commission_wallets, 'user_wallet_cart_international');
|
||||||
|
@ -2369,7 +2396,9 @@ class iLinkTransactionController extends Controller
|
||||||
$data['montant_net'] = round($request->montant - $data['frais'], 2);
|
$data['montant_net'] = round($request->montant - $data['frais'], 2);
|
||||||
break;
|
break;
|
||||||
case 10: //User - Retrait de carte vers wallet
|
case 10: //User - Retrait de carte vers wallet
|
||||||
$final_country = $walletUser->user->network->country->id;
|
if(!$simulator){
|
||||||
|
$final_country = $walletUser->user->network->country->id;
|
||||||
|
}
|
||||||
|
|
||||||
$plr_user_cart_wallet_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_wallet_national');
|
$plr_user_cart_wallet_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_wallet_national');
|
||||||
$plr_user_cart_wallet_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_wallet_international');
|
$plr_user_cart_wallet_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_wallet_international');
|
||||||
|
@ -2388,7 +2417,9 @@ class iLinkTransactionController extends Controller
|
||||||
$data['montant_net_final'] = $this->toMoneyWithCurrency(round($request->montant, 2), $init_country, $final_country);
|
$data['montant_net_final'] = $this->toMoneyWithCurrency(round($request->montant, 2), $init_country, $final_country);
|
||||||
break;
|
break;
|
||||||
case 11: // User - Retrait de carte vers cash
|
case 11: // User - Retrait de carte vers cash
|
||||||
$final_country = $walletUser->user->network->country->id;
|
if(!$simulator){
|
||||||
|
$final_country = $walletUser->user->network->country->id;
|
||||||
|
}
|
||||||
|
|
||||||
$plr_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_national');
|
$plr_user_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_national');
|
||||||
$plr_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_international');
|
$plr_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_cash_international');
|
||||||
|
@ -2493,11 +2524,18 @@ class iLinkTransactionController extends Controller
|
||||||
$data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $request->final_country);
|
$data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $request->final_country);
|
||||||
break;
|
break;
|
||||||
case 21: //User - Retrait de carte vers autre wallet
|
case 21: //User - Retrait de carte vers autre wallet
|
||||||
|
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'final_country' => 'required|integer|exists:countries,id',
|
|
||||||
'id_destinataire' => 'required_without:phone_destinataire',
|
|
||||||
'network_destinataire' => 'required|integer|min:0|not_in:0',
|
'network_destinataire' => 'required|integer|min:0|not_in:0',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if(!$simulator){
|
||||||
|
$this->validate($request, [
|
||||||
|
'final_country' => 'required|integer|exists:countries,id',
|
||||||
|
'id_destinataire' => 'required_without:phone_destinataire'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$plr_user_cart_autre_wallet_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_autre_wallet_national');
|
$plr_user_cart_autre_wallet_national = $this->getPaliers($paliers_commission_wallets, 'user_cart_autre_wallet_national');
|
||||||
$plr_user_cart_autre_wallet_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_autre_wallet_international');
|
$plr_user_cart_autre_wallet_international = $this->getPaliers($paliers_commission_wallets, 'user_cart_autre_wallet_international');
|
||||||
$frais = $this->calculateFees($init_country != $request->final_country ? $plr_user_cart_autre_wallet_international : $plr_user_cart_autre_wallet_national, $request->montant);
|
$frais = $this->calculateFees($init_country != $request->final_country ? $plr_user_cart_autre_wallet_international : $plr_user_cart_autre_wallet_national, $request->montant);
|
||||||
|
@ -2518,11 +2556,13 @@ class iLinkTransactionController extends Controller
|
||||||
'payment_method' => PaymentMethod::WALLET
|
'payment_method' => PaymentMethod::WALLET
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country);
|
if(!$simulator){
|
||||||
if(!($destinataire instanceof User)){
|
$destinataire = $this->verifyiLinkRecipient($request->id_destinataire, $request->final_country);
|
||||||
return $destinataire;
|
if(!($destinataire instanceof User)){
|
||||||
|
return $destinataire;
|
||||||
|
}
|
||||||
|
$data['destinataire'] = $destinataire->lastname . ' ' . $destinataire->firstname;
|
||||||
}
|
}
|
||||||
$data['destinataire'] = $destinataire->lastname . ' ' . $destinataire->firstname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$frais += $fees;
|
$frais += $fees;
|
||||||
|
@ -2579,7 +2619,7 @@ class iLinkTransactionController extends Controller
|
||||||
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 (!$this->checkPassword($request->code_retrait, $transaction->encrypted_code_retrait, $transaction->code_retrait_salt))
|
if (!$this->checkPassword(remove_spaces($request->code_retrait), $transaction->encrypted_code_retrait, $transaction->code_retrait_salt))
|
||||||
return $this->errorResponse(trans('errors.invalid_withdrawal_code'));
|
return $this->errorResponse(trans('errors.invalid_withdrawal_code'));
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -700,4 +700,15 @@ trait Helper
|
||||||
return $destination;
|
return $destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function generateRandomString($length = 10)
|
||||||
|
{
|
||||||
|
$characters = '23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ';
|
||||||
|
$charactersLength = strlen($characters);
|
||||||
|
$randomString = '';
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||||
|
}
|
||||||
|
return $randomString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue