Online payment controller sber

This commit is contained in:
2024-11-25 21:32:46 +05:00
parent ca31fc189e
commit f9cc2792c3
3 changed files with 17 additions and 23 deletions

View File

@@ -31,14 +31,15 @@ class MakeSberPaymentAction extends Action
public function handle(ActionFields $fields, Collection $models): mixed
{
$usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value');
$payment_amount = floatval($fields->get('payment_amount'));
$usd_payment = $fields->get('usd_payment');
if (! $usd_to_tmt || ! property_exists($fields, 'payment_amount') || ! property_exists($fields, 'usd_payment')) {
if (! $usd_to_tmt || ! $payment_amount || ! $usd_payment) {
return ActionResponse::danger('Walýuta hasaby girizilmedik, operator bilen habarlaşmagyňyzy haýyş edýärin.');
}
$today = today();
$resource = $models->first();
$payment_amount = floatval($fields->payment_amount);
$hasBeenPaid = false;
$resource->paymentItems->each(function ($item) use (&$hasBeenPaid, $today) {
@@ -83,7 +84,7 @@ class MakeSberPaymentAction extends Action
]);
}
$this->createPaymentRecord($payment, $resource, $total_amount, $fields->usd_payment);
$this->createPaymentRecord($payment, $resource, $total_amount, $usd_payment);
return ActionResponse::openInNewTab($payment['url']);
}
@@ -129,8 +130,10 @@ class MakeSberPaymentAction extends Action
->fullWidth()
->readonly()
->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_rub, $rub_to_tmt) {
if (property_exists($formData, 'payment_amount')) {
$usdValue = number_format($formData->payment_amount / ($usd_to_rub * $rub_to_tmt), 2, '.', '');
$payment_amount = $formData->get('payment_amount');
if ($payment_amount) {
$usdValue = number_format($payment_amount / ($usd_to_rub * $rub_to_tmt), 2, '.', '');
$field->setValue($usdValue);
} else {
@@ -140,8 +143,10 @@ class MakeSberPaymentAction extends Action
Hidden::make('usd_payment')
->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_rub, $rub_to_tmt) {
if (property_exists($formData, 'payment_amount')) {
$usdValue = number_format($formData->payment_amount / ($usd_to_rub * $rub_to_tmt), 2, '.', '');
$payment_amount = $formData->get('payment_amount');
if ($payment_amount) {
$usdValue = number_format($payment_amount / ($usd_to_rub * $rub_to_tmt), 2, '.', '');
$field->setValue($usdValue);
} else {
@@ -153,9 +158,11 @@ class MakeSberPaymentAction extends Action
->fullWidth()
->readonly()
->dependsOn('payment_amount', function ($field, $request, $formData) use ($tvebTaxTMT, $bankTax) {
if (property_exists($formData, 'payment_amount')) {
$payment_amount = $formData->get('payment_amount');
if ($payment_amount) {
$field->setValue(
number_format($formData->payment_amount + $tvebTaxTMT + $bankTax, 2, '.', '')
number_format($payment_amount + $tvebTaxTMT + $bankTax, 2, '.', '')
);
} else {
$field->setValue('');