mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 12:24:18 +00:00
Use token at checkout
This commit is contained in:
parent
19a5e22302
commit
8c2212a580
@ -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
|
||||
)
|
||||
|
@ -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: [] })
|
||||
|
Loading…
x
Reference in New Issue
Block a user