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 504033c2 authored by cyattilakiss's avatar cyattilakiss Committed by GitHub

Merge pull request #373 from Adyen/PW-706

PW-706 Handle iDeal payments using Checkout component
parents 3185f2bf ff4343d8
......@@ -35,34 +35,39 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
/**
* @var PaymentHelper
*/
protected $_paymentHelper;
protected $paymentHelper;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
protected $adyenHelper;
/**
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
protected $request;
/**
* @var \Magento\Framework\UrlInterface
*/
protected $_urlBuilder;
protected $urlBuilder;
/**
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;
protected $customerSession;
/**
* @var \Magento\Checkout\Model\Session
*/
protected $_session;
protected $session;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* AdyenHppConfigProvider constructor.
......@@ -80,14 +85,16 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Customer\Model\Session $customerSession,
\Magento\Checkout\Model\Session $session
\Magento\Checkout\Model\Session $session,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
$this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper;
$this->_request = $request;
$this->_urlBuilder = $urlBuilder;
$this->_customerSession = $customerSession;
$this->_session = $session;
$this->paymentHelper = $paymentHelper;
$this->adyenHelper = $adyenHelper;
$this->request = $request;
$this->urlBuilder = $urlBuilder;
$this->customerSession = $customerSession;
$this->session = $session;
$this->storeManager = $storeManager;
}
/**
......@@ -102,9 +109,9 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl(
'redirectUrl' => $this->urlBuilder->getUrl(
'adyen/process/redirect',
['_secure' => $this->_getRequest()->isSecure()]
['_secure' => $this->getRequest()->isSecure()]
)
]
]
......@@ -114,19 +121,21 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
$dob = "";
// get customer
if ($this->_customerSession->isLoggedIn()) {
if ($this->customerSession->isLoggedIn()) {
$gender = \Adyen\Payment\Model\Gender::getAdyenGenderFromMagentoGender(
$this->_customerSession->getCustomerData()->getGender()
$this->customerSession->getCustomerData()->getGender()
);
// format to calendar date
$dob = $this->_customerSession->getCustomerData()->getDob();
$dob = $this->customerSession->getCustomerData()->getDob();
if ($dob) {
$dob = strtotime($dob);
$dob = date('m/d/Y', $dob);
}
}
$config['payment']['adyenHpp']['locale'] = $this->adyenHelper->getStoreLocale($this->storeManager->getStore()->getId());
// add to config
$config['payment'] ['adyenHpp']['gender'] = $gender;
$config['payment'] ['adyenHpp']['dob'] = $dob;
......@@ -135,16 +144,16 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
$config['payment'] ['adyenHpp']['genderTypes'] = \Adyen\Payment\Model\Gender::getGenderTypes();
$paymentMethodSelectionOnAdyen =
$this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
$this->adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
$config['payment'] ['adyenHpp']['isPaymentMethodSelectionOnAdyen'] = $paymentMethodSelectionOnAdyen;
$config['payment'] ['adyenHpp']['showGender'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_gender');
$config['payment'] ['adyenHpp']['showDob'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_dob');
$config['payment'] ['adyenHpp']['showTelephone'] = $this->_adyenHelper->getAdyenHppConfigDataFlag(
$config['payment'] ['adyenHpp']['showGender'] = $this->adyenHelper->getAdyenHppConfigDataFlag('show_gender');
$config['payment'] ['adyenHpp']['showDob'] = $this->adyenHelper->getAdyenHppConfigDataFlag('show_dob');
$config['payment'] ['adyenHpp']['showTelephone'] = $this->adyenHelper->getAdyenHppConfigDataFlag(
'show_telephone'
);
$config['payment'] ['adyenHpp']['ratePayId'] = $this->_adyenHelper->getRatePayId();
$config['payment'] ['adyenHpp']['deviceIdentToken'] = md5($this->_session->getQuoteId() . date('c'));
$config['payment'] ['adyenHpp']['ratePayId'] = $this->adyenHelper->getRatePayId();
$config['payment'] ['adyenHpp']['deviceIdentToken'] = md5($this->session->getQuoteId() . date('c'));
$config['payment'] ['adyenHpp']['nordicCountries'] = ['SE', 'NO', 'DK', 'FI'];
return $config;
......@@ -155,8 +164,8 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
protected function getRequest()
{
return $this->_request;
return $this->request;
}
}
......@@ -199,6 +199,61 @@ define(
return false;
};
// Can be removed after checkout api feature branch goes live since the issuerId key is changed to
// id there and just use the value.issuers in the component
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 ideal component,
* sets up the callbacks for ideal components and
*/
result.renderIdealComponent = function () {
self.isPlaceOrderActionAllowed(false);
var secureFieldsNode = document.getElementById('iDealContainer');
var checkout = new AdyenCheckout({
locale: self.getLocale()
});
var ideal = checkout.create('ideal', {
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.issuers.length == 0) {
......@@ -370,6 +425,9 @@ define(
},
getRatePayDeviceIdentToken: function () {
return window.checkoutConfig.payment.adyenHpp.deviceIdentToken;
},
getLocale: function () {
return window.checkoutConfig.payment.adyenHpp.locale;
}
});
}
......
......@@ -55,6 +55,10 @@
<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}'>
<!-- ko if: isIssuerListAvailable() -->
<!-- ko if: isIdeal() -->
<div afterRender="renderIdealComponent()" data-bind="attr: { id: 'iDealContainer'}"></div>
<!--/ko-->
<!-- ko ifnot: isIdeal() -->
<label data-bind="attr: {'for': 'issuerId'}" class="label">
<span><!-- ko text: $t('Select Your Bank') --><!-- /ko --></span>
</label>
......@@ -67,6 +71,7 @@
optionsCaption: $t('Choose Your Bank')">
</select>
<!--/ko-->
<!--/ko-->
<!-- ko if: isPaymentMethodOpenInvoiceMethod() -->
<!-- ko if: showGender() -->
......
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