Commit 6f7bbd58 authored by Ricardo Ambrogi's avatar Ricardo Ambrogi Committed by GitHub

Update adyen-cc-method.js

Improve readability of adyen-cc-method.js;
parent 9b5d48cf
...@@ -171,7 +171,7 @@ define( ...@@ -171,7 +171,7 @@ define(
var creditCardType = self.getCcCodeByAltCode(state.brand); var creditCardType = self.getCcCodeByAltCode(state.brand);
if (creditCardType) { if (creditCardType) {
// If the credit card type is already set, check if it changed or not // If the credit card type is already set, check if it changed or not
if (!self.creditCardType() || self.creditCardType() && self.creditCardType() != creditCardType) { if (!self.creditCardType() || self.creditCardType() !== creditCardType) {
var numberOfInstallments = []; var numberOfInstallments = [];
if (creditCardType in allInstallments) { if (creditCardType in allInstallments) {
...@@ -192,11 +192,7 @@ define( ...@@ -192,11 +192,7 @@ define(
} }
// for BCMC as this is not a core payment method inside magento use maestro as brand detection // for BCMC as this is not a core payment method inside magento use maestro as brand detection
if (creditCardType == "BCMC") { self.creditCardType(creditCardType == "BCMC" ? "MI" : creditCardType);
self.creditCardType("MI");
} else {
self.creditCardType(creditCardType);
}
} else { } else {
self.creditCardType("") self.creditCardType("")
self.installments(0); self.installments(0);
...@@ -219,11 +215,8 @@ define( ...@@ -219,11 +215,8 @@ define(
var self = this; var self = this;
var threeDS2Node = document.getElementById('threeDS2Container'); var threeDS2Node = document.getElementById('threeDS2Container');
if (type == "IdentifyShopper") { if (type === "IdentifyShopper") {
self.threeDS2IdentifyComponent = self.checkout var onComplete = function (result) {
.create('threeDS2DeviceFingerprint', {
fingerprintToken: token,
onComplete: function (result) {
self.threeDS2IdentifyComponent.unmount(); self.threeDS2IdentifyComponent.unmount();
var request = result.data; var request = result.data;
request.orderId = orderId; request.orderId = orderId;
...@@ -234,9 +227,14 @@ define( ...@@ -234,9 +227,14 @@ define(
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
}); });
}, };
self.threeDS2IdentifyComponent = self.checkout
.create('threeDS2DeviceFingerprint', {
fingerprintToken: token,
onComplete: onComplete,
onError: function (error) { onError: function (error) {
console.log(JSON.stringify(error)); // console.log(JSON.stringify(error));
} }
}); });
...@@ -255,12 +253,7 @@ define( ...@@ -255,12 +253,7 @@ define(
}); });
popupModal.modal("openModal"); popupModal.modal("openModal");
var onComplete = function (result) {
self.threeDS2ChallengeComponent = self.checkout
.create('threeDS2Challenge', {
challengeToken: token,
size: '05',
onComplete: function (result) {
self.threeDS2ChallengeComponent.unmount(); self.threeDS2ChallengeComponent.unmount();
self.closeModal(popupModal); self.closeModal(popupModal);
fullScreenLoader.startLoader(); fullScreenLoader.startLoader();
...@@ -273,7 +266,13 @@ define( ...@@ -273,7 +266,13 @@ define(
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
}); });
}, };
self.threeDS2ChallengeComponent = self.checkout
.create('threeDS2Challenge', {
challengeToken: token,
size: '05',
onComplete: onComplete,
onError: function (error) { onError: function (error) {
console.log(JSON.stringify(error)); console.log(JSON.stringify(error));
} }
...@@ -410,11 +409,7 @@ define( ...@@ -410,11 +409,7 @@ define(
var validate = $(form).validation() && $(form).validation('isValid'); var validate = $(form).validation() && $(form).validation('isValid');
if (!validate) { return validate
return false;
}
return true;
}, },
/** /**
* Validates if the typed in card holder is valid * Validates if the typed in card holder is valid
...@@ -423,11 +418,7 @@ define( ...@@ -423,11 +418,7 @@ define(
* @returns {boolean} * @returns {boolean}
*/ */
isCardOwnerValid: function () { isCardOwnerValid: function () {
if (this.creditCardOwner().length == 0) { return !!this.creditCardOwner().length;
return false;
}
return true;
}, },
/** /**
* The card component send the card details validity in a callback which is saved in the * The card component send the card details validity in a callback which is saved in the
...@@ -446,11 +437,7 @@ define( ...@@ -446,11 +437,7 @@ define(
*/ */
getCcCodeByAltCode: function (altCode) { getCcCodeByAltCode: function (altCode) {
var ccTypes = window.checkoutConfig.payment.ccform.availableTypesByAlt[this.getCode()]; var ccTypes = window.checkoutConfig.payment.ccform.availableTypesByAlt[this.getCode()];
if (ccTypes.hasOwnProperty(altCode)) { return ccTypes.hasOwnProperty(altCode)) ? ccTypes[altCode] : "";
return ccTypes[altCode];
}
return "";
}, },
/** /**
* Get available card types translated to the Adyen card type codes * Get available card types translated to the Adyen card type codes
...@@ -489,11 +476,7 @@ define( ...@@ -489,11 +476,7 @@ define(
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()]; return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
}, },
canCreateBillingAgreement: function () { canCreateBillingAgreement: function () {
if (customer.isLoggedIn()) { return customer.isLoggedIn() && window.checkoutConfig.payment.adyenCc.canCreateBillingAgreement;
return window.checkoutConfig.payment.adyenCc.canCreateBillingAgreement;
}
return false;
}, },
isShowLegend: function () { isShowLegend: function () {
return true; return true;
...@@ -503,8 +486,7 @@ define( ...@@ -503,8 +486,7 @@ define(
}, },
getIcons: function (type) { getIcons: function (type) {
return window.checkoutConfig.payment.adyenCc.icons.hasOwnProperty(type) return window.checkoutConfig.payment.adyenCc.icons.hasOwnProperty(type)
? window.checkoutConfig.payment.adyenCc.icons[type] && window.checkoutConfig.payment.adyenCc.icons[type];
: false
}, },
hasInstallments: function () { hasInstallments: function () {
return this.comboCardOption() === 'credit' && window.checkoutConfig.payment.adyenCc.hasInstallments; return this.comboCardOption() === 'credit' && window.checkoutConfig.payment.adyenCc.hasInstallments;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment