We will be off on April 7th (Monday) for public holiday in our country

Commit d5518aea authored by attilak's avatar attilak

Retrieve payment methods when new shipping address is selected

parent f6da96d4
...@@ -7,8 +7,11 @@ define( ...@@ -7,8 +7,11 @@ define(
'underscore', 'underscore',
'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/model/quote',
'Adyen_Payment/js/model/adyen-method-list', 'Adyen_Payment/js/model/adyen-method-list',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/url-builder',
'mage/storage'
], ],
function (_, quote, methodList) { function (_, quote, methodList, customer, urlBuilder, storage) {
'use strict'; 'use strict';
return { return {
...@@ -25,6 +28,41 @@ define( ...@@ -25,6 +28,41 @@ define(
*/ */
getAvailablePaymentMethods: function () { getAvailablePaymentMethods: function () {
return methodList(); return methodList();
},
/**
* Retrieve the list of available payment methods from the server
*/
retrieveAvailablePaymentMethods: function (callback) {
var self = this;
// retrieve payment methods
var serviceUrl,
payload;
if (customer.isLoggedIn()) {
serviceUrl = urlBuilder.createUrl('/carts/mine/retrieve-adyen-payment-methods', {});
} else {
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/retrieve-adyen-payment-methods', {
cartId: quote.getQuoteId()
});
}
payload = {
cartId: quote.getQuoteId(),
shippingAddress: quote.shippingAddress()
};
storage.post(
serviceUrl, JSON.stringify(payload)
).done(
function (response) {
self.setPaymentMethods(response);
callback();
}
).fail(
function (response) {
self.setPaymentMethods([]);
}
)
} }
}; };
} }
......
...@@ -90,68 +90,50 @@ define( ...@@ -90,68 +90,50 @@ define(
// reset variable: // reset variable:
adyenPaymentService.setPaymentMethods(); adyenPaymentService.setPaymentMethods();
// retrieve payment methods adyenPaymentService.retrieveAvailablePaymentMethods(function() {
var serviceUrl, let paymentMethods = adyenPaymentService.getAvailablePaymentMethods();
payload; if (JSON.stringify(paymentMethods).indexOf("ratepay") > -1) {
if (customer.isLoggedIn()) { var ratePayId = window.checkoutConfig.payment.adyenHpp.ratePayId;
serviceUrl = urlBuilder.createUrl('/carts/mine/retrieve-adyen-payment-methods', {}); var dfValueRatePay = self.getRatePayDeviceIdentToken();
} else {
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/retrieve-adyen-payment-methods', { window.di = {
cartId: quote.getQuoteId() t: dfValueRatePay.replace(':', ''),
}); v: ratePayId,
} l: 'Checkout'
};
payload = {
cartId: quote.getQuoteId(),
shippingAddress: quote.shippingAddress()
};
storage.post( // Load Ratepay script
serviceUrl, JSON.stringify(payload) var ratepayScriptTag = document.createElement('script');
).done( ratepayScriptTag.src = "//d.ratepay.com/" + ratePayId + "/di.js";
function (response) { ratepayScriptTag.type = "text/javascript";
adyenPaymentService.setPaymentMethods(response); document.body.appendChild(ratepayScriptTag);
if (JSON.stringify(response).indexOf("ratepay") > -1) { }
var ratePayId = window.checkoutConfig.payment.adyenHpp.ratePayId;
var dfValueRatePay = self.getRatePayDeviceIdentToken();
window.di = {
t: dfValueRatePay.replace(':', ''),
v: ratePayId,
l: 'Checkout'
};
// Load Ratepay script // create component needs to be in initialize method
var ratepayScriptTag = document.createElement('script'); var messageComponents = {};
ratepayScriptTag.src = "//d.ratepay.com/" + ratePayId + "/di.js"; _.map(paymentMethods, function (value) {
ratepayScriptTag.type = "text/javascript";
document.body.appendChild(ratepayScriptTag); var messageContainer = new Messages();
} var name = 'messages-' + self.getBrandCodeFromPaymentMethod(value);
var messagesComponent = {
parent: self.name,
name: 'messages-' + self.getBrandCodeFromPaymentMethod(value),
displayArea: 'messages-' + self.getBrandCodeFromPaymentMethod(value),
component: 'Magento_Ui/js/view/messages',
config: {
messageContainer: messageContainer
}
};
layout([messagesComponent]);
// create component needs to be in initialize method messageComponents[name] = messageContainer;
var messageComponents = {}; });
_.map(response, function (value) { self.messageComponents = messageComponents;
var messageContainer = new Messages();
var name = 'messages-' + self.getBrandCodeFromPaymentMethod(value);
var messagesComponent = {
parent: self.name,
name: 'messages-' + self.getBrandCodeFromPaymentMethod(value),
displayArea: 'messages-' + self.getBrandCodeFromPaymentMethod(value),
component: 'Magento_Ui/js/view/messages',
config: {
messageContainer: messageContainer
}
};
layout([messagesComponent]);
messageComponents[name] = messageContainer; quote.shippingAddress.subscribe( function(address) {
}); adyenPaymentService.retrieveAvailablePaymentMethods();
self.messageComponents = messageComponents; });
fullScreenLoader.stopLoader();
}
).fail(function (error) {
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
}); });
}, },
......
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