2020-01-06 22:28:09 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-10-05 11:59:20 +00:00
|
|
|
import { usePaymentMethods } from '@woocommerce/base-hooks';
|
|
|
|
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 = () => {
|
2020-04-09 15:22:34 +00:00
|
|
|
const {
|
|
|
|
customerPaymentMethods = {},
|
2020-09-29 08:15:45 +00:00
|
|
|
paymentMethodData,
|
2020-04-09 15:22:34 +00:00
|
|
|
} = usePaymentMethodDataContext();
|
2020-01-06 22:28:09 +00:00
|
|
|
const { isInitialized, paymentMethods } = usePaymentMethods();
|
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-05 11:59:20 +00:00
|
|
|
return Object.keys( customerPaymentMethods ).length > 0 &&
|
|
|
|
paymentMethodData.isSavedToken ? (
|
|
|
|
<SavedPaymentMethodOptions />
|
|
|
|
) : (
|
2020-03-26 11:11:46 +00:00
|
|
|
<>
|
2020-10-05 11:59:20 +00:00
|
|
|
<SavedPaymentMethodOptions />
|
|
|
|
<PaymentMethodOptions />
|
2020-03-26 11:11:46 +00:00
|
|
|
</>
|
|
|
|
);
|
2020-01-06 22:28:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default PaymentMethods;
|