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,
|
|
|
|
} from '@woocommerce/base-hooks';
|
|
|
|
import {
|
|
|
|
StoreNoticesProvider,
|
|
|
|
useEditorContext,
|
|
|
|
} from '@woocommerce/base-context';
|
2020-06-05 10:00:19 +00:00
|
|
|
import Title from '@woocommerce/base-components/title';
|
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-09-18 10:27:54 +00:00
|
|
|
import { CURRENT_USER_IS_ADMIN } from '@woocommerce/block-settings';
|
2020-01-06 22:28:09 +00:00
|
|
|
|
2020-08-20 14:14:12 +00:00
|
|
|
const CheckoutExpressPayment = () => {
|
|
|
|
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 (
|
|
|
|
<StoreNoticesProvider
|
|
|
|
context={ noticeContexts.EXPRESS_PAYMENTS }
|
|
|
|
></StoreNoticesProvider>
|
|
|
|
);
|
|
|
|
}
|
2020-08-20 14:14:12 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-01-06 22:28:09 +00:00
|
|
|
return (
|
2020-03-09 15:49:01 +00:00
|
|
|
<>
|
2020-08-20 14:14:12 +00:00
|
|
|
<div className="wc-block-components-express-payment wc-block-components-express-payment--checkout">
|
|
|
|
<div className="wc-block-components-express-payment__title-container">
|
2020-06-15 11:39:46 +00:00
|
|
|
<Title
|
2020-08-20 14:14:12 +00:00
|
|
|
className="wc-block-components-express-payment__title"
|
2020-06-15 11:39:46 +00:00
|
|
|
headingLevel="2"
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'Express checkout',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</Title>
|
|
|
|
</div>
|
2020-08-20 14:14:12 +00:00
|
|
|
<div className="wc-block-components-express-payment__content">
|
2020-09-18 10:27:54 +00:00
|
|
|
<StoreNoticesProvider
|
|
|
|
context={ noticeContexts.EXPRESS_PAYMENTS }
|
|
|
|
>
|
2020-08-20 14:14:12 +00:00
|
|
|
<p>
|
|
|
|
{ __(
|
|
|
|
'In a hurry? Use one of our express checkout options below:',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
<ExpressPaymentMethods />
|
2020-04-06 12:18:35 +00:00
|
|
|
</StoreNoticesProvider>
|
2020-03-09 15:49:01 +00:00
|
|
|
</div>
|
2020-01-06 22:28:09 +00:00
|
|
|
</div>
|
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;
|