shopify checkout redirect & api handler

This commit is contained in:
cond0r
2021-02-04 17:18:33 +02:00
parent 2acc21164b
commit b0d8ae565d
11 changed files with 128 additions and 17 deletions

View File

@@ -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, {}, {})