add create another user bank account function and change API authantication to the
same authentication by token for all
This commit is contained in:
parent
6ec8bbe51b
commit
752ca31428
|
|
@ -15,11 +15,12 @@ use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use App\Notifications\BankAccountCreated;
|
|
||||||
use App\Mail\BankAccountCreatedMail;
|
use App\Mail\BankAccountCreatedMail;
|
||||||
|
use App\Mail\BankAccountActivated;
|
||||||
use App\Models\CustomerAccountType;
|
use App\Models\CustomerAccountType;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
|
||||||
class WalletController extends Controller
|
class WalletController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -544,7 +545,7 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
||||||
return $this->errorResponse(trans('errors.wallet_already_linked_to_bank_account'));
|
return $this->errorResponse(trans('errors.wallet_already_linked_to_bank_account'));
|
||||||
|
|
||||||
//Verifier si l'utilisateur est identifié
|
//Verifier si l'utilisateur est identifié
|
||||||
$identification = $this->checkUserIdentification($user->id);
|
$this->checkUserIdentification($user->id);
|
||||||
|
|
||||||
//Verifier si la banque est associée au reseau
|
//Verifier si la banque est associée au reseau
|
||||||
$network_bank = NetworksOperator::where('id_network', $request->id_wallet_network)->where('id_operator_country', $request->id_bank)->first();
|
$network_bank = NetworksOperator::where('id_network', $request->id_wallet_network)->where('id_operator_country', $request->id_bank)->first();
|
||||||
|
|
@ -566,6 +567,17 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
||||||
// return $this->errorResponse(trans('errors.bank_not_match_iban'));
|
// return $this->errorResponse(trans('errors.bank_not_match_iban'));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
$existingLinkingAccount = UsersBankingAccountVerification::where('iban', $request->iban)
|
||||||
|
->where('is_verified', 1)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($existingLinkingAccount)
|
||||||
|
if ($existingLinkingAccount->is_verified == 1 && $existingLinkingAccount->was_treated == 0){
|
||||||
|
return $this->errorResponse(trans('errors.you_already_have_request_in_progress_for_this_account'));
|
||||||
|
}else if ($existingLinkingAccount->is_verified == 1 && $existingLinkingAccount->was_treated == 1){
|
||||||
|
return $this->errorResponse(trans('errors.wallet_already_linked_to_bank_account'));
|
||||||
|
}
|
||||||
|
|
||||||
$user_banking_account_verif = new UsersBankingAccountVerification();
|
$user_banking_account_verif = new UsersBankingAccountVerification();
|
||||||
$user_banking_account_verif->id_transaction = $this->getTransactionID();
|
$user_banking_account_verif->id_transaction = $this->getTransactionID();
|
||||||
$user_banking_account_verif->iban = $request->iban;
|
$user_banking_account_verif->iban = $request->iban;
|
||||||
|
|
@ -575,13 +587,6 @@ 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->id_network = $request->id_wallet_network;
|
||||||
$user_banking_account_verif->save();
|
$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('------------------------------------------------------------------------------------------------');
|
|
||||||
|
|
||||||
return $this->successResponse(trans('messages.successful_bank_account_attachment_taken'));
|
return $this->successResponse(trans('messages.successful_bank_account_attachment_taken'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -665,104 +670,146 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
||||||
'profession' => 'required|string',
|
'profession' => 'required|string',
|
||||||
'niu' => 'nullable|string',
|
'niu' => 'nullable|string',
|
||||||
'employer_city' => 'nullable|string',
|
'employer_city' => 'nullable|string',
|
||||||
'profession' => 'nullable|string',
|
|
||||||
'employer_name' => 'nullable|string',
|
'employer_name' => 'nullable|string',
|
||||||
'employer_address' => 'nullable|string',
|
'employer_address' => 'nullable|string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Vérifier que l’utilisateur est identifié
|
// 1. Initialisation et Vérifications de base
|
||||||
$user = User::findOrFail($request->id_user);
|
$user = User::findOrFail($request->id_user);
|
||||||
$identification = $this->checkUserIdentification($user->id);
|
$this->checkUserIdentification($user->id);
|
||||||
|
|
||||||
$operateur_country = OperatorsCountry::where('id', $request->id_operator)->first();
|
|
||||||
|
|
||||||
if (!$operateur_country) {
|
|
||||||
return $this->errorResponse(trans('errors.bank_not_associated_with_network'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vérifier si la banque est associée au réseau
|
|
||||||
$network_bank = NetworksOperator::where('id_network', $request->id_wallet_network)
|
$network_bank = NetworksOperator::where('id_network', $request->id_wallet_network)
|
||||||
->where('id_operator_country', $operateur_country->id)
|
->where('id_operator_country', $request->id_operator)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (!$network_bank) {
|
if (!$network_bank || $network_bank->operators_country->operator->type != 'bank') {
|
||||||
return $this->errorResponse(trans('errors.bank_not_associated_with_network'));
|
$errorKey = (!$network_bank) ? 'errors.bank_not_associated_with_network' : 'errors.not_banking_operator';
|
||||||
|
return $this->errorResponse(trans($errorKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($network_bank->operators_country->operator->type != 'bank') {
|
// Préparation des données communes pour éviter la répétition plus bas
|
||||||
return $this->errorResponse(trans('errors.not_banking_operator'));
|
$commonAccountData = [
|
||||||
}
|
'id_user' => $request->id_user,
|
||||||
|
'id_operator_country' => $request->id_operator,
|
||||||
|
'customer_account_type_id' => $request->account_type,
|
||||||
|
'firstname' => $request->firstname,
|
||||||
|
'lastname' => $request->lastname,
|
||||||
|
'nationality' => $request->nationality,
|
||||||
|
'birth_date' => $request->birth_date,
|
||||||
|
'birth_country' => $request->birth_country,
|
||||||
|
'birth_city' => $request->birth_city,
|
||||||
|
'marital_status' => $request->marital_status ?? 'celibataire',
|
||||||
|
'profession' => $request->profession,
|
||||||
|
'identification_number' => $request->identification_number,
|
||||||
|
'phone_number' => $request->phone_number ?? 'null',
|
||||||
|
'spouse_name' => $request->spouse_name,
|
||||||
|
'niu' => $request->niu ?? 'null',
|
||||||
|
'employer_city' => $request->employer_city ?? 'null',
|
||||||
|
'employer_name' => $request->employer_name ?? 'null',
|
||||||
|
'employer_address' => $request->employer_address ?? 'null',
|
||||||
|
'balance' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
$existingAccount = UserBankAccount::where('id_user', $request->id_user)
|
// 2. CAS A : Même produit (Même opérateur ET même type)
|
||||||
|
$sameTypeAccount = UserBankAccount::where('id_user', $request->id_user)
|
||||||
->where('id_operator_country', $request->id_operator)
|
->where('id_operator_country', $request->id_operator)
|
||||||
->where('customer_account_type_id', $request->account_type)
|
->where('customer_account_type_id', $request->account_type)
|
||||||
->whereIn('status', ['pending', 'actived', 'rejected', 'closed'])
|
->whereIn('status', ['pending', 'actived', 'rejected', 'closed'])
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($existingAccount) {
|
if ($sameTypeAccount) {
|
||||||
|
$statusMessages = [
|
||||||
|
'actived' => trans('messages.user_already_has_bank_account_with_this_operator', ['user_lastname' => $user->lastname]),
|
||||||
|
'pending' => trans('errors.you_already_have_request_in_progress_for_this_product'),
|
||||||
|
'rejected' => trans('errors.your_previous_request_for_this_product_was_rejected'),
|
||||||
|
'closed' => trans('errors.your_previous_request_for_this_product_was_closed'),
|
||||||
|
];
|
||||||
|
return $this->errorResponse($statusMessages[$sameTypeAccount->status] ?? 'Error', 500);
|
||||||
|
}
|
||||||
|
|
||||||
if ($existingAccount->status == 'actived') {
|
// 3. CAS B : Autre produit chez le même opérateur (Ouverture via API)
|
||||||
return $this->errorResponse(trans('messages.user_already_has_bank_account_with_this_operator',['user_lastname' => $user->lastname]),500);
|
$differentTypeAccount = UserBankAccount::where('id_user', $request->id_user)
|
||||||
}else{
|
->where('id_operator_country', $request->id_operator)
|
||||||
return $this->errorResponse(trans('errors.request_create_account_already_sended'), 500);
|
->where('customer_account_type_id', '!=', $request->account_type)
|
||||||
|
->whereNotNull('account_number')
|
||||||
|
->whereIn('status', ['pending', 'actived', 'rejected', 'closed'])
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($differentTypeAccount) {
|
||||||
|
$customer_account_type = CustomerAccountType::find($request->account_type);
|
||||||
|
if (!$customer_account_type) return $this->errorResponse(trans('errors.account_type_not_found'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$client = new Client(['connect_timeout' => 60]);
|
||||||
|
$baseUrl = env('BANK_API_BASE_URL');
|
||||||
|
|
||||||
|
// Auth API
|
||||||
|
$authResponse = $client->post($baseUrl . '/auth/authenticate', [
|
||||||
|
'json' => ['login' => env('BANK_API_LOGIN'), 'password' => env('BANK_API_PASSWORD')]
|
||||||
|
]);
|
||||||
|
$authResult = json_decode($authResponse->getBody(), true);
|
||||||
|
$token = $authResult['data']['token'] ?? null;
|
||||||
|
|
||||||
|
if (!$token) {
|
||||||
|
Log::error('Token introuvable pour user: ' . $request->id_user);
|
||||||
|
return $this->errorResponse(trans('errors.token_not_found'), 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Account API
|
||||||
|
$response = $client->post($baseUrl . '/clients/' . $differentTypeAccount->account_number . '/account', [
|
||||||
|
'headers' => ['Authorization' => 'Bearer ' . $token, 'Accept' => 'application/json'],
|
||||||
|
'json' => ['productCode' => $customer_account_type->product]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$result = json_decode($response->getBody(), true);
|
||||||
|
|
||||||
|
if ($response->getStatusCode() <= 301 && ($result['success'] ?? true) != false) {
|
||||||
|
$newAccount = new UserBankAccount($commonAccountData);
|
||||||
|
$newAccount->account_number = $result['accountNumber'] ?? null;
|
||||||
|
$newAccount->customer_number = $result['clientMatricul'] ?? null;
|
||||||
|
$newAccount->reason = trans('messages.user_bank_account_activated_successfully');
|
||||||
|
$newAccount->status = 'actived';
|
||||||
|
$newAccount->save();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Mail::to($user->email)->send(new BankAccountActivated($newAccount, $customer_account_type->name));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error("Mail error: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->successResponse(trans('messages.create_bank_account_linked_successfully'), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::error('Échec API Banque User: ' . $request->id_user . ' Res: ' . $response->getBody());
|
||||||
|
return $this->errorResponse(trans('errors.bank_api_exception'), 500);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Exception API Banque User: ' . $request->id_user . ' Error: ' . $e->getMessage());
|
||||||
|
return $this->errorResponse(trans('errors.bank_api_exception'), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$bank_name = $network_bank->operators_country->operator->nom;
|
// 4. CAS STANDARD : Création d'une demande "Pending"
|
||||||
$account_type = CustomerAccountType::where('id', $request->account_type)->first();
|
$account_type = CustomerAccountType::find($request->account_type);
|
||||||
|
if (!$account_type) return $this->errorResponse(trans('errors.account_type_not_found'));
|
||||||
|
|
||||||
if (!$account_type) {
|
$bankAccount = new UserBankAccount($commonAccountData);
|
||||||
return $this->errorResponse(trans('errors.account_type_not_found'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$bankAccount = new UserBankAccount();
|
|
||||||
$bankAccount->id_user = $user->id;
|
|
||||||
$bankAccount->id_operator_country = $request->id_operator;
|
|
||||||
$bankAccount->lastname = $request->lastname;
|
|
||||||
$bankAccount->customer_account_type_id = $account_type->id;
|
|
||||||
$bankAccount->firstname = $request->firstname;
|
|
||||||
$bankAccount->nationality = $request->nationality;
|
|
||||||
$bankAccount->birth_date = $request->birth_date;
|
|
||||||
$bankAccount->birth_country = $request->birth_country;
|
|
||||||
$bankAccount->birth_city = $request->birth_city;
|
|
||||||
$bankAccount->marital_status = $request->marital_status ?? 'celibataire';
|
|
||||||
$bankAccount->profession = $request->profession;
|
|
||||||
$bankAccount->identification_number = $request->identification_number;
|
|
||||||
$bankAccount->phone_number = $request->phone_number ?? 'null';
|
|
||||||
$bankAccount->spouse_name = $request->spouse_name;
|
|
||||||
$bankAccount->niu = $request->niu ?? 'null';
|
|
||||||
$bankAccount->employer_city = $request->employer_city ?? 'null';
|
|
||||||
$bankAccount->profession = $request->profession;
|
|
||||||
$bankAccount->employer_name = $request->employer_name ?? 'null';
|
|
||||||
$bankAccount->employer_address = $request->employer_address ?? 'null';
|
|
||||||
$bankAccount->balance = 0;
|
|
||||||
$bankAccount->status = 'pending';
|
$bankAccount->status = 'pending';
|
||||||
$bankAccount->created_at = date('Y-m-d H:i:s');
|
|
||||||
$bankAccount->updated_at = date('Y-m-d H:i:s');
|
|
||||||
$bankAccount->save();
|
$bankAccount->save();
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$bankAccount->reason = 'Demande de creation de compte bancaire soumise. En attente de verification par un administrateur.';
|
$bankAccount->update(['reason' => trans('messages.request_bank_account_pending_validation_by_administrator')]);
|
||||||
$bankAccount->save();
|
|
||||||
Log::info('Demande de creation de compte bancaire enregistree avec succes');
|
|
||||||
|
|
||||||
// Envoi de notification par email
|
$bank_name = $network_bank->operators_country->operator->nom;
|
||||||
// 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);
|
|
||||||
|
return $this->successResponse(['message' => trans('messages.successful_bank_account_creation')]);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$bankAccount->status = 'rejected';
|
$bankAccount->update(['status' => 'rejected', 'reason' => $e->getMessage()]);
|
||||||
$bankAccount->reason = $e->getMessage();
|
Log::error('Erreur Mail/Creation: ' . $e->getMessage());
|
||||||
$bankAccount->save();
|
|
||||||
Log::error('Erreur lors de la demande de creation de compte bancaire ' . $e->getMessage());
|
|
||||||
return $this->errorResponse(trans('errors.bank_api_exception'));
|
return $this->errorResponse(trans('errors.bank_api_exception'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->successResponse([
|
|
||||||
'message' => trans('messages.successful_bank_account_creation')
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function activateUserBankAccount(Request $request)
|
public function activateUserBankAccount(Request $request)
|
||||||
|
|
@ -773,79 +820,96 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
||||||
'doc_back' => 'required|url',
|
'doc_back' => 'required|url',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$bank_account = UserBankAccount::where('id', $request->id)->with('user')->first();
|
// 1. Récupération des données avec chargement des relations
|
||||||
|
$bank_account = UserBankAccount::with('user')->find($request->id);
|
||||||
|
|
||||||
|
if (!$bank_account) return $this->errorResponse(trans('errors.account_type_not_found'));
|
||||||
|
|
||||||
$user = $bank_account->user;
|
$user = $bank_account->user;
|
||||||
|
if (!$user) return $this->errorResponse(trans('errors.user_not_found'));
|
||||||
|
|
||||||
if (!$bank_account) {
|
$account_type = CustomerAccountType::find($bank_account->customer_account_type_id);
|
||||||
return $this->errorResponse(trans('errors.account_type_not_found'));
|
if (!$account_type) return $this->errorResponse(trans('errors.account_type_not_found'));
|
||||||
}
|
|
||||||
|
|
||||||
if(!$user){
|
// 2. Préparation des variables API
|
||||||
return $this->errorResponse(trans('errors.user_not_found'));
|
$baseUrl = env('BANK_API_BASE_URL');
|
||||||
}
|
$login = env('BANK_API_LOGIN');
|
||||||
|
$password = env('BANK_API_PASSWORD');
|
||||||
$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;
|
$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 = [
|
$payload = [
|
||||||
'phoneNumber' => $bank_account->phone_number ?? ($user->phone ?? ''),
|
'phoneNumber' => $bank_account->phone_number ?? ($user->phone ?? ''),
|
||||||
'email' => $user->email ?? '',
|
'email' => $user->email ?? '',
|
||||||
'fullname' => $bank_account->firstname . ' ' . $bank_account->lastname,
|
'fullname' => $bank_account->firstname . ' ' . $bank_account->lastname,
|
||||||
'branchCode' => $branchCode,
|
'branchCode' => env('BANK_API_BRANCH_CODE'),
|
||||||
'dateOfBirth' => $bank_account->birth_date,
|
'dateOfBirth' => $bank_account->birth_date,
|
||||||
'isMarried' => ($bank_account->marital_status === 'marie') ? 'Yes' : 'No',
|
'isMarried' => ($bank_account->marital_status === 'marie') ? 'Yes' : 'No',
|
||||||
'nameOfSpouse' => $bank_account->spouse_name ?? '',
|
'nameOfSpouse' => $bank_account->spouse_name ?? '',
|
||||||
'city' => $bank_account->birth_city ?? '',
|
'city' => $bank_account->birth_city ?? '',
|
||||||
'accountType' => $name_of_account_type,
|
'accountType' => $name_of_account_type,
|
||||||
'originalNationality' => $bank_account->nationality,
|
'originalNationality' => $bank_account->nationality,
|
||||||
'countryOfResidence' => $bank_account->birth_country,
|
'countryOfResidence' => $bank_account->birth_country,
|
||||||
'employersName' => $bank_account->employer_name ?? '',
|
'employersName' => $bank_account->employer_name ?? '',
|
||||||
'employersAddress' => $bank_account->employer_address ?? '',
|
'employersAddress' => $bank_account->employer_address ?? '',
|
||||||
'employersCity' => $bank_account->employer_city ?? '',
|
'employersCity' => $bank_account->employer_city ?? '',
|
||||||
'product' => $account_type->product ?? '',
|
'product' => $account_type->product ?? '',
|
||||||
'identificationNumber' => $bank_account->identification_number,
|
'identificationNumber' => $bank_account->identification_number,
|
||||||
'paySlip' => $request->doc_front,
|
'paySlip' => $request->doc_front,
|
||||||
'signatureCard' => $request->doc_back,
|
'signatureCard' => $request->doc_back,
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client = new Client();
|
$client = new Client(['connect_timeout' => 60]);
|
||||||
|
|
||||||
$response = $client->post($apiUrl, [
|
$authResponse = $client->post($baseUrl . '/auth/authenticate', [
|
||||||
'auth' => [$username, $password],
|
'json' => [
|
||||||
'json' => $payload,
|
'login' => $login,
|
||||||
|
'password' => $password
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$authResult = json_decode($authResponse->getBody(), true);
|
||||||
|
$token = $authResult['data']['token'] ?? null;
|
||||||
|
|
||||||
|
if (!$token) {
|
||||||
|
Log::error('Token introuvable (Activation) pour compte ID: ' . $bank_account->id);
|
||||||
|
return $this->errorResponse(trans('errors.token_not_found'), 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $client->post($baseUrl . '/clients/create-with-account', [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Accept' => 'application/json',
|
'Authorization' => 'Bearer ' . $token,
|
||||||
|
'Accept' => 'application/json',
|
||||||
],
|
],
|
||||||
'connect_timeout' => 60,
|
'json' => $payload,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = json_decode($response->getBody(), true);
|
$result = json_decode($response->getBody(), true);
|
||||||
|
|
||||||
if ($response->getStatusCode() == 200 || $response->getStatusCode() == 201) {
|
if ($response->getStatusCode() == 200 || $response->getStatusCode() == 201) {
|
||||||
$bank_account->update([
|
$bank_account->update([
|
||||||
'status' => 'actived',
|
'status' => 'actived',
|
||||||
'reason' => 'Compte activé avec succès !',
|
'reason' => 'Compte activé avec succès !',
|
||||||
'account_number' => $result['accountNumber'],
|
'account_number' => $result['accountNumber'] ?? null,
|
||||||
'customer_number' => $result['clientCode']
|
'customer_number' => $result['clientCode'] ?? null
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Mail::to($user->email)->send(new BankAccountActivated($bank_account,$name_of_account_type));
|
$user->update([
|
||||||
|
'id_bank_country' => $bank_account->id_operator_country,
|
||||||
|
'iban' => $result['accountNumber'] ?? null
|
||||||
|
]);
|
||||||
|
|
||||||
return $this->successResponse(trans('messages.user_bank_account_activated_successfully'),200);
|
try {
|
||||||
|
Mail::to($user->email)->send(new BankAccountActivated($bank_account, $name_of_account_type));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error("Mail error lors de l'activation: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->successResponse(trans('messages.user_bank_account_activated_successfully'), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->errorResponse('Erreur lors de l\'activation API', 500);
|
||||||
|
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
$errorBody = $e->hasResponse() ? (string) $e->getResponse()->getBody() : $e->getMessage();
|
$errorBody = $e->hasResponse() ? (string) $e->getResponse()->getBody() : $e->getMessage();
|
||||||
|
|
||||||
|
|
@ -854,7 +918,7 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
||||||
'reason' => 'Erreur API externe : ' . $errorBody
|
'reason' => 'Erreur API externe : ' . $errorBody
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Log::error('Error API externe pour ID ' . $bank_account->id . ' : ' . $errorBody);
|
Log::error('Erreur Activation API pour ID ' . $bank_account->id . ' : ' . $errorBody);
|
||||||
return $this->errorResponse('Error_occurred', 500);
|
return $this->errorResponse('Error_occurred', 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -885,9 +949,9 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
||||||
return $this->errorResponse(trans('errors.user_not_found'), 404);
|
return $this->errorResponse(trans('errors.user_not_found'), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$baseUrl = env('BANK_LINK_API_BASE_URL', 'http://192.168.1.173:2087/api/v1');
|
$baseUrl = env('BANK_API_BASE_URL',);
|
||||||
$login = env('BANK_LINK_API_LOGIN', 'admin');
|
$login = env('BANK_API_LOGIN');
|
||||||
$password = env('BANK_LINK_API_PASSWORD', 'admin');
|
$password = env('BANK_API_PASSWORD');
|
||||||
|
|
||||||
$authApi = $baseUrl . '/auth/authenticate';
|
$authApi = $baseUrl . '/auth/authenticate';
|
||||||
$accountApi = $baseUrl . '/account/getOne/' . $request->iban;
|
$accountApi = $baseUrl . '/account/getOne/' . $request->iban;
|
||||||
|
|
@ -929,6 +993,11 @@ INNER JOIN countries c ON oc.id_country = c.id INNER JOIN type_operators top ON
|
||||||
'was_treated' => 1
|
'was_treated' => 1
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$user->update([
|
||||||
|
'iban' => $user_bank_account_verfication->iban,
|
||||||
|
'id_bank_country' => $user_bank_account_verfication->id_bank_country
|
||||||
|
]);
|
||||||
|
|
||||||
Log::info('Compte bancaire rattaché avec succès pour transaction: ' . $request->id_transaction);
|
Log::info('Compte bancaire rattaché avec succès pour transaction: ' . $request->id_transaction);
|
||||||
try {
|
try {
|
||||||
// Mail::to($user->email)->send(new BankAccountLinked($user_bank_account_verfication));
|
// Mail::to($user->email)->send(new BankAccountLinked($user_bank_account_verfication));
|
||||||
|
|
|
||||||
|
|
@ -646,16 +646,16 @@ class iLinkTransactionController extends Controller
|
||||||
throw new Exception(trans('errors.not_banking_operator') . '. ' . trans('errors.update_banking_information'));
|
throw new Exception(trans('errors.not_banking_operator') . '. ' . trans('errors.update_banking_information'));
|
||||||
|
|
||||||
//Reverifier le code IBAN correspond toujours
|
//Reverifier le code IBAN correspond toujours
|
||||||
$country_code = $network_bank->network->country->code_country;
|
// $country_code = $network_bank->network->country->code_country;
|
||||||
$bank_code = $network_bank->operators_country->code;
|
// $bank_code = $network_bank->operators_country->code;
|
||||||
switch ($this->checkIBAN($user->iban, $country_code, $bank_code)) {
|
// switch ($this->checkIBAN($user->iban, $country_code, $bank_code)) {
|
||||||
case 0:
|
// case 0:
|
||||||
throw new Exception(trans('errors.invalid_iban') . '. ' . trans('errors.update_banking_information'));
|
// throw new Exception(trans('errors.invalid_iban') . '. ' . trans('errors.update_banking_information'));
|
||||||
case 1:
|
// case 1:
|
||||||
throw new Exception(trans('errors.country_not_match_iban') . '. ' . trans('errors.update_banking_information'));
|
// throw new Exception(trans('errors.country_not_match_iban') . '. ' . trans('errors.update_banking_information'));
|
||||||
case 2:
|
// case 2:
|
||||||
throw new Exception(trans('errors.bank_not_match_iban') . '. ' . trans('errors.update_banking_information'));
|
// throw new Exception(trans('errors.bank_not_match_iban') . '. ' . trans('errors.update_banking_information'));
|
||||||
}
|
// }
|
||||||
|
|
||||||
$transaction->frais = $frais = 0;
|
$transaction->frais = $frais = 0;
|
||||||
$transaction->taxe = $taxe = 0;
|
$transaction->taxe = $taxe = 0;
|
||||||
|
|
@ -682,7 +682,7 @@ class iLinkTransactionController extends Controller
|
||||||
|
|
||||||
$message = trans('messages.successful_user_send_to_bank',
|
$message = trans('messages.successful_user_send_to_bank',
|
||||||
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
['id_transaction' => $transaction->id_transaction, 'amount' => $this->toMoney($transaction->montant, $init_country),
|
||||||
'net' => $this->toMoney($transaction->montant, $init_country), 'iban' => $request->iban, 'fees' => $this->toMoney($frais, $init_country),
|
'net' => $this->toMoney($transaction->montant, $init_country), 'iban' => $request->iban ?? $user->iban, 'fees' => $this->toMoney($frais, $init_country),
|
||||||
'sender_code' => $user->user_code, 'bank' => $transaction->bank, 'country' => $transaction->country]);
|
'sender_code' => $user->user_code, 'bank' => $transaction->bank, 'country' => $transaction->country]);
|
||||||
$this->sendMail($user->email, trans('messages.successful_transaction'), $message);
|
$this->sendMail($user->email, trans('messages.successful_transaction'), $message);
|
||||||
$response_message = ($message . trans('messages.sent_by_mail'));
|
$response_message = ($message . trans('messages.sent_by_mail'));
|
||||||
|
|
@ -1568,16 +1568,16 @@ class iLinkTransactionController extends Controller
|
||||||
throw new Exception(trans('errors.not_banking_operator'));
|
throw new Exception(trans('errors.not_banking_operator'));
|
||||||
|
|
||||||
//Verifier le code IBAN
|
//Verifier le code IBAN
|
||||||
$country_code = $network_bank->network->country->code_country;
|
// $country_code = $network_bank->network->country->code_country;
|
||||||
$bank_code = $network_bank->operators_country->code;
|
// $bank_code = $network_bank->operators_country->code;
|
||||||
switch ($this->checkIBAN($request->iban, $country_code, $bank_code)) {
|
// switch ($this->checkIBAN($request->iban, $country_code, $bank_code)) {
|
||||||
case 0:
|
// case 0:
|
||||||
throw new Exception(trans('errors.invalid_iban'));
|
// throw new Exception(trans('errors.invalid_iban'));
|
||||||
case 1:
|
// case 1:
|
||||||
throw new Exception(trans('errors.country_not_match_iban'));
|
// throw new Exception(trans('errors.country_not_match_iban'));
|
||||||
case 2:
|
// case 2:
|
||||||
throw new Exception(trans('errors.bank_not_match_iban'));
|
// throw new Exception(trans('errors.bank_not_match_iban'));
|
||||||
}
|
// }
|
||||||
|
|
||||||
$transaction->frais = $frais = 0;
|
$transaction->frais = $frais = 0;
|
||||||
$transaction->taxe = $taxe = 0;
|
$transaction->taxe = $taxe = 0;
|
||||||
|
|
|
||||||
|
|
@ -99,5 +99,9 @@ Paying network : :network :country',
|
||||||
'transaction_not_found' => 'Transaction not found',
|
'transaction_not_found' => 'Transaction not found',
|
||||||
'token_not_found' => 'Authentication token not found',
|
'token_not_found' => 'Authentication token not found',
|
||||||
'Error_occurred' => 'An error occurred: ',
|
'Error_occurred' => 'An error occurred: ',
|
||||||
|
'you_already_have_request_in_progress_for_this_account' => 'You already have a request in progress for this account',
|
||||||
|
'you_already_have_request_in_progress_for_this_product ' => 'You already have a request in progress for this product',
|
||||||
|
'your_previous_request_for_this_product_was_rejected' => 'Your previous request for this product was rejected',
|
||||||
|
'your_previous_request_for_this_product_was_closed' => 'Your previous request for this product was closed',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ return [
|
||||||
'validated_identification'=>'Validated identification',
|
'validated_identification'=>'Validated identification',
|
||||||
'identification_already_validated'=>'Identification already validated',
|
'identification_already_validated'=>'Identification already validated',
|
||||||
'successful_card_attachment' => 'Attachment of your card made',
|
'successful_card_attachment' => 'Attachment of your card made',
|
||||||
'user_already_has_bank_account_with_this_operator' => ":user_lastname already has a active bank account with this operator",
|
'user_already_has_bank_account_with_this_operator' => ":user_lastname already has a active account with this product",
|
||||||
'successful_bank_account_creation' => 'The bank account creation request has been successfully sent you will be notified by email once the account is created',
|
'successful_bank_account_creation' => 'The bank account creation request has been successfully sent you will be notified by email once the account is created',
|
||||||
'successful_identification_message' => 'Hi :name,
|
'successful_identification_message' => 'Hi :name,
|
||||||
|
|
||||||
|
|
@ -336,5 +336,7 @@ Transaction information :
|
||||||
- Amount: :net_final",
|
- Amount: :net_final",
|
||||||
'create_bank_account_linked_successfully' => 'Bank account successfully linked to your user account',
|
'create_bank_account_linked_successfully' => 'Bank account successfully linked to your user account',
|
||||||
'user_bank_account_activated_successfully' => 'User bank account activated successfully',
|
'user_bank_account_activated_successfully' => 'User bank account activated successfully',
|
||||||
|
'wallet_already_linked_to_bank_account' => 'This wallet is already linked to a bank account',
|
||||||
|
'request_bank_account_pending_validation_by_administrator' => 'Your bank account creation request is pending validation by an administrator',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -99,4 +99,8 @@ Réseau payeur : :network :country',
|
||||||
'transaction_not_found' => 'Transaction non trouvée',
|
'transaction_not_found' => 'Transaction non trouvée',
|
||||||
'token_not_found' => 'Token d\'authentification non trouvé',
|
'token_not_found' => 'Token d\'authentification non trouvé',
|
||||||
'Error_occurred' => 'Une erreur est survenue: ',
|
'Error_occurred' => 'Une erreur est survenue: ',
|
||||||
|
'you_already_have_request_in_progress_for_this_account' => 'Vous avez déjà une demande en cours pour ce compte',
|
||||||
|
'you_already_have_request_in_progress_for_this_product' => 'Vous avez déjà une demande en cours pour ce produit',
|
||||||
|
'your_previous_request_for_this_product_was_rejected' => 'Votre précédente demande pour ce produit a été rejetée',
|
||||||
|
'your_previous_request_for_this_product_was_closed' => 'Votre précédente demande pour ce produit a été clôturée',
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ return [
|
||||||
'user_not_identificated' => 'Utilisateur non identifié',
|
'user_not_identificated' => 'Utilisateur non identifié',
|
||||||
'identification_already_validated' => 'Identification deja validée',
|
'identification_already_validated' => 'Identification deja validée',
|
||||||
'successful_card_attachment' => 'Rattachement de votre carte effectuée',
|
'successful_card_attachment' => 'Rattachement de votre carte effectuée',
|
||||||
'user_already_has_bank_account_with_this_operator' => ":user_lastname possède déjà un compte bancaire actif avec cet opérateur",
|
'user_already_has_bank_account_with_this_operator' => ":user_lastname possède déjà un compte actif avec ce produit",
|
||||||
'successful_bank_account_creation' => 'La demande de création de compte bancaire a été envoyée avec succès vous serez notifié par email une fois le compte créé',
|
'successful_bank_account_creation' => 'La demande de création de compte bancaire a été envoyée avec succès vous serez notifié par email une fois le compte créé',
|
||||||
'successful_identification_message' => 'Salut :name,
|
'successful_identification_message' => 'Salut :name,
|
||||||
|
|
||||||
|
|
@ -337,4 +337,6 @@ Informations de la transaction :
|
||||||
- Montant : :net_final",
|
- Montant : :net_final",
|
||||||
'create_bank_account_linked_successfully' => 'Compte bancaire rattaché avec succès',
|
'create_bank_account_linked_successfully' => 'Compte bancaire rattaché avec succès',
|
||||||
'user_bank_account_activated_successfully' => 'Compte bancaire activé avec succès',
|
'user_bank_account_activated_successfully' => 'Compte bancaire activé avec succès',
|
||||||
|
'wallet_already_linked_to_bank_account' => 'Votre wallet est deja rattaché à votre compte bancaire',
|
||||||
|
'request_bank_account_pending_validation_by_administrator' => 'Votre demande de création de compte bancaire est en attente de validation par un administrateur',
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue