lets check online payment
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests\OnlinePaymentStoreRequest;
|
||||||
use App\Models\Payment\OnlinePaymentHistory;
|
use App\Models\Payment\OnlinePaymentHistory;
|
||||||
use App\Repos\Payment\OnlinePaymentRepo;
|
use App\Repos\Payment\OnlinePaymentRepo;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -76,70 +77,11 @@ class OnlinePaymentController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function visaMaster(Request $request)
|
public function visaMaster(OnlinePaymentStoreRequest $request)
|
||||||
{
|
{
|
||||||
// Validate the order id
|
$data = OnlinePaymentRepo::checkPayment($request);
|
||||||
if (
|
|
||||||
validator(
|
|
||||||
$request->all(),
|
|
||||||
['orderId' => ['required', 'string', 'max:50', 'exists:online_payment_histories,orderId']]
|
|
||||||
)->fails()
|
|
||||||
) {
|
|
||||||
return ['wrong order id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find order from history
|
return view(OnlinePaymentRepo::statusView(), $data);
|
||||||
$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_visa_master_username,
|
|
||||||
'password' => $resource->branch->billing_visa_master_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'),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sber(Request $request)
|
public function sber(Request $request)
|
||||||
|
|||||||
20
app/Http/Requests/OnlinePaymentStoreRequest.php
Normal file
20
app/Http/Requests/OnlinePaymentStoreRequest.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class OnlinePaymentStoreRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'orderId' => ['required', 'string', 'max:50', 'exists:online_payment_histories,orderId'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ use App\Repos\Order\OrderRepo;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Spatie\MediaLibrary\HasMedia;
|
use Spatie\MediaLibrary\HasMedia;
|
||||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||||
@@ -16,6 +17,7 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
|||||||
class VisaMasterPaymentOrder extends Model implements HasMedia
|
class VisaMasterPaymentOrder extends Model implements HasMedia
|
||||||
{
|
{
|
||||||
use InteractsWithMedia;
|
use InteractsWithMedia;
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table
|
* Table
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace App\Repos\Payment;
|
namespace App\Repos\Payment;
|
||||||
|
|
||||||
use App\Models\Payment\OnlinePaymentHistory;
|
use App\Models\Payment\OnlinePaymentHistory;
|
||||||
|
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Laravel\Nova\Makeable;
|
use Laravel\Nova\Makeable;
|
||||||
@@ -153,4 +155,79 @@ class OnlinePaymentRepo
|
|||||||
{
|
{
|
||||||
return 'orders.cards.online-payment.status';
|
return 'orders.cards.online-payment.status';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function checkPayment(Request $request)
|
||||||
|
{
|
||||||
|
// Find order from history
|
||||||
|
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||||
|
|
||||||
|
// Find related resource
|
||||||
|
$resource = VisaMasterPaymentOrderItem::where('online_payment_history_id', $paymentHistory->id)->first();
|
||||||
|
|
||||||
|
// If resource could not be found or does not exist, then inform it via logs
|
||||||
|
if (! $resource) {
|
||||||
|
static::logResourceNotFound($request, $paymentHistory);
|
||||||
|
|
||||||
|
return static::resourceNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
$resource->load('branch');
|
||||||
|
|
||||||
|
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||||
|
'language' => 'ru',
|
||||||
|
'orderId' => $request->orderId,
|
||||||
|
'userName' => $resource->branch->billing_visa_master_username,
|
||||||
|
'password' => $resource->branch->billing_visa_master_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 [
|
||||||
|
'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'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function logResourceNotFound($request, $paymentHistory): void
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function resourceNotFound(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'success' => false,
|
||||||
|
'title' => __('Payment has failed').' '.'(RESOURCE NOT FOUND)',
|
||||||
|
'pnr' => '',
|
||||||
|
'branch_name' => '',
|
||||||
|
'price_amount' => '',
|
||||||
|
'return_url' => url('/'),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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('visa_master_payment_orders', function (Blueprint $table) {
|
||||||
|
$table->softDeletes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('visa_master_payment_orders', function (Blueprint $table) {
|
||||||
|
$table->dropSoftDeletes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user