This commit is contained in:
2025-11-02 17:06:27 +05:00
parent 80973d5b85
commit 3f21f55c39
5 changed files with 177 additions and 3 deletions

View File

@@ -5,8 +5,11 @@ namespace App\Modules\OnlinePayment\Repositories;
use App\Modules\Makeable;
use App\Modules\OnlinePayment\Contracts\PaymentProviderContract;
use App\Modules\OnlinePayment\Models\OnlinePayment;
use Exception;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
class OnlinePaymentRepository
{
@@ -149,6 +152,114 @@ class OnlinePaymentRepository
return $this;
}
/**
* Check payment
*/
public function checkPayment(string $orderId)
{
// Find payment order from history
$paymentHistory = OnlinePayment::where('orderId', $orderId)->first();
// Find related resource
$resource = (new $paymentHistory->online_paymantable_type)->find(id: $paymentHistory->online_paymantable_id);
// If resource could not be found or does not exist, then inform it via logs
if (! $resource) {
return [
'success' => false,
'title' => __('Payment has failed').' '.'(RESOURCE NOT FOUND)',
'pnr' => '',
'branch_name' => '',
'price_amount' => '',
'return_url' => url('/'),
'bank_branch' => null,
'resource' => null,
'paymentHistory' => null,
];
}
$resource->load('branch');
$bank_branch = $resource->branch;
if (! $bank_branch) {
return [
'success' => false,
'title' => __('Payment has failed').' '.'(BRANCH NOT FOUND)',
'pnr' => '',
'branch_name' => '',
'price_amount' => '',
'return_url' => url('/'),
'bank_branch' => null,
'resource' => null,
'paymentHistory' => null,
];
}
try {
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
'language' => 'ru',
'orderId' => $orderId,
'userName' => $bank_branch->billing_username,
'password' => $bank_branch->billing_password,
]);
} catch (Exception $e) {
return [
'success' => false,
'title' => __('Payment has failed').' '.'(REQUEST FAILURE)',
'pnr' => '',
'branch_name' => '',
'price_amount' => '',
'return_url' => url('/'),
'bank_branch' => null,
'resource' => null,
'paymentHistory' => null,
];
}
$payment_status = $response['ErrorCode'] == '0';
$returnURL = '/';
if ($payment_status) {
$resource->update([
'paid' => true,
]);
$paymentHistory->update([
'paymentStatus' => OnlinePaymentRepository::PAID,
]);
return [
'success' => true,
'title' => __('Payment is successful'),
'pnr' => $paymentHistory->orderNumber,
'branch_name' => $bank_branch->name,
'price_amount' => $paymentHistory->amount.' TMT',
'return_url' => $returnURL,
'bank_branch' => $bank_branch,
'resource' => $resource,
'paymentHistory' => $paymentHistory,
'response' => $response,
];
}
$paymentHistory->update([
'paymentStatus' => OnlinePaymentRepository::FAILED,
]);
return [
'success' => false,
'title' => __('Payment has failed'),
'pnr' => $paymentHistory->orderNumber,
'branch_name' => $bank_branch->name,
'price_amount' => $paymentHistory->amount.' TMT',
'return_url' => $returnURL,
'paymentHistory' => $paymentHistory,
'bank_branch' => $bank_branch,
'response' => $response,
];
}
/**
* Payment link
*/
@@ -181,4 +292,12 @@ class OnlinePaymentRepository
OnlinePayment::create($data);
}
/**
* Show payment status
*/
public function paymentStatusView(array $data): View
{
return view('module.online-payment::payment-status', compact('data'));
}
}