diff --git a/app/Http/Controllers/OnlinePaymentController.php b/app/Http/Controllers/OnlinePaymentController.php index 2597b10..971845b 100644 --- a/app/Http/Controllers/OnlinePaymentController.php +++ b/app/Http/Controllers/OnlinePaymentController.php @@ -5,7 +5,6 @@ namespace App\Http\Controllers; use App\Http\Requests\OnlinePaymentStoreRequest; use App\Models\Payment\OnlinePaymentHistory; use App\Repos\Payment\OnlinePaymentRepo; -use Illuminate\Http\Request; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; @@ -13,16 +12,9 @@ class OnlinePaymentController extends Controller { /** * Online payment - * - * @param Request $request */ - public function store(Request $request) + public function store(OnlinePaymentStoreRequest $request) { - // Validate the order id - if (validator($request->all(), ['orderId' => ['required', 'string', 'max:50', 'exists:online_payment_histories,orderId']])->fails()) { - return ['wrong order id']; - } - // Find order from history $paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first(); diff --git a/app/Nova/Actions/MakeSberPaymentAction.php b/app/Nova/Actions/MakeSberPaymentAction.php index cfbbfb0..88adde3 100644 --- a/app/Nova/Actions/MakeSberPaymentAction.php +++ b/app/Nova/Actions/MakeSberPaymentAction.php @@ -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(''); diff --git a/app/Repos/Payment/OnlinePaymentRepo.php b/app/Repos/Payment/OnlinePaymentRepo.php index 3188c1f..828deeb 100644 --- a/app/Repos/Payment/OnlinePaymentRepo.php +++ b/app/Repos/Payment/OnlinePaymentRepo.php @@ -2,7 +2,6 @@ namespace App\Repos\Payment; -use App\Models\Branch\Branch; use App\Models\Payment\OnlinePaymentHistory; use App\Repos\Payment\Sber\HandlesSberPeyments; use App\Repos\Payment\VisaMaster\HandlesVisaMasterPayments; @@ -198,10 +197,6 @@ class OnlinePaymentRepo /** * Failed payment response - * - * @param $paymentHistory - * @param $bank_branch - * @param $resource */ public static function failedPaymentResponse($paymentHistory, $bank_branch, $resource, $returnURL) {