where('currency_to', 'TMT')->first('value'); if (! $usd_to_tmt) { return ActionResponse::danger('Walýuta hasaby girizilmedik, operator bilen habarlaşmagyňyzy haýyş edýärin.'); } $resource = $models->first(); if (! $resource->branch || ! $resource->branch->billing_sber_username) { return ActionResponse::danger('Şahamça sber tölegi kabul edip bilmeýär.'); } $tvebTaxTMT = $usd_to_tmt->value * 18; $bankTax = 120.75; $total_amount = number_format($fields->payment_amount + $tvebTaxTMT + $bankTax, 2, '.', ''); $payment = $this->order($resource, $total_amount); return $payment['status'] === 'success' ? ActionResponse::openInNewTab($payment['url']) : ActionResponse::danger('Töleg ýerinde näsazlyk!'); } /** * Get the fields available on the action. * * @param \Laravel\Nova\Http\Requests\NovaRequest $request * @return array */ public function fields(NovaRequest $request) { $usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value'); $usd_to_rub = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'RUB')->first('value')?->value; $rub_to_tmt = CurrencyRate::where('currency_from', 'RUB')->where('currency_to', 'TMT')->first('value')?->value; if (! $usd_to_tmt || ! $usd_to_rub || ! $rub_to_tmt) { return []; } $max_value = number_format($usd_to_rub * 250 * $rub_to_tmt, 2, '.', ''); $tvebTaxTMT = $usd_to_tmt->value * 18; $bankTax = 120.75; return [ Heading::make(Blade::render(<<1 USD = $usd_to_tmt->value TMT

1 RUB = $rub_to_tmt TMT


TVEB USD tutumy: 18 USD

TVEB tutumy TMT = $tvebTaxTMT TMT


Bank tutumy: $bankTax TMT

HTML))->asHtml(), Text::make(sprintf('%s (%s)', __('Töleg möçberi'), __('TMT')), 'payment_amount') ->fullWidth() ->required() ->rules('required', 'numeric', 'max:'.$max_value) ->help("Iň ýokary möçberi: {$max_value} TMT"), Text::make(__('USD ekwalendi'), 'usd_rate') ->fullWidth() ->readonly() ->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_rub, $rub_to_tmt) { if ($formData->payment_amount) { $usdValue = number_format($formData->payment_amount / ($usd_to_rub * $rub_to_tmt), 2, '.', ''); $field->setValue($usdValue); } else { $field->setValue(''); } }), Text::make(__('Jemi (TMT)'), 'total_amount') ->fullWidth() ->readonly() ->dependsOn('payment_amount', function ($field, $request, $formData) use ($tvebTaxTMT, $bankTax) { if (is_numeric($formData->payment_amount)) { $field->setValue( number_format($formData->payment_amount + $tvebTaxTMT + $bankTax, 2, '.', '') ); } else { $field->setValue(''); } }), ]; } /** * Order a payment page */ public function order($resource, $amount) { $onlinePaymentRepo = OnlinePaymentRepo::make(); $orderNumber = $onlinePaymentRepo->generateOrderNumber($resource); $paymentResponse = Http::get('https://mpi.gov.tm/payment/rest/register.do', [ 'orderNumber' => $orderNumber, 'amount' => number_format($amount, 2, '', ''), 'currency' => 934, 'language' => 'ru', 'userName' => $resource->branch->billing_sber_username, 'password' => $resource->branch->billing_sber_password, 'returnUrl' => route('online-payment-store-sber'), 'pageView' => 'DESKTOP', 'description' => 'Sber tölegi', ])->onError(function ($response) { Log::channel('halkbank_payment_error') ->error('Payment error', [ 'response' => [ 'body' => $response->body(), ], ]); }); if ($paymentResponse->failed()) { return [ 'status' => 'failed', 'url' => '', ]; } OnlinePaymentHistory::create([ 'online_paymantable_id' => $resource->id, 'online_paymantable_type' => SberPaymentOrder::class, 'amount' => number_format($amount, 2, '', ''), 'orderNumber' => $orderNumber, 'description' => 'Sber tölegi', 'orderId' => $paymentResponse['orderId'], 'formUrl' => $paymentResponse['formUrl'], 'successUrl' => route('online-payment-store-sber'), 'errorUrl' => route('online-payment-store-sber'), 'api_client' => 'billing_sber_username', 'username' => $resource->branch->billing_sber_username, 'paymentStatus' => OnlinePaymentRepo::PENDING, ]); return [ 'status' => 'success', 'url' => $paymentResponse['formUrl'], ]; } }