woocommerce/plugins/woocommerce-blocks/assets/js/extensions/payment-methods/bacs/index.js

53 lines
1.3 KiB
JavaScript

/**
* External dependencies
*/
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
import { __ } from '@wordpress/i18n';
import { getPaymentMethodData } from '@woocommerce/settings';
import { decodeEntities } from '@wordpress/html-entities';
import { sanitizeHTML } from '@woocommerce/utils';
import { RawHTML } from '@wordpress/element';
/**
* Internal dependencies
*/
import { PAYMENT_METHOD_NAME } from './constants';
const settings = getPaymentMethodData( 'bacs', {} );
const defaultLabel = __( 'Direct bank transfer', 'woocommerce' );
const label = decodeEntities( settings?.title || '' ) || defaultLabel;
/**
* Content component
*/
const Content = () => {
return <RawHTML>{ sanitizeHTML( settings.description || '' ) }</RawHTML>;
};
/**
* Label component
*
* @param {*} props Props from payment API.
*/
const Label = ( props ) => {
const { PaymentMethodLabel } = props.components;
return <PaymentMethodLabel text={ label } />;
};
/**
* Bank transfer (BACS) payment method config object.
*/
const bankTransferPaymentMethod = {
name: PAYMENT_METHOD_NAME,
label: <Label />,
content: <Content />,
edit: <Content />,
canMakePayment: () => true,
ariaLabel: label,
supports: {
features: settings?.supports ?? [],
},
};
registerPaymentMethod( bankTransferPaymentMethod );