From 3f21f55c39ab1eb9dda00cc1481555762a705a08 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Sun, 2 Nov 2025 17:06:27 +0500 Subject: [PATCH] wip --- .../HalkbankOnlinePaymentController.php | 11 +- .../HalkbankOnlinePaymentRepository.php | 5 + .../Repositories/OnlinePaymentRepository.php | 119 ++++++++++++++++++ .../Resources/Views/payment-status.blade.php | 43 +++++++ database/seeders/FillJsonData.php | 2 +- 5 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 app/Modules/OnlinePayment/Resources/Views/payment-status.blade.php diff --git a/app/Modules/HalkbankOnlinePayment/Controllers/HalkbankOnlinePaymentController.php b/app/Modules/HalkbankOnlinePayment/Controllers/HalkbankOnlinePaymentController.php index 2ecb599..33aeed9 100644 --- a/app/Modules/HalkbankOnlinePayment/Controllers/HalkbankOnlinePaymentController.php +++ b/app/Modules/HalkbankOnlinePayment/Controllers/HalkbankOnlinePaymentController.php @@ -3,6 +3,8 @@ namespace App\Modules\HalkbankOnlinePayment\Controllers; use App\Http\Controllers\Controller; +use App\Modules\HalkbankOnlinePayment\Repositories\HalkbankOnlinePaymentRepository; +use App\Modules\OnlinePayment\Repositories\OnlinePaymentRepository; use Illuminate\Contracts\View\View; use Illuminate\Http\Request; @@ -11,9 +13,14 @@ class HalkbankOnlinePaymentController extends Controller public function store(Request $request): View { $request->validate([ - 'orderId' => ['required', 'string', 'max:50', 'exists:online_payment_histories,orderId'], + 'orderId' => ['required', 'string', 'max:50', 'exists:online_payments,orderId'], ]); - return view('welcome'); + $onlinePaymentRepository = OnlinePaymentRepository::make() + ->paymentProvider(new HalkbankOnlinePaymentRepository); + + $paymentStatus = $onlinePaymentRepository->checkPayment($request->string('orderId')); + + return $onlinePaymentRepository->paymentStatusView($paymentStatus); } } diff --git a/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php b/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php index f52c9a3..573a907 100644 --- a/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php +++ b/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php @@ -71,6 +71,11 @@ class HalkbankOnlinePaymentRepository implements PaymentProviderContract return $paymentResponse; } + public function checkPayment() + { + // ... + } + /** * Format amount to match requirements */ diff --git a/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php b/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php index 1eb2353..3e4b193 100644 --- a/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php +++ b/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php @@ -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')); + } } diff --git a/app/Modules/OnlinePayment/Resources/Views/payment-status.blade.php b/app/Modules/OnlinePayment/Resources/Views/payment-status.blade.php new file mode 100644 index 0000000..0d54f11 --- /dev/null +++ b/app/Modules/OnlinePayment/Resources/Views/payment-status.blade.php @@ -0,0 +1,43 @@ + + + + + + Töleg status + + + +
+
+
+
+ + @if($success) + + + + @else + + + + @endif + +

+ {{ $title }} +

+ Töleg nomeri: {{ $pnr }} +
+
+
+ {{ $branch_name }} + {{ $price_amount }} +
+ {{ __('Go to home') }} +
+
+
+
+ + diff --git a/database/seeders/FillJsonData.php b/database/seeders/FillJsonData.php index c287b00..fd465b9 100644 --- a/database/seeders/FillJsonData.php +++ b/database/seeders/FillJsonData.php @@ -20,7 +20,7 @@ class FillJsonData extends Seeder 'branches', 'loan_types', 'card_states', - 'card_types' + 'card_types', ]); $sort->each(function (string $table_name) use ($dataPath) {