initail work on paid booking, improve validations
This commit is contained in:
1 parent
12de89294d
commit
e284707250
14 files changed
+103
-42
No files matched your search
@@ -0,0 +1,25 @@
|
||||
// Make a middleware that adds a cost to running the request
|
||||
// by calling stripeSubscription addCost() * pricePerBooking
|
||||
// Initially to test out 0,5 cent per booking via API call
|
||||
// withCost(5)(endpoint)
|
||||
// Should add a charge of 0.5 cent per booking to the subscription of the user making the request
|
||||
// Should be called in the middleware of the e
|
||||
//
|
||||
import { NextMiddleware } from "next-api-middleware";
|
||||
|
||||
export const withCost = (priceInCents: number): NextMiddleware => {
|
||||
return async function (req, res, next) {
|
||||
console.log(req.headers);
|
||||
if (
|
||||
priceInCents > 0
|
||||
// && stripeCustomerId && stripeSubscriptionId
|
||||
) {
|
||||
console.log(priceInCents);
|
||||
// if (req.method === allowedHttpMethod || req.method == "OPTIONS") {
|
||||
await next();
|
||||
} else {
|
||||
res.status(405).json({ message: `We weren't able to process the payment for this transaction` });
|
||||
res.end();
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -2,7 +2,7 @@ import { label } from "next-api-middleware";
|
||||
|
||||
import { addRequestId } from "./addRequestid";
|
||||
import { captureErrors } from "./captureErrors";
|
||||
import { HTTP_POST, HTTP_DELETE, HTTP_PATCH, HTTP_GET, httpMethod } from "./httpMethods";
|
||||
import { HTTP_POST, HTTP_DELETE, HTTP_PATCH, HTTP_GET } from "./httpMethods";
|
||||
import { verifyApiKey } from "./verifyApiKey";
|
||||
|
||||
const withMiddleware = label(
|
||||
@@ -14,9 +14,8 @@ const withMiddleware = label(
|
||||
addRequestId,
|
||||
verifyApiKey,
|
||||
sentry: captureErrors,
|
||||
httpMethod: httpMethod("GET" || "DELETE" || "PATCH" || "POST"),
|
||||
},
|
||||
["sentry", "verifyApiKey", "httpMethod", "addRequestId"] // <-- Provide a list of middleware to call automatically
|
||||
["sentry", "verifyApiKey", "addRequestId"] // <-- Provide a list of middleware to call automatically
|
||||
);
|
||||
|
||||
export { withMiddleware };
|
||||
Reference in new issue
Block a user