2020-01-06 22:28:09 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
useExpressPaymentMethods,
|
2020-03-11 10:50:12 +00:00
|
|
|
usePaymentMethodInterface,
|
2020-01-06 22:28:09 +00:00
|
|
|
} from '@woocommerce/base-hooks';
|
2020-03-10 16:35:30 +00:00
|
|
|
import { cloneElement, isValidElement } from '@wordpress/element';
|
|
|
|
import { useCheckoutContext } from '@woocommerce/base-context';
|
2020-01-06 22:28:09 +00:00
|
|
|
|
|
|
|
const ExpressPaymentMethods = () => {
|
2020-03-10 16:35:30 +00:00
|
|
|
const { isEditor } = useCheckoutContext();
|
2020-03-11 10:50:12 +00:00
|
|
|
const paymentMethodInterface = usePaymentMethodInterface();
|
2020-01-06 22:28:09 +00:00
|
|
|
// not implementing isInitialized here because it's utilized further
|
|
|
|
// up in the tree for express payment methods. We won't even get here if
|
|
|
|
// there's no payment methods after initialization.
|
|
|
|
const { paymentMethods } = useExpressPaymentMethods();
|
2020-03-11 10:50:12 +00:00
|
|
|
const paymentMethodIds = Object.keys( paymentMethods );
|
2020-01-06 22:28:09 +00:00
|
|
|
const content =
|
2020-03-11 10:50:12 +00:00
|
|
|
paymentMethodIds.length > 0 ? (
|
|
|
|
paymentMethodIds.map( ( id ) => {
|
2020-03-10 16:35:30 +00:00
|
|
|
const expressPaymentMethod = isEditor
|
2020-03-11 10:50:12 +00:00
|
|
|
? paymentMethods[ id ].edit
|
|
|
|
: paymentMethods[ id ].activeContent;
|
2020-03-10 16:35:30 +00:00
|
|
|
return isValidElement( expressPaymentMethod ) ? (
|
2020-03-11 10:50:12 +00:00
|
|
|
<li key={ id } id={ `express-payment-method-${ id }` }>
|
2020-01-06 22:28:09 +00:00
|
|
|
{ cloneElement( expressPaymentMethod, {
|
2020-03-11 10:50:12 +00:00
|
|
|
...paymentMethodInterface,
|
2020-01-06 22:28:09 +00:00
|
|
|
} ) }
|
|
|
|
</li>
|
2020-03-10 16:35:30 +00:00
|
|
|
) : null;
|
2020-01-06 22:28:09 +00:00
|
|
|
} )
|
|
|
|
) : (
|
|
|
|
<li key="noneRegistered">No registered Payment Methods</li>
|
|
|
|
);
|
|
|
|
return (
|
2020-03-09 15:49:01 +00:00
|
|
|
<ul className="wc-block-component-express-checkout-payment-event-buttons">
|
2020-01-06 22:28:09 +00:00
|
|
|
{ content }
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ExpressPaymentMethods;
|