From ed763381f59420a96428247812a6dab52b0102e0 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Mon, 25 Jan 2021 17:06:06 +0100 Subject: [PATCH] Dummy checkout page --- framework/vendure/api/checkout.ts | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 framework/vendure/api/checkout.ts diff --git a/framework/vendure/api/checkout.ts b/framework/vendure/api/checkout.ts new file mode 100644 index 000000000..6dd565e51 --- /dev/null +++ b/framework/vendure/api/checkout.ts @@ -0,0 +1,63 @@ +import { BigcommerceConfig, getConfig } from '../../bigcommerce/api' +import { NextApiHandler } from 'next' + +const checkoutApi= async (req: any, res: any, config: any) => { + try { + // TODO: make the embedded checkout work too! + const html = ` + + + + + + Checkout + + +
+

Checkout not implemented :(

+
+ + + ` + + res.status(200) + res.setHeader('Content-Type', 'text/html') + res.write(html) + res.end() + } catch (error) { + console.error(error) + + const message = 'An unexpected error ocurred' + + res.status(500).json({ data: null, errors: [{ message }] }) + } +} + +export function createApiHandler< + T = any, + H = {}, + Options extends {} = {} +>( + handler: any, + handlers: H, + defaultOptions: Options +) { + return function getApiHandler({ + config, + operations, + options, + }: { + config?: BigcommerceConfig + operations?: Partial + options?: Options extends {} ? Partial : never + } = {}): NextApiHandler { + const ops = { ...operations, ...handlers } + const opts = { ...defaultOptions, ...options } + + return function apiHandler(req, res) { + return handler(req, res, getConfig(config), ops, opts) + } + } +} + +export default createApiHandler(checkoutApi, {}, {})