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';
|
2020-11-20 15:13:35 +00:00
|
|
|
import { CustomerDataProvider } from '../customer';
|
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-30 09:52:36 +00:00
|
|
|
* @param {Object} props Incoming props for the provider.
|
|
|
|
* @param {Object} props.children The children being wrapped.
|
2020-11-16 13:12:56 +00:00
|
|
|
* @param {boolean} [props.isCart] Whether it's rendered in the Cart
|
|
|
|
* component.
|
2020-04-30 09:52:36 +00:00
|
|
|
* @param {string} [props.redirectUrl] Initialize what the checkout will
|
|
|
|
* redirect to after successful
|
|
|
|
* submit.
|
2020-03-10 13:39:21 +00:00
|
|
|
*/
|
2020-11-16 13:12:56 +00:00
|
|
|
export const CheckoutProvider = ( {
|
|
|
|
children,
|
|
|
|
isCart = false,
|
|
|
|
redirectUrl,
|
|
|
|
} ) => {
|
2020-03-10 13:39:21 +00:00
|
|
|
return (
|
2020-11-16 13:12:56 +00:00
|
|
|
<CheckoutStateProvider redirectUrl={ redirectUrl } isCart={ isCart }>
|
2020-11-20 15:13:35 +00:00
|
|
|
<CustomerDataProvider>
|
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-11-20 15:13:35 +00:00
|
|
|
</CustomerDataProvider>
|
2020-04-01 09:27:53 +00:00
|
|
|
</CheckoutStateProvider>
|
2020-03-10 13:39:21 +00:00
|
|
|
);
|
|
|
|
};
|