2020-01-06 22:28:09 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-04-08 12:31:12 +00:00
|
|
|
import { usePaymentMethods } from '@woocommerce/base-context/hooks';
|
2021-02-02 04:51:47 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2021-05-18 08:10:31 +00:00
|
|
|
import { Label } from '@woocommerce/blocks-checkout';
|
2021-02-02 04:51:47 +00:00
|
|
|
import { usePaymentMethodDataContext } from '@woocommerce/base-context';
|
2020-01-06 22:28:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-03-26 11:11:46 +00:00
|
|
|
import NoPaymentMethods from './no-payment-methods';
|
2020-10-05 11:59:20 +00:00
|
|
|
import PaymentMethodOptions from './payment-method-options';
|
2020-03-26 11:11:46 +00:00
|
|
|
import SavedPaymentMethodOptions from './saved-payment-method-options';
|
2020-03-10 16:35:30 +00:00
|
|
|
|
2020-03-20 16:48:11 +00:00
|
|
|
/**
|
|
|
|
* PaymentMethods component.
|
|
|
|
*
|
|
|
|
* @return {*} The rendered component.
|
|
|
|
*/
|
2020-01-06 22:28:09 +00:00
|
|
|
const PaymentMethods = () => {
|
|
|
|
const { isInitialized, paymentMethods } = usePaymentMethods();
|
2021-02-02 04:51:47 +00:00
|
|
|
const { customerPaymentMethods } = usePaymentMethodDataContext();
|
2020-03-10 16:35:30 +00:00
|
|
|
|
2020-10-05 11:59:20 +00:00
|
|
|
if ( isInitialized && Object.keys( paymentMethods ).length === 0 ) {
|
2020-03-20 16:48:11 +00:00
|
|
|
return <NoPaymentMethods />;
|
2020-01-06 22:28:09 +00:00
|
|
|
}
|
2020-03-26 11:11:46 +00:00
|
|
|
|
2020-10-12 12:43:52 +00:00
|
|
|
return (
|
2020-03-26 11:11:46 +00:00
|
|
|
<>
|
2021-02-02 04:51:47 +00:00
|
|
|
<SavedPaymentMethodOptions />
|
|
|
|
{ Object.keys( customerPaymentMethods ).length > 0 && (
|
|
|
|
<Label
|
|
|
|
label={ __(
|
|
|
|
'Use another payment method.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
screenReaderLabel={ __(
|
|
|
|
'Other available payment methods',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
wrapperElement="p"
|
|
|
|
wrapperProps={ {
|
|
|
|
className: [
|
|
|
|
'wc-block-components-checkout-step__description wc-block-components-checkout-step__description-payments-aligned',
|
|
|
|
],
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
<PaymentMethodOptions />
|
2020-03-26 11:11:46 +00:00
|
|
|
</>
|
|
|
|
);
|
2020-01-06 22:28:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default PaymentMethods;
|