{% extends 'shop/_layouts/checkout' %} {% block content %}

Payment

{# ╔══════════════════════════════════════════════════╗ ║ ┌───────────────────────────────────────────┐ ║ ║ │ Set up variables and check if we have any │ ║ ║ │ gateways set up. │ ║ ║ └───────────────────────────────────────────┘ ║ ╚══════════════════════════════════════════════════╝ #} {# Get the available payment sources the user has to be used later in this page. #} {% set storedCards = craft.commerce.paymentSources.allPaymentSourcesByUserId(currentUser.id ?? null) %} {# Get the available gateways to be used later in this page #} {% set availableGateways = craft.commerce.gateways.allCustomerEnabledGateways %} {# If there are no gateway then payment sources wont work either, so lets #} {% if availableGateways is empty %}

No payment methods available.

{% endif %} {# ╔══════════════════════════════════════════════════╗ ║ ┌───────────────────────────────────────────┐ ║ ║ │ This form updates the order with the │ ║ ║ │ preferred payment source or gateway, as │ ║ ║ │well as allowing the selection of a payment│ ║ ║ │ currency if more than one is set up. │ ║ ║ └───────────────────────────────────────────┘ ║ ╚══════════════════════════════════════════════════╝ #}

Update Cart

{% if availableGateways|length %}
{{ redirectInput('shop/checkout/payment') }} {{ csrfInput() }} {% set currencies = craft.commerce.paymentCurrencies.allPaymentCurrencies %} {% if currencies|length > 1 %} {% endif %}
{% endif %} {% js %} // If the payment currency changes, submit the form immediately $('#paymentCurrency').change(function(){ $('form#paymentPreferenceForm').submit(); }); $('#paymentMethod').change(function(ev){ $select = $(ev.currentTarget); $("#cart-update-spinner").toggleClass('hidden'); if ($select.val().length === 0) { return; } var parts = $select.val().split(':'); var name = parts[0]; // get the form param NAME from the select value. Format: 'gatewayId:2' or 'paymentSourceId:1' var value = parts[1]; // // get the form param VALUE from the select value. Format: 'gatewayId:2' or 'paymentSourceId:1' $select.prop('disabled', 'disabled'); $('form#paymentPreferenceForm').append('').submit(); $('form#paymentPreferenceForm').append('').submit(); }); {% endjs %} {# ╔══════════════════════════════════════════════════╗ ║ ┌───────────────────────────────────────────┐ ║ ║ │ This makes payment using the │ ║ ║ │ payment form. │ ║ ║ └───────────────────────────────────────────┘ ║ ╚══════════════════════════════════════════════════╝ #} {% if cart.gatewayId or cart.paymentSourceId %}

Payment Form

{% if paymentForm is defined %} {% for key, errors in paymentForm.getErrors() %} {% for error in errors %} {% if loop.first %}{% endif %} {% endfor %} {% endfor %} {% endif %}
{{ redirectInput('/shop/customer/order?number='~cart.number~'&success=true') }} {{ csrfInput() }} {% if cart.gatewayId %} {% set params = {} %} {# Set gateway specific parameters #} {% if className(cart.gateway) == 'craft\\commerce\\paypalcheckout\\gateways\\Gateway' %} {% set params = { currency: cart.paymentCurrency } %} {% endif %} {{ cart.gateway.getPaymentFormHtml(params)|raw }} {% if cart.gateway.supportsPaymentSources() and currentUser %}

{% endif %} {% else %} {{ cart.gateway.getPaymentConfirmationFormHtml({})|raw }} {% endif %} {% set user = craft.users.email(cart.email).one() %} {% if not user %} {% endif %}
{% endif %}
{% include "shop/_includes/order-review" with { showShippingAddress: true, showShippingMethod: true } %}
{% js %} $('#paymentForm').on('submit', function (ev) { $form = $(this); if ($form.data('processing')) { ev.preventDefault(); return false; } $form.data('processing', true); }); {% endjs %} {% endblock %}