{#
╔══════════════════════════════════════════════════╗
║ ┌───────────────────────────────────────────┐ ║
║ │ 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 %}
{% 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 %}