2020-01-06 22:28:09 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-09-18 10:27:54 +00:00
|
|
|
import {
|
|
|
|
useEmitResponse,
|
|
|
|
useExpressPaymentMethods,
|
2021-04-08 12:31:12 +00:00
|
|
|
} from '@woocommerce/base-context/hooks';
|
2020-09-18 10:27:54 +00:00
|
|
|
import {
|
2022-04-08 12:11:50 +00:00
|
|
|
StoreNoticesContainer,
|
2021-06-16 12:44:40 +00:00
|
|
|
useCheckoutContext,
|
|
|
|
usePaymentMethodDataContext,
|
2020-09-18 10:27:54 +00:00
|
|
|
useEditorContext,
|
|
|
|
} from '@woocommerce/base-context';
|
2020-06-05 10:00:19 +00:00
|
|
|
import Title from '@woocommerce/base-components/title';
|
2021-06-16 12:44:40 +00:00
|
|
|
import LoadingMask from '@woocommerce/base-components/loading-mask';
|
2021-04-22 11:37:27 +00:00
|
|
|
import { CURRENT_USER_IS_ADMIN } from '@woocommerce/settings';
|
2020-01-06 22:28:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-08-20 14:14:12 +00:00
|
|
|
import ExpressPaymentMethods from '../express-payment-methods';
|
2020-03-27 20:56:48 +00:00
|
|
|
import './style.scss';
|
2020-01-06 22:28:09 +00:00
|
|
|
|
2020-08-20 14:14:12 +00:00
|
|
|
const CheckoutExpressPayment = () => {
|
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
|
|
|
const { paymentMethods, isInitialized } = useExpressPaymentMethods();
|
2020-09-18 10:27:54 +00:00
|
|
|
const { isEditor } = useEditorContext();
|
|
|
|
const { noticeContexts } = useEmitResponse();
|
2020-08-20 14:14:12 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
! isInitialized ||
|
|
|
|
( isInitialized && Object.keys( paymentMethods ).length === 0 )
|
|
|
|
) {
|
2020-09-18 10:27:54 +00:00
|
|
|
// Make sure errors are shown in the editor and for admins. For example,
|
|
|
|
// when a payment method fails to register.
|
|
|
|
if ( isEditor || CURRENT_USER_IS_ADMIN ) {
|
|
|
|
return (
|
2022-04-08 12:11:50 +00:00
|
|
|
<StoreNoticesContainer
|
2020-09-18 10:27:54 +00:00
|
|
|
context={ noticeContexts.EXPRESS_PAYMENTS }
|
2022-04-08 12:11:50 +00:00
|
|
|
/>
|
2020-09-18 10:27:54 +00:00
|
|
|
);
|
|
|
|
}
|
2020-08-20 14:14:12 +00:00
|
|
|
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-01-06 22:28:09 +00:00
|
|
|
return (
|
2020-03-09 15:49:01 +00:00
|
|
|
<>
|
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--checkout">
|
|
|
|
<div className="wc-block-components-express-payment__title-container">
|
|
|
|
<Title
|
|
|
|
className="wc-block-components-express-payment__title"
|
|
|
|
headingLevel="2"
|
|
|
|
>
|
2020-08-20 14:14:12 +00:00
|
|
|
{ __(
|
2021-06-16 12:44:40 +00:00
|
|
|
'Express checkout',
|
2020-08-20 14:14:12 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2021-06-16 12:44:40 +00:00
|
|
|
</Title>
|
|
|
|
</div>
|
|
|
|
<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
|
|
|
/>
|
|
|
|
<p>
|
|
|
|
{ __(
|
|
|
|
'In a hurry? Use one of our express checkout options:',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
<ExpressPaymentMethods />
|
2021-06-16 12:44:40 +00:00
|
|
|
</div>
|
2020-03-09 15:49:01 +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--checkout">
|
2020-03-09 15:49:01 +00:00
|
|
|
{ __( 'Or continue below', 'woo-gutenberg-products-block' ) }
|
|
|
|
</div>
|
|
|
|
</>
|
2020-01-06 22:28:09 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-08-20 14:14:12 +00:00
|
|
|
export default CheckoutExpressPayment;
|