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-04-29 10:57:58 +00:00
|
|
|
const defaultLabel = __( 'Check Payment', 'woo-gutenberg-products-block' );
|
|
|
|
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;
|
|
|
|
return <PaymentMethodLabel icon="checkPayment" text={ label } />;
|
|
|
|
};
|
|
|
|
|
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-29 10:57:58 +00:00
|
|
|
icons: null,
|
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
|
|
|
};
|
|
|
|
|
|
|
|
registerPaymentMethod( ( Config ) => new Config( offlineChequePaymentMethod ) );
|