Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Model/Config/Cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ public function getCardTheme()
{
return $this->getValue('card_form_theme', self::CODE);
}

/**
* Get the card brands icons enabled in the payment configuration.
*
* @return array
*/
public function getSupportedCardIcons()
{
$supportedCardIcons = $this->getValue('supported_card_icons', self::CODE);
return $supportedCardIcons ? explode(',', $supportedCardIcons) : [];
}
}
42 changes: 42 additions & 0 deletions Model/Source/CardBrandIcon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Omise\Payment\Model\Source;

use Magento\Framework\Option\ArrayInterface;

class CardBrandIcon implements ArrayInterface
{
/**
* Return array of supported card brand icons
* @return array
*/
public function toOptionArray()
{
return [
[
'value' => 'visa',
'label' => __('Visa'),
],
[
'value' => 'mastercard',
'label' => __('Mastercard'),
],
[
'value' => 'amex',
'label' => __('American Express'),
],
[
'value' => 'jcb',
'label' => __('JCB'),
],
[
'value' => 'diners',
'label' => __('Diners Club'),
],
[
'value' => 'discover',
'label' => __('Discover'),
],
];
}
}
3 changes: 2 additions & 1 deletion Model/Ui/CcConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function getConfig()
'cards' => $this->getCards(),
'locale' => $this->omiseCcConfig->getStoreLocale(),
'formDesign' => $theme->getFormDesign($selectedTheme, $customDesign),
'theme' => $selectedTheme
'theme' => $selectedTheme,
'supported_card_icons' => $this->omiseCcConfig->getSupportedCardIcons()
],
]
];
Expand Down
53 changes: 53 additions & 0 deletions Test/Unit/Model/Config/CcConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Omise\Payment\Test\Unit\Model\Config;

use Omise\Payment\Model\Config\Cc;
use PHPUnit\Framework\TestCase;

class CcConfigTest extends TestCase
{
/**
* @covers \Omise\Payment\Model\Config\Cc::getSupportedCardIcons
*/
public function testGetSupportedCardIconsReturnsConfiguredCommaSeparatedValues(): void
{
$config = $this->createConfigMock('visa,mastercard,amex');

$this->assertSame(['visa', 'mastercard', 'amex'], $config->getSupportedCardIcons());
}

/**
* @covers \Omise\Payment\Model\Config\Cc::getSupportedCardIcons
* @dataProvider emptyConfigValueProvider
*/
public function testGetSupportedCardIconsReturnsEmptyArrayWhenNoIconsAreConfigured($emptyValue): void
{
$config = $this->createConfigMock($emptyValue);

$this->assertSame([], $config->getSupportedCardIcons());
}

public static function emptyConfigValueProvider(): array
{
return [
'null' => [null],
'empty string' => [''],
];
}

private function createConfigMock($value): Cc
{
$config = $this->getMockBuilder(Cc::class)
->disableOriginalConstructor()
->onlyMethods(['getValue'])
->getMock();

$config->expects($this->once())
->method('getValue')
->with('supported_card_icons', Cc::CODE)
->willReturn($value);

return $config;
}
}
38 changes: 38 additions & 0 deletions Test/Unit/Model/Source/CardBrandIconTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Omise\Payment\Test\Unit\Model\Source;

use Omise\Payment\Model\Source\CardBrandIcon;
use PHPUnit\Framework\TestCase;

class CardBrandIconTest extends TestCase
{
/**
* @covers \Omise\Payment\Model\Source\CardBrandIcon::toOptionArray
*/
public function testToOptionArrayReturnsSupportedCardBrandIcons(): void
{
$source = new CardBrandIcon();
$options = $source->toOptionArray();

$this->assertSame(
[
['value' => 'visa', 'label' => 'Visa'],
['value' => 'mastercard', 'label' => 'Mastercard'],
['value' => 'amex', 'label' => 'American Express'],
['value' => 'jcb', 'label' => 'JCB'],
['value' => 'diners', 'label' => 'Diners Club'],
['value' => 'discover', 'label' => 'Discover'],
],
array_map(
static function (array $option): array {
return [
'value' => $option['value'],
'label' => (string) $option['label'],
];
},
$options
)
);
}
}
7 changes: 6 additions & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
<![CDATA[Credit/debit card secure form design on checkout page. <a style="cursor:pointer" onclick="cardFormCustomization.showModal()"><b>Click here</b></a> for more secure card form customization.]]>
</comment>
</field>
<field id="supported_card_icons" translate="label" type="multiselect" sortOrder="114" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Supported card icons</label>
<config_path>payment/omise_cc/supported_card_icons</config_path>
<source_model>Omise\Payment\Model\Source\CardBrandIcon</source_model>
</field>
<field id="card_form_theme_config" sortOrder="113" showInDefault="1" showInWebsite="1" showInStore="1">
<config_path>payment/omise_cc/card_form_theme_config</config_path>
<frontend_model>Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization\FormModal</frontend_model>
Expand Down Expand Up @@ -940,4 +945,4 @@
</group>
</section>
</system>
</config>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ define(
}

const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc
const supportedCardIcons = window.checkoutConfig.payment.omise_cc.supported_card_icons
const { font, input, checkbox } = formDesign
let iframeElementHeight = iframeHeightMatching[input.height]
if (hideRememberCard) {
iframeElementHeight = iframeElementHeight - 25
}
element.style.height = iframeElementHeight + 'px'

OmiseCard.configure({
const cardFormConfig = {
publicKey: self.getPublicKey(),
element,
locale: localeMatching[locale] ?? 'en',
Expand All @@ -157,7 +158,14 @@ define(
}
},
customCardFormHideRememberCard: hideRememberCard
})
}

if (Array.isArray(supportedCardIcons) && supportedCardIcons.length > 0) {
cardFormConfig.customCardFormBrandIcons = supportedCardIcons
cardFormConfig.cardBrands = supportedCardIcons.join(' ')
}
Comment thread
rosle marked this conversation as resolved.

OmiseCard.configure(cardFormConfig)

OmiseCard.open({
onCreateTokenSuccess: (payload) => {
Expand Down
Loading