2020-10-05 11:59:20 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import {
|
|
|
|
useCheckoutContext,
|
|
|
|
useEditorContext,
|
|
|
|
usePaymentMethodDataContext,
|
|
|
|
} from '@woocommerce/base-context';
|
|
|
|
import CheckboxControl from '@woocommerce/base-components/checkbox-control';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import PaymentMethodErrorBoundary from './payment-method-error-boundary';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component used to render the contents of a payment method tab.
|
|
|
|
*
|
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
|
|
|
|
* the data for future purchases and should
|
|
|
|
* display the checkbox to do so.
|
|
|
|
* @param {Object} props.children Content of the payment method tab.
|
2020-10-05 11:59:20 +00:00
|
|
|
*
|
|
|
|
* @return {*} The rendered component.
|
|
|
|
*/
|
2021-01-24 13:59:13 +00:00
|
|
|
const PaymentMethodTab = ( { children, showSaveOption } ) => {
|
2020-10-05 11:59:20 +00:00
|
|
|
const { isEditor } = useEditorContext();
|
|
|
|
const {
|
|
|
|
shouldSavePayment,
|
|
|
|
setShouldSavePayment,
|
|
|
|
} = usePaymentMethodDataContext();
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
PaymentMethodTab.propTypes = {
|
2021-01-24 13:59:13 +00:00
|
|
|
showSaveOption: PropTypes.bool,
|
2020-10-05 11:59:20 +00:00
|
|
|
children: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PaymentMethodTab;
|