Skip to content

Commit

Permalink
Merge branch 'release/0.0.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinballard committed Oct 21, 2019
2 parents 9661528 + 3c2b537 commit 878d516
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@discolabs/submarine-js",
"version": "0.0.18",
"version": "0.0.19",
"description": "Javascript client library for Submarine.",
"main": "index.js",
"author": "Gavin Ballard",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const CYBERSOURCE_CARD_TYPE_MAPPINGS = {
forbrugsforeningen: null,
};

const MAXIMUM_FUTURE_EXPIRY_IN_YEARS = 15;

export class CybersourceCreditCardShopPaymentMethod extends ShopPaymentMethod {

beforeSetup() {
Expand Down Expand Up @@ -66,7 +68,7 @@ export class CybersourceCreditCardShopPaymentMethod extends ShopPaymentMethod {
},
expiry: {
value: expiry,
valid: payform.validateCardExpiry(expiry.month, expiry.year)
valid: this.isValidExpiry(expiry.month, expiry.year)
},
cvv: {
value: cvv,
Expand Down Expand Up @@ -99,6 +101,16 @@ export class CybersourceCreditCardShopPaymentMethod extends ShopPaymentMethod {
return !!cardType && (['visa', 'mastercard', 'amex', 'discover'].indexOf(cardType) !== -1);
}

isValidExpiry(month, year) {
if(!payform.validateCardExpiry(month, year)) {
return false;
}

// Payform does not enforce any maximum future expiry, so we add our own here.
const currentYear = new Date().getFullYear();
return year < (currentYear + MAXIMUM_FUTURE_EXPIRY_IN_YEARS);
}

displayValidationErrors(state, errors) {
this.$cardNumber.closest('.field').toggleClass('field--error field--submarine-error', !state.number.valid);
this.$cardName.closest('.field').toggleClass('field--error field--submarine-error', !state.name.valid);
Expand Down

0 comments on commit 878d516

Please sign in to comment.