Commit 62f66ed0 authored by attilak's avatar attilak

Use the generic component to render the checkout component

Add initCheckoutComponent to adyen-payment-service.js to create the
main AdyenCheckout with default configuration
Add getCheckoutComponent() to retrieve the initialised AdyenCheckout
main component
Remove the checkout component direct links from Data.php
parent b989e524
......@@ -67,14 +67,6 @@ class Cc extends \Magento\Payment\Block\Form\Cc
$this->checkoutSession = $checkoutSession;
}
/**
* @return string
*/
public function getCheckoutCardComponentJs()
{
return $this->adyenHelper->getCheckoutCardComponentJs($this->checkoutSession->getQuote()->getStore()->getId());
}
/**
* @return string
* @throws \Adyen\AdyenException
......
......@@ -34,8 +34,6 @@ class Data extends AbstractHelper
const MODULE_NAME = 'adyen-magento2';
const TEST = 'test';
const LIVE = 'live';
const CHECKOUT_COMPONENT_JS_LIVE = 'https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/3.2.0/adyen.js';
const CHECKOUT_COMPONENT_JS_TEST = 'https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/3.2.0/adyen.js';
/**
* @var \Magento\Framework\Encryption\EncryptorInterface
......@@ -1603,19 +1601,6 @@ class Data extends AbstractHelper
return new \Adyen\Service\CheckoutUtility($client);
}
/**
* @param int|null $storeId
* @return string
*/
public function getCheckoutCardComponentJs($storeId = null)
{
if ($this->isDemoMode($storeId)) {
return self::CHECKOUT_COMPONENT_JS_TEST;
}
return self::CHECKOUT_COMPONENT_JS_LIVE;
}
/**
* @param $order
* @param $additionalData
......
......@@ -69,8 +69,6 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
$config['payment']['adyen']['showLogo'] = false;
}
$config['payment']['checkoutCardComponentSource'] = $this->_adyenHelper->getCheckoutCardComponentJs($this->storeManager->getStore()->getId());
return $config;
}
......
......@@ -9,11 +9,12 @@ define(
'Adyen_Payment/js/model/adyen-method-list',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/url-builder',
'mage/storage'
'mage/storage',
'Adyen_Payment/js/bundle',
],
function (_, quote, methodList, customer, urlBuilder, storage) {
'use strict';
var checkoutComponent = {};
return {
/**
* Populate the list of payment methods
......@@ -75,6 +76,17 @@ define(
});
return storage.get(serviceUrl);
},
initCheckoutComponent: function(paymentMethodsResponse, originKey, locale, environment, ) {
checkoutComponent = new AdyenCheckout({
locale: locale,
originKey: originKey,
environment: environment,
paymentMethodsResponse: paymentMethodsResponse,
});
},
getCheckoutComponent: function() {
return checkoutComponent;
}
};
}
......
......@@ -25,12 +25,14 @@ define(
[
'uiComponent',
'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'
],
function (
Component,
rendererList,
adyenPaymentService
adyenPaymentService,
adyenConfiguration
) {
'use strict';
rendererList.push(
......@@ -95,12 +97,14 @@ define(
}
});
// include checkout card component javascript
var checkoutCardComponentScriptTag = document.createElement('script');
checkoutCardComponentScriptTag.id = "AdyenCheckoutCardComponentScript";
checkoutCardComponentScriptTag.src = self.getCheckoutCardComponentSource();
checkoutCardComponentScriptTag.type = "text/javascript";
document.head.appendChild(checkoutCardComponentScriptTag);
// Initialises adyen checkout main component with default configuration
adyenPaymentService.initCheckoutComponent(
paymentMethodsResponse,
adyenConfiguration.getOriginKey(),
adyenConfiguration.getLocale(),
adyenConfiguration.getCheckoutEnvironment()
);
})
if (this.isGooglePayEnabled()) {
var googlepayscript = document.createElement('script');
......@@ -109,15 +113,12 @@ define(
document.head.appendChild(googlepayscript);
}
},
getCheckoutCardComponentSource: function() {
return window.checkoutConfig.payment.checkoutCardComponentSource;
},
isGooglePayEnabled: function() {
return window.checkoutConfig.payment.adyenGooglePay.active;
},
getRatePayDeviceIdentToken: function () {
return window.checkoutConfig.payment.adyenHpp.deviceIdentToken;
},
}
});
}
);
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