migrate *** ** * ***** **** ***
This commit is contained in:
@@ -75,4 +75,70 @@ class OnlinePaymentController extends Controller
|
||||
'return_url' => $resource->panelUrl('index'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function visaMaster(Request $request)
|
||||
{
|
||||
// Validate the order id
|
||||
if (
|
||||
validator(
|
||||
$request->all(),
|
||||
['orderId' => ['required', 'string', 'max:50', 'exists:online_payment_histories,orderId']]
|
||||
)->fails()
|
||||
) {
|
||||
return ['wrong order id'];
|
||||
}
|
||||
|
||||
// Find order from history
|
||||
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->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) {
|
||||
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,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$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['ErrorCode'] == '0';
|
||||
|
||||
if ($payment_status) {
|
||||
$resource->update([
|
||||
'paid' => true,
|
||||
]);
|
||||
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::PAID,
|
||||
]);
|
||||
} else {
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::FAILED,
|
||||
]);
|
||||
}
|
||||
|
||||
return view(OnlinePaymentRepo::statusView(), [
|
||||
'success' => $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('index'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,4 +176,15 @@ class VisaMasterPaymentOrder extends Model implements HasMedia
|
||||
{
|
||||
return 250;
|
||||
}
|
||||
|
||||
/**
|
||||
* Panel url
|
||||
*/
|
||||
public function panelUrl(string $type = 'index'): string
|
||||
{
|
||||
return match ($type) {
|
||||
'index' => sprintf('%s/resources/nova-visa-master-payment-orders', config('nova.path')),
|
||||
default => config('nova.path'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class MakePaymentNovaVisaMaster extends Action
|
||||
}
|
||||
|
||||
return $payment['status'] === 'success'
|
||||
? ActionResponse::redirect($payment['url'])
|
||||
? ActionResponse::openInNewTab($payment['url'])
|
||||
: ActionResponse::danger('Töleg ýerinde näsazlyk!');
|
||||
}
|
||||
|
||||
@@ -78,9 +78,9 @@ class MakePaymentNovaVisaMaster extends Action
|
||||
'language' => 'ru',
|
||||
'userName' => $resource->branch->billing_username,
|
||||
'password' => $resource->branch->billing_password,
|
||||
'returnUrl' => route('online-payment-store'),
|
||||
'returnUrl' => route('online-payment-store-visa-master'),
|
||||
'pageView' => 'DESKTOP',
|
||||
'description' => 'Kart tölegi',
|
||||
'description' => 'Visa/Master tölegi',
|
||||
])->onError(function ($response) {
|
||||
Log::channel('halkbank_payment_error')
|
||||
->error('Payment error', [
|
||||
@@ -105,8 +105,8 @@ class MakePaymentNovaVisaMaster extends Action
|
||||
'description' => 'Visa/Master tölegi',
|
||||
'orderId' => $paymentResponse['orderId'],
|
||||
'formUrl' => $paymentResponse['formUrl'],
|
||||
'successUrl' => route('online-payment-store'),
|
||||
'errorUrl' => route('online-payment-store'),
|
||||
'successUrl' => route('online-payment-store-visa-master'),
|
||||
'errorUrl' => route('online-payment-store-visa-master'),
|
||||
'api_client' => config('app.url'),
|
||||
'username' => $resource->branch->billing_username,
|
||||
'paymentStatus' => OnlinePaymentRepo::PENDING,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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('visa_master_payment_orders', function (Blueprint $table) {
|
||||
$table->boolean('paid')->default(true);
|
||||
});
|
||||
|
||||
Schema::table('sber_payment_orders', function (Blueprint $table) {
|
||||
$table->boolean('paid')->default(true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('visa_master_payment_orders', function (Blueprint $table) {
|
||||
$table->dropColumn('paid');
|
||||
});
|
||||
|
||||
Schema::table('sber_payment_orders', function (Blueprint $table) {
|
||||
$table->dropColumn('paid');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -37,5 +37,8 @@ Route::middleware(['auth', 'unVerified'])->group(function () {
|
||||
});
|
||||
|
||||
Route::get('online-payment-store', [OnlinePaymentController::class, 'store'])->name('online-payment-store');
|
||||
Route::get('online-payment-store-visa-master', [
|
||||
OnlinePaymentController::class, 'visaMaster'
|
||||
])->name('online-payment-store-visa-master');
|
||||
|
||||
Route::redirect('/', config('nova.path'));
|
||||
|
||||
Reference in New Issue
Block a user