2020-08-20 14:14:12 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2022-07-08 05:53:24 +00:00
|
|
|
import { useExpressPaymentMethods } from '@woocommerce/base-context/hooks';
|
2022-11-17 13:33:58 +00:00
|
|
|
import { noticeContexts } from '@woocommerce/base-context';
|
|
|
|
import { StoreNoticesContainer } from '@woocommerce/blocks-checkout';
|
2021-06-16 12:44:40 +00:00
|
|
|
import LoadingMask from '@woocommerce/base-components/loading-mask';
|
2022-06-10 16:33:15 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
2022-10-06 12:46:46 +00:00
|
|
|
import { CHECKOUT_STORE_KEY, PAYMENT_STORE_KEY } from '@woocommerce/block-data';
|
2020-08-20 14:14:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ExpressPaymentMethods from '../express-payment-methods';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
const CartExpressPayment = () => {
|
|
|
|
const { paymentMethods, isInitialized } = useExpressPaymentMethods();
|
2021-06-16 12:44:40 +00:00
|
|
|
const {
|
|
|
|
isCalculating,
|
|
|
|
isProcessing,
|
|
|
|
isAfterProcessing,
|
|
|
|
isBeforeProcessing,
|
|
|
|
isComplete,
|
|
|
|
hasError,
|
2022-06-10 16:33:15 +00:00
|
|
|
} = useSelect( ( select ) => {
|
|
|
|
const store = select( CHECKOUT_STORE_KEY );
|
|
|
|
return {
|
|
|
|
isCalculating: store.isCalculating(),
|
|
|
|
isProcessing: store.isProcessing(),
|
|
|
|
isAfterProcessing: store.isAfterProcessing(),
|
|
|
|
isBeforeProcessing: store.isBeforeProcessing(),
|
|
|
|
isComplete: store.isComplete(),
|
|
|
|
hasError: store.hasError(),
|
|
|
|
};
|
|
|
|
} );
|
2022-11-10 16:15:31 +00:00
|
|
|
const isExpressPaymentMethodActive = useSelect( ( select ) =>
|
|
|
|
select( PAYMENT_STORE_KEY ).isExpressPaymentMethodActive()
|
|
|
|
);
|
2020-08-20 14:14:12 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
! isInitialized ||
|
|
|
|
( isInitialized && Object.keys( paymentMethods ).length === 0 )
|
|
|
|
) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-16 12:44:40 +00:00
|
|
|
// Set loading state for express payment methods when payment or checkout is in progress.
|
|
|
|
const checkoutProcessing =
|
|
|
|
isProcessing ||
|
|
|
|
isAfterProcessing ||
|
|
|
|
isBeforeProcessing ||
|
|
|
|
( isComplete && ! hasError );
|
|
|
|
|
2020-08-20 14:14:12 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-06-16 12:44:40 +00:00
|
|
|
<LoadingMask
|
|
|
|
isLoading={
|
|
|
|
isCalculating ||
|
|
|
|
checkoutProcessing ||
|
2022-11-10 16:15:31 +00:00
|
|
|
isExpressPaymentMethodActive
|
2021-06-16 12:44:40 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<div className="wc-block-components-express-payment wc-block-components-express-payment--cart">
|
|
|
|
<div className="wc-block-components-express-payment__content">
|
2022-04-08 12:11:50 +00:00
|
|
|
<StoreNoticesContainer
|
2021-06-16 12:44:40 +00:00
|
|
|
context={ noticeContexts.EXPRESS_PAYMENTS }
|
2022-04-08 12:11:50 +00:00
|
|
|
/>
|
|
|
|
<ExpressPaymentMethods />
|
2021-06-16 12:44:40 +00:00
|
|
|
</div>
|
2020-08-20 14:14:12 +00:00
|
|
|
</div>
|
2021-06-16 12:44:40 +00:00
|
|
|
</LoadingMask>
|
2020-08-20 14:14:12 +00:00
|
|
|
<div className="wc-block-components-express-payment-continue-rule wc-block-components-express-payment-continue-rule--cart">
|
|
|
|
{ /* translators: Shown in the Cart block between the express payment methods and the Proceed to Checkout button */ }
|
2022-10-11 16:07:23 +00:00
|
|
|
{ __( 'Or', 'woo-gutenberg-products-block' ) }
|
2020-08-20 14:14:12 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CartExpressPayment;
|