stripe controller
This commit is contained in:
1 parent
f476a57748
commit
6eabaebd86
10 files changed
+125
-10
No files matched your search
@@ -400,7 +400,7 @@ class MonitorController {
|
||||
throw new ApiError("Entitlements not found", 500);
|
||||
}
|
||||
|
||||
const result: any = await this.monitorService.import(
|
||||
const result = await this.monitorService.import(
|
||||
orgId,
|
||||
teamId,
|
||||
userContext.sub,
|
||||
@@ -414,7 +414,8 @@ class MonitorController {
|
||||
UNEXPECTED: `Import failed unexpectedly`,
|
||||
};
|
||||
|
||||
const message = result?.message || defaultMessageMap[result?.code] || "Import completed";
|
||||
const message =
|
||||
result?.message || defaultMessageMap[result?.code] || "Import completed";
|
||||
res.status(result?.status ?? 200).json({ message, data: result });
|
||||
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import type { Request, Response, NextFunction } from "express";
|
||||
|
||||
export interface IStripeController {
|
||||
webhook: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
||||
}
|
||||
|
||||
class StripeController implements IStripeController {
|
||||
webhook = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const sig = req.headers["stripe-signature"] as string | undefined;
|
||||
const raw = req.body as unknown; // Buffer when express.raw is used
|
||||
|
||||
let event: any = undefined;
|
||||
if (Buffer.isBuffer(raw)) {
|
||||
const json = raw.toString("utf8");
|
||||
try {
|
||||
event = JSON.parse(json);
|
||||
} catch (_e) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
}
|
||||
} else if (typeof raw === "string") {
|
||||
try {
|
||||
event = JSON.parse(raw);
|
||||
} catch (_e) {
|
||||
res.status(400).json({ message: "Invalid JSON payload" });
|
||||
}
|
||||
} else if (raw && typeof raw === "object") {
|
||||
event = raw;
|
||||
}
|
||||
|
||||
// Basic routing by event type (no-ops for now)
|
||||
const type = event?.type;
|
||||
switch (type) {
|
||||
case "checkout.session.completed":
|
||||
case "customer.subscription.updated":
|
||||
case "customer.subscription.deleted":
|
||||
case "invoice.payment_succeeded":
|
||||
case "invoice.payment_failed":
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
res.status(200);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default StripeController;
|
||||
@@ -14,3 +14,4 @@ export { default as RecoveryController } from "./RecoveryController.js";
|
||||
export { default as ProfileController } from "./ProfileController.js";
|
||||
export { default as IncidentsController } from "./IncidentsController.js";
|
||||
export { default as SettingsController } from "./SettingsController.js";
|
||||
export { default as StripeController } from "./StripeController.js";
|
||||
Reference in new issue
Block a user