feat: Implement stripe webhooks

This commit is contained in:
Faruk AYDIN
2023-03-07 17:13:20 +01:00
parent 7676bc5836
commit b0b6b72b4c
7 changed files with 97 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import { Response } from 'express';
import { IRequest } from '@automatisch/types';
import Billing from '../../helpers/billing/index.ee';
import appConfig from '../../config/app';
import logger from '../../helpers/logger';
export default async (request: IRequest, response: Response) => {
const signature = request.headers['stripe-signature'];
try {
const event = Billing.stripe.webhooks.constructEvent(
request.rawBody,
signature,
appConfig.stripeSigningSecret
);
await Billing.handleWebhooks(event);
return response.sendStatus(200);
} catch (error) {
logger.error(`Webhook Error: ${error.message}`);
return response.sendStatus(400);
}
};