Billing - router - RESTful API
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -314,6 +314,7 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
});
}
// Destructuring the STRIPE invoice to extract the required information
+ // eslint-disable-next-line id-blacklist
const { id: invoiceID, customer, number, amount_due: amount, amount_paid: amountPaid, status, currency, invoice_pdf: downloadUrl, metadata } = stripeInvoice;
const customerID = customer as string;
const createdOn = moment.unix(stripeInvoice.created).toDate(); // epoch to Date!
@@ -340,6 +341,7 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
const billingInvoice: BillingInvoice = await BillingStorage.getInvoiceByInvoiceID(this.tenantID, stripeInvoice.id);
const invoiceToSave: BillingInvoice = {
id: billingInvoice?.id, // ACHTUNG: billingInvoice is null when creating the Billing Invoice
+ // eslint-disable-next-line id-blacklist
userID, invoiceID, customerID, number, amount, amountPaid, currency, createdOn, downloadUrl, downloadable: !!downloadUrl,
status: status as BillingInvoiceStatus,
};

MODIFY
src/server/rest/v1/router/api/BillingRouter.ts
src/server/rest/v1/router/api/BillingRouter.ts
import { ServerAction, ServerRoute } from '../../../../../types/Server';
-/* eslint-disable @typescript-eslint/no-misused-promises */
import express, { NextFunction, Request, Response } from 'express';
import BillingService from '../../service/BillingService';
@@ -25,42 +24,46 @@ export default class BillingRouter {
}
protected buildRouteBillingPaymentMethods(): void {
- this.router.get(`/${ServerRoute.REST_BILLING_PAYMENT_METHODS}`, async (req: Request, res: Response, next: NextFunction) => {
- req.body.userID = req.params.userID;
- await RouterUtils.handleServerAction(BillingService.handleBillingGetPaymentMethods.bind(this), ServerAction.BILLING_PAYMENT_METHODS, req, res, next);
+ this.router.get(`/${ServerRoute.REST_BILLING_PAYMENT_METHODS}`, (req: Request, res: Response, next: NextFunction) => {
+ // GET {{base_url}}/v1/api/billing/users/5be451dad0685c19bff48856/payment-methods?Limit=100&SortFields=id
+ req.query.userID = req.params.userID;
+ void RouterUtils.handleServerAction(BillingService.handleBillingGetPaymentMethods.bind(this), ServerAction.BILLING_PAYMENT_METHODS, req, res, next);
});
}
protected buildRouteBillingDeletePaymentMethod(): void {
- this.router.delete(`/${ServerRoute.REST_BILLING_PAYMENT_METHOD}`, async (req: Request, res: Response, next: NextFunction) => {
+ // DELETE {{base_url}}/v1/api/billing/users/5be451dad0685c19bff48856/payment-methods?Limit=100&SortFields=id
+ this.router.delete(`/${ServerRoute.REST_BILLING_PAYMENT_METHOD}`, (req: Request, res: Response, next: NextFunction) => {
req.body.userID = req.params.userID;
req.body.paymentMethodId = req.params.paymentMethodID;
- await RouterUtils.handleServerAction(BillingService.handleBillingDeletePaymentMethod.bind(this), ServerAction.BILLING_DELETE_PAYMENT_METHOD, req, res, next);
+ void RouterUtils.handleServerAction(BillingService.handleBillingDeletePaymentMethod.bind(this), ServerAction.BILLING_DELETE_PAYMENT_METHOD, req, res, next);
});
}
protected buildRouteBillingPaymentMethodSetup(): void {
- this.router.post(`/${ServerRoute.REST_BILLING_PAYMENT_METHOD_SETUP}`, async (req: Request, res: Response, next: NextFunction) => {
+ this.router.post(`/${ServerRoute.REST_BILLING_PAYMENT_METHOD_SETUP}`, (req: Request, res: Response, next: NextFunction) => {
// STRIPE prerequisite - ask for a setup intent first!
req.body.userID = req.params.userID;
- await RouterUtils.handleServerAction(BillingService.handleBillingSetupPaymentMethod.bind(this), ServerAction.BILLING_SETUP_PAYMENT_METHOD, req, res, next);
+ void RouterUtils.handleServerAction(BillingService.handleBillingSetupPaymentMethod.bind(this), ServerAction.BILLING_SETUP_PAYMENT_METHOD, req, res, next);
});
}
protected buildRouteBillingPaymentMethodAttach(): void {
- this.router.post(`/${ServerRoute.REST_BILLING_PAYMENT_METHOD_ATTACH}`, async (req: Request, res: Response, next: NextFunction) => {
+ this.router.post(`/${ServerRoute.REST_BILLING_PAYMENT_METHOD_ATTACH}`, (req: Request, res: Response, next: NextFunction) => {
// Creates a new payment method and attach it to the user as its default
req.body.userID = req.params.userID;
- await RouterUtils.handleServerAction(BillingService.handleBillingSetupPaymentMethod.bind(this), ServerAction.BILLING_SETUP_PAYMENT_METHOD, req, res, next);
+ req.body.paymentMethodId = req.params.paymentMethodID;
+ void RouterUtils.handleServerAction(BillingService.handleBillingSetupPaymentMethod.bind(this), ServerAction.BILLING_SETUP_PAYMENT_METHOD, req, res, next);
});
}
protected buildRouteBillingPaymentMethodDetach(): void {
- this.router.post(`/${ServerRoute.REST_BILLING_PAYMENT_METHOD_DETACH}`, async (req: Request, res: Response, next: NextFunction) => {
- // Detach a payment method from the user
+ this.router.post(`/${ServerRoute.REST_BILLING_PAYMENT_METHOD_DETACH}`, (req: Request, res: Response, next: NextFunction) => {
+ // POST {{base_url}}/v1/api/billing/users/5be451dad0685c19bff48856/payment-methods/pm_1Ib3MxF5e1VSb1v6eH3Zhn4K/detach
+ // Detach a payment method from the user:
req.body.userID = req.params.userID;
- await RouterUtils.handleServerAction(BillingService.handleBillingSetupPaymentMethod.bind(this), ServerAction.BILLING_SETUP_PAYMENT_METHOD, req, res, next);
+ req.body.paymentMethodId = req.params.paymentMethodID;
+ void RouterUtils.handleServerAction(BillingService.handleBillingDeletePaymentMethod.bind(this), ServerAction.BILLING_DELETE_PAYMENT_METHOD, req, res, next);
});
}
-
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -497,12 +497,12 @@ export enum ServerRoute {
REST_TENANTS = 'tenants',
- // URLs for CRUD operations on PAYMENT METHODS
+ // BILLING URLs for CRUD operations on PAYMENT METHODS
REST_BILLING_PAYMENT_METHODS = 'billing/users/:userID/payment-methods',
REST_BILLING_PAYMENT_METHOD = 'billing/users/:userID/payment-methods/:paymentMethodID',
- // URLs for Non-CRUD Operations on PAYMENT METHODS
+ // BILLING URLs for Non-CRUD Operations on PAYMENT METHODS
REST_BILLING_PAYMENT_METHOD_SETUP = 'billing/users/:userID/payment-methods/setup',
- REST_BILLING_PAYMENT_METHOD_ATTACH = 'billing/users/:userID/payment-methods/attach',
- REST_BILLING_PAYMENT_METHOD_DETACH = 'billing/users/:userID/payment-methods/detach',
+ REST_BILLING_PAYMENT_METHOD_ATTACH = 'billing/users/:userID/payment-methods/:paymentMethodID/attach',
+ REST_BILLING_PAYMENT_METHOD_DETACH = 'billing/users/:userID/payment-methods/:paymentMethodID/detach',
}

Billing - router - RESTful API