phpstan 5 errors fixed
This commit is contained in:
@@ -3,14 +3,14 @@
|
||||
namespace App\Repos\Payment;
|
||||
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Repos\Payment\VisaMaster\HandlesVisaMasterPayments;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Laravel\Nova\Makeable;
|
||||
|
||||
class OnlinePaymentRepo
|
||||
{
|
||||
use HandlesVisaMasterPayments;
|
||||
use Makeable;
|
||||
|
||||
/**
|
||||
@@ -156,63 +156,6 @@ class OnlinePaymentRepo
|
||||
return 'orders.cards.online-payment.status';
|
||||
}
|
||||
|
||||
public static function checkPaymentVisaMaster(Request $request)
|
||||
{
|
||||
// Find order from history
|
||||
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||
|
||||
// Find related resource
|
||||
$resource = VisaMasterPaymentOrderItem::where('online_payment_history_id', $paymentHistory->id)->first();
|
||||
|
||||
// If resource could not be found or does not exist, then inform it via logs
|
||||
if (! $resource) {
|
||||
static::logResourceNotFound($request, $paymentHistory);
|
||||
|
||||
return static::resourceNotFound();
|
||||
}
|
||||
|
||||
$bank_branch = $resource->parent->branch;
|
||||
|
||||
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
'language' => 'ru',
|
||||
'orderId' => $request->orderId,
|
||||
'userName' => $bank_branch->billing_visa_master_username,
|
||||
'password' => $bank_branch->billing_visa_master_password,
|
||||
]);
|
||||
|
||||
$payment_status = $response['ErrorCode'] == '0';
|
||||
|
||||
if ($payment_status) {
|
||||
$resource->update([
|
||||
'payer_name' => $response['cardholderName'],
|
||||
'payer_card' => $response['Pan'],
|
||||
'paid' => true,
|
||||
]);
|
||||
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::PAID,
|
||||
]);
|
||||
} else {
|
||||
$resource->update([
|
||||
'payer_name' => $response['cardholderName'] ?? '-',
|
||||
'payer_card' => $response['Pan'] ?? '-',
|
||||
]);
|
||||
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::FAILED,
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => $payment_status,
|
||||
'title' => $payment_status ? __('Payment is successful') : __('Payment has failed'),
|
||||
'pnr' => $paymentHistory->orderNumber,
|
||||
'branch_name' => $bank_branch->name,
|
||||
'price_amount' => convertToOriginalFormat($paymentHistory->amount).' TMT',
|
||||
'return_url' => url('/work-place/resources/nova-visa-master-payment-orders/'.$resource->visa_master_payment_order_id),
|
||||
];
|
||||
}
|
||||
|
||||
protected static function logResourceNotFound($request, $paymentHistory): void
|
||||
{
|
||||
Log::channel('halkbank_payment_check_error')
|
||||
@@ -226,6 +169,30 @@ class OnlinePaymentRepo
|
||||
]);
|
||||
}
|
||||
|
||||
public static function successfulPaymentResponse($paymentHistory, $bank_branch, $resource)
|
||||
{
|
||||
return [
|
||||
'success' => true,
|
||||
'title' => __('Payment is successful'),
|
||||
'pnr' => $paymentHistory->orderNumber,
|
||||
'branch_name' => $bank_branch->name,
|
||||
'price_amount' => convertToOriginalFormat($paymentHistory->amount).' TMT',
|
||||
'return_url' => url('/work-place/resources/nova-visa-master-payment-orders/'.$resource->visa_master_payment_order_id),
|
||||
];
|
||||
}
|
||||
|
||||
public static function failedPaymentResponse($paymentHistory, $bank_branch, $resource)
|
||||
{
|
||||
return [
|
||||
'success' => false,
|
||||
'title' => __('Payment is successful'),
|
||||
'pnr' => $paymentHistory->orderNumber,
|
||||
'branch_name' => $bank_branch->name,
|
||||
'price_amount' => convertToOriginalFormat($paymentHistory->amount).' TMT',
|
||||
'return_url' => url('/work-place/resources/nova-visa-master-payment-orders/'.$resource->visa_master_payment_order_id),
|
||||
];
|
||||
}
|
||||
|
||||
protected static function resourceNotFound(): array
|
||||
{
|
||||
return [
|
||||
|
||||
64
app/Repos/Payment/VisaMaster/HandlesVisaMasterPayments.php
Normal file
64
app/Repos/Payment/VisaMaster/HandlesVisaMasterPayments.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repos\Payment\VisaMaster;
|
||||
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem;
|
||||
use App\Repos\Payment\OnlinePaymentRepo;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
trait HandlesVisaMasterPayments
|
||||
{
|
||||
public static function checkPaymentVisaMaster(Request $request)
|
||||
{
|
||||
// Find order from history
|
||||
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||
|
||||
// Find related resource
|
||||
$resource = VisaMasterPaymentOrderItem::where('online_payment_history_id', $paymentHistory->id)->first();
|
||||
|
||||
// If resource could not be found or does not exist, then inform it via logs
|
||||
if (! $resource) {
|
||||
static::logResourceNotFound($request, $paymentHistory);
|
||||
|
||||
return static::resourceNotFound();
|
||||
}
|
||||
|
||||
$bank_branch = $resource->parent->branch;
|
||||
|
||||
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
'language' => 'ru',
|
||||
'orderId' => $request->orderId,
|
||||
'userName' => $bank_branch->billing_visa_master_username,
|
||||
'password' => $bank_branch->billing_visa_master_password,
|
||||
]);
|
||||
|
||||
$payment_status = $response['ErrorCode'] == '0';
|
||||
|
||||
if ($payment_status) {
|
||||
$resource->update([
|
||||
'payer_name' => $response['cardholderName'],
|
||||
'payer_card' => $response['Pan'],
|
||||
'paid' => true,
|
||||
]);
|
||||
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::PAID,
|
||||
]);
|
||||
|
||||
return static::successfulPaymentResponse($paymentHistory, $bank_branch, $resource);
|
||||
}
|
||||
|
||||
$resource->update([
|
||||
'payer_name' => $response['cardholderName'] ?? '-',
|
||||
'payer_card' => $response['Pan'] ?? '-',
|
||||
]);
|
||||
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::FAILED,
|
||||
]);
|
||||
|
||||
return static::failedPaymentResponse($paymentHistory, $bank_branch, $resource);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user