This commit is contained in:
2025-09-25 15:18:08 +05:00
parent abe8334ed5
commit 88ea93bb79
5 changed files with 153 additions and 6 deletions

View File

@@ -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',

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class OnlinePaymentController extends Controller
{
public function index(Request $request)
{
$request->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' => '',
]);
}
}

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('orders', function (Blueprint $table) {
$table->string('halkbank_id')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('orders', function (Blueprint $table) {
$table->dropColumn('halkbank_id')->nullable();
});
}
};

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Töleg status</title>
<style>
body{font-family: 'Trebuchet MS', sans-serif;}.top:before,a{display:block}.bottom,.inner-container,.top{text-align:center}.card{box-shadow:0 15px 16.8px rgba(0,0,0,.031),0 100px 134px rgba(0,0,0,.05);background-color:#fff;border-radius:15px;padding:35px}.top{padding-bottom:25px;min-width:250px;border-bottom:2px dashed #dfe4f3;border-top-right-radius:8px;border-bottom-right-radius:8px;border-left:.18em dashed #fff;position:relative}.outer-container,.top:before{background-color:#fafcff;position:absolute}.top:before{content:"";width:20px;height:20px;border-radius:100%;bottom:0;right:-10px;margin-bottom:-10px}svg{margin:0 auto;width:60px;height:60px}h3{margin-top:0;margin-bottom:10px}span{color:#adb3c4;font-size:12px}.bottom{margin-top:30px}.key-value{display:flex;justify-content:space-between}.key-value span:first-child{font-weight:0}a{padding:8px 20px;text-decoration:none;color:#fff;border-radius:8px;font-size:14px;margin-top:20px}.outer-container{display:table;width:100%;height:100%;top:0;right:0}.inner-container{display:table-cell;vertical-align:middle}.centered-content{display:inline-block;text-align:left;background:#fff;margin-top:10px}.success{color:#17cca9}.danger{color:#f2131f}.bg-success{background-color:#17cca9}.bg-danger{background-color:#f2131f}
</style>
</head>
<body>
<div class="outer-container">
<div class="inner-container">
<div class="card centered-content">
<div class="top">
@if($success)
<svg class="success" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
</svg>
@else
<svg class="danger" xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 1.944A11.954 11.954 0 012.166 5C2.056 5.649 2 6.319 2 7c0 5.225 3.34 9.67 8 11.317C14.66 16.67 18 12.225 18 7c0-.682-.057-1.35-.166-2.001A11.954 11.954 0 0110 1.944zM11 14a1 1 0 11-2 0 1 1 0 012 0zm0-7a1 1 0 10-2 0v3a1 1 0 102 0V7z" clip-rule="evenodd" />
</svg>
@endif
<h3 class="{{ $success ? 'success' : 'danger' }}">
{{ $title }}
</h3>
<span>Töleg nomeri: {{ $pnr }}</span>
</div>
<div class="bottom">
<div class="key-value">
<span>{{ $branch_name }}</span>
<span>{{ $price_amount }}</span>
</div>
<a class="{{ $success ? 'bg-success' : 'bg-danger' }}" href="{{ $return_url }}">{{ __('Go to home') }}</a>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@@ -1,9 +1,7 @@
<?php
use App\Http\Controllers\OnlinePaymentController;
use Illuminate\Support\Facades\Route;
Route::view('/login', 'wip')->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');