mirror of
https://github.com/vercel/commerce.git
synced 2025-03-27 15:55:54 +00:00
* Implement custom checkout core * Fix elements on core * Add files to providers * Adapt providers * Update types * Update shopify file * Format files
31 lines
866 B
TypeScript
31 lines
866 B
TypeScript
import { CommerceAPI, createEndpoint, GetAPISchema } from '@commerce/api'
|
|
import { CheckoutSchema } from '@commerce/types/checkout'
|
|
import { SWELL_CHECKOUT_URL_COOKIE } from '../../../const'
|
|
import checkoutEndpoint from '@commerce/api/endpoints/checkout'
|
|
|
|
const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
|
|
req,
|
|
res,
|
|
config,
|
|
}) => {
|
|
const { cookies } = req
|
|
const checkoutUrl = cookies[SWELL_CHECKOUT_URL_COOKIE]
|
|
|
|
if (checkoutUrl) {
|
|
res.redirect(checkoutUrl)
|
|
} else {
|
|
res.redirect('/cart')
|
|
}
|
|
}
|
|
export const handlers: CheckoutEndpoint['handlers'] = { submitCheckout }
|
|
|
|
export type CheckoutAPI = GetAPISchema<CommerceAPI, CheckoutSchema>
|
|
export type CheckoutEndpoint = CheckoutAPI['endpoint']
|
|
|
|
const checkoutApi = createEndpoint<CheckoutAPI>({
|
|
handler: checkoutEndpoint,
|
|
handlers,
|
|
})
|
|
|
|
export default checkoutApi
|