Removed billing webhooks
DELETE
src/assets/server/rest/v1/schemas/billing/billing-webhook.json
-{
- "$id": "billing-webhook",
- "title": "Billing webhook Request",
- "type": "object",
- "properties": {
- "TenantID": {
- "$ref": "common#/definitions/id"
- }
- },
- "required": [
- "TenantID"
- ]
-}

MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -291,11 +291,6 @@ export default class CentralRestServerService {
case 'POST':
// Check Context
switch (action) {
- // Ping
- case ServerAction.BILLING_WEB_HOOK:
- await BillingService.handleBillingWebHook(action, req, res, next);
- // Res.sendStatus(StatusCodes.OK);
- break;
default:
// Delegate
await UtilsService.handleUnknownAction(action, req, res, next);

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -347,7 +347,7 @@ export default class BillingService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
Action.LIST, Entity.INVOICE, MODULE_NAME, 'handleGetInvoice');
// Filter
- const filteredRequest = BillingValidator.getInstance().validateBillingInvoicesGetByIdReq(req.query);
+ const filteredRequest = BillingValidator.getInstance().validateBillingInvoiceReq(req.query);
UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetInvoice', req.user);
// Check Users
let userProject: string[] = [];
@@ -618,7 +618,7 @@ export default class BillingService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
Action.DOWNLOAD, Entity.BILLING, MODULE_NAME, 'handleDownloadInvoice');
// Filter
- const filteredRequest = BillingValidator.getInstance().validateBillingInvoicesGetByIdReq(req.query);
+ const filteredRequest = BillingValidator.getInstance().validateBillingInvoiceReq(req.query);
// Get the Invoice
const billingInvoice = await BillingStorage.getInvoice(req.tenant, filteredRequest.ID);
UtilsService.assertObjectExists(action, billingInvoice, `Invoice ID '${filteredRequest.ID}' does not exist`,
@@ -660,51 +660,6 @@ export default class BillingService {
res.end(buffer, 'binary');
}
- public static async handleBillingWebHook(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- // Check if component is active
- UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
- Action.SYNCHRONIZE, Entity.BILLING, MODULE_NAME, 'handleBillingWebHook');
- // Check if component is active
- // ?? How to do it in this context
- // Filter
- const filteredRequest = BillingValidator.getInstance().validateBillingWebhookReq(req.query);
- // Check Auth
- // How to check it - no JWT!
- // Retrieve Tenant ID from the URL Query Parameters
- if (!filteredRequest.TenantID) {
- throw new AppError({
- errorCode: HTTPError.GENERAL_ERROR,
- message: 'Unexpected situation - TenantID is not set',
- module: MODULE_NAME, method: 'handleBillingWebHook',
- action: action,
- });
- }
- // Get Tenant
- const tenant = await TenantStorage.getTenant(filteredRequest.TenantID);
- if (!tenant) {
- throw new AppError({
- errorCode: HTTPError.GENERAL_ERROR,
- action: action,
- module: MODULE_NAME, method: 'handleBillingWebHook',
- message: `Tenant ID '${filteredRequest.TenantID}' does not exist!`
- });
- }
- const billingImpl = await BillingFactory.getBillingImpl(tenant);
- if (!billingImpl) {
- throw new AppError({
- errorCode: HTTPError.GENERAL_ERROR,
- message: 'Billing service is not configured',
- module: MODULE_NAME, method: 'handleBillingWebHook',
- action: action,
- });
- }
- // STRIPE expects a fast response - make sure to postpone time consuming operations when handling these events
- const done = await billingImpl.consumeBillingEvent(req);
- // Return a response to acknowledge receipt of the event
- res.json({ received: done });
- next();
- }
-
public static async handleGetBillingSetting(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,

MODIFY
src/server/rest/v1/service/security/BillingSecurity.ts
src/server/rest/v1/service/security/BillingSecurity.ts
-import { HttpBillingInvoiceRequest, HttpBillingRequest, HttpBillingWebHookRequest, HttpDeletePaymentMethod, HttpPaymentMethods, HttpSetupPaymentMethod } from '../../../../../types/requests/HttpBillingRequest';
+import { HttpBillingInvoiceRequest, HttpBillingRequest, HttpDeletePaymentMethod, HttpPaymentMethods, HttpSetupPaymentMethod } from '../../../../../types/requests/HttpBillingRequest';
import { HttpCreateTransactionInvoiceRequest, HttpForceSynchronizeUserInvoicesRequest, HttpSynchronizeUserRequest } from '../../../../../types/requests/HttpUserRequest';
import Utils from '../../../../../utils/Utils';
@@ -63,12 +63,6 @@ export default class BillingSecurity {
};
}
- public static filterBillingWebHookRequest(requestQuery: any): HttpBillingWebHookRequest {
- return {
- TenantID: sanitize(requestQuery.TenantID)
- };
- }
-
public static filterSetupPaymentMethodRequest(requestBody: any): HttpSetupPaymentMethod {
return {
userID: sanitize(requestBody.userID),

MODIFY
src/server/rest/v1/validator/BillingValidator.ts
src/server/rest/v1/validator/BillingValidator.ts
-import { HttpBillingInvoiceRequest, HttpBillingRequest, HttpBillingWebHookRequest, HttpDeletePaymentMethod, HttpPaymentMethods, HttpSetupPaymentMethod } from '../../../../types/requests/HttpBillingRequest';
+import { HttpBillingInvoiceRequest, HttpBillingRequest, HttpDeletePaymentMethod, HttpPaymentMethods, HttpSetupPaymentMethod } from '../../../../types/requests/HttpBillingRequest';
import { BillingSettings } from '../../../../types/Setting';
import Schema from '../../../../types/validator/Schema';
@@ -14,7 +14,6 @@ export default class BillingValidator extends SchemaValidator {
private billingSetupUserPaymentMethod: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/billing/billing-setup-payment-method.json`, 'utf8'));
private billingInvoicesGet: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/billing/invoices-get.json`, 'utf8'));
private billingInvoiceGetByID: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/billing/invoice-get-by-id.json`, 'utf8'));
- private billingWebhook: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/billing/billing-webhook.json`, 'utf8'));
private constructor() {
super('BillingValidator');
@@ -47,11 +46,7 @@ export default class BillingValidator extends SchemaValidator {
return this.validate(this.billingInvoicesGet, data);
}
- public validateBillingInvoicesGetByIdReq(data: Record<string, unknown>): HttpBillingRequest {
+ public validateBillingInvoiceReq(data: Record<string, unknown>): HttpBillingRequest {
return this.validate(this.billingInvoiceGetByID, data);
}
-
- public validateBillingWebhookReq(data: Record<string, unknown>): HttpBillingWebHookRequest {
- return this.validate(this.billingWebhook, data);
- }
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -435,7 +435,6 @@ export enum ServerAction {
BILLING_PAYMENT_METHODS = 'BillingPaymentMethods',
BILLING_DELETE_PAYMENT_METHOD = 'BillingDeletePaymentMethod',
BILLING_CHARGE_INVOICE = 'BillingChargeInvoice',
- BILLING_WEB_HOOK = 'BillingWebHook',
BILLING_TEST_DATA_CLEANUP = 'BillingTestDataCleanup',
BILLING_BILL_PENDING_TRANSACTION = 'BillingBillPendingTransaction',

MODIFY
src/types/requests/HttpBillingRequest.ts
src/types/requests/HttpBillingRequest.ts
@@ -15,10 +15,6 @@ export interface HttpBillingInvoiceRequest extends HttpDatabaseRequest {
ID?: string;
}
-export interface HttpBillingWebHookRequest {
- TenantID?: string
-}
-
export interface HttpSetupPaymentMethod {
userID: string;
paymentMethodId?: string;

Removed billing webhooks