@php /* * Normalize the checkout currency through the central currency helper. */ $checkoutCurrency = currency_code( $checkout->currency_code ?? $paymentSettings->default_currency ?? null ); $checkoutTotal = (float) ( $checkout->grand_total ?? 0 ); $formattedCheckoutTotal = money( $checkoutTotal, $checkoutCurrency ); $formattedWalletBalance = money( (float) ($walletBalance ?? 0), $checkoutCurrency ); /* * Normalize legacy bank-transfer account formats. */ $rawBankAccounts = $paymentSettings->bank_transfer_accounts ?? []; if (is_string($rawBankAccounts)) { $decodedBankAccounts = json_decode( $rawBankAccounts, true ); $rawBankAccounts = is_array($decodedBankAccounts) ? $decodedBankAccounts : []; } $bankAccounts = collect($rawBankAccounts) ->filter( static function ($account): bool { return is_array($account) && ( filled($account['bank_name'] ?? null) || filled($account['account_name'] ?? null) || filled($account['account_number'] ?? null) ); } ) ->values(); /* * Normalize available payment methods into a collection. */ $paymentMethods = collect( $availablePaymentMethods ?? [] ); /* * Restore the previously selected method after a validation error. * If none was selected, choose the first usable payment method. */ $selectedPaymentMethod = old('payment_method'); if ( blank($selectedPaymentMethod) || ! $paymentMethods->has($selectedPaymentMethod) ) { $selectedPaymentMethod = $paymentMethods ->keys() ->first( static function ($key) use ( $walletCanCoverCheckout ): bool { return $key !== 'wallet' || (bool) $walletCanCoverCheckout; } ); } @endphp
@csrf {{-- JavaScript assigns the appropriate names and values before submitting to the selected payment controller. --}}
{{ __('Payment Method') }}
@if($paymentMethods->isEmpty())
{{ __( 'No payment method is currently available for this checkout.' ) }}
@else @error('payment_method')
{{ $message }}
@enderror @error('method')
{{ $message }}
@enderror @error('provider')
{{ $message }}
@enderror
@foreach($paymentMethods as $key => $label) @php $key = (string) $key; $isWallet = $key === 'wallet'; $isBankTransfer = $key === 'bank_transfer'; $isCod = $key === 'cash_on_delivery'; $isGateway = ! $isWallet && ! $isBankTransfer && ! $isCod; $walletUnavailable = $isWallet && ! (bool) $walletCanCoverCheckout; $isSelected = $selectedPaymentMethod === $key && ! $walletUnavailable; $providerIcon = match ($key) { 'wallet' => 'fas fa-wallet', 'bank_transfer' => 'fas fa-university', 'cash_on_delivery' => 'fas fa-money-bill-wave', 'paypal' => 'fab fa-paypal', 'paystack' => 'fas fa-credit-card', 'flutterwave' => 'fas fa-credit-card', default => 'fas fa-credit-card', }; @endphp
@if( $isBankTransfer && $bankAccounts->isNotEmpty() ) @endif @endforeach
@endif
@if($paymentMethods->isNotEmpty())
@endif
@push('styles') @endpush @push('scripts') @endpush