diff options
| author | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-08 08:14:29 +0100 |
|---|---|---|
| committer | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-08 08:18:27 +0100 |
| commit | c3950f3de28e7ac1e677f4006521ffbed5db4ee0 (patch) | |
| tree | c5f69297c6f289ec46f95bcd7df65001474eee47 /api-src/order.ts | |
| parent | 4a5bd8bf5e3c6017794d7c5c7eb4f2794a902245 (diff) | |
Renames createPaypalOrder -> create-paypal-order
Diffstat (limited to 'api-src/order.ts')
| -rw-r--r-- | api-src/order.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/api-src/order.ts b/api-src/order.ts new file mode 100644 index 0000000..8937d04 --- /dev/null +++ b/api-src/order.ts @@ -0,0 +1,30 @@ +import type { VercelRequest, VercelResponse } from '@vercel/node'; +import type Order from './_Order'; +import { paypalCreateOrder } from './_paypal'; + +export default async function handler(request: VercelRequest, response: VercelResponse) { + const { productDescription, shortDescription, totalPrice }: Partial<Order> = request.body; + + if (request.method !== 'POST') { + console.warn('Method was not POST. Method was ' + request.method); + response.status(404); + return; + } + + if (!productDescription) { + response.status(400).send('Expected body to contain productDescription, but none provided.'); + } else if (!shortDescription) { + response.status(400).send('Expected body to contain shortDescription, but none provided.'); + } else if (!totalPrice) { + response.status(400).send('Expected body to contain totalPrice, but none provided.'); + } else { + try { + const paypalResponse = await paypalCreateOrder({ productDescription, shortDescription, totalPrice }); + response.status(201).json({ + orderId: paypalResponse.id, + }); + } catch (err) { + response.status(500).send(`Internal server error. ${err}`); + } + } +} |
