summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2023-08-05 21:37:27 +0100
committerJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2023-08-06 22:40:07 +0100
commit925f6de56ef43013583a48dbc49a350ee84cdb3e (patch)
tree865f859ffdbeb488f95a8136d0e566c648a7768f /api
parent59b0bf5e441a9b6352962d2b50220c7c1be1ea41 (diff)
Defines createPaypalOrder endpoint
Diffstat (limited to 'api')
-rw-r--r--api/createPaypalOrder.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/api/createPaypalOrder.ts b/api/createPaypalOrder.ts
new file mode 100644
index 0000000..1a6e810
--- /dev/null
+++ b/api/createPaypalOrder.ts
@@ -0,0 +1,28 @@
+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(400);
+ 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 {
+ const paypalResponse = await paypalCreateOrder({ productDescription, shortDescription, totalPrice });
+
+ if (paypalResponse.ok) {
+ response.status(200).json({
+ orderId: paypalResponse.id,
+ });
+ }
+ }
+}