We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit cfb02277 authored by Rik ter Beek's avatar Rik ter Beek Committed by GitHub

Merge pull request #241 from Adyen/PW-352

Pw 352
parents a713fbd5 d2458081
...@@ -61,6 +61,9 @@ ...@@ -61,6 +61,9 @@
<item name="adyen_boleto" xsi:type="array"> <item name="adyen_boleto" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item> <item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item> </item>
<item name="adyen_pos" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
<item name="adyen_apple_pay" xsi:type="array"> <item name="adyen_apple_pay" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item> <item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item> </item>
......
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
define(
[
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/url-builder',
'mage/storage',
'mage/url',
'Magento_Checkout/js/model/error-processor',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/full-screen-loader'
],
function (quote, urlBuilder, storage, url, errorProcessor, customer, fullScreenLoader) {
'use strict';
return function (paymentData, redirectOnSuccess) {
var serviceUrl,
payload;
//redirectOnSuccess = redirectOnSuccess !== false;
redirectOnSuccess = redirectOnSuccess === false ? false : true;
/** Checkout for guest and registered customer. */
if (!customer.isLoggedIn()) {
serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payment-information', {
quoteId: quote.getQuoteId()
});
payload = {
cartId: quote.getQuoteId(),
email: quote.guestEmail,
paymentMethod: paymentData,
billingAddress: quote.billingAddress()
};
} else {
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
payload = {
cartId: quote.getQuoteId(),
paymentMethod: paymentData,
billingAddress: quote.billingAddress()
};
}
fullScreenLoader.startLoader();
return storage.post(
serviceUrl, JSON.stringify(payload)
).done(
function (response) {
if (redirectOnSuccess) {
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
} else{
fullScreenLoader.stopLoader();
}
}
).fail(
function (response) {
errorProcessor.process(response);
fullScreenLoader.stopLoader();
}
);
};
}
);
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
define(
[
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/url-builder',
'mage/storage',
'Magento_Checkout/js/model/error-processor',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/full-screen-loader',
'Magento_CheckoutAgreements/js/model/agreements-assigner'
],
function ($, quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader, agreementsAssigner) {
'use strict';
return function () {
var serviceUrl,
payload,
paymentData = quote.paymentMethod();
// use core code to assign the agreement
agreementsAssigner(paymentData);
/** Checkout for guest and registered customer. */
if (!customer.isLoggedIn()) {
serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payment-information', {
quoteId: quote.getQuoteId()
});
payload = {
cartId: quote.getQuoteId(),
email: quote.guestEmail,
paymentMethod: paymentData,
billingAddress: quote.billingAddress()
};
} else {
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
payload = {
cartId: quote.getQuoteId(),
paymentMethod: paymentData,
billingAddress: quote.billingAddress()
};
}
fullScreenLoader.startLoader();
return storage.post(
serviceUrl, JSON.stringify(payload)
).done(
function () {
$.mage.redirect(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl);
}
).fail(
function (response) {
errorProcessor.process(response);
fullScreenLoader.stopLoader();
}
);
};
}
);
...@@ -19,19 +19,14 @@ ...@@ -19,19 +19,14 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
/*browser:true*/
/*global define*/
define( define(
[ [
'underscore', 'underscore',
'jquery', 'jquery',
'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/model/quote',
'Magento_Payment/js/view/payment/cc-form', 'Magento_Payment/js/view/payment/cc-form'
'Adyen_Payment/js/action/place-order',
'mage/translate',
'Magento_Checkout/js/model/payment/additional-validators'
], ],
function (_, $, quote, Component, placeOrderAction, $t, additionalValidators) { function (_, $, quote, Component) {
'use strict'; 'use strict';
var billingAddress = quote.billingAddress(); var billingAddress = quote.billingAddress();
return Component.extend({ return Component.extend({
...@@ -51,16 +46,16 @@ define( ...@@ -51,16 +46,16 @@ define(
]); ]);
return this; return this;
}, },
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_boleto'; return 'adyen_boleto';
}, },
getData: function() { getData: function () {
return { return {
'method': this.item.method, 'method': this.item.method,
'additional_data': { 'additional_data': {
...@@ -71,56 +66,34 @@ define( ...@@ -71,56 +66,34 @@ define(
} }
}; };
}, },
isActive: function() { isActive: function () {
return true; return true;
}, },
/** getControllerName: function () {
* @override
*/
placeOrder: function(data, event) {
var self = this,
placeOrder;
if (event) {
event.preventDefault();
}
if (this.validate() && additionalValidators.validate()) {
this.isPlaceOrderActionAllowed(false);
placeOrder = placeOrderAction(this.getData(), this.redirectAfterPlaceOrder);
$.when(placeOrder).fail(function(response) {
self.isPlaceOrderActionAllowed(true);
});
return true;
}
return false;
},
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()];
}, },
context: function() { context: function () {
return this; return this;
}, },
validate: function () { validate: function () {
var form = 'form[data-role=adyen-boleto-form]'; var form = 'form[data-role=adyen-boleto-form]';
var validate = $(form).validation() && $(form).validation('isValid'); var validate = $(form).validation() && $(form).validation('isValid');
if(!validate) { if (!validate) {
return false; return false;
} }
return true; return true;
}, },
showLogo: function() { showLogo: function () {
return window.checkoutConfig.payment.adyen.showLogo; return window.checkoutConfig.payment.adyen.showLogo;
}, },
getBoletoTypes: function() { getBoletoTypes: function () {
return _.map(window.checkoutConfig.payment.adyenBoleto.boletoTypes, function(value, key) { return _.map(window.checkoutConfig.payment.adyenBoleto.boletoTypes, function (value, key) {
return { return {
'key': value.value, 'key': value.value,
'value': value.label 'value': value.label
......
...@@ -19,23 +19,19 @@ ...@@ -19,23 +19,19 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
/*browser:true*/
/*global define*/
define( define(
[ [
'underscore',
'jquery', 'jquery',
'ko',
'Magento_Payment/js/view/payment/cc-form', 'Magento_Payment/js/view/payment/cc-form',
'Adyen_Payment/js/action/place-order',
'mage/translate',
'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Customer/js/model/customer', 'Magento_Customer/js/model/customer',
'Magento_Payment/js/model/credit-card-validation/credit-card-data', 'Magento_Payment/js/model/credit-card-validation/credit-card-data',
'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/model/quote',
'ko',
'Adyen_Payment/js/model/installments', 'Adyen_Payment/js/model/installments',
'mage/url'
], ],
function (_, $, Component, placeOrderAction, $t, additionalValidators, customer, creditCardData, quote, ko, installments) { function ($, ko, Component, customer, creditCardData, additionalValidators, quote, installments, url) {
'use strict'; 'use strict';
var cvcLength = ko.observable(4); var cvcLength = ko.observable(4);
...@@ -160,39 +156,50 @@ define( ...@@ -160,39 +156,50 @@ define(
* @override * @override
*/ */
placeOrder: function (data, event) { placeOrder: function (data, event) {
var self = this, var self = this;
placeOrder;
if (event) { if (event) {
event.preventDefault(); event.preventDefault();
} }
var options = {}; var options = {};
var cseInstance = adyen.createEncryption(options); var cseInstance = adyen.createEncryption(options);
var generationtime = self.getGenerationTime(); var generationtime = this.getGenerationTime();
var cardData = { var cardData = {
number: self.creditCardNumber(), number: this.creditCardNumber(),
cvc: self.creditCardVerificationNumber(), cvc: this.creditCardVerificationNumber(),
holderName: self.creditCardOwner(), holderName: this.creditCardOwner(),
expiryMonth: self.creditCardExpMonth(), expiryMonth: this.creditCardExpMonth(),
expiryYear: self.creditCardExpYear(), expiryYear: this.creditCardExpYear(),
generationtime: generationtime generationtime: generationtime
}; };
var data = cseInstance.encrypt(cardData); var data = cseInstance.encrypt(cardData);
self.encryptedData(data); this.encryptedData(data);
if (this.validate() && additionalValidators.validate()) { if (this.validate() && additionalValidators.validate()) {
this.isPlaceOrderActionAllowed(false); this.isPlaceOrderActionAllowed(false);
placeOrder = placeOrderAction(this.getData(), this.redirectAfterPlaceOrder);
$.when(placeOrder).fail(function (response) { this.getPlaceOrderDeferredObject()
self.isPlaceOrderActionAllowed(true); .fail(
}); function () {
self.isPlaceOrderActionAllowed(true);
}
).done(
function () {
self.afterPlaceOrder();
if (self.redirectAfterPlaceOrder) {
// use custom redirect Link for supporting 3D secure
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
}
}
);
return true; return true;
} }
return false; return false;
}, },
getControllerName: function () { getControllerName: function () {
......
...@@ -19,14 +19,11 @@ ...@@ -19,14 +19,11 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
/*browser:true*/
/*global define*/
define( define(
[ [
'ko', 'ko',
'jquery', 'jquery',
'Magento_Checkout/js/view/payment/default', 'Magento_Checkout/js/view/payment/default',
'Adyen_Payment/js/action/set-payment-method',
'Magento_Checkout/js/action/select-payment-method', 'Magento_Checkout/js/action/select-payment-method',
'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/checkout-data', 'Magento_Checkout/js/checkout-data',
...@@ -35,14 +32,17 @@ define( ...@@ -35,14 +32,17 @@ define(
'Magento_Checkout/js/model/url-builder', 'Magento_Checkout/js/model/url-builder',
'Adyen_Payment/js/model/adyen-payment-service', 'Adyen_Payment/js/model/adyen-payment-service',
'Magento_Customer/js/model/customer', 'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/full-screen-loader' 'Magento_Checkout/js/model/full-screen-loader',
'Magento_Checkout/js/action/place-order',
'uiLayout',
'Magento_Ui/js/model/messages'
], ],
function (ko, $, Component, setPaymentMethodAction, selectPaymentMethodAction, quote, checkoutData, additionalValidators, storage, urlBuilder, adyenPaymentService, customer, fullScreenLoader) { function (ko, $, Component, selectPaymentMethodAction, quote, checkoutData, additionalValidators, storage, urlBuilder, adyenPaymentService, customer, fullScreenLoader, placeOrderAction, layout, Messages) {
'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 dfValue = ko.observable(null); var dfValue = ko.observable(null);
var messageComponents;
return Component.extend({ return Component.extend({
self: this, self: this,
defaults: { defaults: {
...@@ -128,6 +128,27 @@ define( ...@@ -128,6 +128,27 @@ define(
document.body.appendChild(dfScriptTag); document.body.appendChild(dfScriptTag);
waitForDfSet(); waitForDfSet();
// create component needs to be in initialize method
var messageComponents = {};
_.map(response, function (value) {
var messageContainer = new Messages();
var name = 'messages-' + value.brandCode;
var messagesComponent = {
parent: self.name,
name: 'messages-' + value.brandCode,
displayArea: 'messages-' + value.brandCode,
component: 'Magento_Ui/js/view/messages',
config: {
messageContainer: messageContainer
}
};
layout([messagesComponent]);
messageComponents[name] = messageContainer;
});
self.messageComponents = messageComponents;
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
} }
).fail(function (error) { ).fail(function (error) {
...@@ -150,6 +171,15 @@ define( ...@@ -150,6 +171,15 @@ define(
result.validate = function () { result.validate = function () {
return self.validate(value.brandCode); return self.validate(value.brandCode);
}; };
result.placeRedirectOrder = function placeRedirectOrder(data) {
return self.placeRedirectOrder(data);
};
result.isPlaceOrderActionAllowed = function(bool) {
return self.isPlaceOrderActionAllowed(bool);
};
result.afterPlaceOrder = function() {
return self.afterPlaceOrder();
};
result.isPaymentMethodOpenInvoiceMethod = function () { result.isPaymentMethodOpenInvoiceMethod = function () {
return value.isPaymentMethodOpenInvoiceMethod; return value.isPaymentMethodOpenInvoiceMethod;
}; };
...@@ -212,10 +242,12 @@ define( ...@@ -212,10 +242,12 @@ define(
}, },
/** Redirect to adyen */ /** Redirect to adyen */
continueToAdyen: function () { continueToAdyen: function () {
var self = this;
if (this.validate() && additionalValidators.validate()) { if (this.validate() && additionalValidators.validate()) {
//update payment method information if additional data was changed var data = {};
this.selectPaymentMethod(); data.method = self.method;
setPaymentMethodAction(); this.placeRedirectOrder(data);
return false; return false;
} }
}, },
...@@ -246,9 +278,7 @@ define( ...@@ -246,9 +278,7 @@ define(
} }
data.additional_data = additionalData; data.additional_data = additionalData;
this.placeRedirectOrder(data);
selectPaymentMethodAction(data);
setPaymentMethodAction();
} }
return false; return false;
...@@ -276,6 +306,32 @@ define( ...@@ -276,6 +306,32 @@ define(
return true; return true;
}, },
placeRedirectOrder: function(data) {
// Place Order but use our own redirect url after
var self = this;
var messageContainer = this.messageContainer;
if(brandCode()) {
messageContainer = self.messageComponents['messages-' + brandCode()];
}
this.isPlaceOrderActionAllowed(false);
fullScreenLoader.startLoader();
$.when(
placeOrderAction(data, messageContainer)
).fail(
function () {
self.isPlaceOrderActionAllowed(true);
}
).done(
function () {
self.afterPlaceOrder();
$.mage.redirect(
window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl
);
}
)
},
isBrandCodeChecked: ko.computed(function () { isBrandCodeChecked: ko.computed(function () {
if (!quote.paymentMethod()) { if (!quote.paymentMethod()) {
......
...@@ -19,31 +19,38 @@ ...@@ -19,31 +19,38 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
/*browser:true*/
/*global define*/
define( define(
[ [
'ko', 'ko',
'underscore', 'underscore',
'jquery', 'jquery',
'Magento_Payment/js/view/payment/cc-form', 'Magento_Payment/js/view/payment/cc-form',
'Adyen_Payment/js/action/place-order',
'mage/translate',
'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Checkout/js/action/select-payment-method', 'Magento_Checkout/js/action/select-payment-method',
'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/checkout-data' 'Magento_Checkout/js/checkout-data',
'Magento_Checkout/js/action/redirect-on-success',
'uiLayout',
'Magento_Ui/js/model/messages',
'Magento_Checkout/js/action/place-order',
'mage/url'
], ],
function (ko, _, $, Component, placeOrderAction, $t, additionalValidators, selectPaymentMethodAction, quote, checkoutData) { function (ko, _, $, Component, selectPaymentMethodAction, additionalValidators, quote, checkoutData, redirectOnSuccessAction, layout, Messages, placeOrderAction, url) {
'use strict'; 'use strict';
var updatedExpiryDate = false; var updatedExpiryDate = false;
var recurringDetailReference = ko.observable(null); var recurringDetailReference = ko.observable(null);
var variant = ko.observable(null);
var paymentMethod = ko.observable(null); var paymentMethod = ko.observable(null);
var encryptedData = ko.observable(null);
var numberOfInstallments = ko.observable(null);
var messageComponents;
return Component.extend({ return Component.extend({
defaults: { defaults: {
template: 'Adyen_Payment/payment/oneclick-form', template: 'Adyen_Payment/payment/oneclick-form',
recurringDetailReference: '', recurringDetailReference: '',
encryptedData: '' encryptedData: '',
variant: '',
numberOfInstallments: ''
}, },
initObservable: function () { initObservable: function () {
this._super() this._super()
...@@ -51,13 +58,37 @@ define( ...@@ -51,13 +58,37 @@ define(
'recurringDetailReference', 'recurringDetailReference',
'creditCardType', 'creditCardType',
'creditCardVerificationNumber', 'creditCardVerificationNumber',
'encryptedData' 'encryptedData',
'variant',
'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
var messageComponents = {};
_.map(window.checkoutConfig.payment.adyenOneclick.billingAgreements, function (value) {
var messageContainer = new Messages();
var name = 'messages-' + value.reference_id;
var messagesComponent = {
parent: self.name,
name: 'messages-' + value.reference_id,
// name: self.name + '.messages',
displayArea: 'messages-' + value.reference_id,
component: 'Magento_Ui/js/view/messages',
config: {
messageContainer: messageContainer
}
};
layout([messagesComponent]);
messageComponents[name] = messageContainer;
});
this.messageComponents = messageComponents;
}, },
placeOrderHandler: null, placeOrderHandler: null,
validateHandler: null, validateHandler: null,
...@@ -73,63 +104,6 @@ define( ...@@ -73,63 +104,6 @@ define(
isActive: function () { isActive: function () {
return true; return true;
}, },
/**
* @override
*/
placeOrder: function (data, event) {
var self = this,
placeOrder;
if (event) {
event.preventDefault();
}
var data = {
"method": self.method,
"additional_data": {
variant: self.agreement_data.variant,
recurring_detail_reference: self.value
}
}
// only use CSE and installments for cards
if (self.agreement_data.card) {
var generationtime = self.getGenerationTime();
var cardData = {
cvc: self.creditCardVerificationNumber,
expiryMonth: self.creditCardExpMonth(),
expiryYear: self.creditCardExpYear(),
generationtime: generationtime
};
if (updatedExpiryDate || self.hasVerification()) {
var options = {enableValidations: false};
var cseInstance = adyen.createEncryption(options);
var encryptedData = cseInstance.encrypt(cardData);
data.additional_data.encrypted_data = encryptedData;
}
// set payment method to adyen_hpp
data.additional_data.number_of_installments = self.installment;
}
if (this.validate() && additionalValidators.validate()) {
//this.isPlaceOrderActionAllowed(false);
placeOrder = placeOrderAction(data, this.redirectAfterPlaceOrder);
$.when(placeOrder).fail(function (response) {
//self.isPlaceOrderActionAllowed(true);
});
return true;
}
return false;
},
getControllerName: function () { getControllerName: function () {
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()]; return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
}, },
...@@ -172,6 +146,8 @@ define( ...@@ -172,6 +146,8 @@ define(
} }
} }
var messageContainer = self.messageComponents['messages-' + value.reference_id];
return { return {
'expiry': ko.observable(false), 'expiry': ko.observable(false),
'label': value.agreement_label, 'label': value.agreement_label,
...@@ -195,6 +171,91 @@ define( ...@@ -195,6 +171,91 @@ define(
hasVerification: function () { hasVerification: function () {
return window.checkoutConfig.payment.adyenOneclick.hasCustomerInteraction; return window.checkoutConfig.payment.adyenOneclick.hasCustomerInteraction;
}, },
/**
* @override
*/
placeOrder: function (data, event) {
var self = this;
if (event) {
event.preventDefault();
}
var data = {
"method": self.method,
"additional_data": {
variant: self.agreement_data.variant,
recurring_detail_reference: self.value
}
}
// only use CSE and installments for cards
if (self.agreement_data.card) {
var generationtime = self.getGenerationTime();
var cardData = {
cvc: self.creditCardVerificationNumber,
expiryMonth: self.creditCardExpMonth(),
expiryYear: self.creditCardExpYear(),
generationtime: generationtime
};
if (updatedExpiryDate || self.hasVerification()) {
var options = {enableValidations: false};
var cseInstance = adyen.createEncryption(options);
var encryptedDataResult = cseInstance.encrypt(cardData);
encryptedData(encryptedDataResult)
}
// set payment method to adyen_hpp
// TODO can observer in front-end this not needed
numberOfInstallments(self.installment);
}
// in different context so need custom place order logic
if (this.validate() && additionalValidators.validate()) {
self.isPlaceOrderActionAllowed(false);
this.getPlaceOrderDeferredObject()
.fail(
function () {
self.isPlaceOrderActionAllowed(true);
}
).done(
function () {
self.afterPlaceOrder();
// use custom redirect Link for supporting 3D secure
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
}
);
return true;
}
return false;
},
getData: function () {
return {
"method": self.item.method,
"additional_data": {
variant: variant(),
recurring_detail_reference: recurringDetailReference(),
number_of_installments: numberOfInstallments(),
encrypted_data: encryptedData()
}
};
},
isPlaceOrderActionAllowed: function () {
return self.isPlaceOrderActionAllowed(); // needed for placeOrder method
},
afterPlaceOrder: function () {
return self.afterPlaceOrder(); // needed for placeOrder method
},
getPlaceOrderDeferredObject: function () {
return $.when(
placeOrderAction(this.getData(), this.getMessageContainer())
);
},
validate: function () { validate: function () {
var code = self.item.method; var code = self.item.method;
...@@ -233,7 +294,13 @@ define( ...@@ -233,7 +294,13 @@ define(
var self = this; var self = this;
self.expiry(true); self.expiry(true);
return true; return true;
} },
getMessageName: function () {
return 'messages-' + value.reference_id;
},
getMessageContainer: function () {
return messageContainer;
},
} }
}); });
return paymentList; return paymentList;
...@@ -254,6 +321,7 @@ define( ...@@ -254,6 +321,7 @@ define(
// set the brandCode // set the brandCode
recurringDetailReference(self.value); recurringDetailReference(self.value);
variant(self.agreement_data.variant);
// set payment method // set payment method
paymentMethod(self.method); paymentMethod(self.method);
......
...@@ -19,42 +19,53 @@ ...@@ -19,42 +19,53 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
/*browser:true*/
/*global define*/
define( define(
[ [
'ko', 'jquery',
'Magento_Checkout/js/view/payment/default', 'Magento_Checkout/js/view/payment/default',
'Adyen_Payment/js/action/set-payment-method', 'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Checkout/js/model/payment/additional-validators' 'Magento_Checkout/js/model/full-screen-loader',
'Magento_Checkout/js/action/place-order',
'Magento_Checkout/js/model/quote'
], ],
function (ko, Component, setPaymentMethodAction, additionalValidators) { function ($, Component, additionalValidators, fullScreenLoader, placeOrderAction, quote) {
'use strict'; 'use strict';
var brandCode = ko.observable(null);
var paymentMethod = ko.observable(null);
return Component.extend({ return Component.extend({
self: this,
defaults: { defaults: {
template: 'Adyen_Payment/payment/pos-form', template: 'Adyen_Payment/payment/pos-form'
brandCode: ''
}, },
initObservable: function () { initObservable: function () {
this._super() this._super()
.observe([ .observe([]);
]);
return this; return this;
}, },
/** Redirect to adyen */ /** Redirect to adyen */
continueToAdyen: function () { continueToAdyen: function () {
var self = this;
if (this.validate() && additionalValidators.validate()) { if (this.validate() && additionalValidators.validate()) {
//update payment method information if additional data was changed //update payment method information if additional data was changed
this.selectPaymentMethod(); this.isPlaceOrderActionAllowed(false);
setPaymentMethodAction(); fullScreenLoader.startLoader();
return false;
$.when(
placeOrderAction(this.getData(), this.messageContainer)
).fail(
function () {
self.isPlaceOrderActionAllowed(true);
}
).done(
function () {
self.afterPlaceOrder();
$.mage.redirect(
window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl
);
}
);
} }
return false;
}, },
showLogo: function() { showLogo: function () {
return window.checkoutConfig.payment.adyen.showLogo; return window.checkoutConfig.payment.adyen.showLogo;
}, },
validate: function () { validate: function () {
......
...@@ -19,19 +19,14 @@ ...@@ -19,19 +19,14 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
/*browser:true*/
/*global define*/
define( define(
[ [
'underscore', 'underscore',
'jquery', 'jquery',
'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/model/quote',
'Magento_Payment/js/view/payment/cc-form', 'Magento_Payment/js/view/payment/cc-form'
'Adyen_Payment/js/action/place-order',
'mage/translate',
'Magento_Checkout/js/model/payment/additional-validators'
], ],
function (_, $, quote, Component, placeOrderAction, $t, additionalValidators) { function (_, $, quote, Component) {
'use strict'; 'use strict';
var billingAddress = quote.billingAddress(); var billingAddress = quote.billingAddress();
return Component.extend({ return Component.extend({
...@@ -56,16 +51,16 @@ define( ...@@ -56,16 +51,16 @@ define(
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_sepa'; return 'adyen_sepa';
}, },
getData: function() { getData: function () {
return { return {
'method': this.item.method, 'method': this.item.method,
'additional_data': { 'additional_data': {
...@@ -76,56 +71,34 @@ define( ...@@ -76,56 +71,34 @@ define(
} }
}; };
}, },
isActive: function() { isActive: function () {
return true; return true;
}, },
/** getControllerName: function () {
* @override
*/
placeOrder: function(data, event) {
var self = this,
placeOrder;
if (event) {
event.preventDefault();
}
if (this.validate() && additionalValidators.validate()) {
this.isPlaceOrderActionAllowed(false);
placeOrder = placeOrderAction(this.getData(), this.redirectAfterPlaceOrder);
$.when(placeOrder).fail(function(response) {
self.isPlaceOrderActionAllowed(true);
});
return true;
}
return false;
},
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()];
}, },
context: function() { context: function () {
return this; return this;
}, },
validate: function () { validate: function () {
var form = 'form[data-role=adyen-sepa-form]'; var form = 'form[data-role=adyen-sepa-form]';
var validate = $(form).validation() && $(form).validation('isValid'); var validate = $(form).validation() && $(form).validation('isValid');
if(!validate) { if (!validate) {
return false; return false;
} }
return true; return true;
}, },
showLogo: function() { showLogo: function () {
return window.checkoutConfig.payment.adyen.showLogo; return window.checkoutConfig.payment.adyen.showLogo;
}, },
getCountries: function() { getCountries: function () {
return _.map(window.checkoutConfig.payment.adyenSepa.countries, function(value, key) { return _.map(window.checkoutConfig.payment.adyenSepa.countries, function (value, key) {
return { return {
'key': key, 'key': key,
'value': value 'value': value
......
...@@ -55,6 +55,10 @@ ...@@ -55,6 +55,10 @@
'orderSaveUrl':getPlaceOrderUrl(), 'orderSaveUrl':getPlaceOrderUrl(),
}, 'validation':[]}"> }, 'validation':[]}">
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<fieldset data-bind="attr: {class: 'fieldset payment items adyen_boleto ' + getCode(), id: 'payment_form_' + getCode()}"> <fieldset data-bind="attr: {class: 'fieldset payment items adyen_boleto ' + getCode(), id: 'payment_form_' + getCode()}">
<!-- ko if: (isShowLegend())--> <!-- ko if: (isShowLegend())-->
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
</div> </div>
<div class="payment-method-content"> <div class="payment-method-content">
<div class="payment-method-billing-address"> <div class="payment-method-billing-address">
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) --> <!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
<!-- ko template: getTemplate() --><!-- /ko --> <!-- ko template: getTemplate() --><!-- /ko -->
...@@ -53,6 +54,11 @@ ...@@ -53,6 +54,11 @@
}, 'validation':[]}"> }, 'validation':[]}">
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<fieldset <fieldset
data-bind="attr: {class: 'fieldset payment items ccard ' + getCode(), id: 'payment_form_' + getCode()}"> data-bind="attr: {class: 'fieldset payment items ccard ' + getCode(), id: 'payment_form_' + getCode()}">
<!-- ko if: (isShowLegend())--> <!-- ko if: (isShowLegend())-->
...@@ -268,6 +274,8 @@ ...@@ -268,6 +274,8 @@
<!-- ko template: getTemplate() --><!-- /ko --> <!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko--> <!--/ko-->
</div> </div>
<div class="actions-toolbar"> <div class="actions-toolbar">
<div class="primary"> <div class="primary">
<button class="action primary checkout" <button class="action primary checkout"
......
...@@ -97,13 +97,17 @@ ...@@ -97,13 +97,17 @@
<div class="control"> <div class="control">
<input type="text" class="input-text" <input type="text" class="input-text"
name="payment[dob]" name="payment[dob]"
data-bind=" datepicker: { storage: datepickerValue, options: { showOn: 'both', changeYear: true, yearRange: '-99:-1', defaultDate: '-20y' } }, data-bind="
attr: { attr: {
id: getCode() + '_dob_' + value, id: getCode() + '_dob_' + value,
title: $t('Date of Birth'), title: $t('Date of Birth'),
'data-container': getCode() + '-dob' 'data-container': getCode() + '-dob_' + value,
}, },
value: dob" datepicker: {
storage: datepickerValue,
options: { showOn: 'both', changeYear: true, yearRange: '-99:-1', defaultDate: '-20y' }
},
value: dob"
data-validate="{required:true}" data-validate="{required:true}"
/> />
</div> </div>
......
...@@ -23,9 +23,11 @@ ...@@ -23,9 +23,11 @@
--> -->
<!-- ko foreach: getAdyenBillingAgreements() -->
<!-- ko foreach: getAdyenBillingAgreements() -->
<div class="payment-method" data-bind="css: {'_active': (value == $parent.isBillingAgreementChecked())}"> <div class="payment-method" data-bind="css: {'_active': (value == $parent.isBillingAgreementChecked())}">
<div class="payment-method-title field choice"> <div class="payment-method-title field choice">
<input type="radio" <input type="radio"
name="payment[method]" name="payment[method]"
...@@ -50,12 +52,18 @@ ...@@ -50,12 +52,18 @@
</div> </div>
<div class="payment-method-content"> <div class="payment-method-content">
<!-- ko foreach: $parent.getRegion(getMessageName()) -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div class="payment-method-billing-address"> <div class="payment-method-billing-address">
<!-- ko foreach: $parents[1].getRegion($parent.getBillingAddressFormName()) --> <!-- ko foreach: $parents[1].getRegion($parent.getBillingAddressFormName()) -->
<!-- ko template: getTemplate() --><!-- /ko --> <!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko--> <!--/ko-->
</div> </div>
<form class="form" action="#" method="post" data-bind=" <form class="form" action="#" method="post" data-bind="
attr: {'id': 'adyen_oneclick_' + value, 'data-role': 'adyen_oneclick_' + value }, attr: {'id': 'adyen_oneclick_' + value, 'data-role': 'adyen_oneclick_' + value },
mageInit: { mageInit: {
...@@ -221,9 +229,6 @@ ...@@ -221,9 +229,6 @@
<!-- /ko --> <!-- /ko -->
</fieldset> </fieldset>
<div class="checkout-agreements-block"> <div class="checkout-agreements-block">
<!-- ko foreach: $parents[1].getRegion('before-place-order') --> <!-- ko foreach: $parents[1].getRegion('before-place-order') -->
...@@ -235,7 +240,7 @@ ...@@ -235,7 +240,7 @@
<button class="action primary checkout" <button class="action primary checkout"
type="submit" type="submit"
data-bind=" data-bind="
click: $parent.placeOrder, click: placeOrder,
attr: {title: $t('Place Order')}, attr: {title: $t('Place Order')},
enable: (value == $parent.isBillingAgreementChecked()) enable: (value == $parent.isBillingAgreementChecked())
" "
......
...@@ -45,6 +45,11 @@ ...@@ -45,6 +45,11 @@
<!-- ko template: getTemplate() --><!-- /ko --> <!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko--> <!--/ko-->
</div> </div>
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<fieldset class="fieldset" data-bind='attr: {id: "payment_form_" + getCode()}'> <fieldset class="fieldset" data-bind='attr: {id: "payment_form_" + getCode()}'>
<div class="payment-method-note"> <div class="payment-method-note">
<!-- ko text: $t('You will be redirected to the Adyen App.') --><!-- /ko --> <!-- ko text: $t('You will be redirected to the Adyen App.') --><!-- /ko -->
......
...@@ -46,7 +46,9 @@ ...@@ -46,7 +46,9 @@
<!--/ko--> <!--/ko-->
</div> </div>
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<form class="form" id="adyen-sepa-form" data-role="adyen-sepa-form" action="#" method="post" data-bind="mageInit: { <form class="form" id="adyen-sepa-form" data-role="adyen-sepa-form" action="#" method="post" data-bind="mageInit: {
'transparent':{ 'transparent':{
......
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