add f payment

This commit is contained in:
2024-09-30 08:22:34 +05:00
parent c3b3691ca5
commit e8515d95c9
10 changed files with 212 additions and 4 deletions

View File

@@ -5,7 +5,6 @@ namespace App\Http\Controllers;
use App\Models\Order\Loan\LoanOrder;
use App\Repos\Order\OrderRepo;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class MetricsController extends Controller
{

View File

@@ -168,4 +168,12 @@ class VisaMasterPaymentOrder extends Model implements HasMedia
static::creating(LoanOrderRepo::creating());
}
/**
* Price for order
*/
public function priceAmount(): float
{
return 250;
}
}

View File

@@ -61,6 +61,9 @@ class VisaMasterPaymentOrderFieldsForDetail
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $resource),
]),
new Panel(__('Payment'), [
]),
new Panel(__('Application type'), [
Select::make(__('Application type'), 'type')

View File

@@ -6,6 +6,7 @@ use App\Models\Branch\Branch;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder;
use App\Modules\VisaMasterPaymentOrder\Nova\Resources\Concerns\VisaMasterPaymentOrderFieldsForDetail;
use App\Modules\VisaMasterPaymentOrder\Nova\Resources\Concerns\VisaMasterPaymentOrderFieldsForIndex;
use App\Nova\Actions\MakePaymentNovaVisaMaster;
use App\Nova\Resource;
use App\Repos\Order\Card\CardOrderRepo;
use App\Repos\Order\OrderRepo;
@@ -333,4 +334,16 @@ class NovaVisaMasterPaymentOrder extends Resource
]),
];
}
/**
* Actions
*/
public function actions(NovaRequest $request): array
{
return [
MakePaymentNovaVisaMaster::make()
->icon('credit-card')
->sole(),
];
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace App\Nova\Actions;
use App\Models\Payment\OnlinePaymentHistory;
use App\Repos\Payment\OnlinePaymentRepo;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Actions\ActionResponse;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Http\Requests\NovaRequest;
class MakePaymentNovaVisaMaster extends Action
{
use InteractsWithQueue, Queueable;
/**
* Perform the action on the given models.
*
* @param \Laravel\Nova\Fields\ActionFields $fields
* @param \Illuminate\Support\Collection $models
* @return mixed
*/
public function handle(ActionFields $fields, Collection $models)
{
$resource = $models->first();
$payment = $this->order($resource, $fields->payment_method);
if (! $resource->branch) {
return ActionResponse::danger('Şahamça visa/master tölegi kabul edip bilmeýär.');
}
return $payment['status'] === 'success'
? ActionResponse::redirect($payment['url'])
: ActionResponse::danger('Töleg ýerinde näsazlyk!');
}
/**
* Get the fields available on the action.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request): array
{
return [
Select::make(__('Select payment method'), 'payment_method')
->displayUsingLabels()
->searchable()
->options([
'usd' => __('USD'),
'rubl' => __('RUBL'),
])
->rules('required')
->fullWidth(),
];
}
/**
* Order a payment page
*/
public function order($resource, $paymentMethod)
{
$onlinePaymentRepo = OnlinePaymentRepo::make();
$orderNumber = $onlinePaymentRepo->generateOrderNumber();
$paymentResponse = Http::get('https://mpi.gov.tm/payment/rest/register.do', [
'orderNumber' => $orderNumber,
'amount' => $onlinePaymentRepo->getPrice($paymentMethod == 'usd' ? '902.38' : '1058,60'),
'currency' => 934,
'language' => 'ru',
'userName' => $resource->branch->billing_username,
'password' => $resource->branch->billing_password,
'returnUrl' => route('online-payment-store'),
'pageView' => 'DESKTOP',
'description' => 'Kart tölegi',
])->onError(function ($response) {
Log::channel('halkbank_payment_error')
->error('Payment error', [
'response' => [
'body' => $response->body(),
],
]);
});
if ($paymentResponse->failed()) {
return [
'status' => 'failed',
'url' => '',
];
}
OnlinePaymentHistory::create([
'online_paymantable_id' => $resource->id,
'online_paymantable_type' => $resource::$model,
'amount' => $resource->priceAmount(),
'orderNumber' => $orderNumber,
'description' => 'Kart tölegi',
'orderId' => $paymentResponse['orderId'],
'formUrl' => $paymentResponse['formUrl'],
'successUrl' => route('online-payment-store'),
'errorUrl' => route('online-payment-store'),
'api_client' => config('app.url'),
'username' => $resource->branch->billing_username,
'paymentStatus' => OnlinePaymentRepo::PENDING,
]);
return [
'status' => 'success',
'url' => $paymentResponse['formUrl'],
];
}
}

View File

@@ -5,9 +5,12 @@ namespace App\Repos\Payment;
use App\Models\Payment\OnlinePaymentHistory;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Laravel\Nova\Makeable;
class OnlinePaymentRepo
{
use Makeable;
/**
* Pending orders are brand new orders that have not been processed yet.
*/