feat: add aggregator transaction fees to each transaction and add method "User - Retrait de carte vers autre wallet"

This commit is contained in:
Djery-Tom 2023-07-12 20:32:21 +01:00
parent ef554d0ad0
commit d5764e8984
8 changed files with 377 additions and 17 deletions

View File

@ -0,0 +1,11 @@
<?php
namespace App\Enums;
abstract class PaymentMethod
{
const CARD = 'CARD'; // Les remboursements ou recharges vers des clients
const WALLET = 'WALLET'; // Les paiements effectués par les clients
}

11
app/Enums/PaymentType.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace App\Enums;
abstract class PaymentType
{
const CASH_IN = 'CASH_IN'; // Les remboursements ou recharges vers des clients
const CASH_OUT = 'CASH_OUT'; // Les paiements effectués par les clients
}

View File

@ -2,6 +2,8 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Enums\PaymentMethod;
use App\Enums\PaymentType;
use App\Exceptions\AppException; use App\Exceptions\AppException;
use App\Models\AgentPlus; use App\Models\AgentPlus;
use App\Models\CodeGenerer; use App\Models\CodeGenerer;
@ -247,13 +249,29 @@ class iLinkTransactionController extends Controller
//Verification des limites reglementaires //Verification des limites reglementaires
$this->checkReguationsLimits($walletUser->id, $init_country, $request->final_country, $transaction->montant); $this->checkReguationsLimits($walletUser->id, $init_country, $request->final_country, $transaction->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); $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 = ($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);
$transaction->montant_net = $montantDepot = $transaction->montant - $frais - $taxe;
$transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $request->final_country);
$configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->first(); $reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->first();
$configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
$fees = 0;
if ($configPayeur->type != 'ilink') {
$fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_IN,
'payment_method' => PaymentMethod::WALLET
]);
}
$frais += $fees;
$transaction->frais = $frais;
$transaction->taxe = $taxe;
$transaction->montant_net = $montantDepot = $transaction->montant - $frais - $taxe;
$transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $request->final_country);
if (isset($reseauPayeur)) { if (isset($reseauPayeur)) {
$transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100; $transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100;
$transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country); $transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country);
@ -272,7 +290,7 @@ class iLinkTransactionController extends Controller
if ($destinataire) { // Si c'est un wallet ilink if ($destinataire) { // Si c'est un wallet ilink
if ($destinataire->network->country->id == $request->final_country) { if ($destinataire->network->country->id == $request->final_country) {
$walletDestinataire = WalletsUser::where('idUser', $destinataire->id)->firstOrFail(); $walletDestinataire = WalletsUser::where('idUser', $destinataire->id)->firstOrFail();
$walletDestinataire->balance += $this->toMoneyAmount($montantDepot, $init_country, $request->final_country); $walletDestinataire->balance += $transaction->montant_net_final_country;
$walletDestinataire->save(); $walletDestinataire->save();
} else { } else {
$country = Country::findOrFail($request->final_country); $country = Country::findOrFail($request->final_country);
@ -360,6 +378,14 @@ class iLinkTransactionController extends Controller
// $plr_bank_user_wallet_cart_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_wallet_cart_international'); // $plr_bank_user_wallet_cart_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_wallet_cart_international');
$frais = $this->calculateFees($plr_user_wallet_cart_national, $request->montant); $frais = $this->calculateFees($plr_user_wallet_cart_national, $request->montant);
$fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_IN,
'payment_method' => PaymentMethod::CARD
]);
$frais += $fees;
$transaction->montant_net = $montantDepot = $transaction->montant - $frais; $transaction->montant_net = $montantDepot = $transaction->montant - $frais;
$identification = Identification::with(['country'])->where('id_user', $user->id)->first(); $identification = Identification::with(['country'])->where('id_user', $user->id)->first();
@ -671,7 +697,13 @@ class iLinkTransactionController extends Controller
// $plr_bank_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_international'); // $plr_bank_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_international');
$frais = $this->calculateFees($plr_user_cart_wallet_national, $request->montant); $frais = $this->calculateFees($plr_user_cart_wallet_national, $request->montant);
$fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_OUT,
'payment_method' => PaymentMethod::CARD
]);
$frais += $fees;
$transaction->montant_net = $montantRetrait = $transaction->montant + $frais; $transaction->montant_net = $montantRetrait = $transaction->montant + $frais;
$identification = Identification::where('id_user', $user->id)->first(); $identification = Identification::where('id_user', $user->id)->first();
$customer_country_code = $identification ? Country::where('name', $identification->country)->first()?->code_country : $user->network->country->code_country; $customer_country_code = $identification ? Country::where('name', $identification->country)->first()?->code_country : $user->network->country->code_country;
@ -742,7 +774,13 @@ class iLinkTransactionController extends Controller
// $plr_bank_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_international'); // $plr_bank_user_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_cart_cash_international');
$frais = $this->calculateFees($plr_user_cart_cash_national, $request->montant); $frais = $this->calculateFees($plr_user_cart_cash_national, $request->montant);
$fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_OUT,
'payment_method' => PaymentMethod::CARD
]);
$frais += $fees;
$transaction->montant_net = $montantRetrait = $transaction->montant + $frais; $transaction->montant_net = $montantRetrait = $transaction->montant + $frais;
$transaction->montant_net_final_country = $transaction->montant; $transaction->montant_net_final_country = $transaction->montant;
@ -917,6 +955,14 @@ class iLinkTransactionController extends Controller
// $plr_bank_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_cart_cash_international'); // $plr_bank_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_cart_cash_international');
$frais = $this->calculateFees($plr_customer_cart_cash_national, $request->montant); $frais = $this->calculateFees($plr_customer_cart_cash_national, $request->montant);
$fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_OUT,
'payment_method' => PaymentMethod::CARD
]);
$frais += $fees;
$montantRetrait = $transaction->montant + $frais; $montantRetrait = $transaction->montant + $frais;
$transaction->montant_net = $montantRetrait; $transaction->montant_net = $montantRetrait;
@ -1052,6 +1098,13 @@ class iLinkTransactionController extends Controller
$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); $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);
$fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_IN,
'payment_method' => PaymentMethod::WALLET
]);
$frais += $fees;
$montantDepot = $request->montant - $frais - $taxe; $montantDepot = $request->montant - $frais - $taxe;
$transaction->montant_net = $montantDepot; $transaction->montant_net = $montantDepot;
$transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $request->final_country); $transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $request->final_country);
@ -1148,7 +1201,13 @@ class iLinkTransactionController extends Controller
// $plr_bank_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'bank_cash_cart_international'); // $plr_bank_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'bank_cash_cart_international');
$frais = $this->calculateFees($plr_customer_cash_cart_national, $request->montant); $frais = $this->calculateFees($plr_customer_cash_cart_national, $request->montant);
$fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_IN,
'payment_method' => PaymentMethod::CARD
]);
$frais += $fees;
$montantDepot = $transaction->montant - $frais; $montantDepot = $transaction->montant - $frais;
$transaction->montant_net = $montantDepot; $transaction->montant_net = $montantDepot;
@ -1661,6 +1720,173 @@ class iLinkTransactionController extends Controller
$this->sendMail($user->email, trans('messages.successful_transaction'), $message); $this->sendMail($user->email, trans('messages.successful_transaction'), $message);
$response_message = ($message . trans('messages.sent_by_mail')); $response_message = ($message . trans('messages.sent_by_mail'));
break; break;
case 21: //User - Retrait de carte vers autre wallet
$this->validate($request, array_merge($transaction->user_card_rules(), $transaction->send_wallet_wallet_rules(), [
'nom_destinataire' => 'required',
'prenom_destinataire' => 'required',
'type_document_destinataire' => 'required',
'id_document_destinataire' => 'required'
]));
$user = $walletUser->user;
$this->validatePassword($request->password, $user->encrypted_password, $user->salt);
$this->checkUserIdentification($user->id);
$withLinkedCard = $request->input('with_linked_card', false);
if ($withLinkedCard) {
if (!(isset($user->numero_carte) && isset($user->expiration_date))) {
throw new Exception(trans('errors.no_bank_card_attached'));
}
$transaction->expiration_date = $user->expiration_date;
$transaction->numero_carte = $user->numero_carte;
} else {
$this->validate($request, [
'numero_carte' => 'required',
'expiration_date' => 'required|date_format:m/y|after_or_equal:today',
'customer_name' => 'nullable|string',
'customer_surname' => 'required|string',
'customer_address' => 'required|string',
'customer_city' => 'required|string',
'customer_country' => "required|string"
]);
$transaction->expiration_date = DateTime::createFromFormat('m/y', $request->expiration_date);
$transaction->numero_carte = $request->numero_carte;
}
$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_bank_user_autre_wallet_national = $this->getPaliers($paliers_commission_wallets, 'bank_user_autre_wallet_national');
$plr_bank_user_autre_wallet_international = $this->getPaliers($paliers_commission_wallets, 'bank_user_autre_wallet_international');
//Verification des limites reglementaires
$this->checkReguationsLimits($walletUser->id, $init_country, $request->final_country, $transaction->montant);
$frais = $this->calculateFees($init_country != $request->final_country ? $plr_user_cart_autre_wallet_international : $plr_user_cart_autre_wallet_national, $request->montant);
$taxe = $this->calculateTax($init_country != $request->final_country ? $taxesInternationales : $taxesNationales, $frais);
$fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_OUT,
'payment_method' => PaymentMethod::CARD
]);
$frais += $fees;
$transaction->frais = $frais;
$transaction->taxe = $taxe;
$transaction->montant_net = $montantRetrait = $transaction->montant + $frais + $taxe;
$transaction->montant_net_final_country = $this->toMoneyAmount($transaction->montant, $init_country, $request->final_country);
$configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->first();
if (isset($reseauPayeur)) {
$transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100;
$transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country);
$transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur;
} else {
$transaction->part_reseau_payeur = 0;
$transaction->part_reseau_payeur_final_country = 0;
$transaction->part_reseau_emetteur = $frais;
}
$transaction->commission_hyp = $transaction->part_reseau_emetteur;
$transaction->id_transaction = $this->getTransactionID();
$transaction->type_id_destinataire = $request->input('type_id_destinataire');
// Retirer l'argent de la carte
$identification = Identification::where('id_user', $user->id)->first();
$customer_country_code = $withLinkedCard ? Country::where('name', $identification->country)->first()?->code_country : $request->input('customer_country');
$payment_transaction_id = $request->input('payment_transaction_id');
$result = $this->handlePayIn($transaction, [
'card_no' => $transaction->numero_carte,
'exp_month' => date("m", strtotime($transaction->expiration_date)),
'exp_year' => date("Y", strtotime($transaction->expiration_date)),
'cvc' => $request->input('cvv'),
'amount' => $montantRetrait,
'currency' => $this->getCurrency($init_country),
'payment_method' => 'CARD',
'customer_id' => $user->id,
'customer_email' => $user->email,
'customer_name' => $withLinkedCard ? $identification->firstname : $request->input('customer_name'),
'customer_surname' => $withLinkedCard ? $identification->lastname : $request->input('customer_surname'),
'customer_address' => $withLinkedCard ? $identification->town : $request->input('customer_address'),
'customer_city' => $withLinkedCard ? $identification->town : $request->input('customer_city'),
'customer_country' => $customer_country_code,
'reason' => "User - Retrait de carte vers autre wallet"
], $payment_transaction_id);
if (!($result instanceof WalletIlinkTransaction)) {
return $result;
}
// Envoyer l'argent au destinataire
if ($configPayeur->type == 'ilink') {
$destinataire = User::where($transaction->type_id_destinataire, $request->id_destinataire)->first();
if ($destinataire) { // Si c'est un wallet ilink
if ($destinataire->network->country->id == $request->final_country) {
$walletDestinataire = WalletsUser::where('idUser', $destinataire->id)->firstOrFail();
$walletDestinataire->balance += $transaction->montant_net_final_country;
$walletDestinataire->save();
} else {
$country = Country::findOrFail($request->final_country);
throw new Exception(trans('errors.wallet_country_not_match', ['country' => $country->name]), 500);
}
} else {
throw new Exception(trans('errors.wallet_not_defined'), 500);
}
//Mise a jour des comissions et compensation
if (isset($reseauPayeur)) {
$reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country;
$reseauPayeur->balance_compensation += $transaction->montant_net_final_country;
}
//Hyperviseur payeur
$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
$transaction->id_wallet_hyp_payeur = $walletHyperviseur->id;
} else {
$wallet_agent_hypPayeur = WalletAgent::where('agent_id', $hyperviseurPayeur->id)->firstOrFail();
$walletHyperviseurPayeur = Wallet::findOrFail($wallet_agent_hypPayeur->wallet_id);
$walletHyperviseurPayeur->balance_com += $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country);
$transaction->id_wallet_hyp_payeur = $walletHyperviseurPayeur->id;
$walletHyperviseurPayeur->save();
}
} else {
//Emettre requete SSL vers wallet extene correspondant pour recharger le compte du destinataire
$countryCurrency = CountriesCurrency::findOrFail($transaction->final_country);
// PayOut through payment service
$this->handlePayOut($transaction, [
'network_name' => $reseauPayeur->network->name,
'payment_method' => 'WALLET',
'amount' => $transaction->montant_net_final_country,
'currency' => $countryCurrency->currency_code,
'customer_id' => $user->id,
'customer_email' => $user->email,
'customer_name' => $transaction->prenom_destinataire,
'customer_surname' => $transaction->nom_destinataire,
'customer_phone_number' => $transaction->id_destinataire,
'customer_country' => $countryCurrency->code_country,
'reason' => "User - Retrait de carte vers autre wallet"
]);
}
$transaction->commission_banque = $this->calculateFees($init_country != $request->final_country ? $plr_bank_user_autre_wallet_international : $plr_bank_user_autre_wallet_national, $request->montant, $frais);
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
$walletHyperviseur->balance_com += $transaction->commission_hyp;
$transaction->id_wallet_hyp = $walletHyperviseur->id;
$walletHyperviseur->save();
$transaction->id_transaction = $this->getTransactionID();
$transaction->date = $this->getCurrentTime($init_country);
$transaction->save();
$message = trans('messages.successful_user_remove_from_cart_to_other_wallet',
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
'total' => $this->toMoney($montantRetrait, $init_country), 'fees' => $this->toMoney($frais, $init_country),
'sender_code' => $transaction->id_destinataire, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]);
$this->sendMail($user->email, trans('messages.successful_transaction'), $message);
$response_message = ($message . trans('messages.sent_by_mail'));
break;
default: default:
$response_message = "Default response message"; $response_message = "Default response message";
@ -1744,6 +1970,29 @@ class iLinkTransactionController extends Controller
return $transaction; return $transaction;
} }
/**
* @throws Exception
*/
private function getBasicTransactionFees($data)
{
$client = new Client([
'base_uri' => config('services.payment_service.base_uri'),
'headers' => [
'Authorization' => config('services.payment_service.key'),
]
]);
// PayOut through payment service
$response = $client->get('/fees', ['query' => $data, 'http_errors' => false]);
$code = $response->getStatusCode();
$content = json_decode($response->getBody()->getContents(), true);
if ($code == 200) {
return $content["response"]['fees'];
} else {
Log::error("getBasicTransactionFees :: " . $content['error']);
throw new Exception(__('errors.unexpected_error'), $content['status'] ?? 500);
}
}
public function lastUserTransactions($id_user) public function lastUserTransactions($id_user)
{ {
@ -1889,16 +2138,30 @@ class iLinkTransactionController extends Controller
} else { } else {
$destinataire = User::where('user_code', $request->id_destinataire)->orWhere('phone', $request->id_destinataire)->first(); $destinataire = User::where('user_code', $request->id_destinataire)->orWhere('phone', $request->id_destinataire)->first();
$data['destinataire'] = $destinataire ? $destinataire->lastname . ' ' . $destinataire->firstname : $request->id_destinataire; $data['destinataire'] = $destinataire ? $destinataire->lastname . ' ' . $destinataire->firstname : $request->id_destinataire;
$fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_IN,
'payment_method' => PaymentMethod::WALLET
]);
$data['frais'] += $fees;
} }
$data['frais'] = round($frais + $taxe, 2); $data['frais'] = round($frais + $taxe, 2);
$data['montant_net_init'] = round($request->montant - $data['frais'], 2); $data['montant_net_init'] = round($request->montant - $data['frais'], 2);
$data['exchange_rate'] = $this->getExchangeRate($init_country, $request->final_country);
$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
$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');
$frais = $this->calculateFees($plr_user_wallet_cart_national, $request->montant); $frais = $this->calculateFees($plr_user_wallet_cart_national, $request->montant);
$data['frais'] = round($frais, 2); $fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_IN,
'payment_method' => PaymentMethod::CARD
]);
$data['frais'] = round($frais + $fees, 2);
$data['montant_net'] = round($request->montant - $data['frais'], 2); $data['montant_net'] = round($request->montant - $data['frais'], 2);
break; break;
case 3: // User - Envoi wallet à cash case 3: // User - Envoi wallet à cash
@ -1909,6 +2172,7 @@ class iLinkTransactionController extends Controller
$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);
$data['montant_net_init'] = round($request->montant - $data['frais'], 2); $data['montant_net_init'] = round($request->montant - $data['frais'], 2);
$data['exchange_rate'] = $this->getExchangeRate($init_country, $request->final_country);
$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 9: // User - Retrait de wallet en cash case 9: // User - Retrait de wallet en cash
@ -1921,21 +2185,39 @@ class iLinkTransactionController extends Controller
$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');
$frais = $this->calculateFees($plr_user_cart_wallet_national, $request->montant); $frais = $this->calculateFees($plr_user_cart_wallet_national, $request->montant);
$data['frais'] = round($frais, 2); $fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_OUT,
'payment_method' => PaymentMethod::CARD
]);
$data['frais'] = round($frais + $fees, 2);
$data['montant_net'] = round($request->montant + $data['frais'], 2); $data['montant_net'] = round($request->montant + $data['frais'], 2);
break; break;
case 11: // User - Retrait de carte vers cash case 11: // User - Retrait de carte vers cash
$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');
$frais = $this->calculateFees($plr_user_cart_cash_national, $request->montant); $frais = $this->calculateFees($plr_user_cart_cash_national, $request->montant);
$data['frais'] = round($frais, 2); $fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_OUT,
'payment_method' => PaymentMethod::CARD
]);
$data['frais'] = round($frais + $fees, 2);
$data['montant_net'] = round($request->montant + $data['frais'], 2); $data['montant_net'] = round($request->montant + $data['frais'], 2);
break; break;
case 13: // Agent - Retrait de la carte vers cash case 13: // Agent - Retrait de la carte vers cash
$plr_customer_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_national'); $plr_customer_cart_cash_national = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_national');
// $plr_customer_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_international'); // $plr_customer_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_international');
$frais = $this->calculateFees($plr_customer_cart_cash_national, $request->montant); $frais = $this->calculateFees($plr_customer_cart_cash_national, $request->montant);
$data['frais'] = round($frais, 2); $fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_OUT,
'payment_method' => PaymentMethod::CARD
]);
$data['frais'] = round($frais + $fees, 2);
$data['montant_net'] = round($request->montant + $data['frais'], 2); $data['montant_net'] = round($request->montant + $data['frais'], 2);
break; break;
case 14: // Agent - Envoi de cash vers wallet iLink case 14: // Agent - Envoi de cash vers wallet iLink
@ -1950,6 +2232,7 @@ class iLinkTransactionController extends Controller
$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);
$data['frais'] = round($frais + $taxe, 2); $data['frais'] = round($frais + $taxe, 2);
$data['montant_net_init'] = round($request->montant - $data['frais'], 2); $data['montant_net_init'] = round($request->montant - $data['frais'], 2);
$data['exchange_rate'] = $this->getExchangeRate($init_country, $final_country);
$data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $final_country); $data['montant_net_final'] = $this->toMoneyWithCurrency($data['montant_net_init'], $init_country, $final_country);
break; break;
case 15: // Agent - Envoi de cash vers autre wallet case 15: // Agent - Envoi de cash vers autre wallet
@ -1958,15 +2241,28 @@ class iLinkTransactionController extends Controller
]); ]);
$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); $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'] = round($frais + $taxe, 2); $fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_IN,
'payment_method' => PaymentMethod::WALLET
]);
$data['frais'] = round($frais + $taxe + $fees, 2);
$data['montant_net_init'] = round($request->montant - $data['frais'], 2); $data['montant_net_init'] = round($request->montant - $data['frais'], 2);
$data['exchange_rate'] = $this->getExchangeRate($init_country, $request->final_country);
$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 16: // Agent - Envoi de cash vers une carte visa case 16: // Agent - Envoi de cash vers une carte visa
$plr_customer_cash_cart_national = $this->getPaliers($paliers_commission_wallets, 'customer_cash_cart_national'); $plr_customer_cash_cart_national = $this->getPaliers($paliers_commission_wallets, 'customer_cash_cart_national');
// $plr_customer_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'customer_cash_cart_international'); // $plr_customer_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'customer_cash_cart_international');
$frais = $this->calculateFees($plr_customer_cash_cart_national, $request->montant); $frais = $this->calculateFees($plr_customer_cash_cart_national, $request->montant);
$data['frais'] = round($frais, 2); $fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_IN,
'payment_method' => PaymentMethod::CARD
]);
$data['frais'] = round($frais + $fees, 2);
$data['montant_net'] = round($request->montant - $data['frais'], 2); $data['montant_net'] = round($request->montant - $data['frais'], 2);
break; break;
case 17: // Agent - Envoi de cash vers cash case 17: // Agent - Envoi de cash vers cash
@ -1976,9 +2272,29 @@ class iLinkTransactionController extends Controller
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_agent_cash_cash, $request->montant) : $this->calculateFees($plr_agent_cash_cash_national, $request->montant); $frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_agent_cash_cash, $request->montant) : $this->calculateFees($plr_agent_cash_cash_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'] = round($frais + $taxe, 2); $data['frais'] = round($frais + $taxe, 2);
$data['exchange_rate'] = $this->getExchangeRate($init_country, $request->final_country);
$data['montant_net_init'] = round($request->montant - $data['frais'], 2); $data['montant_net_init'] = round($request->montant - $data['frais'], 2);
$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
$this->validate($request, [
'final_country' => 'required|integer|exists:countries,id',
]);
$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');
$frais = $this->calculateFees($init_country != $request->final_country ? $plr_user_cart_autre_wallet_international : $plr_user_cart_autre_wallet_national, $request->montant);
$taxe = $this->calculateTax($init_country != $request->final_country ? $taxesInternationales : $taxesNationales, $frais);
$fees = $this->getBasicTransactionFees([
'amount' => $request->montant,
'country_id' => $init_country,
'payment_type' => PaymentType::CASH_OUT,
'payment_method' => PaymentMethod::CARD
]);
$data['frais'] = round($frais + $taxe + $fees, 2);
$data['exchange_rate'] = $this->getExchangeRate($init_country, $request->final_country);
$data['montant_net'] = round($request->montant + $data['frais'], 2);
$data['montant_net_final'] = $this->toMoneyWithCurrency($request->montant, $init_country, $request->final_country);
break;
} }
$net = $data['montant_net'] ?? $data['montant_net_init']; $net = $data['montant_net'] ?? $data['montant_net_init'];
if (isset($net)) if (isset($net))

View File

@ -231,7 +231,7 @@ class WalletIlinkTransaction extends Model
'nom_destinataire' => 'required', 'nom_destinataire' => 'required',
'prenom_destinataire' => 'required', 'prenom_destinataire' => 'required',
'type_document_destinataire' => 'required', 'type_document_destinataire' => 'required',
// 'id_document_destinataire'=>'required' 'id_document_destinataire' => 'required'
]; ];
} }

View File

@ -211,6 +211,11 @@ trait Helper
return $this->convertMoney($amount, $init_country, $final_country)->getAmount()->toFloat(); return $this->convertMoney($amount, $init_country, $final_country)->getAmount()->toFloat();
} }
public function getExchangeRate($init_country, $final_country)
{
return $this->toMoney(1, $init_country) . ' = ' . $this->toMoneyWithCurrency(1, $init_country, $final_country);
}
public function toUSDAmount($amount, $init_country, $final_currency_code = 'USD') public function toUSDAmount($amount, $init_country, $final_currency_code = 'USD')
{ {
// set to whatever your rates are relative to // set to whatever your rates are relative to

View File

@ -20,7 +20,8 @@
"maatwebsite/excel": "^3.1", "maatwebsite/excel": "^3.1",
"sentry/sentry-laravel": "2.9", "sentry/sentry-laravel": "2.9",
"simplesoftwareio/simple-qrcode": "^4.2", "simplesoftwareio/simple-qrcode": "^4.2",
"twilio/sdk": "^6.28" "twilio/sdk": "^6.28",
"ext-pdo": "*"
}, },
"require-dev": { "require-dev": {
"fzaninotto/faker": "^1.9.1", "fzaninotto/faker": "^1.9.1",

View File

@ -314,4 +314,12 @@ Transaction Information:
- IBAN of the recipient : :iban - IBAN of the recipient : :iban
- Bank : :bank :country", - Bank : :bank :country",
'successful_bank_account_attachment_taken' => 'Your request to link your bank account has been taken into account, you will receive a confirmation email as soon as the bank has validated your IBAN code', 'successful_bank_account_attachment_taken' => 'Your request to link your bank account has been taken into account, you will receive a confirmation email as soon as the bank has validated your IBAN code',
'successful_user_remove_from_cart_to_other_wallet' => "Withdraw money from your card to another account
Transaction information :
- Number: :id_transaction
- Transaction amount: :amount
- Fees: :fees
- Total withdrawal amount: :total
- Recipient account: :sender_code
- Card number: :cart_number"
]; ];

View File

@ -315,4 +315,12 @@ Informations de la transaction :
- IBAN du destinataire : :iban - IBAN du destinataire : :iban
- Banque : :bank :country", - Banque : :bank :country",
'successful_bank_account_attachment_taken' => 'Votre requête de rattachement de votre compte bancaire a été prise en compte, vous recevrez un mail de confirmation dès lors que la banque aura validé votre code IBAN.', 'successful_bank_account_attachment_taken' => 'Votre requête de rattachement de votre compte bancaire a été prise en compte, vous recevrez un mail de confirmation dès lors que la banque aura validé votre code IBAN.',
'successful_user_remove_from_cart_to_other_wallet' => "Retrait d'argent de votre carte vers un autre compte
Informations de la transaction :
- Numéro : :id_transaction
- Montant de la transaction : :amount
- Frais : :fees
- Montant total de retrait: :total
- Compte destinataire : :sender_code
- Numero de la carte : :cart_number"
]; ];