Refactor payment processing: update method names for clarity, enhance VisaMasterPaymentOrderRepository with payment validation logic, and improve Turkish translations for payment notifications.
This commit is contained in:
@@ -5,11 +5,14 @@ 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;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Schemas\Components\Fieldset;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
use Livewire\Component;
|
||||
|
||||
class PayVisaMasterPaymentAction
|
||||
{
|
||||
@@ -28,8 +31,11 @@ class PayVisaMasterPaymentAction
|
||||
return [];
|
||||
}
|
||||
|
||||
$bank_fee = 20;
|
||||
$gbus_fee = 3;
|
||||
$visaMasterPaymentOrderRepository = VisaMasterPaymentOrderRepository::make();
|
||||
|
||||
$bankFee = $visaMasterPaymentOrderRepository->bankFee();
|
||||
$gbusFee = $visaMasterPaymentOrderRepository->gbusFee();
|
||||
|
||||
$max_value = number_format($usd_to_tmt * 250, 2);
|
||||
|
||||
return [
|
||||
@@ -46,11 +52,11 @@ class PayVisaMasterPaymentAction
|
||||
|
||||
TextEntry::make('bank_fee')
|
||||
->extraAttributes(['class' => 'uppercase tracking-wide font-bold text-xs'])
|
||||
->label(sprintf('Bankyň tutumy: %s TMT', $bank_fee)),
|
||||
->label(sprintf('Bankyň tutumy: %s TMT', $bankFee)),
|
||||
|
||||
TextEntry::make('gbus_fee')
|
||||
->extraAttributes(['class' => 'uppercase tracking-wide font-bold text-xs'])
|
||||
->label(sprintf('GBÜS tutumy: %s TMT', $gbus_fee)),
|
||||
->label(sprintf('GBÜS tutumy: %s TMT', $gbusFee)),
|
||||
]),
|
||||
|
||||
Fieldset::make()
|
||||
@@ -67,32 +73,94 @@ class PayVisaMasterPaymentAction
|
||||
->maxValue($max_value)
|
||||
->helperText(sprintf('Iň ýokary möçberi: %s TMT', $max_value))
|
||||
->live()
|
||||
->afterStateUpdated(function (Set $set, ?string $state) use ($usd_to_tmt) {
|
||||
->afterStateUpdated(function (Set $set, ?string $state) use ($usd_to_tmt, $bankFee, $gbusFee) {
|
||||
if (! $state || $state === 0 || $state === '') {
|
||||
$set('usd_rate', '');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$usd_rate = number_format($state / $usd_to_tmt, 2, '.', '');
|
||||
$total_amount = floatval(number_format($state, 2, '.', '')) + 23;
|
||||
$usd_rate = floatval(number_format($state / $usd_to_tmt, 2, '.', ''));
|
||||
$total_amount = floatval(number_format($state, 2, '.', '')) + $bankFee + $gbusFee;
|
||||
|
||||
$set('usd_rate', $usd_rate.' USD');
|
||||
$set('total_amount', $total_amount.' TMT');
|
||||
$set('usd_rate', $usd_rate);
|
||||
$set('total_amount', $total_amount);
|
||||
}),
|
||||
|
||||
TextEntry::make('usd_rate')
|
||||
->label(__('USD ekwalendi')),
|
||||
TextInput::make('usd_rate')
|
||||
->label(__('USD ekwalendi'))
|
||||
->suffix('USD')
|
||||
->readOnly(),
|
||||
|
||||
TextEntry::make('total_amount')
|
||||
->label(__('Total amount')),
|
||||
TextInput::make('total_amount')
|
||||
->label(__('Total amount'))
|
||||
->suffix('TMT')
|
||||
->readOnly(),
|
||||
]),
|
||||
|
||||
];
|
||||
})
|
||||
->action(function (array $data, VisaMasterPaymentOrder $record): void {
|
||||
// $record->author()->associate($data['authorId']);
|
||||
// $record->save();
|
||||
});
|
||||
->action(function (array $data, VisaMasterPaymentOrder $record, Component $livewire): void {
|
||||
/** @var array{payment_amount: float, usd_rate: float, total_amount: float} */
|
||||
$formData = $data;
|
||||
|
||||
$visaMasterPaymentOrderRepository = VisaMasterPaymentOrderRepository::make();
|
||||
|
||||
$today = today();
|
||||
|
||||
// Needs to be tested...
|
||||
if ($visaMasterPaymentOrderRepository->hasBeenPaidThisMonth($record, $today)) {
|
||||
Notification::make()
|
||||
->title(__('This month has already been paid').'!')
|
||||
->body(__('This month has already been paid'))
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Needs to be tested...
|
||||
if ($visaMasterPaymentOrderRepository->isEndOfMonth($today)) {
|
||||
Notification::make()
|
||||
->title(__('Payment cannot be accepted on the last day of the month').'!')
|
||||
->body(__('Payment cannot be accepted on the last day of the month'))
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Needs to be tested...
|
||||
if (! $record->branch || ! $record->branch->billing_visa_master_username) {
|
||||
Notification::make()
|
||||
->title(__('Contact with the operator').'!')
|
||||
->body(__('Billing information is not available in the branch! The branch cannot accept Visa/Master payments.'))
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$total_amount = $formData['payment_amount'] + $visaMasterPaymentOrderRepository->bankFee() + $visaMasterPaymentOrderRepository->gbusFee();
|
||||
|
||||
$onlinePaymentRepository = $visaMasterPaymentOrderRepository->createOnlinePaymentOrder($record, $total_amount);
|
||||
|
||||
if ($onlinePaymentRepository->failed()) {
|
||||
Notification::make()
|
||||
->title(__('Payment error').'!')
|
||||
->body(sprintf('%s. %s. %s.', __('Problem connecting on HALKBANK SYSTEM'), __('Error has been captured'), __('Please try again later')))
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$visaMasterPaymentOrderRepository->createPaymentRecord($record, $onlinePaymentRepository, $formData['usd_rate']);
|
||||
|
||||
// Tell Livewire to open it in a new tab
|
||||
$livewire->js("window.open('{$onlinePaymentRepository->paymentLink()}', '_blank')");
|
||||
|
||||
})
|
||||
->modalSubmitActionLabel(__('Pay'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user