We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 8752c473 authored by attilak's avatar attilak

Add iDeal component

parent 3185f2bf
...@@ -35,34 +35,39 @@ class AdyenHppConfigProvider implements ConfigProviderInterface ...@@ -35,34 +35,39 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
/** /**
* @var PaymentHelper * @var PaymentHelper
*/ */
protected $_paymentHelper; protected $paymentHelper;
/** /**
* @var \Adyen\Payment\Helper\Data * @var \Adyen\Payment\Helper\Data
*/ */
protected $_adyenHelper; protected $adyenHelper;
/** /**
* Request object * Request object
* *
* @var \Magento\Framework\App\RequestInterface * @var \Magento\Framework\App\RequestInterface
*/ */
protected $_request; protected $request;
/** /**
* @var \Magento\Framework\UrlInterface * @var \Magento\Framework\UrlInterface
*/ */
protected $_urlBuilder; protected $urlBuilder;
/** /**
* @var \Magento\Customer\Model\Session * @var \Magento\Customer\Model\Session
*/ */
protected $_customerSession; protected $customerSession;
/** /**
* @var \Magento\Checkout\Model\Session * @var \Magento\Checkout\Model\Session
*/ */
protected $_session; protected $session;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/** /**
* AdyenHppConfigProvider constructor. * AdyenHppConfigProvider constructor.
...@@ -80,14 +85,16 @@ class AdyenHppConfigProvider implements ConfigProviderInterface ...@@ -80,14 +85,16 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
\Magento\Framework\App\RequestInterface $request, \Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\UrlInterface $urlBuilder,
\Magento\Customer\Model\Session $customerSession, \Magento\Customer\Model\Session $customerSession,
\Magento\Checkout\Model\Session $session \Magento\Checkout\Model\Session $session,
\Magento\Store\Model\StoreManagerInterface $storeManager
) { ) {
$this->_paymentHelper = $paymentHelper; $this->paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper; $this->adyenHelper = $adyenHelper;
$this->_request = $request; $this->request = $request;
$this->_urlBuilder = $urlBuilder; $this->urlBuilder = $urlBuilder;
$this->_customerSession = $customerSession; $this->customerSession = $customerSession;
$this->_session = $session; $this->session = $session;
$this->storeManager = $storeManager;
} }
/** /**
...@@ -102,9 +109,9 @@ class AdyenHppConfigProvider implements ConfigProviderInterface ...@@ -102,9 +109,9 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
'payment' => [ 'payment' => [
self::CODE => [ self::CODE => [
'isActive' => true, 'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl( 'redirectUrl' => $this->urlBuilder->getUrl(
'adyen/process/redirect', 'adyen/process/redirect',
['_secure' => $this->_getRequest()->isSecure()] ['_secure' => $this->getRequest()->isSecure()]
) )
] ]
] ]
...@@ -114,19 +121,23 @@ class AdyenHppConfigProvider implements ConfigProviderInterface ...@@ -114,19 +121,23 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
$dob = ""; $dob = "";
// get customer // get customer
if ($this->_customerSession->isLoggedIn()) { if ($this->customerSession->isLoggedIn()) {
$gender = \Adyen\Payment\Model\Gender::getAdyenGenderFromMagentoGender( $gender = \Adyen\Payment\Model\Gender::getAdyenGenderFromMagentoGender(
$this->_customerSession->getCustomerData()->getGender() $this->customerSession->getCustomerData()->getGender()
); );
// format to calendar date // format to calendar date
$dob = $this->_customerSession->getCustomerData()->getDob(); $dob = $this->customerSession->getCustomerData()->getDob();
if ($dob) { if ($dob) {
$dob = strtotime($dob); $dob = strtotime($dob);
$dob = date('m/d/Y', $dob); $dob = date('m/d/Y', $dob);
} }
} }
$config['payment']['adyenHpp']['originKey'] = $this->adyenHelper->getOriginKeyForBaseUrl();
$config['payment']['adyenHpp']['checkoutUrl'] = $this->adyenHelper->getCheckoutContextUrl($this->storeManager->getStore()->getId());
$config['payment']['adyenHpp']['locale'] = $this->adyenHelper->getStoreLocale($this->storeManager->getStore()->getId());
// add to config // add to config
$config['payment'] ['adyenHpp']['gender'] = $gender; $config['payment'] ['adyenHpp']['gender'] = $gender;
$config['payment'] ['adyenHpp']['dob'] = $dob; $config['payment'] ['adyenHpp']['dob'] = $dob;
...@@ -135,16 +146,16 @@ class AdyenHppConfigProvider implements ConfigProviderInterface ...@@ -135,16 +146,16 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
$config['payment'] ['adyenHpp']['genderTypes'] = \Adyen\Payment\Model\Gender::getGenderTypes(); $config['payment'] ['adyenHpp']['genderTypes'] = \Adyen\Payment\Model\Gender::getGenderTypes();
$paymentMethodSelectionOnAdyen = $paymentMethodSelectionOnAdyen =
$this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen'); $this->adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
$config['payment'] ['adyenHpp']['isPaymentMethodSelectionOnAdyen'] = $paymentMethodSelectionOnAdyen; $config['payment'] ['adyenHpp']['isPaymentMethodSelectionOnAdyen'] = $paymentMethodSelectionOnAdyen;
$config['payment'] ['adyenHpp']['showGender'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_gender'); $config['payment'] ['adyenHpp']['showGender'] = $this->adyenHelper->getAdyenHppConfigDataFlag('show_gender');
$config['payment'] ['adyenHpp']['showDob'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_dob'); $config['payment'] ['adyenHpp']['showDob'] = $this->adyenHelper->getAdyenHppConfigDataFlag('show_dob');
$config['payment'] ['adyenHpp']['showTelephone'] = $this->_adyenHelper->getAdyenHppConfigDataFlag( $config['payment'] ['adyenHpp']['showTelephone'] = $this->adyenHelper->getAdyenHppConfigDataFlag(
'show_telephone' 'show_telephone'
); );
$config['payment'] ['adyenHpp']['ratePayId'] = $this->_adyenHelper->getRatePayId(); $config['payment'] ['adyenHpp']['ratePayId'] = $this->adyenHelper->getRatePayId();
$config['payment'] ['adyenHpp']['deviceIdentToken'] = md5($this->_session->getQuoteId() . date('c')); $config['payment'] ['adyenHpp']['deviceIdentToken'] = md5($this->session->getQuoteId() . date('c'));
$config['payment'] ['adyenHpp']['nordicCountries'] = ['SE', 'NO', 'DK', 'FI']; $config['payment'] ['adyenHpp']['nordicCountries'] = ['SE', 'NO', 'DK', 'FI'];
return $config; return $config;
...@@ -155,8 +166,8 @@ class AdyenHppConfigProvider implements ConfigProviderInterface ...@@ -155,8 +166,8 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
* *
* @return \Magento\Framework\App\RequestInterface * @return \Magento\Framework\App\RequestInterface
*/ */
protected function _getRequest() protected function getRequest()
{ {
return $this->_request; return $this->request;
} }
} }
...@@ -199,6 +199,65 @@ define( ...@@ -199,6 +199,65 @@ define(
return false; return false;
}; };
// Can be removed after checkout api feature branch goes live since the issuerId key is changed to
// id there
result.getIssuerListForComponent = function() {
if (result.isIssuerListAvailable()) {
return _.map(value.issuers, function (issuer, key) {
return {
"id": issuer.issuerId,
"name": issuer.name
};
});
}
return [];
};
result.isIdeal = function () {
if (value.brandCode.indexOf("ideal") >= 0) {
return true;
}
return false;
};
/**
* Renders the secure fields,
* creates the card component,
* sets up the callbacks for card components and
* set up the installments
*/
result.renderIdealComponent = function () {
self.isPlaceOrderActionAllowed(false);
var secureFieldsNode = document.getElementById('iDealContainer');
var checkout = new AdyenCheckout({
locale: self.getLocale()
});
var ideal = checkout.create('ideal', {
originKey: self.getOriginKey(),
loadingContext: self.getLoadingContext(),
items: result.getIssuerListForComponent(),
onChange: function (state) {
// isValid is not present on start
if (typeof state.isValid !== 'undefined' && state.isValid === false) {
self.isPlaceOrderActionAllowed(false);
}
},
onValid: function (state) {
result.issuerId(state.data.issuer);
self.isPlaceOrderActionAllowed(true);
},
onError: function (state) {
self.isPlaceOrderActionAllowed(false);
}
});
ideal.mount(secureFieldsNode);
};
if (value.hasOwnProperty("issuers")) { if (value.hasOwnProperty("issuers")) {
if (value.issuers.length == 0) { if (value.issuers.length == 0) {
...@@ -370,6 +429,15 @@ define( ...@@ -370,6 +429,15 @@ define(
}, },
getRatePayDeviceIdentToken: function () { getRatePayDeviceIdentToken: function () {
return window.checkoutConfig.payment.adyenHpp.deviceIdentToken; return window.checkoutConfig.payment.adyenHpp.deviceIdentToken;
},
getOriginKey: function () {
return window.checkoutConfig.payment.adyenHpp.originKey;
},
getLoadingContext: function () {
return window.checkoutConfig.payment.adyenHpp.checkoutUrl;
},
getLocale: function () {
return window.checkoutConfig.payment.adyenHpp.locale;
} }
}); });
} }
......
...@@ -55,17 +55,22 @@ ...@@ -55,17 +55,22 @@
<form class="form" data-role="adyen-hpp-form" action="#" method="post" data-bind="mageInit: { 'validation':[]}, attr: {id: 'payment_form_' + $parent.getCode() + '_' + value}"> <form class="form" data-role="adyen-hpp-form" action="#" method="post" data-bind="mageInit: { 'validation':[]}, attr: {id: 'payment_form_' + $parent.getCode() + '_' + value}">
<fieldset class="fieldset" data-bind='attr: {id: "payment_fieldset_" + $parent.getCode() + "_" + value}'> <fieldset class="fieldset" data-bind='attr: {id: "payment_fieldset_" + $parent.getCode() + "_" + value}'>
<!-- ko if: isIssuerListAvailable() --> <!-- ko if: isIssuerListAvailable() -->
<label data-bind="attr: {'for': 'issuerId'}" class="label"> <!-- ko if: isIdeal() -->
<span><!-- ko text: $t('Select Your Bank') --><!-- /ko --></span> <div afterRender="renderIdealComponent()" data-bind="attr: { id: 'iDealContainer'}"></div>
</label> <!--/ko-->
<!-- ko ifnot: isIdeal() -->
<select name="payment[issuer_id]" data-bind=" <label data-bind="attr: {'for': 'issuerId'}" class="label">
options: name.issuers, <span><!-- ko text: $t('Select Your Bank') --><!-- /ko --></span>
optionsText: 'name', </label>
optionsValue: 'issuerId',
value: issuerId, <select name="payment[issuer_id]" data-bind="
optionsCaption: $t('Choose Your Bank')"> options: name.issuers,
</select> optionsText: 'name',
optionsValue: 'issuerId',
value: issuerId,
optionsCaption: $t('Choose Your Bank')">
</select>
<!--/ko-->
<!--/ko--> <!--/ko-->
<!-- ko if: isPaymentMethodOpenInvoiceMethod() --> <!-- ko if: isPaymentMethodOpenInvoiceMethod() -->
......
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