Commit 5e9598fd authored by attilak's avatar attilak

Fix loggedIn user retrieving payment methods

parent 0cfc5323
...@@ -27,14 +27,16 @@ define( ...@@ -27,14 +27,16 @@ define(
'Magento_Checkout/js/model/payment/renderer-list', 'Magento_Checkout/js/model/payment/renderer-list',
'Adyen_Payment/js/model/adyen-payment-service', 'Adyen_Payment/js/model/adyen-payment-service',
'Adyen_Payment/js/model/adyen-configuration', 'Adyen_Payment/js/model/adyen-configuration',
'Magento_Checkout/js/model/quote' 'Magento_Checkout/js/model/quote',
'Magento_Customer/js/model/customer'
], ],
function ( function (
Component, Component,
rendererList, rendererList,
adyenPaymentService, adyenPaymentService,
adyenConfiguration, adyenConfiguration,
quote quote,
customer
) { ) {
'use strict'; 'use strict';
rendererList.push( rendererList.push(
...@@ -70,6 +72,8 @@ define( ...@@ -70,6 +72,8 @@ define(
/** Add view logic here if needed */ /** Add view logic here if needed */
return Component.extend({ return Component.extend({
initialize: function () { initialize: function () {
var self = this;
this._super(); this._super();
if (this.isGooglePayEnabled()) { if (this.isGooglePayEnabled()) {
...@@ -79,40 +83,47 @@ define( ...@@ -79,40 +83,47 @@ define(
document.head.appendChild(googlepayscript); document.head.appendChild(googlepayscript);
} }
if (customer.isLoggedIn()) {
self.setAdyenPaymentMethods();
}
quote.shippingAddress.subscribe(function() { quote.shippingAddress.subscribe(function() {
adyenPaymentService.retrieveAvailablePaymentMethods().done(function (response) { self.setAdyenPaymentMethods();
var responseJson = JSON.parse(response); })
var paymentMethodsResponse = responseJson.paymentMethodsResponse; },
setAdyenPaymentMethods: function() {
adyenPaymentService.retrieveAvailablePaymentMethods().done(function (response) {
var responseJson = JSON.parse(response);
var paymentMethodsResponse = responseJson.paymentMethodsResponse;
// TODO check if this is still required or if can be outsourced for the generic component, or checkout can create a ratepay component // TODO check if this is still required or if can be outsourced for the generic component, or checkout can create a ratepay component
/*if (!!window.checkoutConfig.payment.adyenHpp) { /*if (!!window.checkoutConfig.payment.adyenHpp) {
if (JSON.stringify(paymentMethods).indexOf("ratepay") > -1) { if (JSON.stringify(paymentMethods).indexOf("ratepay") > -1) {
var ratePayId = window.checkoutConfig.payment.adyenHpp.ratePayId; var ratePayId = window.checkoutConfig.payment.adyenHpp.ratePayId;
var dfValueRatePay = self.getRatePayDeviceIdentToken(); var dfValueRatePay = self.getRatePayDeviceIdentToken();
window.di = { window.di = {
t: dfValueRatePay.replace(':', ''), t: dfValueRatePay.replace(':', ''),
v: ratePayId, v: ratePayId,
l: 'Checkout' l: 'Checkout'
}; };
// Load Ratepay script // Load Ratepay script
var ratepayScriptTag = document.createElement('script'); var ratepayScriptTag = document.createElement('script');
ratepayScriptTag.src = "//d.ratepay.com/" + ratePayId + "/di.js"; ratepayScriptTag.src = "//d.ratepay.com/" + ratePayId + "/di.js";
ratepayScriptTag.type = "text/javascript"; ratepayScriptTag.type = "text/javascript";
document.body.appendChild(ratepayScriptTag); document.body.appendChild(ratepayScriptTag);
} }
}*/ }*/
// Initialises adyen checkout main component with default configuration // Initialises adyen checkout main component with default configuration
adyenPaymentService.initCheckoutComponent( adyenPaymentService.initCheckoutComponent(
paymentMethodsResponse, paymentMethodsResponse,
adyenConfiguration.getOriginKey(), adyenConfiguration.getOriginKey(),
adyenConfiguration.getLocale(), adyenConfiguration.getLocale(),
adyenConfiguration.getCheckoutEnvironment() adyenConfiguration.getCheckoutEnvironment()
); );
})
}) })
}, },
isGooglePayEnabled: function() { isGooglePayEnabled: function() {
......
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