wip
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Repos\Payment\OnlinePaymentRepo;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OnlinePaymentController extends Controller
|
||||
{
|
||||
@@ -13,25 +17,59 @@ class OnlinePaymentController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
return $request->all();
|
||||
// Validate the order id
|
||||
$request->validate(['orderId' => ['required', 'string', 'max:50', 'exists:online_payment_histories,orderId']]);
|
||||
|
||||
// $response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
// 'language' => 'ru',
|
||||
// 'orderId' => $request->orderId,
|
||||
// 'userName' => 301161000067,
|
||||
// 'password' => 'E3vb2SR3dgTPdff'
|
||||
// ]);
|
||||
// Find order from history
|
||||
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||
|
||||
// if ($response['depositAmount'] > 0) {
|
||||
// $payment_history = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||
// Find related resource
|
||||
$resource = (new $paymentHistory->online_paymantable_type)->find(id: $paymentHistory->online_paymantable_id);
|
||||
|
||||
// $booking = Booking::where('id', $payment_history->online_paymantable_id)->update([
|
||||
// 'status' => Settings::PAID
|
||||
// ]);
|
||||
if (! $resource) {
|
||||
Log::channel('halkbank_payment_check_error')
|
||||
->error('Related resource not found', [
|
||||
'orderId' => $request->orderId,
|
||||
'onlinePaymentHistory_id' => $paymentHistory->id,
|
||||
'related_resource' => [
|
||||
'type' => $paymentHistory->online_paymantable_type,
|
||||
'id' => $paymentHistory->online_paymantable_id,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// $payment_history->update([
|
||||
// 'paymentStatus' => Settings::PAID
|
||||
// ]);
|
||||
// }
|
||||
$resource->load('branch');
|
||||
|
||||
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
'language' => 'ru',
|
||||
'orderId' => $request->orderId,
|
||||
'userName' => $resource->branch->billing_username,
|
||||
'password' => $resource->branch->billing_password,
|
||||
]);
|
||||
|
||||
$payment_status = $response['depositAmount'] > 0;
|
||||
|
||||
if ($payment_status) {
|
||||
$resource->update([
|
||||
'paid' => true,
|
||||
]);
|
||||
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::PAID,
|
||||
]);
|
||||
} else {
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::FAILED,
|
||||
]);
|
||||
}
|
||||
|
||||
return view(OnlinePaymentRepo::statusView(), [
|
||||
'status' => $payment_status,
|
||||
'title' => $payment_status ? __('Payment is successful') : __('Payment has failed'),
|
||||
'pnr' => $paymentHistory->orderNumber,
|
||||
'branch_name' => $resource->branch->name,
|
||||
'price_amount' => $paymentHistory->amount,
|
||||
'return_url' => $resource->panelUrl(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,4 +120,14 @@ class CardOrder extends Model
|
||||
return 1;
|
||||
// return floatval($this->cardType->price);
|
||||
}
|
||||
|
||||
/**
|
||||
* Panel url
|
||||
*/
|
||||
public function panelUrl(string $type = 'index'): string
|
||||
{
|
||||
return match ($type) {
|
||||
'index' => sprintf('resources/card-orders'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,26 @@ namespace App\Repos\Payment;
|
||||
|
||||
use App\Models\Payment\ApiKeyHalkbank;
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OnlinePaymentRepo
|
||||
{
|
||||
/**
|
||||
* Pending orders are brand new orders that have not been processed yet.
|
||||
*/
|
||||
public const PENDING = 'pending';
|
||||
|
||||
/**
|
||||
* Failed orders are existing orders that could be paid
|
||||
*/
|
||||
public const FAILED = 'failed';
|
||||
|
||||
/**
|
||||
* Paid orders are existing order that could be paid successfully
|
||||
*/
|
||||
public const PAID = 'paid';
|
||||
|
||||
/**
|
||||
* Pay card order
|
||||
*
|
||||
@@ -58,7 +71,7 @@ class OnlinePaymentRepo
|
||||
'errorUrl' => route('online-payment-store'),
|
||||
'api_client' => config('app.url'),
|
||||
'username' => $resource->branch->billing_username,
|
||||
'paymentStatus' => OrderRepo::PENDING,
|
||||
'paymentStatus' => self::PENDING,
|
||||
]);
|
||||
|
||||
return [
|
||||
@@ -74,4 +87,12 @@ class OnlinePaymentRepo
|
||||
{
|
||||
return ApiKeyHalkbank::generateOrderNumber($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Status view
|
||||
*/
|
||||
public static function statusView(): string
|
||||
{
|
||||
return 'orders.cards.online-payment.status';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,13 @@ return [
|
||||
'level' => env('LOG_LEVEL', 'error'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'halkbank_payment_check_error' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/halkbank_payment_check_error.log'),
|
||||
'level' => env('LOG_LEVEL', 'error'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
@@ -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('card_orders', function (Blueprint $table) {
|
||||
$table->boolean('paid')->default(false)->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('card_orders', function (Blueprint $table) {
|
||||
$table->boolean('paid')->default(true)->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -254,5 +254,8 @@
|
||||
"I accept terms of contract": "Şertnama bilen razylaşýaryn",
|
||||
"Click to read": "Okamak üçin bas",
|
||||
"Agree": "Razylaşýaryn",
|
||||
"I have read the contract": "Şertnama bilen tanyşdym"
|
||||
"I have read the contract": "Şertnama bilen tanyşdym",
|
||||
"Go to home": "Baş sahypa git",
|
||||
"Payment is successful": "Töleg geçdi",
|
||||
"Payment has failed": "Töleg geçmedi"
|
||||
}
|
||||
|
||||
36
resources/views/orders/cards/online-payment/status.blade.php
Normal file
36
resources/views/orders/cards/online-payment/status.blade.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>P</title>
|
||||
<style>
|
||||
.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}h3,svg{color:#17cca9}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;background-color:#17cca9;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}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="outer-container">
|
||||
<div class="inner-container">
|
||||
<div class="card centered-content">
|
||||
<div class="top">
|
||||
|
||||
<svg 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>
|
||||
<h3>
|
||||
{{ $title }}
|
||||
</h3>
|
||||
<span>PNR: {{ $pnr }}</span>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="key-value">
|
||||
<span>{{ $branch_name }}</span>
|
||||
<span>{{ $price_amount }}</span>
|
||||
</div>
|
||||
<a href="{{ $return_url }}">{{ __('Go to home') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -33,6 +33,8 @@ Route::middleware(['auth', 'un_verified'])->group(function () {
|
||||
Route::post('sms-verification', [RegisterController::class, 'verifySmsCode']);
|
||||
});
|
||||
|
||||
Route::view('test', 'orders.cards.online-payment.status');
|
||||
|
||||
Route::get('online-payment-store', [OnlinePaymentController::class, 'store'])->name('online-payment-store');
|
||||
|
||||
Route::redirect('/', config('nova.path'));
|
||||
|
||||
Reference in New Issue
Block a user