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 @@
<item name="adyen_boleto" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</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="isBillingAddressRequired" xsi:type="boolean">true</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 @@
*
* Author: Adyen <magento@adyen.com>
*/
/*browser:true*/
/*global define*/
define(
[
'underscore',
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Payment/js/view/payment/cc-form',
'Adyen_Payment/js/action/place-order',
'mage/translate',
'Magento_Checkout/js/model/payment/additional-validators'
'Magento_Payment/js/view/payment/cc-form'
],
function (_, $, quote, Component, placeOrderAction, $t, additionalValidators) {
function (_, $, quote, Component) {
'use strict';
var billingAddress = quote.billingAddress();
return Component.extend({
......@@ -51,16 +46,16 @@ define(
]);
return this;
},
setPlaceOrderHandler: function(handler) {
setPlaceOrderHandler: function (handler) {
this.placeOrderHandler = handler;
},
setValidateHandler: function(handler) {
setValidateHandler: function (handler) {
this.validateHandler = handler;
},
getCode: function() {
getCode: function () {
return 'adyen_boleto';
},
getData: function() {
getData: function () {
return {
'method': this.item.method,
'additional_data': {
......@@ -71,56 +66,34 @@ define(
}
};
},
isActive: function() {
isActive: function () {
return true;
},
/**
* @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() {
getControllerName: function () {
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
},
getPlaceOrderUrl: function() {
getPlaceOrderUrl: function () {
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
},
context: function() {
context: function () {
return this;
},
validate: function () {
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 true;
},
showLogo: function() {
showLogo: function () {
return window.checkoutConfig.payment.adyen.showLogo;
},
getBoletoTypes: function() {
return _.map(window.checkoutConfig.payment.adyenBoleto.boletoTypes, function(value, key) {
getBoletoTypes: function () {
return _.map(window.checkoutConfig.payment.adyenBoleto.boletoTypes, function (value, key) {
return {
'key': value.value,
'value': value.label
......
......@@ -19,23 +19,19 @@
*
* Author: Adyen <magento@adyen.com>
*/
/*browser:true*/
/*global define*/
define(
[
'underscore',
'jquery',
'ko',
'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_Payment/js/model/credit-card-validation/credit-card-data',
'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Checkout/js/model/quote',
'ko',
'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';
var cvcLength = ko.observable(4);
......@@ -160,39 +156,50 @@ define(
* @override
*/
placeOrder: function (data, event) {
var self = this,
placeOrder;
var self = this;
if (event) {
event.preventDefault();
}
var options = {};
var cseInstance = adyen.createEncryption(options);
var generationtime = self.getGenerationTime();
var generationtime = this.getGenerationTime();
var cardData = {
number: self.creditCardNumber(),
cvc: self.creditCardVerificationNumber(),
holderName: self.creditCardOwner(),
expiryMonth: self.creditCardExpMonth(),
expiryYear: self.creditCardExpYear(),
number: this.creditCardNumber(),
cvc: this.creditCardVerificationNumber(),
holderName: this.creditCardOwner(),
expiryMonth: this.creditCardExpMonth(),
expiryYear: this.creditCardExpYear(),
generationtime: generationtime
};
var data = cseInstance.encrypt(cardData);
self.encryptedData(data);
this.encryptedData(data);
if (this.validate() && additionalValidators.validate()) {
this.isPlaceOrderActionAllowed(false);
placeOrder = placeOrderAction(this.getData(), this.redirectAfterPlaceOrder);
$.when(placeOrder).fail(function (response) {
self.isPlaceOrderActionAllowed(true);
});
this.getPlaceOrderDeferredObject()
.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 false;
},
getControllerName: function () {
......
......@@ -19,14 +19,11 @@
*
* Author: Adyen <magento@adyen.com>
*/
/*browser:true*/
/*global define*/
define(
[
'ko',
'jquery',
'Magento_Checkout/js/view/payment/default',
'Adyen_Payment/js/action/set-payment-method',
'Magento_Checkout/js/action/select-payment-method',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/checkout-data',
......@@ -35,14 +32,17 @@ define(
'Magento_Checkout/js/model/url-builder',
'Adyen_Payment/js/model/adyen-payment-service',
'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';
var brandCode = ko.observable(null);
var paymentMethod = ko.observable(null);
var dfValue = ko.observable(null);
var messageComponents;
return Component.extend({
self: this,
defaults: {
......@@ -128,6 +128,27 @@ define(
document.body.appendChild(dfScriptTag);
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();
}
).fail(function (error) {
......@@ -150,6 +171,15 @@ define(
result.validate = function () {
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 () {
return value.isPaymentMethodOpenInvoiceMethod;
};
......@@ -212,10 +242,12 @@ define(
},
/** Redirect to adyen */
continueToAdyen: function () {
var self = this;
if (this.validate() && additionalValidators.validate()) {
//update payment method information if additional data was changed
this.selectPaymentMethod();
setPaymentMethodAction();
var data = {};
data.method = self.method;
this.placeRedirectOrder(data);
return false;
}
},
......@@ -246,9 +278,7 @@ define(
}
data.additional_data = additionalData;
selectPaymentMethodAction(data);
setPaymentMethodAction();
this.placeRedirectOrder(data);
}
return false;
......@@ -276,6 +306,32 @@ define(
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 () {
if (!quote.paymentMethod()) {
......
......@@ -19,42 +19,53 @@
*
* Author: Adyen <magento@adyen.com>
*/
/*browser:true*/
/*global define*/
define(
[
'ko',
'jquery',
'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';
var brandCode = ko.observable(null);
var paymentMethod = ko.observable(null);
return Component.extend({
self: this,
defaults: {
template: 'Adyen_Payment/payment/pos-form',
brandCode: ''
template: 'Adyen_Payment/payment/pos-form'
},
initObservable: function () {
this._super()
.observe([
]);
.observe([]);
return this;
},
/** Redirect to adyen */
continueToAdyen: function () {
var self = this;
if (this.validate() && additionalValidators.validate()) {
//update payment method information if additional data was changed
this.selectPaymentMethod();
setPaymentMethodAction();
return false;
this.isPlaceOrderActionAllowed(false);
fullScreenLoader.startLoader();
$.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;
},
validate: function () {
......
......@@ -19,19 +19,14 @@
*
* Author: Adyen <magento@adyen.com>
*/
/*browser:true*/
/*global define*/
define(
[
'underscore',
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Payment/js/view/payment/cc-form',
'Adyen_Payment/js/action/place-order',
'mage/translate',
'Magento_Checkout/js/model/payment/additional-validators'
'Magento_Payment/js/view/payment/cc-form'
],
function (_, $, quote, Component, placeOrderAction, $t, additionalValidators) {
function (_, $, quote, Component) {
'use strict';
var billingAddress = quote.billingAddress();
return Component.extend({
......@@ -56,16 +51,16 @@ define(
isShowLegend: function () {
return true;
},
setPlaceOrderHandler: function(handler) {
setPlaceOrderHandler: function (handler) {
this.placeOrderHandler = handler;
},
setValidateHandler: function(handler) {
setValidateHandler: function (handler) {
this.validateHandler = handler;
},
getCode: function() {
getCode: function () {
return 'adyen_sepa';
},
getData: function() {
getData: function () {
return {
'method': this.item.method,
'additional_data': {
......@@ -76,56 +71,34 @@ define(
}
};
},
isActive: function() {
isActive: function () {
return true;
},
/**
* @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() {
getControllerName: function () {
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
},
getPlaceOrderUrl: function() {
getPlaceOrderUrl: function () {
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
},
context: function() {
context: function () {
return this;
},
validate: function () {
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 true;
},
showLogo: function() {
showLogo: function () {
return window.checkoutConfig.payment.adyen.showLogo;
},
getCountries: function() {
return _.map(window.checkoutConfig.payment.adyenSepa.countries, function(value, key) {
getCountries: function () {
return _.map(window.checkoutConfig.payment.adyenSepa.countries, function (value, key) {
return {
'key': key,
'value': value
......
......@@ -55,6 +55,10 @@
'orderSaveUrl':getPlaceOrderUrl(),
}, '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()}">
<!-- ko if: (isShowLegend())-->
......
......@@ -38,6 +38,7 @@
</div>
<div class="payment-method-content">
<div class="payment-method-billing-address">
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
<!-- ko template: getTemplate() --><!-- /ko -->
......@@ -53,6 +54,11 @@
}, 'validation':[]}">
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<fieldset
data-bind="attr: {class: 'fieldset payment items ccard ' + getCode(), id: 'payment_form_' + getCode()}">
<!-- ko if: (isShowLegend())-->
......@@ -268,6 +274,8 @@
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<div class="actions-toolbar">
<div class="primary">
<button class="action primary checkout"
......
......@@ -97,13 +97,17 @@
<div class="control">
<input type="text" class="input-text"
name="payment[dob]"
data-bind=" datepicker: { storage: datepickerValue, options: { showOn: 'both', changeYear: true, yearRange: '-99:-1', defaultDate: '-20y' } },
attr: {
id: getCode() + '_dob_' + value,
title: $t('Date of Birth'),
'data-container': getCode() + '-dob'
},
value: dob"
data-bind="
attr: {
id: getCode() + '_dob_' + value,
title: $t('Date of Birth'),
'data-container': getCode() + '-dob_' + value,
},
datepicker: {
storage: datepickerValue,
options: { showOn: 'both', changeYear: true, yearRange: '-99:-1', defaultDate: '-20y' }
},
value: dob"
data-validate="{required:true}"
/>
</div>
......
......@@ -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-title field choice">
<input type="radio"
name="payment[method]"
......@@ -50,12 +52,18 @@
</div>
<div class="payment-method-content">
<!-- ko foreach: $parent.getRegion(getMessageName()) -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div class="payment-method-billing-address">
<!-- ko foreach: $parents[1].getRegion($parent.getBillingAddressFormName()) -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<form class="form" action="#" method="post" data-bind="
attr: {'id': 'adyen_oneclick_' + value, 'data-role': 'adyen_oneclick_' + value },
mageInit: {
......@@ -221,9 +229,6 @@
<!-- /ko -->
</fieldset>
<div class="checkout-agreements-block">
<!-- ko foreach: $parents[1].getRegion('before-place-order') -->
......@@ -235,7 +240,7 @@
<button class="action primary checkout"
type="submit"
data-bind="
click: $parent.placeOrder,
click: placeOrder,
attr: {title: $t('Place Order')},
enable: (value == $parent.isBillingAgreementChecked())
"
......
......@@ -45,6 +45,11 @@
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<fieldset class="fieldset" data-bind='attr: {id: "payment_form_" + getCode()}'>
<div class="payment-method-note">
<!-- ko text: $t('You will be redirected to the Adyen App.') --><!-- /ko -->
......
......@@ -46,7 +46,9 @@
<!--/ko-->
</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: {
'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