woocommerce/packages/woocommerce-blocks/assets/js/payment-method-extensions/payment-methods/cheque/index.js
2021-12-10 12:03:04 +00:00

55 lines
1.3 KiB
JavaScript

/**
* External dependencies
*/
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
import { __ } from '@wordpress/i18n';
import { getSetting } from '@woocommerce/settings';
import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import { PAYMENT_METHOD_NAME } from './constants';
const settings = getSetting( 'cheque_data', {} );
const defaultLabel = __( 'Check payment', 'woocommerce' );
const label = decodeEntities( settings.title ) || defaultLabel;
/**
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').RegisteredPaymentMethodProps} RegisteredPaymentMethodProps
*/
/**
* Content component
*/
const Content = () => {
return decodeEntities( settings.description || '' );
};
/**
* Label component
*
* @param {*} props Props from payment API.
*/
const Label = ( props ) => {
const { PaymentMethodLabel } = props.components;
return <PaymentMethodLabel text={ label } />;
};
/**
* Cheque payment method config object.
*/
const offlineChequePaymentMethod = {
name: PAYMENT_METHOD_NAME,
label: <Label />,
content: <Content />,
edit: <Content />,
canMakePayment: () => true,
ariaLabel: label,
supports: {
features: settings?.supports ?? [],
},
};
registerPaymentMethod( offlineChequePaymentMethod );