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
|
|
|
useCheckoutContext,
|
|
|
|
usePaymentMethodDataContext,
|
|
|
|
} from '@woocommerce/base-context';
|
|
|
|
import LoadingMask from '@woocommerce/base-components/loading-mask';
|
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,
|
|
|
|
} = useCheckoutContext();
|
|
|
|
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 */ }
|
|
|
|
{ __( 'Or', 'woo-gutenberg-products-block' ) }
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CartExpressPayment;
|