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 @@
*
* Author: Adyen <magento@adyen.com>
*/
define(
[
'underscore',
......
......@@ -19,7 +19,6 @@
*
* Author: Adyen <magento@adyen.com>
*/
define(
[
'jquery',
......
......@@ -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,9 +32,10 @@ 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',
],
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';
var brandCode = ko.observable(null);
var paymentMethod = ko.observable(null);
......@@ -150,6 +148,15 @@ define(
result.validate = function () {
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 () {
return value.isPaymentMethodOpenInvoiceMethod;
};
......@@ -212,10 +219,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;
}
},
......@@ -245,9 +254,7 @@ define(
}
data.additional_data = additionalData;
selectPaymentMethodAction(data);
setPaymentMethodAction();
this.placeRedirectOrder(data);
}
return false;
......@@ -275,6 +282,27 @@ define(
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 () {
if (!quote.paymentMethod()) {
......
......@@ -19,7 +19,6 @@
*
* Author: Adyen <magento@adyen.com>
*/
define(
[
'ko',
......
......@@ -19,15 +19,16 @@
*
* Author: Adyen <magento@adyen.com>
*/
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';
return Component.extend({
self: this,
......@@ -41,12 +42,29 @@ 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();
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 () {
return window.checkoutConfig.payment.adyen.showLogo;
......
......@@ -19,7 +19,6 @@
*
* Author: Adyen <magento@adyen.com>
*/
define(
[
'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