2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-10-20 16:18:13 +00:00
|
|
|
import classnames from 'classnames';
|
2021-07-22 11:03:00 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
2021-11-26 14:47:37 +00:00
|
|
|
import { PanelBody, ExternalLink } from '@wordpress/components';
|
2021-07-22 11:03:00 +00:00
|
|
|
import { ADMIN_URL, getSetting } from '@woocommerce/settings';
|
|
|
|
import ExternalLinkCard from '@woocommerce/editor-components/external-link-card';
|
2021-09-03 13:25:09 +00:00
|
|
|
import { innerBlockAreas } from '@woocommerce/blocks-checkout';
|
2021-11-26 14:47:37 +00:00
|
|
|
import Noninteractive from '@woocommerce/base-components/noninteractive';
|
2022-12-28 16:30:46 +00:00
|
|
|
import { GlobalPaymentMethod } from '@woocommerce/types';
|
|
|
|
import { useSelect } from '@wordpress/data';
|
|
|
|
import { PAYMENT_STORE_KEY } from '@woocommerce/block-data';
|
2023-06-07 09:29:15 +00:00
|
|
|
import { blocksConfig } from '@woocommerce/block-settings';
|
|
|
|
import { trimCharacters, trimWords } from '@woocommerce/utils';
|
2021-07-22 11:03:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
FormStepBlock,
|
|
|
|
AdditionalFields,
|
|
|
|
AdditionalFieldsContent,
|
|
|
|
} from '../../form-step';
|
|
|
|
import Block from './block';
|
|
|
|
|
2021-10-20 16:18:13 +00:00
|
|
|
export const Edit = ( {
|
|
|
|
attributes,
|
|
|
|
setAttributes,
|
|
|
|
}: {
|
|
|
|
attributes: {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
showStepNumber: boolean;
|
|
|
|
className: string;
|
|
|
|
};
|
|
|
|
setAttributes: ( attributes: Record< string, unknown > ) => void;
|
|
|
|
} ): JSX.Element => {
|
2022-12-28 16:30:46 +00:00
|
|
|
const globalPaymentMethods = getSetting< GlobalPaymentMethod[] >(
|
2021-07-22 11:03:00 +00:00
|
|
|
'globalPaymentMethods'
|
2022-12-28 16:30:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const { incompatiblePaymentMethods } = useSelect( ( select ) => {
|
|
|
|
const { getIncompatiblePaymentMethods } = select( PAYMENT_STORE_KEY );
|
|
|
|
return {
|
|
|
|
incompatiblePaymentMethods: getIncompatiblePaymentMethods(),
|
|
|
|
};
|
|
|
|
}, [] );
|
|
|
|
const incompatiblePaymentMethodMessage = __(
|
|
|
|
'Incompatible with block-based checkout',
|
2023-12-12 22:12:36 +00:00
|
|
|
'woocommerce'
|
2022-12-28 16:30:46 +00:00
|
|
|
);
|
2023-06-07 09:29:15 +00:00
|
|
|
const wordCountType = blocksConfig.wordCountType;
|
2021-07-22 11:03:00 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FormStepBlock
|
2021-10-20 16:18:13 +00:00
|
|
|
attributes={ attributes }
|
|
|
|
setAttributes={ setAttributes }
|
|
|
|
className={ classnames(
|
|
|
|
'wc-block-checkout__payment-method',
|
|
|
|
attributes?.className
|
|
|
|
) }
|
2021-07-22 11:03:00 +00:00
|
|
|
>
|
|
|
|
<InspectorControls>
|
|
|
|
{ globalPaymentMethods.length > 0 && (
|
2023-12-12 23:05:20 +00:00
|
|
|
<PanelBody title={ __( 'Methods', 'woocommerce' ) }>
|
2021-07-22 11:03:00 +00:00
|
|
|
<p className="wc-block-checkout__controls-text">
|
|
|
|
{ __(
|
|
|
|
'You currently have the following payment integrations active.',
|
2023-12-12 22:12:36 +00:00
|
|
|
'woocommerce'
|
2021-07-22 11:03:00 +00:00
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
{ globalPaymentMethods.map( ( method ) => {
|
2022-12-28 16:30:46 +00:00
|
|
|
const isIncompatible =
|
|
|
|
!! incompatiblePaymentMethods[ method.id ];
|
|
|
|
|
2023-06-07 09:29:15 +00:00
|
|
|
let trimmedDescription;
|
|
|
|
|
|
|
|
if ( wordCountType === 'words' ) {
|
|
|
|
trimmedDescription = trimWords(
|
|
|
|
method.description,
|
|
|
|
30,
|
|
|
|
undefined,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
trimmedDescription = trimCharacters(
|
|
|
|
method.description,
|
|
|
|
30,
|
|
|
|
wordCountType ===
|
|
|
|
'characters_including_spaces',
|
|
|
|
undefined,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-22 11:03:00 +00:00
|
|
|
return (
|
|
|
|
<ExternalLinkCard
|
|
|
|
key={ method.id }
|
|
|
|
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=checkout§ion=${ method.id }` }
|
|
|
|
title={ method.title }
|
2023-06-07 09:29:15 +00:00
|
|
|
description={ trimmedDescription }
|
2022-12-28 16:30:46 +00:00
|
|
|
{ ...( isIncompatible
|
|
|
|
? {
|
|
|
|
warning:
|
|
|
|
incompatiblePaymentMethodMessage,
|
|
|
|
}
|
|
|
|
: {} ) }
|
2021-07-22 11:03:00 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
<ExternalLink
|
|
|
|
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=checkout` }
|
|
|
|
>
|
2023-12-12 23:05:20 +00:00
|
|
|
{ __( 'Manage payment methods', 'woocommerce' ) }
|
2021-07-22 11:03:00 +00:00
|
|
|
</ExternalLink>
|
|
|
|
</PanelBody>
|
|
|
|
) }
|
|
|
|
</InspectorControls>
|
2021-11-26 14:47:37 +00:00
|
|
|
<Noninteractive>
|
2021-07-22 11:03:00 +00:00
|
|
|
<Block />
|
2021-11-26 14:47:37 +00:00
|
|
|
</Noninteractive>
|
2021-09-07 16:01:14 +00:00
|
|
|
<AdditionalFields block={ innerBlockAreas.PAYMENT_METHODS } />
|
2021-07-22 11:03:00 +00:00
|
|
|
</FormStepBlock>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Save = (): JSX.Element => {
|
|
|
|
return (
|
|
|
|
<div { ...useBlockProps.save() }>
|
|
|
|
<AdditionalFieldsContent />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|