mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Use token at checkout
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import type { CheckoutEndpoint } from '.'
|
import type { CheckoutEndpoint } from '.'
|
||||||
|
|
||||||
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||||
|
req,
|
||||||
res,
|
res,
|
||||||
body: { cartId },
|
body: { cartId },
|
||||||
config: { restBuyerFetch },
|
config: { restBuyerFetch, tokenCookie },
|
||||||
}) => {
|
}) => {
|
||||||
// Return an error if no item is present
|
// Return an error if no item is present
|
||||||
if (!cartId) {
|
if (!cartId) {
|
||||||
@@ -13,15 +14,22 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get token from cookies
|
||||||
|
const token = req.cookies[tokenCookie]
|
||||||
|
|
||||||
// Register credit card
|
// Register credit card
|
||||||
const payments = await restBuyerFetch(
|
const payments = await restBuyerFetch(
|
||||||
'GET',
|
'GET',
|
||||||
`/orders/Outgoing/${cartId}/payments`
|
`/orders/Outgoing/${cartId}/payments`,
|
||||||
|
null,
|
||||||
|
{ token }
|
||||||
).then((response: { Items: unknown[] }) => response.Items)
|
).then((response: { Items: unknown[] }) => response.Items)
|
||||||
|
|
||||||
const address = await restBuyerFetch(
|
const address = await restBuyerFetch(
|
||||||
'GET',
|
'GET',
|
||||||
`/orders/Outgoing/${cartId}`
|
`/orders/Outgoing/${cartId}`,
|
||||||
|
null,
|
||||||
|
{ token }
|
||||||
).then(
|
).then(
|
||||||
(response: { ShippingAddressID: string }) => response.ShippingAddressID
|
(response: { ShippingAddressID: string }) => response.ShippingAddressID
|
||||||
)
|
)
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
import type { CheckoutEndpoint } from '.'
|
import type { CheckoutEndpoint } from '.'
|
||||||
|
|
||||||
const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
|
const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
|
||||||
|
req,
|
||||||
res,
|
res,
|
||||||
body: { cartId },
|
body: { cartId },
|
||||||
config: { restBuyerFetch },
|
config: { restBuyerFetch, tokenCookie },
|
||||||
}) => {
|
}) => {
|
||||||
// Return an error if no item is present
|
// Return an error if no item is present
|
||||||
if (!cartId) {
|
if (!cartId) {
|
||||||
@@ -13,8 +14,16 @@ const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get token from cookies
|
||||||
|
const token = req.cookies[tokenCookie]
|
||||||
|
|
||||||
// Submit order
|
// Submit order
|
||||||
await restBuyerFetch('POST', `/orders/Outgoing/${cartId}/submit`, {})
|
await restBuyerFetch(
|
||||||
|
'POST',
|
||||||
|
`/orders/Outgoing/${cartId}/submit`,
|
||||||
|
{},
|
||||||
|
{ token }
|
||||||
|
)
|
||||||
|
|
||||||
// Return cart and errors
|
// Return cart and errors
|
||||||
res.status(200).json({ data: null, errors: [] })
|
res.status(200).json({ data: null, errors: [] })
|
||||||
|
Reference in New Issue
Block a user