The purchase
resource and its associated operations on this page are deprecated. Avoid using them in your integrations. The ability to purchase multiple plans in a single subscription will be supported through the Subscriptions API in the future.
The purchase
resource represents a collection of item prices bought together. A purchase can contain one or more of the following:
subscription
resource consists of item prices such that at least one of the item prices belongs to an item
of type
plan
.)Prerequisite
Purchases must be enabled explicitly for the site. If not already enabled, contact eap@chargebee.com. Purchases require the following features to work so they’re automatically enabled along with them:
Note
Once created, Chargebee never modifies a purchase
resource; it cannot be modified via API either.
{
"created_at": 1651662622,
"customer_id": "__test__rHsiT4rY1zmz",
"id": "__test__rHsiT4rY2hC1A",
"invoice_ids": [
"__demo_inv__1",
"__demo_inv__2"
],
"object": "purchase",
"subscription_ids": [
"__test__rHsiT4rY2Lr12",
"__test__rHsiT4rY2R615"
]
}
The purchase
resource and its associated operations on this page are deprecated. Avoid using them in your integrations. The ability to purchase multiple plans in a single subscription will be supported through the Subscriptions API in the future.
Creates a purchase
resource. A purchase can contain one or more of the following:
subscription
resource consists of item prices such that at least one of the item prices belongs to an item
of type
plan
.)Note
Providing shipping_addresses[]
is required when the Orders feature has been enabled.
purchase_item
groups
When creating a purchase, you must specify the group or index
to which each item price belongs. You can do this by setting the purchase_items[index]
for each item price. Item prices with the same purchase_items[index]
belong to the same group.
The grouping of item prices allows you to specify the discounts[]
applicable for each group and indicate which item prices should be added to any subscriptions you want to create. Groups can be one of two types:
The following subsections describe the types of groups in detail.
Note
You can specify up to 10 groups,
The total limit for group items for a single purchase is 60.
To create a subscription, specify a subscription group. A subscription group is a group of item prices that contains exactly one item price of type
plan
. To create multiple subscriptions, provide multiple subscription groups.
Note
A subscription group can have up to 20 non-plan item prices. To increase this limit to a maximum of 60, contact eap@chargebee.com.
Purchase API supports custom fields of Subscriptions, use the following format to specify custom fields in Purchase API: subscription_info[custom_field]
.
A one-time charge group is a group of charge item prices (i.e. item prices belonging to items of type
charge
). Charge item prices can be added to subscription groups as well. The charges within and across each one-time group must be unique.
Note
Discounts, both manual discounts and coupons, can be applied to groups by specifying the discounts[]
array. The following table describes the method of application based on whether discounts[index][i]
is provided:
discounts[index][i] is provided |
discounts[index][i] is not provided |
|
Coupons |
|
|
Manual discounts |
|
|
curl https://{site}.chargebee.com/api/v2/purchases \ -u {site_api_key}:\ -d customer_id="__test__XpbG9acT88TIfH3T" \ -d "purchase_items[index][0]"=1 \ -d "purchase_items[item_price_id][0]"="basic-USD" \ -d "purchase_items[quantity][0]"=10 \ -d "purchase_items[index][1]"=2 \ -d "purchase_items[item_price_id][1]"="basic-USD-yearly" \ -d "purchase_items[quantity][1]"=5
curl https://{site}.chargebee.com/api/v2/purchases \ -u {site_api_key}:\ -d customer_id="__test__XpbG9acT88TJ8h43" \ -d "purchase_items[index][0]"=1 \ -d "purchase_items[item_price_id][0]"="basic-USD" \ -d "purchase_items[quantity][0]"=5 \ -d "purchase_items[index][1]"=1 \ -d "purchase_items[item_price_id][1]"="day-pass-USD" \ -d "purchase_items[index][2]"=2 \ -d "purchase_items[item_price_id][2]"="basic-USD-yearly" \ -d "purchase_items[quantity][2]"=5 \ -d "purchase_items[index][3]"=2 \ -d "purchase_items[item_price_id][3]"="day-pass-USD"
curl https://{site}.chargebee.com/api/v2/purchases \ -u {site_api_key}:\ -d customer_id="__test__XpbG9acT88TIuk3m" \ -d "purchase_items[index][0]"=1 \ -d "purchase_items[item_price_id][0]"="basic-USD" \ -d "purchase_items[quantity][0]"=10 \ -d "purchase_items[index][1]"=2 \ -d "purchase_items[item_price_id][1]"="basic-USD-yearly" \ -d "purchase_items[quantity][1]"=5 \ -d "subscription_info[index][0]"=1 \ -d "subscription_info[subscription_id][0]"="sub-1" \ -d "subscription_info[index][1]"=2 \ -d "subscription_info[subscription_id][1]"="sub-2"
payment_schedule_scheme
, used to create the payment schedules. checkout_com
: While adding a new payment method using permanent token or passing raw card details to Checkout.com, document
ID and country_of_residence
are required to support payments through dLocal.payer
: User related information.country_of_residence
: This is required since the billing country associated with the user’s payment method may not be the same as their country of residence. Hence the user’s country of residence needs to be specified. The country code should be a two-character ISO code.document
: Document ID is the user’s identification number based on their country.bluesnap
: While passing raw card details to BlueSnap, if fraud_session_id
is added, additional validation is performed to avoid fraudulent transactions.fraud
: Fraud identification related information.fraud_session_id
: Your BlueSnap fraud session ID required to perform anti-fraud validation.braintree
: While passing raw card details to Braintree, your fraud_merchant_id
and the user’s device_session_id
can be added to perform additional validation and avoid fraudulent transactions.fraud
: Fraud identification related information.device_session_id
: Session ID associated with the user's device.fraud_merchant_id
: Your merchant ID for fraud detection.chargebee_payments
: While passing raw card details to Chargebee Payments, if fraud_session_id
is added, additional validation is performed to avoid fraudulent transactions.fraud
: Fraud identification related information.fraud_session_id
: Your Chargebee Payments fraud session ID required to perform anti-fraud validation.bank_of_america
: While passing raw card details to Bank of America, your user’s device_session_id
can be added to perform additional validation and avoid fraudulent transactions.fraud
: Fraud identification related information.device_session_id
: Session ID associated with the user's device.ecentric
: This parameter is used to verify and process payment method details in Ecentric. If the merchant_id
parameter is included, Chargebee will vault it / perform a lookup and verification against this merchant_id
, overriding the one configured in Chargebee. If tokens and processing occur in the same Merchant GUID, you can just skip this part. merchant_id
: Merchant GUID where the card is vaulted or need to be vaulted.ebanx
: While passing raw card details to EBANX, the user's document
is required for some countries and device_session_id
can be added to perform additional validation and avoid fraudulent transactions. payer
: User related information. document
: Document is the user's identification number based on their country. fraud
: Fraud identification related information. device_session_id
: Session ID associated with the user's device dlocal
: While passing raw card details to D-Local, the user's document
is required for some countries to avoid fraudulent transactions. document
: Document is the user's identification number based on their country. flat_fee
. You can provide this value whether multi-decimal pricing is enabled or disabled. purchase_items[quantity_in_decimal][0..n]
for providing quantity-based item prices when multi-decimal pricing is enabled. When multi-decimal pricing is disabled provide the value in purchase_items[quantity][0..n]
. purchase_items[index]
array. purchase_items[item_price_id]
array. ending_unit_in_decimal
of the very next lower tier. starting_unit_in_decimal
of the very next higher tier. pricing_model
is tiered
or volume
. When the pricing_model
is stairstep
, it is the total price of the item. The currency units in which this value is expressed depends on the type of currency. ending_unit_in_decimal
of the next lower tier. Returned only when the pricing_model is tiered
, volume
or stairstep
and multi-decimal pricing is enabled. starting_unit_in_decimal
of the next higher tier. Returned only when the pricing_model is tiered
, volume
or stairstep
and multi-decimal pricing is enabled. pricing_model
is tiered
or volume
. When the pricing_model
is stairstep
, it is the decimal representation of the total price for the item. The value is in major units of the currency. Returned when the plan is quantity-based and multi-decimal pricing is enabled. mandatory
when providing shipping information. mandatory
when providing shipping information. mandatory
when providing shipping information. mandatory
when providing shipping information. state_code
as AZ
(not US-AZ
). For Tamil Nadu (India), set as TN
(not IN-TN
). For British Columbia (Canada), set as BC
(not CA-BC
). mandatory
when providing shipping information.
Brexit
If you have enabled EU VAT in 2021 or later, or have manually enable the Brexit configuration, then XI
(the code for United Kingdom – Northern Ireland) is available as an option.
mandatory
when providing shipping information. This must be a value from the purchase_items[index]
array. When not provided, the coupon is applied to the first invoice only; irrespective of the values set for coupon.duration_type
or coupon.max_redemptions
.
See also:
The unique ID of a coupon to be applied to the group. Alternatively, you may provide a coupon code. Applicable only for coupons.
See also:
The percentage of the discount. Applicable only for manual discounts. For any given array index i
, you must either provide discounts[percentage][i]
or discounts[amount][i]
and never both.
See also:
The absolute value of the discount. The currency units in which this value is expressed depends on the type of currency. Applicable only for manual discounts.
For any given array index i
, you must either provide discounts[percentage][i]
or discounts[amount][i]
and never both.
See also:
For manual discounts, set this to false
if this manual discount should be excluded from monthly recurring revenue (MRR) calculations for the site. The following prerequisites must be met to allow this parameter to be passed:
See also:
purchase_items[index]
array and the group must be a subscription group. billing_cycles
or a custom value depending on the site configuration. 0
and 9
(inclusive) for each group that is to be created. To increase this limit, contact Chargebee Support contract_billing_cycle_on_renewal
.action_at_term_end
for the new contract term is set to renew
.contract_billing_cycle_on_renewal
.action_at_term_end
for the new contract term is set to cancel
.contract_end
, during which the customer is barred from canceling the contract term. The customer is allowed to cancel the contract term via the Self-Serve Portal only before this period. This allows you to have sufficient time for processing the contract term closure The purchase
resource and its associated operations on this page are deprecated. Avoid using them in your integrations. The ability to purchase multiple plans in a single subscription will be supported through the Subscriptions API in the future.
Returns an estimate for creating a purchase
resource. The operation works exactly like Create a purchase, except that only an estimate
resource is returned without an actual purchase
resource being created.
curl https://{site}.chargebee.com/api/v2/purchases/estimate \ -u {site_api_key}:\ -d "purchase_items[index][0]"=1 \ -d "purchase_items[item_price_id][0]"="basic-USD" \ -d "purchase_items[quantity][0]"=10 \ -d "purchase_items[index][1]"=2 \ -d "purchase_items[item_price_id][1]"="basic-USD-yearly" \ -d "purchase_items[quantity][1]"=5
curl https://{site}.chargebee.com/api/v2/purchases/estimate \ -u {site_api_key}:\ -d customer_id="__test__XpbG9acT88TIUT3H" \ -d "purchase_items[index][0]"=1 \ -d "purchase_items[item_price_id][0]"="basic-USD" \ -d "purchase_items[quantity][0]"=5 \ -d "purchase_items[index][1]"=1 \ -d "purchase_items[item_price_id][1]"="day-pass-USD" \ -d "purchase_items[index][2]"=2 \ -d "purchase_items[item_price_id][2]"="basic-USD-yearly" \ -d "purchase_items[quantity][2]"=5 \ -d "purchase_items[index][3]"=2 \ -d "purchase_items[item_price_id][3]"="day-pass-USD"
curl https://{site}.chargebee.com/api/v2/purchases/estimate \ -u {site_api_key}:\ -d customer_id="__test__XpbG9acT88TII837" \ -d "purchase_items[index][0]"=1 \ -d "purchase_items[item_price_id][0]"="basic-USD" \ -d "purchase_items[quantity][0]"=10 \ -d "purchase_items[index][1]"=2 \ -d "purchase_items[item_price_id][1]"="basic-USD-yearly" \ -d "purchase_items[quantity][1]"=5
billing_address
country
as XI
(which is United Kingdom - Northern Ireland).billing_address
country
as XI
. That’s the code for United Kingdom - Northern
Ireland. The first two characters of the VAT number in such a case is
XI
by default. However, if the VAT number was registered in UK, the value should be GB
. Set
vat_number_prefix
to GB
for such cases. true
then the Reverse Charge Mechanism is applicable. This field is applicable only when Australian GST is configured for your site. 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.state_code
as AZ
(not US-AZ
). For Tamil Nadu (India), set as TN
(not IN-TN
). For British Columbia (Canada), set as BC
(not CA-BC
). Brexit
If you have enabled EU VAT in 2021 or later, or have manually enable the Brexit configuration, then XI
(the code for United Kingdom – Northern Ireland) is available as an option.
flat_fee
. You can provide this value whether multi-decimal pricing is enabled or disabled. purchase_items[quantity_in_decimal][0..n]
for providing quantity-based item prices when multi-decimal pricing is enabled. When multi-decimal pricing is disabled provide the value in purchase_items[quantity][0..n]
. purchase_items[index]
array. purchase_items[item_price_id]
array. ending_unit_in_decimal
of the very next lower tier. starting_unit_in_decimal
of the very next higher tier. pricing_model
is tiered
or volume
. When the pricing_model
is stairstep
, it is the total price of the item. The currency units in which this value is expressed depends on the type of currency. ending_unit_in_decimal
of the next lower tier. Returned only when the pricing_model is tiered
, volume
or stairstep
and multi-decimal pricing is enabled. starting_unit_in_decimal
of the next higher tier. Returned only when the pricing_model is tiered
, volume
or stairstep
and multi-decimal pricing is enabled. pricing_model
is tiered
or volume
. When the pricing_model
is stairstep
, it is the decimal representation of the total price for the item. The value is in major units of the currency. Returned when the plan is quantity-based and multi-decimal pricing is enabled. mandatory
when providing shipping information. mandatory
when providing shipping information. mandatory
when providing shipping information. mandatory
when providing shipping information. state_code
as AZ
(not US-AZ
). For Tamil Nadu (India), set as TN
(not IN-TN
). For British Columbia (Canada), set as BC
(not CA-BC
). mandatory
when providing shipping information.
Brexit
If you have enabled EU VAT in 2021 or later, or have manually enable the Brexit configuration, then XI
(the code for United Kingdom – Northern Ireland) is available as an option.
mandatory
when providing shipping information. This must be a value from the purchase_items[index]
array. When not provided, the coupon is applied to the first invoice only; irrespective of the values set for coupon.duration_type
or coupon.max_redemptions
.
See also:
The unique ID of a coupon to be applied to the group. Alternatively, you may provide a coupon code. Applicable only for coupons.
See also:
The percentage of the discount. Applicable only for manual discounts. For any given array index i
, you must either provide discounts[percentage][i]
or discounts[amount][i]
and never both.
See also:
The absolute value of the discount. The currency units in which this value is expressed depends on the type of currency. Applicable only for manual discounts.
For any given array index i
, you must either provide discounts[percentage][i]
or discounts[amount][i]
and never both.
See also:
For manual discounts, set this to false
if this manual discount should be excluded from monthly recurring revenue (MRR) calculations for the site. The following prerequisites must be met to allow this parameter to be passed:
See also:
purchase_items[index]
array and the group must be a subscription group. billing_cycles
or a custom value depending on the site configuration. 0
and 9
(inclusive) for each group that is to be created. To increase this limit, contact Chargebee Support contract_billing_cycle_on_renewal
.action_at_term_end
for the new contract term is set to renew
.contract_billing_cycle_on_renewal
.action_at_term_end
for the new contract term is set to cancel
.contract_end
, during which the customer is barred from canceling the contract term. The customer is allowed to cancel the contract term via the Self-Serve Portal only before this period. This allows you to have sufficient time for processing the contract term closure