import { getSetting } from '@woocommerce/settings'; import { __ } from '@wordpress/i18n'; import { InlineCard, AirwallexSaveCard } from './elements'; import { useEffect, useState } from 'react'; import { getCardData } from '../api'; import type { BlockMethodSettings, PaymentMethodComponentProps } from '../../types/blocks'; interface CardSettings extends BlockMethodSettings { checkout_form_type?: 'inline' | 'redirect' | string; is_logged_in?: boolean; is_save_card_enabled?: boolean; is_subscription?: boolean; is_funnelkit_active?: boolean; } const settings: CardSettings = getSetting('airwallex_card_data', {}); const title = settings?.title || __('Card', 'airwallex-online-payments-gateway'); const description = settings?.description; const cardInformationMessage = __('Card information', 'airwallex-online-payments-gateway'); const savePaymentMessage = __('Save payment information to my account for future purchases', 'airwallex-online-payments-gateway'); // `components` is optional for compile-time JSX (the factory is // invoked as `` without props); WC blocks injects // `props.components.PaymentMethodLabel` at runtime via cloneElement. type AirwallexLabelProps = Partial; const AirwallexLabelCard = (props: AirwallexLabelProps) => { const { PaymentMethodLabel } = props.components!; const [logos, setLogos] = useState>({}); useEffect(() => { getCardData().then((response) => { if (response.data?.logos) { setLogos(response.data.logos); } }); }, []); return ( <> {Object.entries(logos).map(([name, src]) => { return ( {title} ); })} ); } const AirwallexContentCard = (props: Partial) => { if (settings?.enabled === false) { return null; } const card = settings.checkout_form_type == 'inline' ? ( <>
{cardInformationMessage}
{description &&

{description}

} { settings.is_logged_in && settings.is_save_card_enabled && ! settings.is_subscription && (
)} ) : (
{description}
); return card; }; const canMakePayment = (): boolean => { return settings?.enabled ?? false; } export const airwallexCardOption = { name: settings?.name ?? 'airwallex_card', label: , content: , edit: , savedTokenComponent: , canMakePayment: canMakePayment, ariaLabel: title, supports: { features: settings?.supports ?? [], } };