Setup Payout while send to external wallet
This commit is contained in:
parent
da31786a21
commit
e1504b610b
|
@ -6,6 +6,7 @@ use App\Exceptions\AppException;
|
|||
use App\Models\AgentPlus;
|
||||
use App\Models\CodeGenerer;
|
||||
use App\Models\ConfigWallet;
|
||||
use App\Models\CountriesCurrency;
|
||||
use App\Models\Country;
|
||||
use App\Models\Identification;
|
||||
use App\Models\NetworksAgent;
|
||||
|
@ -32,12 +33,7 @@ use Throwable;
|
|||
|
||||
class iLinkTransactionController extends Controller
|
||||
{
|
||||
|
||||
private $PAYMENT_URL = "/stripe/payIn";
|
||||
private $PAYOUT_URL = "/stripe/payOut";
|
||||
private $REFUND_URL = "/adyen-api/v1/transaction/refund";
|
||||
|
||||
private $PAYMENT_CHECK_STATUS = "/checkStatus";
|
||||
private $PAYING_NETWORK_SIMULATOR_SEND_FRAME_URL = 'http://localhost:8084/receive_payment';
|
||||
|
||||
/**
|
||||
|
@ -306,11 +302,21 @@ class iLinkTransactionController extends Controller
|
|||
} else {
|
||||
//Emettre requete SSL vers wallet extene correspondant pour recharger le compte du destinataire
|
||||
// La mise à jour des comissions de compensation se fera lors du traitement de la transaction
|
||||
$transaction->status_reseau_payeur = 'EN_COURS';
|
||||
$result = $this->sendFrame($this->PAYING_NETWORK_SIMULATOR_SEND_FRAME_URL, $transaction);
|
||||
if ($result->getStatusCode() != 200) {
|
||||
throw new Exception(trans('errors.unexpected_error'), 500);
|
||||
}
|
||||
$countryCurrency = CountriesCurrency::findOrFail($transaction->final_country);
|
||||
// PayOut through payment service
|
||||
$this->handlePayOut($transaction, [
|
||||
'network_name' => $reseauPayeur->network->name,
|
||||
'payment_method' => 'WALLET',
|
||||
'amount' => $transaction->montant_net_final_country,
|
||||
'currency' => $countryCurrency->currency_code,
|
||||
'customer_id' => $user->id,
|
||||
'customer_email' => $user->email,
|
||||
'customer_name' => $request->input('prenom_destinataire'),
|
||||
'customer_surname' => $request->input('nom_destinataire'),
|
||||
'customer_phone_number' => $transaction->id_destinataire,
|
||||
'customer_country' => $countryCurrency->code_country,
|
||||
'reason' => "User - Envoi de wallet à wallet"
|
||||
]);
|
||||
}
|
||||
$walletHyperviseur->balance_com += $transaction->part_reseau_emetteur;
|
||||
$walletUser->balance -= $transaction->montant;
|
||||
|
@ -360,7 +366,7 @@ class iLinkTransactionController extends Controller
|
|||
$customer_country_code = $identification ? Country::where('name', $identification->country)->first()?->code_country : $user->network->country->code_country;
|
||||
|
||||
// PayOut through payment service
|
||||
$response = $client->post($this->PAYOUT_URL, ['json' => [
|
||||
$this->handlePayOut($transaction, [
|
||||
'card_no' => $user->numero_carte,
|
||||
'exp_month' => date("m", strtotime($user->expiration_date)),
|
||||
'exp_year' => date("Y", strtotime($user->expiration_date)),
|
||||
|
@ -377,37 +383,28 @@ class iLinkTransactionController extends Controller
|
|||
'customer_city' => $identification ? $identification->town : $user->adresse,
|
||||
'customer_country' => $customer_country_code,
|
||||
'reason' => "User - Envoi de wallet à carte"
|
||||
], 'http_errors' => false]);
|
||||
]);
|
||||
|
||||
$code = $response->getStatusCode();
|
||||
$content = json_decode($response->getBody()->getContents(), true);
|
||||
if ($code == 200) {
|
||||
$response = $content["response"];
|
||||
$transaction->payment_transaction_id = $response["transaction_id"];
|
||||
$walletUser->balance -= $transaction->montant;
|
||||
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
|
||||
$transaction->commission_banque = $this->calculateFees($plr_bank_user_wallet_cart_national, $request->montant, $frais);
|
||||
$transaction->commission_hyp = $this->calculateFees($plr_hyp_user_wallet_cart_national, $request->montant, $frais);
|
||||
|
||||
$walletUser->balance -= $transaction->montant;
|
||||
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
|
||||
$transaction->commission_banque = $this->calculateFees($plr_bank_user_wallet_cart_national, $request->montant, $frais);
|
||||
$transaction->commission_hyp = $this->calculateFees($plr_hyp_user_wallet_cart_national, $request->montant, $frais);
|
||||
$walletHyperviseur->balance_com += $transaction->commission_hyp;
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->frais = $frais;
|
||||
$walletHyperviseur->save();
|
||||
$walletUser->save();
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
$transaction->date = $this->getCurrentTime($init_country);
|
||||
$transaction->save();
|
||||
$message = trans('messages.successful_user_send_to_cart',
|
||||
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
||||
'net' => $this->toMoney($montantDepot, $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);
|
||||
$response_message = $message . trans('messages.sent_by_mail');
|
||||
|
||||
$walletHyperviseur->balance_com += $transaction->commission_hyp;
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->frais = $frais;
|
||||
$walletHyperviseur->save();
|
||||
$walletUser->save();
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
$transaction->date = $this->getCurrentTime($init_country);
|
||||
$transaction->save();
|
||||
$message = trans('messages.successful_user_send_to_cart',
|
||||
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
||||
'net' => $this->toMoney($montantDepot, $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);
|
||||
$response_message = $message . trans('messages.sent_by_mail');
|
||||
|
||||
} else {
|
||||
throw new Exception($content['error'] ?? __('errors.visa_api_failed'), $content['status'] ?? 500);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3: //User - Envoi de wallet à cash
|
||||
|
@ -466,11 +463,21 @@ class iLinkTransactionController extends Controller
|
|||
} else {
|
||||
//Emettre requete SSL vers wallet extene correspondant pour recharger le compte du destinataire
|
||||
// La mise à jour des comissions de compensation se fera lors du traitement de la transaction
|
||||
$transaction->status_reseau_payeur = 'EN_COURS';
|
||||
$result = $this->sendFrame($this->PAYING_NETWORK_SIMULATOR_SEND_FRAME_URL, $transaction);
|
||||
if ($result->getStatusCode() != 200) {
|
||||
throw new Exception(trans('errors.unexpected_error'), 500);
|
||||
}
|
||||
$countryCurrency = CountriesCurrency::findOrFail($transaction->final_country);
|
||||
// PayOut through payment service
|
||||
$this->handlePayOut($transaction, [
|
||||
'network_name' => $reseauPayeur->network->name,
|
||||
'payment_method' => 'WALLET',
|
||||
'amount' => $transaction->montant_net_final_country,
|
||||
'currency' => $countryCurrency->currency_code,
|
||||
'customer_id' => $user->id,
|
||||
'customer_email' => $user->email,
|
||||
'customer_name' => $request->input('prenom_destinataire'),
|
||||
'customer_surname' => $request->input('nom_destinataire'),
|
||||
'customer_phone_number' => $transaction->id_destinataire,
|
||||
'customer_country' => $countryCurrency->code_country,
|
||||
'reason' => "User - Envoi de wallet à cash"
|
||||
]);
|
||||
}
|
||||
$walletUser->balance -= $transaction->montant;
|
||||
$walletHyperviseur->balance_com += $transaction->commission_hyp;
|
||||
|
@ -670,68 +677,48 @@ class iLinkTransactionController extends Controller
|
|||
$customer_country_code = $identification ? Country::where('name', $identification->country)->first()?->code_country : $user->network->country->code_country;
|
||||
|
||||
$payment_transaction_id = $request->input('payment_transaction_id');
|
||||
if (empty($payment_transaction_id)) {
|
||||
// PayIn through payment service
|
||||
$response = $client->post($this->PAYMENT_URL, ['json' => [
|
||||
'card_no' => $user->numero_carte,
|
||||
'exp_month' => date("m", strtotime($user->expiration_date)),
|
||||
'exp_year' => date("Y", strtotime($user->expiration_date)),
|
||||
'cvc' => $request->input('cvv'),
|
||||
'amount' => $montantRetrait,
|
||||
'currency' => $this->getCurrency($init_country),
|
||||
'payment_method' => 'CARD',
|
||||
'customer_id' => $user->id,
|
||||
'customer_email' => $user->email,
|
||||
'customer_name' => $identification ? $identification->firstname : $user->firstname,
|
||||
'customer_surname' => $identification ? $identification->lastname : $user->lastname,
|
||||
'customer_address' => $identification ? $identification->town : $user->adresse,
|
||||
'customer_city' => $identification ? $identification->town : $user->adresse,
|
||||
'customer_country' => $customer_country_code,
|
||||
'reason' => "User - Retrait de carte vers wallet"
|
||||
], 'http_errors' => false]);
|
||||
$result = $this->handlePayIn($transaction, [
|
||||
'card_no' => $user->numero_carte,
|
||||
'exp_month' => date("m", strtotime($user->expiration_date)),
|
||||
'exp_year' => date("Y", strtotime($user->expiration_date)),
|
||||
'cvc' => $request->input('cvv'),
|
||||
'amount' => $montantRetrait,
|
||||
'currency' => $this->getCurrency($init_country),
|
||||
'payment_method' => 'CARD',
|
||||
'customer_id' => $user->id,
|
||||
'customer_email' => $user->email,
|
||||
'customer_name' => $identification ? $identification->firstname : $user->firstname,
|
||||
'customer_surname' => $identification ? $identification->lastname : $user->lastname,
|
||||
'customer_address' => $identification ? $identification->town : $user->adresse,
|
||||
'customer_city' => $identification ? $identification->town : $user->adresse,
|
||||
'customer_country' => $customer_country_code,
|
||||
'reason' => "User - Retrait de carte vers wallet"
|
||||
], $payment_transaction_id);
|
||||
|
||||
} else {
|
||||
// Check payment status through payment service
|
||||
if (WalletIlinkTransaction::where('payment_transaction_id', $payment_transaction_id)->exists()) {
|
||||
throw new Exception(__('errors.transaction_already_completed'), 500);
|
||||
}
|
||||
|
||||
$response = $client->get($this->PAYMENT_CHECK_STATUS . '/' . $payment_transaction_id, ['http_errors' => false]);
|
||||
if (!($result instanceof WalletIlinkTransaction)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$code = $response->getStatusCode();
|
||||
$content = json_decode($response->getBody()->getContents(), true);
|
||||
if ($code == 301) {
|
||||
return $this->successResponse($content["response"], $content['status']);
|
||||
}
|
||||
$transaction->commission_banque = $this->calculateFees($plr_bank_user_cart_cash_national, $request->montant, $frais);
|
||||
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
|
||||
|
||||
if ($code == 200) {
|
||||
$response = $content["response"];
|
||||
$transaction->payment_transaction_id = $response["transaction_id"];
|
||||
$walletUser->balance += $transaction->montant;
|
||||
$transaction->commission_hyp = $this->calculateFees($plr_hyp_user_cart_cash_national, $request->montant, $frais);
|
||||
$walletHyperviseur->balance_com += $transaction->commission_hyp;
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->frais = $frais;
|
||||
$walletHyperviseur->save();
|
||||
$walletUser->save();
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
$transaction->date = $this->getCurrentTime($init_country);
|
||||
$transaction->save();
|
||||
$message = trans('messages.successful_user_remove_from_cart_to_wallet',
|
||||
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
||||
'total' => $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);
|
||||
$response_message = ($message . trans('messages.sent_by_mail'));
|
||||
|
||||
$transaction->commission_banque = $this->calculateFees($plr_bank_user_cart_cash_national, $request->montant, $frais);
|
||||
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
|
||||
|
||||
$walletUser->balance += $transaction->montant;
|
||||
$transaction->commission_hyp = $this->calculateFees($plr_hyp_user_cart_cash_national, $request->montant, $frais);
|
||||
$walletHyperviseur->balance_com += $transaction->commission_hyp;
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->frais = $frais;
|
||||
$walletHyperviseur->save();
|
||||
$walletUser->save();
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
$transaction->date = $this->getCurrentTime($init_country);
|
||||
$transaction->save();
|
||||
$message = trans('messages.successful_user_remove_from_cart_to_wallet',
|
||||
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
||||
'total' => $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);
|
||||
$response_message = ($message . trans('messages.sent_by_mail'));
|
||||
|
||||
} else {
|
||||
throw new Exception($content['error'] ?? __('errors.visa_api_failed'), $content['status'] ?? 500);
|
||||
}
|
||||
break;
|
||||
case 11: // User - Retrait de carte vers cash
|
||||
$this->validate($request, $transaction->user_card_rules());
|
||||
|
@ -763,72 +750,54 @@ class iLinkTransactionController extends Controller
|
|||
$customer_country_code = $identification ? Country::where('name', $identification->country)->first()?->code_country : $user->network->country->code_country;
|
||||
|
||||
$payment_transaction_id = $request->input('payment_transaction_id');
|
||||
if (empty($payment_transaction_id)) {
|
||||
$response = $client->post($this->PAYMENT_URL, ['json' => [
|
||||
'card_no' => $user->numero_carte,
|
||||
'exp_month' => date("m", strtotime($user->expiration_date)),
|
||||
'exp_year' => date("Y", strtotime($user->expiration_date)),
|
||||
'cvc' => $request->input('cvv'),
|
||||
'amount' => $montantRetrait,
|
||||
'currency' => $this->getCurrency($init_country),
|
||||
'payment_method' => 'CARD',
|
||||
'customer_id' => $user->id,
|
||||
'customer_email' => $user->email,
|
||||
'customer_name' => $identification ? $identification->firstname : $user->firstname,
|
||||
'customer_surname' => $identification ? $identification->lastname : $user->lastname,
|
||||
'customer_address' => $identification ? $identification->town : $user->adresse,
|
||||
'customer_city' => $identification ? $identification->town : $user->adresse,
|
||||
'customer_country' => $customer_country_code,
|
||||
'reason' => "User - Retrait de carte vers cash"
|
||||
], 'http_errors' => false]);
|
||||
|
||||
} else {
|
||||
// Check payment status through payment service
|
||||
if (WalletIlinkTransaction::where('payment_transaction_id', $payment_transaction_id)->exists()) {
|
||||
throw new Exception(__('errors.transaction_already_completed'), 500);
|
||||
}
|
||||
$result = $this->handlePayIn($transaction, [
|
||||
'card_no' => $user->numero_carte,
|
||||
'exp_month' => date("m", strtotime($user->expiration_date)),
|
||||
'exp_year' => date("Y", strtotime($user->expiration_date)),
|
||||
'cvc' => $request->input('cvv'),
|
||||
'amount' => $montantRetrait,
|
||||
'currency' => $this->getCurrency($init_country),
|
||||
'payment_method' => 'CARD',
|
||||
'customer_id' => $user->id,
|
||||
'customer_email' => $user->email,
|
||||
'customer_name' => $identification ? $identification->firstname : $user->firstname,
|
||||
'customer_surname' => $identification ? $identification->lastname : $user->lastname,
|
||||
'customer_address' => $identification ? $identification->town : $user->adresse,
|
||||
'customer_city' => $identification ? $identification->town : $user->adresse,
|
||||
'customer_country' => $customer_country_code,
|
||||
'reason' => "User - Retrait de carte vers cash"
|
||||
], $payment_transaction_id);
|
||||
|
||||
$response = $client->get($this->PAYMENT_CHECK_STATUS . '/' . $payment_transaction_id, ['http_errors' => false]);
|
||||
if (!($result instanceof WalletIlinkTransaction)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$code = $response->getStatusCode();
|
||||
$content = json_decode($response->getBody()->getContents(), true);
|
||||
if ($code == 301) {
|
||||
return $this->successResponse($content["response"], $content['status']);
|
||||
}
|
||||
$transaction->commission_banque = $this->calculateFees($plr_bank_user_cart_cash_national, $request->montant, $frais);
|
||||
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
|
||||
|
||||
if ($code == 200) {
|
||||
$response = $content["response"];
|
||||
$transaction->payment_transaction_id = $response["transaction_id"];
|
||||
$code_retrait = $this->random_string();
|
||||
$hash = $this->hashSSHA($code_retrait);
|
||||
$transaction->encrypted_code_retrait = $hash['encrypted'];
|
||||
$transaction->code_retrait_salt = $hash['salt'];
|
||||
|
||||
$transaction->commission_banque = $this->calculateFees($plr_bank_user_cart_cash_national, $request->montant, $frais);
|
||||
//Emettre une trame SSL pour recharger le compte de la banque partenaire du montant de sa commission
|
||||
$transaction->commission_hyp = $this->calculateFees($plr_hyp_user_cart_cash_national, $request->montant, $frais);
|
||||
$walletHyperviseur->balance_com += $transaction->commission_hyp;
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->frais = $frais;
|
||||
$transaction->date = $this->getCurrentTime($init_country);
|
||||
$transaction->status_retrait = 0;
|
||||
$walletHyperviseur->save();
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
$transaction->save();
|
||||
$message = trans('messages.successful_user_remove_from_cart_to_cash',
|
||||
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
||||
'final_country' => $this->getCountryName($init_country), 'init_country' => $this->getCountryName($init_country),
|
||||
'total' => $this->toMoney($transaction->montant, $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);
|
||||
$response_message = $message . trans('messages.sent_by_mail');
|
||||
|
||||
$code_retrait = $this->random_string();
|
||||
$hash = $this->hashSSHA($code_retrait);
|
||||
$transaction->encrypted_code_retrait = $hash['encrypted'];
|
||||
$transaction->code_retrait_salt = $hash['salt'];
|
||||
|
||||
$transaction->commission_hyp = $this->calculateFees($plr_hyp_user_cart_cash_national, $request->montant, $frais);
|
||||
$walletHyperviseur->balance_com += $transaction->commission_hyp;
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->frais = $frais;
|
||||
$transaction->date = $this->getCurrentTime($init_country);
|
||||
$transaction->status_retrait = 0;
|
||||
$walletHyperviseur->save();
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
$transaction->save();
|
||||
$message = trans('messages.successful_user_remove_from_cart_to_cash',
|
||||
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
||||
'final_country' => $this->getCountryName($init_country), 'init_country' => $this->getCountryName($init_country),
|
||||
'total' => $this->toMoney($transaction->montant, $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 {
|
||||
throw new Exception($content['error'] ?? __('errors.visa_api_failed'), $content['status'] ?? 500);
|
||||
}
|
||||
break;
|
||||
case 12: // Agent - Retrait en cash
|
||||
$this->validate($request, $transaction->remove_cash_rules());
|
||||
|
@ -952,79 +921,61 @@ class iLinkTransactionController extends Controller
|
|||
$transaction->montant_net = $montantRetrait;
|
||||
|
||||
$payment_transaction_id = $request->input('payment_transaction_id');
|
||||
if (empty($payment_transaction_id)) {
|
||||
$response = $client->post($this->PAYMENT_URL, ['json' => [
|
||||
'card_no' => $request->input('numero_carte'),
|
||||
'exp_month' => $expiration_date->format('m'),
|
||||
'exp_year' => $expiration_date->format('Y'),
|
||||
'cvc' => $request->input('cvv'),
|
||||
'amount' => $montantRetrait,
|
||||
'currency' => $this->getCurrency($init_country),
|
||||
'payment_method' => 'CARD',
|
||||
'customer_email' => $request->input('customer_email'),
|
||||
'customer_name' => $request->input('customer_name'),
|
||||
'customer_surname' => $request->input('customer_surname'),
|
||||
'customer_address' => $request->input('customer_address'),
|
||||
'customer_city' => $request->input('customer_city'),
|
||||
'customer_country' => $request->input('customer_country'),
|
||||
'customer_state' => $request->input('customer_state'),
|
||||
'customer_zip_code' => $request->input('customer_zip_code'),
|
||||
'reason' => " Agent - Retrait de la carte vers cash"
|
||||
], 'http_errors' => false]);
|
||||
} else {
|
||||
// Check payment status through payment service
|
||||
if (WalletIlinkTransaction::where('payment_transaction_id', $payment_transaction_id)->exists()) {
|
||||
throw new Exception(__('errors.transaction_already_completed'), 500);
|
||||
}
|
||||
|
||||
$response = $client->get($this->PAYMENT_CHECK_STATUS . '/' . $payment_transaction_id, ['http_errors' => false]);
|
||||
$result = $this->handlePayIn($transaction, [
|
||||
'card_no' => $request->input('numero_carte'),
|
||||
'exp_month' => $expiration_date->format('m'),
|
||||
'exp_year' => $expiration_date->format('Y'),
|
||||
'cvc' => $request->input('cvv'),
|
||||
'amount' => $montantRetrait,
|
||||
'currency' => $this->getCurrency($init_country),
|
||||
'payment_method' => 'CARD',
|
||||
'customer_email' => $request->input('customer_email'),
|
||||
'customer_name' => $request->input('customer_name'),
|
||||
'customer_surname' => $request->input('customer_surname'),
|
||||
'customer_address' => $request->input('customer_address'),
|
||||
'customer_city' => $request->input('customer_city'),
|
||||
'customer_country' => $request->input('customer_country'),
|
||||
'customer_state' => $request->input('customer_state'),
|
||||
'customer_zip_code' => $request->input('customer_zip_code'),
|
||||
'reason' => " Agent - Retrait de la carte vers cash"
|
||||
], $payment_transaction_id);
|
||||
|
||||
if (!($result instanceof WalletIlinkTransaction)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$code = $response->getStatusCode();
|
||||
$content = json_decode($response->getBody()->getContents(), true);
|
||||
if ($code == 301) {
|
||||
return $this->successResponse($content["response"], $content['status']);
|
||||
}
|
||||
$banqueCommission = $this->calculateFees($plr_bank_cart_cash_national, $request->montant, $frais);
|
||||
$transaction->commission_banque = $banqueCommission;
|
||||
// 2---> Emmètre via API sécurisé SSL une requête de débit de notre
|
||||
//compte marchand du (Part de la banque partenaire en %
|
||||
//pour le dépôt qui s’applique sur les frais minimum) et créditer
|
||||
//le compte des opérations défini avec notre banque
|
||||
//partenaire
|
||||
|
||||
if ($code == 200) {
|
||||
$response = $content["response"];
|
||||
$transaction->payment_transaction_id = $response["transaction_id"];
|
||||
$walletAgent->balance_princ += $transaction->montant;
|
||||
|
||||
$banqueCommission = $this->calculateFees($plr_bank_cart_cash_national, $request->montant, $frais);
|
||||
$transaction->commission_banque = $banqueCommission;
|
||||
// 2---> Emmètre via API sécurisé SSL une requête de débit de notre
|
||||
//compte marchand du (Part de la banque partenaire en %
|
||||
//pour le dépôt qui s’applique sur les frais minimum) et créditer
|
||||
//le compte des opérations défini avec notre banque
|
||||
//partenaire
|
||||
$agentCommission = $this->calculateFees($plr_agent_cart_cash_national, $request->montant, $frais);
|
||||
$superviseurCommission = $this->calculateFees($plr_sup_cart_cash_national, $request->montant, $frais);
|
||||
$hyperviseurCommission = $this->calculateFees($plr_hyp_cart_cash_national, $request->montant, $frais);
|
||||
|
||||
$walletAgent->balance_princ += $transaction->montant;
|
||||
|
||||
$agentCommission = $this->calculateFees($plr_agent_cart_cash_national, $request->montant, $frais);
|
||||
$superviseurCommission = $this->calculateFees($plr_sup_cart_cash_national, $request->montant, $frais);
|
||||
$hyperviseurCommission = $this->calculateFees($plr_hyp_cart_cash_national, $request->montant, $frais);
|
||||
|
||||
$walletAgent->balance_com += $agentCommission;
|
||||
$transaction->commission_ag = $agentCommission;
|
||||
$walletSuperviseur->balance_com += $superviseurCommission;
|
||||
$transaction->commission_sup = $superviseurCommission;
|
||||
$walletHyperviseur->balance_com += $hyperviseurCommission;
|
||||
$transaction->commission_hyp = $hyperviseurCommission;
|
||||
$transaction->id_wallet_ag = $walletAgent->id;
|
||||
$transaction->id_wallet_sup = $walletSuperviseur->id;
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->frais = $frais;
|
||||
$transaction->date = $this->getCurrentTime($init_country);
|
||||
$walletAgent->save();
|
||||
$walletSuperviseur->save();
|
||||
$walletHyperviseur->save();
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
$transaction->save();
|
||||
$response_message = (trans('messages.successful_transaction'));
|
||||
|
||||
} else {
|
||||
throw new Exception($content['error'] ?? __('errors.visa_api_failed'), $content['status'] ?? 500);
|
||||
}
|
||||
$walletAgent->balance_com += $agentCommission;
|
||||
$transaction->commission_ag = $agentCommission;
|
||||
$walletSuperviseur->balance_com += $superviseurCommission;
|
||||
$transaction->commission_sup = $superviseurCommission;
|
||||
$walletHyperviseur->balance_com += $hyperviseurCommission;
|
||||
$transaction->commission_hyp = $hyperviseurCommission;
|
||||
$transaction->id_wallet_ag = $walletAgent->id;
|
||||
$transaction->id_wallet_sup = $walletSuperviseur->id;
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->frais = $frais;
|
||||
$transaction->date = $this->getCurrentTime($init_country);
|
||||
$walletAgent->save();
|
||||
$walletSuperviseur->save();
|
||||
$walletHyperviseur->save();
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
$transaction->save();
|
||||
$response_message = (trans('messages.successful_transaction'));
|
||||
break;
|
||||
case 14: // Agent - Envoi de cash vers wallet iLink
|
||||
$this->validate($request, $transaction->cash_wallet_rules());
|
||||
|
@ -1186,7 +1137,7 @@ class iLinkTransactionController extends Controller
|
|||
$transaction->montant_net = $montantDepot;
|
||||
|
||||
// PayOut through payment service
|
||||
$response = $client->post($this->PAYOUT_URL, ['json' => [
|
||||
$this->handlePayOut($transaction, [
|
||||
'card_no' => $request->input('numero_carte'),
|
||||
'exp_month' => $expiration_date->format('m'),
|
||||
'exp_year' => $expiration_date->format('Y'),
|
||||
|
@ -1203,50 +1154,40 @@ class iLinkTransactionController extends Controller
|
|||
'customer_state' => $request->input('customer_state'),
|
||||
'customer_zip_code' => $request->input('customer_zip_code'),
|
||||
'reason' => "Agent - Envoi de cash vers une carte visa"
|
||||
], 'http_errors' => false]);
|
||||
]);
|
||||
|
||||
$code = $response->getStatusCode();
|
||||
$content = json_decode($response->getBody()->getContents(), true);
|
||||
$banqueCommission = $this->calculateFees($plr_bank_cash_cart_national, $request->montant, $frais);
|
||||
$transaction->commission_banque = $banqueCommission;
|
||||
// 2---> Emmètre via API sécurisé SSL une requête de débit de notre
|
||||
//compte marchand du (Part de la banque partenaire en %
|
||||
//pour le dépôtqui s’applique sur les frais minimum) et créditer
|
||||
//le compte des opérations défini avec notre banque
|
||||
//partenaire
|
||||
|
||||
if ($code == 200) {
|
||||
$response = $content["response"];
|
||||
$transaction->payment_transaction_id = $response["transaction_id"];
|
||||
$walletAgent->balance_princ -= $transaction->montant;
|
||||
|
||||
$banqueCommission = $this->calculateFees($plr_bank_cash_cart_national, $request->montant, $frais);
|
||||
$transaction->commission_banque = $banqueCommission;
|
||||
// 2---> Emmètre via API sécurisé SSL une requête de débit de notre
|
||||
//compte marchand du (Part de la banque partenaire en %
|
||||
//pour le dépôtqui s’applique sur les frais minimum) et créditer
|
||||
//le compte des opérations défini avec notre banque
|
||||
//partenaire
|
||||
$agentCommission = $this->calculateFees($plr_agent_cash_cart_national, $request->montant, $frais);
|
||||
$superviseurCommission = $this->calculateFees($plr_sup_cash_cart_national, $request->montant, $frais);
|
||||
$hyperviseurCommission = $this->calculateFees($plr_hyp_cash_cart_national, $request->montant, $frais);
|
||||
|
||||
$walletAgent->balance_princ -= $transaction->montant;
|
||||
$walletAgent->balance_com += $agentCommission;
|
||||
$transaction->commission_ag = $agentCommission;
|
||||
$walletSuperviseur->balance_com += $superviseurCommission;
|
||||
$transaction->commission_sup = $superviseurCommission;
|
||||
$walletHyperviseur->balance_com += $hyperviseurCommission;
|
||||
$transaction->commission_hyp = $hyperviseurCommission;
|
||||
$transaction->id_wallet_ag = $walletAgent->id;
|
||||
$transaction->id_wallet_sup = $walletSuperviseur->id;
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->frais = $frais;
|
||||
$transaction->date = $this->getCurrentTime($init_country);
|
||||
$walletAgent->save();
|
||||
$walletSuperviseur->save();
|
||||
$walletHyperviseur->save();
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
$transaction->save();
|
||||
$response_message = (trans('messages.successful_transaction'));
|
||||
|
||||
$agentCommission = $this->calculateFees($plr_agent_cash_cart_national, $request->montant, $frais);
|
||||
$superviseurCommission = $this->calculateFees($plr_sup_cash_cart_national, $request->montant, $frais);
|
||||
$hyperviseurCommission = $this->calculateFees($plr_hyp_cash_cart_national, $request->montant, $frais);
|
||||
|
||||
$walletAgent->balance_com += $agentCommission;
|
||||
$transaction->commission_ag = $agentCommission;
|
||||
$walletSuperviseur->balance_com += $superviseurCommission;
|
||||
$transaction->commission_sup = $superviseurCommission;
|
||||
$walletHyperviseur->balance_com += $hyperviseurCommission;
|
||||
$transaction->commission_hyp = $hyperviseurCommission;
|
||||
$transaction->id_wallet_ag = $walletAgent->id;
|
||||
$transaction->id_wallet_sup = $walletSuperviseur->id;
|
||||
$transaction->id_wallet_hyp = $walletHyperviseur->id;
|
||||
$transaction->frais = $frais;
|
||||
$transaction->date = $this->getCurrentTime($init_country);
|
||||
$walletAgent->save();
|
||||
$walletSuperviseur->save();
|
||||
$walletHyperviseur->save();
|
||||
$transaction->id_transaction = $this->getTransactionID();
|
||||
$transaction->save();
|
||||
$response_message = (trans('messages.successful_transaction'));
|
||||
|
||||
} else {
|
||||
throw new Exception($content['error'] ?? __('errors.visa_api_failed'), $content['status'] ?? 500);
|
||||
}
|
||||
break;
|
||||
case 17: // Agent - Envoi de cash vers cash
|
||||
$this->validate($request, $transaction->cash_cash_rules());
|
||||
|
@ -1309,10 +1250,22 @@ class iLinkTransactionController extends Controller
|
|||
} else {
|
||||
//Emettre requete SSL vers wallet extene correspondant pour recharger le compte du destinataire
|
||||
// La mise à jour des comissions de compensation se fera lors du traitement de la transaction
|
||||
$transaction->status_reseau_payeur = 'EN_COURS';
|
||||
$result = $this->sendFrame($this->PAYING_NETWORK_SIMULATOR_SEND_FRAME_URL, $transaction);
|
||||
if ($result->getStatusCode() != 200)
|
||||
throw new Exception(trans('errors.unexpected_error'));
|
||||
$countryCurrency = CountriesCurrency::findOrFail($transaction->final_country);
|
||||
|
||||
// PayOut through payment service
|
||||
$this->handlePayOut($transaction, [
|
||||
'network_name' => $reseauPayeur->network->name,
|
||||
'payment_method' => 'WALLET',
|
||||
'amount' => $transaction->montant_net_final_country,
|
||||
'currency' => $countryCurrency->currency_code,
|
||||
'customer_id' => $agent->id,
|
||||
'customer_email' => $agent->email,
|
||||
'customer_name' => $request->input('prenom_destinataire'),
|
||||
'customer_surname' => $request->input('nom_destinataire'),
|
||||
'customer_phone_number' => $transaction->id_destinataire,
|
||||
'customer_country' => $countryCurrency->code_country,
|
||||
'reason' => "Agent - Envoi de casg à casg"
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1709,6 +1662,73 @@ class iLinkTransactionController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function handlePayOut(WalletIlinkTransaction $transaction, $data): void
|
||||
{
|
||||
$client = new Client([
|
||||
'base_uri' => config('services.payment_service.base_uri'),
|
||||
'headers' => [
|
||||
'Authorization' => config('services.payment_service.key'),
|
||||
]
|
||||
]);
|
||||
// PayOut through payment service
|
||||
$response = $client->post('/payOut', ['json' => $data, 'http_errors' => false]);
|
||||
$code = $response->getStatusCode();
|
||||
$content = json_decode($response->getBody()->getContents(), true);
|
||||
if ($code == 200) {
|
||||
$response = $content["response"];
|
||||
$transaction->payment_transaction_id = $response["transaction_id"];
|
||||
$transaction->status_reseau_payeur = $response['transaction_status'] ?? null;
|
||||
} else {
|
||||
throw new Exception($content['error'] ?? __('errors.paying_network_api_failed'), $content['status'] ?? 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function handlePayIn(WalletIlinkTransaction $transaction, $data, $payment_transaction_id = null)
|
||||
{
|
||||
$client = new Client([
|
||||
'base_uri' => config('services.payment_service.base_uri'),
|
||||
'headers' => [
|
||||
'Authorization' => config('services.payment_service.key'),
|
||||
]
|
||||
]);
|
||||
// PayIn through payment service
|
||||
if (empty($payment_transaction_id)) {
|
||||
// PayIn through payment service
|
||||
$response = $client->post('/stripe/payIn', ['json' => $data, 'http_errors' => false]);
|
||||
|
||||
} else {
|
||||
// Check payment status through payment service
|
||||
if (WalletIlinkTransaction::where('payment_transaction_id', $payment_transaction_id)->exists()) {
|
||||
throw new Exception(__('errors.transaction_already_completed'), 500);
|
||||
}
|
||||
|
||||
$response = $client->get('/checkStatus/' . $payment_transaction_id, ['http_errors' => false]);
|
||||
}
|
||||
|
||||
$code = $response->getStatusCode();
|
||||
$content = json_decode($response->getBody()->getContents(), true);
|
||||
if ($code == 301) {
|
||||
return $this->successResponse($content["response"], $content['status']);
|
||||
}
|
||||
|
||||
if ($code == 200) {
|
||||
$response = $content["response"];
|
||||
$transaction->payment_transaction_id = $response["transaction_id"];
|
||||
} else {
|
||||
throw new Exception($content['error'] ?? __('errors.visa_api_failed'), $content['status'] ?? 500);
|
||||
}
|
||||
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
|
||||
public function lastUserTransactions($id_user)
|
||||
{
|
||||
$user = User::findOrFail($id_user);
|
||||
|
|
|
@ -86,5 +86,6 @@ Paying network : :network :country',
|
|||
"wallet_already_linked_to_bank_account" => "Your wallet is already linked to your bank account",
|
||||
"users_group_not_found" => "This group code does not exist",
|
||||
"amount_not_allowed" => "This amount is not allowed. It must be between :min and :max",
|
||||
"transaction_already_completed" => "This transaction has already been completed"
|
||||
"transaction_already_completed" => "This transaction has already been completed",
|
||||
'paying_network_api_failed' => "Request to API paying network failed",
|
||||
];
|
||||
|
|
|
@ -7,12 +7,12 @@ return [
|
|||
'invalid_cvv' => 'CVV invalide',
|
||||
'compression_failed' => 'Échec de la compression d\'image',
|
||||
'identification_carried_out' => 'Identification déjà éffectuée',
|
||||
'visa_api_failed' => 'La requete vers l\'api visa a échouée',
|
||||
'visa_api_failed' => 'La requête vers l\'api visa a échouée',
|
||||
'failed_transaction' => 'Transaction échouée',
|
||||
'user_phone_not_exist' => 'Ce numéro client n\'existe pas',
|
||||
'wallet_not_defined' => 'Ce code wallet destinataire n\'existe pas',
|
||||
'insufficient_balance' => 'Le solde est insuffisant pour effectuer cette transaction',
|
||||
'no_ilink_network' => 'Désolé , il n\'existe pas de reseau iLink World dans votre pays',
|
||||
'no_ilink_network' => 'Désolé , il n\'existe pas de réseau iLink World dans votre pays',
|
||||
'wallet_country_not_match' => 'Ce code wallet destinataire n\'est pas enregistré dans le pays :country',
|
||||
'no_bank_card_attached' => 'Aucune carte bancaire n\'est rattachée à votre compte',
|
||||
'transaction_not_exist' => 'Cette transaction n\'existe pas',
|
||||
|
@ -20,7 +20,7 @@ return [
|
|||
'invalid_withdrawal_code' => 'Code de retrait invalide',
|
||||
'incorrect_withdrawal_amount' => 'Montant de retrait incorrect',
|
||||
'operation_cannot_performed_in_country' => 'Cette operation ne peut pas etre effectuée dans ce pays',
|
||||
'withdrawal_network_unauthorized' => 'Ce retrait ne peut etre effectué dans ce reseau.
|
||||
'withdrawal_network_unauthorized' => 'Ce retrait ne peut etre effectué dans ce réseau.
|
||||
Réseau payeur : :network :country',
|
||||
'user_identification_required' => 'L\'identification de l\'utilisateur est requise pour continuer l\'operation',
|
||||
'validation_user_identification_required' => 'La validation de l\'identification de l\'utilisateur est requise pour continuer l\'operation',
|
||||
|
@ -68,13 +68,13 @@ Réseau payeur : :network :country',
|
|||
"international_weekly_regulations_limits_reached" => "Vous avez atteint votre limite hebdomadaire internationale.",
|
||||
"international_monthly_regulations_limits_reached" => "Vous avez atteint votre limite mensuelle internationale.",
|
||||
"forbidden" => "Interdit d'access",
|
||||
"request_already_processed" => "Cette requete a déja ete traitée",
|
||||
"recipient_network_not_configured" => "Ce reseau destinataire n'est pas configuré dans notre systeme",
|
||||
"recipient_network_not_authorized" => "Ce reseau destinataire n'est pas autorise à recevoir des transactions dans notre systeme",
|
||||
"request_already_processed" => "Cette requête a déja ete traitée",
|
||||
"recipient_network_not_configured" => "Ce réseau destinataire n'est pas configuré dans notre systeme",
|
||||
"recipient_network_not_authorized" => "Ce réseau destinataire n'est pas autorise à recevoir des transactions dans notre systeme",
|
||||
"bank_not_associated_with_network" => "Cette banque n'est pas associée à votre réseau",
|
||||
"transmitter_network_not_configured" => "Ce reseau emetteur n'est pas configuré dans notre systeme",
|
||||
"transmitter_network_not_authorized" => "Ce reseau emetteur n'est pas autorisé à recevoir des transactions dans notre systeme",
|
||||
"transmitter_network_not_recognized" => "Ce réseau n'est pas reconnu comme etant un réseau emetteur du reseau destinataire",
|
||||
"transmitter_network_not_configured" => "Ce réseau émetteur n'est pas configuré dans notre systeme",
|
||||
"transmitter_network_not_authorized" => "Ce réseau émetteur n'est pas autorisé à recevoir des transactions dans notre systeme",
|
||||
"transmitter_network_not_recognized" => "Ce réseau n'est pas reconnu comme etant un réseau émetteur du réseau destinataire",
|
||||
"invalid_iban" => "Le code IBAN est invalide",
|
||||
"country_not_match_iban" => "Le code IBAN ne correspond pas au pays cette banque",
|
||||
"bank_not_match_iban" => "Le code IBAN ne correspond à cette banque",
|
||||
|
@ -86,5 +86,6 @@ Réseau payeur : :network :country',
|
|||
"wallet_already_linked_to_bank_account" => "Votre wallet est déjà rattaché à votre compte bancaire",
|
||||
"users_group_not_found" => "Ce code de groupe n'existe pas",
|
||||
"amount_not_allowed" => "Ce montant n'est pas autorisé. Il doit être compris entre :min et :max",
|
||||
"transaction_already_completed" => "Cette transaction a déjà été éffectuée"
|
||||
"transaction_already_completed" => "Cette transaction a déjà été éffectuée",
|
||||
'paying_network_api_failed' => "La requête vers l'API du réseau payeur a échouée",
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue