{% set currentYear = date()|date_modify("+1 year").format('Y') %}
{% if order %} {{ redirectInput(order.cpEditUrl) }} {% endif %} {{ csrfInput() }} {{ formHtml|raw }}
Payment Amount
{% set currencies = craft.commerce.paymentCurrencies.getAllPaymentCurrencies() %} {% set primaryCurrency = craft.commerce.paymentCurrencies.getPrimaryPaymentCurrency() %} {% if currencies|length > 1 %} {% else %} {% endif %} {{ 'Pay {amount} of {currency} on the order.'|t('commerce', {'amount' : order.outstandingBalanceAsCurrency, 'currency' : order.currency}) }}

{% js %} var primaryBaseCurrency = '{{ primaryCurrency.iso }}'; var paymentAmount = '{{ order.getpaymentAmount() }}'; var orderId = '{{ order.id }}'; function debounce(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }; function updatePrice(form) { var price = form.find("input.paymentAmount").val(); $.ajax({ type: "POST", dataType: 'json', headers: { "X-CSRF-Token" : '{{ craft.app.request.csrfToken }}', }, url: '', data: { 'action' : 'commerce/orders/payment-amount-data', 'paymentAmount': price, 'paymentCurrency': form.find(".paymentCurrency").val(), 'orderId' : orderId }, success: function(data){ console.log(data); form.find(".baseCurrencyAmount").html(data.baseCurrencyPaymentAmountAsCurrency); form.find(".response-message").html(data.message); window.dispatchEvent(new Event('resize')); form.find('.submit-payment').prop('disabled', false); } }); } $("input.paymentAmount").bind('keyup mouseup', debounce(function(){ var $input = $(this); var $form = $input.closest('form') var newVal = $form.find("input.paymentAmount").val(); if(!newVal) { newVal = paymentAmount; $form.find("input.paymentAmount").val(newVal); } updatePrice($form); },500)); $("select.paymentCurrency").each(function( index ) { var $form = $(this.form); $(this).on('change', function() { console.log('change'); updatePrice($form); }); }); {% endjs %}