A usage-based plan connects one or more pricing models to a recurring billing schedule.
Create a usage-based plan
POST {{base_url}}/public/v1/plan
JSON
{
"name": "Nexa Cloud monthly usage",
"interval": "month",
"every": 1,
"billing_cycle": "usage",
"billing_cycle_anchor_config": {
"day_of_month": 1
},
"product": [
{
"product_id": "{{product_id}}",
"quantity": 1
}
],
"is_usage_based": true,
"pricing_models": [
"{{pricing_model_id}}"
]
}Usage-based plan rules:
All pricing models on one plan must use the same
type. A plan can contain multiple one-time models or multiple recurring models, but it can't mix the two.is_usage_basedistrue.pricing_modelsis a non-empty array of unique pricing model IDs.- Every pricing model belongs to the same merchant account, store, mode, and environment as the plan.
- The product and calendar fields follow the Plans and billing cycles.
Attach more pricing models
POST {{base_url}}/public/v1/plan/pricing/models/{plan_id}
JSON
{
"pricing_models": [
"{{additional_pricing_model_id}}"
]
}XPay accepts the request when:
- The plan is usage-based.
- Each pricing model exists and isn't already attached.
- The new pricing models use the same
typeas the plan's existing pricing models.
Retrieve the plan after the request and store the complete pricing_models array.
See Usage-based pricing models for how XPay evaluates the models attached to a plan.
Before accepting usage
Verify the complete configuration:
- The product is active.
- The plan is active and usage-based.
- Every pricing model is available.
- Every pricing model component references an active meter.
- The subscription was created under this plan.
An event is rejected when its meter isn't referenced by a pricing model attached to the subscription's plan.