feat: add card payment method while pay insurance

This commit is contained in:
Djery-Tom 2023-08-02 19:08:22 +01:00
parent 0f65d9d1df
commit 92c4fb55a7
3 changed files with 455 additions and 415 deletions

View File

@ -6,34 +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\Models\WalletIlinkTransaction;
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;
@ -308,12 +293,63 @@ class InsuranceInvoiceController extends Controller
}
} else {
$result = $this->handlePayIn([
// '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'),
$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;
$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);
$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' => date("m", strtotime($cardExpiryDate)),
'exp_year' => date("Y", strtotime($cardExpiryDate)),
'cvc' => $request->input('cvv'),
'currency' => $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' => $user->network->country->currency_code,
'customer_id' => $user->id,
'customer_email' => $user->email,
@ -325,9 +361,10 @@ class InsuranceInvoiceController extends Controller
'customer_city' => $user->adresse,
'customer_state' => $user->network->country->code_country,
'customer_zip_code' => '00237',
'payment_method' => $request->input('payment_method'),
'reason' => trans('messages.insurance_invoice'),
], $transaction_id);
]);
}
$result = $this->handlePayIn($data, $transaction_id);
if (!is_string($result)) {
return $result;
@ -337,15 +374,10 @@ class InsuranceInvoiceController extends Controller
}
if (!empty($transaction_id)) {
$transaction = PaymentTransaction::where('transaction_id', $transaction_id)->where('state', 'ACCEPTED')->first();
if (!$transaction) {
return $this->errorResponse(trans('errors.payment_not_found'), 404);
}
$payment = NhInsurancesPayment::where('payment_id', $transaction_id)->first();
if ($payment) {
return $this->errorResponse(trans('errors.payment_invalid'), 400);
}
$amountToPaid = $transaction->amount;
}
try {
@ -474,7 +506,7 @@ class InsuranceInvoiceController extends Controller
} else {
// Check payment status through payment service
if (NhInsurancesPayment::where('payment_id', $payment_transaction_id)->exists()) {
throw new Exception(__('errors.transaction_already_completed'), 500);
return $this->errorResponse(__('errors.transaction_already_completed'), 500);
}
$response = $client->get('/checkStatus/' . $payment_transaction_id, ['http_errors' => false]);
@ -490,9 +522,7 @@ class InsuranceInvoiceController extends Controller
$response = $content["response"];
return $response["transaction_id"];
} else {
throw new Exception($content['error'] ?? __('errors.visa_api_failed'), $content['status'] ?? 500);
// return $this->errorResponse($responseData->error ?? trans('errors.unexpected_error'), $responseCode);
return $this->errorResponse($content['error'] ?? trans('errors.unexpected_error'), $content['status'] ?? 500);
}
}
// public function generateInvoices()

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,

747
composer.lock generated

File diff suppressed because it is too large Load Diff