diff --git a/framework/ordercloud/api/endpoints/checkout/get-checkout.ts b/framework/ordercloud/api/endpoints/checkout/get-checkout.ts index b46e64ba2..c0ab1a40d 100644 --- a/framework/ordercloud/api/endpoints/checkout/get-checkout.ts +++ b/framework/ordercloud/api/endpoints/checkout/get-checkout.ts @@ -1,9 +1,10 @@ import type { CheckoutEndpoint } from '.' const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({ + req, res, body: { cartId }, - config: { restBuyerFetch }, + config: { restBuyerFetch, tokenCookie }, }) => { // Return an error if no item is present if (!cartId) { @@ -13,15 +14,22 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({ }) } + // Get token from cookies + const token = req.cookies[tokenCookie] + // Register credit card const payments = await restBuyerFetch( 'GET', - `/orders/Outgoing/${cartId}/payments` + `/orders/Outgoing/${cartId}/payments`, + null, + { token } ).then((response: { Items: unknown[] }) => response.Items) const address = await restBuyerFetch( 'GET', - `/orders/Outgoing/${cartId}` + `/orders/Outgoing/${cartId}`, + null, + { token } ).then( (response: { ShippingAddressID: string }) => response.ShippingAddressID ) diff --git a/framework/ordercloud/api/endpoints/checkout/submit-checkout.ts b/framework/ordercloud/api/endpoints/checkout/submit-checkout.ts index 80cce6fbd..8cd9be5e4 100644 --- a/framework/ordercloud/api/endpoints/checkout/submit-checkout.ts +++ b/framework/ordercloud/api/endpoints/checkout/submit-checkout.ts @@ -1,9 +1,10 @@ import type { CheckoutEndpoint } from '.' const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({ + req, res, body: { cartId }, - config: { restBuyerFetch }, + config: { restBuyerFetch, tokenCookie }, }) => { // Return an error if no item is present if (!cartId) { @@ -13,8 +14,16 @@ const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({ }) } + // Get token from cookies + const token = req.cookies[tokenCookie] + // Submit order - await restBuyerFetch('POST', `/orders/Outgoing/${cartId}/submit`, {}) + await restBuyerFetch( + 'POST', + `/orders/Outgoing/${cartId}/submit`, + {}, + { token } + ) // Return cart and errors res.status(200).json({ data: null, errors: [] })