mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
shopify checkout redirect & api handler
This commit is contained in:
@@ -1,5 +1,23 @@
|
||||
const getCheckout = async (req: any, res: any, config: any): Promise<any> => {
|
||||
res.end()
|
||||
import isAllowedMethod from '../utils/is-allowed-method'
|
||||
import createApiHandler, {
|
||||
ShopifyApiHandler,
|
||||
} from '../utils/create-api-handler'
|
||||
|
||||
import { SHOPIFY_CHECKOUT_URL_COOKIE } from '@framework/const'
|
||||
|
||||
const METHODS = ['GET']
|
||||
|
||||
const checkoutApi: ShopifyApiHandler<any> = async (req, res) => {
|
||||
if (!isAllowedMethod(req, res, METHODS)) return
|
||||
|
||||
const { cookies } = req
|
||||
const checkoutUrl = cookies[SHOPIFY_CHECKOUT_URL_COOKIE]
|
||||
|
||||
if (checkoutUrl) {
|
||||
res.redirect(checkoutUrl)
|
||||
} else {
|
||||
res.redirect('/cart')
|
||||
}
|
||||
}
|
||||
|
||||
export default getCheckout
|
||||
export default createApiHandler(checkoutApi, {}, {})
|
||||
|
Reference in New Issue
Block a user