{% extends 'shop/_layouts/checkout' %} {% set number = craft.app.request.getParam('orderNumber') %} {% set email = craft.app.request.getParam('email') %} {% set paymentMethod = craft.app.request.getParam('paymentMethod') %} {% set paymentCurrency = craft.app.request.getParam('paymentCurrency') %} {% set url = 'shop/checkout/pay-static' %} {% block content %} {% set cart = null %} {% if number and email %} {% set cart = craft.orders.number(number).email(email).one() ?? null %} {% endif %}

Cart/Order Payment

{# Show form to be filled out allowing access to the payment form. #} {% if (not number or not email) or (number and email and (not cart or (cart and not cart.hasOutstandingBalance))) %} {# Display errors if cart cannot be retrieved or if there is no outstanding balance to be paid. #} {% if number and email and (not cart or (cart and not cart.hasOutstandingBalance)) %}
{% if cart and not cart.hasOutstandingBalance %} No outstanding balance on this order. {% else %} Unable to retrieve order. {% endif %}
{% endif %}

Enter cart/order number and corresponding email address to be able to pay.

{% else %} {% set customer = cart.customer ?? null %} {# Display payment form. #} {% if not paymentMethod %} {# Get the available payment sources the user has to be used later in this page. #} {% set storedCards = null %} {% if customer and customer.userId and currentUser and currentUser.id == customer.userId %} {% set storedCards = craft.commerce.paymentSources.allPaymentSourcesByUserId(currentUser.id) %} {% endif %} {# Get the available gateways to be used later in this page #} {% set availableGateways = craft.commerce.gateways.allCustomerEnabledGateways %} {% if availableGateways|length %}

Select a payment method:

{% set currencies = craft.commerce.paymentCurrencies.allPaymentCurrencies %} {% if currencies|length > 1 %} {% endif %}
{% endif %} {% else %} {% do cart.setPaymentCurrency(paymentCurrency) %} {% set canPay = true %}
{{ redirectInput('/shop/customer/order?number='~cart.number~'&success=true') }} {{ csrfInput() }}
{% set paymentMethodParts = paymentMethod|split(':') %} {% if paymentMethodParts[0] == 'gateway' %} {% set gateway = craft.commerce.gateways.getGatewayById(paymentMethodParts[1]) ?? null %} {% if not gateway %} {% set canPay = false %}
Unable to retrieve gateway.
{% else %} {% set params = {} %} {# Set gateway specific parameters #} {% if className(gateway) == 'craft\\commerce\\paypalcheckout\\gateways\\Gateway' %} {% set params = { currency: cart.paymentCurrency } %} {% endif %} {{ gateway.getPaymentFormHtml(params)|raw }} {% if gateway.supportsPaymentSources() and currentUser and customer.userId and customer.userId == currentUser.id %}

{% endif %} {% endif %} {% elseif paymentMethodParts[0] == 'card' %} {% set paymentSource = craft.commerce.paymentSources.getPaymentSourceById(paymentMethodParts[1]) ?? null %} {% if not paymentSource or not currentUser or (currentUser and currentUser.id != customer.userId) %} {% set canPay = false %}
Payment source not applicable for current user.
{% else %}

Pay with: {{ paymentSource.description }}

{% endif %} {% endif %}
{% if canPay %} {% endif %}
{% endif %} {% endif %}
{% if cart %} {% include "shop/_includes/order-review" with { showShippingAddress: true, showShippingMethod: true, cart: cart } %} {% endif %}
{% js %} $('#paymentForm').on('submit', function (ev) { $form = $(this); if ($form.data('processing')) { ev.preventDefault(); return false; } $form.data('processing', true); }); {% endjs %} {% endblock %}