finish whith link bank account fonctionality

This commit is contained in:
root 2026-02-03 17:28:09 +01:00
parent 666e516973
commit 6ec8bbe51b
12 changed files with 336 additions and 66 deletions

View File

@ -555,16 +555,16 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
return $this->errorResponse(trans('errors.not_banking_operator'));
//Verifier le code IBAN
$country_code = $network_bank->network->country->code_country;
$bank_code = $network_bank->operators_country->code;
switch ($this->checkIBAN($request->iban, $country_code, $bank_code)) {
case 0:
return $this->errorResponse(trans('errors.invalid_iban'));
case 1:
return $this->errorResponse(trans('errors.country_not_match_iban'));
case 2:
return $this->errorResponse(trans('errors.bank_not_match_iban'));
}
// $country_code = $network_bank->network->country->code_country;
// $bank_code = $network_bank->operators_country->code;
// switch ($this->checkIBAN($request->iban, $country_code, $bank_code)) {
// case 0:
// return $this->errorResponse(trans('errors.invalid_iban'));
// case 1:
// return $this->errorResponse(trans('errors.country_not_match_iban'));
// case 2:
// return $this->errorResponse(trans('errors.bank_not_match_iban'));
// }
$user_banking_account_verif = new UsersBankingAccountVerification();
$user_banking_account_verif->id_transaction = $this->getTransactionID();
@ -575,12 +575,12 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
$user_banking_account_verif->id_network = $request->id_wallet_network;
$user_banking_account_verif->save();
// Envoyer une requete vers la banque contant ses informations personnelles pour verfication du code iban
Log::info('-------------------------- User - Rattacher le compte bancaire au wallet --------------------------');
Log::info(json_encode(
array_merge($request->toArray(), $identification->toArray(), ['id_transaction' => $user_banking_account_verif->id_transaction])
));
Log::info('------------------------------------------------------------------------------------------------');
// // Envoyer une requete vers la banque contant ses informations personnelles pour verfication du code iban
// Log::info('-------------------------- User - Rattacher le compte bancaire au wallet --------------------------');
// Log::info(json_encode(
// array_merge($request->toArray(), $identification->toArray(), ['id_transaction' => $user_banking_account_verif->id_transaction])
// ));
// Log::info('------------------------------------------------------------------------------------------------');
return $this->successResponse(trans('messages.successful_bank_account_attachment_taken'));
}
@ -693,22 +693,22 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
return $this->errorResponse(trans('errors.not_banking_operator'));
}
$exist_user_request_create_account = UserBankAccount::where('id_user', $request->id_user)
->where('id_operator_country', $request->id_operator)
->first();
$existingAccount = UserBankAccount::where('id_user', $request->id_user)
->where('id_operator_country', $request->id_operator)
->where('customer_account_type_id', $request->account_type)
->whereIn('status', ['pending', 'actived', 'rejected', 'closed'])
->first();
if ($exist_user_request_create_account){
if ($exist_user_request_create_account->status == 'pending' && $exist_user_request_create_account->customer_account_type_id == $request->account_type) {
return $this->errorResponse(trans('errors.request_create_account_already_sended'));
if ($existingAccount) {
if ($existingAccount->status == 'actived') {
return $this->errorResponse(trans('messages.user_already_has_bank_account_with_this_operator',['user_lastname' => $user->lastname]),500);
}else{
return $this->errorResponse(trans('errors.request_create_account_already_sended'), 500);
}
}
if(isset($exist_user_request_create_account)){
if ($exist_user_request_create_account->status == 'active') {
return $this->errorResponse(trans('messages.user_already_has_bank_account_with_this_operator', ['user_lastname' => $user->lastname]));
}
}
$bank_name = $network_bank->operators_country->operator->nom;
$account_type = CustomerAccountType::where('id', $request->account_type)->first();
@ -870,14 +870,19 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
public function validateLinkUserBankAccount(Request $request)
{
$this->validate($request, [
'iban' => 'nullable|string',
'code_client' => 'required',
'iban' => 'required',
'id_transaction' => 'required'
]);
$user_bank_account_verfication = UsersBankingAccountVerification::where('id_transaction', $request->id_transaction)->first();
if (!$user_bank_account_verfication) {
return $this->errorResponse('errors.transaction_not_found', 404);
return $this->errorResponse(trans('errors.transaction_not_found'), 404);
}
$user = User::where('user_code', $user_bank_account_verfication->user_code)->firstOrFail();($user_bank_account_verfication->user_code);
if (!$user) {
return $this->errorResponse(trans('errors.user_not_found'), 404);
}
$baseUrl = env('BANK_LINK_API_BASE_URL', 'http://192.168.1.173:2087/api/v1');
@ -885,7 +890,7 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
$password = env('BANK_LINK_API_PASSWORD', 'admin');
$authApi = $baseUrl . '/auth/authenticate';
$accountApi = $baseUrl . '/account/getOne/' . $request->code_client;
$accountApi = $baseUrl . '/account/getOne/' . $request->iban;
try {
$client = new Client();
@ -899,11 +904,12 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
]);
$authResult = json_decode($authResponse->getBody(), true);
$token = $authResult['token'] ?? null;
$token = $authResult['data']['token'] ?? null;
if (!$token) {
Log::error('Token introuvable dans la réponse auth pour transaction: ' . $request->id_transaction);
return $this->errorResponse(trans('errors.token_not_found'));
return $this->errorResponse(trans('errors.token_not_found'), 404);
}
$response = $client->get($accountApi, [
@ -916,15 +922,20 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
$result = json_decode($response->getBody(), true);
if ($response->getStatusCode() == 200 || $response->getStatusCode() == 201) {
if (($response->getStatusCode() == 200 || $response->getStatusCode() <= 301) && ($result['data']['accountID'] == $user_bank_account_verfication->iban)) {
$user_bank_account_verfication->update([
'is_verified' => 1,
'was_traited' => 1
'was_treated' => 1
]);
Log::info('Compte bancaire rattaché avec succès pour transaction: ' . $request->id_transaction);
return $this->successResponse(trans('messages.create_bank_account_linked_successfully'), $result);
try {
// Mail::to($user->email)->send(new BankAccountLinked($user_bank_account_verfication));
} catch (\Exception $e) {
Log::error("Mail error: " . $e->getMessage());
}
return $this->successResponse(trans('messages.create_bank_account_linked_successfully'), 200);
}
} catch (RequestException $e) {
@ -940,7 +951,7 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
return $this->errorResponse(trans('errors.Error_occurred'));
} catch (\Exception $e) {
Log::error('Erreur inattendue Bank Link : ' . $e->getMessage());
return $this->errorResponse('Internal Server Error');
return $this->errorResponse(trans('errors.Error_occurred'));
}
}
}

2
app/Mail/BankAccountActivated.php Normal file → Executable file
View File

@ -22,7 +22,7 @@ class BankAccountActivated extends Mailable
public function build()
{
return $this->subject('Votre compte bancaire a été activé')
return $this->subject(trans('emails.account_activated_subject'))
->view('emails.bank_account_activated');
}
}

View File

@ -34,7 +34,7 @@ class BankAccountCreatedMail extends Mailable
*/
public function build()
{
return $this->subject('Création de compte bancaire en attente de validation')
return $this->subject(trans('emails.account_created_subject'))
->view('emails.bank_account_created')
->with(['bankAccount' => $this->bankAccount, 'bank_name' => $this->bank_name, 'user' => $this->user]);
}

View File

@ -0,0 +1,42 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use App\Models\UsersBankingAccountVerification;
class BankAccountLinked extends Mailable
{
use Queueable, SerializesModels;
/**
* L'instance de la vérification contenant les infos (iban, user_code).
*
* @var UsersBankingAccountVerification
*/
public $verification;
/**
* Create a new message instance.
*
* @param UsersBankingAccountVerification $verification
*/
public function __construct(UsersBankingAccountVerification $verification)
{
$this->verification = $verification;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject(trans('emails.bank_linked_subject'))
->view('emails.bank_account_linked');
}
}

View File

@ -0,0 +1,42 @@
<?php
return [
'bank_linked_subject' => 'Bank Account Linking Confirmation',
'bank_linked_title' => 'Bank Linking Confirmed',
'greeting' => 'Hello,',
'bank_linked_body' => 'We are pleased to inform you that your bank account linking request has been successfully validated.',
'bank_linked_details' => 'Here are your linking details:',
'label_user_code' => 'Your Wallet Code (User Code)',
'label_iban' => 'Account Number / IBAN',
'bank_linked_footer' => 'You can now perform transactions between your bank account and your digital wallet.',
'automated_msg' => 'This email is generated automatically, please do not reply.',
// ACCOUNT ACTIVATION
'account_activated_subject' => 'Your bank account has been activated',
'account_activated_title' => 'Account Activation Successful',
'congratulations' => 'Congratulations',
'account_activated_body' => 'Your account opening request has been accepted and validated by our services.',
'account_activated_footer' => 'You can start using our banking services right now.',
// ACCOUNT CREATION (PENDING)
'account_created_subject' => 'Bank account creation pending validation',
'account_created_title' => 'Opening Request Received',
'account_created_body' => 'Your bank account creation request has been successfully recorded.',
'account_created_footer' => 'We will notify you as soon as the account is validated by our agents.',
// COMMON LABELS
'label_account_number' => 'Account Number',
'label_customer_code' => 'Customer Code',
'label_account_type' => 'Account Type',
'label_bank_name' => 'Bank',
'label_status' => 'Status',
'status_active' => 'Active',
// SIGNATURE & FOOTER
'regards' => 'Regards,',
'team_signature' => 'The Team',
'company_name' => 'SunEx by Ilink World Corporation',
'automated_msg' => 'This email is generated automatically, please do not reply.',
'all_rights' => 'All rights reserved.',
];

View File

@ -322,7 +322,7 @@ Transaction Information:
- Recipient's names : :receiver_name
- IBAN of the recipient : :iban
- Bank : :bank :country",
'successful_bank_account_attachment_taken' => 'Your request to link your bank account has been taken into account, you will receive a confirmation email as soon as the bank has validated your IBAN code',
'successful_bank_account_attachment_taken' => 'Your request to link your bank account has been taken into account, you will receive a confirmation email as soon as the bank has validated your account number.',
'successful_user_remove_from_cart_to_other_wallet' => "Withdraw money from your card to another account
Transaction information :
- Number: :id_transaction

View File

@ -0,0 +1,41 @@
<?php
return [
'bank_linked_subject' => 'Confirmation de rattachement de compte bancaire',
'bank_linked_title' => 'Rattachement Bancaire Confirmé',
'greeting' => 'Bonjour,',
'bank_linked_body' => 'Nous avons le plaisir de vous informer que votre demande de rattachement de compte bancaire a été validée avec succès.',
'bank_linked_details' => 'Voici les détails de votre liaison :',
'label_user_code' => 'Votre Code Wallet (User Code)',
'label_iban' => 'Numéro de Compte / IBAN',
'bank_linked_footer' => 'Vous pouvez dès à présent effectuer des opérations entre votre compte bancaire et votre portefeuille numérique.',
'automated_msg' => 'Cet email est généré automatiquement, merci de ne pas y répondre.',
// ACTIVATION COMPTE
'account_activated_subject' => 'Votre compte bancaire a été activé',
'account_activated_title' => 'Activation de Compte Réussie',
'congratulations' => 'Félicitations',
'account_activated_body' => 'Votre demande d\'ouverture de compte a été acceptée et validée par nos services.',
'account_activated_footer' => 'Vous pouvez utiliser nos services bancaires dès maintenant.',
// CRÉATION COMPTE (PENDING)
'account_created_subject' => 'Création de compte bancaire en attente de validation',
'account_created_title' => 'Demande d\'Ouverture Reçue',
'account_created_body' => 'Votre demande de création de compte bancaire a été enregistrée avec succès.',
'account_created_footer' => 'Nous vous informerons dès que le compte sera validé par nos agents.',
// LABELS COMMUNS
'label_account_number' => 'Numéro de compte',
'label_customer_code' => 'Code client',
'label_account_type' => 'Type de compte',
'label_bank_name' => 'Banque',
'label_status' => 'Statut',
'status_active' => 'Activé',
// SIGNATURE & FOOTER
'regards' => 'Cordialement,',
'team_signature' => 'L\'équipe',
'company_name' => 'SunEx by Ilink World Corporation',
'automated_msg' => 'Cet email est généré automatiquement, merci de ne pas y répondre.',
'all_rights' => 'Tous droits réservés.',
];

View File

@ -323,7 +323,7 @@ Informations de la transaction :
- Noms du destinataire : :receiver_name
- IBAN du destinataire : :iban
- Banque : :bank :country",
'successful_bank_account_attachment_taken' => 'Votre requête de rattachement de votre compte bancaire a été prise en compte, vous recevrez un mail de confirmation dès lors que la banque aura validé votre code IBAN.',
'successful_bank_account_attachment_taken' => 'Votre requête de rattachement de votre compte bancaire a été prise en compte, vous recevrez un mail de confirmation dès lors que la banque aura validé votre numéro de compte.',
'successful_user_remove_from_cart_to_other_wallet' => "Retrait d'argent de votre carte vers un autre compte
Informations de la transaction :
- Numéro : :id_transaction

62
resources/views/emails/bank_account_activated.blade.php Normal file → Executable file
View File

@ -1,21 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>Activation de compte</title>
<title>{{ __('emails.account_activated_title') }}</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { width: 100%; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #ddd; border-radius: 5px; }
.header { background-color: #f8f9fa; padding: 10px; text-align: center; border-bottom: 1px solid #ddd; }
.content { padding: 20px 0; }
.info-box { background-color: #e9ecef; padding: 15px; border-radius: 4px; margin: 10px 0; }
.footer { font-size: 12px; color: #777; text-align: center; margin-top: 20px; border-top: 1px solid #ddd; padding-top: 10px; }
.label { font-weight: bold; color: #555; }
.brand-name { color: #003366; font-weight: bold; } /* Bleu foncé gras */
</style>
</head>
<body>
<h1>Félicitations {{ $bankAccount->user->firstname }} !</h1>
<p>Votre demande d'ouverture de compte a été acceptée et activée.</p>
<div class="container">
<div class="header">
<h2>{{ __('emails.account_activated_title') }}</h2>
</div>
<ul>
<li><strong>Numéro de compte :</strong> {{ $bankAccount->account_number }}</li>
<li><strong>Code client :</strong> {{ $bankAccount->customer_number }}</li>
<li><strong>Type de compte :</strong> {{ $bankName }}</li>
<li><strong>Statut :</strong> Activé</li>
</ul>
<div class="content">
<!-- Salutation -->
<h3>{{ __('emails.congratulations') }} {{ $bankAccount->user->firstname }} !</h3>
<p>Vous pouvez désormais utiliser nos services bancaires dès maintenant.</p>
<p>{{ __('emails.account_activated_body') }}</p>
<p>Cordialement,<br>L'équipe SunEx.</p>
<div class="info-box">
<p>
<span class="label">{{ __('emails.label_account_number') }} :</span>
{{ $bankAccount->account_number }}
</p>
<p>
<span class="label">{{ __('emails.label_customer_code') }} :</span>
{{ $bankAccount->customer_number }}
</p>
<p>
<span class="label">{{ __('emails.label_account_type') }} :</span>
{{ $bankName }}
</p>
<p>
<span class="label">{{ __('emails.label_status') }} :</span>
<span style="color: green; font-weight: bold;">{{ __('emails.status_active') }}</span>
</p>
</div>
<p>{{ __('emails.account_activated_footer') }}</p>
<p>
{{ __('emails.regards') }}<br>
{{ __('emails.team_signature') }} <span class="brand-name">{{ __('emails.company_name') }}</span>.
</p>
</div>
<div class="footer">
<p>{{ __('emails.automated_msg') }}</p>
<p>&copy; {{ date('Y') }} <span class="brand-name">{{ __('emails.company_name') }}</span>. {{ __('emails.all_rights') }}</p>
</div>
</div>
</body>
</html>

View File

@ -1,11 +1,53 @@
<!DOCTYPE html>
<html lang="fr">
<html>
<head>
<title>{{ __('emails.account_created_title') }}</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { width: 100%; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #ddd; border-radius: 5px; }
.header { background-color: #f8f9fa; padding: 10px; text-align: center; border-bottom: 1px solid #ddd; }
.content { padding: 20px 0; }
.info-box { background-color: #e9ecef; padding: 15px; border-radius: 4px; margin: 10px 0; }
.footer { font-size: 12px; color: #777; text-align: center; margin-top: 20px; border-top: 1px solid #ddd; padding-top: 10px; }
.label { font-weight: bold; color: #555; }
.brand-name { color: #003366; font-weight: bold; } /* Bleu foncé gras */
</style>
</head>
<body>
<h2>Bonjour {{ $user->lastname ?? '' }},</h2>
<p>Votre demande de création de compte bancaire a été enregistrée avec succès.</p>
<p><strong>Banque :</strong> {{ $bank_name }}</p>
<p><strong>Statut :</strong> {{ ucfirst($bankAccount->status) }}</p>
<p>Nous vous informerons dès que le compte sera validé.</p>
<p>Merci,<br>Léquipe SunEx by iLink World</p>
<div class="container">
<div class="header">
<h2>{{ __('emails.account_created_title') }}</h2>
</div>
<div class="content">
<!-- Salutation -->
<h3>{{ __('emails.greeting') }} {{ $user->lastname ?? '' }},</h3>
<p>{{ __('emails.account_created_body') }}</p>
<div class="info-box">
<p>
<span class="label">{{ __('emails.label_bank_name') }} :</span>
{{ $bank_name }}
</p>
<p>
<span class="label">{{ __('emails.label_status') }} :</span>
{{ ucfirst($bankAccount->status) }}
</p>
</div>
<p>{{ __('emails.account_created_footer') }}</p>
<p>
{{ __('emails.regards') }}<br>
{{ __('emails.team_signature') }} <span class="brand-name">{{ __('emails.company_name') }}</span>.
</p>
</div>
<div class="footer">
<p>{{ __('emails.automated_msg') }}</p>
<p>&copy; {{ date('Y') }} <span class="brand-name">{{ __('emails.company_name') }}</span>. {{ __('emails.all_rights') }}</p>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ __('emails.bank_linked_title') }}</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { width: 100%; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #ddd; border-radius: 5px; }
.header { background-color: #f8f9fa; padding: 10px; text-align: center; border-bottom: 1px solid #ddd; }
.content { padding: 20px 0; }
.info-box { background-color: #e9ecef; padding: 15px; border-radius: 4px; margin: 10px 0; }
.footer { font-size: 12px; color: #777; text-align: center; margin-top: 20px; border-top: 1px solid #ddd; padding-top: 10px; }
.label { font-weight: bold; color: #555; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>{{ __('emails.bank_linked_title') }}</h2>
</div>
<div class="content">
<p>{{ __('emails.greeting') }}</p>
<p>{{ __('emails.bank_linked_body') }}</p>
<p>{{ __('emails.bank_linked_details') }}</p>
<div class="info-box">
<!-- Affichage des variables dynamiques -->
<p>
<span class="label">{{ __('emails.label_user_code') }} :</span>
{{ $verification->user_code }}
</p>
<p>
<span class="label">{{ __('emails.label_iban') }} :</span>
{{ $verification->iban }}
</p>
</div>
<p>{{ __('emails.bank_linked_footer') }}</p>
</div>
<div class="footer">
<p>{{ __('emails.automated_msg') }}</p>
<p>&copy; {{ date('Y') }} <span class="brand-name">{{ __('emails.company_name') }}</span>. {{ __('emails.all_rights') }}</p>
</div>
</div>
</body>
</html>

View File

@ -67,16 +67,19 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
// Wallets users iLink
$router->group(['prefix' => '/users'], function () use ($router) {
$router->get('{id_user}', 'WalletController@showWalletUser');
//Liste des operateurs
$router->get('operators/{type}/{id_wallet_network}', 'WalletController@getWalletOperators');
$router->get('banks_for_link/{id_wallet_network}', 'WalletController@getBanksInNetworkForLink');
$router->post('link_bank_account', 'WalletController@linkBankAccount');
//Creation d'un compte bancaire (Agency Banking)
$router->post('create_user_bank_account', 'WalletController@createUserBankAccount');
$router->post('activate_user_bank_account', 'WalletController@activateUserBankAccount');
$router->get('customer_account_type', 'WalletController@getCustomerAccountTypes');
$router->post('validate_link_user_bank_account', 'WalletController@validateLinkUserBankAccount');
$router->get('{id_user}', 'WalletController@showWalletUser');
//Liste des operateurs
$router->get('operators/{type}/{id_wallet_network}', 'WalletController@getWalletOperators');
$router->get('banks_for_link/{id_wallet_network}', 'WalletController@getBanksInNetworkForLink');
$router->post('link_bank_account', 'WalletController@linkBankAccount');
});
});