message_credits
.
Upon creating a customer via the create customer API endpoint:
identifier
of the currency (in this case message_credits
). For these
alert types, the thresholds
body parameter is not required, since the threshold is implicitly set to 0 and these alerts fire on either side
of that threshold. As long as these alert configurations are created, you won’t need to store the configuration ID in your data model.message_credits
currency will automatically draw down from the message_credits
prepaid balance. You can mix and match
price currencies in a subscription, and Orb will automatically draw down from the appropriate balance.messages_blocked_until
. When this field is a non-null timestamp in the future,
the customer is blocked from sending messages. When this field is null
, the customer is not blocked from sending messages.credits
.entry_type
= increment
signifies an incrementamount
represents the additional credits being bought.per_unit_cost_basis
represents the cost of each token in your invoicing currency, USD. Set this to $0.01, since each credit costs $0.01.expiry_date
represents when the message_credit
will automatically be depleted. Set this to one year from the current grant date.invoice_settings.auto_collection
to True
,
invoice_settings.require_successful_payment
to True, and invoice_settings.net_terms
to 0.messages_blocked_until
field.
Use the following logic to determine eligibility based on the value of messages_blocked_until
:
null
, your application should allow the customer to send messages. This is the case where the customer has a positive credit balance.MAX_DATE
, your application should block the customer from sending messages. This is the case where the customer has no known credit blocks that
may become effective.messages_blocked_until
. This is the case where the customer had no positive credit balance, but
a credit block may have become effective so a re-query is required.message_credit
s. When testing, parse this webhook and confirm that properties.pricing_unit.name
matches message_credit
.
Simply listening to this webhook is insufficient. This is because webhook systems do not provide ordering guarantees,
and you need to ensure that the customer is only blocked from sending the message under the appropriate conditions.
For example, suppose that a customer has a balance of 10 message credits, sends 10 messages and immediately purchases a new block in quick succession.
In this case, the balance depleted alert may be delivered via webhook after the block has been purchased, and the customer will be erroneously blocked from sending messages.
Instead, you should always re-query the customer’s current credit balance using
the API when you receive a balance depleted webhook.
This API is never cached, and will always return the most up to date balance per the usage events that Orb has ingested; it will also reflect
any other operations that have been performed on the balance, such as the purchase of new credits or the expiration of existing credits. For this request,
be sure to set include_all_blocks=False
to only query for active blocks at the current point in time.
In order to set messages_blocked_until
, use the following logic:
messages_blocked_until
to null
.messages_blocked_until
to the earliest future effective_date
of any of the customer’s credit blocks. If the customer has no
credit blocks effective in the future, set messages_blocked_until
to MAX_DATE
.effective_date
of the entry to match the current_billing_period_start_date
of the
subscription (you’ll need to make sure that you have the latest subscription response).
This amounts to ‘backdating’ the credits to the beginning of the billing period, and ensures that your customer never incurs any overages
for the current billing period. Specifically, if there are seconds or minutes of lag between the consumption of credits and your system consuming
the webhook, your customer may temporarily accrue a small overage charge until product access is blocked (and more credits are bought). When the customer
purchases more credits, the above effective_date
strategy will ensure no charges remain on the current period invoice.
After creating the block, query again for the customer’s current balance using the current credit balance
endpoint and use the same exact logic detailed above, setting messages_blocked_until
to null
, MAX_DATE
, or a different future effective date.
messages_blocked_until
.
messages_blocked_until
to the earliest future effective date
will ensure that future allocations are accounted for in our message sending strategy.
messages_blocked_until
accordingly. If the customer has no remaining blocks after the expiration, messages_blocked_until
will be set to MAX_DATE
.
conversion_rate
to $0.00 for the message_credits
currency, since this will ensure that the customer is not charged for any overages that may occur.
In the vast majority of cases, this is an acceptable tradeoff but reach out to Orb if you want to discuss how faster SLAs may bound the potential overage costs.