diff --git a/src/templates/checkout/payment.twig b/src/templates/checkout/payment.twig index 078cd7a..e3edd12 100644 --- a/src/templates/checkout/payment.twig +++ b/src/templates/checkout/payment.twig @@ -5,7 +5,7 @@ {% set addresses = currentUser ? (currentUser.addresses.all() ?? null) : null %}
+ v-scope="{ gatewayId: {{ cart.gatewayId ? cart.gatewayId : 1 }}, billingSameAsShipping: {{ cart.hasMatchingAddresses() ? 1 : 0 }}, addressBookBillingAddress: 0, newBillingAddress: {{ cart.hasMatchingAddresses() ? 0 : 1 }}, billingAddressId: {{ cart.billingAddressId ?? cart.shippingAddressId ?? 'null'}} }">

{{ 'Checkout'|t('foster-checkout') }}

@@ -35,7 +35,7 @@
+ :disabled="parseInt(billingSameAsShipping) === 0"/>
@@ -171,63 +171,79 @@
{% for gateway in gateways %} -
-
- - -
-
-
- {{ csrfInput() }} - {{ actionInput('commerce/payments/pay') }} - {{ redirectInput(craft.fostercheckout.getPath('checkout') ~ '/order') }} - {{ redirectInput(siteUrl(craft.fostercheckout.getPath('checkout') ~ '/order', { - number: cart.uid, - success: 'true' - })) }} - {{ hiddenInput('cancelUrl', siteUrl(craft.fostercheckout.getPath('checkout') ~ '/payment')|hash) }} - {{ hiddenInput('orderEmail', cart.email) }} - - - - {% set params = {} %} - - {# Special params for Paypal checkout #} - {% if className(gateway) == 'craft\\commerce\\paypalcheckout\\gateways\\Gateway' %} - {% set params = { currency: cart.paymentCurrency } %} - {% endif %} + {% set gatewayClass = className(gateway) %} + {% + set shouldRender = cart.total == 0 and gatewayClass == 'craft\\commerce\\gateways\\Manual' + or cart.total > 0 and gatewayClass != 'craft\\commerce\\gateways\\Manual' + %} + {% if shouldRender %} +
+
+ + +
+
+ + {{ csrfInput() }} + {{ actionInput('commerce/payments/pay') }} + {{ redirectInput(craft.fostercheckout.getPath('checkout') ~ '/order') }} + {{ redirectInput(siteUrl(craft.fostercheckout.getPath('checkout') ~ '/order', { + number: cart.uid, + success: 'true' + })) }} + {{ hiddenInput('cancelUrl', siteUrl(craft.fostercheckout.getPath('checkout') ~ '/payment')|hash) }} + {{ hiddenInput('orderEmail', cart.email) }} + + + + {% set params = {} %} + + {# Special params for Paypal checkout #} + {% if gatewayClass == 'craft\\commerce\\paypalcheckout\\gateways\\Gateway' %} + {% set params = { currency: cart.paymentCurrency } %} + {% endif %} - {% if className(gateway) == 'craft\\commerce\\stripe\\gateways\\PaymentIntents' %} {% set buttonText = 'Pay'|t('foster-checkout') ~ ' ' ~ cart.totalAsCurrency %} - {% set params = { - order: cart, - paymentFormType: 'elements', - appearance: { - theme: 'stripe', - labels: 'floating', - variables: { - colorPrimary: 'var(--brandColor)' - } - }, - submitButtonText: buttonText, - submitButtonClasses: 'mt-8 justify-between items-center gap-4 w-full px-4 py-3 font-medium text-white text-center bg-[var(--brandColor)] border border-[var(--brandColor)] rounded-xl lg:inline-block' - } %} - {% endif %} - - - {% namespace gateway.handle|commercePaymentFormNamespace %} - {{ gateway.getPaymentFormHtml(params)|raw }} - {% endnamespace %} - - + {% if gatewayClass == 'craft\\commerce\\stripe\\gateways\\PaymentIntents' %} + {% set params = { + order: cart, + paymentFormType: 'elements', + appearance: { + theme: 'stripe', + labels: 'floating', + variables: { + colorPrimary: 'var(--brandColor)' + } + }, + submitButtonText: buttonText, + submitButtonClasses: 'mt-8 justify-between items-center gap-4 w-full px-4 py-3 font-medium text-white text-center bg-[var(--brandColor)] border border-[var(--brandColor)] rounded-xl lg:inline-block' + } %} + {% endif %} + + + {% namespace gateway.handle|commercePaymentFormNamespace %} + {{ gateway.getPaymentFormHtml(params)|raw }} + {% endnamespace %} + + {% if gatewayClass == 'craft\\commerce\\gateways\\Manual' %} + + {% endif %} + + +
-
+ {% endif %} {% endfor %}
@@ -315,17 +331,17 @@ {% js %} var $paymentForms = document.querySelectorAll('.paymentForm'); if ($paymentForms.length) { - $paymentForms.forEach(($paymentForm) => { - // Only allow the payment form submit to be triggered once. - $paymentForm.addEventListener('submit', function(ev) { - if ($paymentForm.dataset.processing) { - ev.preventDefault(); - return false; - } - - $paymentForm.dataset.processing = true; - }); - }); + $paymentForms.forEach(($paymentForm) => { + // Only allow the payment form submit to be triggered once. + $paymentForm.addEventListener('submit', function(ev) { + if ($paymentForm.dataset.processing) { + ev.preventDefault(); + return false; + } + + $paymentForm.dataset.processing = true; + }); + }); } {% endjs %}