We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 426c103c authored by rikterbeek's avatar rikterbeek

Fixes #41 added Maestro and UnionPay

parent bdc15957
...@@ -25,6 +25,7 @@ namespace Adyen\Payment\Model; ...@@ -25,6 +25,7 @@ namespace Adyen\Payment\Model;
use Magento\Payment\Model\CcGenericConfigProvider; use Magento\Payment\Model\CcGenericConfigProvider;
use Magento\Payment\Helper\Data as PaymentHelper; use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Framework\View\Asset\Source as Source;
class AdyenCcConfigProvider extends CcGenericConfigProvider class AdyenCcConfigProvider extends CcGenericConfigProvider
{ {
...@@ -51,6 +52,11 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -51,6 +52,11 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
*/ */
protected $_genericConfig; protected $_genericConfig;
/**
* @var Source
*/
protected $_assetSource;
/** /**
* AdyenCcConfigProvider constructor. * AdyenCcConfigProvider constructor.
* *
...@@ -58,17 +64,20 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -58,17 +64,20 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
* @param PaymentHelper $paymentHelper * @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param AdyenGenericConfig $genericConfig * @param AdyenGenericConfig $genericConfig
* @param Source $assetSource
*/ */
public function __construct( public function __construct(
\Magento\Payment\Model\CcConfig $ccConfig, \Magento\Payment\Model\CcConfig $ccConfig,
PaymentHelper $paymentHelper, PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\AdyenGenericConfig $genericConfig \Adyen\Payment\Model\AdyenGenericConfig $genericConfig,
Source $assetSource
) { ) {
parent::__construct($ccConfig, $paymentHelper, $this->_methodCodes); parent::__construct($ccConfig, $paymentHelper, $this->_methodCodes);
$this->_paymentHelper = $paymentHelper; $this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_genericConfig = $genericConfig; $this->_genericConfig = $genericConfig;
$this->_assetSource = $assetSource;
} }
/** /**
...@@ -104,6 +113,10 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -104,6 +113,10 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
if ($this->_genericConfig->showLogos()) { if ($this->_genericConfig->showLogos()) {
$config['payment']['adyenCc']['creditCardPaymentMethodIcon'] = $this->_getCreditCardPaymentMethodIcon(); $config['payment']['adyenCc']['creditCardPaymentMethodIcon'] = $this->_getCreditCardPaymentMethodIcon();
} }
$config['payment']['adyenCc']['icons'] = $this->getIcons();
return $config; return $config;
} }
...@@ -126,4 +139,53 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -126,4 +139,53 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
} }
return $icon; return $icon;
} }
/**
* Retrieve availables credit card types
*
* @param string $methodCode
* @return array
*/
protected function getCcAvailableTypes($methodCode)
{
$types = [];
$ccTypes = $this->_adyenHelper->getAdyenCcTypes();
$availableTypes = $this->methods[$methodCode]->getConfigData('cctypes');
if ($availableTypes) {
$availableTypes = explode(',', $availableTypes);
foreach (array_keys($ccTypes) as $code) {
if (in_array($code, $availableTypes)) {
$types[$code] = $ccTypes[$code]['name'];
}
}
}
return $types;
}
/**
* Get icons for available payment methods
*
* @return array
*/
protected function getIcons()
{
$icons = [];
$types = $this->_adyenHelper->getAdyenCcTypes();
foreach (array_keys($types) as $code) {
if (!array_key_exists($code, $icons)) {
$asset = $this->ccConfig->createAsset('Magento_Payment::images/cc/' . strtolower($code) . '.png');
$placeholder = $this->_assetSource->findRelativeSourceFilePath($asset);
if ($placeholder) {
list($width, $height) = getimagesize($asset->getSourceFile());
$icons[$code] = [
'url' => $asset->getUrl(),
'width' => $width,
'height' => $height
];
}
}
}
return $icons;
}
} }
\ No newline at end of file
...@@ -127,6 +127,8 @@ class AdyenHppConfigProvider implements ConfigProviderInterface ...@@ -127,6 +127,8 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
} }
/** /**
* Set configuration for AdyenHPP payemnt method
*
* @return array * @return array
*/ */
public function getConfig() public function getConfig()
......
...@@ -29,6 +29,26 @@ namespace Adyen\Payment\Model\Config\Source; ...@@ -29,6 +29,26 @@ namespace Adyen\Payment\Model\Config\Source;
*/ */
class CcType extends \Magento\Payment\Model\Source\Cctype class CcType extends \Magento\Payment\Model\Source\Cctype
{ {
/**
* @var \Adyen\Payment\Helper\Data
*/
private $_adyenHelper;
/**
* CcType constructor.
*
* @param \Magento\Payment\Model\Config $paymentConfig
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Magento\Payment\Model\Config $paymentConfig,
\Adyen\Payment\Helper\Data $adyenHelper
) {
parent::__construct($paymentConfig);
$this->_adyenHelper = $adyenHelper;
}
/** /**
* Allowed credit card types * Allowed credit card types
* *
...@@ -36,6 +56,26 @@ class CcType extends \Magento\Payment\Model\Source\Cctype ...@@ -36,6 +56,26 @@ class CcType extends \Magento\Payment\Model\Source\Cctype
*/ */
public function getAllowedTypes() public function getAllowedTypes()
{ {
return ['VI', 'MC', 'AE', 'DI', 'JCB', 'OT']; return ['VI', 'MC', 'AE', 'DI', 'JCB', 'UN', 'OT', 'MI'];
}
/**
* {@inheritdoc}
*/
public function toOptionArray()
{
/**
* making filter by allowed cards
*/
$allowed = $this->getAllowedTypes();
$options = [];
foreach ($this->_adyenHelper->getAdyenCcTypes() as $code => $name) {
if (in_array($code, $allowed) || !count($allowed)) {
$options[] = ['value' => $code, 'label' => $name['name']];
}
}
return $options;
} }
} }
...@@ -53,5 +53,13 @@ ...@@ -53,5 +53,13 @@
<label>Diners</label> <label>Diners</label>
<code_alt>diners</code_alt> <code_alt>diners</code_alt>
</type> </type>
<type id="MI" order="70">
<label>Maestro</label>
<code_alt>maestro</code_alt>
</type>
<type id="UN" order="80">
<label>UnionPay</label>
<code_alt>unionpay</code_alt>
</type>
</adyen_credit_cards> </adyen_credit_cards>
</payment> </payment>
...@@ -29,8 +29,9 @@ ...@@ -29,8 +29,9 @@
* @see \Magento\Payment\Block\Info * @see \Magento\Payment\Block\Info
*/ */
?> ?>
<?php echo $block->escapeHtml($block->getMethod()->getTitle()) ?> <div>
<?php echo $block->escapeHtml($block->getMethod()->getTitle()) ?>
</div>
<?php <?php
$_info = $this->getInfo(); $_info = $this->getInfo();
$_isDemoMode = $block->isDemoMode(); $_isDemoMode = $block->isDemoMode();
...@@ -46,7 +47,9 @@ $_isDemoMode = $block->isDemoMode(); ...@@ -46,7 +47,9 @@ $_isDemoMode = $block->isDemoMode();
<?php endif;?> <?php endif;?>
<?php if($block->getCcTypeName() != ""):?> <?php if($block->getCcTypeName() != ""):?>
<?php echo __('Credit Card Type: %1', $block->getCcTypeName()) ?><br/> <div>
<?php echo __('Credit Card Type: %1', $block->getCcTypeName()) ?><br/>
</div>
<?php endif; ?> <?php endif; ?>
<?php if($_info->getCcLast4() != ""):?> <?php if($_info->getCcLast4() != ""):?>
<?php echo __('Credit Card Number: xxxx-%1', $this->getInfo()->getCcLast4()) ?><br/> <?php echo __('Credit Card Number: xxxx-%1', $this->getInfo()->getCcLast4()) ?><br/>
......
...@@ -29,7 +29,7 @@ define( ...@@ -29,7 +29,7 @@ define(
'Adyen_Payment/js/action/place-order', 'Adyen_Payment/js/action/place-order',
'mage/translate', 'mage/translate',
'Magento_Checkout/js/model/payment/additional-validators', 'Magento_Checkout/js/model/payment/additional-validators',
'adyen/encrypt', 'adyen/encrypt'
], ],
function (_, $, Component, placeOrderAction, $t, additionalValidators, adyenEncrypt) { function (_, $, Component, placeOrderAction, $t, additionalValidators, adyenEncrypt) {
...@@ -165,7 +165,12 @@ define( ...@@ -165,7 +165,12 @@ define(
}, },
showLogo: function() { showLogo: function() {
return window.checkoutConfig.payment.adyen.showLogo; return window.checkoutConfig.payment.adyen.showLogo;
} },
getIcons: function (type) {
return window.checkoutConfig.payment.adyenCc.icons.hasOwnProperty(type)
? window.checkoutConfig.payment.adyenCc.icons[type]
: false
},
}); });
} }
); );
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
<span><!-- ko text: $t('Credit Card Information')--><!-- /ko --></span> <span><!-- ko text: $t('Credit Card Information')--><!-- /ko --></span>
</legend><br /> </legend><br />
<!-- /ko --> <!-- /ko -->
<div class="field type required"> <div class="field type required">
<label data-bind="attr: {for: getCode() + '_cc_type'}" class="label"> <label data-bind="attr: {for: getCode() + '_cc_type'}" class="label">
<span><!-- ko text: $t('Credit Card Type')--><!-- /ko --></span> <span><!-- ko text: $t('Credit Card Type')--><!-- /ko --></span>
......
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