From 833667eca49fb33df447c2f92cf5992596881199 Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Tue, 6 Oct 2026 14:49:28 +0530 Subject: [PATCH 1/7] Create admin configuration and display brand icons based on configuration --- Model/Config/Cc.php | 16 ++++++++ Model/Source/CardBrandIcon.php | 38 +++++++++++++++++++ Model/Ui/CcConfigProvider.php | 3 +- etc/adminhtml/system.xml | 5 +++ .../method-renderer/omise-cc-method.js | 12 +++++- 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 Model/Source/CardBrandIcon.php diff --git a/Model/Config/Cc.php b/Model/Config/Cc.php index 89180e8d..84b2c44b 100644 --- a/Model/Config/Cc.php +++ b/Model/Config/Cc.php @@ -26,4 +26,20 @@ 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 getAllowedCardsIcon() + { + $allowedCardsIcon = $this->getValue('allow_card_icon', self::CODE); + + if (is_array($allowedCardsIcon)) { + return $allowedCardsIcon; + } + + return $allowedCardsIcon ? explode(',', $allowedCardsIcon) : []; + } } diff --git a/Model/Source/CardBrandIcon.php b/Model/Source/CardBrandIcon.php new file mode 100644 index 00000000..2f40c468 --- /dev/null +++ b/Model/Source/CardBrandIcon.php @@ -0,0 +1,38 @@ + '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'), + ], + ]; + } +} diff --git a/Model/Ui/CcConfigProvider.php b/Model/Ui/CcConfigProvider.php index 8d0abaaf..a0a572f8 100644 --- a/Model/Ui/CcConfigProvider.php +++ b/Model/Ui/CcConfigProvider.php @@ -57,7 +57,8 @@ public function getConfig() 'cards' => $this->getCards(), 'locale' => $this->omiseCcConfig->getStoreLocale(), 'formDesign' => $theme->getFormDesign($selectedTheme, $customDesign), - 'theme' => $selectedTheme + 'theme' => $selectedTheme, + 'omise_cc_allow_card_icon' => $this->omiseCcConfig->getAllowedCardsIcon() ], ] ]; diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 6564f801..86836068 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -109,6 +109,11 @@ Click here for more secure card form customization.]]> + + + payment/omise_cc/allow_card_icon + Omise\Payment\Model\Source\CardBrandIcon + payment/omise_cc/card_form_theme_config Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization\FormModal diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js index ebe0ba32..943be7ae 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js @@ -124,6 +124,7 @@ define( } const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc + const allowedCardIcons = window.checkoutConfig.payment.omise_cc.omise_cc_allow_card_icon const { font, input, checkbox } = formDesign let iframeElementHeight = iframeHeightMatching[input.height] if (hideRememberCard) { @@ -131,7 +132,7 @@ define( } element.style.height = iframeElementHeight + 'px' - OmiseCard.configure({ + const cardFormConfig = { publicKey: self.getPublicKey(), element, locale: localeMatching[locale] ?? 'en', @@ -157,7 +158,14 @@ define( } }, customCardFormHideRememberCard: hideRememberCard - }) + } + + if (Array.isArray(allowedCardIcons) && allowedCardIcons.length > 0) { + cardFormConfig.customCardFormBrandIcons = allowedCardIcons + cardFormConfig.cardBrands = allowedCardIcons.join(' ') + } + + OmiseCard.configure(cardFormConfig) OmiseCard.open({ onCreateTokenSuccess: (payload) => { From 9c8c382b60d854f565a38e8bdfecd949b6c909fd Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Tue, 6 Oct 2026 14:56:43 +0530 Subject: [PATCH 2/7] Create a test unit class --- Test/Unit/Model/Source/CardBrandIconTest.php | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Test/Unit/Model/Source/CardBrandIconTest.php diff --git a/Test/Unit/Model/Source/CardBrandIconTest.php b/Test/Unit/Model/Source/CardBrandIconTest.php new file mode 100644 index 00000000..14a81b8c --- /dev/null +++ b/Test/Unit/Model/Source/CardBrandIconTest.php @@ -0,0 +1,38 @@ +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 + ) + ); + } +} From 8bd73963e7ce2321310f2f37964ed0db4d9f3fc7 Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Tue, 6 Oct 2026 15:03:50 +0530 Subject: [PATCH 3/7] Create a test unit class --- Model/Config/Cc.php | 2 - Model/Source/CardBrandIcon.php | 6 ++- Test/Unit/Model/Config/CcConfigTest.php | 64 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 Test/Unit/Model/Config/CcConfigTest.php diff --git a/Model/Config/Cc.php b/Model/Config/Cc.php index 84b2c44b..9ae8839d 100644 --- a/Model/Config/Cc.php +++ b/Model/Config/Cc.php @@ -35,11 +35,9 @@ public function getCardTheme() public function getAllowedCardsIcon() { $allowedCardsIcon = $this->getValue('allow_card_icon', self::CODE); - if (is_array($allowedCardsIcon)) { return $allowedCardsIcon; } - return $allowedCardsIcon ? explode(',', $allowedCardsIcon) : []; } } diff --git a/Model/Source/CardBrandIcon.php b/Model/Source/CardBrandIcon.php index 2f40c468..66cbe705 100644 --- a/Model/Source/CardBrandIcon.php +++ b/Model/Source/CardBrandIcon.php @@ -6,6 +6,10 @@ class CardBrandIcon implements ArrayInterface { + /** + * Return array of supported card brand icons + * @return array + */ public function toOptionArray() { return [ @@ -20,7 +24,7 @@ public function toOptionArray() [ 'value' => 'amex', 'label' => __('American Express'), - ], + ], [ 'value' => 'jcb', 'label' => __('JCB'), diff --git a/Test/Unit/Model/Config/CcConfigTest.php b/Test/Unit/Model/Config/CcConfigTest.php new file mode 100644 index 00000000..94fc1317 --- /dev/null +++ b/Test/Unit/Model/Config/CcConfigTest.php @@ -0,0 +1,64 @@ +createConfigMock('visa,mastercard,amex'); + + $this->assertSame(['visa', 'mastercard', 'amex'], $config->getAllowedCardsIcon()); + } + + /** + * @covers \Omise\Payment\Model\Config\Cc::getAllowedCardsIcon + */ + public function testGetAllowedCardsIconReturnsArrayConfigurationAsIs(): void + { + $allowedIcons = ['visa', 'mastercard']; + $config = $this->createConfigMock($allowedIcons); + + $this->assertSame($allowedIcons, $config->getAllowedCardsIcon()); + } + + /** + * @covers \Omise\Payment\Model\Config\Cc::getAllowedCardsIcon + * @dataProvider emptyConfigValueProvider + */ + public function testGetAllowedCardsIconReturnsEmptyArrayWhenNoIconsAreConfigured($emptyValue): void + { + $config = $this->createConfigMock($emptyValue); + + $this->assertSame([], $config->getAllowedCardsIcon()); + } + + 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('allow_card_icon', Cc::CODE) + ->willReturn($value); + + return $config; + } +} From eb4929cc429d852d6d13249e3b4b174a2fb57a84 Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Tue, 6 Oct 2026 15:13:54 +0530 Subject: [PATCH 4/7] Resolve git-copilot suggestion --- .../web/js/view/payment/method-renderer/omise-cc-method.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js index 943be7ae..c74d7f42 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js @@ -160,7 +160,7 @@ define( customCardFormHideRememberCard: hideRememberCard } - if (Array.isArray(allowedCardIcons) && allowedCardIcons.length > 0) { + if (Array.isArray(allowedCardIcons)) { cardFormConfig.customCardFormBrandIcons = allowedCardIcons cardFormConfig.cardBrands = allowedCardIcons.join(' ') } From bfbe3fe4b08bc8d89ef642a34e393ea007d10ae2 Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Wed, 7 Oct 2026 16:31:21 +0530 Subject: [PATCH 5/7] refactor the variable name in complete flow --- Model/Config/Cc.php | 9 +++---- Model/Ui/CcConfigProvider.php | 2 +- Test/Unit/Model/Config/CcConfigTest.php | 24 +++++++------------ etc/adminhtml/system.xml | 8 +++---- .../method-renderer/omise-cc-method.js | 8 +++---- 5 files changed, 20 insertions(+), 31 deletions(-) diff --git a/Model/Config/Cc.php b/Model/Config/Cc.php index 9ae8839d..1338ffb6 100644 --- a/Model/Config/Cc.php +++ b/Model/Config/Cc.php @@ -32,12 +32,9 @@ public function getCardTheme() * * @return array */ - public function getAllowedCardsIcon() + public function getSupportedCardIcons() { - $allowedCardsIcon = $this->getValue('allow_card_icon', self::CODE); - if (is_array($allowedCardsIcon)) { - return $allowedCardsIcon; - } - return $allowedCardsIcon ? explode(',', $allowedCardsIcon) : []; + $supportedCardIcons = $this->getValue('supported_card_icons', self::CODE); + return $supportedCardIcons ? explode(',', $supportedCardIcons) : []; } } diff --git a/Model/Ui/CcConfigProvider.php b/Model/Ui/CcConfigProvider.php index a0a572f8..53fb410d 100644 --- a/Model/Ui/CcConfigProvider.php +++ b/Model/Ui/CcConfigProvider.php @@ -58,7 +58,7 @@ public function getConfig() 'locale' => $this->omiseCcConfig->getStoreLocale(), 'formDesign' => $theme->getFormDesign($selectedTheme, $customDesign), 'theme' => $selectedTheme, - 'omise_cc_allow_card_icon' => $this->omiseCcConfig->getAllowedCardsIcon() + 'supported_card_icons' => $this->omiseCcConfig->getSupportedCardIcons() ], ] ]; diff --git a/Test/Unit/Model/Config/CcConfigTest.php b/Test/Unit/Model/Config/CcConfigTest.php index 94fc1317..a6dea394 100644 --- a/Test/Unit/Model/Config/CcConfigTest.php +++ b/Test/Unit/Model/Config/CcConfigTest.php @@ -8,35 +8,27 @@ class CcConfigTest extends TestCase { /** - * @covers \Omise\Payment\Model\Config\Cc::getAllowedCardsIcon + * @covers \Omise\Payment\Model\Config\Cc::getSupportedCardIcons */ - public function testGetAllowedCardsIconReturnsConfiguredCommaSeparatedValues(): void + public function testGetSupportedCardIconsReturnsConfiguredCommaSeparatedValues(): void { $config = $this->createConfigMock('visa,mastercard,amex'); - $this->assertSame(['visa', 'mastercard', 'amex'], $config->getAllowedCardsIcon()); + $this->assertSame(['visa', 'mastercard', 'amex'], $config->getSupportedCardIcons()); } /** - * @covers \Omise\Payment\Model\Config\Cc::getAllowedCardsIcon + * @covers \Omise\Payment\Model\Config\Cc::getSupportedCardIcons */ - public function testGetAllowedCardsIconReturnsArrayConfigurationAsIs(): void - { - $allowedIcons = ['visa', 'mastercard']; - $config = $this->createConfigMock($allowedIcons); - - $this->assertSame($allowedIcons, $config->getAllowedCardsIcon()); - } - /** - * @covers \Omise\Payment\Model\Config\Cc::getAllowedCardsIcon + * @covers \Omise\Payment\Model\Config\Cc::getSupportedCardIcons * @dataProvider emptyConfigValueProvider */ - public function testGetAllowedCardsIconReturnsEmptyArrayWhenNoIconsAreConfigured($emptyValue): void + public function testGetSupportedCardIconsReturnsEmptyArrayWhenNoIconsAreConfigured($emptyValue): void { $config = $this->createConfigMock($emptyValue); - $this->assertSame([], $config->getAllowedCardsIcon()); + $this->assertSame([], $config->getSupportedCardIcons()); } public static function emptyConfigValueProvider(): array @@ -56,7 +48,7 @@ private function createConfigMock($value): Cc $config->expects($this->once()) ->method('getValue') - ->with('allow_card_icon', Cc::CODE) + ->with('supported_card_icons', Cc::CODE) ->willReturn($value); return $config; diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 86836068..a2435603 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -109,9 +109,9 @@ Click here for more secure card form customization.]]> - - - payment/omise_cc/allow_card_icon + + + payment/omise_cc/supported_card_icons Omise\Payment\Model\Source\CardBrandIcon @@ -945,4 +945,4 @@ - \ No newline at end of file + diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js index c74d7f42..6f52bed8 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js @@ -124,7 +124,7 @@ define( } const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc - const allowedCardIcons = window.checkoutConfig.payment.omise_cc.omise_cc_allow_card_icon + const supportedCardIcons = window.checkoutConfig.payment.omise_cc.supported_card_icons const { font, input, checkbox } = formDesign let iframeElementHeight = iframeHeightMatching[input.height] if (hideRememberCard) { @@ -160,9 +160,9 @@ define( customCardFormHideRememberCard: hideRememberCard } - if (Array.isArray(allowedCardIcons)) { - cardFormConfig.customCardFormBrandIcons = allowedCardIcons - cardFormConfig.cardBrands = allowedCardIcons.join(' ') + if (Array.isArray(supportedCardIcons) && supportedCardIcons.length > 0) { + cardFormConfig.customCardFormBrandIcons = supportedCardIcons + cardFormConfig.cardBrands = supportedCardIcons.join(' ') } OmiseCard.configure(cardFormConfig) From 978b0211450b87d9446c9fc129aa73f095171178 Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Wed, 7 Oct 2026 17:22:53 +0530 Subject: [PATCH 6/7] Minor space issue --- Model/Source/CardBrandIcon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Source/CardBrandIcon.php b/Model/Source/CardBrandIcon.php index 66cbe705..9d586460 100644 --- a/Model/Source/CardBrandIcon.php +++ b/Model/Source/CardBrandIcon.php @@ -24,7 +24,7 @@ public function toOptionArray() [ 'value' => 'amex', 'label' => __('American Express'), - ], + ], [ 'value' => 'jcb', 'label' => __('JCB'), From d390d1c56edace1615c17676e390afc1471396cb Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Thu, 8 Oct 2026 10:02:43 +0530 Subject: [PATCH 7/7] git co-pilot issue fixed --- Test/Unit/Model/Config/CcConfigTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Test/Unit/Model/Config/CcConfigTest.php b/Test/Unit/Model/Config/CcConfigTest.php index a6dea394..c07608dc 100644 --- a/Test/Unit/Model/Config/CcConfigTest.php +++ b/Test/Unit/Model/Config/CcConfigTest.php @@ -16,10 +16,7 @@ public function testGetSupportedCardIconsReturnsConfiguredCommaSeparatedValues() $this->assertSame(['visa', 'mastercard', 'amex'], $config->getSupportedCardIcons()); } - - /** - * @covers \Omise\Payment\Model\Config\Cc::getSupportedCardIcons - */ + /** * @covers \Omise\Payment\Model\Config\Cc::getSupportedCardIcons * @dataProvider emptyConfigValueProvider