Compare commits

...

10 Commits

Author SHA1 Message Date
Djery-Tom 30f8387ee8 fix: missing traductions and some issues 2023-09-13 11:10:10 +01:00
Djery-Tom 63ce95ff71 fix: datetime while pay receipt 2023-08-25 17:21:45 +01:00
Djery-Tom 0e867ae5cb fix: set correct currency code of network 2023-08-11 18:01:40 +01:00
Djery-Tom 0d1514b293 fix: in wallet type 2023-08-04 12:42:36 +01:00
Djery-Tom 92c4fb55a7 feat: add card payment method while pay insurance 2023-08-02 19:08:22 +01:00
Djery-Tom 0f65d9d1df fix: remove payment method 2023-07-31 14:21:14 +01:00
Djery-Tom 21cf029a13 fix: improve insurance payment 2023-07-31 13:50:33 +01:00
Djery-Tom 8218c8053b Fix insurance payments while using wallet 2023-03-16 14:23:30 +01:00
Djery-Tom d053ae86da Rename nh_network_config_id to network_id in nh_validating_agents 2023-03-13 17:35:19 +01:00
Djery-Tom 0dd7038b7f Fix reason while pay insurance invoice 2022-10-09 01:25:17 +01:00
11 changed files with 11118 additions and 88 deletions

1
.gitignore vendored
View File

@ -10,4 +10,3 @@ Homestead.yaml
/public/insurances-subscriptions-docs
/public/qrcodes
/public/invoices-docs
composer.lock

View File

@ -6,32 +6,19 @@ use App\Events\InsuranceEvent;
use App\InsuranceAction;
use App\InsuranceInvoiceState;
use App\InsuranceState;
use App\InsuranceSubscriptionAffiliation;
use App\InsuranceSubscriptionState;
use App\Models\AgentPlus;
use App\Models\CountriesCurrency;
use App\Models\Identification;
use App\Models\NhHavingRight;
use App\Models\NhInsurance;
use App\Models\NhInsurancesHavingRight;
use App\Models\NhInsurancesInvoice;
use App\Models\NhInsurancesPayment;
use App\Models\NhInsurancesSubscription;
use App\Models\NhInsurancesSubscriptionsHistory;
use App\Models\NhMonthsPricesGrid;
use App\Models\NhNetworksConfig;
use App\Models\PaymentAggregator;
use App\Models\PaymentTransaction;
use App\Models\User;
use App\Models\Wallet;
use App\Rules\PasswordValidation;
use App\Traits\Helper;
use Carbon\Carbon;
use DateTime;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
@ -233,7 +220,7 @@ class InsuranceInvoiceController extends Controller
* description="Token la transaction de paiement"
* )
* ),
* example = {"password":"adbc1215448", "amount" : 50000 , "payment_method" : "wallet" }
* example = {"password":"adbc1215448", "amount" : 50000 , "payment_method" : "WALLET" }
* )
* ),
* @OA\Response(
@ -252,10 +239,10 @@ class InsuranceInvoiceController extends Controller
$this->validate($request, [
'password' => 'required|string',
'amount' => 'required|numeric|min:0',
'payment_method' => 'required|string',
'payment_phone' => 'required_unless:payment_method,wallet|string',
'payment_method' => 'required|string|in:CARD,MOBILE_MONEY,WALLET',
// 'payment_phone' => 'required_unless:payment_method,WALLET|string',
'payment_transaction_id' => 'nullable|exists:payment_transactions,transaction_id', // A envoyer apres avoir effectuer le paiement
'payment_token' => 'required_with:payment_transaction_id|string', // A envoyer apres avoir effectuer le paiement
// 'payment_token' => 'required_with:payment_transaction_id|string', // A envoyer apres avoir effectuer le paiement
'otp' => 'nullable|string'
]);
@ -298,30 +285,103 @@ class InsuranceInvoiceController extends Controller
return $this->errorResponse(trans('errors.minimum amount_to_paid', ['amount' => $this->toMoneyWithCurrencyCode($invoice->amount_per_split, $currency)]));
}
if (empty($transaction_id)) {
if ($payment_method == 'wallet') {
if ($user->wallet->balance < $amountToPaid) {
$remains_amount = $amountToPaid - $user->wallet->balance;
return $this->errorResponse(trans('errors.insufficient_balance', ['amount' => $this->toMoneyWithCurrencyCode($remains_amount, $currency)]));
}
} else {
$aggregator = PaymentAggregator::where('status', 1)->first();
if (!$aggregator) {
return $this->errorResponse(trans('errors.payment_not_available'));
}
if ($payment_method == 'WALLET') {
if ($user->wallet->balance < $amountToPaid) {
$remains_amount = $amountToPaid - $user->wallet->balance;
return $this->errorResponse(trans('errors.insufficient_balance', ['amount' => $this->toMoneyWithCurrencyCode($remains_amount, $currency)]));
}
} else {
$transaction = PaymentTransaction::where('transaction_id', $transaction_id)->where('payment_token', $request->input('payment_token'))->where('state', 'ACCEPTED')->first();
if (!$transaction) {
return $this->errorResponse(trans('errors.payment_not_found'), 404);
$data = [
'amount' => $amountToPaid,
'payment_method' => $payment_method,
'reason' => trans('messages.insurance_invoice')
];
if ($payment_method == 'CARD') {
$withLinkedCard = $request->input('with_linked_card', false);
$this->validate($request, [
'cvv' => 'required|size:3',
]);
if ($withLinkedCard) {
if (!(isset($user->numero_carte) && isset($user->expiration_date))) {
return $this->errorResponse(trans('errors.no_bank_card_attached'));
}
$cardExpiryDate = $user->expiration_date;
$expMonth = date("m", strtotime($cardExpiryDate));
$expYear = date("Y", strtotime($cardExpiryDate));
$cardNumber = $user->numero_carte;
$country = CountriesCurrency::findOrFail($user->card_country_id);
} else {
$this->validate($request, [
'numero_carte' => 'required',
'expiration_date' => 'required|date_format:m/y|after_or_equal:today',
'customer_name' => 'nullable|string',
'customer_surname' => 'required|string',
'customer_address' => 'required|string',
'customer_city' => 'required|string',
'customer_country' => "required|string|size:2"
]);
$cardExpiryDate = DateTime::createFromFormat('m/y', $request->expiration_date);
$expMonth = $cardExpiryDate->format('m');
$expYear = $cardExpiryDate->format('Y');
$cardNumber = $request->numero_carte;
$country = CountriesCurrency::where('code_country', $request->input('customer_country'))->firstOrFail();
}
$identification = Identification::where('id_user', $user->id)->first();
$data = array_merge($data, [
'card_no' => $cardNumber,
'exp_month' => $expMonth,
'exp_year' => $expYear,
'cvc' => $request->input('cvv'),
'currency' => $networkConfig->network->country->currency_code,
'payment_method' => 'CARD',
'customer_id' => $user->id,
'customer_email' => $user->email,
'customer_name' => $withLinkedCard ? $identification->firstname : $request->input('customer_name'),
'customer_surname' => $withLinkedCard ? $identification->lastname : $request->input('customer_surname'),
'customer_address' => $withLinkedCard ? $identification->town : $request->input('customer_address'),
'customer_city' => $withLinkedCard ? $identification->town : $request->input('customer_city'),
'customer_country' => $country->code_country,
]);
}
if ($payment_method == 'MOBILE_MONEY') {
$data = array_merge($data, [
'currency' => $networkConfig->network->country->currency_code,
'customer_id' => $user->id,
'customer_email' => $user->email,
'customer_name' => $user->lastname,
'customer_surname' => $user->lastname,
'customer_phone_number' => $user->phone,
'customer_address' => $user->adresse,
'customer_country' => $user->network->country->code_country,
'customer_city' => $user->adresse,
'customer_state' => $user->network->country->code_country,
'customer_zip_code' => '00237',
]);
}
$result = $this->handlePayIn($data, $transaction_id);
if (!is_string($result)) {
return $result;
}
$transaction_id = $result;
}
if (!empty($transaction_id)) {
$payment = NhInsurancesPayment::where('payment_id', $transaction_id)->first();
if ($payment) {
return $this->errorResponse(trans('errors.payment_invalid'), 400);
}
$amountToPaid = $transaction->amount;
}
try {
@ -336,54 +396,14 @@ class InsuranceInvoiceController extends Controller
$user->save();
if (empty($transaction_id)) {
if ($payment_method == 'wallet') {
if ($payment_method == 'WALLET') {
$user->wallet->balance -= $amountToPaid;
$user->wallet->save();
} else {
// Pay through payment service
$client = new Client([
'base_uri' => config('variable.payment_service_url'),
'headers' => [
'Authorization' => config('variable.payment_service_key'),
]
]);
$paymentResponse = $client->post('/pay', [
'json' => [
'aggregator_id' => $aggregator->id,
'amount' => $amountToPaid,
'currency' => $user->network->country->currency_code,
'customer_id' => $user->id,
'customer_email' => $user->email,
'customer_name' => $user->lastname,
'customer_surname' => $user->lastname,
'customer_phone_number' => $request->input('payment_phone'),
'customer_address' => $user->adresse,
'customer_country' => $user->network->country->code_country,
'customer_city' => $user->adresse,
'customer_state' => $user->network->country->code_country,
'customer_zip_code' => '00237',
'payment_method' => $request->input('payment_method'),
'reason' => trans('states.receipt'),
'otp' => $request->input('otp')
],
'http_errors' => false
]);
$responseData = json_decode($paymentResponse->getBody()->getContents());
$responseCode = $paymentResponse->getStatusCode();
if ($responseCode == 200) {
// $transaction_id = $responseData->response->transaction_id;
return $this->successResponse($responseData->response);
} else {
return $this->errorResponse($responseData->error ?? trans('errors.unexpected_error'), $responseCode);
}
}
}
$payment = NhInsurancesPayment::create([
'payment_id' => $transaction_id,
'payment_id' => empty($transaction_id) ? $this->generateID('nh_insurances_payments', 'payment_id', 10) : $transaction_id,
'invoice_id' => $invoice->id,
'amount' => $amountToPaid
]);
@ -470,6 +490,45 @@ class InsuranceInvoiceController extends Controller
}
}
/**
* @throws Exception
*/
private function handlePayIn($data, $payment_transaction_id = null)
{
// Pay through payment service
$client = new Client([
'base_uri' => config('variable.payment_service_url'),
'headers' => [
'Authorization' => config('variable.payment_service_key'),
]
]);
// PayIn through payment service
if (empty($payment_transaction_id)) {
// PayIn through payment service
$response = $client->post('/pay', ['json' => $data, 'http_errors' => false]);
} else {
// Check payment status through payment service
if (NhInsurancesPayment::where('payment_id', $payment_transaction_id)->exists()) {
return $this->errorResponse(__('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"];
return $response["transaction_id"];
} else {
return $this->errorResponse($content['error'] ?? trans('errors.unexpected_error'), $content['status'] ?? 500);
}
}
// public function generateInvoices()
// {
// try {

View File

@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\Model;
* Class NhValidatingDoctor
*
* @property int $id
* @property int $nh_network_config_id
* @property int $network_id
* @property string|null $firstname
* @property string $lastname
* @property string $email
@ -32,7 +32,7 @@ class NhValidatingAgent extends Model
protected $table = 'nh_validating_agents';
protected $casts = [
'nh_network_config_id' => 'int'
'network_id' => 'int'
];
protected $hidden = [
@ -41,7 +41,7 @@ class NhValidatingAgent extends Model
];
protected $fillable = [
'nh_network_config_id',
'network_id',
'firstname',
'lastname',
'email',

View File

@ -440,9 +440,10 @@ trait Helper
->whereDate('next_payment_reminder', date('Y-m-d'))->get();
foreach ($invoices as $invoice) {
if (in_array($invoice->insurance->monthsGrid->payment_period, ['DAILY', 'MONTHLY'])) {
$paymentPeriod = $invoice->insurance->monthsGrid->payment_period;
if (in_array($paymentPeriod, ['DAILY', 'MONTHLY'])) {
// Si le paiement est mensuel, se rassurer que cela fait deja 1 mois
if ($invoice->monthsGrid->payment_period == 'MONTHLY' && date_create($invoice->next_payment_deadline)->diff(new DateTime())->m < 1) {
if ($paymentPeriod == 'MONTHLY' && date_create($invoice->next_payment_deadline)->diff(new DateTime())->m < 1) {
continue;
}

View File

@ -5,7 +5,7 @@
"license": "MIT",
"type": "project",
"require": {
"php": "^7.3|^8.0",
"php": "^8.0",
"ext-gd": "*",
"ext-intl": "*",
"ext-json": "*",
@ -46,7 +46,10 @@
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
"optimize-autoloader": true,
"allow-plugins": {
"php-http/discovery": true
}
},
"minimum-stability": "dev",
"prefer-stable": true,

10930
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class RenameNhNetworkConfigIdInNhValidatingAgentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('nh_validating_agents', function (Blueprint $table) {
$table->renameColumn('nh_network_config_id', 'network_id');
DB::statement("alter table nh_validating_agents modify role enum ('DOCTOR', 'AGENT', 'CONTROLLER','OPENING_ACCOUNT_AGENT') default 'DOCTOR' not null;");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('nh_validating_agents', function (Blueprint $table) {
$table->renameColumn('network_id', 'nh_network_config_id');
});
}
}

View File

@ -76,5 +76,6 @@ return [
"amount_not_allowed" => "This amount is not allowed. It must be between :min and :max",
'payment_not_available' => "Payment not available at this time. Please try again later",
'payment_not_found' => "Payment not found",
'payment_invalid' => "Invalid payment"
'payment_invalid' => "Invalid payment",
"transaction_already_completed" => "This transaction has already been completed",
];

View File

@ -249,5 +249,6 @@ Your insurance has expired.
'the_invoice' => "the invoice",
'the_payment' => "the payment",
'care_request_already_been_processed' => "The care request has already been processed",
'successful_authentification' => "Successful authentication"
'successful_authentification' => "Successful authentication",
'insurance_invoice' => "Insurance invoice"
];

View File

@ -79,5 +79,6 @@ return [
"amount_not_allowed" => "Ce montant n'est pas autorisé. Il doit être compris entre :min et :max",
'payment_not_available' => "Paiement non disponible pour le moment. Veuillez réessayer plus tard",
'payment_not_found' => "Paiement non trouvé",
'payment_invalid' => "Paiement invalide"
'payment_invalid' => "Paiement invalide",
"transaction_already_completed" => "Cette transaction a déjà été éffectuée",
];

View File

@ -266,5 +266,6 @@ Votre assurance est arrivée à échéance.
'the_invoice' => "la facture",
'the_payment' => "le paiement",
'care_request_already_been_processed' => "La demande de prise en charge a deja ete traitée",
'successful_authentification' => "Authentification réussie"
'successful_authentification' => "Authentification réussie",
'insurance_invoice' => "Facture d'assurance"
];