> ## Documentation Index
> Fetch the complete documentation index at: https://developer.transactbridge.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Prepaid Invoices

> Understand how prepaid invoices are generated and collected in Transact Bridge.

A **prepaid subscription** requires the customer to pay for the subscription before accessing the service.

In Transact Bridge, a prepaid subscription is configured by setting `billAtStart` to `true`.

When `billAtStart` is `true`, Transact Bridge collects the subscription amount **before providing access to the service** and generates the invoice at the start of the subscription period.

## How Prepaid Invoices Work

The prepaid invoice flow works as follows:

1. The merchant creates a subscription with `billAtStart: true`, which enters the `PENDING` state. Post succesfull payment by the customer, the subscription becomes `ACTIVE`.
2. Here, the invoice is generated at the start of the subscription period.
3. The customer receives access to the service for the applicable billing period.
4. Before the next billing period begins, Transact Bridge generates an invoice for renewal which is auto-approved within fraction of seconds. And then Transact Bridge attempts to collect the recurring amount.
5. If the renewal payment succeeds, the subscription continues into the next billing period.
6. If If the collection fails, Transact Bridge applies the configured retry and invoice handling policies. The subscription configuration includes parameters such as `dayUntillDue`, `maxUnpaidInvoices`, `postMaxUnpaidInvoices`, and `reAttemptConfig` to control unpaid-invoice and retry behavior.

## Prepaid Invoice Flow

```mermaid theme={null}
flowchart TD
    A[Create Subscription<br/>billAtStart: true]
    --> B[PENDING]

    B --> C[Hosted Checkout]

    C --> D[Initial Payment]

    D --> E{Payment Successful?}

    E -->|Yes| F[Invoice Generated]

    F --> G[ACTIVE<br/>Service Access Begins]

    E -->|No| H[Payment Retry or<br/>Pending Expiry]

    G --> I[Customer Uses Service]

    I --> J[Next Billing Cycle]

    J --> K[Renewal Invoice Generated]

    K --> L[Automatic Collection<br/>from Saved Mandate]

    L --> M{Renewal Payment Successful?}

    M -->|Yes| N[Next Billing Period]

    N --> I

    M -->|No| O[Retries / Due / Overdue<br/>Policy]

    O --> L
```

## Example: Monthly Prepaid Subscription

Consider a customer subscribing to a monthly plan.

```text theme={null}
Plan:
Monthly Subscription

Amount:
₹999

Frequency:
MNTH

```

### Step 1: Subscription Creation/Activation

The merchant creates the subscription with:

```json theme={null}
{
  "frequency": "MNTH",
  "billAtStart": true,
 
}
```

The subscription is created in the `PENDING` state. The customer receives the payment URL and makes the payment of `₹999`. After successful payment the subscription becomes `ACTIVE`, and the customer can access the service.
The invoice for the subscription period is generated at the start of the subscription period.

### Step 2: Customer Uses the Service

Assume the customer starts the subscription on **1 August**.

```text theme={null}
1 August
   |
   | ₹999 paid
   |
   | Subscription becomes ACTIVE
   |
   | Customer gets access
   |
   |-----------------------------|
   |      August Service         |
   |-----------------------------|
                               31 August
```

The customer has prepaid for the August service period.

### Step 3: Renewal

Before the next billing period begins, Transact Bridge generates the renewal invoice and attempts to collect the recurring amount.

```text theme={null}
31 August
    |
    v
Renewal Invoice
    |
    v
Automatic Collection
    |
    v
₹999 collected
    |
    v
September Access
```

If the payment succeeds, the customer continues to have access during September.

## Prepaid vs Postpaid Invoice

|                    | Prepaid                                     | Postpaid                              |
| ------------------ | ------------------------------------------- | ------------------------------------- |
| Configuration      | `billAtStart: true`                         | `billAtStart: false`                  |
| When customer pays | Before service access                       | After service usage                   |
| Initial activation | Payment required                            | Payment method authorization          |
| Initial invoice    | Generated at start of subscription period   | Generated at end of billing period    |
| Renewal            | Amount collected before next service period | Amount collected after billing period |
| Typical use case   | Fixed-price subscriptions                   | Usage-based or metered services       |
