+ Fix bug on Wallet to wallet
This commit is contained in:
parent
9c86ac281d
commit
5d29d3e6b2
|
@ -128,8 +128,8 @@ class iLinkTransactionController extends Controller
|
|||
$transaction->taxe = $taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
||||
$transaction->montant_net = $montantDepot = $transaction->montant - $frais - $taxe;
|
||||
$configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
|
||||
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->firstOrFail();
|
||||
if ($init_country != $request->final_country) {
|
||||
$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;
|
||||
} else {
|
||||
|
@ -139,7 +139,8 @@ class iLinkTransactionController extends Controller
|
|||
$transaction->montant_net_final_country = $this->toMoneyAmount($montantDepot, $init_country, $request->final_country);
|
||||
$transaction->commission_hyp = $transaction->part_reseau_emetteur;
|
||||
$transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country);
|
||||
$reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country;
|
||||
if(isset($reseauPayeur))
|
||||
$reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country;
|
||||
if ($configPayeur->type == 'ilink') {
|
||||
$destinataire = User::where('user_code', $request->id_destinataire)->first();
|
||||
if ($destinataire) { // Si c'est un wallet ilink
|
||||
|
@ -158,7 +159,6 @@ class iLinkTransactionController extends Controller
|
|||
$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
|
||||
$walletHyperviseur->balance_com += $transaction->part_reseau_payeur;
|
||||
$reseauPayeur->balance_com += $this->toMoneyAmount($transaction->part_reseau_emetteur, $init_country, $request->final_country);
|
||||
$transaction->id_wallet_hyp_payeur = $walletHyperviseur->id;
|
||||
} else {
|
||||
$wallet_agent_hypPayeur = WalletAgent::where('agent_id', $hyperviseurPayeur->id)->firstOrFail();
|
||||
|
@ -180,7 +180,8 @@ class iLinkTransactionController extends Controller
|
|||
|
||||
$walletHyperviseur->save();
|
||||
$walletUser->save();
|
||||
$reseauPayeur->save();
|
||||
if(isset($reseauPayeur))
|
||||
$reseauPayeur->save();
|
||||
$transaction->save();
|
||||
$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),
|
||||
|
@ -254,8 +255,8 @@ class iLinkTransactionController extends Controller
|
|||
$transaction->taxe = $taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
||||
$transaction->montant_net = $montantRetrait = $transaction->montant - $frais - $taxe;
|
||||
$configPayeur = ConfigWallet::where('id_network', $request->network_destinataire)->firstOrFail();
|
||||
$reseauPayeur = PayingNetwork::where('id_network', $request->network_destinataire)->where('id_configWallet', $config->id)->firstOrFail();
|
||||
if ($init_country != $request->final_country) {
|
||||
$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;
|
||||
} else {
|
||||
|
@ -265,13 +266,13 @@ class iLinkTransactionController extends Controller
|
|||
$transaction->montant_net_final_country = $this->toMoneyAmount($montantRetrait, $init_country, $request->final_country);
|
||||
$transaction->commission_hyp = $transaction->part_reseau_emetteur;
|
||||
$transaction->part_reseau_payeur_final_country = $this->toMoneyAmount($transaction->part_reseau_payeur, $init_country, $request->final_country);
|
||||
$reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country;
|
||||
if(isset($reseauPayeur))
|
||||
$reseauPayeur->balance_com += $transaction->part_reseau_payeur_final_country;
|
||||
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
|
||||
$walletHyperviseur->balance_com += $transaction->part_reseau_payeur;
|
||||
$reseauPayeur->balance_com += $this->toMoneyAmount($transaction->part_reseau_emetteur, $init_country, $request->final_country);
|
||||
$transaction->id_wallet_hyp_payeur = $walletHyperviseur->id;
|
||||
} else {
|
||||
$wallet_agent_hypPayeur = WalletAgent::where('agent_id', $hyperviseurPayeur->id)->firstOrFail();
|
||||
|
@ -295,8 +296,8 @@ class iLinkTransactionController extends Controller
|
|||
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
|
||||
$reseauPayeur->save();
|
||||
if(isset($reseauPayeur))
|
||||
$reseauPayeur->save();
|
||||
$walletHyperviseur->save();
|
||||
$walletUser->save();
|
||||
$transaction->date = new \DateTime();
|
||||
|
@ -327,10 +328,94 @@ class iLinkTransactionController extends Controller
|
|||
//// $taxe = ($init_country != $final_country) ? $this->calculateTax($taxesInternationales , $frais) : $this->calculateTax($taxesNationales ,$frais);
|
||||
// break;
|
||||
case 9: // User - Retrait de wallet en cash
|
||||
$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 {
|
||||
$transaction->frais = $frais = $this->calculateFees($plr_user_wallet_cash_national, $request->montant);
|
||||
$transaction->taxe = $taxe = $this->calculateTax($taxesNationales, $frais);
|
||||
$transaction->montant_net = $montantRetrait = $transaction->montant - $frais - $taxe;
|
||||
$transaction->commission_hyp = $frais;
|
||||
|
||||
$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();
|
||||
|
||||
$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),
|
||||
'fees' => $this->toMoney($frais + $taxe, $init_country), 'code' => wordwrap($code_retrait, 4, ' ', true),
|
||||
'sender_code' => $user->user_code]);
|
||||
$this->sendMail($user->email, trans('messages.successful_transaction'),$message );
|
||||
return $this->successResponse($message.trans('messages.sent_by_mail'));
|
||||
}
|
||||
}else{
|
||||
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
||||
|
||||
}
|
||||
break;
|
||||
case 10: //User - Retrait de carte vers wallet
|
||||
$this->validate($request, $transaction->card_rules());
|
||||
$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 {
|
||||
$expiration_date = \DateTime::createFromFormat('m/y', $request->expiration_date);
|
||||
if (!$expiration_date)
|
||||
$expiration_date = new \DateTime();
|
||||
$transaction->expiration_date = $expiration_date;
|
||||
|
||||
$frais = $request->montant * $config->taux_com_user_carte_wallet / 100;
|
||||
|
||||
$transaction->montant_net = $montantRetrait = $transaction->montant - $frais;
|
||||
$body['amount'] = $this->toUSDAmount($montantRetrait,$init_country);
|
||||
$body['card_number'] = $request->numero_carte;
|
||||
$body['cvv'] = $request->cvv;
|
||||
$body['expiry_date'] = $expiration_date->format('Y-m');
|
||||
|
||||
$response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]);
|
||||
$code = $response->getStatusCode();
|
||||
|
||||
if ($code == 200) {
|
||||
$walletUser->balance -= $transaction->montant;
|
||||
$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
|
||||
|
||||
$walletHyperviseur->balance_com += $frais;
|
||||
$transaction->commission_hyp = $frais * $config->taux_com_hyp_retrait_carte_cash_ilink / 100 ;
|
||||
$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($request->numero_carte, 4, ' ', true)]);
|
||||
$this->sendMail($user->email, trans('messages.successful_transaction'), $message);
|
||||
return $this->successResponse($message.trans('messages.sent_by_mail'));
|
||||
|
||||
} else {
|
||||
return $this->errorResponse(trans('errors.visa_api_failed'), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
||||
}
|
||||
break;
|
||||
case 11: // User - Retrait de carte vers cash
|
||||
|
||||
|
|
|
@ -103,6 +103,34 @@ trait Helper
|
|||
return $this->convertMoney($amount , $init_country , $final_country)->getAmount()->toFloat();
|
||||
}
|
||||
|
||||
public function toUSDAmount($amount , $init_country , $final_currency_code = 'USD'){
|
||||
// set to whatever your rates are relative to
|
||||
$baseCurrency = 'USD';
|
||||
|
||||
// use your own credentials, or re-use your existing PDO connection
|
||||
$pdo = new PDO('mysql:host=' .env('DB_HOST') . ';dbname=' .env('DB_DATABASE'), env('DB_USERNAME'), env('DB_PASSWORD'));
|
||||
|
||||
$configuration = new PDOProviderConfiguration();
|
||||
|
||||
$configuration->tableName = 'exchange_rate';
|
||||
$configuration->exchangeRateColumnName = 'exchange_rate';
|
||||
$configuration->targetCurrencyColumnName = 'target_currency';
|
||||
$configuration->sourceCurrencyCode = $baseCurrency;
|
||||
|
||||
// this provider loads exchange rates from your database
|
||||
$provider = new PDOProvider($pdo, $configuration);
|
||||
|
||||
// this provider calculates exchange rates relative to the base currency
|
||||
$provider = new BaseCurrencyProvider($provider, $baseCurrency);
|
||||
|
||||
// this currency converter can now handle any currency pair
|
||||
$converter = new CurrencyConverter($provider);
|
||||
$init_country = Country::findOrFail($init_country);
|
||||
$init_money = Money::of(round($amount, 2),$init_country->currency->code,new AutoContext());
|
||||
return $converter->convert($init_money, $final_currency_code, RoundingMode::DOWN)->getAmount()->toFloat();
|
||||
}
|
||||
|
||||
|
||||
public function getTransactionID(){
|
||||
$d = new DateTime();
|
||||
$first = str_replace(['-',':'], '',$d->format("y-m-d H:i:s.u"));
|
||||
|
|
|
@ -79,4 +79,20 @@ Transaction information :
|
|||
- Issuer account: :sender_code
|
||||
- Recipient names: :receiver_name.
|
||||
- Withdrawal code: :code ',
|
||||
'successful_user_remove_from_wallet_to_cash'=>'Personal money withdrawal
|
||||
Transaction information:
|
||||
- Number : :id_transaction
|
||||
- Amount of the transaction : :amount
|
||||
- Fees and Taxes: :fees
|
||||
- Net withdrawal amount : :net
|
||||
- Issuer account : :sender_code
|
||||
- Withdrawal code : :code',
|
||||
'successful_user_remove_from_cart_to_wallet'=>'Withdrawing money from card to account
|
||||
Transaction information:
|
||||
- Number : :id_transaction
|
||||
- Amount of the transaction : :amount
|
||||
- Fees : :fees
|
||||
- Net withdrawal amount : :net
|
||||
- Recipient account : :sender_code
|
||||
- Recipient\'s card number : :cart_number',
|
||||
];
|
||||
|
|
|
@ -79,4 +79,20 @@ Informations de la transaction :
|
|||
- Compte émetteur : :sender_code
|
||||
- Noms du destinataire : :receiver_name.
|
||||
- Code de retrait : :code',
|
||||
'successful_user_remove_from_wallet_to_cash'=>'Retrait d\'argent personnel
|
||||
Informations de la transaction :
|
||||
- Numéro : :id_transaction
|
||||
- Montant de la transaction : :amount
|
||||
- Frais et Taxes: :fees
|
||||
- Montant net de retrait: :net
|
||||
- Compte émetteur : :sender_code
|
||||
- Code de retrait : :code',
|
||||
'successful_user_remove_from_cart_to_wallet'=>'Retrait d\'argent de la carte vers le compte
|
||||
Informations de la transaction :
|
||||
- Numéro : :id_transaction
|
||||
- Montant de la transaction : :amount
|
||||
- Frais : :fees
|
||||
- Montant net de retrait: :net
|
||||
- Compte destinataire : :sender_code
|
||||
- Numero de la carte du destinataire : :cart_number',
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue