mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Implements custom checkout along with ordercloud provider
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import type { CustomerAddressEndpoint } from '.'
|
||||
|
||||
const addItem: CustomerAddressEndpoint['handlers']['addItem'] = async ({
|
||||
res,
|
||||
body: { item, cartId },
|
||||
config: { restFetch },
|
||||
}) => {
|
||||
// Return an error if no item is present
|
||||
if (!item) {
|
||||
return res.status(400).json({
|
||||
data: null,
|
||||
errors: [{ message: 'Missing item' }],
|
||||
})
|
||||
}
|
||||
|
||||
// Return an error if no item is present
|
||||
if (!cartId) {
|
||||
return res.status(400).json({
|
||||
data: null,
|
||||
errors: [{ message: 'Cookie not found' }],
|
||||
})
|
||||
}
|
||||
|
||||
// Register address
|
||||
const address = await restFetch('POST', `/me/addresses`, {
|
||||
"AddressName": "main address",
|
||||
"CompanyName": item.company,
|
||||
"FirstName": item.firstName,
|
||||
"LastName": item.lastName,
|
||||
"Street1": item.streetNumber,
|
||||
"Street2": item.streetNumber,
|
||||
"City": item.city,
|
||||
"State": item.city,
|
||||
"Zip": item.zipCode,
|
||||
"Country": item.country.slice(0, 2).toLowerCase(),
|
||||
"Shipping": true
|
||||
}).then(
|
||||
(response: {ID: string}) => response.ID
|
||||
)
|
||||
|
||||
// Assign address to order
|
||||
await restFetch('PATCH', `/orders/Outgoing/${cartId}`, {
|
||||
ShippingAddressID: address
|
||||
})
|
||||
|
||||
return res.status(200).json({ data: null, errors: [] })
|
||||
}
|
||||
|
||||
export default addItem
|
Reference in New Issue
Block a user