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 4fbf8974 authored by Rik ter Beek's avatar Rik ter Beek

Remove custom set-payment-method and use core code to place order

parent c0c84b89
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* 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,7 +19,6 @@ ...@@ -19,7 +19,6 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
define( define(
[ [
'underscore', 'underscore',
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
define( define(
[ [
'jquery', 'jquery',
......
...@@ -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,9 +32,10 @@ define( ...@@ -35,9 +32,10 @@ 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',
], ],
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) {
'use strict'; 'use strict';
var brandCode = ko.observable(null); var brandCode = ko.observable(null);
var paymentMethod = ko.observable(null); var paymentMethod = ko.observable(null);
...@@ -150,6 +148,15 @@ define( ...@@ -150,6 +148,15 @@ define(
result.validate = function () { result.validate = function () {
return self.validate(); return self.validate();
}; };
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 +219,12 @@ define( ...@@ -212,10 +219,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;
} }
}, },
...@@ -245,9 +254,7 @@ define( ...@@ -245,9 +254,7 @@ define(
} }
data.additional_data = additionalData; data.additional_data = additionalData;
this.placeRedirectOrder(data);
selectPaymentMethodAction(data);
setPaymentMethodAction();
} }
return false; return false;
...@@ -275,6 +282,27 @@ define( ...@@ -275,6 +282,27 @@ define(
return true; return true;
}, },
placeRedirectOrder: function(data) {
// Place Order but use our own redirect url after
var self = this;
this.isPlaceOrderActionAllowed(false);
fullScreenLoader.startLoader();
$.when(
placeOrderAction(data, this.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,7 +19,6 @@ ...@@ -19,7 +19,6 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
define( define(
[ [
'ko', 'ko',
......
...@@ -19,15 +19,16 @@ ...@@ -19,15 +19,16 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
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';
return Component.extend({ return Component.extend({
self: this, self: this,
...@@ -41,12 +42,29 @@ define( ...@@ -41,12 +42,29 @@ 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 //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;
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
define( define(
[ [
'underscore', 'underscore',
......
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