2020-06-19 13:48:27 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\AgentPlus;
|
|
|
|
|
use App\Models\CodeGenerer;
|
|
|
|
|
use App\Models\ConfigWallet;
|
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-06-21 21:49:24 +00:00
|
|
|
|
use App\Models\PayingNetwork;
|
2020-06-19 13:48:27 +00:00
|
|
|
|
use App\Models\TypeIlinkTransaction;
|
|
|
|
|
use App\Models\PaliersConfigWallet;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Wallet;
|
|
|
|
|
use App\Models\WalletAgent;
|
|
|
|
|
use App\Models\WalletIlinkTransaction;
|
|
|
|
|
use App\Models\WalletsUser;
|
|
|
|
|
use App\Models\WalletTransaction;
|
|
|
|
|
use App\Traits\ApiResponser;
|
|
|
|
|
use App\Traits\Helper;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
2020-07-01 17:54:12 +00:00
|
|
|
|
use function DeepCopy\deep_copy;
|
2020-06-19 13:48:27 +00:00
|
|
|
|
use function GuzzleHttp\Promise\all;
|
|
|
|
|
|
|
|
|
|
class iLinkTransactionController extends Controller
|
|
|
|
|
{
|
|
|
|
|
use ApiResponser;
|
|
|
|
|
use Helper;
|
|
|
|
|
|
2020-08-09 22:13:21 +00:00
|
|
|
|
private $PAYMENT_URL = "/adyen-api/v1/transaction/payement";
|
|
|
|
|
private $PAYOUT_URL = "/adyen-api/v1/transaction/payout";
|
|
|
|
|
private $REFUND_URL = "/adyen-api/v1/transaction/refund";
|
|
|
|
|
|
2020-06-19 13:48:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function add(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$transaction = new WalletIlinkTransaction();
|
|
|
|
|
$this->validate($request, [
|
|
|
|
|
'type' => 'required|integer|min:0|not_in:0',
|
2020-06-21 21:49:24 +00:00
|
|
|
|
'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',
|
|
|
|
|
'password' => 'required',
|
|
|
|
|
'montant' => 'required|numeric|min:0|not_in:0',
|
2020-06-19 13:48:27 +00:00
|
|
|
|
]);
|
|
|
|
|
$type = TypeIlinkTransaction::findOrFail($request->type);
|
|
|
|
|
|
2020-06-21 21:49:24 +00:00
|
|
|
|
if (isset($request->id_wallet_agent)) {
|
|
|
|
|
$walletAgent = Wallet::findOrFail($request->get('id_wallet_agent'));
|
|
|
|
|
$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);
|
|
|
|
|
$walletHyperviseur = Wallet::findOrFail($wallet_agent_hyp->wallet_id);
|
|
|
|
|
} elseif (isset($request->id_wallet_user)) {
|
2020-06-24 07:36:54 +00:00
|
|
|
|
$walletUser = WalletsUser::findOrFail($request->id_wallet_user);
|
|
|
|
|
$transaction->init_country = $init_country = $walletUser->user->network->country->id;
|
|
|
|
|
$result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network')
|
|
|
|
|
->where('networks.country_id', $init_country)->where('configWallet.type', 'ilink')
|
|
|
|
|
->select('configWallet.id')->first();
|
|
|
|
|
if ($result) {
|
|
|
|
|
$config = ConfigWallet::findOrFail($result->id);
|
|
|
|
|
} 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();
|
|
|
|
|
$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) {
|
|
|
|
|
return $tax->destination == 'national';
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$taxesInternationales = array_values(array_filter($config->taxes->all(), function ($tax) {
|
|
|
|
|
return $tax->destination == 'international';
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$plr_user_wallet_wallet = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_wallet_international");
|
|
|
|
|
$plr_user_wallet_cash = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_cash_international");
|
|
|
|
|
$plr_agent_depot_wallet_ilink = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_wallet_ilink_international");
|
|
|
|
|
$plr_agent_depot_autre_wallet = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_autre_wallet_international");
|
|
|
|
|
$plr_agent_cash_cash = $this->getPaliers($config->paliers_config_wallets->all(), "agent_cash_cash_international");
|
|
|
|
|
|
|
|
|
|
$plr_user_wallet_wallet_national = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_wallet_national");
|
|
|
|
|
$plr_user_wallet_cash_national = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_cash_national");
|
|
|
|
|
$plr_agent_depot_wallet_ilink_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_wallet_ilink_national");
|
|
|
|
|
$plr_agent_depot_autre_wallet_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_autre_wallet_national");
|
|
|
|
|
$plr_agent_cash_cash_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_cash_cash_national");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data = $request->all();
|
|
|
|
|
if (isset($request->cvv) && !is_numeric($request->cvv))
|
|
|
|
|
return $this->errorResponse('errors.invalid_cvv');
|
|
|
|
|
|
|
|
|
|
$transaction->fill($data);
|
|
|
|
|
// Client API
|
|
|
|
|
$client = new \GuzzleHttp\Client([
|
|
|
|
|
'base_uri' => env('VISA_API_URL'),
|
|
|
|
|
'auth' => [env('VISA_API_USERNAME'), env('VISA_API_PASSWORD')]
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
switch ($type->id) {
|
|
|
|
|
case 1: //User - Envoi wallet à wallet
|
2020-06-21 21:49:24 +00:00
|
|
|
|
$this->validate($request, $transaction->send_wallet_wallet_rules());
|
2020-06-24 07:36:54 +00:00
|
|
|
|
$user = $walletUser->user;
|
2020-06-21 21:49:24 +00:00
|
|
|
|
if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
2020-07-25 18:02:54 +00:00
|
|
|
|
if($init_country != $request->final_country)
|
|
|
|
|
return $this->checkUserIdentification($user->id);
|
2020-06-24 07:36:54 +00:00
|
|
|
|
if ($request->montant > $walletUser->balance) {
|
2020-06-23 16:21:26 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
2020-06-24 07:36:54 +00:00
|
|
|
|
} else {
|
|
|
|
|
$transaction->frais = $frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_wallet, $request->montant) : $this->calculateFees($plr_user_wallet_wallet_national, $request->montant);
|
|
|
|
|
$transaction->taxe = $taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
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-06-23 16:21:26 +00:00
|
|
|
|
$configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
|
2020-07-03 19:53:34 +00:00
|
|
|
|
|
2020-07-04 10:20:26 +00:00
|
|
|
|
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->first();
|
|
|
|
|
if (isset($reseauPayeur)) {
|
|
|
|
|
$transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100;
|
|
|
|
|
$transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country);
|
|
|
|
|
$transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur;
|
|
|
|
|
$reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country;
|
2020-07-25 18:02:54 +00:00
|
|
|
|
$reseauPayeur->balance_compensation += $transaction->montant_net_final_country;
|
2020-07-04 10:20:26 +00:00
|
|
|
|
} 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;
|
|
|
|
|
if ($configPayeur->type == 'ilink') {
|
|
|
|
|
$destinataire = User::where('user_code', $request->id_destinataire)->first();
|
2020-06-24 07:36:54 +00:00
|
|
|
|
if ($destinataire) { // Si c'est un wallet ilink
|
|
|
|
|
if ($destinataire->network->country->id == $request->final_country) {
|
|
|
|
|
$walletDestinataire = WalletsUser::where('idUser', $destinataire->id)->firstOrFail();
|
2020-06-27 15:04:28 +00:00
|
|
|
|
$walletDestinataire->balance += $this->toMoneyAmount($montantDepot, $init_country, $request->final_country);
|
2020-06-24 07:36:54 +00:00
|
|
|
|
$walletDestinataire->save();
|
|
|
|
|
} else {
|
|
|
|
|
$country = Country::findOrFail($request->final_country);
|
|
|
|
|
return $this->errorResponse(trans('errors.wallet_country_not_match', ['country' => $country->name]));
|
|
|
|
|
}
|
2020-06-23 16:21:26 +00:00
|
|
|
|
} else {
|
|
|
|
|
return $this->errorResponse(trans('errors.wallet_not_defined'));
|
|
|
|
|
}
|
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 {
|
|
|
|
|
//Emettre requete SSL vers wallet extene correspondant pour recharger le compte dont l'id est :
|
2020-06-23 05:36:12 +00:00
|
|
|
|
// $transaction->id_destinataire ;
|
2020-06-23 16:21:26 +00:00
|
|
|
|
// et le montant est:
|
2020-06-23 05:36:12 +00:00
|
|
|
|
// $montantDepot;
|
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-25 08:01:59 +00:00
|
|
|
|
$transaction->id_transaction = $this->getTransactionID();
|
2020-06-24 17:34:18 +00:00
|
|
|
|
|
2020-06-24 17:28:11 +00:00
|
|
|
|
$walletHyperviseur->save();
|
|
|
|
|
$walletUser->save();
|
2020-06-30 13:09:00 +00:00
|
|
|
|
if (isset($reseauPayeur))
|
2020-06-29 16:46:43 +00:00
|
|
|
|
$reseauPayeur->save();
|
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),
|
2020-06-25 08:01:59 +00:00
|
|
|
|
'net_final' => $this->toMoneyWithCurrency($montantDepot, $init_country, $request->final_country), 'fees' => $this->toMoney($frais + $taxe, $init_country),
|
|
|
|
|
'init_country' => $this->getCountryName($init_country), 'final_country' => $this->getCountryName($request->final_country),
|
2020-07-08 18:34:09 +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);
|
2020-06-30 13:09:00 +00:00
|
|
|
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
2020-06-22 15:09:26 +00:00
|
|
|
|
}
|
2020-06-21 21:49:24 +00:00
|
|
|
|
} else {
|
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case 2: //User - Envoi de wallet à carte
|
2020-06-30 11:06:56 +00:00
|
|
|
|
$this->validate($request, $transaction->user_card_rules());
|
2020-06-24 07:36:54 +00:00
|
|
|
|
$user = $walletUser->user;
|
2020-06-23 16:21:26 +00:00
|
|
|
|
if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
|
|
|
|
if ($request->montant > $walletUser->balance) {
|
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
|
|
|
|
} else {
|
2020-06-30 13:09:00 +00:00
|
|
|
|
if (!(isset($user->numero_carte) && isset($user->expiration_date)))
|
2020-06-30 11:06:56 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.no_bank_card_attached'));
|
|
|
|
|
|
|
|
|
|
$transaction->expiration_date = $user->expiration_date;
|
|
|
|
|
$transaction->numero_carte = $user->numero_carte;
|
2020-06-23 16:21:26 +00:00
|
|
|
|
|
|
|
|
|
$frais = $request->montant * $config->taux_com_user_wallet_carte / 100;
|
2020-06-28 10:45:17 +00:00
|
|
|
|
$transaction->montant_net = $montantDepot = $transaction->montant - $frais;
|
2020-08-09 22:13:21 +00:00
|
|
|
|
// $body['amount'] = $this->toUSDAmount($montantDepot, $init_country);
|
2020-06-30 11:06:56 +00:00
|
|
|
|
$body['card_number'] = $user->numero_carte;
|
2020-06-23 16:21:26 +00:00
|
|
|
|
$body['cvv'] = $request->cvv;
|
2020-08-09 22:13:21 +00:00
|
|
|
|
// $body['expiry_date'] = $user->expiration_date->format('Y-m');
|
|
|
|
|
$body['expiry_date'] = $user->expiration_date->format('m/y');
|
|
|
|
|
$body['amount'] = $montantDepot;
|
|
|
|
|
$identification = Identification::where('id_user', $user->id)->first();
|
|
|
|
|
$body['cardholder_name'] = $identification ? $identification->lastname . ' ' . $identification->firstname : $user->lastname . ' ' . $user->firstname; //"John Smith" ;
|
|
|
|
|
$body['currency'] = $this->getCurrency($init_country);
|
|
|
|
|
$body['ref'] = date("Y-m-d H:i:s.u");
|
|
|
|
|
|
2020-08-09 23:17:35 +00:00
|
|
|
|
$response = $client->post($this->PAYOUT_URL, ['json' => $body, 'http_errors' => false]);
|
2020-06-23 16:21:26 +00:00
|
|
|
|
|
|
|
|
|
$code = $response->getStatusCode();
|
|
|
|
|
|
|
|
|
|
if ($code == 200) {
|
2020-08-09 22:13:21 +00:00
|
|
|
|
$response = json_decode($response->getBody()->getContents(), true)["response"];
|
|
|
|
|
$transaction->pspReference = $response["pspReference"];
|
|
|
|
|
|
2020-06-23 16:21:26 +00:00
|
|
|
|
$walletUser->balance -= $transaction->montant;
|
2020-07-01 17:54:12 +00:00
|
|
|
|
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
|
2020-07-03 18:24:41 +00:00
|
|
|
|
$transaction->commission_banque = $frais * $config->taux_com_banque_envoi_wallet_carte_ilink / 100;
|
2020-06-23 16:21:26 +00:00
|
|
|
|
|
2020-07-03 18:24:41 +00:00
|
|
|
|
$transaction->commission_hyp = $frais * $config->taux_com_hyp_envoi_wallet_carte_ilink / 100;
|
2020-07-01 17:54:12 +00:00
|
|
|
|
$walletHyperviseur->balance_com += $transaction->commission_hyp;
|
2020-06-23 16:21:26 +00:00
|
|
|
|
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
|
|
|
|
$transaction->frais = $frais;
|
|
|
|
|
$transaction->date = new \DateTime();
|
|
|
|
|
$walletHyperviseur->save();
|
|
|
|
|
$walletUser->save();
|
2020-06-25 08:01:59 +00:00
|
|
|
|
$transaction->id_transaction = $this->getTransactionID();
|
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_cart',
|
2020-06-25 08:01:59 +00:00
|
|
|
|
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
2020-06-24 07:36:54 +00:00
|
|
|
|
'net' => $this->toMoney($montantDepot, $init_country), 'fees' => $this->toMoney($frais, $init_country),
|
2020-06-30 11:06:56 +00:00
|
|
|
|
'sender_code' => $user->user_code, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]);
|
2020-08-09 22:49:00 +00:00
|
|
|
|
$this->sendMail($user->email, trans('messages.successful_transaction'), $message);
|
2020-06-30 13:09:00 +00:00
|
|
|
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
2020-06-19 13:48:27 +00:00
|
|
|
|
|
2020-06-23 16:21:26 +00:00
|
|
|
|
} else {
|
2020-08-10 07:17:57 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.visa_api_failed'));
|
2020-06-23 16:21:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-24 07:36:54 +00:00
|
|
|
|
} else {
|
2020-06-23 16:21:26 +00:00
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case 3: //User - Envoi de wallet à cash
|
2020-06-27 15:04:28 +00:00
|
|
|
|
$this->validate($request, $transaction->send_wallet_cash_rules());
|
|
|
|
|
$user = $walletUser->user;
|
|
|
|
|
if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
2020-07-25 18:02:54 +00:00
|
|
|
|
if($init_country != $request->final_country)
|
|
|
|
|
return $this->checkUserIdentification($user->id);;
|
2020-06-27 15:04:28 +00:00
|
|
|
|
if ($request->montant > $walletUser->balance) {
|
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
|
|
|
|
} else {
|
|
|
|
|
$transaction->frais = $frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_cash, $request->montant) : $this->calculateFees($plr_user_wallet_cash_national, $request->montant);
|
|
|
|
|
$transaction->taxe = $taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
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-06-28 10:45:17 +00:00
|
|
|
|
$configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
|
2020-07-03 19:53:34 +00:00
|
|
|
|
|
2020-07-04 10:20:26 +00:00
|
|
|
|
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->first();
|
|
|
|
|
if (isset($reseauPayeur)) {
|
|
|
|
|
$transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100;
|
|
|
|
|
$transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country);
|
|
|
|
|
$transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur;
|
|
|
|
|
$reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country;
|
2020-07-25 18:02:54 +00:00
|
|
|
|
$reseauPayeur->balance_compensation += $transaction->montant_net_final_country;
|
2020-07-04 10:20:26 +00:00
|
|
|
|
} 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-06-28 10:45:17 +00:00
|
|
|
|
if ($configPayeur->type == 'ilink') {
|
|
|
|
|
//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-06-28 10:45:17 +00:00
|
|
|
|
//Emettre requete SSL vers wallet extene correspondant pour recharger le compte dont l'id est :
|
|
|
|
|
// $transaction->id_destinataire ;
|
|
|
|
|
// et le montant est:
|
|
|
|
|
// $montantDepot;
|
|
|
|
|
}
|
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;
|
|
|
|
|
$transaction->id_transaction = $this->getTransactionID();
|
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-06-28 10:45:17 +00:00
|
|
|
|
$transaction->date = new \DateTime();
|
|
|
|
|
$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-07-08 18:34:09 +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);
|
|
|
|
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
2020-06-27 15:04:28 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case 4: //User - Envoi de wallet à banque
|
|
|
|
|
// Non disponible
|
|
|
|
|
//Pas de taxes
|
|
|
|
|
break;
|
|
|
|
|
// 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;
|
|
|
|
|
case 9: // User - Retrait de wallet en cash
|
2020-06-29 16:46:43 +00:00
|
|
|
|
$user = $walletUser->user;
|
|
|
|
|
if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
|
|
|
|
if ($request->montant > $walletUser->balance) {
|
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
|
|
|
|
} else {
|
2020-07-25 18:02:54 +00:00
|
|
|
|
return $this->checkUserIdentification($user->id);;
|
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();
|
|
|
|
|
$transaction->date = new \DateTime();
|
|
|
|
|
$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);
|
|
|
|
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
2020-06-29 16:46:43 +00:00
|
|
|
|
}
|
2020-06-30 13:09:00 +00:00
|
|
|
|
} else {
|
2020-06-29 16:46:43 +00:00
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
|
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case 10: //User - Retrait de carte vers wallet
|
2020-06-30 11:06:56 +00:00
|
|
|
|
$this->validate($request, $transaction->user_card_rules());
|
2020-06-29 16:46:43 +00:00
|
|
|
|
$user = $walletUser->user;
|
|
|
|
|
if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
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)))
|
|
|
|
|
return $this->errorResponse(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
|
|
|
|
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$frais = $request->montant * $config->taux_com_user_carte_wallet / 100;
|
2020-06-29 16:46:43 +00:00
|
|
|
|
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$transaction->montant_net = $montantRetrait = $transaction->montant - $frais;
|
2020-08-09 22:13:21 +00:00
|
|
|
|
// $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country);
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$body['card_number'] = $user->numero_carte;
|
|
|
|
|
$body['cvv'] = $request->cvv;
|
2020-08-09 22:13:21 +00:00
|
|
|
|
// $body['expiry_date'] = $user->expiration_date->format('Y-m');
|
|
|
|
|
$body['expiry_date'] = $user->expiration_date->format('m/y');
|
|
|
|
|
$body['amount'] = $montantRetrait;
|
|
|
|
|
$identification = Identification::where('id_user', $user->id)->first();
|
|
|
|
|
$body['cardholder_name'] = $identification ? $identification->lastname . ' ' . $identification->firstname : $user->lastname . ' ' . $user->firstname; //"John Smith" ;
|
|
|
|
|
$body['currency'] = $this->getCurrency($init_country);
|
|
|
|
|
$body['cardholder_name'] = "John Smith";
|
|
|
|
|
$body['ref'] = date("Y-m-d H:i:s.u");
|
2020-07-02 19:18:28 +00:00
|
|
|
|
// dd($body);
|
2020-06-29 16:46:43 +00:00
|
|
|
|
|
2020-08-09 23:17:35 +00:00
|
|
|
|
$response = $client->post($this->PAYMENT_URL, ['json' => $body, 'http_errors' => false]);
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$code = $response->getStatusCode();
|
2020-06-29 16:46:43 +00:00
|
|
|
|
|
2020-06-30 13:09:00 +00:00
|
|
|
|
if ($code == 200) {
|
2020-08-09 22:13:21 +00:00
|
|
|
|
$response = json_decode($response->getBody()->getContents(), true)["response"];
|
|
|
|
|
$transaction->pspReference = $response["pspReference"];
|
|
|
|
|
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$transaction->commission_banque = $commissionBanque = $frais * $config->taux_com_banque_retrait_carte_cash_ilink / 100;
|
|
|
|
|
//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
|
|
|
|
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$walletUser->balance += $montantRetrait;
|
|
|
|
|
$transaction->commission_hyp = $frais * $config->taux_com_hyp_retrait_carte_cash_ilink / 100;
|
|
|
|
|
$walletHyperviseur->balance_com += $transaction->commission_hyp;
|
|
|
|
|
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
|
|
|
|
$transaction->frais = $frais;
|
|
|
|
|
$transaction->date = new \DateTime();
|
|
|
|
|
$walletHyperviseur->save();
|
|
|
|
|
$walletUser->save();
|
|
|
|
|
$transaction->id_transaction = $this->getTransactionID();
|
|
|
|
|
$transaction->save();
|
|
|
|
|
$message = trans('messages.successful_user_remove_from_cart_to_wallet',
|
|
|
|
|
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
|
|
|
|
'net' => $this->toMoney($montantRetrait, $init_country), 'fees' => $this->toMoney($frais, $init_country),
|
|
|
|
|
'sender_code' => $user->user_code, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]);
|
|
|
|
|
$this->sendMail($user->email, trans('messages.successful_transaction'), $message);
|
|
|
|
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
|
|
|
|
|
|
|
|
|
} else {
|
2020-08-10 07:17:57 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.visa_api_failed'));
|
2020-06-29 16:46:43 +00:00
|
|
|
|
}
|
2020-06-30 13:09:00 +00:00
|
|
|
|
|
2020-06-29 16:46:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case 11: // User - Retrait de carte vers cash
|
2020-06-30 11:06:56 +00:00
|
|
|
|
$this->validate($request, $transaction->user_card_rules());
|
|
|
|
|
$user = $walletUser->user;
|
|
|
|
|
if ($this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
2020-07-25 18:02:54 +00:00
|
|
|
|
return $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)))
|
|
|
|
|
return $this->errorResponse(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;
|
2020-07-04 10:20:26 +00:00
|
|
|
|
$transaction->final_country = $init_country;
|
2020-06-30 11:06:56 +00:00
|
|
|
|
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$frais = $request->montant * $config->taux_com_user_carte_cash / 100;
|
2020-07-07 19:15:30 +00:00
|
|
|
|
$transaction->montant_net_final_country = $transaction->montant_net = $montantRetrait = $transaction->montant - $frais;
|
2020-08-09 22:13:21 +00:00
|
|
|
|
// $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country);
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$body['card_number'] = $user->numero_carte;
|
|
|
|
|
$body['cvv'] = $request->cvv;
|
2020-08-09 22:13:21 +00:00
|
|
|
|
// $body['expiry_date'] = $user->expiration_date->format('Y-m');
|
|
|
|
|
$body['expiry_date'] = $user->expiration_date->format('m/y');
|
|
|
|
|
$body['amount'] = $montantDepot;
|
|
|
|
|
$identification = Identification::where('id_user', $user->id)->first();
|
|
|
|
|
$body['cardholder_name'] = $identification ? $identification->lastname . ' ' . $identification->firstname : $user->lastname . ' ' . $user->firstname; //"John Smith" ;
|
|
|
|
|
$body['currency'] = $this->getCurrency($init_country);
|
|
|
|
|
$body['ref'] = date("Y-m-d H:i:s.u");
|
|
|
|
|
|
2020-08-09 23:17:35 +00:00
|
|
|
|
$response = $client->post($this->PAYMENT_URL, ['json' => $body, 'http_errors' => false]);
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$code = $response->getStatusCode();
|
2020-06-30 11:06:56 +00:00
|
|
|
|
|
2020-06-30 13:09:00 +00:00
|
|
|
|
if ($code == 200) {
|
2020-08-09 22:13:21 +00:00
|
|
|
|
$response = json_decode($response->getBody()->getContents(), true)["response"];
|
|
|
|
|
$transaction->pspReference = $response["pspReference"];
|
|
|
|
|
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$transaction->commission_banque = $commissionBanque = $frais * $config->taux_com_banque_retrait_carte_cash_ilink / 100;
|
|
|
|
|
//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
|
|
|
|
|
2020-06-30 13:09:00 +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-30 13:09:00 +00:00
|
|
|
|
$transaction->commission_hyp = $frais * $config->taux_com_hyp_retrait_carte_cash_ilink / 100;
|
|
|
|
|
$walletHyperviseur->balance_com += $transaction->commission_hyp;
|
|
|
|
|
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
|
|
|
|
$transaction->frais = $frais;
|
|
|
|
|
$transaction->date = new \DateTime();
|
|
|
|
|
$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),
|
2020-07-07 19:15:30 +00:00
|
|
|
|
'final_country' => $this->getCountryName($init_country),'init_country' => $this->getCountryName($init_country),
|
2020-06-30 13:09:00 +00:00
|
|
|
|
'net' => $this->toMoney($montantRetrait, $init_country), 'fees' => $this->toMoney($frais, $init_country), 'code' => wordwrap($code_retrait, 4, ' ', true),
|
|
|
|
|
'sender_code' => $user->user_code, 'cart_number' => wordwrap($transaction->numero_carte, 4, ' ', true)]);
|
|
|
|
|
$this->sendMail($user->email, trans('messages.successful_transaction'), $message);
|
|
|
|
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
|
|
|
|
|
|
|
|
|
} else {
|
2020-08-10 07:17:57 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.visa_api_failed'));
|
2020-06-30 11:06:56 +00:00
|
|
|
|
}
|
2020-06-30 13:09:00 +00:00
|
|
|
|
|
2020-06-30 11:06:56 +00:00
|
|
|
|
} else {
|
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case 12: // Agent - Retrait en cash
|
2020-06-20 15:08:13 +00:00
|
|
|
|
$this->validate($request, $transaction->remove_cash_rules());
|
|
|
|
|
$agent = AgentPlus::findOrFail($network_agent->agent_id);
|
|
|
|
|
if ($this->checkPassword($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
|
|
|
|
|
if($transaction->type == 17)
|
|
|
|
|
if($transaction->id_wallet_ag == $walletAgent->id)
|
|
|
|
|
return $this->errorResponse(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')
|
2020-07-08 16:51:11 +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-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)
|
|
|
|
|
return $this->errorResponse(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-07-08 16:51:11 +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
|
|
|
|
|
2020-07-03 10:58:43 +00:00
|
|
|
|
$transactionRetrait->commission_ag = floatval($commissionHyp * $config->taux_com_ag_retrait_cash / 100);
|
2020-07-03 18:24:41 +00:00
|
|
|
|
$transactionRetrait->commission_sup = floatval($commissionHyp * $config->taux_com_sup_retrait_cash / 100);
|
2020-07-03 10:58:43 +00:00
|
|
|
|
$transactionRetrait->commission_hyp = $commissionHyp - $transactionRetrait->commission_ag - $transactionRetrait->commission_sup;
|
|
|
|
|
$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;
|
|
|
|
|
$transaction->date_retrait = new \DateTime();
|
2020-07-01 17:54:12 +00:00
|
|
|
|
$transactionRetrait->date = new \DateTime();
|
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-07-08 16:51:11 +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);
|
2020-07-01 17:54:12 +00:00
|
|
|
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
2020-06-21 21:49:24 +00:00
|
|
|
|
} else {
|
2020-07-01 17:54:12 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.incorrect_withdrawal_amount'));
|
2020-06-21 21:49:24 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-07-01 17:54:12 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.invalid_withdrawal_code'));
|
2020-06-20 15:08:13 +00:00
|
|
|
|
}
|
2020-06-21 21:49:24 +00:00
|
|
|
|
} else {
|
2020-07-01 17:54:12 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.withdrawal_already_made'));
|
2020-06-20 15:08:13 +00:00
|
|
|
|
}
|
2020-06-21 21:49:24 +00:00
|
|
|
|
} else {
|
2020-07-01 17:54:12 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.transaction_not_exist'), Response::HTTP_NOT_FOUND);
|
2020-06-20 15:08:13 +00:00
|
|
|
|
}
|
2020-06-21 21:49:24 +00:00
|
|
|
|
} else {
|
2020-06-20 15:08:13 +00:00
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case 13: // Agent - Retrait de la carte vers cash
|
2020-06-21 21:49:24 +00:00
|
|
|
|
$this->validate($request, $transaction->card_rules());
|
|
|
|
|
$agent = AgentPlus::findOrFail($network_agent->agent_id);
|
|
|
|
|
if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) {
|
|
|
|
|
$expiration_date = \DateTime::createFromFormat('m/y', $request->expiration_date);
|
|
|
|
|
if (!$expiration_date)
|
|
|
|
|
$expiration_date = new \DateTime();
|
|
|
|
|
$transaction->expiration_date = $expiration_date;
|
2020-07-09 18:43:47 +00:00
|
|
|
|
$transaction->final_country = $init_country;
|
2020-06-21 21:49:24 +00:00
|
|
|
|
|
|
|
|
|
$frais = floatval($request->montant * $config->taux_com_wallet_ag_carte_cash / 100);
|
2020-07-03 10:58:43 +00:00
|
|
|
|
$montantRetrait = $transaction->montant - $frais;
|
2020-06-28 10:45:17 +00:00
|
|
|
|
$transaction->montant_net = $montantRetrait;
|
2020-08-09 22:13:21 +00:00
|
|
|
|
// $body['amount'] = $this->toUSDAmount($montantRetrait, $init_country);
|
2020-06-21 21:49:24 +00:00
|
|
|
|
$body['card_number'] = $request->numero_carte;
|
|
|
|
|
$body['cvv'] = $request->cvv;
|
2020-08-09 22:13:21 +00:00
|
|
|
|
// $body['expiry_date'] = $expiration_date->format('Y-m');
|
|
|
|
|
$body['expiry_date'] = $expiration_date->format('m/y');
|
|
|
|
|
$body['amount'] = $montantRetrait;
|
2020-08-09 22:49:00 +00:00
|
|
|
|
$body['cardholder_name'] = $request->lastname ? $request->lastname . ' ' . $request->firstname : "John Smith";
|
2020-08-09 22:13:21 +00:00
|
|
|
|
$body['currency'] = $this->getCurrency($init_country);
|
|
|
|
|
$body['ref'] = date("Y-m-d H:i:s.u");
|
|
|
|
|
|
2020-08-09 23:17:35 +00:00
|
|
|
|
$response = $client->post($this->PAYMENT_URL, ['json' => $body, 'http_errors' => false]);
|
2020-07-02 19:18:28 +00:00
|
|
|
|
$code = $response->getStatusCode();
|
2020-06-21 21:49:24 +00:00
|
|
|
|
|
|
|
|
|
if ($code == 200) {
|
2020-08-09 22:13:21 +00:00
|
|
|
|
$response = json_decode($response->getBody()->getContents(), true)["response"];
|
|
|
|
|
$transaction->pspReference = $response["pspReference"];
|
|
|
|
|
|
2020-06-21 21:49:24 +00:00
|
|
|
|
$banqueCommission = floatval($frais * $config->taux_com_banque_retrait_carte_cash / 100);
|
|
|
|
|
$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 %
|
2020-07-02 19:18:28 +00:00
|
|
|
|
//pour le dépôt qui s’applique sur les frais minimum) et créditer
|
2020-06-21 21:49:24 +00:00
|
|
|
|
//le compte des opérations défini avec notre banque
|
|
|
|
|
//partenaire
|
|
|
|
|
|
|
|
|
|
$walletAgent->balance_princ += $transaction->montant;
|
|
|
|
|
|
|
|
|
|
$agentCommission = floatval($frais * $config->taux_com_ag_retrait_carte_cash / 100);
|
|
|
|
|
$superviseurCommission = floatval($frais * $config->taux_com_sup_retrait_carte_cash / 100);
|
2020-07-02 19:18:28 +00:00
|
|
|
|
$hyperviseurCommission = floatval($frais * $config->taux_com_hyp_retrait_carte_cash / 100);
|
2020-06-21 21:49:24 +00:00
|
|
|
|
|
|
|
|
|
$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 = new \DateTime();
|
|
|
|
|
$walletAgent->save();
|
|
|
|
|
$walletSuperviseur->save();
|
|
|
|
|
$walletHyperviseur->save();
|
2020-07-02 19:18:28 +00:00
|
|
|
|
$transaction->id_transaction = $this->getTransactionID();
|
2020-06-21 21:49:24 +00:00
|
|
|
|
$transaction->save();
|
|
|
|
|
return $this->successResponse(trans('messages.successful_transaction'));
|
|
|
|
|
|
|
|
|
|
} else {
|
2020-08-10 07:17:57 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.visa_api_failed'));
|
2020-06-21 21:49:24 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case 14: // Agent - Envoi de cash vers wallet iLink
|
2020-06-20 15:08:13 +00:00
|
|
|
|
$this->validate($request, $transaction->cash_wallet_rules());
|
2020-06-19 19:31:32 +00:00
|
|
|
|
$agent = AgentPlus::findOrFail($network_agent->agent_id);
|
2020-06-20 15:08:13 +00:00
|
|
|
|
if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) {
|
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)
|
2020-07-02 19:18:28 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.wallet_not_defined'));
|
|
|
|
|
|
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-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;
|
2020-06-19 13:48:27 +00:00
|
|
|
|
$commisionAgent = floatval($frais * $config->taux_com_ag_envoi_cash / 100);
|
|
|
|
|
$commisionSuper = floatval($frais * $config->taux_com_sup_envoi_cash / 100);
|
2020-06-19 18:33:10 +00:00
|
|
|
|
$commisionHyper = floatval($frais * $config->taux_com_hyp_envoi_cash / 100);
|
2020-07-02 20:57:18 +00:00
|
|
|
|
|
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;
|
|
|
|
|
$transaction->date = new \DateTime();
|
|
|
|
|
$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);
|
|
|
|
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
2020-06-20 15:08:13 +00:00
|
|
|
|
} else {
|
2020-06-19 13:48:27 +00:00
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 15: // Agent - Envoi de cash vers autre wallet
|
2020-07-04 10:20:26 +00:00
|
|
|
|
$this->validate($request, array_merge($transaction->cash_cash_rules(), [
|
|
|
|
|
'id_destinataire' => 'required'
|
|
|
|
|
]));
|
2020-06-19 19:31:32 +00:00
|
|
|
|
$agent = AgentPlus::findOrFail($network_agent->agent_id);
|
2020-06-20 15:08:13 +00:00
|
|
|
|
if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) {
|
2020-07-03 10:58:43 +00:00
|
|
|
|
if ($request->montant > $walletAgent->balance_princ)
|
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
|
|
|
|
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_agent_depot_autre_wallet, $request->montant) : $this->calculateFees($plr_agent_depot_autre_wallet_national, $request->montant);
|
2020-07-03 18:24:41 +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
|
2020-07-03 10:58:43 +00:00
|
|
|
|
$commisionAgent = floatval($transaction->part_reseau_emetteur * $config->taux_com_ag_envoi_cash / 100);
|
|
|
|
|
$commisionSuper = floatval($transaction->part_reseau_emetteur * $config->taux_com_sup_envoi_cash / 100);
|
|
|
|
|
$commisionHyper = floatval($transaction->part_reseau_emetteur * $config->taux_com_hyp_envoi_cash / 100);
|
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;
|
|
|
|
|
$transaction->date = new \DateTime();
|
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-07-08 18:34:09 +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);
|
|
|
|
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
2020-06-20 15:08:13 +00:00
|
|
|
|
} else {
|
2020-06-19 19:31:32 +00:00
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case 16: // Agent - Envoi de cash vers une carte visa
|
2020-06-21 21:49:24 +00:00
|
|
|
|
$this->validate($request, $transaction->card_rules());
|
2020-06-19 19:31:32 +00:00
|
|
|
|
$agent = AgentPlus::findOrFail($network_agent->agent_id);
|
2020-06-20 15:08:13 +00:00
|
|
|
|
if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) {
|
2020-07-03 10:58:43 +00:00
|
|
|
|
if ($request->montant > $walletAgent->balance_princ)
|
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
2020-06-19 19:31:32 +00:00
|
|
|
|
$expiration_date = \DateTime::createFromFormat('m/y', $request->expiration_date);
|
|
|
|
|
if (!$expiration_date)
|
|
|
|
|
$expiration_date = new \DateTime();
|
|
|
|
|
$transaction->expiration_date = $expiration_date;
|
2020-07-09 18:43:47 +00:00
|
|
|
|
$transaction->final_country = $init_country;
|
2020-06-19 19:31:32 +00:00
|
|
|
|
|
|
|
|
|
$frais = $request->montant * $config->taux_com_wallet_ag_envoi_cash_carte / 100;
|
|
|
|
|
$montantDepot = $transaction->montant - $frais;
|
2020-06-28 10:45:17 +00:00
|
|
|
|
$transaction->montant_net = $montantDepot;
|
2020-08-09 22:13:21 +00:00
|
|
|
|
// $body['amount'] = $this->toUSDAmount($montantDepot, $init_country);;
|
2020-06-19 19:31:32 +00:00
|
|
|
|
$body['card_number'] = $request->numero_carte;
|
|
|
|
|
$body['cvv'] = $request->cvv;
|
2020-08-09 22:13:21 +00:00
|
|
|
|
// $body['expiry_date'] = $expiration_date->format('Y-m');
|
|
|
|
|
$body['expiry_date'] = $expiration_date->format('m/y');
|
|
|
|
|
$body['amount'] = $montantDepot;
|
2020-06-19 19:31:32 +00:00
|
|
|
|
|
2020-08-09 22:49:00 +00:00
|
|
|
|
$body['cardholder_name'] = $request->lastname ? $request->lastname . ' ' . $request->firstname : "John Smith";
|
2020-08-09 22:13:21 +00:00
|
|
|
|
$body['currency'] = $this->getCurrency($init_country);
|
|
|
|
|
$body['ref'] = date("Y-m-d H:i:s.u");
|
|
|
|
|
|
2020-08-09 23:17:35 +00:00
|
|
|
|
$response = $client->post($this->PAYOUT_URL, ['json' => $body, 'http_errors' => false]);
|
2020-06-19 19:31:32 +00:00
|
|
|
|
$code = $response->getStatusCode();
|
|
|
|
|
|
|
|
|
|
if ($code == 200) {
|
2020-08-09 22:13:21 +00:00
|
|
|
|
$response = json_decode($response->getBody()->getContents(), true)["response"];
|
|
|
|
|
$transaction->pspReference = $response["pspReference"];
|
|
|
|
|
|
2020-06-19 19:31:32 +00:00
|
|
|
|
$banqueCommission = floatval($frais * $config->taux_com_banque_depot_cash_carte / 100);
|
|
|
|
|
$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 = floatval($frais * $config->taux_com_ag_depot_cash_carte / 100);
|
|
|
|
|
$superviseurCommission = floatval($frais * $config->taux_com_sup_depot_cash_carte / 100);
|
|
|
|
|
$hyperviseurCommission = floatval($frais * $config->taux_com_hyp_depot_cash_carte / 100);
|
|
|
|
|
|
|
|
|
|
$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 = new \DateTime();
|
|
|
|
|
$walletAgent->save();
|
|
|
|
|
$walletSuperviseur->save();
|
|
|
|
|
$walletHyperviseur->save();
|
2020-07-03 10:58:43 +00:00
|
|
|
|
$transaction->id_transaction = $this->getTransactionID();
|
2020-06-19 19:31:32 +00:00
|
|
|
|
$transaction->save();
|
|
|
|
|
return $this->successResponse(trans('messages.successful_transaction'));
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
return $this->errorResponse(trans('errors.visa_api_failed'), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
|
|
|
}
|
2020-06-20 15:08:13 +00:00
|
|
|
|
} else {
|
2020-06-19 19:31:32 +00:00
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 17: // Agent - Envoi de cash vers cash
|
2020-07-03 10:58:43 +00:00
|
|
|
|
$this->validate($request, $transaction->cash_cash_rules());
|
2020-06-19 19:31:32 +00:00
|
|
|
|
$agent = AgentPlus::findOrFail($network_agent->agent_id);
|
2020-06-20 15:08:13 +00:00
|
|
|
|
if ($this->checkPassword($request->password, $agent->encrypted_password, $agent->salt)) {
|
2020-07-03 10:58:43 +00:00
|
|
|
|
if ($request->montant > $walletAgent->balance_princ)
|
|
|
|
|
return $this->errorResponse(trans('errors.insufficient_balance'));
|
|
|
|
|
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_agent_cash_cash, $request->montant) : $this->calculateFees($plr_agent_cash_cash_national, $request->montant);
|
|
|
|
|
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
2020-06-19 19:31:32 +00:00
|
|
|
|
$montantRetrait = $request->montant - $frais - $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
|
|
|
|
|
|
|
|
|
$configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
|
2020-07-03 19:53:34 +00:00
|
|
|
|
|
2020-07-04 10:20:26 +00:00
|
|
|
|
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->first();
|
|
|
|
|
if (isset($reseauPayeur)) {
|
|
|
|
|
$transaction->part_reseau_payeur = $frais * $reseauPayeur->taux_partage / 100;
|
|
|
|
|
$transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country);
|
|
|
|
|
$transaction->part_reseau_emetteur = $frais - $transaction->part_reseau_payeur;
|
2020-07-03 19:14:11 +00:00
|
|
|
|
$reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country;
|
2020-07-25 18:02:54 +00:00
|
|
|
|
$reseauPayeur->balance_compensation += $transaction->montant_net_final_country;
|
2020-07-04 10:20:26 +00:00
|
|
|
|
} else {
|
|
|
|
|
$transaction->part_reseau_payeur = 0;
|
|
|
|
|
$transaction->part_reseau_payeur_final_country = 0;
|
|
|
|
|
$transaction->part_reseau_emetteur = $frais;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$commisionAgent = floatval($transaction->part_reseau_emetteur * $config->taux_com_ag_envoi_cash / 100);
|
|
|
|
|
$commisionSuper = floatval($transaction->part_reseau_emetteur * $config->taux_com_sup_envoi_cash / 100);
|
|
|
|
|
$commisionHyper = floatval($transaction->part_reseau_emetteur * $config->taux_com_hyp_envoi_cash / 100);
|
2020-07-03 19:14:11 +00:00
|
|
|
|
|
|
|
|
|
if ($configPayeur->type == 'ilink') {
|
|
|
|
|
//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 dont l'id est :
|
|
|
|
|
// $transaction->id_destinataire ;
|
|
|
|
|
// et le montant est:
|
|
|
|
|
// $montantDepot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-06-19 13:48:27 +00:00
|
|
|
|
$transaction->date = new \DateTime();
|
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-07-03 10:58:43 +00:00
|
|
|
|
$transaction->id_transaction = $this->getTransactionID();
|
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),
|
|
|
|
|
'network'=> $this->getNetworkName($transaction->network_destinataire)]);
|
2020-07-03 18:24:41 +00:00
|
|
|
|
$this->sendMail($request->email_emetteur, trans('messages.successful_transaction'), $message);
|
2020-07-03 10:58:43 +00:00
|
|
|
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
2020-06-20 15:08:13 +00:00
|
|
|
|
} else {
|
2020-06-19 19:31:32 +00:00
|
|
|
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
2020-06-19 13:48:27 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 18: // Agent - Envoi de cash vers banque
|
|
|
|
|
// Indisponible
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 11:28:19 +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-07-10 11:22:51 +00:00
|
|
|
|
$wallet_user = WalletsUser::where('idUser',$user->id)->firstOrFail();
|
|
|
|
|
|
|
|
|
|
$transactions = DB::select('SELECT id_wallet_user , operation , 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-07-20 11:13:49 +00:00
|
|
|
|
ORDER BY date DESC LIMIT 10;', ['id_wallet' => $wallet_user->id]);
|
2020-07-10 11:22:51 +00:00
|
|
|
|
|
|
|
|
|
foreach ($transactions as $data){
|
|
|
|
|
$date = $data->date;
|
|
|
|
|
unset($data->date);
|
|
|
|
|
|
|
|
|
|
$user_destinataire = isset($data->id_destinataire) ? User::where('user_code',$data->id_destinataire)->first() : null ;
|
|
|
|
|
// $emetteur = $wallet_user ? $wallet_user->user->lastname.' '.$wallet_user->user->firstname : $data->prenom_emetteur . ' ' . $data->nom_emetteur;
|
|
|
|
|
$emetteur = 'Moi';
|
|
|
|
|
|
|
|
|
|
if($data->destinataire_phone){
|
|
|
|
|
$destinataire = $data->destinataire_name;
|
|
|
|
|
}else{
|
|
|
|
|
$destinataire = $data->prenom_destinataire ? $data->prenom_destinataire . ' ' . $data->nom_destinataire : $emetteur;
|
|
|
|
|
}
|
|
|
|
|
// $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);
|
|
|
|
|
$data->montant_net_final = $data->montant_net_final_country ? $this->toMoney($data->montant_net_final_country, $data->final_country) : $data->montant_net_init ;
|
|
|
|
|
$data->montant = $this->toMoney($data->montant, $data->init_country);
|
|
|
|
|
$data->init_country = $data->pays_init;
|
|
|
|
|
$data->final_country = $data->pays_final;
|
|
|
|
|
$data->reseau_payeur = isset($data->network_destinataire) ? $this->getNetworkName($data->network_destinataire).' '.$data->final_country : null;
|
|
|
|
|
$data->date = $date;
|
|
|
|
|
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);
|
|
|
|
|
}
|
2020-06-24 07:36:54 +00:00
|
|
|
|
return $this->successResponse($transactions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function lastAgentTransactions($id_wallet_agent)
|
2020-06-19 13:48:27 +00:00
|
|
|
|
{
|
2020-07-10 10:13:27 +00:00
|
|
|
|
$transactions = DB::select('SELECT wit.id_transaction, tit.nom as operation , 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
|
|
|
|
|
|
|
|
|
foreach ($transactions as $data){
|
2020-07-09 18:43:47 +00:00
|
|
|
|
$date = $data->date;
|
|
|
|
|
unset($data->date);
|
2020-07-09 18:26:05 +00:00
|
|
|
|
$wallet_user = isset($data->id_wallet_user) ? WalletsUser::findOrFail($data->id_wallet_user) : null ;
|
2020-07-10 10:13:27 +00:00
|
|
|
|
$user_destinataire = isset($data->id_destinataire) ? User::where('user_code',$data->id_destinataire)->first() : null ;
|
2020-07-09 18:26:05 +00:00
|
|
|
|
$emetteur = $wallet_user ? $wallet_user->user->lastname.' '.$wallet_user->user->firstname : $data->prenom_emetteur . ' ' . $data->nom_emetteur;
|
2020-07-10 10:13:27 +00:00
|
|
|
|
if(!$wallet_user && !$data->nom_emetteur)
|
|
|
|
|
$emetteur = $data->numero_carte;
|
2020-07-10 10:27:29 +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-07-10 10:13:27 +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);
|
|
|
|
|
$data->final_country = $this->getCountryName($data->final_country);
|
2020-07-09 18:43:47 +00:00
|
|
|
|
$data->reseau_payeur = isset($data->network_destinataire) ? $this->getNetworkName($data->network_destinataire).' '.$data->final_country : null;
|
|
|
|
|
$data->date = $date;
|
2020-07-10 10:13:27 +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);
|
2020-07-09 18:26:05 +00:00
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
|
return $this->successResponse($transactions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function calculateCommission(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$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);
|
|
|
|
|
$init_country = $walletUser->user->network->country->id;
|
|
|
|
|
$result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network')
|
|
|
|
|
->where('networks.country_id', $init_country)->where('configWallet.type', 'ilink')
|
|
|
|
|
->select('configWallet.id')->first();
|
|
|
|
|
if ($result) {
|
|
|
|
|
$config = ConfigWallet::findOrFail($result->id);
|
|
|
|
|
} else {
|
|
|
|
|
return $this->errorResponse(trans('errors.no_ilink_network'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$taxesNationales = array_values(array_filter($config->taxes->all(), function ($tax) {
|
|
|
|
|
return $tax->destination == 'national';
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$taxesInternationales = array_values(array_filter($config->taxes->all(), function ($tax) {
|
|
|
|
|
return $tax->destination == 'international';
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$plr_user_wallet_wallet = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_wallet_international");
|
|
|
|
|
$plr_user_wallet_cash = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_cash_international");
|
|
|
|
|
$plr_agent_depot_wallet_ilink = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_wallet_ilink_international");
|
|
|
|
|
$plr_agent_depot_autre_wallet = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_autre_wallet_international");
|
|
|
|
|
$plr_agent_cash_cash = $this->getPaliers($config->paliers_config_wallets->all(), "agent_cash_cash_international");
|
|
|
|
|
|
|
|
|
|
$plr_user_wallet_wallet_national = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_wallet_national");
|
|
|
|
|
$plr_user_wallet_cash_national = $this->getPaliers($config->paliers_config_wallets->all(), "user_wallet_cash_national");
|
|
|
|
|
$plr_agent_depot_wallet_ilink_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_wallet_ilink_national");
|
|
|
|
|
$plr_agent_depot_autre_wallet_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_depot_autre_wallet_national");
|
|
|
|
|
$plr_agent_cash_cash_national = $this->getPaliers($config->paliers_config_wallets->all(), "agent_cash_cash_national");
|
|
|
|
|
switch ($request->type) {
|
|
|
|
|
case 1: //User - Envoi wallet à wallet
|
|
|
|
|
$this->validate($request, [
|
|
|
|
|
'final_country' => 'required|integer|min:0|not_in:0',
|
|
|
|
|
'id_destinataire' => 'required_without:phone_destinataire'
|
|
|
|
|
]);
|
|
|
|
|
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_wallet, $request->montant) : $this->calculateFees($plr_user_wallet_wallet_national, $request->montant);
|
|
|
|
|
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
|
|
|
|
$destinataire = User::where('user_code', $request->id_destinataire)->first();
|
2020-06-25 08:01:59 +00:00
|
|
|
|
$data['destinataire'] = $destinataire ? $destinataire->lastname . ' ' . $destinataire->firstname : $request->id_destinataire;
|
2020-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais + $taxe,2);
|
|
|
|
|
$data['montant_net_init'] = round($request->montant - $data['frais'] , 2);
|
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
|
|
|
|
|
$frais = $request->montant * $config->taux_com_user_wallet_carte / 100;
|
2020-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais,2);
|
|
|
|
|
$data['montant_net'] = round($request->montant - $data['frais'],2);
|
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',
|
|
|
|
|
]);
|
|
|
|
|
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_cash, $request->montant) : $this->calculateFees($plr_user_wallet_cash_national, $request->montant);
|
|
|
|
|
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
2020-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais + $taxe,2);
|
|
|
|
|
$data['montant_net_init'] = round($request->montant - $data['frais'],2);
|
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-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais + $taxe,2);
|
|
|
|
|
$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
|
|
|
|
|
$frais = $request->montant * $config->taux_com_user_carte_wallet / 100;;
|
2020-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais,2);
|
|
|
|
|
$data['montant_net'] = round($request->montant - $data['frais'],2);
|
2020-06-30 11:06:56 +00:00
|
|
|
|
break;
|
|
|
|
|
case 11: // User - Retrait de carte vers cash
|
2020-06-30 13:09:00 +00:00
|
|
|
|
$frais = $request->montant * $config->taux_com_user_carte_cash / 100;
|
2020-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais,2);
|
|
|
|
|
$data['montant_net'] = round($request->montant - $data['frais'],2);
|
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
|
|
|
|
|
$frais = $request->montant * $config->taux_com_wallet_ag_carte_cash / 100;
|
2020-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais,2);
|
|
|
|
|
$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-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais + $taxe,2);
|
|
|
|
|
$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, $final_country);
|
|
|
|
|
break;
|
|
|
|
|
case 15: // Agent - Envoi de cash vers autre wallet
|
|
|
|
|
$this->validate($request, [
|
|
|
|
|
'final_country' => 'required|integer|min:0|not_in:0',
|
|
|
|
|
]);
|
|
|
|
|
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_agent_depot_autre_wallet, $request->montant) : $this->calculateFees($plr_agent_depot_autre_wallet_national, $request->montant);
|
2020-07-03 18:24:41 +00:00
|
|
|
|
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
2020-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais + $taxe,2);
|
|
|
|
|
$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;
|
|
|
|
|
case 16: // Agent - Envoi de cash vers une carte visa
|
|
|
|
|
$frais = $request->montant * $config->taux_com_wallet_ag_envoi_cash_carte / 100;
|
2020-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais,2);
|
|
|
|
|
$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, [
|
|
|
|
|
'final_country' => 'required|integer|min:0|not_in:0',
|
|
|
|
|
]);
|
|
|
|
|
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_agent_cash_cash, $request->montant) : $this->calculateFees($plr_agent_cash_cash_national, $request->montant);
|
|
|
|
|
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
2020-07-20 11:13:49 +00:00
|
|
|
|
$data['frais'] = round($frais + $taxe,2);
|
|
|
|
|
$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;
|
2020-06-19 13:48:27 +00:00
|
|
|
|
}
|
2020-07-08 16:51:11 +00:00
|
|
|
|
$net = isset($data['montant_net']) ? $data['montant_net'] : $data['montant_net_init'];
|
|
|
|
|
if(isset($net))
|
|
|
|
|
if($net < 0)
|
|
|
|
|
return $this->errorResponse(trans('errors.incorrect_net_amount'));
|
|
|
|
|
return $this->successResponse($data);
|
2020-06-19 13:48:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-03 18:24:41 +00:00
|
|
|
|
public function getTransactionRetrait(Request $request)
|
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
$transaction = WalletIlinkTransaction::select('nom_destinataire', 'prenom_destinataire', 'type_document_destinataire', 'id_document_destinataire', 'type','encrypted_code_retrait','code_retrait_salt',
|
2020-07-07 18:18:25 +00:00
|
|
|
|
'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-07-07 18:17:07 +00:00
|
|
|
|
if(!$this->checkPassword($request->code_retrait, $transaction->encrypted_code_retrait, $transaction->code_retrait_salt))
|
|
|
|
|
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')
|
2020-07-04 10:20:26 +00:00
|
|
|
|
return $this->errorResponse(trans('errors.withdrawal_network_unauthorized'));
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
private function getPaliers(array $paliers, $type)
|
|
|
|
|
{
|
|
|
|
|
return array_values(array_filter($paliers, function ($palier) use ($type) {
|
|
|
|
|
return $palier->type == $type;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Calcul des frais internationaux
|
|
|
|
|
private function calculateFees(array $paliers, $montant)
|
|
|
|
|
{
|
|
|
|
|
$size = sizeof($paliers);
|
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) {
|
|
|
|
|
return (($palier->min + $palier->max) / 2 * $palier->taux / 100);
|
|
|
|
|
} else {
|
|
|
|
|
if ($montant < $min)
|
|
|
|
|
return $min * $paliers[0]->taux / 100;
|
|
|
|
|
else if ($montant > $max)
|
|
|
|
|
return $max * $paliers[$size - 1]->taux / 100;
|
2020-06-19 13:48:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-25 11:43:27 +00:00
|
|
|
|
return 0;
|
2020-06-19 13:48:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Calcul des taxes
|
|
|
|
|
private function calculateTax(array $taxes, $frais)
|
|
|
|
|
{
|
|
|
|
|
$sommeTaux = 0;
|
|
|
|
|
$sommeFixe = 0;
|
|
|
|
|
foreach ($taxes as $tax) {
|
|
|
|
|
if ($tax->type == '%')
|
|
|
|
|
$sommeTaux += $tax->valeur;
|
|
|
|
|
|
|
|
|
|
if ($tax->type == 'fixe')
|
|
|
|
|
$sommeFixe += $tax->valeur;
|
|
|
|
|
}
|
|
|
|
|
return ($frais * $sommeTaux / 100) + $sommeFixe;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function random_string()
|
|
|
|
|
{
|
|
|
|
|
$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
|
|
|
|
|
|
|
|
|
private function getTransactionID(){
|
|
|
|
|
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);
|
|
|
|
|
return $code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function generateTransactionCode($length = 12) {
|
2020-07-07 19:15:30 +00:00
|
|
|
|
$characters = '23456789ABCDEFGHJKLMNOPQRSTUVWXYZ';
|
2020-07-06 16:09:25 +00:00
|
|
|
|
$charactersLength = strlen($characters);
|
|
|
|
|
$randomString = '';
|
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
|
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
|
|
|
}
|
|
|
|
|
return $randomString;
|
|
|
|
|
}
|
2020-07-17 13:48:50 +00:00
|
|
|
|
|
2020-07-25 18:02:54 +00:00
|
|
|
|
private function checkUserIdentification($id_user){
|
|
|
|
|
$identification = Identification::where('id_user', $id_user)->first();
|
|
|
|
|
if(isset($identification)) {
|
|
|
|
|
if ($identification->status == 0)
|
|
|
|
|
return $this->errorResponse(trans('errors.validation_user_identification_required'));
|
|
|
|
|
}else {
|
|
|
|
|
return $this->errorResponse(trans('errors.user_identification_required'));
|
|
|
|
|
}
|
|
|
|
|
}
|
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);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public function cancel($id_transaction)
|
|
|
|
|
{
|
|
|
|
|
$transaction = WalletIlinkTransaction::where('id_transaction',$id_transaction)->firstOrFail();
|
|
|
|
|
$transactionInverse = $transaction->replicate();
|
|
|
|
|
$transactionInverse->date = new \DateTime();
|
|
|
|
|
$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;
|
|
|
|
|
$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-06-19 13:48:27 +00:00
|
|
|
|
}
|