diff --git a/app/code/Magento/Payment/Model/CcConfig.php b/app/code/Magento/Payment/Model/CcConfig.php index 59928e91953bb7889cb8a1b05fc2516af5aa84da..97921c769ea94ea813f1dd0b1b5f8fa62bdfe01e 100644 --- a/app/code/Magento/Payment/Model/CcConfig.php +++ b/app/code/Magento/Payment/Model/CcConfig.php @@ -152,4 +152,18 @@ class CcConfig return $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound']); } } + + /** + * Create a file asset that's subject of fallback system + * + * @param string $fileId + * @param array $params + * @return \Magento\Framework\View\Asset\File + */ + public function createAsset($fileId, array $params = []) + { + $params = array_merge(['_secure' => $this->request->isSecure()], $params); + return $this->assetRepo->createAsset($fileId, $params); + + } } diff --git a/app/code/Magento/Payment/Model/CcConfigProvider.php b/app/code/Magento/Payment/Model/CcConfigProvider.php new file mode 100644 index 0000000000000000000000000000000000000000..7792a2c29a046e785576c507e226177dd7ee918c --- /dev/null +++ b/app/code/Magento/Payment/Model/CcConfigProvider.php @@ -0,0 +1,74 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Payment\Model; + +use Magento\Checkout\Model\ConfigProviderInterface; +use Magento\Framework\View\Asset\Source; + +class CcConfigProvider implements ConfigProviderInterface +{ + /** + * @var CcConfig + */ + protected $ccConfig; + + /** + * @var \Magento\Framework\View\Asset\Source + */ + protected $assetSource; + + /** + * @param CcConfig $ccConfig + * @param Source $assetSource + */ + public function __construct( + CcConfig $ccConfig, + Source $assetSource + ) { + $this->ccConfig = $ccConfig; + $this->assetSource = $assetSource; + } + + /** + * {@inheritdoc} + */ + public function getConfig() + { + return [ + 'payment' => [ + 'ccform' => [ + 'icons' => $this->getIcons() + ] + ] + ]; + } + + /** + * Get icons for available payment methods + * + * @return array + */ + protected function getIcons() + { + $icons = []; + $types = $this->ccConfig->getCcAvailableTypes(); + 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; + } +} diff --git a/app/code/Magento/Payment/etc/frontend/di.xml b/app/code/Magento/Payment/etc/frontend/di.xml new file mode 100644 index 0000000000000000000000000000000000000000..fdfda8b2027921ab7c665bd94c27b802ec288d99 --- /dev/null +++ b/app/code/Magento/Payment/etc/frontend/di.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd"> + <type name="Magento\Checkout\Model\CompositeConfigProvider"> + <arguments> + <argument name="configProviders" xsi:type="array"> + <item name="cc_card_config_provider" xsi:type="object">Magento\Payment\Model\CcConfigProvider</item> + </argument> + </arguments> + </type> +</config> diff --git a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/credit-card-type.js b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/credit-card-type.js index 71e0e57c5c16e71a394d1fa948f35ed807c75495..bd7d0772c0222af0de3a7903a7b1445402c55d40 100644 --- a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/credit-card-type.js +++ b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/credit-card-type.js @@ -70,7 +70,7 @@ define( }, { title: 'JCB', - type: 'JC', + type: 'JCB', pattern: '^((2|21|213|2131\\d*)|(1|18|180|1800\\d*)|(3|35\\d*))$', gaps: [4, 8, 12], lengths: [16], @@ -92,23 +92,8 @@ define( }, { title: 'Maestro', - type: 'SM', - pattern: '(^(5[0678])[0-9]{11,18}$)' + - '|(^(6[^05])[0-9]{11,18}$)' + - '|(^(601)[^1][0-9]{9,16}$)' + - '|(^(6011)[0-9]{9,11}$)' + - '|(^(6011)[0-9]{13,16}$)' + - '|(^(65)[0-9]{11,13}$)' + - '|(^(65)[0-9]{15,18}$)' + - '|(^(49030)[2-9]([0-9]{10}$' + - '|[0-9]{12,13}$))' + - '|(^(49033)[5-9]([0-9]{10}$' + - '|[0-9]{12,13}$))' + - '|(^(49110)[1-2]([0-9]{10}$' + - '|[0-9]{12,13}$))' + - '|(^(49117)[4-9]([0-9]{10}$|[0-9]{12,13}$))' + - '|(^(49118)[0-2]([0-9]{10}$|[0-9]{12,13}$))' + - '|(^(4936)([0-9]{12}$|[0-9]{14,15}$))', + type: 'MI', + pattern: '^((5((0|[6-9])\\d*)?)|(6|6[37]\\d*))$', gaps: [4, 8, 12], lengths: [12, 13, 14, 15, 16, 17, 18, 19], code: { diff --git a/app/code/Magento/Payment/view/frontend/web/js/view/payment/cc-form.js b/app/code/Magento/Payment/view/frontend/web/js/view/payment/cc-form.js index 5c1abc1e3c75b1721a889badee6e364009bd448f..e957c254fb3719ca2e30319a01221fff7b27e227 100644 --- a/app/code/Magento/Payment/view/frontend/web/js/view/payment/cc-form.js +++ b/app/code/Magento/Payment/view/frontend/web/js/view/payment/cc-form.js @@ -104,6 +104,11 @@ define( getCcAvailableTypes: function() { return window.checkoutConfig.payment.ccform.availableTypes[this.getCode()]; }, + getIcons: function (type) { + return window.checkoutConfig.payment.ccform.icons.hasOwnProperty(type) + ? window.checkoutConfig.payment.ccform.icons[type] + : false + }, getCcMonths: function() { return window.checkoutConfig.payment.ccform.months[this.getCode()]; }, diff --git a/app/code/Magento/Payment/view/frontend/web/template/payment/cc-form.html b/app/code/Magento/Payment/view/frontend/web/template/payment/cc-form.html index 49d1d57f958bdd938284aaeaf11abf1ca926fb3d..eb7865ddf83c8151653159b59d8c3c725a4d65b8 100644 --- a/app/code/Magento/Payment/view/frontend/web/template/payment/cc-form.html +++ b/app/code/Magento/Payment/view/frontend/web/template/payment/cc-form.html @@ -19,13 +19,14 @@ <ul class="credit-card-types"> <!-- ko foreach: {data: getCcAvailableTypesValues(), as: 'item'} --> <li class="item" data-bind="css: {_active: $parent.selectedCardType() == item.value} "> - <!-- if picture --> + <!--ko if: $parent.getIcons(item.value) --> <img data-bind="attr: { - 'src': 'Magento_Payment::images/cc/'+ item.value + '.png', - 'alt': item.type + 'src': $parent.getIcons(item.value).url, + 'alt': item.type, + 'width': $parent.getIcons(item.value).width, + 'height': $parent.getIcons(item.value).height }"> - <!-- if NOpicture --> - <span><!-- ko text: item.type --><!-- /ko --></span> + <!--/ko--> </li> <!--/ko--> </ul>