/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { useEditorContext, usePaymentMethodDataContext, } from '@woocommerce/base-context'; import { CheckboxControl } from '@woocommerce/blocks-checkout'; import PropTypes from 'prop-types'; import { useSelect } from '@wordpress/data'; import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data'; /** * Internal dependencies */ import PaymentMethodErrorBoundary from './payment-method-error-boundary'; /** * Component used to render the contents of a payment method card. * * @param {Object} props Incoming props for the component. * @param {boolean} props.showSaveOption Whether that payment method allows saving * the data for future purchases. * @param {Object} props.children Content of the payment method card. * * @return {*} The rendered component. */ const PaymentMethodCard = ( { children, showSaveOption } ) => { const { isEditor } = useEditorContext(); const { shouldSavePayment, setShouldSavePayment } = usePaymentMethodDataContext(); const customerId = useSelect( ( select ) => select( CHECKOUT_STORE_KEY ).getCustomerId() ); return ( { children } { customerId > 0 && showSaveOption && ( setShouldSavePayment( ! shouldSavePayment ) } /> ) } ); }; PaymentMethodCard.propTypes = { showSaveOption: PropTypes.bool, children: PropTypes.node, }; export default PaymentMethodCard;