ChargebeeAPI

Create a subscription

Idempotency Supported

Note: This operation optionally supports 3DS verification flow. To achieve the same, create the Payment Intent and pass it as input parameter to this API.

Creates a new subscription along with the customer. You can attach a plan, plan quantity, one or more addons and coupon while creating this subscription.

Future Subscriptions

If the start_date is specified, the subscription will be created in 'future' state (.ie, instead of starting immediately it will be scheduled to start at the specified 'start_date'). Besides if 'trial' is specified (plan configuration or specified explicitly using trial_end), the subscription will go into 'trial' state when it starts. Otherwise it will directly become 'active' when it starts.

Trial Period

If the plan has trial period or if the trial_end is specified explicitly, the subscription will be created in 'in_trial' state.

If the card details are passed, it is not charged until the end of the trial period. Incase you need to verify the card you could enable the 'card verification option' in the gateway settings.

Invoice

If the plan does not have a trial period and if any of the recurring items has charges, then a invoice would be raised immediately. If 'auto_collection' is turned 'on', then card attributes are mandatory and subscription will be created only if the payment was successful.

Card details

Passing card details to this API involves PCI liability at your end as sensitive card information passes through your servers. If you wish to avoid that, you can use one of the following integration methodologies if applicable

  • If you are using Stripe gateway, you can use Stripe.js with your checkout form. Take a look at this Stripe tutorial for more details.
  • If you are using Braintree gateway, you can use Braintree.js with your checkout form. Please refer this tutorial for more details.
  • If you are using Authorize.Net gateway, you use Accept.js with your checkout form.
  • In case you are using the Adyen gateway, you will have to use the Adyen's Client Side Encryption to encrypt sensitive cardholder data. Once the cardholder data is encrypted, pass the value in adyen.encrypted.data as temp token in this API. You can also use our Hosted Pages based integration.

Legacy behavior:

  • For sites created before March 1st, 2014: On making this request, the billing_address and vat_number of the customer are deleted and replaced by the values passed with this request. Ensure that you pass the billing address parameters and the vat_number parameters each time you make this request, to avoid losing the same information at the customer-level.
  • For sites created on or after March 1st, 2014: This request does not alter the billing_address and vat_number of the customer.

Sample Request

URL Format

POST https://[site].chargebee.com/api/v2/subscriptions

Input Parameters

id
optional, string, max chars=50

A unique and immutable identifier for the subscription. If not provided, it is autogenerated.

plan_id
required, string, max chars=100

Identifier of the plan for this subscription.

plan_quantity
optional, integer, default=1, min=1

Plan quantity for this subscription.

plan_quantity_in_decimal
optional, string, max chars=33

The decimal representation of the quantity of the plan purchased. Can be provided for quantity-based plans and only when multi-decimal pricing is enabled.

plan_unit_price
optional, in cents, min=0

Plan Unit Amount for create subscription.

plan_unit_price_in_decimal
optional, string, max chars=39

Plan Unit Amount in Decimal for create subscription.

setup_fee
optional, in cents, min=0

Amount that will override the default setup fee. The unit depends on the type of currency .

trial_end
optional, timestamp(UTC) in seconds

The time at which the trial ends for this subscription. Can be specified to override the default trial period.If '0' is passed, the subscription will be activated immediately.

billing_cycles
optional, integer, min=0

Specifies the number of billing cycles for the subscription. The behavior of the subscription after the billing cycles have completed depends on whether the subscription is on a contract term or not.

  • When the subscription is not on a contract term: if billing_cycles is not provided, then the billing cycles set for the plan is used. Moreover, once the billing_cycles have completed, the subscription cancels.
  • When the subscription is on a contract term: Providing billing_cycles is mandatory. Moreover, once the billing_cycles have completed, the behavior of the subscription is determined by the contract_term[action_at_term_end] parameter.
mandatory_addons_to_remove
optional, string

List of addons IDs that are mandatory to the plan and has to be removed from the subscription.

start_date
optional, timestamp(UTC) in seconds

The date/time at which the subscription is to start. If not provided, the subscription starts immediately. You can provide a value in the past as well. This is called backdating the subscription creation and is done when the subscription has already been provisioned but its billing has been delayed. Backdating is allowed only when the following prerequisites are met:

  • Backdating is enabled for subscription creation operations.
  • The current day of the month does not exceed the limit set in Chargebee for backdating such operations. This day is typically the day of the month by which the accounting for the previous month must be closed.
  • The date is not more than duration X into the past, where X is the billing period of the plan. For example, if the period of the plan in the subscription is 2 months and today is 14th April, start_date cannot be earlier than 14th February. .
auto_collection
optional, enumerated string

Defines whether payments need to be collected automatically for this subscription. Overrides customer's auto-collection property.

Possible Enum Values
on

Whenever an invoice is created for this subscription, an automatic charge will be attempted on the payment method available.

off

Automatic collection of charges will not be made for this subscription. Use this for offline payments.

terms_to_charge
optional, integer, min=1

The number of subscription billing cycles (including the first one) to invoice in advance .

billing_alignment_mode
optional, enumerated string

Override the billing alignment mode for Calendar Billing. Only applicable when using Calendar Billing. The default value is that which has been configured for the site.

Possible Enum Values
immediate

Subscription period will be aligned with the configured billing date immediately, with credits or charges raised accordingly..

delayed

Subscription period will be aligned with the configured billing date at the next renewal.

offline_payment_method
optional, enumerated string

The preferred offline payment method for the subscription.

Possible Enum Values
no_preference

No Preference

cash

Cash

check

Check

bank_transfer

Bank Transfer

ach_credit

ACH Credit

po_number
optional, string, max chars=100

Purchase order number for this subscription.

coupon_ids
optional, string

List of coupons to be applied to this subscription. You can provide coupon ids or coupon codes.

token_id
optional, string, max chars=40

The Chargebee payment token generated by Chargebee JS.

Note: The payment token created via Chargebee JS uses the gateway selected through Smart Routing. Explicitly passing a gateway_id in this API call will not override the gateway associated with the token.

affiliate_token
optional, string, max chars=250

A unique tracking token.

invoice_notes
optional, string, max chars=2000

A customer-facing note added to all invoices associated with this subscription. This note is one among all the notes displayed on the invoice PDF.

invoice_date
optional, timestamp(UTC) in seconds

The document date displayed on the invoice PDF. The default value is the current date. Provide this value to backdate the invoice. Backdating an invoice is done for reasons such as booking revenue for a previous date or when the subscription is effective as of a past date. Moreover, if create_pending_invoices is set to true , and if the site is configured to set invoice dates to the date of closing, then upon invoice closure, this date is changed to the invoice closing date. taxes and line_item_taxes are computed based on the tax configuration as of invoice_date. When passing this parameter, the following prerequisites must be met:

  • invoice_date must be in the past.
  • It is not earlier than start_date.
  • It is not more than one calendar month into the past. Eg. If today is 13th January, then you cannot pass a value that is earlier than 13th December.
  • invoice_immediately is true. .
meta_data
optional, jsonobject

A collection of key-value pairs that provides extra information about the subscription.

Note: There's a character limit of 65,535.

Learn more .

invoice_immediately
optional, boolean

If there are charges raised immediately for the subscription, this parameter specifies whether those charges are to be invoiced immediately or added to unbilled charges. The default value is as per the site settings .

Note: invoice_immediately only affects charges that are raised at the time of execution of this API call. Any charges scheduled to be raised in the future are not affected by this parameter.

.

free_period
optional, integer, min=1

The period of time by which the first term of the subscription is to be extended free-of-charge. The value must be in multiples of free_period_unit.

free_period_unit
optional, enumerated string

The unit of time in multiples of which the free_period parameter is expressed. The value must be equal to or lower than the period_unit attribute of the plan chosen.

Possible Enum Values
day

Charge based on day(s)

week

Charge based on week(s)

month

Charge based on month(s)

year

Charge based on year(s)

contract_term_billing_cycle_on_renewal
optional, integer, min=1, max=100

Number of billing cycles the new contract term should run for, on contract renewal. The default value is the same as billing_cycles or a custom value depending on the site configuration .

trial_end_action
optional, enumerated string

Applicable only when End-of-trial Action has been enabled for the site. Whenever the subscription has a trial period, this attribute (parameter) is returned (required) and specifies the operation to be carried out for the subscription once the trial ends.

Possible Enum Values
site_default

This is the default value. The action configured for the site at the time when the trial ends, takes effect.

plan_default

The action configured for the site at the time when the trial ends, takes effect.

activate_subscription

The subscription activates and charges are raised for non-metered items.

cancel_subscription

The subscription cancels.

client_profile_id
optional, string, max chars=50

Indicates the Client profile id for the customer. This is applicable only if you use Chargebee's AvaTax for Communications integration.

payment_initiator
optional, enumerated string

The type of initiator to be used for the payment request triggered by this operation.

Possible Enum Values
customer

Pass this value to indicate that the request is initiated by the customer

merchant

Pass this value to indicate that the request is initiated by the merchant

customer
optional, string

Parameters for customer

card
optional, string

Parameters for card

bank_account
optional, string

Parameters for bank_account

payment_method
optional, enumerated string

Parameters for payment_method

payment_intent
optional, string

Parameters for payment_intent

billing_address
optional, string

Parameters for billing_address

shipping_address
optional, string

Parameters for shipping_address

statement_descriptor
optional, string

Parameters for statement_descriptor

contract_term
optional, enumerated string

Parameters for contract_term

entity_identifiers
optional, string

Parameters for entity_identifiers

tax_providers_fields
optional, string

Parameters for tax_providers_fields

addons
optional, string

Parameters for addons

event_based_addons
optional, string

Parameters for event_based_addons

Returns

subscriptionSubscription object

Resource object representing subscription

customerCustomer object

Resource object representing customer

cardCard object

Resource object representing card

invoiceInvoice object

Resource object representing invoice

Resource object representing unbilled_charge