diff options
| author | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-07 20:46:07 +0100 |
|---|---|---|
| committer | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-07 20:50:17 +0100 |
| commit | 48f6b38c333fdaf57fe418c6e6a5fc4bfb928921 (patch) | |
| tree | 2f13763840bd55545b5ce7085517ce369dbf1bef /api/createPaypalOrder.ts | |
| parent | 1ec33f27f5bff2b96c80b954b53a62951b6cd354 (diff) | |
Pre-compiles api
Diffstat (limited to 'api/createPaypalOrder.ts')
| -rw-r--r-- | api/createPaypalOrder.ts | 34 |
1 files changed, 0 insertions, 34 deletions
diff --git a/api/createPaypalOrder.ts b/api/createPaypalOrder.ts deleted file mode 100644 index c0053d4..0000000 --- a/api/createPaypalOrder.ts +++ /dev/null @@ -1,34 +0,0 @@ -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') { - 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 }); - - if (paypalResponse.ok) { - response.status(200).json({ - orderId: paypalResponse.id, - }); - } else { - throw new Error(`PayPal returned ${paypalResponse.statusCode} ${paypalResponse.statusMessage}`); - } - } catch (err) { - response.status(500).send(`Internal server error. ${err}`); - } - } -} |
