2020-06-19 13:48:27 +00:00
< ? php
namespace App\Http\Controllers ;
2023-07-12 19:32:21 +00:00
use App\Enums\PaymentMethod ;
use App\Enums\PaymentType ;
2022-04-15 18:09:52 +00:00
use App\Exceptions\AppException ;
2020-06-19 13:48:27 +00:00
use App\Models\AgentPlus ;
use App\Models\CodeGenerer ;
use App\Models\ConfigWallet ;
2023-06-29 08:51:55 +00:00
use App\Models\CountriesCurrency ;
2020-06-24 07:36:54 +00:00
use App\Models\Country ;
2020-07-04 14:32:57 +00:00
use App\Models\Identification ;
2020-06-19 13:48:27 +00:00
use App\Models\NetworksAgent ;
2020-11-06 17:40:08 +00:00
use App\Models\NetworksOperator ;
2020-06-21 21:49:24 +00:00
use App\Models\PayingNetwork ;
2020-09-28 15:39:57 +00:00
use App\Models\Regulation ;
2020-06-19 13:48:27 +00:00
use App\Models\TypeIlinkTransaction ;
2020-11-09 18:05:04 +00:00
use App\Models\TypeOperator ;
2020-06-19 13:48:27 +00:00
use App\Models\User ;
use App\Models\Wallet ;
use App\Models\WalletAgent ;
use App\Models\WalletIlinkTransaction ;
use App\Models\WalletsUser ;
2020-09-28 15:39:57 +00:00
use Carbon\Carbon ;
2022-04-20 08:08:32 +00:00
use DateTime ;
use Exception ;
2023-06-07 20:08:33 +00:00
use GuzzleHttp\Client ;
2020-06-19 13:48:27 +00:00
use Illuminate\Http\Request ;
use Illuminate\Http\Response ;
use Illuminate\Support\Facades\DB ;
2020-11-03 09:05:30 +00:00
use Illuminate\Support\Facades\Log ;
2022-04-20 08:08:32 +00:00
use Illuminate\Validation\ValidationException ;
use Throwable ;
2020-06-19 13:48:27 +00:00
class iLinkTransactionController extends Controller
{
2020-08-09 22:13:21 +00:00
2020-06-19 13:48:27 +00:00
/**
* Create a new controller instance .
*
* @ return void
*/
public function __construct ()
{
//
}
2020-11-13 06:39:24 +00:00
/**
* @ OA\Post (
* path = " /transactions/ilink " ,
* summary = " Effectuer une transaction dans le wallet iLink " ,
* tags = { " Transaction iLink " },
* security = {{ " api_key " : {}}},
* @ OA\RequestBody (
* description = " Corps de la requete " ,
* required = true ,
* @ OA\MediaType (
* mediaType = " application/json " ,
* @ OA\Schema (
* oneOf = {
* @ OA\Schema ( ref = " #/components/schemas/user_payement_of_operator " ),
* @ OA\Schema ( ref = " #/components/schemas/user_remove_from_bank_to_wallet " ),
2020-11-23 14:27:25 +00:00
* @ OA\Schema ( ref = " #/components/schemas/user_send_from_wallet_to_bank " ),
* @ OA\Schema ( ref = " #/components/schemas/agent_send_from_cash_to_bank " ),
2020-11-13 06:39:24 +00:00
* }
* ),
* examples = {
2022-04-14 18:27:06 +00:00
* @ OA\Examples (
* example = " user_payement_of_operator " ,
* summary = " User - Payer une facture chez un opérateur donné " ,
* value = { " type " : 19 , " id_wallet_user " : 9 , " id_wallet_network " : 101 , " no_facture " : " CDE1425533 " , " type_operator " : " water " , " id_operator " : 6 , " montant " : 100000 , " password " : " 1234 " }
* ),
* @ OA\Examples (
* example = " user_remove_from_bank_to_wallet " ,
* summary = " User - Retrait du compte bancaire rattaché vers le wallet de l'utilisateur " ,
* value = { " type " : 20 , " id_wallet_user " : 1 , " montant " : 100000 , " password " : " 1234 " }
* ),
* @ OA\Examples (
* example = " user_send_from_wallet_to_bank " ,
* summary = " User - Envoi de wallet à banque " ,
* value = { " type " : 4 , " id_wallet_user " : 9 , " id_wallet_network " : 101 , " montant " : 100000 , " password " : " 1234 " }
* ),
* @ OA\Examples (
* example = " agent_send_from_cash_to_bank " ,
* summary = " Agent - Envoi de cash vers banque " ,
* value = { " type " : 18 , " id_wallet_agent " : 9716 , " id_wallet_network " : 101 , " iban " : " CM15UBAA412341234123412341233 " , " id_bank " : 4 , " nom_emetteur " : " Djery " , " prenom_emetteur " : " Tom " , " email_emetteur " : " ddietchi@ilink-app.com " , " type_document_emetteur " : " passport " , " id_document_emetteur " : " 12345 " , " nom_destinataire " : " Brice " , " prenom_destinataire " : " zele " , " montant " : 100000 , " password " : " 1234 " }
* )
2020-11-13 06:39:24 +00:00
* }
* )
* ),
* @ OA\Response (
* response = 200 ,
* description = " OK " ,
2020-11-30 16:12:22 +00:00
* @ OA\MediaType (
* mediaType = " application/json " ,
* @ OA\Schema (
2020-12-02 16:08:43 +00:00
* ref = " #/components/schemas/ApiResponse " ,
2020-11-30 16:12:22 +00:00
* ),
2020-11-13 06:39:24 +00:00
* examples = {
2022-04-14 18:27:06 +00:00
* @ OA\Examples (
* example = " user_payement_of_operator " ,
* summary = " User - Payer une facture chez un opérateur donné " ,
* value = {
2020-11-13 06:39:24 +00:00
* " status " : 200 ,
* " response " : " Paiement d'une facture chez un operateur \n Informations de la transaction : \n - Numéro : 7S9PZO26VAQ3 \n - Montant de la transaction : 100 000 FCFA \n
- Frais : 0 FCFA\n - Montant net payé : 100 000 FCFA\n - Compte émetteur : s6LD9PmCJC\n - Operateur : CDE\n - Type d 'operateur : Opérateur d' eau\n - No facture : CDE1425533\n\nCe message a été envoyé dans le mail de l ' émetteur " ,
* " error " : null
* }
2022-04-14 18:27:06 +00:00
* ),
* @ OA\Examples (
* example = " user_remove_from_bank_to_wallet " ,
* summary = " User - Retrait du compte bancaire rattaché vers le wallet de l'utilisateur " ,
* value = {
2020-11-13 06:39:24 +00:00
* " status " : 200 ,
* " response " : " Retrait de la banque vers le wallet \n Informations de la transaction : \n - Numéro : 2XWQD7ZD9E7R \n - Montant de la transaction : 100 000 FCFA \n
- Frais : 0 FCFA\n - Montant net d\\ 'envoi: 100 000 FCFA\n - Compte émetteur : BZdsWkdfl\n - Banque : UBA Cameroon\n - IBAN : \n\nCe message a été envoyé dans le mail de l' émetteur " ,
2020-11-23 14:27:25 +00:00
* " error " : null
* }
2022-04-14 18:27:06 +00:00
* ),
* @ OA\Examples (
* example = " user_send_from_wallet_to_bank " ,
* summary = " User - Envoi de wallet à banque " ,
* value = {
2020-11-23 14:27:25 +00:00
* " status " : 200 ,
* " response " : " Envoi d'argent de votre compte vers la banque \n Informations de la transaction : \n - Numéro : NA69C5RTBY7B \n - Montant de la transaction : 100 000 FCFA \n
- Frais : 0 FCFA\n - Montant net d 'envoi: 100 000 FCFA\n - Compte émetteur : s6LD9PmCJC\n - Banque : UBA Cameroon\n - IBAN : \n\nCe message a été envoyé dans le mail de l' émetteur " ,
* " error " : null
* }
2022-04-14 18:27:06 +00:00
* ),
* @ OA\Examples (
* example = " agent_send_from_cash_to_bank " ,
* summary = " Agent - Envoi de cash vers banque " ,
* value = {
2020-11-23 14:27:25 +00:00
* " status " : 200 ,
* " response " : " Envoi d'argent en cash vers la banque \n Informations de la transaction : \n - Numéro : E58K8ZFPB5AN \n - Montant de la transaction : 100 000 FCFA \n - Frais : 0 FCFA \n - Montant net d'envoi: 100 000 FCFA \n
- Compte de l 'agent : 38LEDBostp\n - Noms de l' emetteur : Tom Djery\n - Noms du destinataire : zele Brice\n - IBAN du destinataire : CM15UBAA412341234123412341233\n - Banque : UBA Cameroon\n\nCe message a été envoyé dans le mail de l ' émetteur " ,
2020-11-13 06:39:24 +00:00
* " error " : null
* }
2022-04-14 18:27:06 +00:00
* ),
2020-11-13 06:39:24 +00:00
* }
* )
* )
* )
*/
// Transactions dans le wallet iLink
2020-06-19 13:48:27 +00:00
public function add ( Request $request )
{
$transaction = new WalletIlinkTransaction ();
$this -> validate ( $request , [
2022-04-20 08:08:32 +00:00
'type' => 'required|integer|exists:type_ilink_transaction,id' ,
'id_wallet_agent' => 'required_without:id_wallet_user|integer|exists:wallets,id' ,
'id_wallet_user' => 'required_without:id_wallet_agent|integer|exists:wallets_users,id' ,
2020-06-21 21:49:24 +00:00
'password' => 'required' ,
'montant' => 'required|numeric|min:0|not_in:0' ,
2020-06-19 13:48:27 +00:00
]);
2022-04-20 08:08:32 +00:00
$id_wallet_agent = $request -> input ( 'id_wallet_agent' );
$id_wallet_user = $request -> input ( 'id_wallet_user' );
$type = TypeIlinkTransaction :: findOrFail ( $request -> input ( 'type' ));
if ( isset ( $id_wallet_agent )) {
$walletAgent = Wallet :: findOrFail ( $id_wallet_agent );
2020-06-21 21:49:24 +00:00
$network_agent = NetworksAgent :: findOrFail ( $walletAgent -> id_networkAgent );
2020-07-02 19:18:28 +00:00
$transaction -> init_country = $init_country = $network_agent -> network -> country -> id ;
2020-06-21 21:49:24 +00:00
// Configuratrion du wallet
$config = ConfigWallet :: where ( 'id_network' , $network_agent -> network_id ) -> firstOrFail ();
// Recuperation des wallets hyperviseur et superviseur
$codeGenerer = CodeGenerer :: findOrFail ( $network_agent -> codeGenerer_id );
$superviseur = AgentPlus :: where ( 'code_membre' , $codeGenerer -> code_parrain ) -> firstOrFail ();
$hyperviseur = AgentPlus :: where ( 'code_membre' , $superviseur -> code_parrain ) -> firstOrFail ();
$wallet_agent_sup = WalletAgent :: where ( 'agent_id' , $superviseur -> id ) -> firstOrFail ();
$wallet_agent_hyp = WalletAgent :: where ( 'agent_id' , $hyperviseur -> id ) -> firstOrFail ();
$walletSuperviseur = Wallet :: findOrFail ( $wallet_agent_sup -> wallet_id );
2022-04-20 16:03:13 +00:00
} else {
2022-04-20 08:08:32 +00:00
$walletUser = WalletsUser :: findOrFail ( $id_wallet_user );
2023-07-26 12:52:32 +00:00
// Pour les operations à cartes, le pays initial c'est le pays de la carte
if ( in_array ( $type -> id , [ 10 , 11 ])){
$init_country = $walletUser -> user -> card_country_id ;
} else {
$init_country = $walletUser -> user -> network -> country -> id ;
2023-08-02 18:16:06 +00:00
if ( $type -> id == 21 ){
$withLinkedCard = $request -> input ( 'with_linked_card' , false );
if ( $withLinkedCard ) {
$init_country = $walletUser -> user -> card_country_id ;
} else {
$init_country = Country :: where ( 'code_country' , $request -> input ( 'customer_country' )) -> first () ? -> id ;
}
}
2023-07-26 12:52:32 +00:00
}
$transaction -> init_country = $init_country ;
2020-06-24 07:36:54 +00:00
$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 );
} else {
return $this -> errorResponse ( trans ( 'errors.no_ilink_network' ));
}
2020-06-21 21:49:24 +00:00
2020-06-24 07:36:54 +00:00
$hyperviseur = AgentPlus :: where ( 'category' , 'hyper' ) -> where ( 'network_id' , $config -> id_network ) -> firstOrFail ();
2020-06-21 21:49:24 +00:00
$wallet_agent_hyp = WalletAgent :: where ( 'agent_id' , $hyperviseur -> id ) -> firstOrFail ();
}
2022-04-20 16:03:13 +00:00
$walletHyperviseur = Wallet :: findOrFail ( $wallet_agent_hyp -> wallet_id );
2020-06-24 15:49:41 +00:00
$transaction -> network_emetteur = $config -> id_network ;
2020-06-19 13:48:27 +00:00
$taxesNationales = array_values ( array_filter ( $config -> taxes -> all (), function ( $tax ) {
2020-08-14 16:14:49 +00:00
return $tax -> destination == 'national' && $tax -> categorie == 'wallet' ;
2020-06-19 13:48:27 +00:00
}));
$taxesInternationales = array_values ( array_filter ( $config -> taxes -> all (), function ( $tax ) {
2020-08-14 16:14:49 +00:00
return $tax -> destination == 'international' && $tax -> categorie == 'wallet' ;
2020-06-19 13:48:27 +00:00
}));
2022-04-20 08:08:32 +00:00
$paliers_config_wallets = $config -> paliers_config_wallets -> all ();
$paliers_commission_wallets = $config -> paliers_commissions_wallets -> all ();
2020-06-19 13:48:27 +00:00
2022-04-20 08:08:32 +00:00
$plr_user_wallet_wallet = $this -> getPaliers ( $paliers_config_wallets , " user_wallet_wallet_international " );
$plr_user_wallet_cash = $this -> getPaliers ( $paliers_config_wallets , " user_wallet_cash_international " );
$plr_agent_depot_wallet_ilink = $this -> getPaliers ( $paliers_config_wallets , " agent_depot_wallet_ilink_international " );
$plr_agent_depot_autre_wallet = $this -> getPaliers ( $paliers_config_wallets , " agent_depot_autre_wallet_international " );
$plr_agent_cash_cash = $this -> getPaliers ( $paliers_config_wallets , " agent_cash_cash_international " );
2020-06-19 13:48:27 +00:00
2022-04-20 08:08:32 +00:00
$plr_user_wallet_wallet_national = $this -> getPaliers ( $paliers_config_wallets , " user_wallet_wallet_national " );
$plr_user_wallet_cash_national = $this -> getPaliers ( $paliers_config_wallets , " user_wallet_cash_national " );
$plr_agent_depot_wallet_ilink_national = $this -> getPaliers ( $paliers_config_wallets , " agent_depot_wallet_ilink_national " );
$plr_agent_depot_autre_wallet_national = $this -> getPaliers ( $paliers_config_wallets , " agent_depot_autre_wallet_national " );
$plr_agent_cash_cash_national = $this -> getPaliers ( $paliers_config_wallets , " agent_cash_cash_national " );
2020-06-19 13:48:27 +00:00
$data = $request -> all ();
2023-08-10 11:15:37 +00:00
if ( isset ( $request -> cvv ) && ! is_numeric ( $request -> cvv )){
2020-06-19 13:48:27 +00:00
return $this -> errorResponse ( 'errors.invalid_cvv' );
2023-08-10 11:15:37 +00:00
}
// Verify transaction id
$transaction_id = $request -> input ( 'payment_transaction_id' );
if ( ! empty ( $transaction_id )) {
if ( WalletIlinkTransaction :: where ( 'payment_transaction_id' , $transaction_id ) -> exists ()) {
return $this -> errorResponse ( trans ( 'errors.payment_invalid' ), 400 );
}
}
2020-06-19 13:48:27 +00:00
$transaction -> fill ( $data );
2022-04-20 08:08:32 +00:00
try {
DB :: beginTransaction ();
switch ( $type -> id ) {
case 1 : //User - Envoi wallet à wallet
$this -> validate ( $request , $transaction -> send_wallet_wallet_rules ());
$user = $walletUser -> user ;
$this -> validatePassword ( $request -> password , $user -> encrypted_password , $user -> salt );
2020-09-28 15:39:57 +00:00
if ( $init_country != $request -> final_country ) {
2022-04-20 08:08:32 +00:00
$this -> checkUserIdentification ( $user -> id );
2020-09-28 15:39:57 +00:00
}
2020-06-24 07:36:54 +00:00
if ( $request -> montant > $walletUser -> balance ) {
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.insufficient_balance' ), 500 );
2020-06-24 07:36:54 +00:00
} else {
2020-09-28 15:39:57 +00:00
//Verification des limites reglementaires
2022-04-20 08:08:32 +00:00
$this -> checkReguationsLimits ( $walletUser -> id , $init_country , $request -> final_country , $transaction -> montant );
2020-09-28 15:39:57 +00:00
2023-07-12 19:32:21 +00:00
$frais = ( $init_country != $request -> final_country ) ? $this -> calculateFees ( $plr_user_wallet_wallet , $request -> montant ) : $this -> calculateFees ( $plr_user_wallet_wallet_national , $request -> montant );
$reseauPayeur = PayingNetwork :: where ( 'id_network' , $request -> network_destinataire ) -> where ( 'id_configWallet' , $config -> id ) -> first ();
2023-10-04 11:32:23 +00:00
if ( empty ( $reseauPayeur )){
return $this -> errorResponse ( __ ( 'errors.service_unavailable_in_country' ));
}
2023-07-12 19:32:21 +00:00
$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 ;
2023-07-14 12:24:10 +00:00
$taxe = ( $init_country != $request -> final_country ) ? $this -> calculateTax ( $taxesInternationales , $frais ) : $this -> calculateTax ( $taxesNationales , $frais );
2023-07-12 19:32:21 +00:00
$transaction -> frais = $frais ;
$transaction -> taxe = $taxe ;
2020-06-28 10:45:17 +00:00
$transaction -> montant_net = $montantDepot = $transaction -> montant - $frais - $taxe ;
2020-07-04 10:20:26 +00:00
$transaction -> montant_net_final_country = $this -> toMoneyAmount ( $montantDepot , $init_country , $request -> final_country );
2020-07-03 19:53:34 +00:00
2020-07-04 10:20:26 +00:00
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 ;
}
2020-07-03 19:53:34 +00:00
2020-06-23 16:21:26 +00:00
$transaction -> commission_hyp = $transaction -> part_reseau_emetteur ;
2020-10-27 10:52:37 +00:00
$transaction -> id_transaction = $this -> getTransactionID ();
2023-06-07 20:08:33 +00:00
$transaction -> type_id_destinataire = $request -> input ( 'type_id_destinataire' );
2023-08-01 06:24:56 +00:00
$transaction -> nom_destinataire = $request -> nom_destinataire ;
$transaction -> prenom_destinataire = $request -> prenom_destinataire ;
2020-06-23 16:21:26 +00:00
if ( $configPayeur -> type == 'ilink' ) {
2023-06-07 20:08:33 +00:00
$destinataire = User :: where ( $transaction -> type_id_destinataire , $request -> id_destinataire ) -> first ();
2020-06-24 07:36:54 +00:00
if ( $destinataire ) { // Si c'est un wallet ilink
2023-08-01 06:24:56 +00:00
$transaction -> nom_destinataire = $destinataire -> lastname ;
$transaction -> prenom_destinataire = $destinataire -> firstname ;
2020-06-24 07:36:54 +00:00
if ( $destinataire -> network -> country -> id == $request -> final_country ) {
$walletDestinataire = WalletsUser :: where ( 'idUser' , $destinataire -> id ) -> firstOrFail ();
2023-07-12 19:32:21 +00:00
$walletDestinataire -> balance += $transaction -> montant_net_final_country ;
2020-06-24 07:36:54 +00:00
$walletDestinataire -> save ();
} else {
$country = Country :: findOrFail ( $request -> final_country );
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.wallet_country_not_match' , [ 'country' => $country -> name ]), 500 );
2020-06-24 07:36:54 +00:00
}
2020-06-23 16:21:26 +00:00
} else {
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.wallet_not_defined' ), 500 );
2020-06-23 16:21:26 +00:00
}
2020-10-27 10:52:37 +00:00
//Mise a jour des comissions et compensation
2020-11-13 14:39:03 +00:00
if ( isset ( $reseauPayeur )) {
$reseauPayeur -> balance_com += $transaction -> part_reseau_payeur_final_country ;
$reseauPayeur -> balance_compensation += $transaction -> montant_net_final_country ;
}
2020-10-27 10:52:37 +00:00
2020-06-24 17:34:18 +00:00
//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 );
2020-06-27 15:04:28 +00:00
$walletHyperviseurPayeur -> balance_com += $this -> toMoneyAmount ( $transaction -> part_reseau_payeur , $init_country , $request -> final_country );
2020-06-24 17:34:18 +00:00
$transaction -> id_wallet_hyp_payeur = $walletHyperviseurPayeur -> id ;
$walletHyperviseurPayeur -> save ();
}
2020-06-23 16:21:26 +00:00
} else {
2020-10-27 10:52:37 +00:00
//Emettre requete SSL vers wallet extene correspondant pour recharger le compte du destinataire
// La mise à jour des comissions de compensation se fera lors du traitement de la transaction
2023-06-29 08:51:55 +00:00
$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 ,
2023-08-01 06:24:56 +00:00
'customer_name' => $transaction -> prenom_destinataire ,
'customer_surname' => $transaction -> nom_destinataire ,
2023-06-29 08:51:55 +00:00
'customer_phone_number' => $transaction -> id_destinataire ,
'customer_country' => $countryCurrency -> code_country ,
'reason' => " User - Envoi de wallet à wallet "
]);
2020-06-23 16:21:26 +00:00
}
2020-06-24 17:28:11 +00:00
$walletHyperviseur -> balance_com += $transaction -> part_reseau_emetteur ;
$walletUser -> balance -= $transaction -> montant ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
2020-06-24 17:34:18 +00:00
2020-06-24 17:28:11 +00:00
$walletHyperviseur -> save ();
$walletUser -> save ();
2023-07-25 10:12:53 +00:00
if ( isset ( $reseauPayeur )){
2020-06-29 16:46:43 +00:00
$reseauPayeur -> save ();
2023-07-25 10:12:53 +00:00
}
2020-11-13 14:21:17 +00:00
$transaction -> date = $this -> getCurrentTime ( $init_country );
2020-06-23 16:21:26 +00:00
$transaction -> save ();
2020-06-27 15:04:28 +00:00
$message = trans ( 'messages.successful_user_send_to_wallet' ,
[ 'id_transaction' => $transaction -> id_transaction , 'amount' => $this -> toMoney ( $transaction -> montant , $init_country ), 'net_init' => $this -> toMoney ( $montantDepot , $init_country ),
2023-07-26 12:52:32 +00:00
'net_final' => $this -> toMoney ( $transaction -> montant_net_final_country , $request -> final_country ), 'fees' => $this -> toMoney ( $frais + $taxe , $init_country ),
2020-06-25 08:01:59 +00:00
'init_country' => $this -> getCountryName ( $init_country ), 'final_country' => $this -> getCountryName ( $request -> final_country ),
2020-11-03 09:05:30 +00:00
'sender_code' => $user -> user_code , 'receiver_code' => $transaction -> id_destinataire , 'network' => $this -> getNetworkName ( $transaction -> network_destinataire )]);
2020-07-08 16:51:11 +00:00
$this -> sendMail ( $user -> email , trans ( 'messages.successful_transaction' ), $message );
2022-04-20 08:08:32 +00:00
$response_message = $message . trans ( 'messages.sent_by_mail' );
2020-06-22 15:09:26 +00:00
}
2022-04-20 08:08:32 +00:00
break ;
case 2 : //User - Envoi de wallet à carte
$this -> validate ( $request , $transaction -> user_card_rules ());
$user = $walletUser -> user ;
$this -> validatePassword ( $request -> password , $user -> encrypted_password , $user -> salt );
2020-06-23 16:21:26 +00:00
if ( $request -> montant > $walletUser -> balance ) {
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.insufficient_balance' ), 500 );
2020-06-23 16:21:26 +00:00
} else {
2022-04-20 08:08:32 +00:00
if ( ! ( isset ( $user -> numero_carte ) && isset ( $user -> expiration_date ))) {
throw new Exception ( trans ( 'errors.no_bank_card_attached' ), 500 );
}
2020-06-30 11:06:56 +00:00
$transaction -> expiration_date = $user -> expiration_date ;
$transaction -> numero_carte = $user -> numero_carte ;
2020-06-23 16:21:26 +00:00
2023-07-26 12:52:32 +00:00
$final_country = $user -> card_country_id ;
$transaction -> final_country = $final_country ;
2022-04-20 16:03:13 +00:00
$plr_user_wallet_cart_national = $this -> getPaliers ( $paliers_commission_wallets , 'user_wallet_cart_national' );
2023-07-26 12:52:32 +00:00
$plr_user_wallet_cart_international = $this -> getPaliers ( $paliers_commission_wallets , 'user_wallet_cart_international' );
2022-04-20 16:03:13 +00:00
$plr_hyp_user_wallet_cart_national = $this -> getPaliers ( $paliers_commission_wallets , 'hyp_user_wallet_cart_national' );
2023-07-26 12:52:32 +00:00
$plr_hyp_user_wallet_cart_international = $this -> getPaliers ( $paliers_commission_wallets , 'hyp_user_wallet_cart_international' );
2022-04-20 16:03:13 +00:00
$plr_bank_user_wallet_cart_national = $this -> getPaliers ( $paliers_commission_wallets , 'bank_user_wallet_cart_national' );
2023-07-26 12:52:32 +00:00
$plr_bank_user_wallet_cart_international = $this -> getPaliers ( $paliers_commission_wallets , 'bank_user_wallet_cart_international' );
2022-04-20 16:03:13 +00:00
2023-07-26 12:52:32 +00:00
$frais = $this -> calculateFees ( $init_country != $final_country ? $plr_user_wallet_cart_international : $plr_user_wallet_cart_national , $request -> montant );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
2023-07-26 12:52:32 +00:00
'country_id' => $final_country ,
2023-07-12 19:32:21 +00:00
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: CARD
]);
$frais += $fees ;
2022-04-20 16:03:13 +00:00
2023-07-26 12:52:32 +00:00
$taxe = $this -> calculateTax ( $init_country != $final_country ? $taxesInternationales : $taxesNationales , $frais );
2023-07-14 12:24:10 +00:00
$transaction -> taxe = $taxe ;
2023-07-26 12:52:32 +00:00
$transaction -> frais = $frais ;
2023-07-14 12:24:10 +00:00
$transaction -> montant_net = $montantDepot = $transaction -> montant - $frais - $taxe ;
2023-09-26 12:40:14 +00:00
$transaction -> montant_net_final_country = $this -> toMoneyAmount ( $montantDepot , $init_country , $final_country );
2023-06-07 20:08:33 +00:00
2023-07-26 12:52:32 +00:00
$identification = Identification :: with ([ 'country' ]) -> where ( 'id_user' , $user -> id ) -> first ();
$countryCurrency = CountriesCurrency :: findOrFail ( $final_country );
2023-06-07 20:08:33 +00:00
// PayOut through payment service
2023-06-29 08:51:55 +00:00
$this -> handlePayOut ( $transaction , [
2023-06-07 20:08:33 +00:00
'card_no' => $user -> numero_carte ,
'exp_month' => date ( " m " , strtotime ( $user -> expiration_date )),
'exp_year' => date ( " Y " , strtotime ( $user -> expiration_date )),
'cvc' => $request -> input ( 'cvv' ),
2023-07-26 12:52:32 +00:00
'amount' => $transaction -> montant_net_final_country ,
'currency' => $countryCurrency -> currency_code ,
2023-06-07 20:08:33 +00:00
'payment_method' => 'CARD' ,
'customer_id' => $user -> id ,
'customer_email' => $user -> email ,
'customer_name' => $identification ? $identification -> firstname : $user -> firstname ,
'customer_surname' => $identification ? $identification -> lastname : $user -> lastname ,
'customer_phone_number' => $user -> phone ,
'customer_address' => $identification ? $identification -> town : $user -> adresse ,
'customer_city' => $identification ? $identification -> town : $user -> adresse ,
2023-07-26 12:52:32 +00:00
'customer_country' => $countryCurrency -> code_country ,
2023-06-07 20:08:33 +00:00
'reason' => " User - Envoi de wallet à carte "
2023-06-29 08:51:55 +00:00
]);
$walletUser -> balance -= $transaction -> montant ;
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
2023-07-26 12:52:32 +00:00
$transaction -> commission_banque = $this -> calculateFees ( $init_country != $final_country ? $plr_bank_user_wallet_cart_international : $plr_bank_user_wallet_cart_national , $request -> montant , $frais );
$transaction -> commission_hyp = $this -> calculateFees ( $init_country != $final_country ? $plr_hyp_user_wallet_cart_international : $plr_hyp_user_wallet_cart_national , $request -> montant , $frais );
2023-06-29 08:51:55 +00:00
$walletHyperviseur -> balance_com += $transaction -> commission_hyp ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
$walletHyperviseur -> save ();
$walletUser -> save ();
$transaction -> id_transaction = $this -> getTransactionID ();
$transaction -> date = $this -> getCurrentTime ( $init_country );
$transaction -> save ();
$message = trans ( 'messages.successful_user_send_to_cart' ,
[ 'id_transaction' => $transaction -> id_transaction , 'amount' => $this -> toMoney ( $transaction -> montant , $init_country ),
2023-07-26 12:52:32 +00:00
'net_init' => $this -> toMoney ( $montantDepot , $init_country ), 'net_final' => $this -> toMoney ( $transaction -> montant_net_final_country , $final_country ), 'fees' => $this -> toMoney ( $frais + $taxe , $init_country ),
'init_country' => $this -> getCountryName ( $init_country ), 'final_country' => $this -> getCountryName ( $final_country ),
2023-06-29 08:51:55 +00:00
'sender_code' => $user -> user_code , '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' );
2020-06-19 13:48:27 +00:00
2020-06-23 16:21:26 +00:00
}
2022-04-20 08:08:32 +00:00
break ;
case 3 : //User - Envoi de wallet à cash
$this -> validate ( $request , $transaction -> send_wallet_cash_rules ());
$user = $walletUser -> user ;
$this -> validatePassword ( $request -> password , $user -> encrypted_password , $user -> salt );
2020-09-28 15:39:57 +00:00
if ( $init_country != $request -> final_country ) {
2022-04-20 08:08:32 +00:00
$this -> checkUserIdentification ( $user -> id );
2020-09-28 15:39:57 +00:00
}
2020-06-27 15:04:28 +00:00
if ( $request -> montant > $walletUser -> balance ) {
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.insufficient_balance' ), 500 );
2020-06-27 15:04:28 +00:00
} else {
2020-09-28 15:39:57 +00:00
//Verification des limites reglementaires
2022-04-20 08:08:32 +00:00
$this -> checkReguationsLimits ( $walletUser -> id , $init_country , $request -> final_country , $transaction -> montant );
2020-09-28 15:39:57 +00:00
2023-07-22 14:12:07 +00:00
$frais = ( $init_country != $request -> final_country ) ? $this -> calculateFees ( $plr_user_wallet_cash , $request -> montant ) : $this -> calculateFees ( $plr_user_wallet_cash_national , $request -> montant );
$configPayeur = ConfigWallet :: where ( 'id_network' , $request -> network_destinataire ) -> firstOrFail ();
$reseauPayeur = PayingNetwork :: where ( 'id_network' , $request -> network_destinataire ) -> where ( 'id_configWallet' , $config -> id ) -> first ();
2023-10-04 11:32:23 +00:00
if ( empty ( $reseauPayeur )){
return $this -> errorResponse ( __ ( 'errors.service_unavailable_in_country' ));
}
2023-07-22 14:12:07 +00:00
$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 ;
$taxe = ( $init_country != $request -> final_country ) ? $this -> calculateTax ( $taxesInternationales , $frais ) : $this -> calculateTax ( $taxesNationales , $frais );
$transaction -> frais = $frais ;
$transaction -> taxe = $taxe ;
2020-06-28 10:45:17 +00:00
$transaction -> montant_net = $montantRetrait = $transaction -> montant - $frais - $taxe ;
2020-07-04 10:20:26 +00:00
$transaction -> montant_net_final_country = $this -> toMoneyAmount ( $montantRetrait , $init_country , $request -> final_country );
2020-07-03 19:53:34 +00:00
2020-07-04 10:20:26 +00:00
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 ;
}
2020-07-03 19:53:34 +00:00
2020-06-28 10:45:17 +00:00
$transaction -> commission_hyp = $transaction -> part_reseau_emetteur ;
2020-07-03 18:24:41 +00:00
$transaction -> commission_hyp_final_country = $this -> toMoneyAmount ( $transaction -> commission_hyp , $init_country , $request -> final_country );
2020-07-04 10:20:26 +00:00
2020-10-27 10:52:37 +00:00
$transaction -> id_transaction = $this -> getTransactionID ();
2020-06-28 10:45:17 +00:00
if ( $configPayeur -> type == 'ilink' ) {
2020-10-27 10:52:37 +00:00
//Mise a jour des comissions et compensation
2020-11-13 14:39:03 +00:00
if ( isset ( $reseauPayeur )) {
$reseauPayeur -> balance_com += $transaction -> part_reseau_payeur_final_country ;
$reseauPayeur -> balance_compensation += $transaction -> montant_net_final_country ;
}
2020-10-27 10:52:37 +00:00
2020-06-28 10:45:17 +00:00
//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 ();
}
2020-06-30 13:09:00 +00:00
} else {
2020-10-27 10:52:37 +00:00
//Emettre requete SSL vers wallet extene correspondant pour recharger le compte du destinataire
// La mise à jour des comissions de compensation se fera lors du traitement de la transaction
2023-06-29 08:51:55 +00:00
$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' => $request -> input ( 'prenom_destinataire' ),
'customer_surname' => $request -> input ( 'nom_destinataire' ),
'customer_phone_number' => $transaction -> id_destinataire ,
'customer_country' => $countryCurrency -> code_country ,
'reason' => " User - Envoi de wallet à cash "
]);
2020-06-28 10:45:17 +00:00
}
2020-06-27 15:04:28 +00:00
$walletUser -> balance -= $transaction -> montant ;
2020-06-28 10:45:17 +00:00
$walletHyperviseur -> balance_com += $transaction -> commission_hyp ;
2020-06-27 15:04:28 +00:00
$code_retrait = $this -> random_string ();
$hash = $this -> hashSSHA ( $code_retrait );
$transaction -> encrypted_code_retrait = $hash [ 'encrypted' ];
$transaction -> code_retrait_salt = $hash [ 'salt' ];
2020-06-19 13:48:27 +00:00
2020-06-27 15:04:28 +00:00
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
2020-10-27 10:52:37 +00:00
2020-06-30 13:09:00 +00:00
if ( isset ( $reseauPayeur ))
2020-06-29 16:46:43 +00:00
$reseauPayeur -> save ();
2020-06-27 15:04:28 +00:00
$walletHyperviseur -> save ();
$walletUser -> save ();
2020-11-13 14:21:17 +00:00
$transaction -> date = $this -> getCurrentTime ( $init_country );
2020-06-28 10:45:17 +00:00
$transaction -> status_retrait = 0 ;
2020-06-27 15:04:28 +00:00
$transaction -> save ();
$message = trans ( 'messages.successful_user_send_to_cash' ,
[ '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 ),
2020-06-30 13:09:00 +00:00
'init_country' => $this -> getCountryName ( $init_country ), 'final_country' => $this -> getCountryName ( $request -> final_country ), 'code' => wordwrap ( $code_retrait , 4 , ' ' , true ),
2020-07-08 16:51:11 +00:00
'sender_code' => $user -> user_code , 'receiver_code' => $transaction -> id_destinataire , 'receiver_name' => $request -> prenom_destinataire . ' ' . $request -> nom_destinataire ,
2020-11-03 09:05:30 +00:00
'sender_name' => $user -> lastname . ' ' . $user -> firstname , 'network' => $this -> getNetworkName ( $transaction -> network_destinataire )]);
2020-06-30 13:09:00 +00:00
$this -> sendMail ( $user -> email , trans ( 'messages.successful_transaction' ), $message );
2022-04-20 08:08:32 +00:00
$response_message = ( $message . trans ( 'messages.sent_by_mail' ));
}
break ;
/**
* @ OA\Schema (
* schema = " user_send_from_wallet_to_bank " ,
* title = " User - Envoi de wallet à banque " ,
* @ OA\Property ( property = " type " ,
* type = " integer " ,
* enum = { 4 },
* default = 4 ,
* description = " Type de la transaction "
* ),
* @ OA\Property ( property = " id_wallet_user " ,
* type = " integer " ,
* example = 9 ,
* description = " ID du wallet de l'utilisateur enregistré dans la base de données "
* ),
* @ OA\Property ( property = " id_wallet_network " ,
* type = " integer " ,
* example = 101 ,
* description = " ID du reseau enregistré dans la base de données auquel appartient le wallet "
* ),
* @ OA\Property ( property = " montant " ,
* type = " number " ,
* example = 10000 ,
* description = " Montant de la transaction "
* ),
* @ OA\Property ( property = " password " ,
* type = " string " ,
* description = " Mot de passe "
* )
* )
*/
case 4 : //User - Envoi de wallet à banque
$this -> validate ( $request , [
'id_wallet_network' => 'required|integer|min:0|not_in:0' ,
]);
$user = $walletUser -> user ;
$this -> validatePassword ( $request -> password , $user -> encrypted_password , $user -> salt );
$this -> checkUserIdentification ( $user -> id );
if ( ! ( isset ( $user -> iban ) && isset ( $user -> id_bank_country )))
throw new Exception ( trans ( 'errors.wallet_not_linked_to_bank_account' ), 422 );
if ( $request -> montant > $walletUser -> balance )
throw new Exception ( trans ( 'errors.insufficient_balance' ), 422 );
//Reverifier si l'operateur est toujours associé au reseau
$network_bank = NetworksOperator :: where ( 'id_network' , $request -> id_wallet_network ) -> where ( 'id_operator_country' , $user -> id_bank_country ) -> first ();
if ( ! $network_bank )
throw new Exception ( trans ( 'errors.operator_not_associated_with_network' ) . '. ' . trans ( 'errors.update_banking_information' ));
if ( $network_bank -> operators_country -> operator -> type != 'bank' )
throw new Exception ( trans ( 'errors.not_banking_operator' ) . '. ' . trans ( 'errors.update_banking_information' ));
//Reverifier le code IBAN correspond toujours
$country_code = $network_bank -> network -> country -> code_country ;
$bank_code = $network_bank -> operators_country -> code ;
switch ( $this -> checkIBAN ( $user -> iban , $country_code , $bank_code )) {
case 0 :
throw new Exception ( trans ( 'errors.invalid_iban' ) . '. ' . trans ( 'errors.update_banking_information' ));
case 1 :
throw new Exception ( trans ( 'errors.country_not_match_iban' ) . '. ' . trans ( 'errors.update_banking_information' ));
case 2 :
throw new Exception ( trans ( 'errors.bank_not_match_iban' ) . '. ' . trans ( 'errors.update_banking_information' ));
2020-06-27 15:04:28 +00:00
}
2020-11-03 09:05:30 +00:00
2022-04-20 08:08:32 +00:00
$transaction -> frais = $frais = 0 ;
$transaction -> taxe = $taxe = 0 ;
// $walletUser->balance -= $transaction->montant;
//Emettre une trame SSL pour recharger le compte bancaire du montant de la transaction
$transaction -> commission_banque = 0 ;
2020-11-06 17:40:08 +00:00
2022-04-20 08:08:32 +00:00
$transaction -> commission_hyp = 0 ;
2020-11-05 17:12:55 +00:00
2022-04-20 08:08:32 +00:00
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
$transaction -> frais = $frais ;
$transaction -> bank = $user -> bank -> operators_country -> operator -> nom ;
$transaction -> country = $user -> bank -> network -> country -> name ;
$transaction -> id_bank = $user -> id_bank_country ;
$transaction -> iban = $user -> iban ;
$transaction -> date = $this -> getCurrentTime ( $init_country );
2020-11-03 09:05:30 +00:00
// $walletUser->save();
2022-04-20 08:08:32 +00:00
$transaction -> id_transaction = $this -> getTransactionID ();
2020-11-03 09:05:30 +00:00
// $transaction->save();
2022-04-20 08:08:32 +00:00
Log :: info ( '-------------------------- User - Envoi de wallet à banque ------------------------------------' );
Log :: info ( json_encode ( $transaction ));
Log :: info ( '------------------------------------------------------------------------------------------------' );
2020-11-03 09:05:30 +00:00
2022-04-20 08:08:32 +00:00
$message = trans ( 'messages.successful_user_send_to_bank' ,
[ 'id_transaction' => $transaction -> id_transaction , 'amount' => $this -> toMoney ( $transaction -> montant , $init_country ),
'net' => $this -> toMoney ( $transaction -> montant , $init_country ), 'iban' => $request -> iban , 'fees' => $this -> toMoney ( $frais , $init_country ),
'sender_code' => $user -> user_code , 'bank' => $transaction -> bank , 'country' => $transaction -> country ]);
$this -> sendMail ( $user -> email , trans ( 'messages.successful_transaction' ), $message );
$response_message = ( $message . trans ( 'messages.sent_by_mail' ));
2020-11-03 09:05:30 +00:00
2022-04-20 08:08:32 +00:00
break ;
2020-06-19 13:48:27 +00:00
// case 5: //User - Envoi de carte à wallet
// $frais =$montant * $config->taux_com_user_carte_wallet / 100;
//// $taxe = ($init_country != $final_country) ? $this->calculateTax($taxesInternationales , $frais) : $this->calculateTax($taxesNationales ,$frais);
// break;
// case 6: //User - Envoi de carte à cash
// $frais =$montant * $config->taux_com_user_carte_cash / 100;
//// $taxe = ($init_country != $final_country) ? $this->calculateTax($taxesInternationales , $frais) : $this->calculateTax($taxesNationales ,$frais);
// break;
2022-04-20 08:08:32 +00:00
case 9 : // User - Retrait de wallet en cash
$user = $walletUser -> user ;
$this -> validatePassword ( $request -> password , $user -> encrypted_password , $user -> salt );
2020-06-29 16:46:43 +00:00
if ( $request -> montant > $walletUser -> balance ) {
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.insufficient_balance' ));
2020-06-29 16:46:43 +00:00
} else {
2022-04-20 08:08:32 +00:00
$this -> checkUserIdentification ( $user -> id );
2020-09-28 15:39:57 +00:00
2020-07-01 17:54:12 +00:00
$transaction -> final_country = $init_country ;
2020-06-29 16:46:43 +00:00
$transaction -> frais = $frais = $this -> calculateFees ( $plr_user_wallet_cash_national , $request -> montant );
$transaction -> taxe = $taxe = $this -> calculateTax ( $taxesNationales , $frais );
2020-07-03 10:58:43 +00:00
$transaction -> montant_net_final_country = $transaction -> montant_net = $montantRetrait = $transaction -> montant - $frais - $taxe ;
$transaction -> commission_hyp_final_country = $transaction -> commission_hyp = $frais ;
2020-06-29 16:46:43 +00:00
$walletUser -> balance -= $transaction -> montant ;
$walletHyperviseur -> balance_com += $transaction -> commission_hyp ;
$code_retrait = $this -> random_string ();
$hash = $this -> hashSSHA ( $code_retrait );
$transaction -> encrypted_code_retrait = $hash [ 'encrypted' ];
$transaction -> code_retrait_salt = $hash [ 'salt' ];
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
$transaction -> id_transaction = $this -> getTransactionID ();
2020-06-19 13:48:27 +00:00
2020-06-29 16:46:43 +00:00
$walletHyperviseur -> save ();
$walletUser -> save ();
2020-11-13 14:21:17 +00:00
$transaction -> date = $this -> getCurrentTime ( $init_country );
2020-06-29 16:46:43 +00:00
$transaction -> status_retrait = 0 ;
$transaction -> save ();
$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 ),
2020-06-30 13:09:00 +00:00
'fees' => $this -> toMoney ( $frais + $taxe , $init_country ), 'code' => wordwrap ( $code_retrait , 4 , ' ' , true ),
2020-07-03 18:24:41 +00:00
'sender_code' => $user -> user_code , 'init_country' => $this -> getCountryName ( $init_country ),]);
2020-06-30 13:09:00 +00:00
$this -> sendMail ( $user -> email , trans ( 'messages.successful_transaction' ), $message );
2022-04-20 08:08:32 +00:00
$response_message = ( $message . trans ( 'messages.sent_by_mail' ));
2020-06-29 16:46:43 +00:00
}
2022-04-20 08:08:32 +00:00
break ;
case 10 : //User - Retrait de carte vers wallet
$this -> validate ( $request , $transaction -> user_card_rules ());
$user = $walletUser -> user ;
$this -> validatePassword ( $request -> password , $user -> encrypted_password , $user -> salt );
2020-06-30 13:09:00 +00:00
if ( ! ( isset ( $user -> numero_carte ) && isset ( $user -> expiration_date )))
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.no_bank_card_attached' ));
2020-06-29 16:46:43 +00:00
2020-06-30 13:09:00 +00:00
$transaction -> expiration_date = $user -> expiration_date ;
$transaction -> numero_carte = $user -> numero_carte ;
2020-06-29 16:46:43 +00:00
2023-07-26 12:52:32 +00:00
$final_country = $walletUser -> user -> network -> country -> id ;
$transaction -> final_country = $final_country ;
2022-04-20 16:03:13 +00:00
$plr_user_cart_wallet_national = $this -> getPaliers ( $paliers_commission_wallets , 'user_cart_wallet_national' );
2023-07-26 12:52:32 +00:00
$plr_user_cart_wallet_international = $this -> getPaliers ( $paliers_commission_wallets , 'user_cart_wallet_international' );
2022-04-20 16:03:13 +00:00
$plr_hyp_user_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'hyp_user_cart_cash_national' );
2023-07-26 12:52:32 +00:00
$plr_hyp_user_cart_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'hyp_user_cart_cash_international' );
2022-04-20 16:03:13 +00:00
$plr_bank_user_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'bank_user_cart_cash_national' );
2023-07-26 12:52:32 +00:00
$plr_bank_user_cart_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'bank_user_cart_cash_international' );
2022-04-20 16:03:13 +00:00
2023-07-26 12:52:32 +00:00
$frais = $this -> calculateFees ( $init_country != $final_country ? $plr_user_cart_wallet_international : $plr_user_cart_wallet_national , $request -> montant );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_OUT ,
'payment_method' => PaymentMethod :: CARD
]);
$frais += $fees ;
2023-07-26 12:52:32 +00:00
$taxe = $this -> calculateTax ( $init_country != $final_country ? $taxesInternationales : $taxesNationales , $frais );
2023-07-14 12:24:10 +00:00
$transaction -> taxe = $taxe ;
2023-07-26 12:52:32 +00:00
$transaction -> frais = $frais ;
2023-09-14 12:33:11 +00:00
$montantRetrait = $transaction -> montant + ( $frais + $taxe );
$transaction -> montant_net = $this -> toMoneyAmount ( $transaction -> montant , $init_country , $final_country );
2023-07-26 12:52:32 +00:00
$transaction -> montant_net_final_country = $this -> toMoneyAmount ( $montantRetrait , $init_country , $final_country );
2020-08-09 22:13:21 +00:00
$identification = Identification :: where ( 'id_user' , $user -> id ) -> first ();
2023-07-26 12:52:32 +00:00
$countryCurrency = CountriesCurrency :: findOrFail ( $init_country );
2023-06-07 20:08:33 +00:00
$payment_transaction_id = $request -> input ( 'payment_transaction_id' );
2023-06-29 08:51:55 +00:00
$result = $this -> handlePayIn ( $transaction , [
'card_no' => $user -> numero_carte ,
'exp_month' => date ( " m " , strtotime ( $user -> expiration_date )),
'exp_year' => date ( " Y " , strtotime ( $user -> expiration_date )),
'cvc' => $request -> input ( 'cvv' ),
2023-09-14 12:33:11 +00:00
'amount' => $transaction -> montant_net_final_country ,
2023-07-26 12:52:32 +00:00
'currency' => $countryCurrency -> currency_code ,
2023-06-29 08:51:55 +00:00
'payment_method' => 'CARD' ,
'customer_id' => $user -> id ,
'customer_email' => $user -> email ,
'customer_name' => $identification ? $identification -> firstname : $user -> firstname ,
'customer_surname' => $identification ? $identification -> lastname : $user -> lastname ,
'customer_address' => $identification ? $identification -> town : $user -> adresse ,
'customer_city' => $identification ? $identification -> town : $user -> adresse ,
2023-07-26 12:52:32 +00:00
'customer_country' => $countryCurrency -> code_country ,
2023-06-29 08:51:55 +00:00
'reason' => " User - Retrait de carte vers wallet "
], $payment_transaction_id );
if ( ! ( $result instanceof WalletIlinkTransaction )) {
return $result ;
2023-06-07 20:08:33 +00:00
}
2020-06-29 16:46:43 +00:00
2023-07-26 12:52:32 +00:00
$transaction -> commission_banque = $this -> calculateFees ( $init_country != $final_country ? $plr_bank_user_cart_cash_international : $plr_bank_user_cart_cash_national , $request -> montant , $frais );
2023-06-29 08:51:55 +00:00
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
2020-06-19 13:48:27 +00:00
2023-09-14 12:33:11 +00:00
$walletUser -> balance += $transaction -> montant_net ;
2023-07-26 12:52:32 +00:00
$transaction -> commission_hyp = $this -> calculateFees ( $init_country != $final_country ? $plr_hyp_user_cart_cash_international : $plr_hyp_user_cart_cash_national , $request -> montant , $frais );
2023-06-29 08:51:55 +00:00
$walletHyperviseur -> balance_com += $transaction -> commission_hyp ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
$walletHyperviseur -> save ();
$walletUser -> save ();
$transaction -> id_transaction = $this -> getTransactionID ();
$transaction -> date = $this -> getCurrentTime ( $init_country );
$transaction -> save ();
$message = trans ( 'messages.successful_user_remove_from_cart_to_wallet' ,
[ 'id_transaction' => $transaction -> id_transaction , 'amount' => $this -> toMoney ( $transaction -> montant , $init_country ),
2023-09-14 12:33:11 +00:00
'net_init' => $this -> toMoney ( $transaction -> montant , $init_country ), 'net_final' => $this -> toMoney ( $transaction -> montant_net_final_country , $final_country ),
2023-07-26 12:52:32 +00:00
'fees' => $this -> toMoney ( $frais + $taxe , $init_country ), 'init_country' => $this -> getCountryName ( $init_country ), 'final_country' => $this -> getCountryName ( $final_country ),
2023-06-29 08:51:55 +00:00
'sender_code' => $user -> user_code , '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' ));
2020-06-30 13:09:00 +00:00
2022-04-20 08:08:32 +00:00
break ;
case 11 : // User - Retrait de carte vers cash
$this -> validate ( $request , $transaction -> user_card_rules ());
$user = $walletUser -> user ;
$this -> validatePassword ( $request -> password , $user -> encrypted_password , $user -> salt );
$this -> checkUserIdentification ( $user -> id );
2020-06-30 11:06:56 +00:00
2020-06-30 13:09:00 +00:00
if ( ! ( isset ( $user -> numero_carte ) && isset ( $user -> expiration_date )))
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.no_bank_card_attached' ));
2020-06-30 11:06:56 +00:00
2020-06-30 13:09:00 +00:00
$transaction -> expiration_date = $user -> expiration_date ;
$transaction -> numero_carte = $user -> numero_carte ;
2023-07-26 12:52:32 +00:00
$final_country = $walletUser -> user -> network -> country -> id ;
$transaction -> final_country = $final_country ;
2022-04-20 16:03:13 +00:00
$plr_user_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'user_cart_cash_national' );
2023-07-26 12:52:32 +00:00
$plr_user_cart_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'user_cart_cash_international' );
2022-04-20 16:03:13 +00:00
$plr_hyp_user_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'hyp_user_cart_cash_national' );
2023-07-26 12:52:32 +00:00
$plr_hyp_user_cart_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'hyp_user_cart_cash_international' );
2022-04-20 16:03:13 +00:00
$plr_bank_user_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'bank_user_cart_cash_national' );
2023-07-26 12:52:32 +00:00
$plr_bank_user_cart_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'bank_user_cart_cash_international' );
2022-04-20 16:03:13 +00:00
2023-07-26 12:52:32 +00:00
$frais = $this -> calculateFees ( $init_country != $final_country ? $plr_user_cart_cash_international : $plr_user_cart_cash_national , $request -> montant );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_OUT ,
'payment_method' => PaymentMethod :: CARD
]);
$frais += $fees ;
2023-07-26 12:52:32 +00:00
$taxe = $this -> calculateTax ( $init_country != $final_country ? $taxesInternationales : $taxesNationales , $frais );
2023-07-14 12:24:10 +00:00
$transaction -> taxe = $taxe ;
2023-07-26 12:52:32 +00:00
$transaction -> frais = $frais ;
2023-09-14 12:33:11 +00:00
$montantRetrait = $transaction -> montant + ( $frais + $taxe );
$transaction -> montant_net = $this -> toMoneyAmount ( $transaction -> montant , $init_country , $final_country );
2023-07-26 12:52:32 +00:00
$transaction -> montant_net_final_country = $this -> toMoneyAmount ( $montantRetrait , $init_country , $final_country );
2023-06-07 20:08:33 +00:00
2023-07-26 12:52:32 +00:00
$countryCurrency = CountriesCurrency :: findOrFail ( $init_country );
2020-08-09 22:13:21 +00:00
$identification = Identification :: where ( 'id_user' , $user -> id ) -> first ();
2023-06-07 20:08:33 +00:00
$payment_transaction_id = $request -> input ( 'payment_transaction_id' );
2020-08-09 22:13:21 +00:00
2023-06-29 08:51:55 +00:00
$result = $this -> handlePayIn ( $transaction , [
'card_no' => $user -> numero_carte ,
'exp_month' => date ( " m " , strtotime ( $user -> expiration_date )),
'exp_year' => date ( " Y " , strtotime ( $user -> expiration_date )),
'cvc' => $request -> input ( 'cvv' ),
2023-09-14 12:33:11 +00:00
'amount' => $transaction -> montant_net_final_country ,
2023-07-26 12:52:32 +00:00
'currency' => $countryCurrency -> currency_code ,
2023-06-29 08:51:55 +00:00
'payment_method' => 'CARD' ,
'customer_id' => $user -> id ,
'customer_email' => $user -> email ,
'customer_name' => $identification ? $identification -> firstname : $user -> firstname ,
'customer_surname' => $identification ? $identification -> lastname : $user -> lastname ,
'customer_address' => $identification ? $identification -> town : $user -> adresse ,
'customer_city' => $identification ? $identification -> town : $user -> adresse ,
2023-07-26 12:52:32 +00:00
'customer_country' => $countryCurrency -> code_country ,
2023-06-29 08:51:55 +00:00
'reason' => " User - Retrait de carte vers cash "
], $payment_transaction_id );
if ( ! ( $result instanceof WalletIlinkTransaction )) {
return $result ;
2023-06-07 20:08:33 +00:00
}
2020-06-30 11:06:56 +00:00
2023-07-26 12:52:32 +00:00
$transaction -> commission_banque = $this -> calculateFees ( $init_country != $final_country ? $plr_bank_user_cart_cash_international : $plr_bank_user_cart_cash_national , $request -> montant , $frais );
2023-06-29 08:51:55 +00:00
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
2020-06-30 11:06:56 +00:00
2023-06-29 08:51:55 +00:00
$code_retrait = $this -> random_string ();
$hash = $this -> hashSSHA ( $code_retrait );
$transaction -> encrypted_code_retrait = $hash [ 'encrypted' ];
$transaction -> code_retrait_salt = $hash [ 'salt' ];
2020-06-19 13:48:27 +00:00
2023-07-26 12:52:32 +00:00
$transaction -> commission_hyp = $this -> calculateFees ( $init_country != $final_country ? $plr_hyp_user_cart_cash_international : $plr_hyp_user_cart_cash_national , $request -> montant , $frais );
2023-06-29 08:51:55 +00:00
$walletHyperviseur -> balance_com += $transaction -> commission_hyp ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
$transaction -> date = $this -> getCurrentTime ( $init_country );
$transaction -> status_retrait = 0 ;
$walletHyperviseur -> save ();
$transaction -> id_transaction = $this -> getTransactionID ();
$transaction -> save ();
$message = trans ( 'messages.successful_user_remove_from_cart_to_cash' ,
[ 'id_transaction' => $transaction -> id_transaction , 'amount' => $this -> toMoney ( $transaction -> montant , $init_country ),
2023-09-14 12:33:11 +00:00
'net_init' => $this -> toMoney ( $transaction -> montant_net , $init_country ), 'net_final' => $this -> toMoney ( $transaction -> montant_net_final_country , $final_country ),
2023-07-26 12:52:32 +00:00
'fees' => $this -> toMoney ( $frais + $taxe , $init_country ), 'init_country' => $this -> getCountryName ( $init_country ), 'final_country' => $this -> getCountryName ( $final_country ),
'code' => wordwrap ( $code_retrait , 4 , ' ' , true ),
2023-06-29 08:51:55 +00:00
'sender_code' => $user -> user_code , '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' );
2020-06-30 13:09:00 +00:00
2022-04-20 08:08:32 +00:00
break ;
case 12 : // Agent - Retrait en cash
$this -> validate ( $request , $transaction -> remove_cash_rules ());
$agent = AgentPlus :: findOrFail ( $network_agent -> agent_id );
2022-05-09 14:19:12 +00:00
$this -> validatePassword ( $request -> password , $agent -> encrypted_password , $agent -> salt );
2020-07-03 18:24:41 +00:00
$transaction = WalletIlinkTransaction :: where ( 'id_transaction' , $request -> id_transaction ) -> first ();
2020-06-21 21:49:24 +00:00
if ( $transaction ) {
2020-07-09 18:26:05 +00:00
//Verifier si l'agent qui a effectué l'envoi de cash à cash ne puisse pas retirer l'argent
2020-11-03 09:05:30 +00:00
if ( $transaction -> type == 17 )
if ( $transaction -> id_wallet_ag == $walletAgent -> id )
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.agent_unauthorized' ));
2020-07-04 10:20:26 +00:00
//Verifier que le reseau payeur est de type iLink
2020-07-04 10:48:06 +00:00
if ( in_array ( $transaction -> type , [ 3 , 17 ])) {
2020-07-04 14:21:53 +00:00
$configPayeur = ConfigWallet :: where ( 'id_network' , $transaction -> network_destinataire ) -> firstOrFail ();
2020-07-04 10:48:06 +00:00
if ( $configPayeur -> type != 'ilink' )
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.withdrawal_network_unauthorized' , [ 'network' => $this -> getNetworkName ( $transaction -> network_destinataire ),
2020-07-08 16:51:11 +00:00
'country' => $this -> getCountryName ( $transaction -> final_country )]));
2020-07-04 10:20:26 +00:00
}
2020-06-21 21:49:24 +00:00
if ( $transaction -> status_retrait == 0 ) {
2020-07-03 10:58:43 +00:00
//Verifier que le pays de destinatation correspond au pays de retrait
2020-07-04 10:20:26 +00:00
if ( $init_country != $transaction -> final_country )
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.operation_cannot_performed_in_country' ));
2020-06-21 21:49:24 +00:00
if ( $this -> checkPassword ( $request -> code_retrait , $transaction -> encrypted_code_retrait , $transaction -> code_retrait_salt )) {
2020-07-03 10:58:43 +00:00
$montantNet = $transaction -> type == 11 ? $transaction -> montant_net : $transaction -> montant_net_final_country ;
2020-07-04 10:48:06 +00:00
if ( in_array ( $transaction -> type , [ 3 , 17 ])) {
$commissionHyp = ( $transaction -> network_emetteur != $transaction -> network_destinataire ) ?
$transaction -> part_reseau_payeur_final_country : $transaction -> commission_hyp_final_country ;
} else {
$commissionHyp = $transaction -> type == 11 ? $transaction -> commission_hyp : $transaction -> commission_hyp_final_country ;
}
2020-07-03 10:58:43 +00:00
if ( $montantNet == $request -> montant ) {
2020-07-01 17:54:12 +00:00
$transactionRetrait = $transaction -> replicate ();
$transactionRetrait -> id = null ;
2020-07-02 19:18:28 +00:00
$transactionRetrait -> type = $request -> type ;
2020-07-01 17:54:12 +00:00
$transactionRetrait -> id_transaction = $this -> getTransactionID ();
2020-07-03 10:58:43 +00:00
$transactionRetrait -> montant = $montantNet ;
2020-07-02 19:18:28 +00:00
$emailEmetteur = $transaction -> wallet_user ? $transaction -> wallet_user -> user -> email : $transaction -> email_emetteur ;
2020-11-03 09:05:30 +00:00
$emetteur = $transaction -> wallet_user ? $transaction -> wallet_user -> user -> lastname . ' ' . $transaction -> wallet_user -> user -> firstname : $transaction -> prenom_emetteur . ' ' . $transaction -> nom_emetteur ;
$destinataire = in_array ( $transaction -> type , [ 9 , 11 ]) ? $emetteur : $transaction -> prenom_destinataire . ' ' . $transaction -> nom_destinataire ;
2020-07-01 17:54:12 +00:00
2022-04-20 16:03:13 +00:00
// $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_hyp = $commissionHyp - $transactionRetrait->commission_ag - $transactionRetrait->commission_sup;
// Commissions
$final_country = $transaction -> final_country ;
$plr_agent_wallet_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'agent_wallet_cash_national' );
$plr_agent_wallet_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'agent_wallet_cash_international' );
$plr_sup_wallet_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'sup_wallet_cash_national' );
$plr_sup_wallet_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'sup_wallet_cash_international' );
2022-04-21 16:10:14 +00:00
$transactionRetrait -> commission_ag = ( $init_country != $final_country ) ? $this -> calculateFees ( $plr_agent_wallet_cash_international , $transaction -> montant ) : $this -> calculateFees ( $plr_agent_wallet_cash_national , $transaction -> montant );
$transactionRetrait -> commission_sup = ( $init_country != $final_country ) ? $this -> calculateFees ( $plr_sup_wallet_cash_international , $transaction -> montant , $transactionRetrait -> commission_ag ) : $this -> calculateFees ( $plr_sup_wallet_cash_national , $transaction -> montant , $transactionRetrait -> commission_ag );
$transactionRetrait -> commission_hyp = $commissionHyp - ( $transactionRetrait -> commission_ag + $transactionRetrait -> commission_sup );
2022-04-20 16:03:13 +00:00
2020-07-03 10:58:43 +00:00
$walletAgent -> balance_princ += $montantNet ;
2020-07-01 17:54:12 +00:00
$walletAgent -> balance_com += $transactionRetrait -> commission_ag ;
$walletSuperviseur -> balance_com += $transactionRetrait -> commission_sup ;
2020-07-03 18:24:41 +00:00
$walletHyperviseur -> balance_com -= ( $transactionRetrait -> commission_ag + $transactionRetrait -> commission_sup );
2020-07-02 19:18:28 +00:00
$transactionRetrait -> id_wallet_ag = $walletAgent -> id ;
$transactionRetrait -> id_wallet_sup = $walletSuperviseur -> id ;
$transactionRetrait -> id_wallet_hyp = $walletHyperviseur -> id ;
2020-07-03 10:58:43 +00:00
$transactionRetrait -> status_retrait = $transactionRetrait -> commission_banque = $transactionRetrait -> code_retrait_salt = $transactionRetrait -> encrypted_code_retrait = null ;
2020-07-02 19:18:28 +00:00
$transactionRetrait -> frais = $transactionRetrait -> taxe = 0 ;
$transaction -> status_retrait = 1 ;
2020-11-13 14:21:17 +00:00
$transaction -> date_retrait = $this -> getCurrentTime ( $init_country );
$transaction -> date = $this -> getCurrentTime ( $init_country );
2020-11-02 09:34:35 +00:00
//Si la transaction provient du reseau emetteur
if ( $transaction -> from_network_emetteur ) {
$transaction -> status_reseau_payeur = 'TRAITEE' ;
}
2020-06-21 21:49:24 +00:00
$walletAgent -> save ();
$walletSuperviseur -> save ();
$walletHyperviseur -> save ();
$transaction -> save ();
2020-07-01 17:54:12 +00:00
$transactionRetrait -> save ();
$message = trans ( 'messages.successful_agent_remove_cash' ,
2020-11-02 09:34:35 +00:00
[ 'id_transaction' => $transactionRetrait -> id_transaction , 'amount' => $this -> toMoney ( $request -> montant , $init_country ), 'init_country' => $this -> getCountryName ( $transaction -> init_country ),
2020-07-07 19:15:30 +00:00
'code' => wordwrap ( $request -> code_retrait , 4 , ' ' , true ), 'final_country' => $this -> getCountryName ( $transaction -> final_country ),
2020-07-08 16:51:11 +00:00
'sender_name' => $emetteur , 'receiver_name' => $destinataire , 'id_transaction_retrait' => $transaction -> id_transaction ]);
2020-07-02 19:18:28 +00:00
$this -> sendMail ( $emailEmetteur , trans ( 'messages.successful_transaction' ), $message );
2022-04-20 08:08:32 +00:00
$response_message = ( $message . trans ( 'messages.sent_by_mail' ));
2020-06-21 21:49:24 +00:00
} else {
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.incorrect_withdrawal_amount' ));
2020-06-21 21:49:24 +00:00
}
} else {
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.invalid_withdrawal_code' ));
2020-06-20 15:08:13 +00:00
}
2020-06-21 21:49:24 +00:00
} else {
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.withdrawal_already_made' ));
2020-06-20 15:08:13 +00:00
}
2020-06-21 21:49:24 +00:00
} else {
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.transaction_not_exist' ), Response :: HTTP_NOT_FOUND );
2020-06-20 15:08:13 +00:00
}
2022-04-20 08:08:32 +00:00
break ;
case 13 : // Agent - Retrait de la carte vers cash
$this -> validate ( $request , $transaction -> card_rules ());
$agent = AgentPlus :: findOrFail ( $network_agent -> agent_id );
$this -> validatePassword ( $request -> password , $agent -> encrypted_password , $agent -> salt );
$expiration_date = DateTime :: createFromFormat ( 'm/y' , $request -> expiration_date );
2020-06-21 21:49:24 +00:00
if ( ! $expiration_date )
2022-04-20 08:08:32 +00:00
$expiration_date = new DateTime ();
2020-06-21 21:49:24 +00:00
$transaction -> expiration_date = $expiration_date ;
2022-04-21 08:07:57 +00:00
$transaction -> final_country = $init_country ;
2022-04-20 16:03:13 +00:00
2022-04-21 08:07:57 +00:00
// $final_country = $request->final_country;
2022-04-20 16:03:13 +00:00
$plr_customer_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'customer_cart_cash_national' );
2022-04-21 08:07:57 +00:00
// $plr_customer_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_international');
2022-04-20 16:03:13 +00:00
$plr_agent_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'agent_cart_cash_national' );
2022-04-21 08:07:57 +00:00
// $plr_agent_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'agent_cart_cash_international');
2022-04-20 16:03:13 +00:00
$plr_sup_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'sup_cart_cash_national' );
2022-04-21 08:07:57 +00:00
// $plr_sup_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'sup_cart_cash_international');
2022-04-20 16:03:13 +00:00
$plr_hyp_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'hyp_cart_cash_national' );
2022-04-21 08:07:57 +00:00
// $plr_hyp_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'hyp_cart_cash_international');
2022-04-20 16:03:13 +00:00
$plr_bank_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'bank_cart_cash_national' );
2022-04-21 08:07:57 +00:00
// $plr_bank_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'bank_cart_cash_international');
2022-04-20 16:03:13 +00:00
2022-04-21 08:07:57 +00:00
$frais = $this -> calculateFees ( $plr_customer_cart_cash_national , $request -> montant );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_OUT ,
'payment_method' => PaymentMethod :: CARD
]);
$frais += $fees ;
2023-07-14 12:24:10 +00:00
$taxe = $this -> calculateTax ( $taxesNationales , $frais );
$transaction -> taxe = $taxe ;
$montantRetrait = $transaction -> montant + ( $frais + $taxe );
2020-06-28 10:45:17 +00:00
$transaction -> montant_net = $montantRetrait ;
2023-06-07 20:08:33 +00:00
$payment_transaction_id = $request -> input ( 'payment_transaction_id' );
2023-06-29 08:51:55 +00:00
$result = $this -> handlePayIn ( $transaction , [
'card_no' => $request -> input ( 'numero_carte' ),
'exp_month' => $expiration_date -> format ( 'm' ),
'exp_year' => $expiration_date -> format ( 'Y' ),
'cvc' => $request -> input ( 'cvv' ),
'amount' => $montantRetrait ,
'currency' => $this -> getCurrency ( $init_country ),
'payment_method' => 'CARD' ,
'customer_email' => $request -> input ( 'customer_email' ),
'customer_name' => $request -> input ( 'customer_name' ),
'customer_surname' => $request -> input ( 'customer_surname' ),
'customer_address' => $request -> input ( 'customer_address' ),
'customer_city' => $request -> input ( 'customer_city' ),
'customer_country' => $request -> input ( 'customer_country' ),
'customer_state' => $request -> input ( 'customer_state' ),
'customer_zip_code' => $request -> input ( 'customer_zip_code' ),
'reason' => " Agent - Retrait de la carte vers cash "
], $payment_transaction_id );
2023-06-07 20:08:33 +00:00
2023-06-29 08:51:55 +00:00
if ( ! ( $result instanceof WalletIlinkTransaction )) {
return $result ;
2023-06-07 20:08:33 +00:00
}
2020-06-21 21:49:24 +00:00
2023-06-29 08:51:55 +00:00
$banqueCommission = $this -> calculateFees ( $plr_bank_cart_cash_national , $request -> montant , $frais );
$transaction -> commission_banque = $banqueCommission ;
// 2---> Emmètre via API sécurisé SSL une requête de débit de notre
//compte marchand du (Part de la banque partenaire en %
//pour le dépôt qui s’ applique sur les frais minimum) et créditer
//le compte des opérations défini avec notre banque
//partenaire
$walletAgent -> balance_princ += $transaction -> montant ;
$agentCommission = $this -> calculateFees ( $plr_agent_cart_cash_national , $request -> montant , $frais );
$superviseurCommission = $this -> calculateFees ( $plr_sup_cart_cash_national , $request -> montant , $frais );
$hyperviseurCommission = $this -> calculateFees ( $plr_hyp_cart_cash_national , $request -> montant , $frais );
$walletAgent -> balance_com += $agentCommission ;
$transaction -> commission_ag = $agentCommission ;
$walletSuperviseur -> balance_com += $superviseurCommission ;
$transaction -> commission_sup = $superviseurCommission ;
$walletHyperviseur -> balance_com += $hyperviseurCommission ;
$transaction -> commission_hyp = $hyperviseurCommission ;
$transaction -> id_wallet_ag = $walletAgent -> id ;
$transaction -> id_wallet_sup = $walletSuperviseur -> id ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
$transaction -> frais = $frais ;
$transaction -> date = $this -> getCurrentTime ( $init_country );
$walletAgent -> save ();
$walletSuperviseur -> save ();
$walletHyperviseur -> save ();
$transaction -> id_transaction = $this -> getTransactionID ();
$transaction -> save ();
$response_message = ( trans ( 'messages.successful_transaction' ));
2022-04-20 08:08:32 +00:00
break ;
case 14 : // Agent - Envoi de cash vers wallet iLink
$this -> validate ( $request , $transaction -> cash_wallet_rules ());
$agent = AgentPlus :: findOrFail ( $network_agent -> agent_id );
$this -> validatePassword ( $request -> password , $agent -> encrypted_password , $agent -> salt );
2020-12-05 15:34:10 +00:00
if ( $request -> montant > $walletAgent -> balance_princ )
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.insufficient_balance' ));
2020-12-05 15:34:10 +00:00
2020-07-02 19:18:28 +00:00
$user = User :: where ( 'user_code' , $request -> user_code ) -> first ();
2020-07-03 18:24:41 +00:00
if ( ! $user )
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.wallet_not_defined' ));
2020-07-02 19:18:28 +00:00
2020-07-10 11:22:51 +00:00
$transaction -> id_destinataire = $request -> user_code ;
2020-06-19 13:48:27 +00:00
$walletUser = WalletsUser :: where ( 'idUser' , $user -> id ) -> firstOrFail ();
2020-07-02 19:18:28 +00:00
$transaction -> final_country = $final_country = $user -> network -> country -> id ;
2020-06-19 13:48:27 +00:00
2020-09-28 15:39:57 +00:00
//Verification des limites reglementaires
2022-04-20 08:08:32 +00:00
$this -> checkReguationsLimits ( $walletUser -> id , $init_country , $final_country , $transaction -> montant );
2020-09-28 15:39:57 +00:00
2020-07-02 19:18:28 +00:00
$frais = ( $init_country != $final_country ) ? $this -> calculateFees ( $plr_agent_depot_wallet_ilink , $request -> montant ) : $this -> calculateFees ( $plr_agent_depot_wallet_ilink_national , $request -> montant );
2020-07-03 18:24:41 +00:00
$taxe = ( $init_country != $final_country ) ? $this -> calculateTax ( $taxesInternationales , $frais ) : $this -> calculateTax ( $taxesNationales , $frais );
2020-06-19 13:48:27 +00:00
$montantDepot = $request -> montant - $frais - $taxe ;
2020-06-28 10:45:17 +00:00
$transaction -> montant_net = $montantDepot ;
2020-07-03 10:58:43 +00:00
$transaction -> montant_net_final_country = $this -> toMoneyAmount ( $montantDepot , $init_country , $final_country );
$walletUser -> balance += $transaction -> montant_net_final_country ;
2022-04-20 16:03:13 +00:00
$plr_agent_cash_wallet_or_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'agent_cash_wallet_or_cash_national' );
$plr_agent_cash_wallet_or_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'agent_cash_wallet_or_cash_international' );
$plr_sup_cash_wallet_or_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'sup_cash_wallet_or_cash_national' );
$plr_sup_cash_wallet_or_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'sup_cash_wallet_or_cash_international' );
$commisionAgent = ( $init_country != $final_country ) ? $this -> calculateFees ( $plr_agent_cash_wallet_or_cash_international , $request -> montant ) : $this -> calculateFees ( $plr_agent_cash_wallet_or_cash_national , $request -> montant );
$commisionSuper = ( $init_country != $final_country ) ? $this -> calculateFees ( $plr_sup_cash_wallet_or_cash_international , $request -> montant , $commisionAgent ) : $this -> calculateFees ( $plr_sup_cash_wallet_or_cash_national , $request -> montant , $commisionAgent );
$commisionHyper = $frais - $commisionAgent - $commisionSuper ;
2020-07-02 20:57:18 +00:00
2020-12-05 15:34:10 +00:00
$walletAgent -> balance_princ -= $transaction -> montant ;
2020-06-19 13:48:27 +00:00
$walletAgent -> balance_com += $commisionAgent ;
$transaction -> commission_ag = $commisionAgent ;
$walletSuperviseur -> balance_com += $commisionSuper ;
$transaction -> commission_sup = $commisionSuper ;
$walletHyperviseur -> balance_com += $commisionHyper ;
$transaction -> commission_hyp = $commisionHyper ;
$transaction -> taxe = $taxe ;
$transaction -> frais = $frais ;
2020-11-13 14:21:17 +00:00
$transaction -> date = $this -> getCurrentTime ( $init_country );
2020-06-19 13:48:27 +00:00
$walletUser -> save ();
$walletAgent -> save ();
$walletSuperviseur -> save ();
$walletHyperviseur -> save ();
$transaction -> id_wallet_user = $walletUser -> id ;
$transaction -> id_wallet_ag = $walletAgent -> id ;
$transaction -> id_wallet_sup = $walletSuperviseur -> id ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
2020-07-02 20:38:15 +00:00
$transaction -> id_transaction = $this -> getTransactionID ();
2020-06-19 13:48:27 +00:00
$transaction -> save ();
2020-07-03 10:58:43 +00:00
$message = trans ( 'messages.successful_agent_deposit_wallet_ilink' ,
2020-07-02 20:57:18 +00:00
[ 'id_transaction' => $transaction -> id_transaction , 'amount' => $this -> toMoney ( $transaction -> montant , $init_country ), 'net_init' => $this -> toMoney ( $montantDepot , $init_country ),
'net_final' => $this -> toMoneyWithCurrency ( $montantDepot , $init_country , $final_country ), 'fees' => $this -> toMoney ( $frais + $taxe , $init_country ), 'init_country' => $this -> getCountryName ( $init_country ),
'final_country' => $this -> getCountryName ( $final_country ), 'user_code' => $request -> user_code ]);
2020-07-02 19:18:28 +00:00
$this -> sendMail ( $user -> email , trans ( 'messages.successful_transaction' ), $message );
2022-04-20 08:08:32 +00:00
$response_message = ( $message . trans ( 'messages.sent_by_mail_to_recipient' ));
break ;
case 15 : // Agent - Envoi de cash vers autre wallet
$this -> validate ( $request , array_merge ( $transaction -> cash_cash_rules (), [
'id_destinataire' => 'required'
]));
$agent = AgentPlus :: findOrFail ( $network_agent -> agent_id );
$this -> validatePassword ( $request -> password , $agent -> encrypted_password , $agent -> salt );
2020-07-03 10:58:43 +00:00
if ( $request -> montant > $walletAgent -> balance_princ )
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.insufficient_balance' ), 422 );
2020-09-28 15:39:57 +00:00
//Verification des limites reglementaires
2022-04-20 08:08:32 +00:00
$this -> checkReguationsLimits ( $request -> id_document_emetteur , $init_country , $request -> final_country , $transaction -> montant , true );
2020-07-03 10:58:43 +00:00
$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 );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: WALLET
]);
$frais += $fees ;
2023-07-14 12:24:10 +00:00
$taxe = ( $init_country != $request -> final_country ) ? $this -> calculateTax ( $taxesInternationales , $frais ) : $this -> calculateTax ( $taxesNationales , $frais );
2020-06-19 19:31:32 +00:00
$montantDepot = $request -> montant - $frais - $taxe ;
2020-06-28 10:45:17 +00:00
$transaction -> montant_net = $montantDepot ;
2020-07-03 10:58:43 +00:00
$transaction -> montant_net_final_country = $this -> toMoneyAmount ( $montantDepot , $init_country , $request -> final_country );
2020-07-03 18:24:41 +00:00
$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 ;
2020-07-03 10:58:43 +00:00
$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 ;
2020-06-19 19:31:32 +00:00
//Emettre une trame securise pour crediter le wallet utilisateur
2020-07-03 10:58:43 +00:00
// $walletUser->balance += $transaction->montant_net_final_country;
2020-06-19 19:31:32 +00:00
// $transaction->id_destinataire = r
2022-04-20 16:03:13 +00:00
2023-07-03 07:30:21 +00:00
$countryCurrency = CountriesCurrency :: findOrFail ( $request -> 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' => $agent -> id ,
'customer_email' => $request -> input ( 'email_emetteur' ),
'customer_name' => $request -> input ( 'prenom_destinataire' ),
'customer_surname' => $request -> input ( 'nom_destinataire' ),
'customer_phone_number' => $transaction -> id_destinataire ,
'customer_country' => $countryCurrency -> code_country ,
'reason' => " Agent - Envoi de cash vers autre wallet "
]);
2022-04-20 16:03:13 +00:00
$final_country = $request -> final_country ;
$plr_agent_cash_wallet_or_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'agent_cash_wallet_or_cash_national' );
$plr_agent_cash_wallet_or_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'agent_cash_wallet_or_cash_international' );
$plr_sup_cash_wallet_or_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'sup_cash_wallet_or_cash_national' );
$plr_sup_cash_wallet_or_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'sup_cash_wallet_or_cash_international' );
$commisionAgent = ( $init_country != $final_country ) ? $this -> calculateFees ( $plr_agent_cash_wallet_or_cash_international , $request -> montant ) : $this -> calculateFees ( $plr_agent_cash_wallet_or_cash_national , $request -> montant );
$commisionSuper = ( $init_country != $final_country ) ? $this -> calculateFees ( $plr_sup_cash_wallet_or_cash_international , $request -> montant , $commisionAgent ) : $this -> calculateFees ( $plr_sup_cash_wallet_or_cash_national , $request -> montant , $commisionAgent );
$commisionHyper = $transaction -> part_reseau_emetteur - $commisionAgent - $commisionSuper ;
2020-06-19 19:31:32 +00:00
$walletAgent -> balance_princ -= $transaction -> montant ;
$walletAgent -> balance_com += $commisionAgent ;
$transaction -> commission_ag = $commisionAgent ;
$walletSuperviseur -> balance_com += $commisionSuper ;
$transaction -> commission_sup = $commisionSuper ;
$walletHyperviseur -> balance_com += $commisionHyper ;
$transaction -> commission_hyp = $commisionHyper ;
$transaction -> taxe = $taxe ;
$transaction -> frais = $frais ;
2020-11-13 14:21:17 +00:00
$transaction -> date = $this -> getCurrentTime ( $init_country );
2020-06-19 13:48:27 +00:00
2020-06-19 19:31:32 +00:00
$walletAgent -> save ();
$walletSuperviseur -> save ();
$walletHyperviseur -> save ();
2020-07-03 10:58:43 +00:00
if ( isset ( $reseauPayeur ))
$reseauPayeur -> save ();
2020-06-19 19:31:32 +00:00
$transaction -> id_wallet_ag = $walletAgent -> id ;
$transaction -> id_wallet_sup = $walletSuperviseur -> id ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
2020-07-03 10:58:43 +00:00
$transaction -> id_transaction = $this -> getTransactionID ();
2020-06-19 19:31:32 +00:00
$transaction -> save ();
2020-07-03 10:58:43 +00:00
$message = trans ( 'messages.successful_agent_deposit_other_wallet' ,
[ 'id_transaction' => $transaction -> id_transaction , 'amount' => $this -> toMoney ( $transaction -> montant , $init_country ), 'net_init' => $this -> toMoney ( $montantDepot , $init_country ),
'net_final' => $this -> toMoneyWithCurrency ( $montantDepot , $init_country , $request -> final_country ), 'fees' => $this -> toMoney ( $frais + $taxe , $init_country ), 'init_country' => $this -> getCountryName ( $init_country ),
2020-11-03 09:05:30 +00:00
'final_country' => $this -> getCountryName ( $request -> final_country ), 'receiver_code' => $request -> id_destinataire , 'network' => $this -> getNetworkName ( $transaction -> network_destinataire ),
2020-07-03 10:58:43 +00:00
'sender_name' => $request -> prenom_emetteur . ' ' . $request -> nom_emetteur , 'receiver_name' => $request -> prenom_destinataire . ' ' . $request -> nom_destinataire ,]);
$this -> sendMail ( $request -> email_emetteur , trans ( 'messages.successful_transaction' ), $message );
2022-04-20 08:08:32 +00:00
$response_message = ( $message . trans ( 'messages.sent_by_mail' ));
break ;
case 16 : // Agent - Envoi de cash vers une carte visa
$this -> validate ( $request , $transaction -> card_rules ());
$agent = AgentPlus :: findOrFail ( $network_agent -> agent_id );
$this -> validatePassword ( $request -> password , $agent -> encrypted_password , $agent -> salt );
2020-07-03 10:58:43 +00:00
if ( $request -> montant > $walletAgent -> balance_princ )
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.insufficient_balance' ), 422 );
$expiration_date = DateTime :: createFromFormat ( 'm/y' , $request -> expiration_date );
2020-06-19 19:31:32 +00:00
if ( ! $expiration_date )
2022-04-20 08:08:32 +00:00
$expiration_date = new DateTime ();
2020-06-19 19:31:32 +00:00
$transaction -> expiration_date = $expiration_date ;
2022-04-21 08:07:57 +00:00
$transaction -> final_country = $init_country ;
2022-04-20 16:03:13 +00:00
2022-04-21 08:07:57 +00:00
// $final_country = $request->final_country;
2022-04-20 16:03:13 +00:00
$plr_customer_cash_cart_national = $this -> getPaliers ( $paliers_commission_wallets , 'customer_cash_cart_national' );
2022-04-21 08:07:57 +00:00
// $plr_customer_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'customer_cash_cart_international');
2022-04-20 16:03:13 +00:00
$plr_agent_cash_cart_national = $this -> getPaliers ( $paliers_commission_wallets , 'agent_cash_cart_national' );
2022-04-21 08:07:57 +00:00
// $plr_agent_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'agent_cash_cart_international');
2022-04-20 16:03:13 +00:00
$plr_sup_cash_cart_national = $this -> getPaliers ( $paliers_commission_wallets , 'sup_cash_cart_national' );
2022-04-21 08:07:57 +00:00
// $plr_sup_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'sup_cash_cart_international');
2022-04-20 16:03:13 +00:00
$plr_hyp_cash_cart_national = $this -> getPaliers ( $paliers_commission_wallets , 'hyp_cash_cart_national' );
2022-04-21 08:07:57 +00:00
// $plr_hyp_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'hyp_cash_cart_international');
2022-04-20 16:03:13 +00:00
$plr_bank_cash_cart_national = $this -> getPaliers ( $paliers_commission_wallets , 'bank_cash_cart_national' );
2022-04-21 08:07:57 +00:00
// $plr_bank_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'bank_cash_cart_international');
2022-04-20 16:03:13 +00:00
2022-04-21 08:07:57 +00:00
$frais = $this -> calculateFees ( $plr_customer_cash_cart_national , $request -> montant );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: CARD
]);
$frais += $fees ;
2023-07-14 12:24:10 +00:00
$taxe = $this -> calculateTax ( $taxesNationales , $frais );
$transaction -> taxe = $taxe ;
$montantDepot = $transaction -> montant - $frais - $taxe ;
2020-06-28 10:45:17 +00:00
$transaction -> montant_net = $montantDepot ;
2023-06-07 20:08:33 +00:00
// PayOut through payment service
2023-06-29 08:51:55 +00:00
$this -> handlePayOut ( $transaction , [
2023-06-07 20:08:33 +00:00
'card_no' => $request -> input ( 'numero_carte' ),
'exp_month' => $expiration_date -> format ( 'm' ),
'exp_year' => $expiration_date -> format ( 'Y' ),
'cvc' => $request -> input ( 'cvv' ),
'amount' => $montantDepot ,
'currency' => $this -> getCurrency ( $init_country ),
'payment_method' => 'CARD' ,
'customer_email' => $request -> input ( 'customer_email' ),
2023-06-27 08:37:30 +00:00
'customer_name' => $request -> input ( 'customer_name' ),
'customer_surname' => $request -> input ( 'customer_surname' ),
2023-06-07 20:08:33 +00:00
'customer_address' => $request -> input ( 'customer_address' ),
'customer_city' => $request -> input ( 'customer_city' ),
'customer_country' => $request -> input ( 'customer_country' ),
'customer_state' => $request -> input ( 'customer_state' ),
'customer_zip_code' => $request -> input ( 'customer_zip_code' ),
'reason' => " Agent - Envoi de cash vers une carte visa "
2023-06-29 08:51:55 +00:00
]);
$banqueCommission = $this -> calculateFees ( $plr_bank_cash_cart_national , $request -> montant , $frais );
$transaction -> commission_banque = $banqueCommission ;
// 2---> Emmètre via API sécurisé SSL une requête de débit de notre
//compte marchand du (Part de la banque partenaire en %
//pour le dépôtqui s’ applique sur les frais minimum) et créditer
//le compte des opérations défini avec notre banque
//partenaire
$walletAgent -> balance_princ -= $transaction -> montant ;
$agentCommission = $this -> calculateFees ( $plr_agent_cash_cart_national , $request -> montant , $frais );
$superviseurCommission = $this -> calculateFees ( $plr_sup_cash_cart_national , $request -> montant , $frais );
$hyperviseurCommission = $this -> calculateFees ( $plr_hyp_cash_cart_national , $request -> montant , $frais );
$walletAgent -> balance_com += $agentCommission ;
$transaction -> commission_ag = $agentCommission ;
$walletSuperviseur -> balance_com += $superviseurCommission ;
$transaction -> commission_sup = $superviseurCommission ;
$walletHyperviseur -> balance_com += $hyperviseurCommission ;
$transaction -> commission_hyp = $hyperviseurCommission ;
$transaction -> id_wallet_ag = $walletAgent -> id ;
$transaction -> id_wallet_sup = $walletSuperviseur -> id ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
$transaction -> frais = $frais ;
$transaction -> date = $this -> getCurrentTime ( $init_country );
$walletAgent -> save ();
$walletSuperviseur -> save ();
$walletHyperviseur -> save ();
$transaction -> id_transaction = $this -> getTransactionID ();
$transaction -> save ();
$response_message = ( trans ( 'messages.successful_transaction' ));
2020-06-19 19:31:32 +00:00
2022-04-20 08:08:32 +00:00
break ;
case 17 : // Agent - Envoi de cash vers cash
$this -> validate ( $request , $transaction -> cash_cash_rules ());
$agent = AgentPlus :: findOrFail ( $network_agent -> agent_id );
$this -> validatePassword ( $request -> password , $agent -> encrypted_password , $agent -> salt );
2020-07-03 10:58:43 +00:00
if ( $request -> montant > $walletAgent -> balance_princ )
2022-04-20 08:08:32 +00:00
throw new Exception ( trans ( 'errors.insufficient_balance' ), 422 );
2020-09-28 15:39:57 +00:00
//Verification des limites reglementaires
2022-04-20 08:08:32 +00:00
$this -> checkReguationsLimits ( $request -> id_document_emetteur , $init_country , $request -> final_country , $transaction -> montant , true );
2020-09-28 15:39:57 +00:00
2023-07-22 14:12:07 +00:00
$configPayeur = ConfigWallet :: where ( 'id_network' , $request -> network_destinataire ) -> firstOrFail ();
$reseauPayeur = PayingNetwork :: where ( 'id_network' , $request -> network_destinataire ) -> where ( 'id_configWallet' , $config -> id ) -> first ();
2023-10-04 11:32:23 +00:00
if ( empty ( $reseauPayeur )){
return $this -> errorResponse ( __ ( 'errors.service_unavailable_in_country' ));
}
2020-07-03 10:58:43 +00:00
$frais = ( $init_country != $request -> final_country ) ? $this -> calculateFees ( $plr_agent_cash_cash , $request -> montant ) : $this -> calculateFees ( $plr_agent_cash_cash_national , $request -> montant );
2023-07-22 14:12:07 +00:00
$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 ;
2020-07-03 10:58:43 +00:00
$taxe = ( $init_country != $request -> final_country ) ? $this -> calculateTax ( $taxesInternationales , $frais ) : $this -> calculateTax ( $taxesNationales , $frais );
2020-06-19 19:31:32 +00:00
$montantRetrait = $request -> montant - $frais - $taxe ;
2023-07-22 14:12:07 +00:00
$transaction -> frais = $frais ;
$transaction -> taxe = $taxe ;
2020-06-28 10:45:17 +00:00
$transaction -> montant_net = $montantRetrait ;
2020-07-03 10:58:43 +00:00
$transaction -> montant_net_final_country = $this -> toMoneyAmount ( $transaction -> montant_net , $init_country , $request -> final_country );
2020-07-03 19:14:11 +00:00
2020-07-04 10:20:26 +00:00
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 ;
}
2022-04-20 16:03:13 +00:00
$final_country = $request -> final_country ;
$plr_agent_cash_wallet_or_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'agent_cash_wallet_or_cash_national' );
$plr_agent_cash_wallet_or_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'agent_cash_wallet_or_cash_international' );
$plr_sup_cash_wallet_or_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'sup_cash_wallet_or_cash_national' );
$plr_sup_cash_wallet_or_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'sup_cash_wallet_or_cash_international' );
$commisionAgent = ( $init_country != $final_country ) ? $this -> calculateFees ( $plr_agent_cash_wallet_or_cash_international , $request -> montant ) : $this -> calculateFees ( $plr_agent_cash_wallet_or_cash_national , $request -> montant );
$commisionSuper = ( $init_country != $final_country ) ? $this -> calculateFees ( $plr_sup_cash_wallet_or_cash_international , $request -> montant , $commisionAgent ) : $this -> calculateFees ( $plr_sup_cash_wallet_or_cash_national , $request -> montant , $commisionAgent );
$commisionHyper = $transaction -> part_reseau_emetteur - $commisionAgent - $commisionSuper ;
2020-07-03 19:14:11 +00:00
2020-10-27 10:52:37 +00:00
$transaction -> id_transaction = $this -> getTransactionID ();
2020-07-03 19:14:11 +00:00
if ( $configPayeur -> type == 'ilink' ) {
2020-10-27 10:52:37 +00:00
//Mise a jour des comissions et compensation
2020-11-13 14:39:03 +00:00
if ( isset ( $reseauPayeur )) {
$reseauPayeur -> balance_com += $transaction -> part_reseau_payeur_final_country ;
$reseauPayeur -> balance_compensation += $transaction -> montant_net_final_country ;
}
2020-10-27 10:52:37 +00:00
2020-07-03 19:14:11 +00:00
//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 {
2020-10-27 10:52:37 +00:00
//Emettre requete SSL vers wallet extene correspondant pour recharger le compte du destinataire
// La mise à jour des comissions de compensation se fera lors du traitement de la transaction
2023-06-29 08:51:55 +00:00
$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' => $agent -> id ,
'customer_email' => $agent -> email ,
'customer_name' => $request -> input ( 'prenom_destinataire' ),
'customer_surname' => $request -> input ( 'nom_destinataire' ),
'customer_phone_number' => $transaction -> id_destinataire ,
'customer_country' => $countryCurrency -> code_country ,
2023-06-29 09:03:17 +00:00
'reason' => " Agent - Envoi de cash à cash "
2023-06-29 08:51:55 +00:00
]);
2020-07-03 19:14:11 +00:00
}
2020-06-19 19:31:32 +00:00
$walletAgent -> balance_com += $commisionAgent ;
$transaction -> commission_ag = $commisionAgent ;
$walletSuperviseur -> balance_com += $commisionSuper ;
$transaction -> commission_sup = $commisionSuper ;
$walletHyperviseur -> balance_com += $commisionHyper ;
$transaction -> commission_hyp = $commisionHyper ;
2020-07-03 10:58:43 +00:00
$transaction -> commission_hyp_final_country = $this -> toMoneyAmount ( $transaction -> commission_hyp , $init_country , $request -> final_country );
2020-06-19 13:48:27 +00:00
$transaction -> id_wallet_ag = $walletAgent -> id ;
$transaction -> id_wallet_sup = $walletSuperviseur -> id ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
2020-06-19 19:31:32 +00:00
$code_retrait = $this -> random_string ();
2020-06-20 15:08:13 +00:00
$hash = $this -> hashSSHA ( $code_retrait );
2020-06-19 19:31:32 +00:00
$transaction -> encrypted_code_retrait = $hash [ 'encrypted' ];
$transaction -> code_retrait_salt = $hash [ 'salt' ];
$walletAgent -> balance_princ -= $transaction -> montant ;
2020-06-19 13:48:27 +00:00
$transaction -> frais = $frais ;
2020-06-19 19:31:32 +00:00
$transaction -> taxe = $taxe ;
2020-11-13 14:21:17 +00:00
$transaction -> date = $this -> getCurrentTime ( $init_country );
2020-06-19 19:31:32 +00:00
$transaction -> status_retrait = 0 ;
2020-07-03 19:14:11 +00:00
if ( isset ( $reseauPayeur ))
$reseauPayeur -> save ();
2020-06-19 18:33:10 +00:00
$walletAgent -> save ();
$walletSuperviseur -> save ();
$walletHyperviseur -> save ();
2020-10-27 10:52:37 +00:00
2020-06-19 13:48:27 +00:00
$transaction -> save ();
2020-07-03 18:24:41 +00:00
$message = trans ( 'messages.successful_agent_send_cash' ,
2020-06-27 15:04:28 +00:00
[ 'sender_name' => $request -> prenom_emetteur . ' ' . $request -> nom_emetteur , 'receiver_name' => $request -> prenom_destinataire . ' ' . $request -> nom_destinataire ,
2020-07-03 10:58:43 +00:00
'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 ),
2020-07-08 18:34:09 +00:00
'final_country' => $this -> getCountryName ( $request -> final_country ), 'code' => wordwrap ( $code_retrait , 4 , ' ' , true ),
2020-11-03 09:05:30 +00:00
'network' => $this -> getNetworkName ( $transaction -> network_destinataire )]);
2020-07-03 18:24:41 +00:00
$this -> sendMail ( $request -> email_emetteur , trans ( 'messages.successful_transaction' ), $message );
2022-04-20 08:08:32 +00:00
$response_message = ( $message . trans ( 'messages.sent_by_mail' ));
break ;
2020-11-23 14:27:25 +00:00
2022-04-20 08:08:32 +00:00
/**
* @ OA\Schema (
* schema = " agent_send_from_cash_to_bank " ,
* title = " Agent - Envoi de cash vers banque " ,
* @ OA\Property ( property = " type " ,
* type = " integer " ,
* enum = { 18 },
* default = 18 ,
* description = " Type de la transaction "
* ),
* @ OA\Property ( property = " id_wallet_user " ,
* type = " integer " ,
* example = 9 ,
* description = " ID du wallet de l'agent enregistré dans la base de données "
* ),
* @ OA\Property ( property = " id_wallet_network " ,
* type = " integer " ,
* example = 101 ,
* description = " ID du reseau enregistré dans la base de données auquel appartient le wallet "
* ),
* @ OA\Property ( property = " iban " ,
* type = " string " ,
* description = " Identifiant bancaire "
* ),
* @ OA\Property ( property = " id_bank " ,
* type = " integer " ,
* example = 4 ,
* description = " ID de la banque enregistré dans la base de données "
* ),
* @ OA\Property ( property = " nom_emetteur " ,
* type = " string " ,
* description = " Noms de l'emetteur "
* ),
* @ OA\Property ( property = " prenom_emetteur " ,
* type = " string " ,
* description = " Prenoms de l'emetteur "
* ),
* @ OA\Property ( property = " email_emetteur " ,
* type = " string " ,
* description = " Email de l'emetteur "
* ),
* @ OA\Property ( property = " type_document_emetteur " ,
* type = " string " ,
* description = " Type de document que l'emetteur a fourni pour son identification "
* ),
* @ OA\Property ( property = " id_document_emetteur " ,
* type = " string " ,
* description = " ID de l'emetteur sur le document qu'il a fourni pour son identification "
* ),
* @ OA\Property ( property = " nom_destinataire " ,
* type = " string " ,
* description = " Noms du destinataire "
* ),
* @ OA\Property ( property = " prenom_destinataire " ,
* type = " string " ,
* description = " Prenoms du destinataire "
* ),
* @ OA\Property ( property = " montant " ,
* type = " number " ,
* example = 10000 ,
* description = " Montant de la transaction "
* ),
* @ OA\Property ( property = " password " ,
* type = " string " ,
* description = " Mot de passe "
* )
* )
*/
case 18 : // Agent - Envoi de cash vers banque
$this -> validate ( $request , [
'iban' => 'required' ,
'id_wallet_network' => 'required|integer|min:0|not_in:0' ,
'id_bank' => 'required|integer|min:0|not_in:0' ,
'nom_emetteur' => 'required' ,
'prenom_emetteur' => 'required' ,
'type_document_emetteur' => 'required' ,
'id_document_emetteur' => 'required' ,
'email_emetteur' => 'required|email:rfc' ,
'nom_destinataire' => 'required' ,
'prenom_destinataire' => 'required' ,
]);
$agent = AgentPlus :: findOrFail ( $network_agent -> agent_id );
$this -> validatePassword ( $request -> password , $agent -> encrypted_password , $agent -> salt );
2020-11-05 17:12:55 +00:00
2022-04-20 08:08:32 +00:00
if ( $request -> montant > $walletAgent -> balance_princ )
throw new Exception ( trans ( 'errors.insufficient_balance' ), 422 );
//Verifier si la banque est associée au reseau
$network_bank = NetworksOperator :: where ( 'id_network' , $request -> id_wallet_network ) -> where ( 'id_operator_country' , $request -> id_bank ) -> first ();
if ( ! $network_bank )
throw new Exception ( trans ( 'errors.bank_not_associated_with_network' ));
if ( $network_bank -> operators_country -> operator -> type != 'bank' )
throw new Exception ( trans ( 'errors.not_banking_operator' ));
//Verifier le code IBAN
$country_code = $network_bank -> network -> country -> code_country ;
$bank_code = $network_bank -> operators_country -> code ;
switch ( $this -> checkIBAN ( $request -> iban , $country_code , $bank_code )) {
case 0 :
throw new Exception ( trans ( 'errors.invalid_iban' ));
case 1 :
throw new Exception ( trans ( 'errors.country_not_match_iban' ));
case 2 :
throw new Exception ( trans ( 'errors.bank_not_match_iban' ));
}
$transaction -> frais = $frais = 0 ;
$transaction -> taxe = $taxe = 0 ;
2020-11-03 09:05:30 +00:00
// $walletUser->balance -= $transaction->montant;
2022-04-20 08:08:32 +00:00
//Emettre une trame SSL pour recharger le compte bancaire du montant de la transaction
$transaction -> commission_banque = 0 ;
$transaction -> commission_hyp = 0 ;
$transaction -> commission_sup = 0 ;
$transaction -> commission_ag = 0 ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
$transaction -> id_wallet_ag = $walletAgent -> id ;
$transaction -> id_wallet_sup = $walletSuperviseur -> id ;
$transaction -> frais = $frais ;
$transaction -> date = $this -> getCurrentTime ( $init_country );
$transaction -> bank = $network_bank -> operators_country -> operator -> nom ;
$transaction -> country = $network_bank -> network -> country -> name ;
$transaction -> id_bank = $request -> id_bank ;
$transaction -> iban = $request -> iban ;
2020-11-03 09:05:30 +00:00
// $walletUser->save();
2022-04-20 08:08:32 +00:00
$transaction -> id_transaction = $this -> getTransactionID ();
2020-11-03 09:05:30 +00:00
// $transaction->save();
2022-04-20 08:08:32 +00:00
Log :: info ( '-------------------------- Agent - Envoi de cash vers banque ------------------------------------' );
Log :: info ( json_encode ( $transaction ));
Log :: info ( '------------------------------------------------------------------------------------------------' );
$message = trans ( 'messages.successful_agent_send_from_cash_to_bank' ,
[ 'id_transaction' => $transaction -> id_transaction , 'amount' => $this -> toMoney ( $transaction -> montant , $init_country ), 'receiver_name' => $request -> prenom_destinataire . ' ' . $request -> nom_destinataire ,
'net' => $this -> toMoney ( $transaction -> montant , $init_country ), 'iban' => $request -> iban , 'fees' => $this -> toMoney ( $frais , $init_country ), 'sender_name' => $request -> prenom_emetteur . ' ' . $request -> nom_emetteur ,
'sender_code' => $codeGenerer -> code_membre , 'bank' => $transaction -> bank , 'country' => $transaction -> country ]);
$this -> sendMail ( $request -> email_emetteur , trans ( 'messages.successful_transaction' ), $message );
$response_message = ( $message . trans ( 'messages.sent_by_mail' ));
break ;
2020-11-09 18:05:04 +00:00
2022-04-20 08:08:32 +00:00
/**
* @ OA\Schema (
* schema = " user_payement_of_operator " ,
* title = " User - Payer une facture chez un operateur " ,
* @ OA\Property ( property = " type " ,
* type = " integer " ,
* enum = { 19 },
* default = 19 ,
* description = " Type de la transaction "
* ),
* @ OA\Property ( property = " id_wallet_user " ,
* type = " integer " ,
* example = 9 ,
* description = " ID du wallet de l'utilisateur enregistré dans la base de données "
* ),
* @ OA\Property ( property = " id_wallet_network " ,
* type = " integer " ,
* example = 101 ,
* description = " ID du reseau enregistré dans la base de données auquel appartient le wallet "
* ),
* @ OA\Property ( property = " no_facture " ,
* type = " string " ,
* description = " Numero de la facture "
* ),
* @ OA\Property ( property = " type_operator " ,
* type = " string " ,
* enum = { " electricity " , " phone " , " tv " , " school " , " water " },
* default = " electricity " ,
* description = " Type d'operateur "
* ),
* @ OA\Property ( property = " id_operator " ,
* type = " integer " ,
* example = 16 ,
* description = " ID de l'operateur "
* ),
* @ OA\Property ( property = " montant " ,
* type = " number " ,
* example = 10000 ,
* description = " Montant de la transaction "
* ),
* @ OA\Property ( property = " password " ,
* type = " string " ,
* description = " Mot de passe "
* )
* )
*/
case 19 : // User - Payer un operateur
$this -> validate ( $request , [
'id_operator' => 'required|integer|min:0|not_in:0' ,
'id_wallet_network' => 'required|integer|min:0|not_in:0' ,
'type_operator' => 'required|in:water,electricity,tv,school' ,
'no_facture' => 'required' ,
]);
$user = $walletUser -> user ;
$this -> validatePassword ( $request -> password , $user -> encrypted_password , $user -> salt );
if ( $request -> montant > $walletUser -> balance )
throw new Exception ( trans ( 'errors.insufficient_balance' ));
//Verifier si l'operateur est associée au reseau
$network_bank = NetworksOperator :: where ( 'id_network' , $request -> id_wallet_network ) -> where ( 'id_operator_country' , $request -> id_operator ) -> first ();
if ( ! $network_bank )
throw new Exception ( trans ( 'errors.operator_not_associated_with_network' ));
if ( $network_bank -> operators_country -> operator -> type != $request -> type_operator ) {
$type_operator = TypeOperator :: where ( 'code' , $request -> type_operator ) -> firstOrFail ();
$type = app () -> isLocale ( 'en' ) ? $type_operator -> description_en : $type_operator -> description_fr ;
throw new Exception ( trans ( 'errors.not_matching_operator' , [ 'type_operator' => $type ]));
}
2020-11-09 18:05:04 +00:00
2022-04-20 08:08:32 +00:00
$transaction -> frais = $frais = 0 ;
$transaction -> taxe = $taxe = 0 ;
2020-11-09 18:05:04 +00:00
// $walletUser->balance -= $transaction->montant;
2022-04-20 08:08:32 +00:00
//Emettre une trame SSL pour recharger l'api de l'operateur du montant de la transaction
$transaction -> commission_hyp = 0 ;
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
$transaction -> frais = $frais ;
$transaction -> date = $this -> getCurrentTime ( $init_country );
$transaction -> operator = $network_bank -> operators_country -> operator -> nom ;
$type_operator = $network_bank -> operators_country -> operator -> type_operator ;
$transaction -> type_operator = app () -> isLocale ( 'en' ) ? $type_operator -> description_en : $type_operator -> description_fr ;
$transaction -> country = $network_bank -> network -> country -> name ;
$transaction -> id_operator = $request -> id_operator ;
$transaction -> no_facture = $request -> no_facture ;
2020-11-09 18:05:04 +00:00
// $walletUser->save();
2022-04-20 08:08:32 +00:00
$transaction -> id_transaction = $this -> getTransactionID ();
2020-11-09 18:05:04 +00:00
// $transaction->save();
2022-04-20 08:08:32 +00:00
Log :: info ( '-------------------------- User - Payer une facture chez un operateur ------------------------------------' );
Log :: info ( json_encode ( $transaction ));
Log :: info ( '------------------------------------------------------------------------------------------------' );
$message = trans ( 'messages.successful_user_payment_of_operator' ,
[ 'id_transaction' => $transaction -> id_transaction , 'amount' => $this -> toMoney ( $transaction -> montant , $init_country ),
'net' => $this -> toMoney ( $transaction -> montant , $init_country ), 'no_facture' => $request -> no_facture , 'fees' => $this -> toMoney ( $frais , $init_country ),
'sender_code' => $user -> user_code , 'operator' => $transaction -> operator , 'type_operator' => $transaction -> type_operator ]);
$this -> sendMail ( $user -> email , trans ( 'messages.successful_transaction' ), $message );
$response_message = ( $message . trans ( 'messages.sent_by_mail' ));
break ;
/**
* @ OA\Schema (
* schema = " user_remove_from_bank_to_wallet " ,
* title = " User - Retrait de la banque vers le wallet " ,
* @ OA\Property ( property = " type " ,
* type = " integer " ,
* enum = { 20 },
* default = 20 ,
* description = " Type de la transaction "
* ),
* @ OA\Property ( property = " id_wallet_user " ,
* type = " integer " ,
* example = 9 ,
* description = " ID du wallet de l'utilisateur enregistré dans la base de données "
* ),
* @ OA\Property ( property = " montant " ,
* type = " number " ,
* example = 10000 ,
* description = " Montant de la transaction "
* ),
* @ OA\Property ( property = " password " ,
* type = " string " ,
* description = " Mot de passe "
* )
* )
*/
case 20 : //User - Retrait de la banque vers le wallet
2020-11-13 06:39:24 +00:00
// $this->validate($request, [
// 'code_retrait' => 'required',
// ]);
2022-04-20 08:08:32 +00:00
$user = $walletUser -> user ;
$this -> validatePassword ( $request -> password , $user -> encrypted_password , $user -> salt );
2020-11-23 14:27:25 +00:00
2022-04-20 08:08:32 +00:00
$this -> checkUserIdentification ( $user -> id );
2020-11-13 06:39:24 +00:00
2022-04-20 08:08:32 +00:00
if ( ! ( isset ( $user -> iban ) && isset ( $user -> id_bank_country )))
throw new Exception ( trans ( 'errors.wallet_not_linked_to_bank_account' ));
//Reverifier si l'operateur est toujours associé au reseau
$network_bank = NetworksOperator :: where ( 'id_network' , $transaction -> network_emetteur ) -> where ( 'id_operator_country' , $user -> id_bank_country ) -> first ();
if ( ! $network_bank )
throw new Exception ( trans ( 'errors.operator_not_associated_with_network' ) . '. ' . trans ( 'errors.update_banking_information' ));
if ( $network_bank -> operators_country -> operator -> type != 'bank' )
throw new Exception ( trans ( 'errors.not_banking_operator' ) . '. ' . trans ( 'errors.update_banking_information' ));
//Reverifier le code IBAN correspond toujours
$country_code = $network_bank -> network -> country -> code_country ;
$bank_code = $network_bank -> operators_country -> code ;
switch ( $this -> checkIBAN ( $user -> iban , $country_code , $bank_code )) {
case 0 :
throw new Exception ( trans ( 'errors.invalid_iban' ) . '. ' . trans ( 'errors.update_banking_information' ));
case 1 :
throw new Exception ( trans ( 'errors.country_not_match_iban' ) . '. ' . trans ( 'errors.update_banking_information' ));
case 2 :
throw new Exception ( trans ( 'errors.bank_not_match_iban' ) . '. ' . trans ( 'errors.update_banking_information' ));
}
// Envoyer la trame vers banque pour debiter le compte client et recharger le compte bancaire de iLink
// ----->
$transaction -> frais = $frais = 0 ;
$transaction -> taxe = $taxe = 0 ;
2020-11-13 06:39:24 +00:00
// $walletUser->balance += $transaction->montant;
2022-04-20 08:08:32 +00:00
$transaction -> commission_banque = 0 ;
2020-11-13 06:39:24 +00:00
2022-04-20 08:08:32 +00:00
$transaction -> commission_hyp = 0 ;
2020-11-13 06:39:24 +00:00
2022-04-20 08:08:32 +00:00
$transaction -> id_wallet_hyp = $walletHyperviseur -> id ;
$transaction -> frais = $frais ;
$transaction -> date = $this -> getCurrentTime ( $init_country );
$transaction -> bank = $user -> bank -> operators_country -> operator -> nom ;
$transaction -> country = $user -> bank -> network -> country -> name ;
$transaction -> id_bank = $user -> id_bank_country ;
$transaction -> iban = $user -> iban ;
2020-11-13 06:39:24 +00:00
// $walletUser->save();
2022-04-20 08:08:32 +00:00
$transaction -> id_transaction = $this -> getTransactionID ();
2020-11-13 06:39:24 +00:00
// $transaction->save();
2022-04-20 08:08:32 +00:00
Log :: info ( '-------------------------- User - Retrait de la banque vers le wallet ------------------------------------' );
Log :: info ( json_encode ( $transaction ));
Log :: info ( '------------------------------------------------------------------------------------------------' );
2020-11-13 06:39:24 +00:00
2022-04-20 08:08:32 +00:00
$message = trans ( 'messages.successful_user_remove_from_bank_to_wallet' ,
[ 'id_transaction' => $transaction -> id_transaction , 'amount' => $this -> toMoney ( $transaction -> montant , $init_country ),
'net' => $this -> toMoney ( $transaction -> montant , $init_country ), 'iban' => $user -> iban , 'fees' => $this -> toMoney ( $frais , $init_country ),
'sender_code' => $user -> user_code , 'bank' => $transaction -> bank , 'country' => $transaction -> country ]);
$this -> sendMail ( $user -> email , trans ( 'messages.successful_transaction' ), $message );
$response_message = ( $message . trans ( 'messages.sent_by_mail' ));
break ;
2023-07-12 19:32:21 +00:00
case 21 : //User - Retrait de carte vers autre wallet
$this -> validate ( $request , array_merge ( $transaction -> user_card_rules (), $transaction -> send_wallet_wallet_rules (), [
'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 ))) {
2023-08-02 18:16:06 +00:00
throw new Exception ();
2023-07-12 19:32:21 +00:00
}
$transaction -> expiration_date = $user -> expiration_date ;
$transaction -> numero_carte = $user -> numero_carte ;
} else {
$this -> validate ( $request , [
2023-08-10 10:28:17 +00:00
'nom_destinataire' => 'required' ,
'prenom_destinataire' => 'required' ,
2023-07-12 19:32:21 +00:00
'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 );
2023-07-22 14:12:07 +00:00
2023-08-10 10:18:49 +00:00
$configPayeur = ConfigWallet :: where ( 'id_network' , $request -> network_destinataire ) -> firstOrFail ();
$reseauPayeur = PayingNetwork :: where ( 'id_network' , $request -> network_destinataire ) -> where ( 'id_configWallet' , $config -> id ) -> first ();
2023-10-04 11:32:23 +00:00
if ( empty ( $reseauPayeur )){
return $this -> errorResponse ( __ ( 'errors.service_unavailable_in_country' ));
}
2023-08-01 06:24:56 +00:00
2023-08-10 10:18:49 +00:00
if ( $configPayeur -> type != 'ilink' ) {
$balance = $this -> checkBalance ([
'country_id' => $request -> final_country ,
'amount' => $request -> montant
]);
if ( ! is_string ( $balance )) {
return $balance ;
}
2023-08-01 06:24:56 +00:00
}
2023-07-22 14:12:07 +00:00
2023-07-12 19:32:21 +00:00
$frais = $this -> calculateFees ( $init_country != $request -> final_country ? $plr_user_cart_autre_wallet_international : $plr_user_cart_autre_wallet_national , $request -> montant );
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_OUT ,
'payment_method' => PaymentMethod :: CARD
2023-07-22 14:12:07 +00:00
]);
if ( $configPayeur -> type != 'ilink' ) {
$fees += $this -> getBasicTransactionFees ([
2023-07-18 10:07:41 +00:00
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: WALLET
]);
2023-07-22 14:12:07 +00:00
}
2023-07-14 12:24:10 +00:00
2023-07-22 14:12:07 +00:00
$frais += $fees ;
2023-07-14 12:24:10 +00:00
$taxe = $this -> calculateTax ( $init_country != $request -> final_country ? $taxesInternationales : $taxesNationales , $frais );
2023-07-12 19:32:21 +00:00
$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 );
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 ();
2023-08-02 18:16:06 +00:00
$country = CountriesCurrency :: findOrFail ( $init_country );
2023-07-12 19:32:21 +00:00
$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 ,
2023-08-02 18:16:06 +00:00
'currency' => $country -> currency_code ,
2023-07-12 19:32:21 +00:00
'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' ),
2023-08-02 18:16:06 +00:00
'customer_country' => $country -> code_country ,
2023-07-12 19:32:21 +00:00
'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
2023-08-01 06:24:56 +00:00
$transaction -> nom_destinataire = $destinataire -> lastname ;
$transaction -> prenom_destinataire = $destinataire -> firstname ;
2023-07-12 19:32:21 +00:00
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 ;
2022-04-20 08:08:32 +00:00
default :
2023-07-22 14:12:07 +00:00
DB :: rollBack ();
return $this -> errorResponse ( trans ( 'errors.transaction_not_supported' ));
2020-11-09 18:05:04 +00:00
2022-04-20 08:08:32 +00:00
}
2020-06-19 13:48:27 +00:00
2022-04-20 08:08:32 +00:00
DB :: commit ();
return $this -> successResponse ( $response_message );
} catch ( Throwable $e ) {
DB :: rollBack ();
if ( $e instanceof ValidationException ) {
throw $e ;
}
Log :: error ( $e -> getMessage () . " \n " . $e -> getTraceAsString ());
return $this -> errorResponse ( $e -> getMessage (), $e -> getCode ());
}
2020-06-19 13:48:27 +00:00
}
2023-06-29 08:51:55 +00:00
/**
* @ throws Exception
*/
private function handlePayOut ( WalletIlinkTransaction $transaction , $data ) : void
{
$client = new Client ([
'base_uri' => config ( 'services.payment_service.base_uri' ),
'headers' => [
'Authorization' => config ( 'services.payment_service.key' ),
]
]);
// PayOut through payment service
$response = $client -> post ( '/payOut' , [ 'json' => $data , 'http_errors' => false ]);
$code = $response -> getStatusCode ();
$content = json_decode ( $response -> getBody () -> getContents (), true );
if ( $code == 200 ) {
$response = $content [ " response " ];
$transaction -> payment_transaction_id = $response [ " transaction_id " ];
$transaction -> status_reseau_payeur = $response [ 'transaction_status' ] ? ? null ;
} else {
throw new Exception ( $content [ 'error' ] ? ? __ ( 'errors.paying_network_api_failed' ), $content [ 'status' ] ? ? 500 );
}
}
/**
* @ throws Exception
*/
private function handlePayIn ( WalletIlinkTransaction $transaction , $data , $payment_transaction_id = null )
{
$client = new Client ([
'base_uri' => config ( 'services.payment_service.base_uri' ),
'headers' => [
'Authorization' => config ( 'services.payment_service.key' ),
]
]);
// PayIn through payment service
if ( empty ( $payment_transaction_id )) {
// PayIn through payment service
$response = $client -> post ( '/stripe/payIn' , [ 'json' => $data , 'http_errors' => false ]);
} else {
// Check payment status through payment service
if ( WalletIlinkTransaction :: where ( 'payment_transaction_id' , $payment_transaction_id ) -> exists ()) {
throw new Exception ( __ ( 'errors.transaction_already_completed' ), 500 );
}
$response = $client -> get ( '/checkStatus/' . $payment_transaction_id , [ 'http_errors' => false ]);
}
$code = $response -> getStatusCode ();
$content = json_decode ( $response -> getBody () -> getContents (), true );
if ( $code == 301 ) {
return $this -> successResponse ( $content [ " response " ], $content [ 'status' ]);
}
if ( $code == 200 ) {
$response = $content [ " response " ];
$transaction -> payment_transaction_id = $response [ " transaction_id " ];
} else {
throw new Exception ( $content [ 'error' ] ? ? __ ( 'errors.visa_api_failed' ), $content [ 'status' ] ? ? 500 );
}
return $transaction ;
}
2023-08-01 06:24:56 +00:00
/**
* @ throws Exception
*/
// Check Aggretor balance before payIn
private function checkBalance ( $data )
{
// Pay through payment service
$client = new Client ([
2023-08-09 11:37:58 +00:00
'base_uri' => config ( 'services.payment_service.base_uri' ),
2023-08-01 06:24:56 +00:00
'headers' => [
2023-08-09 11:37:58 +00:00
'Authorization' => config ( 'services.payment_service.key' ),
2023-08-01 06:24:56 +00:00
]
]);
$response = $client -> get ( '/checkBalance' , [ 'query' => $data , 'http_errors' => false ]);
$code = $response -> getStatusCode ();
if ( $code == 200 ) {
return " available " ;
} else {
throw new Exception ( $content [ 'error' ] ? ? __ ( 'errors.service_unavailable' ), $content [ 'status' ] ? ? 500 );
}
}
2023-07-12 19:32:21 +00:00
/**
* @ 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 );
}
}
2023-06-29 08:51:55 +00:00
2020-11-05 17:12:55 +00:00
public function lastUserTransactions ( $id_user )
2020-06-24 07:36:54 +00:00
{
2020-07-10 11:28:19 +00:00
$user = User :: findOrFail ( $id_user );
2020-11-03 09:05:30 +00:00
$wallet_user = WalletsUser :: where ( 'idUser' , $user -> id ) -> firstOrFail ();
2020-07-10 11:22:51 +00:00
2020-10-27 10:52:37 +00:00
$transactions = DB :: select ( ' SELECT id_wallet_user , operation_fr , operation_en , id_transaction , network_destinataire , init_country , final_country , date , id , montant , frais , taxe , pays_init , pays_final ,
2020-07-10 12:18:04 +00:00
destinataire_phone , destinataire_name , nom_destinataire , prenom_destinataire , montant_net , montant_net_final_country FROM infos_ilink_transaction WHERE id_wallet_user = : id_wallet AND type <> 12 AND type <> 14
2020-10-27 10:52:37 +00:00
ORDER BY date DESC LIMIT 10 ; ', [' id_wallet ' => $wallet_user -> id ]);
2020-07-10 11:22:51 +00:00
2020-11-03 09:05:30 +00:00
foreach ( $transactions as $data ) {
2020-10-27 10:52:37 +00:00
$data -> operation = app () -> isLocale ( 'en' ) ? $data -> operation_en : $data -> operation_fr ;
2020-07-10 11:22:51 +00:00
$date = $data -> date ;
unset ( $data -> date );
2020-11-03 09:05:30 +00:00
$user_destinataire = isset ( $data -> id_destinataire ) ? User :: where ( 'user_code' , $data -> id_destinataire ) -> first () : null ;
2020-07-10 11:22:51 +00:00
// $emetteur = $wallet_user ? $wallet_user->user->lastname.' '.$wallet_user->user->firstname : $data->prenom_emetteur . ' ' . $data->nom_emetteur;
$emetteur = 'Moi' ;
2020-11-03 09:05:30 +00:00
if ( $data -> destinataire_phone ) {
2020-07-10 11:22:51 +00:00
$destinataire = $data -> destinataire_name ;
2020-11-03 09:05:30 +00:00
} else {
$destinataire = $data -> prenom_destinataire ? $data -> prenom_destinataire . ' ' . $data -> nom_destinataire : $emetteur ;
2020-07-10 11:22:51 +00:00
}
// $destinataire = in_array($data->type,[12,16]) ? $emetteur : ( $user_destinataire ? $user_destinataire->lastname.' '.$user_destinataire->firstname :
// $data->prenom_destinataire . ' ' . $data->nom_destinataire);
$data -> emetteur = $emetteur ;
$data -> destinataire = $destinataire ;
$data -> frais = $this -> toMoney ( $data -> frais + $data -> taxe , $data -> init_country );
$data -> montant_net_init = $this -> toMoney ( $data -> montant_net , $data -> init_country );
2020-11-03 09:05:30 +00:00
$data -> montant_net_final = $data -> montant_net_final_country ? $this -> toMoney ( $data -> montant_net_final_country , $data -> final_country ) : $data -> montant_net_init ;
2020-07-10 11:22:51 +00:00
$data -> montant = $this -> toMoney ( $data -> montant , $data -> init_country );
$data -> init_country = $data -> pays_init ;
$data -> final_country = $data -> pays_final ;
2020-11-03 09:05:30 +00:00
$data -> reseau_payeur = isset ( $data -> network_destinataire ) ? $this -> getNetworkName ( $data -> network_destinataire ) . ' ' . $data -> final_country : null ;
2020-07-10 11:22:51 +00:00
$data -> date = $date ;
2020-10-27 10:52:37 +00:00
unset ( $data -> type , $data -> destinataire_name , $data -> id_wallet_user , $data -> network_destinataire , $data -> nom_destinataire , $data -> prenom_destinataire , $data -> taxe , $data -> numero_carte ,
$data -> montant_net_final_country , $data -> montant_net , $data -> pays_init , $data -> pays_final , $data -> id_destinataire , $data -> destinataire_phone , $data -> operation_fr , $data -> operation_en );
2020-07-10 11:22:51 +00:00
}
2020-06-24 07:36:54 +00:00
return $this -> successResponse ( $transactions );
}
2020-11-05 17:12:55 +00:00
public function lastAgentTransactions ( $id_wallet_agent )
2020-06-19 13:48:27 +00:00
{
2020-10-27 10:52:37 +00:00
$transactions = DB :: select ( ' SELECT wit . id_transaction , tit . nom as operation_fr , tit . name as operation_en , wit . montant , wit . nom_emetteur , wit . prenom_emetteur , wit . id_wallet_user , wit . frais , wit . taxe , wit . id_destinataire ,
2020-07-09 18:26:05 +00:00
wit . nom_destinataire , wit . prenom_destinataire , wit . type , wit . id_wallet_user , wit . init_country , wit . final_country , wit . network_destinataire , wit . montant_net_final_country ,
2020-07-10 10:13:27 +00:00
wit . date , wit . id , wit . numero_carte , wit . montant_net FROM wallet_ilink_transaction wit
2020-07-09 18:26:05 +00:00
INNER JOIN type_ilink_transaction tit ON wit . type = tit . id WHERE wit . id_wallet_ag = : id_wallet
2020-07-10 10:27:29 +00:00
ORDER BY wit . date DESC LIMIT 10 ; ', [' id_wallet ' => $id_wallet_agent ]);
2020-07-09 18:26:05 +00:00
2020-11-03 09:05:30 +00:00
foreach ( $transactions as $data ) {
2020-10-27 10:52:37 +00:00
$data -> operation = app () -> isLocale ( 'en' ) ? $data -> operation_en : $data -> operation_fr ;
2020-07-09 18:43:47 +00:00
$date = $data -> date ;
unset ( $data -> date );
2020-11-03 09:05:30 +00:00
$wallet_user = isset ( $data -> id_wallet_user ) ? WalletsUser :: findOrFail ( $data -> id_wallet_user ) : null ;
2023-06-07 20:08:33 +00:00
$user_destinataire = isset ( $data -> id_destinataire ) ? User :: where ( 'user_code' , $data -> id_destinataire ) -> orWhere ( 'phone' , $data -> id_destinataire ) -> first () : null ;
2020-11-03 09:05:30 +00:00
$emetteur = $wallet_user ? $wallet_user -> user -> lastname . ' ' . $wallet_user -> user -> firstname : $data -> prenom_emetteur . ' ' . $data -> nom_emetteur ;
if ( ! $wallet_user && ! $data -> nom_emetteur )
2020-07-10 10:13:27 +00:00
$emetteur = $data -> numero_carte ;
2020-11-03 09:05:30 +00:00
$destinataire = in_array ( $data -> type , [ 12 , 16 ]) ? $emetteur : ( $user_destinataire ? $user_destinataire -> lastname . ' ' . $user_destinataire -> firstname :
2020-07-10 10:13:27 +00:00
$data -> prenom_destinataire . ' ' . $data -> nom_destinataire );
2020-07-09 18:26:05 +00:00
$data -> emetteur = $emetteur ;
$data -> destinataire = $destinataire ;
$data -> frais = $this -> toMoney ( $data -> frais + $data -> taxe , $data -> init_country );
$data -> montant_net_init = $this -> toMoney ( $data -> montant_net , $data -> init_country );
2020-11-03 09:05:30 +00:00
$data -> montant_net_final = $data -> montant_net_final_country ? $this -> toMoney ( $data -> montant_net_final_country , $data -> final_country ) : $data -> montant_net_init ;
2020-07-09 18:26:05 +00:00
$data -> montant = $this -> toMoney ( $data -> montant , $data -> init_country );
$data -> init_country = $this -> getCountryName ( $data -> init_country );
2020-10-05 16:32:31 +00:00
$data -> final_country = $data -> montant_net_final_country ? $this -> getCountryName ( $data -> final_country ) : '' ;
$data -> reseau_payeur = isset ( $data -> network_destinataire ) ? $this -> getNetworkName ( $data -> network_destinataire ) . ' ' . $data -> final_country : null ;
2020-07-09 18:43:47 +00:00
$data -> date = $date ;
2020-10-27 10:52:37 +00:00
unset ( $data -> type , $data -> id_wallet_user , $data -> network_destinataire , $data -> nom_destinataire , $data -> prenom_destinataire , $data -> taxe , $data -> numero_carte ,
$data -> montant_net_final_country , $data -> montant_net , $data -> nom_emetteur , $data -> prenom_emetteur , $data -> id_destinataire , $data -> operation_fr , $data -> operation_en );
2020-07-09 18:26:05 +00:00
}
2020-06-19 13:48:27 +00:00
return $this -> successResponse ( $transactions );
}
2020-11-05 17:12:55 +00:00
public function calculateCommission ( Request $request )
2020-06-19 13:48:27 +00:00
{
$rules = [
2020-06-24 07:36:54 +00:00
'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' ,
2020-06-19 13:48:27 +00:00
'montant' => 'required|numeric|min:0|not_in:0' ,
];
$this -> validate ( $request , $rules );
2020-06-24 07:36:54 +00:00
if ( isset ( $request -> id_wallet_agent )) {
$walletAgent = Wallet :: findOrFail ( $request -> get ( 'id_wallet_agent' ));
$network_agent = NetworksAgent :: findOrFail ( $walletAgent -> id_networkAgent );
// Configuratrion du wallet
$config = ConfigWallet :: where ( 'id_network' , $network_agent -> network_id ) -> firstOrFail ();
2020-07-03 10:58:43 +00:00
$init_country = $network_agent -> network -> country -> id ;
2020-06-19 13:48:27 +00:00
2020-06-24 07:36:54 +00:00
} else {
$walletUser = WalletsUser :: findOrFail ( $request -> id_wallet_user );
2023-07-26 12:52:32 +00:00
// Pour les operations à cartes, le pays initial c'est le pays de la carte
if ( in_array ( $request -> type , [ 10 , 11 ])){
$init_country = $walletUser -> user -> card_country_id ;
} else {
$init_country = $walletUser -> user -> network -> country -> id ;
2023-08-02 18:16:06 +00:00
2023-08-09 13:13:44 +00:00
if ( $request -> type == 21 ){
2023-08-02 18:16:06 +00:00
$withLinkedCard = $request -> input ( 'with_linked_card' , false );
if ( $withLinkedCard ) {
$init_country = $walletUser -> user -> card_country_id ;
} else {
$init_country = Country :: where ( 'code_country' , $request -> input ( 'customer_country' )) -> first () ? -> id ;
}
}
2023-07-26 12:52:32 +00:00
}
2020-06-24 07:36:54 +00:00
$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 );
} else {
return $this -> errorResponse ( trans ( 'errors.no_ilink_network' ));
}
}
$taxesNationales = array_values ( array_filter ( $config -> taxes -> all (), function ( $tax ) {
2022-02-21 21:42:50 +00:00
return $tax -> destination == 'national' && $tax -> categorie == 'wallet' ;
2020-06-24 07:36:54 +00:00
}));
$taxesInternationales = array_values ( array_filter ( $config -> taxes -> all (), function ( $tax ) {
2022-02-21 21:42:50 +00:00
return $tax -> destination == 'international' && $tax -> categorie == 'wallet' ;
2020-06-24 07:36:54 +00:00
}));
2022-04-20 16:03:13 +00:00
$paliers_config_wallets = $config -> paliers_config_wallets -> all ();
$paliers_commission_wallets = $config -> paliers_commissions_wallets -> all ();
2020-06-24 07:36:54 +00:00
2022-04-20 16:03:13 +00:00
$plr_user_wallet_wallet = $this -> getPaliers ( $paliers_config_wallets , " user_wallet_wallet_international " );
$plr_user_wallet_cash = $this -> getPaliers ( $paliers_config_wallets , " user_wallet_cash_international " );
$plr_agent_depot_wallet_ilink = $this -> getPaliers ( $paliers_config_wallets , " agent_depot_wallet_ilink_international " );
$plr_agent_depot_autre_wallet = $this -> getPaliers ( $paliers_config_wallets , " agent_depot_autre_wallet_international " );
$plr_agent_cash_cash = $this -> getPaliers ( $paliers_config_wallets , " agent_cash_cash_international " );
2020-06-24 07:36:54 +00:00
2022-04-20 16:03:13 +00:00
$plr_user_wallet_wallet_national = $this -> getPaliers ( $paliers_config_wallets , " user_wallet_wallet_national " );
$plr_user_wallet_cash_national = $this -> getPaliers ( $paliers_config_wallets , " user_wallet_cash_national " );
$plr_agent_depot_wallet_ilink_national = $this -> getPaliers ( $paliers_config_wallets , " agent_depot_wallet_ilink_national " );
$plr_agent_depot_autre_wallet_national = $this -> getPaliers ( $paliers_config_wallets , " agent_depot_autre_wallet_national " );
$plr_agent_cash_cash_national = $this -> getPaliers ( $paliers_config_wallets , " agent_cash_cash_national " );
2020-06-24 07:36:54 +00:00
switch ( $request -> type ) {
case 1 : //User - Envoi wallet à wallet
$this -> validate ( $request , [
2022-04-20 16:03:13 +00:00
'final_country' => 'required|integer|exists:countries,id' ,
2020-11-05 17:12:55 +00:00
'id_destinataire' => 'required_without:phone_destinataire' ,
'network_destinataire' => 'required|integer|min:0|not_in:0' ,
2020-06-24 07:36:54 +00:00
]);
2020-11-05 17:12:55 +00:00
$configNetworkDestinataire = ConfigWallet :: where ( 'id_network' , $request -> network_destinataire ) -> firstOrFail ();
2020-06-24 07:36:54 +00:00
$frais = ( $init_country != $request -> final_country ) ? $this -> calculateFees ( $plr_user_wallet_wallet , $request -> montant ) : $this -> calculateFees ( $plr_user_wallet_wallet_national , $request -> montant );
2020-10-30 11:25:31 +00:00
//Verifier si c'est pas un reseau ilink
2020-11-05 17:12:55 +00:00
if ( $configNetworkDestinataire -> type != 'ilink' ) {
$data [ 'destinataire' ] = $request -> id_destinataire ;
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: WALLET
]);
2023-07-13 09:19:34 +00:00
$frais += $fees ;
} else {
$destinataire = User :: where ( 'user_code' , $request -> id_destinataire ) -> orWhere ( 'phone' , $request -> id_destinataire ) -> first ();
$data [ 'destinataire' ] = $destinataire ? $destinataire -> lastname . ' ' . $destinataire -> firstname : $request -> id_destinataire ;
2020-11-05 17:12:55 +00:00
}
2023-07-14 12:24:10 +00:00
$taxe = ( $init_country != $request -> final_country ) ? $this -> calculateTax ( $taxesInternationales , $frais ) : $this -> calculateTax ( $taxesNationales , $frais );
2020-11-03 09:05:30 +00:00
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
2023-07-14 12:24:10 +00:00
2020-11-03 09:05:30 +00:00
$data [ 'montant_net_init' ] = round ( $request -> montant - $data [ 'frais' ], 2 );
2023-07-12 19:32:21 +00:00
$data [ 'exchange_rate' ] = $this -> getExchangeRate ( $init_country , $request -> final_country );
2020-06-27 15:04:28 +00:00
$data [ 'montant_net_final' ] = $this -> toMoneyWithCurrency ( $data [ 'montant_net_init' ], $init_country , $request -> final_country );
2020-06-24 07:36:54 +00:00
break ;
case 2 : //User - Envoi de wallet à carte
2023-07-26 12:52:32 +00:00
$final_country = $walletUser -> user -> card_country_id ;
2023-08-02 18:16:06 +00:00
if ( empty ( $final_country )){
return $this -> errorResponse ( trans ( 'errors.no_bank_card_attached' ));
}
2022-04-20 16:03:13 +00:00
$plr_user_wallet_cart_national = $this -> getPaliers ( $paliers_commission_wallets , 'user_wallet_cart_national' );
2023-07-26 12:52:32 +00:00
$plr_user_wallet_cart_international = $this -> getPaliers ( $paliers_commission_wallets , 'user_wallet_cart_international' );
$frais = $this -> calculateFees ( $init_country != $final_country ? $plr_user_wallet_cart_international : $plr_user_wallet_cart_national , $request -> montant );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
2023-07-26 12:52:32 +00:00
'country_id' => $final_country ,
2023-07-12 19:32:21 +00:00
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: CARD
]);
2023-07-14 12:24:10 +00:00
$frais += $fees ;
2023-07-26 12:52:32 +00:00
$taxe = $this -> calculateTax ( $init_country != $final_country ? $taxesInternationales : $taxesNationales , $frais );
2023-07-14 12:24:10 +00:00
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
2023-07-26 12:52:32 +00:00
$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 );
2020-06-24 07:36:54 +00:00
break ;
2020-06-27 15:08:34 +00:00
case 3 : // User - Envoi wallet à cash
$this -> validate ( $request , [
'final_country' => 'required|integer|min:0|not_in:0' ,
2023-07-22 14:12:07 +00:00
// 'id_destinataire' => 'required_without:phone_destinataire',
'network_destinataire' => 'required|integer|min:0|not_in:0' ,
2020-06-27 15:08:34 +00:00
]);
2023-07-22 14:12:07 +00:00
$configNetworkDestinataire = ConfigWallet :: where ( 'id_network' , $request -> network_destinataire ) -> firstOrFail ();
2020-06-27 15:08:34 +00:00
$frais = ( $init_country != $request -> final_country ) ? $this -> calculateFees ( $plr_user_wallet_cash , $request -> montant ) : $this -> calculateFees ( $plr_user_wallet_cash_national , $request -> montant );
2023-07-22 14:12:07 +00:00
if ( $configNetworkDestinataire -> type != 'ilink' ) {
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: WALLET
]);
$frais += $fees ;
}
2020-06-27 15:08:34 +00:00
$taxe = ( $init_country != $request -> final_country ) ? $this -> calculateTax ( $taxesInternationales , $frais ) : $this -> calculateTax ( $taxesNationales , $frais );
2020-11-03 09:05:30 +00:00
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
$data [ 'montant_net_init' ] = round ( $request -> montant - $data [ 'frais' ], 2 );
2023-07-12 19:32:21 +00:00
$data [ 'exchange_rate' ] = $this -> getExchangeRate ( $init_country , $request -> final_country );
2020-06-27 15:08:34 +00:00
$data [ 'montant_net_final' ] = $this -> toMoneyWithCurrency ( $data [ 'montant_net_init' ], $init_country , $request -> final_country );
break ;
2020-06-30 11:06:56 +00:00
case 9 : // User - Retrait de wallet en cash
$frais = $this -> calculateFees ( $plr_user_wallet_cash_national , $request -> montant );
$taxe = $this -> calculateTax ( $taxesNationales , $frais );
2020-11-03 09:05:30 +00:00
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
2020-07-20 11:13:49 +00:00
$data [ 'montant_net' ] = round ( $request -> montant - $data [ 'frais' ], 2 );
2020-06-30 11:06:56 +00:00
break ;
case 10 : //User - Retrait de carte vers wallet
2023-07-26 12:52:32 +00:00
$final_country = $walletUser -> user -> network -> country -> id ;
2022-04-20 16:03:13 +00:00
$plr_user_cart_wallet_national = $this -> getPaliers ( $paliers_commission_wallets , 'user_cart_wallet_national' );
2023-07-26 12:52:32 +00:00
$plr_user_cart_wallet_international = $this -> getPaliers ( $paliers_commission_wallets , 'user_cart_wallet_international' );
$frais = $this -> calculateFees ( $init_country != $final_country ? $plr_user_cart_wallet_international : $plr_user_cart_wallet_national , $request -> montant );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_OUT ,
'payment_method' => PaymentMethod :: CARD
]);
2023-07-14 12:24:10 +00:00
$frais += $fees ;
2023-07-26 12:52:32 +00:00
$taxe = $this -> calculateTax ( $init_country != $final_country ? $taxesInternationales : $taxesNationales , $frais );
2023-07-14 12:24:10 +00:00
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
2023-09-14 12:33:11 +00:00
$data [ 'montant_net_init' ] = $request -> montant ;
2023-07-26 12:52:32 +00:00
$data [ 'exchange_rate' ] = $this -> getExchangeRate ( $init_country , $final_country );
2023-09-14 12:33:11 +00:00
$data [ 'montant_net_final' ] = $this -> toMoneyWithCurrency ( round ( $request -> montant + $data [ 'frais' ], 2 ), $init_country , $final_country );
2020-06-30 11:06:56 +00:00
break ;
case 11 : // User - Retrait de carte vers cash
2023-07-26 12:52:32 +00:00
$final_country = $walletUser -> user -> network -> country -> id ;
2022-04-20 16:03:13 +00:00
$plr_user_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'user_cart_cash_national' );
2023-07-26 12:52:32 +00:00
$plr_user_cart_cash_international = $this -> getPaliers ( $paliers_commission_wallets , 'user_cart_cash_international' );
$frais = $this -> calculateFees ( $init_country != $final_country ? $plr_user_cart_cash_international : $plr_user_cart_cash_national , $request -> montant );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_OUT ,
'payment_method' => PaymentMethod :: CARD
]);
2023-07-14 12:24:10 +00:00
$frais += $fees ;
2023-07-26 12:52:32 +00:00
$taxe = $this -> calculateTax ( $init_country != $final_country ? $taxesInternationales : $taxesNationales , $frais );
2023-07-14 12:24:10 +00:00
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
2023-09-14 12:33:11 +00:00
$data [ 'montant_net_init' ] = $request -> montant ;
2023-07-26 12:52:32 +00:00
$data [ 'exchange_rate' ] = $this -> getExchangeRate ( $init_country , $final_country );
2023-09-14 12:33:11 +00:00
$data [ 'montant_net_final' ] = $this -> toMoneyWithCurrency ( round ( $request -> montant + $data [ 'frais' ], 2 ), $init_country , $final_country );
2020-06-30 11:06:56 +00:00
break ;
2020-07-03 10:58:43 +00:00
case 13 : // Agent - Retrait de la carte vers cash
2022-04-20 16:03:13 +00:00
$plr_customer_cart_cash_national = $this -> getPaliers ( $paliers_commission_wallets , 'customer_cart_cash_national' );
2022-04-21 08:07:57 +00:00
// $plr_customer_cart_cash_international = $this->getPaliers($paliers_commission_wallets, 'customer_cart_cash_international');
$frais = $this -> calculateFees ( $plr_customer_cart_cash_national , $request -> montant );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_OUT ,
'payment_method' => PaymentMethod :: CARD
]);
2023-07-14 12:24:10 +00:00
$frais += $fees ;
$taxe = $this -> calculateTax ( $taxesNationales , $frais );
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
2020-10-08 12:04:43 +00:00
$data [ 'montant_net' ] = round ( $request -> montant + $data [ 'frais' ], 2 );
2020-07-03 10:58:43 +00:00
break ;
case 14 : // Agent - Envoi de cash vers wallet iLink
$this -> validate ( $request , [
'user_code' => 'required' ,
]);
$user = User :: where ( 'user_code' , $request -> user_code ) -> first ();
2020-07-03 18:24:41 +00:00
if ( ! $user )
2020-07-03 10:58:43 +00:00
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 );
2020-07-03 18:24:41 +00:00
$taxe = ( $init_country != $final_country ) ? $this -> calculateTax ( $taxesInternationales , $frais ) : $this -> calculateTax ( $taxesNationales , $frais );
2020-11-03 09:05:30 +00:00
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
$data [ 'montant_net_init' ] = round ( $request -> montant - $data [ 'frais' ], 2 );
2023-07-12 19:32:21 +00:00
$data [ 'exchange_rate' ] = $this -> getExchangeRate ( $init_country , $final_country );
2020-07-03 10:58:43 +00:00
$data [ 'montant_net_final' ] = $this -> toMoneyWithCurrency ( $data [ 'montant_net_init' ], $init_country , $final_country );
break ;
case 15 : // Agent - Envoi de cash vers autre wallet
$this -> validate ( $request , [
2022-04-20 16:03:13 +00:00
'final_country' => 'required|integer|exists:countries,id' ,
2020-07-03 10:58:43 +00:00
]);
$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 );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: WALLET
]);
2023-07-14 12:24:10 +00:00
$frais += $fees ;
$taxe = ( $init_country != $request -> final_country ) ? $this -> calculateTax ( $taxesInternationales , $frais ) : $this -> calculateTax ( $taxesNationales , $frais );
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
2020-11-03 09:05:30 +00:00
$data [ 'montant_net_init' ] = round ( $request -> montant - $data [ 'frais' ], 2 );
2023-07-12 19:32:21 +00:00
$data [ 'exchange_rate' ] = $this -> getExchangeRate ( $init_country , $request -> final_country );
2020-07-03 10:58:43 +00:00
$data [ 'montant_net_final' ] = $this -> toMoneyWithCurrency ( $data [ 'montant_net_init' ], $init_country , $request -> final_country );
break ;
case 16 : // Agent - Envoi de cash vers une carte visa
2022-04-20 16:03:13 +00:00
$plr_customer_cash_cart_national = $this -> getPaliers ( $paliers_commission_wallets , 'customer_cash_cart_national' );
2022-04-21 08:07:57 +00:00
// $plr_customer_cash_cart_international = $this->getPaliers($paliers_commission_wallets, 'customer_cash_cart_international');
$frais = $this -> calculateFees ( $plr_customer_cash_cart_national , $request -> montant );
2023-07-12 19:32:21 +00:00
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: CARD
]);
2023-07-14 12:24:10 +00:00
$frais += $fees ;
$taxe = $this -> calculateTax ( $taxesNationales , $frais );
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
2020-11-03 09:05:30 +00:00
$data [ 'montant_net' ] = round ( $request -> montant - $data [ 'frais' ], 2 );
2020-07-03 10:58:43 +00:00
break ;
case 17 : // Agent - Envoi de cash vers cash
$this -> validate ( $request , [
2022-04-20 16:03:13 +00:00
'final_country' => 'required|integer|exists:countries,id' ,
2023-07-22 14:12:07 +00:00
// 'id_destinataire' => 'required_without:phone_destinataire',
'network_destinataire' => 'required|integer|min:0|not_in:0' ,
2020-07-03 10:58:43 +00:00
]);
2023-07-22 14:12:07 +00:00
$configNetworkDestinataire = ConfigWallet :: where ( 'id_network' , $request -> network_destinataire ) -> firstOrFail ();
2020-07-03 10:58:43 +00:00
$frais = ( $init_country != $request -> final_country ) ? $this -> calculateFees ( $plr_agent_cash_cash , $request -> montant ) : $this -> calculateFees ( $plr_agent_cash_cash_national , $request -> montant );
2023-07-22 14:12:07 +00:00
if ( $configNetworkDestinataire -> type != 'ilink' ) {
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: WALLET
]);
$frais += $fees ;
}
2020-07-03 10:58:43 +00:00
$taxe = ( $init_country != $request -> final_country ) ? $this -> calculateTax ( $taxesInternationales , $frais ) : $this -> calculateTax ( $taxesNationales , $frais );
2020-11-03 09:05:30 +00:00
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
2023-07-12 19:32:21 +00:00
$data [ 'exchange_rate' ] = $this -> getExchangeRate ( $init_country , $request -> final_country );
2020-11-03 09:05:30 +00:00
$data [ 'montant_net_init' ] = round ( $request -> montant - $data [ 'frais' ], 2 );
2020-07-03 10:58:43 +00:00
$data [ 'montant_net_final' ] = $this -> toMoneyWithCurrency ( $data [ 'montant_net_init' ], $init_country , $request -> final_country );
break ;
2023-07-12 19:32:21 +00:00
case 21 : //User - Retrait de carte vers autre wallet
$this -> validate ( $request , [
'final_country' => 'required|integer|exists:countries,id' ,
2023-07-22 14:12:07 +00:00
'id_destinataire' => 'required_without:phone_destinataire' ,
'network_destinataire' => 'required|integer|min:0|not_in:0' ,
2023-07-12 19:32:21 +00:00
]);
$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 );
$fees = $this -> getBasicTransactionFees ([
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_OUT ,
'payment_method' => PaymentMethod :: CARD
2023-07-22 14:12:07 +00:00
]);
$configNetworkDestinataire = ConfigWallet :: where ( 'id_network' , $request -> network_destinataire ) -> firstOrFail ();
//Verifier si c'est pas un reseau ilink
if ( $configNetworkDestinataire -> type != 'ilink' ) {
$data [ 'destinataire' ] = $request -> id_destinataire ;
$fees += $this -> getBasicTransactionFees ([
2023-07-18 10:07:41 +00:00
'amount' => $request -> montant ,
'country_id' => $init_country ,
'payment_type' => PaymentType :: CASH_IN ,
'payment_method' => PaymentMethod :: WALLET
]);
2023-07-22 14:12:07 +00:00
} else {
$destinataire = User :: where ( 'user_code' , $request -> id_destinataire ) -> orWhere ( 'phone' , $request -> id_destinataire ) -> first ();
$data [ 'destinataire' ] = $destinataire ? $destinataire -> lastname . ' ' . $destinataire -> firstname : $request -> id_destinataire ;
}
2023-07-14 12:24:10 +00:00
$frais += $fees ;
$taxe = $this -> calculateTax ( $init_country != $request -> final_country ? $taxesInternationales : $taxesNationales , $frais );
$data [ 'frais' ] = round ( $frais + $taxe , 2 );
2023-07-12 19:32:21 +00:00
$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 ;
2023-07-22 14:12:07 +00:00
default :
return $this -> errorResponse ( trans ( 'errors.transaction_not_supported' ));
2020-06-19 13:48:27 +00:00
}
2022-04-20 16:03:13 +00:00
$net = $data [ 'montant_net' ] ? ? $data [ 'montant_net_init' ];
2020-11-03 09:05:30 +00:00
if ( isset ( $net ))
if ( $net < 0 )
2020-07-08 16:51:11 +00:00
return $this -> errorResponse ( trans ( 'errors.incorrect_net_amount' ));
return $this -> successResponse ( $data );
2020-06-19 13:48:27 +00:00
}
2020-11-05 17:12:55 +00:00
public function getTransactionRetrait ( Request $request )
2020-07-03 18:24:41 +00:00
{
2020-07-01 17:54:12 +00:00
$this -> validate ( $request , [
2020-07-03 18:24:41 +00:00
'id_transaction' => 'required' ,
2020-07-02 19:18:28 +00:00
'id_wallet_agent' => 'required|integer|min:0|not_in:0' ,
2020-07-07 18:17:07 +00:00
'code_retrait' => 'required' ,
2020-07-01 17:54:12 +00:00
]);
2020-07-07 18:17:07 +00:00
2020-11-03 09:05:30 +00:00
$transaction = WalletIlinkTransaction :: select ( 'nom_destinataire' , 'prenom_destinataire' , 'type_document_destinataire' , 'id_document_destinataire' , 'type' , 'encrypted_code_retrait' , 'code_retrait_salt' ,
'id_wallet_user' , 'init_country' , 'final_country' , 'network_destinataire' , 'id_transaction' , 'montant_net_final_country' , 'montant_net' ) -> where ( 'id_transaction' , $request -> id_transaction ) -> first ();
2020-07-02 19:18:28 +00:00
2020-07-03 18:24:41 +00:00
if ( ! $transaction )
2020-07-01 17:54:12 +00:00
return $this -> errorResponse ( trans ( 'errors.transaction_not_exist' ), Response :: HTTP_NOT_FOUND );
2020-11-03 09:05:30 +00:00
if ( ! $this -> checkPassword ( $request -> code_retrait , $transaction -> encrypted_code_retrait , $transaction -> code_retrait_salt ))
2020-07-07 18:17:07 +00:00
return $this -> errorResponse ( trans ( 'errors.invalid_withdrawal_code' ));
2020-07-04 10:20:26 +00:00
//Verifier que le reseau payeur est de type iLink
2020-07-04 10:48:06 +00:00
if ( in_array ( $transaction -> type , [ 3 , 17 ])) {
2020-07-04 14:21:53 +00:00
$configPayeur = ConfigWallet :: where ( 'id_network' , $transaction -> network_destinataire ) -> firstOrFail ();
2020-07-04 10:48:06 +00:00
if ( $configPayeur -> type != 'ilink' )
2022-02-22 09:15:59 +00:00
return $this -> errorResponse ( trans ( 'errors.withdrawal_network_unauthorized' , [ 'network' => $this -> getNetworkName ( $transaction -> network_destinataire ),
'country' => $this -> getCountryName ( $transaction -> final_country )]));
2020-07-04 10:20:26 +00:00
}
2020-07-01 17:54:12 +00:00
if ( $transaction -> status_retrait != 0 )
return $this -> errorResponse ( trans ( 'errors.withdrawal_already_made' ));
2020-07-02 19:18:28 +00:00
$walletAgent = Wallet :: findOrFail ( $request -> get ( 'id_wallet_agent' ));
$network_agent = NetworksAgent :: findOrFail ( $walletAgent -> id_networkAgent );
$agent_country = $network_agent -> network -> country -> id ;
2020-07-04 10:20:26 +00:00
if ( $agent_country != $transaction -> final_country )
return $this -> errorResponse ( trans ( 'errors.operation_cannot_performed_in_country' ));
2020-07-02 19:18:28 +00:00
2020-07-01 17:54:12 +00:00
$data = $transaction -> replicate ();
2020-07-03 18:24:41 +00:00
if ( in_array ( $transaction -> type , [ 9 , 11 ])) {
2020-07-04 14:51:59 +00:00
$identification = $identification = Identification :: where ( 'id_user' , $transaction -> wallet_user -> user -> id ) -> first ();
if ( ! $identification )
return $this -> errorResponse ( trans ( 'errors.user_identification_required' ));
if ( $identification -> status != 1 )
return $this -> errorResponse ( trans ( 'errors.validation_user_identification_required' ));
2020-07-01 17:54:12 +00:00
$data -> nom_destinataire = $transaction -> wallet_user -> user -> lastname ;
$data -> prenom_destinataire = $transaction -> wallet_user -> user -> firstname ;
2020-07-04 14:51:59 +00:00
$data -> type_document_destinataire = $identification -> identity_document ;
$data -> id_document_destinataire = $identification -> id_identity_document ;
// $data->user_code = $transaction->wallet_user->user->user_code;
2020-07-01 17:54:12 +00:00
}
2020-07-07 18:17:07 +00:00
$data -> montant = $transaction -> type == 11 ? $transaction -> montant_net : $transaction -> montant_net_final_country ;
2020-11-03 09:05:30 +00:00
unset ( $data -> type , $data -> init_country , $data -> final_country , $data -> id_wallet_user , $data -> network_destinataire , $data -> code_retrait_salt ,
$data -> encrypted_code_retrait , $data -> montant_net_final_country , $data -> montant_net );
2020-07-01 17:54:12 +00:00
return $this -> successResponse ( $data );
}
2020-06-19 13:48:27 +00:00
2020-11-05 17:12:55 +00:00
private function getPaliers ( array $paliers , $type )
2020-06-19 13:48:27 +00:00
{
return array_values ( array_filter ( $paliers , function ( $palier ) use ( $type ) {
return $palier -> type == $type ;
}));
}
//Calcul des frais internationaux
2022-04-15 18:09:52 +00:00
/**
* @ throws AppException
*/
2022-04-20 16:03:13 +00:00
private function calculateFees ( array $paliers , $montant , $frais = null )
2020-06-19 13:48:27 +00:00
{
$size = sizeof ( $paliers );
2022-04-14 18:27:06 +00:00
$fees = 0 ;
2020-06-24 07:36:54 +00:00
if ( $size > 0 ) {
$min = $paliers [ 0 ] -> min ;
$max = $paliers [ $size - 1 ] -> max ;
$palier = null ;
foreach ( $paliers as $p ) {
if ( $montant >= $p -> min && $montant <= $p -> max ) {
$palier = $p ;
break ;
}
}
2020-06-19 13:48:27 +00:00
2020-06-24 07:36:54 +00:00
if ( $palier ) {
2022-04-20 16:03:13 +00:00
if ( isset ( $frais )) {
// Pour le calcul par paliers des commissions uniquement
$montant = $frais ;
}
$fees = round (( $montant * $palier -> taux / 100 ), 2 );
2020-06-24 07:36:54 +00:00
} else {
2022-04-15 18:09:52 +00:00
throw new AppException ( trans ( 'errors.amount_not_allowed' , [ 'min' => floatval ( $min ), 'max' => floatval ( $max )]));
2022-04-14 18:27:06 +00:00
}
if ( ! empty ( $palier -> plafond ) && ( $fees > $palier -> plafond )) {
$fees = $palier -> plafond ;
2020-06-19 13:48:27 +00:00
}
}
2022-04-14 18:27:06 +00:00
return $fees ;
2020-06-19 13:48:27 +00:00
}
2020-11-05 17:12:55 +00:00
private function random_string ()
2020-06-19 13:48:27 +00:00
{
$character_set_array = array ();
2020-06-20 15:08:13 +00:00
$character_set_array [] = array ( 'count' => 12 , 'characters' => 'ABCDEFGHJKMNPQRSTUVWXYZ' );
2020-06-19 13:48:27 +00:00
$character_set_array [] = array ( 'count' => 4 , 'characters' => '23456789' );
$temp_array = array ();
foreach ( $character_set_array as $character_set ) {
for ( $i = 0 ; $i < $character_set [ 'count' ]; $i ++ ) {
$temp_array [] = $character_set [ 'characters' ][ rand ( 0 , strlen ( $character_set [ 'characters' ]) - 1 )];
}
}
shuffle ( $temp_array );
return implode ( '' , $temp_array );
}
2020-07-06 16:09:25 +00:00
2020-11-05 17:12:55 +00:00
private function getTransactionID ()
2020-11-03 09:05:30 +00:00
{
do {
$code = $this -> generateTransactionCode ();
$result = collect ( DB :: select ( 'SELECT * FROM wallet_ilink_transaction WHERE id_transaction = :code' , [ 'code' => $code ]));
$codeCorrect = sizeof ( $result ) < 0 ;
} while ( $codeCorrect );
2020-07-06 16:09:25 +00:00
return $code ;
}
2020-07-17 13:48:50 +00:00
// public function index(Request $request){
//
// $notices = DB::select('select notices.id,notices.title,notices.body,notices.created_at,notices.updated_at,
//users.name,departments.department_name
//FROM notices
//INNER JOIN users ON notices.user_id = users.id
//INNER JOIN departments on users.dpt_id = departments.id
//ORDER BY users.id DESC');
//
// $notices = $this->arrayPaginator($notices, $request);
//
// return view('welcome')->with('allNotices', $notices);
//
// }
2020-11-05 17:12:55 +00:00
public function cancel ( $id_transaction )
2020-07-17 13:48:50 +00:00
{
2020-11-03 09:05:30 +00:00
$transaction = WalletIlinkTransaction :: where ( 'id_transaction' , $id_transaction ) -> firstOrFail ();
2020-07-17 13:48:50 +00:00
$transactionInverse = $transaction -> replicate ();
2021-08-20 15:45:22 +00:00
$transactionInverse -> date = $this -> getCurrentTimeByCountryCode ( $transaction -> country -> code_country );
2020-11-03 09:05:30 +00:00
$transactionInverse -> montant = - $transaction -> montant ;
$transactionInverse -> montant_net = - $transaction -> montant_net ;
$transactionInverse -> montant_net_final_country = - $transaction -> montant_net_final_country ;
$transactionInverse -> taxe = - $transaction -> taxe ;
$transactionInverse -> frais = - $transaction -> frais ;
$transactionInverse -> commission_ag = - $transaction -> commission_ag ;
$transactionInverse -> commission_sup = - $transaction -> commission_sup ;
$transactionInverse -> commission_hyp = - $transaction -> commission_hyp ;
$transactionInverse -> commission_hyp_final_country = - $transaction -> commission_hyp_final_country ;
2020-07-17 13:48:50 +00:00
$transactionInverse -> commission_banque = - $transaction -> commission_banque ;
$transactionInverse -> id = null ;
$transactionInverse -> id_transaction = $this -> getTransactionID ();
// $walletAgent = $transaction->wallet;
// $walletSuperviseur = $transaction->wallet_sup;
// $walletHyperviseur = $transaction->wallet_hyp;
//
// if ($transaction->type == 'credit'){
// //Depot
// $walletAgent->balance_princ += $transaction->montant;
// }elseif ($transaction->type == 'debit'){
// //Retrait
// $walletAgent->balance_princ -= $transaction->montant;
// }
//
// $walletAgent->balance_com -= $transaction->commission_ag;
// $walletSuperviseur->balance_com -= $transaction->commission_sup;
// $walletHyperviseur->balance_com -= $transaction->commission_hyp;
$transaction -> canceled = 1 ;
// $walletAgent->save();
// $walletSuperviseur->save();
// $walletHyperviseur->save();
$transaction -> save ();
$transactionInverse -> save ();
return $this -> successResponse ( trans ( 'messages.canceled_transaction' ));
}
2020-09-28 15:39:57 +00:00
//Verfier les limites reglementaires
2022-04-20 08:08:32 +00:00
/**
* @ throws Exception
*/
2020-11-05 17:12:55 +00:00
public function checkReguationsLimits ( $identifiant , $init_country , $final_country , $montant_transaction , $is_id_document_emetteur = false )
2020-09-28 15:39:57 +00:00
{
$regulation = Regulation :: where ( 'id_country' , $init_country ) -> first ();
if ( ! $regulation )
return ;
// Total montants journalier
if ( $is_id_document_emetteur )
2020-10-05 16:32:31 +00:00
$daily_sum = WalletIlinkTransaction :: where ( 'id_document_emetteur' , $identifiant ) -> where ( 'final_country' , $final_country ) -> whereDate ( 'date' , Carbon :: today ()) -> sum ( 'montant' );
2020-09-28 15:39:57 +00:00
else
2020-10-05 16:32:31 +00:00
$daily_sum = WalletIlinkTransaction :: where ( 'id_wallet_user' , $identifiant ) -> where ( 'final_country' , $final_country ) -> whereDate ( 'date' , Carbon :: today ()) -> sum ( 'montant' );
$max_jour = ( $init_country == $final_country ) ? $regulation -> montant_max_jour_national : $regulation -> montant_max_jour_international ;
$amount_admitted = $max_jour - $daily_sum ;
if (( $daily_sum + $montant_transaction ) > $max_jour )
2022-04-20 08:08:32 +00:00
throw new Exception (( $init_country == $final_country ) ? trans ( 'errors.national_daily_regulations_limits_reached' ) : trans ( 'errors.international_daily_regulations_limits_reached' ) . ' '
. ( $amount_admitted > 0 ? trans ( 'errors.regulations_limits_amount_transaction' , [ 'amount' => $this -> toMoney ( $amount_admitted , $init_country )]) : '' ), 500 );
2020-09-28 15:39:57 +00:00
// Total montants hebdomadaire
if ( $is_id_document_emetteur )
2020-10-05 16:32:31 +00:00
$weekly_sum = WalletIlinkTransaction :: where ( 'id_document_emetteur' , $identifiant ) -> where ( 'final_country' , $final_country ) -> whereBetween ( 'date' , [ Carbon :: today () -> subDay ( 7 ), Carbon :: today ()]) -> sum ( 'montant' );
2020-09-28 15:39:57 +00:00
else
2020-10-05 16:32:31 +00:00
$weekly_sum = WalletIlinkTransaction :: where ( 'id_wallet_user' , $identifiant ) -> where ( 'final_country' , $final_country ) -> whereBetween ( 'date' , [ Carbon :: today () -> subDay ( 7 ), Carbon :: today ()]) -> sum ( 'montant' );
2020-10-07 09:07:11 +00:00
$max_hebdo = ( $init_country == $final_country ) ? $regulation -> montant_max_hebdo_national : $regulation -> montant_max_hebdo_international ;
2020-10-05 16:32:31 +00:00
$amount_admitted = $max_hebdo - $weekly_sum ;
if (( $weekly_sum + $montant_transaction ) > $max_hebdo )
2022-04-20 08:08:32 +00:00
throw new Exception (( $init_country == $final_country ) ? trans ( 'errors.national_weekly_regulations_limits_reached' ) : trans ( 'errors.international_weekly_regulations_limits_reached' ) . ' '
. ( $amount_admitted > 0 ? trans ( 'errors.regulations_limits_amount_transaction' , [ 'amount' => $this -> toMoney ( $amount_admitted , $init_country )]) : '' ), 500 );
2020-09-28 15:39:57 +00:00
// Total montants mensuel
if ( $is_id_document_emetteur )
2020-10-05 16:32:31 +00:00
$monthly_sum = WalletIlinkTransaction :: where ( 'id_document_emetteur' , $identifiant ) -> where ( 'final_country' , $final_country ) -> whereBetween ( 'date' , [ Carbon :: today () -> subDay ( 30 ), Carbon :: today ()]) -> sum ( 'montant' );
2020-09-28 15:39:57 +00:00
else
2020-10-05 16:32:31 +00:00
$monthly_sum = WalletIlinkTransaction :: where ( 'id_wallet_user' , $identifiant ) -> where ( 'final_country' , $final_country ) -> whereBetween ( 'date' , [ Carbon :: today () -> subDay ( 30 ), Carbon :: today ()]) -> sum ( 'montant' );
$max_mensuel = ( $init_country == $final_country ) ? $regulation -> montant_max_mensuel_national : $regulation -> montant_max_mensuel_international ;
$amount_admitted = $max_mensuel - $monthly_sum ;
if (( $monthly_sum + $montant_transaction ) > $max_mensuel )
2022-04-20 08:08:32 +00:00
throw new Exception (( $init_country == $final_country ) ? trans ( 'errors.national_monthly_regulations_limits_reached' ) : trans ( 'errors.international_monthly_regulations_limits_reached' ) . ' '
. ( $amount_admitted > 0 ? trans ( 'errors.regulations_limits_amount_transaction' , [ 'amount' => $this -> toMoney ( $amount_admitted , $init_country )]) : '' ), 500 );
2020-09-28 15:39:57 +00:00
}
2020-10-27 10:52:37 +00:00
// Recevoir le traitement d'une transaction venant d'un reseau payeur
2020-11-05 17:12:55 +00:00
public function receiveRequestProcessingResult ( Request $request )
2020-10-27 10:52:37 +00:00
{
$this -> validate ( $request , [
'id_transaction' => 'required' ,
'status' => 'required|in:NON_TRAITEE,TRAITEE'
]);
$transaction = WalletIlinkTransaction :: where ( 'id_transaction' , $request -> id_transaction ) -> firstOrFail ();
if ( ! in_array ( $transaction -> type , [ 1 , 3 , 17 ]))
return $this -> errorResponse ( trans ( 'errors.forbidden' ));
if ( $transaction -> status_reseau_payeur != 'EN_COURS' )
return $this -> errorResponse ( trans ( 'errors.request_already_processed' ));
// modifier l'etat et mettre les comptes comissions et compensatios du reseau payeur
$transaction -> status_reseau_payeur = $request -> status ;
if ( $request -> status == 'TRAITEE' ) {
//Mise a jour des comissions et compensation
$config = ConfigWallet :: where ( 'id_network' , $transaction -> network_emetteur ) -> firstOrFail ();
$reseauPayeur = PayingNetwork :: where ( 'id_network' , $transaction -> network_destinataire ) -> where ( 'id_configWallet' , $config -> id ) -> firstOrFail ();
$reseauPayeur -> balance_com += $transaction -> part_reseau_payeur_final_country ;
$reseauPayeur -> balance_compensation += $transaction -> montant_net_final_country ;
$reseauPayeur -> save ();
}
$transaction -> save ();
return $this -> successResponse ( trans ( 'messages.success_treated_demand' ));
}
2020-06-19 13:48:27 +00:00
}