mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: sweep up lemon squeezy webhooks.
This commit is contained in:
@@ -31,5 +31,4 @@ export default ({ agenda }: { agenda: Agenda }) => {
|
||||
agenda.start().then(() => {
|
||||
agenda.every('1 hours', 'delete-expired-imported-files', {});
|
||||
});
|
||||
agenda.start();
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getPrice } from '@lemonsqueezy/lemonsqueezy.js';
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import config from '@/config';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import {
|
||||
compareSignatures,
|
||||
@@ -29,10 +29,10 @@ export class LemonSqueezyWebhooks {
|
||||
): Promise<void> {
|
||||
configureLemonSqueezy();
|
||||
|
||||
if (!process.env.LEMONSQUEEZY_WEBHOOK_SECRET) {
|
||||
throw new ServiceError('Lemon Squeezy Webhook Secret not set in .env');
|
||||
if (!config.lemonSqueezy.webhookSecret) {
|
||||
throw new Error('Lemon Squeezy Webhook Secret not set in .env');
|
||||
}
|
||||
const secret = process.env.LEMONSQUEEZY_WEBHOOK_SECRET;
|
||||
const secret = config.lemonSqueezy.webhookSecret;
|
||||
const hmacSignature = createHmacSignature(secret, rawData);
|
||||
|
||||
if (!compareSignatures(hmacSignature, signature)) {
|
||||
@@ -42,14 +42,15 @@ export class LemonSqueezyWebhooks {
|
||||
if (webhookHasMeta(data)) {
|
||||
// Non-blocking call to process the webhook event.
|
||||
void this.processWebhookEvent(data);
|
||||
} else {
|
||||
throw new Error('Data invalid');
|
||||
}
|
||||
throw new Error('Data invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* This action will process a webhook event in the database.
|
||||
*/
|
||||
async processWebhookEvent(eventBody) {
|
||||
private async processWebhookEvent(eventBody) {
|
||||
let processingError = '';
|
||||
const webhookEvent = eventBody.meta.event_name;
|
||||
|
||||
@@ -88,6 +89,7 @@ export class LemonSqueezyWebhooks {
|
||||
? priceData.data?.data.attributes.unit_price_decimal
|
||||
: priceData.data?.data.attributes.unit_price;
|
||||
|
||||
// Create a new subscription of the tenant.
|
||||
if (webhookEvent === 'subscription_created') {
|
||||
await this.subscriptionService.newSubscribtion(
|
||||
tenantId,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import Plan from './Subscriptions/Plan';
|
||||
import PlanSubscription from './Subscriptions/PlanSubscription';
|
||||
import License from './Subscriptions/License';
|
||||
import Tenant from './Tenant';
|
||||
import TenantMetadata from './TenantMetadata';
|
||||
import SystemUser from './SystemUser';
|
||||
@@ -12,7 +11,6 @@ import { Import } from './Import';
|
||||
export {
|
||||
Plan,
|
||||
PlanSubscription,
|
||||
License,
|
||||
Tenant,
|
||||
TenantMetadata,
|
||||
SystemUser,
|
||||
|
||||
Reference in New Issue
Block a user