Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(all-services): update readme #58

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 99 additions & 4 deletions services/subscription-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,131 @@ This is the primary service of the control plane responsible for subscription an
A Microservice for handling subscription management operations. It provides -
- plan creations and management - plan includes plan tier - silo/pooled
- Add or Update Plan Items/Services/Resources to Plans - plan items are the offerings to user with in the selected plan
- Billing Cycle handling - Billing cycle includes start date and end date etc
- Billing & Invoice Management.

## Billing & Invoicing
we have created a package [loopback4-billing](https://github.com/sourcefuse/loopback4-billing) that is designed to integrate billing functionality into LoopBack 4 applications. It provides an abstraction layer to work with billing services such as Chargebee, Stripe etc, offering common billing operations like creating and managing customers, invoices, payment sources, and transactions.


## Installation

Install Subscription service using `npm`;

```sh
$ [npm install | yarn add] @sourceloop/subscription-service
$ [npm install | yarn add] @sourceloop/ctrl-plane-subscription-service
```

## Usage

- Create a new Loopback4 Application (If you don't have one already)
`lb4 testapp`
- Install the subscription service
`npm i @sourceloop/subscription-service`
`npm i @sourceloop/ctrl-plane-subscription-service`
- Set the [environment variables](#environment-variables).
- Run the [migrations](#migrations).
- Add the `SubscriptionServiceComponent` to your Loopback4 Application (in `application.ts`).
```typescript
// import the SubscriptionServiceComponent
import {SubscriptionServiceComponent} from '@sourceloop/subscription-service';
import {SubscriptionServiceComponent} from '@sourceloop/ctrl-plane-subscription-service';
// add Component for subscription-service
this.component(SubscriptionServiceComponent);
```
- Set up a [Loopback4 Datasource](https://loopback.io/doc/en/lb4/DataSource.html) with `dataSourceName` property set to
`SubscriptionDB`. You can see an example datasource [here](#setting-up-a-datasource).
- Bind any of the custom [providers](#providers) you need.

## Integrating Billing Functionality into Subscription Service using LoopBack 4

We are leveraging the [loopback4-billing](https://github.com/sourcefuse/loopback4-billing) package to integrate billing capabilities into our Subscription Service.

To include billing functionality, we integrate the BillingComponent into the SubscriptionServiceComponent as follows:
```typescript
// import billing component from loopback4-billing
import {BillingComponent} from 'loopback4-billing';
// add Component for subscription-service component
this.application.component(BillingComponent);
```
We utilize the BillingProvider binding from [loopback4-billing](https://github.com/sourcefuse/loopback4-billing) in our controllers as shown below:

```typescript
// import billing component from loopback4-billing
import {BillingComponentBindings,IService} from 'loopback4-billing';
// add Component for subscription-service component
export class BillingInvoiceController {
constructor(
...
@inject(BillingComponentBindings.BillingProvider)
private readonly billingProvider: IService,
...
) {}
}
```

Depending on the billing provider, the setup process varies. Currently, we support Stripe and Chargebee.

### For ChargeBee -
To use Chargebee as the billing provider, you need to configure the Chargebee API keys and site URL in your application. You can set these values in the environment variables of your LoopBack 4 project.
```
API_KEY=your_chargebee_api_key
SITE=your_chargebee_site_url
```
Next, bind these values with ChargeBeeBindings.Config and register the Chargebee provider, as shown below:
```typescript
import { ChargeBeeBindings,BillingComponentBindings } from 'loopback4-billing';
import {SubscriptionServiceComponent} from '@sourceloop/ctrl-plane-subscription-service';
export class YourApplication extends BootMixin(
ServiceMixin(RepositoryMixin(RestApplication)),
) {
constructor(options: ApplicationConfig = {}) {
super(options);

// Bind the config values
this.bind(ChargeBeeBindings.config).to({
site: process.env.SITE ?? '',
apiKey: process.env.API_KEY ?? '',
});
// Register Billing component
this.bind(BillingComponentBindings.SDKProvider).toProvider(
ChargeBeeServiceProvider,
);

this.component(SubscriptionServiceComponent);
// Other configurations
}
}
```


### For STRIPE -
To use Stripe as the billing provider, you need to configure the Chargebee API keys and site URL in your application. You can set these values in the environment variables of your LoopBack 4 project.
```
STRIPE_SECRET=your_stripe_secret_key
```
Next, bind these values with StripeBindings.Config and register the Stripe provider, as shown below:

```typescript
import { StripeBindings,BillingComponentBindings } from 'loopback4-billing';
import {SubscriptionServiceComponent} from '@sourceloop/ctrl-plane-subscription-service';
export class YourApplication extends BootMixin(
ServiceMixin(RepositoryMixin(RestApplication)),
) {
constructor(options: ApplicationConfig = {}) {
super(options);

// Bind the config values
this.bind(StripeBindings.config).to({
secretKey: process.env.STRIPE_SECRET ?? '',
});
// Register Billing component
this.bind(BillingComponentBindings.SDKProvider).toProvider(
StripeServiceProvider,
);

this.component(SubscriptionServiceComponent);
// Other configurations
}
}
```
### Environment Variables

<table>
Expand Down
39 changes: 34 additions & 5 deletions services/tenant-management-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A Microservice for handling tenant management operations. It provides -
- Tenant Onboarding of both pooled and silo tenants
- Billing and Invoicing
- Provisioning of resources for silo and pooled tenants
- IDP - confgure identity provider

### work flow

Expand All @@ -22,21 +23,21 @@ A Microservice for handling tenant management operations. It provides -
Install Tenant Management Service using `npm`;

```sh
$ [npm install | yarn add] @sourceloop/tenant-management-service
$ [npm install | yarn add] @sourceloop/ctrl-plane-tenant-management-service
```

## Usage

- Create a new Loopback4 Application (If you don't have one already)
`lb4 testapp`
- Install the tenant management service
`npm i @sourceloop/tenant-management-service`
`npm i @sourceloop/ctrl-plane-tenant-management-service`
- Set the [environment variables](#environment-variables).
- Run the [migrations](#migrations).
- Add the `TenantManagementServiceComponent` to your Loopback4 Application (in `application.ts`).
```typescript
// import the TenantManagementServiceComponent
import {TenantManagementServiceComponent} from '@sourceloop/tenant-management-service';
import {TenantManagementServiceComponent} from '@sourceloop/ctrl-plane-tenant-management-service';
// add Component for TenantManagementService
this.component(TenantManagementServiceComponent);
```
Expand All @@ -56,13 +57,41 @@ $ [npm install | yarn add] @sourceloop/tenant-management-service
- This endpoint would onboard the tenant in the DB, and the facade is then supposed to trigger the relevant events using the `/tenants/{id}/provision` endpoint.
- The provisioning endpoint will invoke the publish method on the `EventConnector`. This connector's purpose is to provide a place for consumer to write the event publishing logic. And your custom service can be bound to the key `EventConnectorBinding` exported by the service. Refer the example with Amazon EventBridge implementation in the [sandbox](./sandbox).

## IDP - Identity Provider

The IDP (Identity Provider) Controller provides an endpoint to manage identity provider configurations for tenants. It supports multiple identity providers, such as Keycloak and Auth0, and ensures secure handling of identity provider setup requests through rate-limiting, authorization, and input validation.
### Features
##### Multi-IDP Support:
- Supports Keycloak and Auth0 as identity providers.
- Extensible for additional providers like Cognito.

##### Bindings:

**TenantManagementServiceBindings.IDP_KEYCLOAK** - Provides Keycloak configuration handler.

**TenantManagementServiceBindings.IDP_AUTH0** - Provides Auth0 configuration handler.

This switch statement selects the appropriate identity provider (IDP) configuration based on the identityProvider value in the request payload.

- AUTH0: Calls idpAuth0Provider to configure Auth0.
- KEYCLOAK: Calls idpKeycloakProvider to configure Keycloak.

Finally, it returns the response (res) from the selected provider.
``` typescript
export interface IdpResp {
authId: string;
}
```
authId is the id of the user created over identity provider.


## Webhook Integration

- A webhook endpoint is available in the service that is supposed to update the status of a tenant based on the updates from the third-party responsible for actual provisioning of resources
- To add Webhook configuration in your application, add the `WebhookTenantManagementServiceComponent` to your Loopback4 Application (in `application.ts`).
```typescript
// import the UserTenantServiceComponent
import {WebhookTenantManagementServiceComponent} from '@sourceloop/tenant-management-service';
import {WebhookTenantManagementServiceComponent} from '@sourceloop/ctrl-plane-tenant-management-service';
// add the component here
this.component(WebhookTenantManagementServiceComponent);
```
Expand Down Expand Up @@ -276,7 +305,7 @@ Here is a sample Implementation `DataSource` implementation using environment va
```typescript
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';
import {TenantManagementDbSourceName} from '@sourceloop/tenant-management-service';
import {TenantManagementDbSourceName} from '@sourceloop/ctrl-plane-tenant-management-service';

const config = {
name: TenantManagementDbSourceName,
Expand Down
Loading