2020-10-05 11:59:20 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import {
|
|
|
|
useCheckoutContext,
|
|
|
|
useEditorContext,
|
|
|
|
usePaymentMethodDataContext,
|
|
|
|
} from '@woocommerce/base-context';
|
2021-11-09 16:47:46 +00:00
|
|
|
import { CheckboxControl } from '@woocommerce/blocks-checkout';
|
2020-10-05 11:59:20 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import PaymentMethodErrorBoundary from './payment-method-error-boundary';
|
|
|
|
|
|
|
|
/**
|
2021-02-02 04:51:47 +00:00
|
|
|
* Component used to render the contents of a payment method card.
|
2020-10-05 11:59:20 +00:00
|
|
|
*
|
2021-01-24 13:59:13 +00:00
|
|
|
* @param {Object} props Incoming props for the component.
|
|
|
|
* @param {boolean} props.showSaveOption Whether that payment method allows saving
|
2021-02-02 04:51:47 +00:00
|
|
|
* the data for future purchases.
|
|
|
|
* @param {Object} props.children Content of the payment method card.
|
2020-10-05 11:59:20 +00:00
|
|
|
*
|
|
|
|
* @return {*} The rendered component.
|
|
|
|
*/
|
2021-02-02 04:51:47 +00:00
|
|
|
const PaymentMethodCard = ( { children, showSaveOption } ) => {
|
2020-10-05 11:59:20 +00:00
|
|
|
const { isEditor } = useEditorContext();
|
2022-06-15 09:56:52 +00:00
|
|
|
const { shouldSavePayment, setShouldSavePayment } =
|
|
|
|
usePaymentMethodDataContext();
|
2020-10-05 11:59:20 +00:00
|
|
|
const { customerId } = useCheckoutContext();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<PaymentMethodErrorBoundary isEditor={ isEditor }>
|
|
|
|
{ children }
|
2021-01-24 13:59:13 +00:00
|
|
|
{ customerId > 0 && showSaveOption && (
|
2020-10-05 11:59:20 +00:00
|
|
|
<CheckboxControl
|
|
|
|
className="wc-block-components-payment-methods__save-card-info"
|
|
|
|
label={ __(
|
|
|
|
'Save payment information to my account for future purchases.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ shouldSavePayment }
|
|
|
|
onChange={ () =>
|
|
|
|
setShouldSavePayment( ! shouldSavePayment )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</PaymentMethodErrorBoundary>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-02-02 04:51:47 +00:00
|
|
|
PaymentMethodCard.propTypes = {
|
2021-01-24 13:59:13 +00:00
|
|
|
showSaveOption: PropTypes.bool,
|
2020-10-05 11:59:20 +00:00
|
|
|
children: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
2021-02-02 04:51:47 +00:00
|
|
|
export default PaymentMethodCard;
|