Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Allow 4 digit CVV for Amex cards (#10929)

Felipe Zavan8cc81bb67e40
diff --git a/backend/app/assets/javascripts/spree/backend/payments/new.js b/backend/app/assets/javascripts/spree/backend/payments/new.js
index 47f8011863..46023e5017 100644
--- a/backend/app/assets/javascripts/spree/backend/payments/new.js
+++ b/backend/app/assets/javascripts/spree/backend/payments/new.js
@@ -2,11 +2,29 @@
$(document).ready(function () {
if ($('#new_payment').length) {
+ var cardCodeCleave;
+ var updateCardCodeCleave = function (length) {
+ if (cardCodeCleave) cardCodeCleave.destroy()
+
+ cardCodeCleave = new Cleave('.cardCode', {
+ numericOnly: true,
+ blocks: [length]
+ })
+ }
+
+ updateCardCodeCleave(3)
+
/* eslint-disable no-new */
new Cleave('.cardNumber', {
creditCard: true,
onCreditCardTypeChanged: function (type) {
$('.ccType').val(type)
+
+ if (type === 'amex') {
+ updateCardCodeCleave(4)
+ } else {
+ updateCardCodeCleave(3)
+ }
}
})
/* eslint-disable no-new */
@@ -14,11 +32,6 @@ $(document).ready(function () {
date: true,
datePattern: ['m', 'Y']
})
- /* eslint-disable no-new */
- new Cleave('.cardCode', {
- numericOnly: true,
- blocks: [3]
- })
$('.payment_methods_radios').click(
function () {
diff --git a/frontend/app/assets/javascripts/spree/frontend/checkout/payment.js b/frontend/app/assets/javascripts/spree/frontend/checkout/payment.js
index 6fa7f98fc5..546a983252 100644
--- a/frontend/app/assets/javascripts/spree/frontend/checkout/payment.js
+++ b/frontend/app/assets/javascripts/spree/frontend/checkout/payment.js
@@ -27,11 +27,29 @@ Spree.ready(function ($) {
if ($(CARD_NUMBER_SELECTOR).length > 0 &&
$(CARD_EXPIRATION_SELECTOR).length > 0 &&
$(CARD_CODE_SELECTOR).length > 0) {
+ var cardCodeCleave;
+ var updateCardCodeCleave = function (length) {
+ if (cardCodeCleave) cardCodeCleave.destroy()
+
+ cardCodeCleave = new Cleave(CARD_CODE_SELECTOR, {
+ numericOnly: true,
+ blocks: [length]
+ })
+ }
+
+ updateCardCodeCleave(3)
+
/* eslint-disable no-new */
new Cleave(CARD_NUMBER_SELECTOR, {
creditCard: true,
onCreditCardTypeChanged: function (type) {
$('.ccType').val(type)
+
+ if (type === 'amex') {
+ updateCardCodeCleave(4)
+ } else {
+ updateCardCodeCleave(3)
+ }
}
})
/* eslint-disable no-new */
@@ -39,11 +57,6 @@ Spree.ready(function ($) {
date: true,
datePattern: ['m', 'Y']
})
- /* eslint-disable no-new */
- new Cleave(CARD_CODE_SELECTOR, {
- numericOnly: true,
- blocks: [3]
- })
}
$('input[type="radio"][name="order[payments_attributes][][payment_method_id]"]').click(function () {