2020-01-06 22:28:09 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2022-11-17 13:33:58 +00:00
|
|
|
import { useEditorContext, noticeContexts } from '@woocommerce/base-context';
|
|
|
|
import { StoreNoticesContainer } from '@woocommerce/blocks-checkout';
|
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';
|
2022-10-06 12:46:46 +00:00
|
|
|
import { CHECKOUT_STORE_KEY, PAYMENT_STORE_KEY } from '@woocommerce/block-data';
|
2022-06-10 16:33:15 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
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,
|
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-07-08 05:53:24 +00:00
|
|
|
const {
|
|
|
|
availableExpressPaymentMethods,
|
|
|
|
expressPaymentMethodsInitialized,
|
2022-11-10 16:15:31 +00:00
|
|
|
isExpressPaymentMethodActive,
|
2022-07-08 05:53:24 +00:00
|
|
|
} = useSelect( ( select ) => {
|
2022-10-06 12:46:46 +00:00
|
|
|
const store = select( PAYMENT_STORE_KEY );
|
2022-07-08 05:53:24 +00:00
|
|
|
return {
|
|
|
|
availableExpressPaymentMethods:
|
|
|
|
store.getAvailableExpressPaymentMethods(),
|
|
|
|
expressPaymentMethodsInitialized:
|
|
|
|
store.expressPaymentMethodsInitialized(),
|
2022-11-10 16:15:31 +00:00
|
|
|
isExpressPaymentMethodActive: store.isExpressPaymentMethodActive(),
|
2022-07-08 05:53:24 +00:00
|
|
|
};
|
|
|
|
} );
|
2020-09-18 10:27:54 +00:00
|
|
|
const { isEditor } = useEditorContext();
|
2020-08-20 14:14:12 +00:00
|
|
|
|
|
|
|
if (
|
2022-07-08 05:53:24 +00:00
|
|
|
! expressPaymentMethodsInitialized ||
|
|
|
|
( expressPaymentMethodsInitialized &&
|
|
|
|
Object.keys( availableExpressPaymentMethods ).length === 0 )
|
2020-08-20 14:14:12 +00:00
|
|
|
) {
|
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 ||
|
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--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
|
|
|
/>
|
|
|
|
<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;
|