diff --git a/app/Http/Controllers/MetricsController.php b/app/Http/Controllers/MetricsController.php index 82607bf..a09233c 100644 --- a/app/Http/Controllers/MetricsController.php +++ b/app/Http/Controllers/MetricsController.php @@ -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 { diff --git a/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrder.php b/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrder.php index 013351e..379f706 100644 --- a/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrder.php +++ b/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrder.php @@ -168,4 +168,12 @@ class VisaMasterPaymentOrder extends Model implements HasMedia static::creating(LoanOrderRepo::creating()); } + + /** + * Price for order + */ + public function priceAmount(): float + { + return 250; + } } diff --git a/app/Modules/VisaMasterPaymentOrder/Nova/Resources/Concerns/VisaMasterPaymentOrderFieldsForDetail.php b/app/Modules/VisaMasterPaymentOrder/Nova/Resources/Concerns/VisaMasterPaymentOrderFieldsForDetail.php index 78f33c7..72c36fb 100644 --- a/app/Modules/VisaMasterPaymentOrder/Nova/Resources/Concerns/VisaMasterPaymentOrderFieldsForDetail.php +++ b/app/Modules/VisaMasterPaymentOrder/Nova/Resources/Concerns/VisaMasterPaymentOrderFieldsForDetail.php @@ -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') diff --git a/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrder.php b/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrder.php index 5907fb6..bc7c238 100644 --- a/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrder.php +++ b/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrder.php @@ -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(), + ]; + } } diff --git a/app/Nova/Actions/MakePaymentNovaVisaMaster.php b/app/Nova/Actions/MakePaymentNovaVisaMaster.php new file mode 100644 index 0000000..d154628 --- /dev/null +++ b/app/Nova/Actions/MakePaymentNovaVisaMaster.php @@ -0,0 +1,120 @@ +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'], + ]; + } +} diff --git a/app/Repos/Payment/OnlinePaymentRepo.php b/app/Repos/Payment/OnlinePaymentRepo.php index 14db7d8..54f350a 100644 --- a/app/Repos/Payment/OnlinePaymentRepo.php +++ b/app/Repos/Payment/OnlinePaymentRepo.php @@ -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. */ diff --git a/composer.json b/composer.json index 25b90f7..5786d82 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "php": "^8.1", "dedoc/scramble": "^0.11.11", "denniseilander/pulse-about-application": "^0.1.1", + "digital-creative/icon-action-toolbar": "^0.1.2", "ebess/advanced-nova-media-library": "^4.2", "eminiarts/nova-tabs": "*", "eolica/nova-locale-switcher": "dev-support-nova-4", diff --git a/composer.lock b/composer.lock index a465bdf..6f4f4c6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a659769fcebee0f25a04da70449c4ac0", + "content-hash": "68508766b98f10cf8e0c0188d45a572e", "packages": [ { "name": "adoy/fastcgi-client", @@ -606,6 +606,65 @@ }, "time": "2024-07-08T12:26:09+00:00" }, + { + "name": "digital-creative/icon-action-toolbar", + "version": "v0.1.2", + "source": { + "type": "git", + "url": "https://github.com/dcasia/icon-action-toolbar.git", + "reference": "2929c90d153553c0bc1d6072d8bdca4399848f23" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dcasia/icon-action-toolbar/zipball/2929c90d153553c0bc1d6072d8bdca4399848f23", + "reference": "2929c90d153553c0bc1d6072d8bdca4399848f23", + "shasum": "" + }, + "require": { + "laravel/nova": "^4.28.0", + "php": ">=8.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "DigitalCreative\\IconActionToolbar\\IconActionToolbarServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "DigitalCreative\\IconActionToolbar\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Rafael Milewski" + } + ], + "description": "Allows you to update a single column of a resource all at once.", + "keywords": [ + "batch-edit", + "laravel", + "nova", + "toolbar" + ], + "support": { + "issues": "https://github.com/dcasia/icon-action-toolbar/issues", + "source": "https://github.com/dcasia/icon-action-toolbar/tree/v0.1.2" + }, + "funding": [ + { + "url": "https://github.com/milewski", + "type": "github" + } + ], + "time": "2024-03-06T08:23:56+00:00" + }, { "name": "doctrine/cache", "version": "2.2.0", diff --git a/lang/tk.json b/lang/tk.json index c09bbc6..871c971 100644 --- a/lang/tk.json +++ b/lang/tk.json @@ -313,5 +313,8 @@ "Guarantor Patronic name": "Zamunyň atasynyň ady", "Satisfiable": "Kanagatlanarly", "Insufficient": "Kanagatlanarsyz", - "Unknown": "Näbelli" + "Unknown": "Näbelli", + "Sber payments": "Sber tölegler", + "Sber payment": "Sber töleg", + "Select payment method": "Töleg görnüşini saýlaň" } diff --git a/routes/api.php b/routes/api.php index e6b6022..c594a5c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -7,7 +7,6 @@ use App\Modules\BaseAppEnum\Controllers\BaseAppEnumController; use App\Modules\Branch\Controllers\BranchController; use App\Modules\LoanOrder\Controllers\LoanOrderController; use App\Modules\Province\Controllers\ProvinceController; -use ArchTech\Enums\Meta\Meta; use Illuminate\Support\Facades\Route; /*