Skip to content

Commit 3db424c

Browse files
committed
fix: filter card brands by key instead of localized title
Card brand detection was breaking in non-English locales because it filtered by comparing title !== 'Card', but 'Card' is a translated string (e.g., "Tarjeta" in Spanish, "Carte" in French). This caused the fallback brand to be incorrectly detected as a real brand, hiding the logo when it shouldn't. Fixed by filtering array keys (key !== 'default') instead of comparing localized titles, making the detection locale-independent. Changes: - WCGatewayMoneiCC.php: Filter by array_keys and check !== 'default' - MoneiCCBlocksSupport.php: Filter by array_keys and check !== 'default' - monei-cc-component.js: Filter keys instead of values, update map to use key
1 parent e9bb3ef commit 3db424c

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

assets/js/components/monei-cc-component.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ export const MoneiCCContent = ( props ) => {
353353
*/
354354
export const CreditCardLabel = ( moneiData ) => {
355355
const cardBrands = moneiData?.cardBrands
356-
? Object.values( moneiData.cardBrands ).filter(
357-
( brand ) => brand.title !== 'Card'
356+
? Object.keys( moneiData.cardBrands ).filter(
357+
( key ) => key !== 'default'
358358
)
359359
: [];
360360

@@ -365,14 +365,17 @@ export const CreditCardLabel = ( moneiData ) => {
365365
) }
366366
{ cardBrands.length > 0 ? (
367367
<span className="monei-card-brands">
368-
{ cardBrands.map( ( brand, index ) => (
369-
<img
370-
key={ index }
371-
src={ brand.url }
372-
alt={ brand.title }
373-
className="card-brand-icon"
374-
/>
375-
) ) }
368+
{ cardBrands.map( ( key ) => {
369+
const brand = moneiData.cardBrands[ key ];
370+
return (
371+
<img
372+
key={ key }
373+
src={ brand.url }
374+
alt={ brand.title }
375+
className="card-brand-icon"
376+
/>
377+
);
378+
} ) }
376379
</span>
377380
) : (
378381
moneiData?.logo && (

src/Gateways/Blocks/MoneiCCBlocksSupport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function get_payment_method_data() {
151151
}
152152

153153
// Remove logo when card brands are available
154-
if ( ! empty( $data['cardBrands'] ) && count( array_filter( $data['cardBrands'], fn( $b ) => $b['title'] !== 'Card' ) ) > 0 ) {
154+
if ( ! empty( $data['cardBrands'] ) && count( array_filter( array_keys( $data['cardBrands'] ), fn( $key ) => $key !== 'default' ) ) > 0 ) {
155155
unset( $data['logo'] );
156156
}
157157

src/Gateways/PaymentMethods/WCGatewayMoneiCC.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function __construct(
9999

100100
// Hide logo if card brands are available
101101
$cardBrands = $this->cardBrandHelper->getCardBrandsConfig();
102-
$hasCardBrands = ! empty( $cardBrands ) && count( array_filter( $cardBrands, fn( $b ) => $b['title'] !== 'Card' ) ) > 0;
102+
$hasCardBrands = ! empty( $cardBrands ) && count( array_filter( array_keys( $cardBrands ), fn( $key ) => $key !== 'default' ) ) > 0;
103103

104104
$this->icon = ( $this->hide_logo || $hasCardBrands ) ? '' : $iconMarkup;
105105
$this->redirect_flow = ( ! empty( $this->get_option( 'cc_mode' ) ) && 'yes' === $this->get_option( 'cc_mode' ) ) ? true : false;
@@ -430,8 +430,13 @@ public function monei_scripts() {
430430
}
431431

432432
// Return early if redirect flow (doesn't need component scripts)
433-
// OR if not on a page that needs scripts
434-
if ( $this->redirect_flow || ( ! is_checkout() && ! is_checkout_pay_page() && ! is_add_payment_method_page() ) ) {
433+
if ( $this->redirect_flow ) {
434+
return;
435+
}
436+
437+
// Return early if not on a page that needs scripts
438+
$is_required_page = is_checkout() || is_checkout_pay_page() || is_add_payment_method_page();
439+
if ( ! $is_required_page ) {
435440
return;
436441
}
437442

0 commit comments

Comments
 (0)