mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
Implements custom checkout along with ordercloud provider
This commit is contained in:
35
framework/ordercloud/api/endpoints/checkout/get-checkout.ts
Normal file
35
framework/ordercloud/api/endpoints/checkout/get-checkout.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { CheckoutEndpoint } from '.'
|
||||
|
||||
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||
res,
|
||||
body: {cartId},
|
||||
config: { restFetch },
|
||||
}) => {
|
||||
// Return an error if no item is present
|
||||
if (!cartId) {
|
||||
return res.status(400).json({
|
||||
data: null,
|
||||
errors: [{ message: 'Missing cookie' }],
|
||||
})
|
||||
}
|
||||
|
||||
// Register credit card
|
||||
const payments = await restFetch('GET', `/orders/Outgoing/${cartId}/payments`).then(
|
||||
(response: {Items: unknown[]}) => response.Items
|
||||
)
|
||||
|
||||
const address = await restFetch('GET', `/orders/Outgoing/${cartId}`).then(
|
||||
(response: {ShippingAddressID: string}) => response.ShippingAddressID
|
||||
)
|
||||
|
||||
// Return cart and errors
|
||||
res.status(200).json({
|
||||
data: {
|
||||
hasPayment: payments.length > 0,
|
||||
hasShipping: Boolean(address)
|
||||
},
|
||||
errors: []
|
||||
})
|
||||
}
|
||||
|
||||
export default getCheckout
|
Reference in New Issue
Block a user