2020-03-26 13:31:09 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
|
2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { PaymentMethodDataProvider } from '../payment-methods';
|
2020-03-26 13:31:09 +00:00
|
|
|
import { ShippingDataProvider } from '../shipping';
|
|
|
|
import { BillingDataProvider } from '../billing';
|
2020-04-01 09:27:53 +00:00
|
|
|
import { CheckoutStateProvider } from '../checkout-state';
|
|
|
|
import CheckoutProcessor from './processor';
|
2020-03-10 13:39:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checkout provider
|
|
|
|
* This wraps the checkout and provides an api interface for the checkout to
|
|
|
|
* children via various hooks.
|
|
|
|
*
|
2020-04-01 09:27:53 +00:00
|
|
|
* @param {Object} props Incoming props for the provider.
|
|
|
|
* @param {Object} props.children The children being wrapped.
|
|
|
|
* @param {string} [props.redirectUrl] Initialize what the checkout will
|
|
|
|
* redirect to after successful
|
|
|
|
* submit.
|
|
|
|
* @param {string} [props.submitLabel] What will be used for the checkout
|
|
|
|
* submit button label.
|
2020-03-10 13:39:21 +00:00
|
|
|
*/
|
|
|
|
export const CheckoutProvider = ( {
|
|
|
|
children,
|
|
|
|
redirectUrl,
|
2020-04-01 09:27:53 +00:00
|
|
|
submitLabel = __( 'Place Order', 'woo-gutenberg-products-block' ),
|
2020-03-10 13:39:21 +00:00
|
|
|
} ) => {
|
|
|
|
return (
|
2020-04-01 09:27:53 +00:00
|
|
|
<CheckoutStateProvider
|
|
|
|
redirectUrl={ redirectUrl }
|
|
|
|
isCart={ false }
|
|
|
|
submitLabel={ submitLabel }
|
|
|
|
>
|
2020-03-26 13:31:09 +00:00
|
|
|
<BillingDataProvider>
|
2020-04-08 16:36:04 +00:00
|
|
|
<ShippingDataProvider>
|
2020-04-15 00:05:01 +00:00
|
|
|
<PaymentMethodDataProvider>
|
2020-03-26 13:31:09 +00:00
|
|
|
{ children }
|
|
|
|
<CheckoutProcessor />
|
2020-04-08 16:36:04 +00:00
|
|
|
</PaymentMethodDataProvider>
|
|
|
|
</ShippingDataProvider>
|
2020-03-26 13:31:09 +00:00
|
|
|
</BillingDataProvider>
|
2020-04-01 09:27:53 +00:00
|
|
|
</CheckoutStateProvider>
|
2020-03-10 13:39:21 +00:00
|
|
|
);
|
|
|
|
};
|