Skip to main content

Fetch customer credits ledger

The credits ledger provides auditing functionality over Orb's credits system with a list of actions that have taken place to modify a customer's credit balance. This paginated endpoint lists these entries, starting from the most recent ledger entry.

More details on using Orb's real-time credit feature are here.

There are four major types of modifications to credit balance, detailed below.

Increment

Credits (which optionally expire on a future date) can be added via the API (Add Ledger Entry). The ledger entry for such an action will always contain the total eligible starting and ending balance for the customer at the time the entry was added to the ledger.

Decrement

Deductions can occur as a result of an API call to create a ledger entry (see Add Ledger Entry), or automatically as a result of incurring usage. Both ledger entries present the decrement entry type.

As usage for a customer is reported into Orb, credits may be deducted according to the customer's plan configuration. An automated deduction of this type will result in a ledger entry, also with a starting and ending balance. In order to provide better tracing capabilities for automatic deductions, Orb always associates each automatic deduction with the event_id at the time of ingestion, used to pinpoint why credit deduction took place and to ensure that credits are never deducted without an associated usage event.

By default, Orb uses an algorithm that automatically deducts from the soonest expiring credit block first in order to ensure that all credits are utilized appropriately. As an example, if trial credits with an expiration date of 2 weeks from now are present for a customer, they will be used before any deductions take place from a non-expiring credit block.

If there are multiple blocks with the same expiration date, Orb will deduct from the block with the lower cost basis first (e.g. trial credits with a $0 cost basis before paid credits with a $5.00 cost basis).

It's also possible for a single usage event's deduction to span credit blocks. In this case, Orb will deduct from the next block, ending at the credit block which consists of unexpiring credits. Each of these deductions will lead to a separate ledger entry, one per credit block that is deducted from. By default, the customer's total credit balance in Orb can be negative as a result of a decrement.

Expiration change

The expiry of credits can be changed as a result of the API (See Add Ledger Entry). This will create a ledger entry that specifies the balance as well as the initial and target expiry dates.

Note that for this entry type, starting_balance will equal ending_balance, and the amount represents the balance transferred. The credit block linked to the ledger entry is the source credit block from which there was an expiration change

Credits expiry

When a set of credits expire on pre-set expiration date, the customer's balance automatically reflects this change and adds an entry to the ledger indicating this event. Note that credit expiry should always happen close to a date boundary in the customer's timezone.

Void initiated

Credit blocks can be voided via the API. The amount on this entry corresponds to the number of credits that were remaining in the block at time of void. void_reason will be populated if the void is created with a reason.

Void

When a set of credits is voided, the customer's balance automatically reflects this change and adds an entry to the ledger indicating this event.

Amendment

When credits are added to a customer's balance as a result of a correction, this entry will be added to the ledger to indicate the adjustment of credits.

Path Parameters
    customer_id string required
Query Parameters
    limit integer

    Default value: 20

    cursor string
    currency string
    minimum_amount string
    entry_type string

    Possible values: [increment, decrement, expiration_change, credit_block_expiry, void, void_initiated, amendment]

    entry_status string

    Possible values: [committed, pending]

    created_at[gte] date-time
    created_at[gt] date-time
    created_at[lt] date-time
    created_at[lte] date-time
Responses

OK

Response Headers

    Schema
      data object[] required
    • Array [
    • oneOf

      metadata object required

      User specified key-value pairs for the resource. If not present, this defaults to an empty dictionary. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

      property name* string
      id string required
      ledger_sequence_number integer required
      entry_status string required

      Possible values: [committed, pending]

      customer object required
      id string required
      external_customer_id string nullable required
      starting_balance number required
      ending_balance number required
      amount number required
      currency string required
      created_at date-time required
      description string nullable required
      credit_block object required
      id string required
      expiry_date date-time nullable required
      per_unit_cost_basis string nullable required
      entry_type string required

      Possible values: [increment]

    • ]
    • pagination_metadata object required
      has_more boolean required
      next_cursor string nullable required
    Loading...