Commit 935f8042 authored by Attila Kiss's avatar Attila Kiss Committed by GitHub

Add bundle.js with checkout component version 3.12.1 (#828)

Add the AdyenComponent var in the requireJS paramas
parent 52839256
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -40,7 +40,8 @@ define( ...@@ -40,7 +40,8 @@ define(
'Adyen_Payment/js/model/threeds2', 'Adyen_Payment/js/model/threeds2',
'Magento_Checkout/js/model/error-processor', 'Magento_Checkout/js/model/error-processor',
'Adyen_Payment/js/model/adyen-payment-service', 'Adyen_Payment/js/model/adyen-payment-service',
'adyenCheckout' 'adyenCheckout',
'Adyen_Payment/js/bundle'
], ],
function ( function (
$, $,
...@@ -62,7 +63,8 @@ define( ...@@ -62,7 +63,8 @@ define(
threeds2, threeds2,
errorProcessor, errorProcessor,
adyenPaymentService, adyenPaymentService,
AdyenCheckout AdyenCheckout,
AdyenComponent
) { ) {
'use strict'; 'use strict';
......
...@@ -34,9 +34,23 @@ define( ...@@ -34,9 +34,23 @@ define(
'Magento_Checkout/js/model/full-screen-loader', 'Magento_Checkout/js/model/full-screen-loader',
'mage/url', 'mage/url',
'Magento_Vault/js/view/payment/vault-enabler', 'Magento_Vault/js/view/payment/vault-enabler',
'adyenCheckout' 'adyenCheckout',
'Adyen_Payment/js/bundle',
], ],
function (ko, $, Component, placeOrderAction, additionalValidators, quote, urlBuilder, fullScreenLoader, url, VaultEnabler, AdyenCheckout) { function(
ko,
$,
Component,
placeOrderAction,
additionalValidators,
quote,
urlBuilder,
fullScreenLoader,
url,
VaultEnabler,
AdyenCheckout,
AdyenComponent,
) {
'use strict'; 'use strict';
/** /**
...@@ -50,34 +64,33 @@ define( ...@@ -50,34 +64,33 @@ define(
defaults: { defaults: {
template: 'Adyen_Payment/payment/google-pay-form', template: 'Adyen_Payment/payment/google-pay-form',
googlePayToken: null, googlePayToken: null,
googlePayAllowed: null googlePayAllowed: null,
}, },
/** /**
* @returns {Boolean} * @returns {Boolean}
*/ */
isShowLegend: function () { isShowLegend: function() {
return true; return true;
}, },
setPlaceOrderHandler: function (handler) { setPlaceOrderHandler: function(handler) {
this.placeOrderHandler = handler; this.placeOrderHandler = handler;
}, },
setValidateHandler: function (handler) { setValidateHandler: function(handler) {
this.validateHandler = handler; this.validateHandler = handler;
}, },
getCode: function () { getCode: function() {
return 'adyen_google_pay'; return 'adyen_google_pay';
}, },
isActive: function () { isActive: function() {
return true; return true;
}, },
initObservable: function () { initObservable: function() {
this._super() this._super().observe([
.observe([
'googlePayToken', 'googlePayToken',
'googlePayAllowed' 'googlePayAllowed',
]); ]);
return this; return this;
}, initialize: function () { }, initialize: function() {
var self = this; var self = this;
this.additionalValidators = additionalValidators; this.additionalValidators = additionalValidators;
this.vaultEnabler = new VaultEnabler(); this.vaultEnabler = new VaultEnabler();
...@@ -86,7 +99,7 @@ define( ...@@ -86,7 +99,7 @@ define(
this._super(); this._super();
}, },
renderGooglePay: function () { renderGooglePay: function() {
this.googlePayNode = document.getElementById('googlePay'); this.googlePayNode = document.getElementById('googlePay');
var self = this; var self = this;
...@@ -95,8 +108,8 @@ define( ...@@ -95,8 +108,8 @@ define(
originKey: self.getOriginKey(), originKey: self.getOriginKey(),
environment: self.getCheckoutEnvironment(), environment: self.getCheckoutEnvironment(),
risk: { risk: {
enabled: false enabled: false,
} },
}); });
var googlepay = self.checkoutComponent.create('paywithgoogle', { var googlepay = self.checkoutComponent.create('paywithgoogle', {
showPayButton: true, showPayButton: true,
...@@ -108,91 +121,92 @@ define( ...@@ -108,91 +121,92 @@ define(
// https://developers.google.com/pay/api/web/reference/object#MerchantInfo // https://developers.google.com/pay/api/web/reference/object#MerchantInfo
merchantIdentifier: self.getMerchantIdentifier(), merchantIdentifier: self.getMerchantIdentifier(),
merchantName: self.getMerchantAccount() merchantName: self.getMerchantAccount(),
}, },
// Payment // Payment
amount: self.formatAmount(quote.totals().grand_total, self.getFormat()), amount: self.formatAmount(quote.totals().grand_total,
self.getFormat()),
currency: quote.totals().quote_currency_code, currency: quote.totals().quote_currency_code,
totalPriceStatus: 'FINAL', totalPriceStatus: 'FINAL',
// empty onSubmit to resolve javascript issues. // empty onSubmit to resolve javascript issues.
onSubmit: function() {}, onSubmit: function() {},
onChange: function (state) { onChange: function(state) {
if (!!state.isValid) { if (!!state.isValid) {
self.googlePayToken(state.data.paymentMethod.googlePayToken); self.googlePayToken(state.data.paymentMethod.googlePayToken);
self.getPlaceOrderDeferredObject() self.getPlaceOrderDeferredObject().fail(
.fail( function() {
function () {
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
} },
).done( ).done(
function () { function() {
self.afterPlaceOrder(); self.afterPlaceOrder();
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl)); window.location.replace(url.build(
window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
} },
); );
} }
}, },
buttonColor: 'black', // default/black/white buttonColor: 'black', // default/black/white
buttonType: 'long', // long/short buttonType: 'long', // long/short
showButton: true // show or hide the Google Pay button showButton: true, // show or hide the Google Pay button
}); });
var promise = googlepay.isAvailable(); var promise = googlepay.isAvailable();
promise.then(function (success) { promise.then(function(success) {
self.googlePayAllowed(true); self.googlePayAllowed(true);
googlepay.mount(self.googlePayNode); googlepay.mount(self.googlePayNode);
$(self.googlePayNode).find('button').prop('disabled', true); $(self.googlePayNode).find('button').prop('disabled', true);
}, function (error) { }, function(error) {
console.log(error); console.log(error);
self.googlePayAllowed(false); self.googlePayAllowed(false);
}); });
}, },
isGooglePayAllowed: function () { isGooglePayAllowed: function() {
if (this.googlePayAllowed()) { if (this.googlePayAllowed()) {
return true; return true;
} }
return false; return false;
}, },
getMerchantAccount: function () { getMerchantAccount: function() {
return window.checkoutConfig.payment.adyenGooglePay.merchantAccount; return window.checkoutConfig.payment.adyenGooglePay.merchantAccount;
}, },
showLogo: function () { showLogo: function() {
return window.checkoutConfig.payment.adyen.showLogo; return window.checkoutConfig.payment.adyen.showLogo;
}, },
getLocale: function () { getLocale: function() {
return window.checkoutConfig.payment.adyenGooglePay.locale; return window.checkoutConfig.payment.adyenGooglePay.locale;
}, },
getFormat: function () { getFormat: function() {
return window.checkoutConfig.payment.adyenGooglePay.format; return window.checkoutConfig.payment.adyenGooglePay.format;
}, },
getMerchantIdentifier: function () { getMerchantIdentifier: function() {
return window.checkoutConfig.payment.adyenGooglePay.merchantIdentifier; return window.checkoutConfig.payment.adyenGooglePay.merchantIdentifier;
}, },
context: function () { context: function() {
return this; return this;
}, },
validate: function (hideErrors) { validate: function(hideErrors) {
return this.additionalValidators.validate(hideErrors); return this.additionalValidators.validate(hideErrors);
}, },
getControllerName: function () { getControllerName: function() {
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()]; return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
}, },
getPlaceOrderUrl: function () { getPlaceOrderUrl: function() {
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()]; return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
}, },
/** /**
* Get data for place order * Get data for place order
* @returns {{method: *}} * @returns {{method: *}}
*/ */
getData: function () { getData: function() {
return { return {
'method': "adyen_google_pay", 'method': 'adyen_google_pay',
'additional_data': { 'additional_data': {
'token': this.googlePayToken() 'token': this.googlePayToken(),
} },
}; };
}, },
...@@ -202,21 +216,21 @@ define( ...@@ -202,21 +216,21 @@ define(
* @param $currency * @param $currency
* @return string * @return string
*/ */
formatAmount: function (amount, format) { formatAmount: function(amount, format) {
return Math.round(amount * (Math.pow(10, format))) return Math.round(amount * (Math.pow(10, format)));
}, },
isVaultEnabled: function () { isVaultEnabled: function() {
return this.vaultEnabler.isVaultEnabled(); return this.vaultEnabler.isVaultEnabled();
}, },
getVaultCode: function () { getVaultCode: function() {
return "adyen_google_pay_vault"; return 'adyen_google_pay_vault';
}, },
getOriginKey: function () { getOriginKey: function() {
return window.checkoutConfig.payment.adyen.originKey; return window.checkoutConfig.payment.adyen.originKey;
}, },
getCheckoutEnvironment: function () { getCheckoutEnvironment: function() {
return window.checkoutConfig.payment.adyen.checkoutEnvironment; return window.checkoutConfig.payment.adyen.checkoutEnvironment;
} },
}); });
} },
); );
...@@ -38,14 +38,42 @@ define( ...@@ -38,14 +38,42 @@ define(
'Magento_Ui/js/model/messages', 'Magento_Ui/js/model/messages',
'Adyen_Payment/js/model/threeds2', 'Adyen_Payment/js/model/threeds2',
'Magento_Checkout/js/model/error-processor', 'Magento_Checkout/js/model/error-processor',
'adyenCheckout' 'adyenCheckout',
'Adyen_Payment/js/bundle'
], ],
function (ko, $, Component, selectPaymentMethodAction, quote, checkoutData, additionalValidators, storage, urlBuilder, adyenPaymentService, customer, fullScreenLoader, placeOrderAction, layout, Messages, threeds2, errorProcessor, AdyenCheckout) { function(
ko,
$,
Component,
selectPaymentMethodAction,
quote,
checkoutData,
additionalValidators,
storage,
urlBuilder,
adyenPaymentService,
customer,
fullScreenLoader,
placeOrderAction,
layout,
Messages,
threeds2,
errorProcessor,
AdyenCheckout,
AdyenComponent
) {
'use strict'; 'use strict';
var brandCode = ko.observable(null); var brandCode = ko.observable(null);
var paymentMethod = ko.observable(null); var paymentMethod = ko.observable(null);
var shippingAddressCountryCode = quote.shippingAddress().countryId; var shippingAddressCountryCode = quote.shippingAddress().countryId;
var unsupportedPaymentMethods = ['scheme', 'boleto', 'bcmc_mobile_QR', 'wechatpay', /^bcmc$/, "applepay", "paywithgoogle"]; var unsupportedPaymentMethods = [
'scheme',
'boleto',
'bcmc_mobile_QR',
'wechatpay',
/^bcmc$/,
'applepay',
'paywithgoogle'];
var popupModal; var popupModal;
/** /**
* Shareble adyen checkout component * Shareble adyen checkout component
...@@ -58,11 +86,10 @@ define( ...@@ -58,11 +86,10 @@ define(
self: this, self: this,
defaults: { defaults: {
template: 'Adyen_Payment/payment/hpp-form', template: 'Adyen_Payment/payment/hpp-form',
brandCode: '' brandCode: '',
}, },
initObservable: function () { initObservable: function() {
this._super() this._super().observe([
.observe([
'brandCode', 'brandCode',
'issuer', 'issuer',
'gender', 'gender',
...@@ -72,11 +99,10 @@ define( ...@@ -72,11 +99,10 @@ define(
'ibanNumber', 'ibanNumber',
'ssn', 'ssn',
'bankAccountNumber', 'bankAccountNumber',
'bankLocationId' 'bankLocationId',
]); ]);
return this; return this;
}, initialize: function () { }, initialize: function() {
var self = this; var self = this;
this._super(); this._super();
...@@ -91,35 +117,35 @@ define( ...@@ -91,35 +117,35 @@ define(
locale: self.getLocale(), locale: self.getLocale(),
onAdditionalDetails: self.handleOnAdditionalDetails.bind(self), onAdditionalDetails: self.handleOnAdditionalDetails.bind(self),
originKey: self.getOriginKey(), originKey: self.getOriginKey(),
environment: self.getCheckoutEnvironment() environment: self.getCheckoutEnvironment(),
}); });
// reset variable: // reset variable:
adyenPaymentService.setPaymentMethods(); adyenPaymentService.setPaymentMethods();
adyenPaymentService.retrieveAvailablePaymentMethods(function () { adyenPaymentService.retrieveAvailablePaymentMethods(function() {
var paymentMethods = adyenPaymentService.getAvailablePaymentMethods(); var paymentMethods = adyenPaymentService.getAvailablePaymentMethods();
if (JSON.stringify(paymentMethods).indexOf("ratepay") > -1) { if (JSON.stringify(paymentMethods).indexOf('ratepay') > -1) {
var ratePayId = window.checkoutConfig.payment.adyenHpp.ratePayId; var ratePayId = window.checkoutConfig.payment.adyenHpp.ratePayId;
var dfValueRatePay = self.getRatePayDeviceIdentToken(); var dfValueRatePay = self.getRatePayDeviceIdentToken();
window.di = { window.di = {
t: dfValueRatePay.replace(':', ''), t: dfValueRatePay.replace(':', ''),
v: ratePayId, v: ratePayId,
l: 'Checkout' l: 'Checkout',
}; };
// Load Ratepay script // Load Ratepay script
var ratepayScriptTag = document.createElement('script'); var ratepayScriptTag = document.createElement('script');
ratepayScriptTag.src = "//d.ratepay.com/" + ratePayId + "/di.js"; ratepayScriptTag.src = '//d.ratepay.com/' + ratePayId + '/di.js';
ratepayScriptTag.type = "text/javascript"; ratepayScriptTag.type = 'text/javascript';
document.body.appendChild(ratepayScriptTag); document.body.appendChild(ratepayScriptTag);
} }
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
}); });
}, },
getAdyenHppPaymentMethods: function () { getAdyenHppPaymentMethods: function() {
var self = this; var self = this;
var currentShippingAddressCountryCode = quote.shippingAddress().countryId; var currentShippingAddressCountryCode = quote.shippingAddress().countryId;
...@@ -133,33 +159,34 @@ define( ...@@ -133,33 +159,34 @@ define(
var paymentMethods = adyenPaymentService.getAvailablePaymentMethods(); var paymentMethods = adyenPaymentService.getAvailablePaymentMethods();
var paymentList = _.reduce(paymentMethods, function (accumulator, value) { var paymentList = _.reduce(paymentMethods,
function(accumulator, value) {
if (!self.isPaymentMethodSupported(value.type)) { if (!self.isPaymentMethodSupported(value.type)) {
return accumulator; return accumulator;
} }
var messageContainer = new Messages(); var messageContainer = new Messages();
var name = 'messages-' + self.getBrandCodeFromPaymentMethod(value); var name = 'messages-' +
self.getBrandCodeFromPaymentMethod(value);
var messagesComponent = { var messagesComponent = {
parent: self.name, parent: self.name,
name: name, name: name,
displayArea: name, displayArea: name,
component: 'Magento_Ui/js/view/messages', component: 'Magento_Ui/js/view/messages',
config: { config: {
messageContainer: messageContainer messageContainer: messageContainer,
} },
}; };
layout([messagesComponent]); layout([messagesComponent]);
var result = {}; var result = {};
/** /**
* Returns the payment method's brand code (in checkout api it is the type) * Returns the payment method's brand code (in checkout api it is the type)
* @returns {*} * @returns {*}
*/ */
result.getBrandCode = function () { result.getBrandCode = function() {
return self.getBrandCodeFromPaymentMethod(value); return self.getBrandCodeFromPaymentMethod(value);
}; };
...@@ -172,16 +199,17 @@ define( ...@@ -172,16 +199,17 @@ define(
* @type {observable} * @type {observable}
*/ */
result.placeOrderAllowed = ko.observable(true); result.placeOrderAllowed = ko.observable(true);
result.getCode = function () { result.getCode = function() {
return self.item.method; return self.item.method;
}; };
result.getMessageName = function () { result.getMessageName = function() {
return 'messages-' + self.getBrandCodeFromPaymentMethod(value) return 'messages-' +
self.getBrandCodeFromPaymentMethod(value);
}; };
result.getMessageContainer = function () { result.getMessageContainer = function() {
return messageContainer; return messageContainer;
} };
result.validate = function () { result.validate = function() {
return self.validate(result.getBrandCode()); return self.validate(result.getBrandCode());
}; };
result.placeRedirectOrder = function placeRedirectOrder(data) { result.placeRedirectOrder = function placeRedirectOrder(data) {
...@@ -192,22 +220,23 @@ define( ...@@ -192,22 +220,23 @@ define(
self.isPlaceOrderActionAllowed(false); self.isPlaceOrderActionAllowed(false);
$.when( $.when(
placeOrderAction(data, self.currentMessageContainer) placeOrderAction(data, self.currentMessageContainer),
).fail( ).fail(
function (response) { function(response) {
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
self.showErrorMessage(response); self.showErrorMessage(response);
} },
).done( ).done(
function (orderId) { function(orderId) {
self.afterPlaceOrder(); self.afterPlaceOrder();
adyenPaymentService.getOrderPaymentStatus(orderId) adyenPaymentService.getOrderPaymentStatus(orderId).
.done(function (responseJSON) { done(function(responseJSON) {
self.validateActionOrPlaceOrder(responseJSON, orderId); self.validateActionOrPlaceOrder(responseJSON,
orderId);
}); });
} },
) );
}; };
/** /**
...@@ -216,18 +245,18 @@ define( ...@@ -216,18 +245,18 @@ define(
* @param bool * @param bool
* @returns {*} * @returns {*}
*/ */
result.isPlaceOrderAllowed = function (bool) { result.isPlaceOrderAllowed = function(bool) {
self.isPlaceOrderActionAllowed(bool); self.isPlaceOrderActionAllowed(bool);
return result.placeOrderAllowed(bool); return result.placeOrderAllowed(bool);
}; };
result.afterPlaceOrder = function () { result.afterPlaceOrder = function() {
return self.afterPlaceOrder(); return self.afterPlaceOrder();
}; };
/** /**
* Checks if payment method is open invoice * Checks if payment method is open invoice
* @returns {*|isPaymentMethodOpenInvoiceMethod} * @returns {*|isPaymentMethodOpenInvoiceMethod}
*/ */
result.isPaymentMethodOpenInvoiceMethod = function () { result.isPaymentMethodOpenInvoiceMethod = function() {
return value.isPaymentMethodOpenInvoiceMethod; return value.isPaymentMethodOpenInvoiceMethod;
}; };
/** /**
...@@ -235,7 +264,7 @@ define( ...@@ -235,7 +264,7 @@ define(
* [klarna, afterpay] * [klarna, afterpay]
* @returns {boolean} * @returns {boolean}
*/ */
result.isPaymentMethodOtherOpenInvoiceMethod = function () { result.isPaymentMethodOtherOpenInvoiceMethod = function() {
if ( if (
!result.isPaymentMethodAfterPay() && !result.isPaymentMethodAfterPay() &&
!result.isPaymentMethodKlarna() && !result.isPaymentMethodKlarna() &&
...@@ -251,8 +280,8 @@ define( ...@@ -251,8 +280,8 @@ define(
* Checks if payment method is klarna * Checks if payment method is klarna
* @returns {boolean} * @returns {boolean}
*/ */
result.isPaymentMethodKlarna = function () { result.isPaymentMethodKlarna = function() {
if (result.getBrandCode() === "klarna") { if (result.getBrandCode() === 'klarna') {
return true; return true;
} }
...@@ -262,8 +291,8 @@ define( ...@@ -262,8 +291,8 @@ define(
* Checks if payment method is after pay * Checks if payment method is after pay
* @returns {boolean} * @returns {boolean}
*/ */
result.isPaymentMethodAfterPay = function () { result.isPaymentMethodAfterPay = function() {
if (result.getBrandCode() === "afterpay_default") { if (result.getBrandCode() === 'afterpay_default') {
return true; return true;
} }
...@@ -273,8 +302,8 @@ define( ...@@ -273,8 +302,8 @@ define(
* Checks if payment method is after pay touch * Checks if payment method is after pay touch
* @returns {boolean} * @returns {boolean}
*/ */
result.isPaymentMethodAfterPayTouch = function () { result.isPaymentMethodAfterPayTouch = function() {
if (result.getBrandCode() === "afterpaytouch") { if (result.getBrandCode() === 'afterpaytouch') {
return true; return true;
} }
...@@ -284,8 +313,8 @@ define( ...@@ -284,8 +313,8 @@ define(
* Get personal number (SSN) length based on the buyer's country * Get personal number (SSN) length based on the buyer's country
* @returns {number} * @returns {number}
*/ */
result.getSsnLength = function () { result.getSsnLength = function() {
if (quote.billingAddress().countryId == "NO") { if (quote.billingAddress().countryId == 'NO') {
//14 digits for Norway ÅÅÅÅMMDD-XXXXX //14 digits for Norway ÅÅÅÅMMDD-XXXXX
return 14; return 14;
} else { } else {
...@@ -296,30 +325,31 @@ define( ...@@ -296,30 +325,31 @@ define(
/** /**
* Get max length for the Bank account number * Get max length for the Bank account number
*/ */
result.getBankAccountNumberMaxLength = function () { result.getBankAccountNumberMaxLength = function() {
return 17; return 17;
}; };
/** /**
* Finds the issuer property in the payment method's response and if available returns it's index * Finds the issuer property in the payment method's response and if available returns it's index
* @returns * @returns
*/ */
result.findIssuersProperty = function () { result.findIssuersProperty = function() {
var issuerKey = false; var issuerKey = false;
if (typeof value.details !== 'undefined') { if (typeof value.details !== 'undefined') {
$.each(value.details, function (key, detail) { $.each(value.details, function(key, detail) {
if (typeof detail.items !== 'undefined' && detail.key == 'issuer') { if (typeof detail.items !== 'undefined' && detail.key ==
'issuer') {
issuerKey = key; issuerKey = key;
} }
}); });
} }
return issuerKey; return issuerKey;
} };
/** /**
* Checks if the payment method has issuers property available * Checks if the payment method has issuers property available
* @returns {boolean} * @returns {boolean}
*/ */
result.hasIssuersProperty = function () { result.hasIssuersProperty = function() {
if (result.findIssuersProperty() !== false) { if (result.findIssuersProperty() !== false) {
return true; return true;
} }
...@@ -330,8 +360,10 @@ define( ...@@ -330,8 +360,10 @@ define(
* Checks if the payment method has issuer(s) available * Checks if the payment method has issuer(s) available
* @returns {boolean} * @returns {boolean}
*/ */
result.hasIssuersAvailable = function () { result.hasIssuersAvailable = function() {
if (result.hasIssuersProperty() && value.details[result.findIssuersProperty()].items.length > 0) { if (result.hasIssuersProperty() &&
value.details[result.findIssuersProperty()].items.length >
0) {
return true; return true;
} }
...@@ -341,7 +373,7 @@ define( ...@@ -341,7 +373,7 @@ define(
* Returns the issuers for a payment method * Returns the issuers for a payment method
* @returns {*} * @returns {*}
*/ */
result.getIssuers = function () { result.getIssuers = function() {
if (result.hasIssuersAvailable()) { if (result.hasIssuersAvailable()) {
return value.details[result.findIssuersProperty()].items; return value.details[result.findIssuersProperty()].items;
} }
...@@ -352,8 +384,8 @@ define( ...@@ -352,8 +384,8 @@ define(
* Checks if payment method is iDeal * Checks if payment method is iDeal
* @returns {boolean} * @returns {boolean}
*/ */
result.isIdeal = function () { result.isIdeal = function() {
if (result.getBrandCode().indexOf("ideal") >= 0) { if (result.getBrandCode().indexOf('ideal') >= 0) {
return true; return true;
} }
...@@ -363,8 +395,8 @@ define( ...@@ -363,8 +395,8 @@ define(
* Checks if payment method is ACH * Checks if payment method is ACH
* @returns {boolean} * @returns {boolean}
*/ */
result.isAch = function () { result.isAch = function() {
if (result.getBrandCode().indexOf("ach") == 0) { if (result.getBrandCode().indexOf('ach') == 0) {
return true; return true;
} }
...@@ -373,8 +405,8 @@ define( ...@@ -373,8 +405,8 @@ define(
/** /**
* Checks if payment method is sepa direct debit * Checks if payment method is sepa direct debit
*/ */
result.isSepaDirectDebit = function () { result.isSepaDirectDebit = function() {
if (result.getBrandCode().indexOf("sepadirectdebit") >= 0) { if (result.getBrandCode().indexOf('sepadirectdebit') >= 0) {
return true; return true;
} }
...@@ -385,21 +417,21 @@ define( ...@@ -385,21 +417,21 @@ define(
* creates the ideal component, * creates the ideal component,
* sets up the callbacks for ideal components and * sets up the callbacks for ideal components and
*/ */
result.renderIdealComponent = function () { result.renderIdealComponent = function() {
result.isPlaceOrderAllowed(false); result.isPlaceOrderAllowed(false);
var idealNode = document.getElementById('iDealContainer'); var idealNode = document.getElementById('iDealContainer');
var ideal = self.checkoutComponent.create('ideal', { var ideal = self.checkoutComponent.create('ideal', {
items: result.getIssuers(), items: result.getIssuers(),
onChange: function (state) { onChange: function(state) {
if (!!state.isValid) { if (!!state.isValid) {
result.issuer(state.data.paymentMethod.issuer); result.issuer(state.data.paymentMethod.issuer);
result.isPlaceOrderAllowed(true); result.isPlaceOrderAllowed(true);
} else { } else {
result.isPlaceOrderAllowed(false); result.isPlaceOrderAllowed(false);
} }
} },
}); });
ideal.mount(idealNode); ideal.mount(idealNode);
...@@ -409,22 +441,26 @@ define( ...@@ -409,22 +441,26 @@ define(
* Creates the sepa direct debit component, * Creates the sepa direct debit component,
* sets up the callbacks for sepa components * sets up the callbacks for sepa components
*/ */
result.renderSepaDirectDebitComponent = function () { result.renderSepaDirectDebitComponent = function() {
result.isPlaceOrderAllowed(false); result.isPlaceOrderAllowed(false);
var sepaDirectDebitNode = document.getElementById('sepaDirectDebitContainer'); var sepaDirectDebitNode = document.getElementById(
'sepaDirectDebitContainer');
var sepaDirectDebit = self.checkoutComponent.create('sepadirectdebit', { var sepaDirectDebit = self.checkoutComponent.create(
'sepadirectdebit', {
countryCode: self.getLocale(), countryCode: self.getLocale(),
onChange: function (state) { onChange: function(state) {
if (!!state.isValid) { if (!!state.isValid) {
result.ownerName(state.data.paymentMethod["sepa.ownerName"]); result.ownerName(
result.ibanNumber(state.data.paymentMethod["sepa.ibanNumber"]); state.data.paymentMethod['sepa.ownerName']);
result.ibanNumber(
state.data.paymentMethod['sepa.ibanNumber']);
result.isPlaceOrderAllowed(true); result.isPlaceOrderAllowed(true);
} else { } else {
result.isPlaceOrderAllowed(false); result.isPlaceOrderAllowed(false);
} }
} },
}); });
sepaDirectDebit.mount(sepaDirectDebitNode); sepaDirectDebit.mount(sepaDirectDebitNode);
...@@ -434,7 +470,7 @@ define( ...@@ -434,7 +470,7 @@ define(
* Creates the klarna component, * Creates the klarna component,
* sets up the callbacks for klarna components * sets up the callbacks for klarna components
*/ */
result.renderKlarnaComponent = function () { result.renderKlarnaComponent = function() {
/* The new Klarna integration doesn't return details and the component does not handle it */ /* The new Klarna integration doesn't return details and the component does not handle it */
if (!value.details) { if (!value.details) {
...@@ -445,20 +481,24 @@ define( ...@@ -445,20 +481,24 @@ define(
var klarna = self.checkoutComponent.create('klarna', { var klarna = self.checkoutComponent.create('klarna', {
countryCode: self.getLocale(), countryCode: self.getLocale(),
details: self.filterOutOpenInvoiceComponentDetails(value.details), details: self.filterOutOpenInvoiceComponentDetails(
value.details),
visibility: { visibility: {
personalDetails: "editable" personalDetails: 'editable',
}, },
onChange: function (state) { onChange: function(state) {
if (!!state.isValid) { if (!!state.isValid) {
result.dob(state.data.paymentMethod.personalDetails.dateOfBirth); result.dob(
result.telephone(state.data.paymentMethod.personalDetails.telephoneNumber); state.data.paymentMethod.personalDetails.dateOfBirth);
result.gender(state.data.paymentMethod.personalDetails.gender); result.telephone(
state.data.paymentMethod.personalDetails.telephoneNumber);
result.gender(
state.data.paymentMethod.personalDetails.gender);
result.isPlaceOrderAllowed(true); result.isPlaceOrderAllowed(true);
} else { } else {
result.isPlaceOrderAllowed(false); result.isPlaceOrderAllowed(false);
} }
} },
}).mount(klarnaNode); }).mount(klarnaNode);
}; };
...@@ -466,28 +506,32 @@ define( ...@@ -466,28 +506,32 @@ define(
* Creates the afterpay component, * Creates the afterpay component,
* sets up the callbacks for klarna components * sets up the callbacks for klarna components
*/ */
result.renderAfterPayComponent = function () { result.renderAfterPayComponent = function() {
var afterPay = self.checkoutComponent.create('afterpay', { var afterPay = self.checkoutComponent.create('afterpay', {
countryCode: self.getLocale(), countryCode: self.getLocale(),
details: self.filterOutOpenInvoiceComponentDetails(value.details), details: self.filterOutOpenInvoiceComponentDetails(
value.details),
visibility: { visibility: {
personalDetails: "editable" personalDetails: 'editable',
}, },
onChange: function (state) { onChange: function(state) {
if (!!state.isValid) { if (!!state.isValid) {
result.dob(state.data.paymentMethod.personalDetails.dateOfBirth); result.dob(
result.telephone(state.data.paymentMethod.personalDetails.telephoneNumber); state.data.paymentMethod.personalDetails.dateOfBirth);
result.gender(state.data.paymentMethod.personalDetails.gender); result.telephone(
state.data.paymentMethod.personalDetails.telephoneNumber);
result.gender(
state.data.paymentMethod.personalDetails.gender);
result.isPlaceOrderAllowed(true); result.isPlaceOrderAllowed(true);
} else { } else {
result.isPlaceOrderAllowed(false); result.isPlaceOrderAllowed(false);
} }
} },
}).mount(document.getElementById('afterPayContainer')); }).mount(document.getElementById('afterPayContainer'));
}; };
result.continueToAdyenBrandCode = function () { result.continueToAdyenBrandCode = function() {
// set payment method to adyen_hpp // set payment method to adyen_hpp
var self = this; var self = this;
...@@ -505,7 +549,7 @@ define( ...@@ -505,7 +549,7 @@ define(
additionalData.dob = this.dob(); additionalData.dob = this.dob();
additionalData.telephone = this.telephone(); additionalData.telephone = this.telephone();
additionalData.ssn = this.ssn(); additionalData.ssn = this.ssn();
if (brandCode() == "ratepay") { if (brandCode() == 'ratepay') {
additionalData.df_value = this.getRatePayDeviceIdentToken(); additionalData.df_value = this.getRatePayDeviceIdentToken();
} }
} else if (self.isSepaDirectDebit()) { } else if (self.isSepaDirectDebit()) {
...@@ -522,8 +566,7 @@ define( ...@@ -522,8 +566,7 @@ define(
} }
return false; return false;
} };
if (result.hasIssuersProperty()) { if (result.hasIssuersProperty()) {
if (!result.hasIssuersAvailable()) { if (!result.hasIssuersAvailable()) {
...@@ -533,17 +576,20 @@ define( ...@@ -533,17 +576,20 @@ define(
result.issuerIds = result.getIssuers(); result.issuerIds = result.getIssuers();
result.issuer = ko.observable(null); result.issuer = ko.observable(null);
} else if (value.isPaymentMethodOpenInvoiceMethod) { } else if (value.isPaymentMethodOpenInvoiceMethod) {
result.telephone = ko.observable(quote.shippingAddress().telephone); result.telephone = ko.observable(
result.gender = ko.observable(window.checkoutConfig.payment.adyenHpp.gender); quote.shippingAddress().telephone);
result.dob = ko.observable(window.checkoutConfig.payment.adyenHpp.dob); result.gender = ko.observable(
window.checkoutConfig.payment.adyenHpp.gender);
result.dob = ko.observable(
window.checkoutConfig.payment.adyenHpp.dob);
result.datepickerValue = ko.observable(); // needed ?? result.datepickerValue = ko.observable(); // needed ??
result.ssn = ko.observable(); result.ssn = ko.observable();
result.getRatePayDeviceIdentToken = function () { result.getRatePayDeviceIdentToken = function() {
return window.checkoutConfig.payment.adyenHpp.deviceIdentToken; return window.checkoutConfig.payment.adyenHpp.deviceIdentToken;
}; };
result.showSsn = function () { result.showSsn = function() {
if (result.getBrandCode().indexOf("klarna") >= 0) { if (result.getBrandCode().indexOf('klarna') >= 0) {
var ba = quote.billingAddress(); var ba = quote.billingAddress();
if (ba != null) { if (ba != null) {
var nordicCountriesList = window.checkoutConfig.payment.adyenHpp.nordicCountries; var nordicCountriesList = window.checkoutConfig.payment.adyenHpp.nordicCountries;
...@@ -576,7 +622,7 @@ define( ...@@ -576,7 +622,7 @@ define(
* @param paymentMethod * @param paymentMethod
* @returns {boolean} * @returns {boolean}
*/ */
isPaymentMethodSupported: function (paymentMethod) { isPaymentMethodSupported: function(paymentMethod) {
if (paymentMethod == 'wechatpayWeb') { if (paymentMethod == 'wechatpayWeb') {
return true; return true;
} }
...@@ -588,24 +634,25 @@ define( ...@@ -588,24 +634,25 @@ define(
} }
return true; return true;
}, },
getGenderTypes: function () { getGenderTypes: function() {
return _.map(window.checkoutConfig.payment.adyenHpp.genderTypes, function (value, key) { return _.map(window.checkoutConfig.payment.adyenHpp.genderTypes,
function(value, key) {
return { return {
'key': key, 'key': key,
'value': value 'value': value,
} };
}); });
}, },
selectPaymentMethodBrandCode: function () { selectPaymentMethodBrandCode: function() {
var self = this; var self = this;
// set payment method to adyen_hpp // set payment method to adyen_hpp
var data = { var data = {
"method": self.method, 'method': self.method,
"po_number": null, 'po_number': null,
"additional_data": { 'additional_data': {
brand_code: self.value brand_code: self.value,
} },
}; };
// set the brandCode // set the brandCode
...@@ -623,18 +670,18 @@ define( ...@@ -623,18 +670,18 @@ define(
* This method is a workaround to close the modal in the right way and reconstruct the ActionModal. * This method is a workaround to close the modal in the right way and reconstruct the ActionModal.
* This will solve issues when you cancel the 3DS2 challenge and retry the payment * This will solve issues when you cancel the 3DS2 challenge and retry the payment
*/ */
closeModal: function (popupModal) { closeModal: function(popupModal) {
popupModal.modal("closeModal"); popupModal.modal('closeModal');
$('.ActionModal').remove(); $('.ActionModal').remove();
$('.modals-overlay').remove(); $('.modals-overlay').remove();
$('body').removeClass('_has-modal'); $('body').removeClass('_has-modal');
// reconstruct the ActionModal container again otherwise component can not find the ActionModal // reconstruct the ActionModal container again otherwise component can not find the ActionModal
$('#ActionWrapper').append("<div id=\"ActionModal\">" + $('#ActionWrapper').append('<div id="ActionModal">' +
"<div id=\"ActionContainer\"></div>" + '<div id="ActionContainer"></div>' +
"</div>"); '</div>');
}, },
isBrandCodeChecked: ko.computed(function () { isBrandCodeChecked: ko.computed(function() {
if (!quote.paymentMethod()) { if (!quote.paymentMethod()) {
return null; return null;
...@@ -645,14 +692,14 @@ define( ...@@ -645,14 +692,14 @@ define(
} }
return null; return null;
}), }),
isIconEnabled: function () { isIconEnabled: function() {
return window.checkoutConfig.payment.adyen.showLogo; return window.checkoutConfig.payment.adyen.showLogo;
}, },
/** /**
* Based on the response we can start a action component or redirect * Based on the response we can start a action component or redirect
* @param responseJSON * @param responseJSON
*/ */
validateActionOrPlaceOrder: function (responseJSON, orderId) { validateActionOrPlaceOrder: function(responseJSON, orderId) {
var self = this; var self = this;
var response = JSON.parse(responseJSON); var response = JSON.parse(responseJSON);
...@@ -662,7 +709,7 @@ define( ...@@ -662,7 +709,7 @@ define(
self.renderActionComponent(response.action); self.renderActionComponent(response.action);
} else { } else {
$.mage.redirect( $.mage.redirect(
window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl,
); );
} }
}, },
...@@ -677,11 +724,10 @@ define( ...@@ -677,11 +724,10 @@ define(
* @param type * @param type
* @param token * @param token
*/ */
renderActionComponent: function (action) { renderActionComponent: function(action) {
var self = this; var self = this;
var actionNode = document.getElementById('ActionContainer'); var actionNode = document.getElementById('ActionContainer');
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
self.popupModal = $('#ActionModal').modal({ self.popupModal = $('#ActionModal').modal({
...@@ -691,13 +737,14 @@ define( ...@@ -691,13 +737,14 @@ define(
innerScroll: false, innerScroll: false,
// empty buttons, we don't need that // empty buttons, we don't need that
buttons: [], buttons: [],
modalClass: 'ActionModal' modalClass: 'ActionModal',
}); });
self.popupModal.modal("openModal"); self.popupModal.modal('openModal');
self.actionComponent = self.checkoutComponent.createFromAction(action).mount(actionNode); self.actionComponent = self.checkoutComponent.createFromAction(
action).mount(actionNode);
}, },
handleOnAdditionalDetails: function (state, component) { handleOnAdditionalDetails: function(state, component) {
var self = this; var self = this;
// call endpoint with state.data // call endpoint with state.data
...@@ -705,11 +752,11 @@ define( ...@@ -705,11 +752,11 @@ define(
request.orderId = self.orderId; request.orderId = self.orderId;
// Using the same processor as 3DS2, refactor to generic name in a upcomming release will be breaking change for merchants. // Using the same processor as 3DS2, refactor to generic name in a upcomming release will be breaking change for merchants.
threeds2.processThreeDS2(request).done(function () { threeds2.processThreeDS2(request).done(function() {
$.mage.redirect( $.mage.redirect(
window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl,
); );
}).fail(function (response) { }).fail(function(response) {
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
self.closeModal(self.popupModal); self.closeModal(self.popupModal);
errorProcessor.process(response, self.currentMessageContainer); errorProcessor.process(response, self.currentMessageContainer);
...@@ -721,18 +768,23 @@ define( ...@@ -721,18 +768,23 @@ define(
* Issue with the default currentMessageContainer needs to be resolved for now just throw manually the eror message * Issue with the default currentMessageContainer needs to be resolved for now just throw manually the eror message
* @param response * @param response
*/ */
showErrorMessage: function (response) { showErrorMessage: function(response) {
if (!!response['responseJSON'].parameters) { if (!!response['responseJSON'].parameters) {
$("#messages-" + brandCode()).text((response['responseJSON'].message).replace('%1', response['responseJSON'].parameters[0])).slideDown(); $('#messages-' + brandCode()).
text((response['responseJSON'].message).replace('%1',
response['responseJSON'].parameters[0])).
slideDown();
} else { } else {
$("#messages-" + brandCode()).text(response['responseJSON'].message).slideDown(); $('#messages-' + brandCode()).
text(response['responseJSON'].message).
slideDown();
} }
setTimeout(function () { setTimeout(function() {
$("#messages-" + brandCode()).slideUp(); $('#messages-' + brandCode()).slideUp();
}, 10000); }, 10000);
}, },
validate: function (brandCode) { validate: function(brandCode) {
var form = '#payment_form_' + this.getCode() + '_' + brandCode; var form = '#payment_form_' + this.getCode() + '_' + brandCode;
var validate = $(form).validation() && $(form).validation('isValid'); var validate = $(form).validation() && $(form).validation('isValid');
...@@ -747,17 +799,17 @@ define( ...@@ -747,17 +799,17 @@ define(
* (in checkout api it is the type) * (in checkout api it is the type)
* @returns {*} * @returns {*}
*/ */
getBrandCodeFromPaymentMethod: function (paymentMethod) { getBrandCodeFromPaymentMethod: function(paymentMethod) {
if (typeof paymentMethod.type !== 'undefined') { if (typeof paymentMethod.type !== 'undefined') {
return paymentMethod.type; return paymentMethod.type;
} }
return ''; return '';
}, },
getRatePayDeviceIdentToken: function () { getRatePayDeviceIdentToken: function() {
return window.checkoutConfig.payment.adyenHpp.deviceIdentToken; return window.checkoutConfig.payment.adyenHpp.deviceIdentToken;
}, },
getLocale: function () { getLocale: function() {
return window.checkoutConfig.payment.adyenHpp.locale; return window.checkoutConfig.payment.adyenHpp.locale;
}, },
/** /**
...@@ -766,11 +818,11 @@ define( ...@@ -766,11 +818,11 @@ define(
* @param details * @param details
* @returns {Array} * @returns {Array}
*/ */
filterOutOpenInvoiceComponentDetails: function (details) { filterOutOpenInvoiceComponentDetails: function(details) {
var self = this; var self = this;
var filteredDetails = _.map(details, function (parentDetail) { var filteredDetails = _.map(details, function(parentDetail) {
if (parentDetail.key == "personalDetails") { if (parentDetail.key == 'personalDetails') {
var detailObject = _.map(parentDetail.details, function (detail) { var detailObject = _.map(parentDetail.details, function(detail) {
if (detail.key == 'dateOfBirth' || if (detail.key == 'dateOfBirth' ||
detail.key == 'telephoneNumber' || detail.key == 'telephoneNumber' ||
detail.key == 'gender') { detail.key == 'gender') {
...@@ -780,9 +832,9 @@ define( ...@@ -780,9 +832,9 @@ define(
if (!!detailObject) { if (!!detailObject) {
return { return {
"key": parentDetail.key, 'key': parentDetail.key,
"type": parentDetail.type, 'type': parentDetail.type,
"details": self.filterUndefinedItemsInArray(detailObject) 'details': self.filterUndefinedItemsInArray(detailObject),
}; };
} }
} }
...@@ -795,17 +847,17 @@ define( ...@@ -795,17 +847,17 @@ define(
* @param arr * @param arr
* @returns {*} * @returns {*}
*/ */
filterUndefinedItemsInArray: function (arr) { filterUndefinedItemsInArray: function(arr) {
return arr.filter(function (item) { return arr.filter(function(item) {
return typeof item !== 'undefined'; return typeof item !== 'undefined';
}); });
}, },
getOriginKey: function () { getOriginKey: function() {
return window.checkoutConfig.payment.adyen.originKey; return window.checkoutConfig.payment.adyen.originKey;
}, },
getCheckoutEnvironment: function () { getCheckoutEnvironment: function() {
return window.checkoutConfig.payment.adyen.checkoutEnvironment; return window.checkoutConfig.payment.adyen.checkoutEnvironment;
} },
}); });
} },
); );
...@@ -42,9 +42,12 @@ define( ...@@ -42,9 +42,12 @@ define(
'Adyen_Payment/js/model/threeds2', 'Adyen_Payment/js/model/threeds2',
'Magento_Checkout/js/model/error-processor', 'Magento_Checkout/js/model/error-processor',
'Adyen_Payment/js/model/adyen-payment-service', 'Adyen_Payment/js/model/adyen-payment-service',
'adyenCheckout' 'adyenCheckout',
], ]
function ( 'Adyen_Payment/js/bundle';
],
function(
ko, ko,
_, _,
$, $,
...@@ -66,8 +69,9 @@ define( ...@@ -66,8 +69,9 @@ define(
threeds2, threeds2,
errorProcessor, errorProcessor,
adyenPaymentService, adyenPaymentService,
AdyenCheckout AdyenCheckout,
) { AdyenComponent,
) {
'use strict'; 'use strict';
...@@ -85,26 +89,26 @@ define( ...@@ -85,26 +89,26 @@ define(
template: 'Adyen_Payment/payment/oneclick-form', template: 'Adyen_Payment/payment/oneclick-form',
recurringDetailReference: '', recurringDetailReference: '',
variant: '', variant: '',
numberOfInstallments: '' numberOfInstallments: '',
}, },
initObservable: function () { initObservable: function() {
this._super() this._super().observe([
.observe([
'recurringDetailReference', 'recurringDetailReference',
'creditCardType', 'creditCardType',
'encryptedCreditCardVerificationNumber', 'encryptedCreditCardVerificationNumber',
'variant', 'variant',
'numberOfInstallments' 'numberOfInstallments',
]); ]);
return this; return this;
}, },
initialize: function () { initialize: function() {
var self = this; var self = this;
this._super(); this._super();
// create component needs to be in initialize method // create component needs to be in initialize method
var messageComponents = {}; var messageComponents = {};
_.map(window.checkoutConfig.payment.adyenOneclick.billingAgreements, function (value) { _.map(window.checkoutConfig.payment.adyenOneclick.billingAgreements,
function(value) {
var messageContainer = new Messages(); var messageContainer = new Messages();
var name = 'messages-' + value.reference_id; var name = 'messages-' + value.reference_id;
...@@ -115,8 +119,8 @@ define( ...@@ -115,8 +119,8 @@ define(
displayArea: 'messages-' + value.reference_id, displayArea: 'messages-' + value.reference_id,
component: 'Magento_Ui/js/view/messages', component: 'Magento_Ui/js/view/messages',
config: { config: {
messageContainer: messageContainer messageContainer: messageContainer,
} },
}; };
layout([messagesComponent]); layout([messagesComponent]);
...@@ -130,7 +134,7 @@ define( ...@@ -130,7 +134,7 @@ define(
* *
* @returns {Array} * @returns {Array}
*/ */
getAdyenBillingAgreements: function () { getAdyenBillingAgreements: function() {
var self = this; var self = this;
// shareable adyen checkout component // shareable adyen checkout component
...@@ -139,12 +143,14 @@ define( ...@@ -139,12 +143,14 @@ define(
originKey: self.getOriginKey(), originKey: self.getOriginKey(),
environment: self.getCheckoutEnvironment(), environment: self.getCheckoutEnvironment(),
risk: { risk: {
enabled: false enabled: false,
} },
}); });
// convert to list so you can iterate // convert to list so you can iterate
var paymentList = _.map(window.checkoutConfig.payment.adyenOneclick.billingAgreements, function (value) { var paymentList = _.map(
window.checkoutConfig.payment.adyenOneclick.billingAgreements,
function(value) {
var creditCardExpMonth, creditCardExpYear = false; var creditCardExpMonth, creditCardExpYear = false;
...@@ -156,22 +162,26 @@ define( ...@@ -156,22 +162,26 @@ define(
// pre-define installments if they are set // pre-define installments if they are set
var i, installments = []; var i, installments = [];
var grandTotal = quote.totals().grand_total; var grandTotal = quote.totals().grand_total;
var dividedString = ""; var dividedString = '';
var dividedAmount = 0; var dividedAmount = 0;
if (value.number_of_installments) { if (value.number_of_installments) {
for (i = 0; i < value.number_of_installments.length; i++) { for (i = 0; i < value.number_of_installments.length; i++) {
dividedAmount = (grandTotal / value.number_of_installments[i]).toFixed(quote.getPriceFormat().precision); dividedAmount = (grandTotal /
dividedString = value.number_of_installments[i] + " x " + dividedAmount + " " + quote.totals().quote_currency_code; value.number_of_installments[i]).toFixed(
quote.getPriceFormat().precision);
dividedString = value.number_of_installments[i] + ' x ' +
dividedAmount + ' ' + quote.totals().quote_currency_code;
installments.push({ installments.push({
key: [dividedString], key: [dividedString],
value: value.number_of_installments[i] value: value.number_of_installments[i],
}); });
} }
} }
var messageContainer = self.messageComponents['messages-' + value.reference_id]; var messageContainer = self.messageComponents['messages-' +
value.reference_id];
// for recurring enable the placeOrder button at all times // for recurring enable the placeOrder button at all times
var placeOrderAllowed = true; var placeOrderAllowed = true;
...@@ -196,9 +206,11 @@ define( ...@@ -196,9 +206,11 @@ define(
'getInstallments': ko.observableArray(installments), 'getInstallments': ko.observableArray(installments),
'placeOrderAllowed': ko.observable(placeOrderAllowed), 'placeOrderAllowed': ko.observable(placeOrderAllowed),
isButtonActive: function() {
isButtonActive: function () { return self.isActive() && this.getCode() == self.isChecked() &&
return self.isActive() && this.getCode() == self.isChecked() && self.isBillingAgreementChecked() && this.placeOrderAllowed() && self.isPlaceOrderActionAllowed(); self.isBillingAgreementChecked() &&
this.placeOrderAllowed() &&
self.isPlaceOrderActionAllowed();
}, },
/** /**
* Custom place order function * Custom place order function
...@@ -209,7 +221,7 @@ define( ...@@ -209,7 +221,7 @@ define(
* @param event * @param event
* @returns {boolean} * @returns {boolean}
*/ */
placeOrder: function (data, event) { placeOrder: function(data, event) {
var self = this; var self = this;
if (event) { if (event) {
...@@ -227,20 +239,20 @@ define( ...@@ -227,20 +239,20 @@ define(
fullScreenLoader.startLoader(); fullScreenLoader.startLoader();
self.isPlaceOrderActionAllowed(false); self.isPlaceOrderActionAllowed(false);
self.getPlaceOrderDeferredObject() self.getPlaceOrderDeferredObject().fail(
.fail( function() {
function () {
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
} },
).done( ).done(
function (orderId) { function(orderId) {
self.afterPlaceOrder(); self.afterPlaceOrder();
adyenPaymentService.getOrderPaymentStatus(orderId) adyenPaymentService.getOrderPaymentStatus(orderId).
.done(function (responseJSON) { done(function(responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId) self.validateThreeDS2OrPlaceOrder(responseJSON,
orderId);
}); });
} },
); );
} }
return false; return false;
...@@ -251,13 +263,14 @@ define( ...@@ -251,13 +263,14 @@ define(
* creates the card component, * creates the card component,
* sets up the callbacks for card components * sets up the callbacks for card components
*/ */
renderSecureCVC: function () { renderSecureCVC: function() {
var self = this; var self = this;
if (!self.getOriginKey()) { if (!self.getOriginKey()) {
return; return;
} }
var oneClickCardNode = document.getElementById('cvcContainer-' + self.value); var oneClickCardNode = document.getElementById(
'cvcContainer-' + self.value);
var hideCVC = false; var hideCVC = false;
// hide cvc if contract has been stored as recurring // hide cvc if contract has been stored as recurring
...@@ -265,51 +278,52 @@ define( ...@@ -265,51 +278,52 @@ define(
hideCVC = true; hideCVC = true;
} }
var oneClickCard = checkout var oneClickCard = checkout.create('card', {
.create('card', {
hideCVC: hideCVC, hideCVC: hideCVC,
brand: self.agreement_data.variant, brand: self.agreement_data.variant,
storedPaymentMethodId: this.value, storedPaymentMethodId: this.value,
expiryMonth: self.agreement_data.card.expiryMonth, expiryMonth: self.agreement_data.card.expiryMonth,
expiryYear: self.agreement_data.card.expiryYear, expiryYear: self.agreement_data.card.expiryYear,
holderName: self.agreement_data.card.holderName, holderName: self.agreement_data.card.holderName,
onChange: function (state, component) { onChange: function(state, component) {
if (state.isValid) { if (state.isValid) {
self.placeOrderAllowed(true); self.placeOrderAllowed(true);
isValid(true); isValid(true);
if (typeof state.data !== 'undefined' && if (typeof state.data !== 'undefined' &&
typeof state.data.paymentMethod !== 'undefined' && typeof state.data.paymentMethod !== 'undefined' &&
typeof state.data.paymentMethod.encryptedSecurityCode !== 'undefined' typeof state.data.paymentMethod.encryptedSecurityCode !==
'undefined'
) { ) {
self.encryptedCreditCardVerificationNumber = state.data.paymentMethod.encryptedSecurityCode; self.encryptedCreditCardVerificationNumber = state.data.paymentMethod.encryptedSecurityCode;
} }
} else { } else {
self.encryptedCreditCardVerificationNumber = ''; self.encryptedCreditCardVerificationNumber = '';
if (self.agreement_data.variant != "maestro") { if (self.agreement_data.variant != 'maestro') {
self.placeOrderAllowed(false); self.placeOrderAllowed(false);
isValid(false); isValid(false);
} }
} }
} },
}) }).mount(oneClickCardNode);
.mount(oneClickCardNode);
window.adyencheckout = oneClickCard; window.adyencheckout = oneClickCard;
}, },
/** /**
* Based on the response we can start a 3DS2 validation or place the order * Based on the response we can start a 3DS2 validation or place the order
* @param responseJSON * @param responseJSON
*/ */
validateThreeDS2OrPlaceOrder: function (responseJSON, orderId) { validateThreeDS2OrPlaceOrder: function(responseJSON, orderId) {
var self = this; var self = this;
var response = JSON.parse(responseJSON); var response = JSON.parse(responseJSON);
if (!!response.threeDS2) { if (!!response.threeDS2) {
// render component // render component
self.renderThreeDS2Component(response.type, response.token, orderId); self.renderThreeDS2Component(response.type, response.token,
orderId);
} else { } else {
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl)); window.location.replace(url.build(
window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
} }
}, },
/** /**
...@@ -323,33 +337,38 @@ define( ...@@ -323,33 +337,38 @@ define(
* @param type * @param type
* @param token * @param token
*/ */
renderThreeDS2Component: function (type, token, orderId) { renderThreeDS2Component: function(type, token, orderId) {
var self = this; var self = this;
var threeDS2Node = document.getElementById('threeDS2ContainerOneClick'); var threeDS2Node = document.getElementById(
'threeDS2ContainerOneClick');
if (type == "IdentifyShopper") { if (type == 'IdentifyShopper') {
self.threeDS2Component = checkout.create('threeDS2DeviceFingerprint', { self.threeDS2Component = checkout.create(
'threeDS2DeviceFingerprint', {
fingerprintToken: token, fingerprintToken: token,
onComplete: function (result) { onComplete: function(result) {
var request = result.data; var request = result.data;
request.orderId = orderId; request.orderId = orderId;
threeds2.processThreeDS2(request).done(function (responseJSON) { threeds2.processThreeDS2(request).
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId) done(function(responseJSON) {
}).fail(function (result) { self.validateThreeDS2OrPlaceOrder(responseJSON,
errorProcessor.process(result, self.getMessageContainer()); orderId);
}).
fail(function(result) {
errorProcessor.process(result,
self.getMessageContainer());
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
}); });
}, },
onError: function (error) { onError: function(error) {
console.log(JSON.stringify(error)); console.log(JSON.stringify(error));
} },
}); });
} else if (type == "ChallengeShopper") { } else if (type == 'ChallengeShopper') {
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
var popupModal = $('#threeDS2ModalOneClick').modal({ var popupModal = $('#threeDS2ModalOneClick').modal({
// disable user to hide popup // disable user to hide popup
clickableOverlay: false, clickableOverlay: false,
...@@ -357,30 +376,34 @@ define( ...@@ -357,30 +376,34 @@ define(
innerScroll: false, innerScroll: false,
// empty buttons, we don't need that // empty buttons, we don't need that
buttons: [], buttons: [],
modalClass: 'threeDS2Modal' modalClass: 'threeDS2Modal',
}); });
popupModal.modal("openModal"); popupModal.modal('openModal');
self.threeDS2Component = checkout self.threeDS2Component = checkout.create('threeDS2Challenge',
.create('threeDS2Challenge', { {
challengeToken: token, challengeToken: token,
onComplete: function (result) { onComplete: function(result) {
popupModal.modal("closeModal"); popupModal.modal('closeModal');
fullScreenLoader.startLoader(); fullScreenLoader.startLoader();
var request = result.data; var request = result.data;
request.orderId = orderId; request.orderId = orderId;
threeds2.processThreeDS2(request).done(function (responseJSON) { threeds2.processThreeDS2(request).
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId) done(function(responseJSON) {
}).fail(function (result) { self.validateThreeDS2OrPlaceOrder(responseJSON,
errorProcessor.process(result, self.getMessageContainer()); orderId);
}).
fail(function(result) {
errorProcessor.process(result,
self.getMessageContainer());
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
}); });
}, },
onError: function (error) { onError: function(error) {
console.log(JSON.stringify(error)); console.log(JSON.stringify(error));
} },
}); });
} }
...@@ -391,12 +414,12 @@ define( ...@@ -391,12 +414,12 @@ define(
* *
* @returns {{method: *, additional_data: {variant: *, recurring_detail_reference: *, number_of_installments: *, cvc: (string|*), expiryMonth: *, expiryYear: *}}} * @returns {{method: *, additional_data: {variant: *, recurring_detail_reference: *, number_of_installments: *, cvc: (string|*), expiryMonth: *, expiryYear: *}}}
*/ */
getData: function () { getData: function() {
var self = this; var self = this;
var browserInfo = threeDS2Utils.getBrowserInfo(); var browserInfo = threeDS2Utils.getBrowserInfo();
return { return {
"method": self.method, 'method': self.method,
additional_data: { additional_data: {
variant: variant(), variant: variant(),
recurring_detail_reference: recurringDetailReference(), recurring_detail_reference: recurringDetailReference(),
...@@ -408,11 +431,11 @@ define( ...@@ -408,11 +431,11 @@ define(
screen_width: browserInfo.screenWidth, screen_width: browserInfo.screenWidth,
screen_height: browserInfo.screenHeight, screen_height: browserInfo.screenHeight,
timezone_offset: browserInfo.timeZoneOffset, timezone_offset: browserInfo.timeZoneOffset,
language: browserInfo.language language: browserInfo.language,
} },
}; };
}, },
validate: function () { validate: function() {
var code = self.item.method; var code = self.item.method;
var value = this.value; var value = this.value;
...@@ -420,42 +443,45 @@ define( ...@@ -420,42 +443,45 @@ define(
var form = 'form[data-role=' + codeValue + ']'; var form = 'form[data-role=' + codeValue + ']';
var validate = $(form).validation() && $(form).validation('isValid'); var validate = $(form).validation() &&
$(form).validation('isValid');
// bcmc does not have any cvc // bcmc does not have any cvc
if (!validate || (isValid() == false && variant() != "bcmc" && variant() != "maestro")) { if (!validate ||
(isValid() == false && variant() != 'bcmc' && variant() !=
'maestro')) {
return false; return false;
} }
return true; return true;
}, },
getCode: function () { getCode: function() {
return self.item.method; return self.item.method;
}, },
hasVerification: function () { hasVerification: function() {
return self.hasVerification() return self.hasVerification();
}, },
getMessageName: function () { getMessageName: function() {
return 'messages-' + value.reference_id; return 'messages-' + value.reference_id;
}, },
getMessageContainer: function () { getMessageContainer: function() {
return messageContainer; return messageContainer;
}, },
getOriginKey: function () { getOriginKey: function() {
return self.getOriginKey(); return self.getOriginKey();
}, },
isPlaceOrderActionAllowed: function () { isPlaceOrderActionAllowed: function() {
return self.isPlaceOrderActionAllowed(); // needed for placeOrder method return self.isPlaceOrderActionAllowed(); // needed for placeOrder method
}, },
afterPlaceOrder: function () { afterPlaceOrder: function() {
return self.afterPlaceOrder(); // needed for placeOrder method return self.afterPlaceOrder(); // needed for placeOrder method
}, },
getPlaceOrderDeferredObject: function () { getPlaceOrderDeferredObject: function() {
return $.when( return $.when(
placeOrderAction(this.getData(), this.getMessageContainer()) placeOrderAction(this.getData(), this.getMessageContainer()),
); );
} },
} };
}); });
return paymentList; return paymentList;
...@@ -465,16 +491,16 @@ define( ...@@ -465,16 +491,16 @@ define(
* *
* @returns {boolean} * @returns {boolean}
*/ */
selectBillingAgreement: function () { selectBillingAgreement: function() {
var self = this; var self = this;
// set payment method data // set payment method data
var data = { var data = {
"method": self.method, 'method': self.method,
"po_number": null, 'po_number': null,
"additional_data": { 'additional_data': {
recurring_detail_reference: self.value recurring_detail_reference: self.value,
} },
}; };
// set the brandCode // set the brandCode
...@@ -489,7 +515,7 @@ define( ...@@ -489,7 +515,7 @@ define(
return true; return true;
}, },
isBillingAgreementChecked: ko.computed(function () { isBillingAgreementChecked: ko.computed(function() {
if (!quote.paymentMethod()) { if (!quote.paymentMethod()) {
return null; return null;
...@@ -502,45 +528,47 @@ define( ...@@ -502,45 +528,47 @@ define(
}), }),
placeOrderHandler: null, placeOrderHandler: null,
validateHandler: null, validateHandler: null,
setPlaceOrderHandler: function (handler) { setPlaceOrderHandler: function(handler) {
this.placeOrderHandler = handler; this.placeOrderHandler = handler;
}, },
setValidateHandler: function (handler) { setValidateHandler: function(handler) {
this.validateHandler = handler; this.validateHandler = handler;
}, },
getPlaceOrderUrl: function () { getPlaceOrderUrl: function() {
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()]; return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
}, },
getCode: function () { getCode: function() {
return window.checkoutConfig.payment.adyenOneclick.methodCode; return window.checkoutConfig.payment.adyenOneclick.methodCode;
}, },
isActive: function () { isActive: function() {
return true; return true;
}, },
getControllerName: function () { getControllerName: function() {
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()]; return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
}, },
context: function () { context: function() {
return this; return this;
}, },
canCreateBillingAgreement: function () { canCreateBillingAgreement: function() {
return window.checkoutConfig.payment.adyenCc.canCreateBillingAgreement; return window.checkoutConfig.payment.adyenCc.canCreateBillingAgreement;
}, },
isShowLegend: function () { isShowLegend: function() {
return true; return true;
}, },
hasVerification: function () { hasVerification: function() {
return window.checkoutConfig.payment.adyenOneclick.hasCustomerInteraction; return window.checkoutConfig.payment.adyenOneclick.hasCustomerInteraction;
}, },
getLocale: function () { getLocale: function() {
return window.checkoutConfig.payment.adyenOneclick.locale; return window.checkoutConfig.payment.adyenOneclick.locale;
}, },
getOriginKey: function () { getOriginKey: function() {
return window.checkoutConfig.payment.adyen.originKey; return window.checkoutConfig.payment.adyen.originKey;
}, },
getCheckoutEnvironment: function () { getCheckoutEnvironment: function() {
return window.checkoutConfig.payment.adyen.checkoutEnvironment; return window.checkoutConfig.payment.adyen.checkoutEnvironment;
} },
}); });
} }
);
)
;
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