From 19abe08a902e1d800e3b4e518278f86025d7cf0f Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Sun, 16 Nov 2025 18:04:18 +0500 Subject: [PATCH] wip --- .../VisaMasterPaymentOrderResource.php | 1 - .../Repositories/CardOrderRepository.php | 2 +- .../HalkbankOnlinePaymentRepository.php | 14 +++++------ .../Repositories/OnlinePaymentRepository.php | 24 +++++++++++-------- .../Actions/PayVisaMasterPaymentAction.php | 2 -- .../VisaMasterPaymentOrderRepository.php | 2 +- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/app/Filament/Clusters/VisaMasterPayments/Resources/VisaMasterPaymentOrders/VisaMasterPaymentOrderResource.php b/app/Filament/Clusters/VisaMasterPayments/Resources/VisaMasterPaymentOrders/VisaMasterPaymentOrderResource.php index 02d72d8..ea10ad9 100644 --- a/app/Filament/Clusters/VisaMasterPayments/Resources/VisaMasterPaymentOrders/VisaMasterPaymentOrderResource.php +++ b/app/Filament/Clusters/VisaMasterPayments/Resources/VisaMasterPaymentOrders/VisaMasterPaymentOrderResource.php @@ -5,7 +5,6 @@ namespace App\Filament\Clusters\VisaMasterPayments\Resources\VisaMasterPaymentOr use App\Filament\Clusters\VisaMasterPayments\Resources\VisaMasterPaymentOrders\Pages\CreateVisaMasterPaymentOrder; use App\Filament\Clusters\VisaMasterPayments\Resources\VisaMasterPaymentOrders\Pages\EditVisaMasterPaymentOrder; use App\Filament\Clusters\VisaMasterPayments\Resources\VisaMasterPaymentOrders\Pages\ListVisaMasterPaymentOrders; -use App\Filament\Clusters\VisaMasterPayments\Resources\VisaMasterPaymentOrders\Pages\ViewVisaMasterPaymentOrder; use App\Filament\Clusters\VisaMasterPayments\Resources\VisaMasterPaymentOrders\Schemas\VisaMasterPaymentOrderForm; use App\Filament\Clusters\VisaMasterPayments\Resources\VisaMasterPaymentOrders\Tables\VisaMasterPaymentOrdersTable; use App\Filament\Clusters\VisaMasterPayments\VisaMasterPaymentsCluster; diff --git a/app/Modules/CardOrder/Repositories/CardOrderRepository.php b/app/Modules/CardOrder/Repositories/CardOrderRepository.php index 3e9f46b..19f2e88 100644 --- a/app/Modules/CardOrder/Repositories/CardOrderRepository.php +++ b/app/Modules/CardOrder/Repositories/CardOrderRepository.php @@ -19,7 +19,7 @@ class CardOrderRepository /** @var \App\Modules\Branch\Models\Branch */ $branch = $record->branch; - return OnlinePaymentRepository::make(relatedModel: $record) + return OnlinePaymentRepository::make(relatedModel: $record, apiClient: 'billing') ->setPaymentProvider( HalkbankOnlinePaymentRepository::make() ->setUsername($branch->billingUsername()) diff --git a/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php b/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php index 23c008a..02fe8d4 100644 --- a/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php +++ b/app/Modules/HalkbankOnlinePayment/Repositories/HalkbankOnlinePaymentRepository.php @@ -23,16 +23,16 @@ class HalkbankOnlinePaymentRepository implements PaymentProviderContract protected string $returnUrl = '', protected string $description = '', ) { - $this->username = $username === '' ? config()->string('module.halkbank-online-payment.username') : $username; - $this->password = $password === '' ? config()->string('module.halkbank-online-payment.password') : $password; - + $this->username = $username !== '' ? $username : config()->string('module.halkbank-online-payment.username'); + $this->password = $password !== '' ? $password : config()->string('module.halkbank-online-payment.password'); + $this->amount = $amount; - $this->orderNumber = $orderNumber === '' ? $this->generateOrderNumber() : $orderNumber; + $this->orderNumber = $orderNumber !== '' ? $orderNumber : $this->generateOrderNumber(); - $this->returnUrl = $returnUrl === '' ? config()->string('module.halkbank-online-payment.returnUrl') : $returnUrl; - - $this->description = $description === '' ? __('Payment') : $description; + $this->returnUrl = $returnUrl !== '' ? $returnUrl : config()->string('module.halkbank-online-payment.returnUrl'); + + $this->description = $description !== '' ? $description : __('Payment'); } /** diff --git a/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php b/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php index 38e3f5f..bde48bd 100644 --- a/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php +++ b/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php @@ -50,6 +50,11 @@ class OnlinePaymentRepository */ protected OnlinePayment $onlinePayment; + /** + * API client + */ + protected string $apiClient; + /** * If payment is successful */ @@ -70,9 +75,10 @@ class OnlinePaymentRepository */ protected string $paymentLink; - public function __construct(?Model $relatedModel = null) + public function __construct(?Model $relatedModel = null, string $apiClient = '') { $this->relatedModel = $relatedModel; + $this->apiClient = $apiClient; } /** @@ -253,19 +259,17 @@ class OnlinePaymentRepository /** @var \App\Modules\Branch\Models\Branch */ $bankBranch = $relatedResource->branch; - if (! $bankBranch || is_null($bankBranch->billing_username) || is_null($bankBranch->billing_password)) { // @phpstan-ignore-line - return $this->paymentFailed('(BRANCH NOT FOUND)'); + $username = $bankBranch->offsetExists($this->apiClient.'_username') ? $bankBranch->{$this->apiClient.'_username'} : ''; + $password = $bankBranch->offsetExists($this->apiClient.'_password') ? $bankBranch->{$this->apiClient.'_password'} : ''; + + if ($username === '' || $password === '') { + return $this->paymentFailed('(USERNAME OR PASSWORD NOT FOUND)'); } - $this->provider->setUsername($bankBranch->billing_username); - $this->provider->setPassword($bankBranch->billing_password); + $this->provider->setUsername($username); + $this->provider->setPassword($password); $response = $this->provider->checkPayment($orderId); - info([ - 'response' => $response, - 'body' => $response->body(), - ]); - if ($response['errorCode'] == '99') { return $this->paymentFailed('(REQUEST FAILURE)'); } diff --git a/app/Modules/VisaMasterPaymentOrder/Filament/Actions/PayVisaMasterPaymentAction.php b/app/Modules/VisaMasterPaymentOrder/Filament/Actions/PayVisaMasterPaymentAction.php index d651d3f..838c54e 100644 --- a/app/Modules/VisaMasterPaymentOrder/Filament/Actions/PayVisaMasterPaymentAction.php +++ b/app/Modules/VisaMasterPaymentOrder/Filament/Actions/PayVisaMasterPaymentAction.php @@ -4,7 +4,6 @@ namespace App\Modules\VisaMasterPaymentOrder\Filament\Actions; use App\Modules\CurrencyRate\Models\CurrencyRate; use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder; -use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterSettings; use App\Modules\VisaMasterPaymentOrder\Repositories\VisaMasterPaymentOrderRepository; use Filament\Actions\Action; use Filament\Forms\Components\TextInput; @@ -142,7 +141,6 @@ class PayVisaMasterPaymentAction $total_amount = $formData['payment_amount'] + $visaMasterPaymentOrderRepository->bankFee() + $visaMasterPaymentOrderRepository->gbusFee(); - $onlinePaymentRepository = $visaMasterPaymentOrderRepository->createOnlinePaymentOrder($record, $total_amount); if ($onlinePaymentRepository->failed()) { diff --git a/app/Modules/VisaMasterPaymentOrder/Repositories/VisaMasterPaymentOrderRepository.php b/app/Modules/VisaMasterPaymentOrder/Repositories/VisaMasterPaymentOrderRepository.php index 6d6bd08..939db35 100644 --- a/app/Modules/VisaMasterPaymentOrder/Repositories/VisaMasterPaymentOrderRepository.php +++ b/app/Modules/VisaMasterPaymentOrder/Repositories/VisaMasterPaymentOrderRepository.php @@ -87,7 +87,7 @@ class VisaMasterPaymentOrderRepository /** @var \App\Modules\Branch\Models\Branch */ $branch = $record->branch; - return OnlinePaymentRepository::make(relatedModel: $record) + return OnlinePaymentRepository::make(relatedModel: $record, apiClient: 'billing_visa_master') ->setPaymentProvider( HalkbankOnlinePaymentRepository::make( username: $branch->billing_visa_master_username,