2020-04-02 17:04:15 +00:00
|
|
|
/**
|
|
|
|
* 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', {} );
|
2020-07-15 14:14:41 +00:00
|
|
|
const defaultLabel = __( 'Check payment', 'woo-gutenberg-products-block' );
|
2020-04-29 10:57:58 +00:00
|
|
|
const label = decodeEntities( settings.title ) || defaultLabel;
|
2020-04-02 17:04:15 +00:00
|
|
|
|
2020-04-03 11:50:54 +00:00
|
|
|
/**
|
|
|
|
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').RegisteredPaymentMethodProps} RegisteredPaymentMethodProps
|
|
|
|
*/
|
2020-04-02 17:04:15 +00:00
|
|
|
|
2020-04-03 11:50:54 +00:00
|
|
|
/**
|
2020-04-28 10:13:48 +00:00
|
|
|
* Content component
|
2020-04-03 11:50:54 +00:00
|
|
|
*/
|
2020-04-28 10:13:48 +00:00
|
|
|
const Content = () => {
|
|
|
|
return <div>{ decodeEntities( settings.description || '' ) }</div>;
|
2020-04-14 06:01:29 +00:00
|
|
|
};
|
|
|
|
|
2020-05-13 15:48:03 +00:00
|
|
|
/**
|
|
|
|
* Label component
|
|
|
|
*
|
|
|
|
* @param {*} props Props from payment API.
|
|
|
|
*/
|
|
|
|
const Label = ( props ) => {
|
|
|
|
const { PaymentMethodLabel } = props.components;
|
2020-08-11 20:44:19 +00:00
|
|
|
return <PaymentMethodLabel text={ label } />;
|
2020-05-13 15:48:03 +00:00
|
|
|
};
|
|
|
|
|
2020-04-29 10:57:58 +00:00
|
|
|
/**
|
|
|
|
* Cheque payment method config object.
|
|
|
|
*/
|
2020-04-02 17:04:15 +00:00
|
|
|
const offlineChequePaymentMethod = {
|
2020-04-09 15:22:34 +00:00
|
|
|
name: PAYMENT_METHOD_NAME,
|
2020-05-13 15:48:03 +00:00
|
|
|
label: <Label />,
|
2020-04-02 17:04:15 +00:00
|
|
|
content: <Content />,
|
2020-04-28 10:13:48 +00:00
|
|
|
edit: <Content />,
|
2020-04-09 11:44:29 +00:00
|
|
|
canMakePayment: () => true,
|
2020-04-29 10:57:58 +00:00
|
|
|
ariaLabel: label,
|
2020-04-02 17:04:15 +00:00
|
|
|
};
|
|
|
|
|
2020-11-18 22:06:33 +00:00
|
|
|
registerPaymentMethod( offlineChequePaymentMethod );
|