finish with the integration of create user account fonction
This commit is contained in:
parent
b14dbedf8f
commit
666e516973
11
.env.example
11
.env.example
|
|
@ -48,3 +48,14 @@ SWAGGER_DOCS_TOKEN=ZfMqCAdHHrSH8ADdXreIejgjJtOwsH4K
|
|||
|
||||
SENTRY_LARAVEL_DSN=https://9d6f6b6a24514295910a3b0e5bdd1449@o1053292.ingest.sentry.io/4504848762863616
|
||||
SENTRY_TRACES_SAMPLE_RATE=1
|
||||
|
||||
# Configuration API GBS
|
||||
BANK_API_BASE_URL=http://192.168.1.173:8084/api/v1
|
||||
BANK_API_USERNAME=sa
|
||||
BANK_API_PASSWORD=Sa123456
|
||||
BANK_API_BRANCH_CODE=99001
|
||||
# Configuration API Bank Link
|
||||
BANK_LINK_API_BASE_URL=http://192.168.1.173:2087/api/v1
|
||||
BANK_LINK_API_LOGIN=admin
|
||||
BANK_LINK_API_PASSWORD=admin
|
||||
|
||||
|
|
|
|||
|
|
@ -473,7 +473,8 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
|||
{
|
||||
$id_country = Network::findOrFail($id_wallet_network)->country->id;
|
||||
$banks = DB::select("SELECT oc.id as id_bank, o.nom as bank_name , oc.adresse as bank_address, c.name as country FROM networks_operators nop INNER JOIN operators_countries oc ON oc.id = nop.id_operator_country INNER JOIN operators o ON o.id = oc.id_operator
|
||||
INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON o.type = top.code WHERE nop.id_network = :id_network AND o.type LIKE '%bank%' AND oc.id_country = :id_country ;", ['id_network' => $id_wallet_network, 'id_country' => $id_country]);
|
||||
INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
||||
o.type = top.code WHERE nop.id_network = :id_network AND o.type LIKE '%bank%' AND oc.id_country = :id_country ;", ['id_network' => $id_wallet_network, 'id_country' => $id_country]);
|
||||
|
||||
return $this->successResponse($banks);
|
||||
}
|
||||
|
|
@ -696,22 +697,23 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
|||
->where('id_operator_country', $request->id_operator)
|
||||
->first();
|
||||
|
||||
if (isset($exist_user_request_create_account)){
|
||||
if ($exist_user_request_create_account->status == 'pending') {
|
||||
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(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('product', $request->account_type)->first();
|
||||
$account_type = CustomerAccountType::where('id', $request->account_type)->first();
|
||||
|
||||
if (!$account_type) {
|
||||
return $this->errorResponse(trans('errors.invalid_account_type'));
|
||||
return $this->errorResponse(trans('errors.account_type_not_found'));
|
||||
}
|
||||
|
||||
$bankAccount = new UserBankAccount();
|
||||
|
|
@ -747,7 +749,7 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
|||
Log::info('Demande de creation de compte bancaire enregistree avec succes');
|
||||
|
||||
// Envoi de notification par email
|
||||
Mail::to($user->email)->send(new BankAccountCreatedMail($bankAccount, $bank_name, $user));
|
||||
// Mail::to($user->email)->send(new BankAccountCreatedMail($bankAccount, $bank_name, $user));
|
||||
Log::info('Mail envoye a l’utilisateur : ' . $user->email);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
|
@ -772,26 +774,40 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
|||
]);
|
||||
|
||||
$bank_account = UserBankAccount::where('id', $request->id)->with('user')->first();
|
||||
$user = $bank_account->user;
|
||||
|
||||
if (!$bank_account) {
|
||||
return $this->errorResponse(trans('errors.account_type_not_found'));
|
||||
}
|
||||
|
||||
$user = $bank_account->user;
|
||||
$account_type = CustomerAccountType::where('id', $bank_account->customer_account_type_id)->first();
|
||||
if(!$user){
|
||||
return $this->errorResponse(trans('errors.user_not_found'));
|
||||
}
|
||||
|
||||
$apiUrl = "http://192.168.1.173:8084/api/v1/clients/create-with-account";
|
||||
$account_type = CustomerAccountType::where('id', $bank_account->customer_account_type_id)->first();
|
||||
if (!$account_type) {
|
||||
return $this->errorResponse(trans('errors.account_type_not_found'));
|
||||
}
|
||||
$name_of_account_type = $account_type->name;
|
||||
|
||||
// --- Récupération des configurations depuis le .env ---
|
||||
$baseUrl = env('BANK_API_BASE_URL', 'http://192.168.1.173:8084/api/v1');
|
||||
$username = env('BANK_API_USERNAME', 'sa');
|
||||
$password = env('BANK_API_PASSWORD', 'Sa123456');
|
||||
$branchCode = env('BANK_API_BRANCH_CODE', '99001');
|
||||
|
||||
$apiUrl = $baseUrl . '/clients/create-with-account';
|
||||
|
||||
$payload = [
|
||||
'phoneNumber' => $bank_account->phone_number ?? ($user->phone ?? ''),
|
||||
'email' => $user->email ?? '',
|
||||
'fullname' => $bank_account->firstname . ' ' . $bank_account->lastname,
|
||||
'branchCode' => '99001',
|
||||
'branchCode' => $branchCode,
|
||||
'dateOfBirth' => $bank_account->birth_date,
|
||||
'isMarried' => ($bank_account->marital_status === 'marie') ? 'Yes' : 'No',
|
||||
'nameOfSpouse' => $bank_account->spouse_name ?? '',
|
||||
'city' => $bank_account->birth_city ?? '',
|
||||
'accountType' => $account_type->name,
|
||||
'accountType' => $name_of_account_type,
|
||||
'originalNationality' => $bank_account->nationality,
|
||||
'countryOfResidence' => $bank_account->birth_country,
|
||||
'employersName' => $bank_account->employer_name ?? '',
|
||||
|
|
@ -807,12 +823,12 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
|||
$client = new Client();
|
||||
|
||||
$response = $client->post($apiUrl, [
|
||||
'auth' => ['sa', 'Sa123456'],
|
||||
'auth' => [$username, $password],
|
||||
'json' => $payload,
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
'connect_timeout' => 30,
|
||||
'connect_timeout' => 60,
|
||||
]);
|
||||
|
||||
$result = json_decode($response->getBody(), true);
|
||||
|
|
@ -820,16 +836,14 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
|||
if ($response->getStatusCode() == 200 || $response->getStatusCode() == 201) {
|
||||
$bank_account->update([
|
||||
'status' => 'actived',
|
||||
'reason' => 'Compte activé avec succès !'
|
||||
'reason' => 'Compte activé avec succès !',
|
||||
'account_number' => $result['accountNumber'],
|
||||
'customer_number' => $result['clientCode']
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Données et liens envoyés avec succès',
|
||||
'customer_number' => $result['customerNumber'] ?? null,
|
||||
'account_number' => $result['accountNumber'] ?? null
|
||||
]);
|
||||
Log::info('Compte bancaire utilisateur activé avec succès : ' . $result);
|
||||
// Mail::to($user->email)->send(new BankAccountActivated($bank_account,$name_of_account_type));
|
||||
|
||||
return $this->successResponse(trans('messages.user_bank_account_activated_successfully'),200);
|
||||
}
|
||||
|
||||
} catch (RequestException $e) {
|
||||
|
|
@ -840,18 +854,8 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
|||
'reason' => 'Erreur API externe : ' . $errorBody
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'L’API distante a refusé la requête',
|
||||
'details' => json_decode($errorBody) ?? $errorBody
|
||||
], 500);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Erreur lors de l’appel API',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
Log::error('Error API externe pour ID ' . $bank_account->id . ' : ' . $errorBody);
|
||||
return $this->errorResponse('Error_occurred', 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -861,4 +865,82 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
|||
|
||||
return $this->successResponse($account_types);
|
||||
}
|
||||
|
||||
|
||||
public function validateLinkUserBankAccount(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'iban' => 'nullable|string',
|
||||
'code_client' => '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);
|
||||
}
|
||||
|
||||
$baseUrl = env('BANK_LINK_API_BASE_URL', 'http://192.168.1.173:2087/api/v1');
|
||||
$login = env('BANK_LINK_API_LOGIN', 'admin');
|
||||
$password = env('BANK_LINK_API_PASSWORD', 'admin');
|
||||
|
||||
$authApi = $baseUrl . '/auth/authenticate';
|
||||
$accountApi = $baseUrl . '/account/getOne/' . $request->code_client;
|
||||
|
||||
try {
|
||||
$client = new Client();
|
||||
|
||||
$authResponse = $client->post($authApi, [
|
||||
'json' => [
|
||||
'login' => $login,
|
||||
'password' => $password
|
||||
],
|
||||
'connect_timeout' => 60,
|
||||
]);
|
||||
|
||||
$authResult = json_decode($authResponse->getBody(), true);
|
||||
$token = $authResult['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'));
|
||||
}
|
||||
|
||||
$response = $client->get($accountApi, [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
'connect_timeout' => 60,
|
||||
]);
|
||||
|
||||
$result = json_decode($response->getBody(), true);
|
||||
|
||||
if ($response->getStatusCode() == 200 || $response->getStatusCode() == 201) {
|
||||
$user_bank_account_verfication->update([
|
||||
'is_verified' => 1,
|
||||
'was_traited' => 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);
|
||||
}
|
||||
|
||||
} catch (RequestException $e) {
|
||||
$errorBody = $e->hasResponse() ? (string) $e->getResponse()->getBody() : $e->getMessage();
|
||||
|
||||
$user_bank_account_verfication->update([
|
||||
'is_verified' => 2,
|
||||
'was_traited' => 0,
|
||||
]);
|
||||
|
||||
Log::error('Erreur API Bank Link pour transaction ' . $request->id_transaction . ' : ' . $errorBody);
|
||||
|
||||
return $this->errorResponse(trans('errors.Error_occurred'));
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Erreur inattendue Bank Link : ' . $e->getMessage());
|
||||
return $this->errorResponse('Internal Server Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\UserBankAccount;
|
||||
|
||||
class BankAccountActivated extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $bankAccount;
|
||||
public $bankName;
|
||||
|
||||
public function __construct(UserBankAccount $bankAccount, $bank_name)
|
||||
{
|
||||
$this->bankAccount = $bankAccount;
|
||||
$this->bankName = $bank_name;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
return $this->subject('Votre compte bancaire a été activé')
|
||||
->view('emails.bank_account_activated');
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ class UserBankAccount extends Model
|
|||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
return $this->belongsTo(User::class, 'id_user');
|
||||
}
|
||||
|
||||
public function bank()
|
||||
|
|
|
|||
|
|
@ -96,5 +96,8 @@ Paying network : :network :country',
|
|||
'request_create_account_already_sended' => "A request to create a bank account has already been sent for this bank",
|
||||
'user_not_found' => "User not found",
|
||||
'account_type_not_found' => "Account type not found",
|
||||
'transaction_not_found' => 'Transaction not found',
|
||||
'token_not_found' => 'Authentication token not found',
|
||||
'Error_occurred' => 'An error occurred: ',
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -333,5 +333,8 @@ Transaction information :
|
|||
- Card number: :cart_number
|
||||
- Country of destination: :final_country
|
||||
- Destination account: :sender_code
|
||||
- Amount: :net_final"
|
||||
- Amount: :net_final",
|
||||
'create_bank_account_linked_successfully' => 'Bank account successfully linked to your user account',
|
||||
'user_bank_account_activated_successfully' => 'User bank account activated successfully',
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -96,4 +96,7 @@ Réseau payeur : :network :country',
|
|||
'request_create_account_already_sended' => "Une demande de création de compte bancaire a déjà été envoyée pour cette banque",
|
||||
'user_not_found' => "Utilisateur non trouvé",
|
||||
'account_type_not_found' => "Type de compte non trouvé",
|
||||
'transaction_not_found' => 'Transaction non trouvée',
|
||||
'token_not_found' => 'Token d\'authentification non trouvé',
|
||||
'Error_occurred' => 'Une erreur est survenue: ',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -335,4 +335,6 @@ Informations de la transaction :
|
|||
- Pays de destination : :final_country
|
||||
- Compte destinataire : :sender_code
|
||||
- Montant : :net_final",
|
||||
'create_bank_account_linked_successfully' => 'Compte bancaire rattaché avec succès',
|
||||
'user_bank_account_activated_successfully' => 'Compte bancaire activé avec succès',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Activation de compte</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Félicitations {{ $bankAccount->user->firstname }} !</h1>
|
||||
<p>Votre demande d'ouverture de compte a été acceptée et activée.</p>
|
||||
|
||||
<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>
|
||||
|
||||
<p>Vous pouvez désormais utiliser nos services bancaires dès maintenant.</p>
|
||||
|
||||
<p>Cordialement,<br>L'équipe SunEx.</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -76,6 +76,7 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
|
|||
$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');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue