lets check online payment

This commit is contained in:
2024-11-23 11:01:17 +05:00
parent 61b6634fce
commit 134fb8507e
5 changed files with 131 additions and 62 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Repos\Payment;
use App\Models\Payment\OnlinePaymentHistory;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Laravel\Nova\Makeable;
@@ -153,4 +155,79 @@ class OnlinePaymentRepo
{
return 'orders.cards.online-payment.status';
}
public static function checkPayment(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();
}
$resource->load('branch');
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
'language' => 'ru',
'orderId' => $request->orderId,
'userName' => $resource->branch->billing_visa_master_username,
'password' => $resource->branch->billing_visa_master_password,
]);
$payment_status = $response['ErrorCode'] == '0';
if ($payment_status) {
$resource->update([
'paid' => true,
]);
$paymentHistory->update([
'paymentStatus' => OnlinePaymentRepo::PAID,
]);
} else {
$paymentHistory->update([
'paymentStatus' => OnlinePaymentRepo::FAILED,
]);
}
return [
'success' => $payment_status,
'title' => $payment_status ? __('Payment is successful') : __('Payment has failed'),
'pnr' => $paymentHistory->orderNumber,
'branch_name' => $resource->branch->name,
'price_amount' => $paymentHistory->amount,
'return_url' => $resource->panelUrl('index'),
];
}
protected static function logResourceNotFound($request, $paymentHistory): void
{
Log::channel('halkbank_payment_check_error')
->error('Related resource not found', [
'orderId' => $request->orderId,
'onlinePaymentHistory_id' => $paymentHistory->id,
'related_resource' => [
'type' => $paymentHistory->online_paymantable_type,
'id' => $paymentHistory->online_paymantable_id,
],
]);
}
protected static function resourceNotFound(): array
{
return [
'success' => false,
'title' => __('Payment has failed').' '.'(RESOURCE NOT FOUND)',
'pnr' => '',
'branch_name' => '',
'price_amount' => '',
'return_url' => url('/'),
];
}
}