Create ledger entry by external ID
This endpoint allows you to create a new ledger entry for a specified customer's balance. This can be used to increment balance, deduct credits, and change the expiry date of existing credits.
Effects of adding a ledger entry
- After calling this endpoint, Fetch Credit Balance will return a credit block that represents the changes (i.e. balance changes or transfers).
- A ledger entry will be added to the credits ledger for this customer, and therefore returned in the View Credits Ledger response as well as serialized in the response to this request. In the case of deductions without a specified block, multiple ledger entries may be created if the deduction spans credit blocks.
- If
invoice_settings
is specified, an invoice will be created that reflects the cost of the credits (based onamount
andper_unit_cost_basis
).
Adding credits
Adding credits is done by creating an entry of type increment
. This requires the caller to specify a number of
credits as well as an optional expiry date in YYYY-MM-DD
format. Orb also recommends specifying a description
to assist with auditing. When adding credits, the caller can also specify a cost basis per-credit, to indicate
how much in USD a customer paid for a single credit in a block. This can later be used for revenue recognition.
The following snippet illustrates a sample request body to increment credits which will expire in January of 2022.
{
"entry_type": "increment",
"amount": 100,
"expiry_date": "2022-12-28",
"per_unit_cost_basis": "0.20",
"description": "Purchased 100 credits"
}
Note that by default, Orb will always first increment any negative balance in existing blocks before adding the remaining amount to the desired credit block.
Invoicing for credits
By default, Orb manipulates the credit ledger but does not charge for credits. However, if you pass
invoice_settings
in the body of this request, Orb will also generate a one-off invoice for the customer for the
credits pre-purchase. Note that you must provide the per_unit_cost_basis
, since the total charges on the
invoice are calculated by multiplying the cost basis with the number of credit units added.
Deducting Credits
Orb allows you to deduct credits from a customer by creating an entry of type decrement
. Orb matches the
algorithm for automatic deductions for determining which credit blocks to decrement from. In the case that the
deduction leads to multiple ledger entries, the response from this endpoint will be the final deduction. Orb also
optionally allows specifying a description to assist with auditing.
The following snippet illustrates a sample request body to decrement credits.
{
"entry_type": "decrement",
"amount": 20,
"description": "Removing excess credits"
}
Changing credits expiry
If you'd like to change when existing credits expire, you should create a ledger entry of type expiration_change
.
For this entry, the required parameter expiry_date
identifies the originating block, and the required parameter
target_expiry_date
identifies when the transferred credits should now expire. A new credit block will be created
with expiry date target_expiry_date
, with the same cost basis data as the original credit block, if present.
Note that the balance of the block with the given expiry_date
must be at least equal to the desired transfer
amount determined by the amount
parameter.
The following snippet illustrates a sample request body to extend the expiration date of credits by one year:
{
"entry_type": "expiration_change",
"amount": 10,
"expiry_date": "2022-12-28",
"block_id": "UiUhFWeLHPrBY4Ad",
"target_expiry_date": "2023-12-28",
"description": "Extending credit validity"
}
Voiding credits
If you'd like to void a credit block, create a ledger entry of type void
. For this entry, block_id
is required
to identify the block, and amount
indicates how many credits to void, up to the block's initial balance. Pass
in a void_reason
of refund
if the void is due to a refund.
Amendment
If you'd like to undo a decrement on a credit block, create a ledger entry of type amendment
. For this entry, block_id
is required to identify the block that was originally decremented from, and amount
indicates how many credits to return
to the customer, up to the block's initial balance.
Path Parameters
Request Body required
metadata object nullable
User-specified key/value pairs for the resource. Individual keys can be removed by setting the value to null
, and the entire metadata mapping can be cleared by setting metadata
to null
.
The currency or custom pricing unit to use for this ledger entry. If this is a real-world currency, it must match the customer's invoicing currency.
Optional metadata that can be specified when adding ledger results via the API. For example, this can be used to note an increment refers to trial credits, or for noting corrections as a result of an incident, etc.
Possible values: [increment
]
The number of credits to effect. Note that this is required for increment, decrement, void, or undo operations.
expiry_date object nullable
An ISO 8601 format date that denotes when this credit balance should expire.
string
An ISO 8601 format date that denotes when this credit balance should expire.
string
An ISO 8601 format date that denotes when this credit balance should expire.
effective_date object nullable
An ISO 8601 format date that denotes when this credit balance should become available for use.
string
An ISO 8601 format date that denotes when this credit balance should become available for use.
string
An ISO 8601 format date that denotes when this credit balance should become available for use.
Can only be specified when entry_type=increment. How much, in the customer's currency, a customer paid for a single credit in this block
invoice_settings object nullable
Whether the credits purchase invoice should auto collect with the customer's saved payment method.
The net terms determines the difference between the invoice date and the issue date for the invoice. If you intend the invoice to be due on issue, set this to 0.
An optional memo to display on the invoice.
Default value: false
If true, the new credit block will require that the corresponding invoice is paid before it can be drawn down from.
metadata object nullable
User-specified key/value pairs for the resource. Individual keys can be removed by setting the value to null
, and the entire metadata mapping can be cleared by setting metadata
to null
.
The currency or custom pricing unit to use for this ledger entry. If this is a real-world currency, it must match the customer's invoicing currency.
Optional metadata that can be specified when adding ledger results via the API. For example, this can be used to note an increment refers to trial credits, or for noting corrections as a result of an incident, etc.
Possible values: [decrement
]
The number of credits to effect. Note that this is required for increment, decrement, void, or undo operations.
metadata object nullable
User-specified key/value pairs for the resource. Individual keys can be removed by setting the value to null
, and the entire metadata mapping can be cleared by setting metadata
to null
.
The currency or custom pricing unit to use for this ledger entry. If this is a real-world currency, it must match the customer's invoicing currency.
Optional metadata that can be specified when adding ledger results via the API. For example, this can be used to note an increment refers to trial credits, or for noting corrections as a result of an incident, etc.
Possible values: [expiration_change
]
The number of credits to effect. Note that this is required for increment, decrement, void, or undo operations.
expiry_date object nullable required
An ISO 8601 format date that identifies the origination credit block to expire
string
An ISO 8601 format date that identifies the origination credit block to expire
string
An ISO 8601 format date that identifies the origination credit block to expire
The ID of the block affected by an expiration_change, used to differentiate between multiple blocks with the same expiry_date
.
A future date (specified in YYYY-MM-DD format) used for expiration change, denoting when credits transferred (as part of a partial block expiration) should expire.
metadata object nullable
User-specified key/value pairs for the resource. Individual keys can be removed by setting the value to null
, and the entire metadata mapping can be cleared by setting metadata
to null
.
The currency or custom pricing unit to use for this ledger entry. If this is a real-world currency, it must match the customer's invoicing currency.
Optional metadata that can be specified when adding ledger results via the API. For example, this can be used to note an increment refers to trial credits, or for noting corrections as a result of an incident, etc.
Possible values: [void
]
The ID of the block to void.
Possible values: [refund
]
Can only be specified when entry_type=void
. The reason for the void.
The number of credits to effect. Note that this is required for increment, decrement, void, or undo operations.
metadata object nullable
User-specified key/value pairs for the resource. Individual keys can be removed by setting the value to null
, and the entire metadata mapping can be cleared by setting metadata
to null
.
The currency or custom pricing unit to use for this ledger entry. If this is a real-world currency, it must match the customer's invoicing currency.
Optional metadata that can be specified when adding ledger results via the API. For example, this can be used to note an increment refers to trial credits, or for noting corrections as a result of an incident, etc.
Possible values: [amendment
]
The number of credits to effect. Note that this is required for increment, decrement or void operations.
The ID of the block to reverse a decrement from.
- 201
- 400
- 401
- 404
- 409
- 413
- 429
- 500
Created
Response Headers
Schema
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
.
Possible values: [committed
, pending
]
customer object required
credit_block object required
Possible values: [increment
]
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
.
Possible values: [committed
, pending
]
customer object required
credit_block object required
Possible values: [decrement
]
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
.
Possible values: [committed
, pending
]
customer object required
credit_block object required
Possible values: [expiration_change
]
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
.
Possible values: [committed
, pending
]
customer object required
credit_block object required
Possible values: [credit_block_expiry
]
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
.
Possible values: [committed
, pending
]
customer object required
credit_block object required
Possible values: [void
]
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
.
Possible values: [committed
, pending
]
customer object required
credit_block object required
Possible values: [void_initiated
]
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
.
Possible values: [committed
, pending
]
customer object required
credit_block object required
Possible values: [amendment
]
{}
Bad Request
Response Headers
Schema
Possible values: [https://docs.withorb.com/reference/error-responses#400-constraint-violation
]
Possible values: [400
]
Possible values: [https://docs.withorb.com/reference/error-responses#400-duplicate-resource-creation
]
Possible values: [400
]
Possible values: [https://docs.withorb.com/reference/error-responses#400-request-validation-errors
]
Possible values: [400
]
{}
Unauthorized
Response Headers
Schema
Possible values: [https://docs.withorb.com/reference/error-responses#401-authentication-error
]
Possible values: [401
]
{
"type": "https://docs.withorb.com/reference/error-responses#401-authentication-error",
"status": 401,
"detail": "string",
"title": "string"
}
Not Found
Response Headers
Schema
Possible values: [https://docs.withorb.com/reference/error-responses#404-feature-not-available
]
Possible values: [400
]
Possible values: [https://docs.withorb.com/reference/error-responses#404-resource-not-found
]
Possible values: [404
]
Possible values: [https://docs.withorb.com/reference/error-responses#404-url-not-found
]
Possible values: [404
]
{}
Conflict
Response Headers
Schema
Possible values: [https://docs.withorb.com/reference/error-responses#409-resource-conflict
]
Possible values: [409
]
{
"type": "https://docs.withorb.com/reference/error-responses#409-resource-conflict",
"status": 409,
"detail": "string",
"title": "string"
}
Request Entity Too Large
Response Headers
Schema
Possible values: [https://docs.withorb.com/reference/error-responses#413-request-too-large
]
Possible values: [413
]
Possible values: [https://docs.withorb.com/reference/error-responses#413-resource-too-large
]
Possible values: [413
]
Possible values: [https://docs.withorb.com/reference/error-responses#413-too-many-results
]
Possible values: [413
]
{}
Too Many Requests
Response Headers
Schema
Possible values: [https://docs.withorb.com/reference/error-responses#429-too-many-requests
]
Possible values: [429
]
{
"type": "https://docs.withorb.com/reference/error-responses#429-too-many-requests",
"status": 429,
"detail": "string",
"title": "string"
}
Internal Server Error
Response Headers
Schema
Possible values: [https://docs.withorb.com/reference/error-responses#500-internal-server-error
]
{
"type": "https://docs.withorb.com/reference/error-responses#500-internal-server-error",
"status": 0,
"detail": "string",
"title": "string"
}