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

@@ -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);
}
}

View File

@@ -71,6 +71,11 @@ class HalkbankOnlinePaymentRepository implements PaymentProviderContract
return $paymentResponse;
}
public function checkPayment()
{
// ...
}
/**
* Format amount to match requirements
*/

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'));
}
}

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

@@ -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) {