Estimates, as the name implies, can be used to find out the estimate for performing an operation as against performing the operation itself. i.e Say you want to create a new subscription or update an existing one, using the estimate API one can deduce the details like how much money the customer needs to be charged for this operation, when it should be collected, the state the subscription would be in etc.
Note:
- Invoking these APIs do not perform the actual operation but just generates an estimate.
- Prorated Credits and Promotional Credits are not taken into account while generating the estimate.
Sample estimate [ JSON ]
{
"amount": 895,
"amount_due": 895,
"collect_now": true,
"created_at": 1517506678,
"credits_applied": 0,
"line_items": [
{
"amount": 895,
"date_from": 1517506678,
"date_to": 1519925878,
"description": "No Trial",
"entity_id": "no_trial",
"entity_type": "plan",
"is_taxed": false,
"object": "line_item",
"quantity": 1,
"tax": 0,
"type": "charge",
"unit_amount": 895
}
],
"object": "estimate",
"price_type": "tax_exclusive",
"recurring": true,
"sub_total": 895,
"subscription_status": "active",
"term_ends_at": 1519925878
}
API Index URL GET
https://{site}.chargebee.com/api/v1/estimates
timestamp(UTC) in seconds The time at which this estimate got generated
boolean, default=true Whether or not the estimate for the invoice is recurring. Will be 'true' or 'false' for subscription related estimates.
optional, string, max chars=100 Applicable only for subsctiption related estimates. The identifier of the subscription this estimate belongs to.
optional, enumerated string Applicable only for subsctiption related estimates. The post-operation status of the subscription. Possible values are
futureThe subscription is scheduled to start at a future date.in_trialThe subscription is in trial.activeThe subscription is active and will be charged for automatically based on the items in it.non_renewingThe subscription will be canceled at the end of the current term.
Show all values[+]
optional, timestamp(UTC) in seconds Applicable only for subsctiption related estimates. End of the current billing term
boolean 'true' means the estimate amount needs to be collected immediately, whereas 'false' means the estimate amount needs to be collected at the term-end
enumerated string, default=tax_exclusive The price type of the invoice. Possible values are
tax_exclusiveAll amounts in the document are exclusive of tax.tax_inclusiveAll amounts in the document are inclusive of tax.
Show all values[+]
in cents, default=0, min=0 Total estimate amount in cents. The 'collect_now' field indicates when this amount needs to be collected.
in cents, default=0, min=0 credits applied to this invoice in cents.
in cents, default=0, min=0 Invoice amount due in cents
in cents, min=0 The sub-total amount optional, list of line_item
The list of items in this estimate
timestamp(UTC) in seconds Start date of this line item.
timestamp(UTC) in seconds End date of this line item.
in cents Unit amount of the line item.
optional, in cents Total amount of this line item. Typically equals to unit amount x quantity
boolean, default=false Specifies whether this line item is taxed or not
optional, in cents, default=0, min=0 The tax amount charged for this item
optional, double, min=0.0, max=100.0 Rate of tax used to calculate tax for this lineitem
optional, string, max chars=40 Invoice Reference Line Item ID
string, max chars=250 Detailed description about this line item.
enumerated string Type of this lineitem. This along with 'entity_type' and 'entity_id' attributes consitutes the meta information of this lineitem. Possible values are
chargeRepresents the 'charge' lineitems in invoice. The 'entity_type' attribute further identifies the modelled entity (plan / addon etc) this charge is based onprorated_chargeRepresents the 'charge' lineitems that are pro-rated. The 'entity_type' attribute further identifies the modelled entity (plan / addon etc) this 'prorated charge' is based onsetup_chargeRepresents the 'setup charge' lineitem in invoice-which is a one-time charge included only in the first invoice of the subscription
Show all values[+]
enumerated string Specifies the modelled entity this line item is based on. Possible values are
planIndicates that this lineitem is based on 'Plan' entity. The 'entity_id' attribute specifies the plan idaddonIndicates that this lineitem is based on 'Addon' entity. The 'entity_id' attribute specifies the addon idadhocIndicates that this lineitem is not modelled. i.e created adhoc. So the 'entity_id' attribute will be null in this case Show all values[+]
optional, string, max chars=100 The identifier of the modelled entity this line item is based on. Will be null for 'adhoc' entity type optional, list of discount
The list of discounts applied to this estimate
in cents, min=0 The amount deducted. The format of this value depends on the kind of currency.
optional, string, max chars=250 Description for this deduction.
enumerated string Type of this Discount lineitem Possible values are
couponRepresents the coupon discount items in invoice. Further the 'entity_id' attribute specifies the coupon id this discount is based oncredit_adjustmentRepresents the Prorated Credits items in invoice. The 'entity_id' attribute will be null in this caseaccount_creditsRepresents the Promotional Credits item in invoice. The 'entity_id' attribute will be null in this case Show all values[+]
optional, string, max chars=100 When the deduction is due to a coupon
, then this is the id
of the coupon. optional, list of tax
The list of taxes applied to this estimate
in cents, min=0 The tax amount.
optional, string, max chars=250 Description of the tax item.
timestamp(UTC) in seconds The time at which this estimate got generated
boolean, default=true Whether or not the estimate for the invoice is recurring. Will be 'true' or 'false' for subscription related estimates.
optional, string, max chars=100 Applicable only for subsctiption related estimates. The identifier of the subscription this estimate belongs to.
optional, enumerated string Applicable only for subsctiption related estimates. The post-operation status of the subscription. Possible values are
futureThe subscription is scheduled to start at a future date.in_trialThe subscription is in trial.activeThe subscription is active and will be charged for automatically based on the items in it.non_renewingThe subscription will be canceled at the end of the current term.
Show all values[+]
optional, timestamp(UTC) in seconds Applicable only for subsctiption related estimates. End of the current billing term
boolean 'true' means the estimate amount needs to be collected immediately, whereas 'false' means the estimate amount needs to be collected at the term-end
enumerated string, default=tax_exclusive The price type of the invoice. Possible values are
tax_exclusiveAll amounts in the document are exclusive of tax.tax_inclusiveAll amounts in the document are inclusive of tax.
Show all values[+]
in cents, default=0, min=0 Total estimate amount in cents. The 'collect_now' field indicates when this amount needs to be collected.
in cents, default=0, min=0 credits applied to this invoice in cents.
in cents, default=0, min=0 Invoice amount due in cents
in cents, min=0 The sub-total amount
optional, list of line_item The list of items in this estimate
optional, list of discount The list of discounts applied to this estimate
optional, list of tax The list of taxes applied to this estimate Generates an estimate for the 'create subscription' operation. This input will be similar to the
Create Subscription API but no subscription will be created, but just an estimate will be generated.
Note:
- If you use the EU VAT tax option, you need to specify 'billing_address[country]' and 'customer[vat_number]' attributes for the tax calculation to happen. If these attributes are not passed, the tax will be ignored for this estimate.
- If you use the Customized Tax option, you need to specify the shipping address and billing address parameters for the tax calculation to happen. This is because Chargebee will use the customer’s shipping address to determine the tax applicable. If the shipping address is not available, then the billing address will be used to determine tax. If both addresses are not available, tax will be ignored for this estimate.
Related Tutorial
This API is not enabled for live sites by default. Please contact
support to get this enabled.
Sample Request
curl https://{site}.chargebee.com/api/v1/estimates/create_subscription \
-u {site_api_key}:\
-d "subscription[plan_id]"="no_trial" \
-d "billing_address[zip]"="91789" \
-d "billing_address[country]"="US"
Sample Response [ JSON ]
Show more...
{
"estimate": {
"amount": 895,
"amount_due": 895,
"collect_now": true,
"created_at": 1517506678,
"credits_applied": 0,
"line_items": [
{
"amount": 895,
"date_from": 1517506678,
"date_to": 1519925878,
"description": "No Trial",
"entity_id": "no_trial",
"entity_type": "plan",
"is_taxed": false,
"object": "line_item",
"quantity": 1,
"tax": 0,
"type": "charge",
"unit_amount": 895
},
{..}
],
"object": "estimate",
"price_type": "tax_exclusive",
"recurring": true,
"sub_total": 895,
"subscription_status": "active",
"term_ends_at": 1519925878
}
}
URL Format
POST
https://{site}.chargebee.com/api/v1/estimates/create_subscription
optional, integer, min=0 Number of cycles(plan interval) this subscription should be charged. After the billing cycles exhausted, the subscription will be cancelled. subscription[[0..n]][0..n]
optional, string Parameters for subscription billing_address[[0..n]][0..n]
optional, string Parameters for billing_address shipping_address[[0..n]][0..n]
optional, string Parameters for shipping_address
optional, string Parameters for customer
optional, array Parameters for addons. Multiple addons can be passed by specifying unique indices.
Parameters for subscription
pass parameters as subscription[<param name>]
optional, string, max chars=50 required, string, max chars=100 subscription[plan_quantity] optional, integer, default=1, min=1 optional, timestamp(UTC) in seconds optional, timestamp(UTC) in seconds optional, string, max chars=100
Parameters for billing_address
pass parameters as billing_address[<param name>]
billing_address[state_code] optional, string, max chars=50 optional, string, max chars=20 optional, string, max chars=50
Parameters for shipping_address
pass parameters as shipping_address[<param name>]
shipping_address[state_code] optional, string, max chars=50 optional, string, max chars=20 shipping_address[country] optional, string, max chars=50
Parameters for customer
pass parameters as customer[<param name>]
optional, string, max chars=20 optional, enumerated string, default=taxable Possible values are
taxableComputes tax for the customer based on the site configuration. In some cases, depending on the region, shipping_address is needed. If not provided, then billing_address is used to compute tax. If that’s not available either, the tax is taken as zero.exempt- Customer is exempted from tax. When using Chargebee’s native Taxes feature or when using the TaxJar integration, no other action is needed.
- However, when using our Avalara integration, optionally, specify
entity_code
or exempt_number
attributes if you use Chargebee’s AvaTax for Sales or specify exemption_details
attribute if you use Chargebee’s AvaTax for Communications integration. Tax may still be applied by Avalara for certain values of entity_code
/exempt_number
/exemption_details
based on the state/region/province of the taxable address.
Show all values[+]
Parameters for addons. Multiple addons can be passed by specifying unique indices.
pass parameters as addons[<param name>][<idx:0..n>]
optional, string, max chars=100 optional, integer, default=1, min=1
always returned required
Resource object representing estimate
Sample admin console URL
https://{site}.chargebee.com/admin-console/estimates/123x
Create a subscription for the existing estimate of a customer.
This API is not enabled for live sites by default. Please contact
support to get this enabled.
Sample Request
curl https://{site}.chargebee.com/api/v1/customers/__test__5SK2liZoRZxq5Tg18/create_subscription_estimate \
-u {site_api_key}:\
--data-urlencode "subscription[plan_id]"="no_trial"
Sample Response [ JSON ]
Show more...
{
"estimate": {
"amount": 895,
"amount_due": 895,
"collect_now": true,
"created_at": 1517480027,
"credits_applied": 0,
"line_items": [
{
"amount": 895,
"date_from": 1517480027,
"date_to": 1519899227,
"description": "No Trial",
"entity_id": "no_trial",
"entity_type": "plan",
"is_taxed": false,
"object": "line_item",
"quantity": 1,
"tax": 0,
"type": "charge",
"unit_amount": 895
},
{..}
],
"object": "estimate",
"price_type": "tax_exclusive",
"recurring": true,
"sub_total": 895,
"subscription_status": "active",
"term_ends_at": 1519899227
}
}
URL Format
GET
https://{site}.chargebee.com/api/v1/customers/{customer-id}/create_subscription_estimate
optional, boolean, default=false If true, all the existing balances - promotional credits, refundable credits and excess payments - will be included for the invoice estimate.
optional, integer, min=0 Number of cycles(plan interval) this subscription should be charged. After the billing cycles exhausted, the subscription will be cancelled. subscription[[0..n]][0..n]
optional, string Parameters for subscription shipping_address[[0..n]][0..n]
optional, string Parameters for shipping_address
optional, array Parameters for addons. Multiple addons can be passed by specifying unique indices.
Parameters for subscription
pass parameters as subscription[<param name>]
optional, string, max chars=50 required, string, max chars=100 subscription[plan_quantity] optional, integer, default=1, min=1 optional, timestamp(UTC) in seconds optional, timestamp(UTC) in seconds optional, string, max chars=100
Parameters for shipping_address
pass parameters as shipping_address[<param name>]
shipping_address[state_code] optional, string, max chars=50 optional, string, max chars=20 shipping_address[country] optional, string, max chars=50
Parameters for addons. Multiple addons can be passed by specifying unique indices.
pass parameters as addons[<param name>][<idx:0..n>]
optional, string, max chars=100 optional, integer, default=1, min=1
always returned required
Resource object representing estimate
Sample admin console URL
https://{site}.chargebee.com/admin-console/estimates/123x
Generates an estimate for the 'update subscription' operation. The input will be similar to the Update Subscription API but subscription will not be updated, but just an estimate will be generated.
In case 'update subscription' operation will not create an invoice immediately, the estimate generated will be for the 'end of term' invoice. Some of the cases where the invoice will not be generated immediately are
- In case of downgrades only credits will be added to customer.
- 'end_of_term' option is true.
- 'prorate' option is false.
- Only coupon is applied.
Note:
- If you use the EU VAT tax option, you need to specify 'billing_address[country]' and 'customer[vat_number]' attributes for the tax calculation to happen. If these attributes are not passed, the tax will be ignored for this estimate.
- If you use the Customized Tax option, you need to specify the shipping address and billing address parameters for the tax calculation to happen. This is because Chargebee will use the customer’s shipping address to determine the tax applicable. If the shipping address is not available, then the billing address will be used to determine tax. If both addresses are not available, tax will be ignored for this estimate.
This API is not enabled for live sites by default. Please contact
support to get this enabled.
Sample Request
curl https://{site}.chargebee.com/api/v1/estimates/update_subscription \
-u {site_api_key}:\
-d "subscription[id]"="__test__5SK0bLNFRFuBxbNB6" \
-d "subscription[plan_id]"="plan1" \
-d "billing_address[zip]"="91789" \
-d "billing_address[country]"="US"
Sample Response [ JSON ]
Show more...
{
"estimate": {
"amount": 1500,
"amount_due": 1500,
"collect_now": true,
"created_at": 1517506678,
"credits_applied": 0,
"line_items": [
{
"amount": 1500,
"date_from": 1517506678,
"date_to": 1519925878,
"description": "Plan1 - Prorated Charges",
"entity_id": "plan1",
"entity_type": "plan",
"is_taxed": false,
"object": "line_item",
"quantity": 1,
"tax": 0,
"type": "prorated_charge",
"unit_amount": 1500
},
{..}
],
"object": "estimate",
"price_type": "tax_exclusive",
"recurring": true,
"sub_total": 1500,
"subscription_id": "__test__5SK0bLNFRFuBxbNB6",
"subscription_status": "active",
"term_ends_at": 1519925878
}
}
URL Format
POST
https://{site}.chargebee.com/api/v1/estimates/update_subscription
optional, boolean, default=false Should be true if the existing addons should be replaced with the ones that are being passed.
optional, integer, min=0 The number of billing cycles the subscription runs before canceling. If not provided, then the billing cycles set for the plan is used.
optional, boolean
- When
true
: Prorated credits or charges are created as applicable for this change.
- When
false
: The subscription is changed without creating any credits or charges.
- When not provided, the value configured in the site settings is considered.
Caveat
For further changes within the same billing term, when prorate
is set to true
, credits are not created when all the conditions below hold true:
An immediate previous change was made
- with
prorate
set to false
and
- no changes were made to the subscription’s billing term and
- a change was made to either the subscription’s plan, its addons, or the prices of the plan or addons.
optional, boolean, default=false Set this to true if you want the update to be applied at the end of the current subscription billing cycle. include_delayed_charges[]
optional, boolean, default=false If true, all the unbilled charges will be included for the invoice estimate.
optional, boolean, default=false If true, all the existing balances - promotional credits, refundable credits and excess payments - will be included for the invoice estimate. subscription[[0..n]][0..n]
optional, string Parameters for subscription billing_address[[0..n]][0..n]
optional, string Parameters for billing_address shipping_address[[0..n]][0..n]
optional, string Parameters for shipping_address
optional, string Parameters for customer
optional, array Parameters for addons. Multiple addons can be passed by specifying unique indices.
Parameters for subscription
pass parameters as subscription[<param name>]
required, string, max chars=50 optional, string, max chars=100 subscription[plan_quantity] optional, integer, default=1, min=1 optional, timestamp(UTC) in seconds optional, timestamp(UTC) in seconds optional, string, max chars=100
Parameters for billing_address
pass parameters as billing_address[<param name>]
billing_address[state_code] optional, string, max chars=50 optional, string, max chars=20 optional, string, max chars=50
Parameters for shipping_address
pass parameters as shipping_address[<param name>]
shipping_address[state_code] optional, string, max chars=50 optional, string, max chars=20 shipping_address[country] optional, string, max chars=50
Parameters for customer
pass parameters as customer[<param name>]
optional, string, max chars=20
Parameters for addons. Multiple addons can be passed by specifying unique indices.
pass parameters as addons[<param name>][<idx:0..n>]
optional, string, max chars=100 optional, integer, default=1, min=1 addons[proration_type][0..n] optional, enumerated string Possible values are
full_termfull charge will be added for the partial termpartial_termprorated charge will be calculated for the partial term.noneNo charge will be added for the partial term
Show all values[+]
always returned required
Resource object representing estimate
Sample admin console URL
https://{site}.chargebee.com/admin-console/estimates/123x
This returns an estimate of the amount that will be charged when the subscription renews. The estimate is calculated based on the items present in the subscription. This includes the plan, addons and coupons(if any) of the subscription. This API is not supported for "Cancelled" subscriptions.
You can also specify whether you need the estimate to include delayed charges.
For "Non Renewing" subscriptions, only delayed charges(one time charges and non renewing addons) that may have been added to the subscription to be charged at the end of the current term will be included. Plan, addons and coupons(if any) of the subscription will not be included.
This API will not generate a renewal invoice if an advance invoice is already present for the subscription.
This API is not enabled for live sites by default. Please contact
support to get this enabled.
Sample Request
curl https://{site}.chargebee.com/api/v1/subscriptions/__test__5SK0bLNFRFuBxMhAX/renewal_estimate \
-u {site_api_key}:
Sample Response [ JSON ]
Show more...
{
"estimate": {
"amount": 895,
"amount_due": 895,
"collect_now": false,
"created_at": 1517506678,
"credits_applied": 0,
"line_items": [
{
"amount": 895,
"date_from": 1519925877,
"date_to": 1522604277,
"description": "No Trial",
"entity_id": "no_trial",
"entity_type": "plan",
"is_taxed": false,
"object": "line_item",
"quantity": 1,
"tax": 0,
"type": "charge",
"unit_amount": 895
},
{..}
],
"object": "estimate",
"price_type": "tax_exclusive",
"recurring": true,
"sub_total": 895,
"subscription_id": "__test__5SK0bLNFRFuBxMhAX",
"subscription_status": "active",
"term_ends_at": 1519925877
}
}
URL Format
GET
https://{site}.chargebee.com/api/v1/subscriptions/{subscription-id}/renewal_estimate
include_delayed_charges[]
optional, boolean, default=true If true, all the unbilled charges will be included for the invoice estimate.
optional, boolean, default=false If true, all the existing balances - promotional credits, refundable credits and excess payments - will be included for the invoice estimate.
always returned required
Resource object representing estimate
Sample admin console URL
https://{site}.chargebee.com/admin-console/estimates/123x
Generates an estimate for the 'create an invoice' operation. This is similar to the Create an invoice API, but the invoice will not be generated. Only an estimate for this operation is created.
This API is not enabled for live sites by default. Please contact
support to get this enabled.
Sample Request
curl https://{site}.chargebee.com/api/v1/estimates/create_invoice \
-u {site_api_key}:\
-d "invoice[customer_id]"="__test__5SK2liZoRZxq5Dum" \
-d "charges[amount][0]"=1000 \
-d "charges[description][0]"="Adhoc charge"
Sample Response [ JSON ]
Show more...
{
"estimate": {
"amount": 1000,
"amount_due": 1000,
"collect_now": true,
"created_at": 1517480026,
"credits_applied": 0,
"line_items": [
{
"amount": 1000,
"date_from": 1517480026,
"date_to": 1517480026,
"description": "Adhoc charge",
"entity_type": "adhoc",
"is_taxed": false,
"object": "line_item",
"quantity": 1,
"tax": 0,
"type": "charge",
"unit_amount": 1000
},
{..}
],
"object": "estimate",
"price_type": "tax_exclusive",
"recurring": false,
"sub_total": 1000
}
}
URL Format
POST
https://{site}.chargebee.com/api/v1/estimates/create_invoice
optional, string, max chars=100 The 'One Time' coupon to be applied.
optional, string Parameters for invoice
optional, string Parameters for customer billing_address[[0..n]][0..n]
optional, string Parameters for billing_address shipping_address[[0..n]][0..n]
optional, string Parameters for shipping_address
optional, array Parameters for addons. Multiple addons can be passed by specifying unique indices.
optional, array Parameters for charges. Multiple charges can be passed by specifying unique indices.
Parameters for invoice
pass parameters as invoice[<param name>]
optional, string, max chars=50 optional, string, max chars=50 optional, string, max chars=100
Parameters for customer
pass parameters as customer[<param name>]
optional, string, max chars=20 optional, enumerated string, default=taxable Possible values are
taxableComputes tax for the customer based on the site configuration. In some cases, depending on the region, shipping_address is needed. If not provided, then billing_address is used to compute tax. If that’s not available either, the tax is taken as zero.exempt- Customer is exempted from tax. When using Chargebee’s native Taxes feature or when using the TaxJar integration, no other action is needed.
- However, when using our Avalara integration, optionally, specify
entity_code
or exempt_number
attributes if you use Chargebee’s AvaTax for Sales or specify exemption_details
attribute if you use Chargebee’s AvaTax for Communications integration. Tax may still be applied by Avalara for certain values of entity_code
/exempt_number
/exemption_details
based on the state/region/province of the taxable address.
Show all values[+]
Parameters for billing_address
pass parameters as billing_address[<param name>]
billing_address[state_code] optional, string, max chars=50 optional, string, max chars=20 optional, string, max chars=50
Parameters for shipping_address
pass parameters as shipping_address[<param name>]
shipping_address[first_name] optional, string, max chars=150 shipping_address[last_name] optional, string, max chars=150 optional, string, max chars=70 shipping_address[company] optional, string, max chars=250 optional, string, max chars=50 optional, string, max chars=150 optional, string, max chars=150 optional, string, max chars=150 optional, string, max chars=50 shipping_address[state_code] optional, string, max chars=50 optional, string, max chars=50 optional, string, max chars=20 shipping_address[country] optional, string, max chars=50
Parameters for addons. Multiple addons can be passed by specifying unique indices.
pass parameters as addons[<param name>][<idx:0..n>]
optional, string, max chars=100 optional, integer, default=1, min=1
Parameters for charges. Multiple charges can be passed by specifying unique indices.
pass parameters as charges[<param name>][<idx:0..n>]
optional, in cents, min=1 charges[description][0..n] optional, string, max chars=250
always returned required
Resource object representing estimate
Sample admin console URL
https://{site}.chargebee.com/admin-console/estimates/123x