From 88ea93bb7953d3a7e0af93927868169a74d5f107 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Thu, 25 Sep 2025 15:18:08 +0500 Subject: [PATCH] wip --- app/Helpers/helpers.php | 21 ++++++- .../Controllers/OnlinePaymentController.php | 61 +++++++++++++++++++ ...5_151716_add_online_id_to_orders_table.php | 28 +++++++++ .../views/onlinepayment/status.blade.php | 43 +++++++++++++ routes/web.php | 6 +- 5 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 app/Http/Controllers/OnlinePaymentController.php create mode 100644 database/migrations/2025_09_25_151716_add_online_id_to_orders_table.php create mode 100644 resources/views/onlinepayment/status.blade.php diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index ce7a37e..c847c13 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -348,6 +348,23 @@ if (! function_exists('calculateProductPriceAmount')) { } } +/** + * Halkbank credentials + * + * @return int|string|array{username: int|string, password: string} + */ +function halkbankCredentials(string $key = ''): int|string|array +{ + return match($key) { + 'username' => 516122500260, + 'password' => 'MrZsO9wfgWOBjf4', + default => [ + 'username' => 516122500260, + 'password' => 'MrZsO9wfgWOBjf4', + ] + }; +} + /** * Create halkbank order * @@ -363,8 +380,8 @@ function createHalkbankOrder($price = 123): array 'amount' => $price, 'currency' => 934, 'language' => 'ru', - 'userName' => 516122500260, - 'password' => 'MrZsO9wfgWOBjf4', + 'userName' => halkbankCredentials('username'), + 'password' => halkbankCredentials('password'), 'returnUrl' => route('online-payment-store'), 'pageView' => 'DESKTOP', 'description' => 'MM.COM.TM', diff --git a/app/Http/Controllers/OnlinePaymentController.php b/app/Http/Controllers/OnlinePaymentController.php new file mode 100644 index 0000000..56f3f71 --- /dev/null +++ b/app/Http/Controllers/OnlinePaymentController.php @@ -0,0 +1,61 @@ +validate([ + 'orderId' => ['required', 'string'] + ]); + + $response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatusExtended.do', [ + 'language' => 'ru', + 'orderId' => $request->orderId, + 'userName' => halkbankCredentials('username'), + 'password' => halkbankCredentials('password'), + ]); + + if ($response->failed()) { + return $this->data([ + 'success' => false, + 'title' => 'Näsazlyk, operator bilen habarlaşyň', + 'pnr' => '-', + 'branch_name' => 'MM.COM.TM', + 'price_amount' => '-', + 'return_url' => 'https://mm.com.tm/orders', + ]); + } + + $payment_status = $response['paymentAmountInfo']['depositedAmount'] > 0; + + // Update resource + $resource->update(['paid' => $payment_status]); + + return $this->view([ + 'success' => $payment_status, + 'title' => $payment_status ? 'Töleg geçdi' : 'Töleg geçmedi', + 'pnr' => $response['orderNumber'], + 'branch_name' => 'MM.COM.TM', + 'price_amount' => number_format($response['amount']), + 'return_url' => 'https://mm.com.tm/orders', + ]); + } + + public function view($data): View + { + return view('oninepayment.status', [ + 'success' => $data['success'], + 'title' => '', + 'pnr' => '', + 'branch_name' => '', + 'price_amount' => '', + 'return_url' => '', + ]); + } +} diff --git a/database/migrations/2025_09_25_151716_add_online_id_to_orders_table.php b/database/migrations/2025_09_25_151716_add_online_id_to_orders_table.php new file mode 100644 index 0000000..d6cf735 --- /dev/null +++ b/database/migrations/2025_09_25_151716_add_online_id_to_orders_table.php @@ -0,0 +1,28 @@ +string('halkbank_id')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('orders', function (Blueprint $table) { + $table->dropColumn('halkbank_id')->nullable(); + }); + } +}; diff --git a/resources/views/onlinepayment/status.blade.php b/resources/views/onlinepayment/status.blade.php new file mode 100644 index 0000000..0d54f11 --- /dev/null +++ b/resources/views/onlinepayment/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/routes/web.php b/routes/web.php index 3bedcd9..7e78e99 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,9 +1,7 @@ name('login'); -Route::get('api/online-payment-store', function () { - return request()->all(); -})->name('online-payment-store'); +Route::get('api/online-payment-store', [OnlinePaymentController::class, 'index'])->name('online-payment-store');