mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
fix: billing
This commit is contained in:
@ -3,5 +3,5 @@ import { stripeWebhookHandler } from '@documenso/ee/server-only/stripe/webhook/h
|
|||||||
import type { Route } from './+types/webhook.trigger';
|
import type { Route } from './+types/webhook.trigger';
|
||||||
|
|
||||||
export async function action({ request }: Route.ActionArgs) {
|
export async function action({ request }: Route.ActionArgs) {
|
||||||
return stripeWebhookHandler(request);
|
return await stripeWebhookHandler(request);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import { Hono } from 'hono';
|
import { Hono } from 'hono';
|
||||||
import { bodyLimit } from 'hono/body-limit';
|
|
||||||
import { contextStorage } from 'hono/context-storage';
|
import { contextStorage } from 'hono/context-storage';
|
||||||
import { timeout } from 'hono/timeout';
|
|
||||||
|
|
||||||
import { tsRestHonoApp } from '@documenso/api/hono';
|
import { tsRestHonoApp } from '@documenso/api/hono';
|
||||||
import { auth } from '@documenso/auth/server';
|
import { auth } from '@documenso/auth/server';
|
||||||
@ -22,12 +20,6 @@ export interface HonoEnv {
|
|||||||
|
|
||||||
const app = new Hono<HonoEnv>();
|
const app = new Hono<HonoEnv>();
|
||||||
|
|
||||||
/**
|
|
||||||
* Global middleware limits.
|
|
||||||
*/
|
|
||||||
app.use(timeout(120000)); // Two minute timeout.
|
|
||||||
app.use(bodyLimit({ maxSize: 50 * 1024 * 1024 })); // 50mb size limit.
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach session and context to requests.
|
* Attach session and context to requests.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -16,7 +16,7 @@ type StripeWebhookResponse = {
|
|||||||
message: string;
|
message: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const stripeWebhookHandler = async (req: Request) => {
|
export const stripeWebhookHandler = async (req: Request): Promise<Response> => {
|
||||||
try {
|
try {
|
||||||
const isBillingEnabled = IS_BILLING_ENABLED();
|
const isBillingEnabled = IS_BILLING_ENABLED();
|
||||||
|
|
||||||
@ -51,17 +51,21 @@ export const stripeWebhookHandler = async (req: Request) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo: (RR7) I'm not sure about this.
|
const payload = await req.text();
|
||||||
const clonedReq = req.clone();
|
|
||||||
const rawBody = await clonedReq.arrayBuffer();
|
|
||||||
const body = Buffer.from(rawBody);
|
|
||||||
|
|
||||||
// It was this:
|
if (!payload) {
|
||||||
// const body = await buffer(req);
|
return Response.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: 'No payload found in request',
|
||||||
|
} satisfies StripeWebhookResponse,
|
||||||
|
{ status: 400 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const event = stripe.webhooks.constructEvent(body, signature, webhookSecret);
|
const event = stripe.webhooks.constructEvent(payload, signature, webhookSecret);
|
||||||
|
|
||||||
await match(event.type)
|
return await match(event.type)
|
||||||
.with('checkout.session.completed', async () => {
|
.with('checkout.session.completed', async () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
const session = event.data.object as Stripe.Checkout.Session;
|
const session = event.data.object as Stripe.Checkout.Session;
|
||||||
|
|||||||
Reference in New Issue
Block a user