2020-08-20 14:14:12 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-09-18 18:39:32 +00:00
|
|
|
import {
|
|
|
|
useEmitResponse,
|
|
|
|
useExpressPaymentMethods,
|
2021-04-08 12:31:12 +00:00
|
|
|
} from '@woocommerce/base-context/hooks';
|
2021-06-16 12:44:40 +00:00
|
|
|
import {
|
2022-04-08 12:11:50 +00:00
|
|
|
StoreNoticesContainer,
|
2021-06-16 12:44:40 +00:00
|
|
|
usePaymentMethodDataContext,
|
|
|
|
} from '@woocommerce/base-context';
|
|
|
|
import LoadingMask from '@woocommerce/base-components/loading-mask';
|
2022-06-10 16:33:15 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
|
|
|
import { CHECKOUT_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();
|
2020-09-18 18:39:32 +00:00
|
|
|
const { noticeContexts } = useEmitResponse();
|
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(),
|
|
|
|
};
|
|
|
|
} );
|
2021-06-16 12:44:40 +00:00
|
|
|
const { currentStatus: paymentStatus } = usePaymentMethodDataContext();
|
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 ||
|
|
|
|
paymentStatus.isDoingExpressPayment
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<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-09-12 08:39:26 +00:00
|
|
|
{ __( 'Any', 'woo-gutenberg-products-block' ) }
|
2020-08-20 14:14:12 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CartExpressPayment;
|