Billify SaaS is a multi-tenant billing microservice designed to handle subscription management, invoicing, and payment processing for a Software as a Service (SaaS) application. This microservice integrates with the AuthoSaaS microservice to retrieve tenant information and ensure proper billing workflows.
- Subscription Management: Create and manage subscriptions for tenants.
- Invoicing: Generate invoices based on subscriptions.
- Payment Processing: Process payments linked to invoices.
Prerequisites
- PHP 8.x
- Laravel 9.x
- Composer
- Database (MySQL, PostgreSQL, etc.)
-
Clone the repository:
git clone https://github.com/your-username/billify-saas.git cd billify-saas -
Install dependencies:
composer install -
Set up your environment:
cp .env.example .env -
Generate the application key:
php artisan key:generate
This microservice follows a microservices architecture, allowing for scalability and modularity. The main components are:
- AuthoSaaS: Handles user authentication and authorization.
- Billify SaaS: Manages billing workflows, including subscriptions, invoices, and payments.
The billing process consists of three main steps, each handled by a separate endpoint:
-
Create Subscription:
- Endpoint:
POST /api/subscriptions - Description: Creates a new subscription for a tenant.
- Endpoint:
-
Create Invoice:
- Endpoint:
POST /api/invoices - Description: Generates an invoice for the newly created subscription.
- Endpoint:
-
Process Payment:
- Endpoint:
POST /api/payments - Description: Processes the payment for the generated invoice.
- Endpoint:
The workflow for billing involves the following steps:
-
Create Subscription
- The frontend collects necessary data (like
tenant_idandplan_id) and sends a request to the/api/subscriptionsendpoint. - Upon successful creation, the backend returns the subscription details.
- The frontend collects necessary data (like
-
Create Invoice
- Using the
subscription_id, the frontend calls the/api/invoicesendpoint to create an invoice linked to the subscription. - The backend returns the invoice details.
- Using the
-
Process Payment
- The frontend calls the
/api/paymentsendpoint using theinvoice_idto process the payment. - The backend updates the invoice status to "paid" upon successful processing.
- The frontend calls the
- Method:
POST - Endpoint:
/api/subscriptions - Request Body:
{ "tenant_id": "string", "plan_id": "string" } - Response:
{ "subscription_id": "string", "status": "active" }
- Method:
POST - Endpoint:
/api/invoices - Request Body:
{ "subscription_id": "string" } - Response:
{ "invoice_id": "string", "amount": "number", "status": "pending" }
- Method:
POST - Endpoint:
/api/payments - Request Body:
{ "invoice_id": "string", "payment_method": "string" } - Response:
{ "payment_id": "string", "status": "successful" }