From 204b30276810206f2df512195355498b2af46a77 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Tue, 22 Apr 2025 20:05:40 +0500 Subject: [PATCH] wip --- app/Nova/Actions/CheckOnlinePaymentStatus.php | 84 +++++++++++++++++++ app/Nova/Resources/Order/Card/CardOrder.php | 6 ++ app/Repos/Order/Loan/LoanTypeRepo.php | 12 ++- 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 app/Nova/Actions/CheckOnlinePaymentStatus.php diff --git a/app/Nova/Actions/CheckOnlinePaymentStatus.php b/app/Nova/Actions/CheckOnlinePaymentStatus.php new file mode 100644 index 0000000..e085c7f --- /dev/null +++ b/app/Nova/Actions/CheckOnlinePaymentStatus.php @@ -0,0 +1,84 @@ +first(); + + $onlinePaymentResource = OnlinePaymentHistory::query() + ->where('online_paymantable_type', 'App\Models\Order\Card\CardOrder') + ->where('online_paymantable_id', $item->id) + ->first(); + + if (! $onlinePaymentResource) { + return Action::modal('modal-response', [ + 'title' => 'Onlaýn töleg taryhy ýok', + 'body' => 'Onlaýn töleg taryhy ýok', + ]); + } + + if (! $item->branch) { + return Action::modal('modal-response', [ + 'title' => 'Şahamça bilen birikdirilmedik', + 'body' => 'Şahamça bilen birikdirilmedik', + ]); + } + + $username = $item->branch->billing_username; + $password = $item->branch->billing_password; + + if (($username == '' || $password == '') || (is_null($username) || is_null($password))) { + return Action::modal('modal-response', [ + 'title' => 'HALKBANK API', + 'body' => 'Ulanyjy ady bilen açar sözi gabat gelmedi', + ]); + } + + $response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatusExtended.do', [ + 'language' => 'ru', + 'orderId' => $onlinePaymentResource->orderId, + 'userName' => $username, + 'password' => $password, + ]); + + return Action::modal('modal-response', [ + 'title' => 'HALKBANK API', + 'html' => CheckOnlinePayment::resultHTML($response), + ]); + } + + /** + * Get the fields available on the action. + * + * @param \Laravel\Nova\Http\Requests\NovaRequest $request + * @return array + */ + public function fields(NovaRequest $request) + { + return []; + } +} diff --git a/app/Nova/Resources/Order/Card/CardOrder.php b/app/Nova/Resources/Order/Card/CardOrder.php index 359f6ac..40122c9 100644 --- a/app/Nova/Resources/Order/Card/CardOrder.php +++ b/app/Nova/Resources/Order/Card/CardOrder.php @@ -5,6 +5,7 @@ namespace App\Nova\Resources\Order\Card; use App\Models\Branch\Branch; use App\Models\Order\Card\CardOrder as CardOrderModel; use App\Modules\CardOrder\Nova\Actions\RetryNovaCardOrderPayment; +use App\Nova\Actions\CheckOnlinePaymentStatus; use App\Nova\Filters\RegionFilter; use App\Nova\Filters\StatusFilter; use App\Nova\Forms\NovaForm; @@ -382,6 +383,11 @@ class CardOrder extends Resource ->onlyOnDetail() ->canSee(fn () => true) ->icon('credit-card'), + + (new CheckOnlinePaymentStatus()) + ->sole() + ->withoutConfirmation() + ->icon('server'), ]; } } diff --git a/app/Repos/Order/Loan/LoanTypeRepo.php b/app/Repos/Order/Loan/LoanTypeRepo.php index 340e4d3..054a59a 100644 --- a/app/Repos/Order/Loan/LoanTypeRepo.php +++ b/app/Repos/Order/Loan/LoanTypeRepo.php @@ -14,7 +14,11 @@ class LoanTypeRepo */ public static function values(): Collection|array { - return LoanType::where('active', true)->pluck('name', 'id'); + return cached( + 'loan-types-plucked', + LoanType::where('active', true)->pluck('name', 'id'), + 60 * 60, + ); } /** @@ -24,7 +28,11 @@ class LoanTypeRepo */ public static function onlyGuarantor(): Collection|array { - return LoanType::where('active', true)->where('id', static::loanTypeGuarantorId())->pluck('name', 'id'); + return cached( + 'only-guarantor-plucked', + LoanType::where('active', true)->where('id', static::loanTypeGuarantorId())->pluck('name', 'id'), + 60 * 60, + ); } /**