Subscription represents the recurring items a customer has subscribed to. The recurring items can be - plan, addons. It may also contain the discount items like coupons.

Subscriptions are invoiced at the start of every term based on the recurring items and charged immediately against the customer's credit card if 'auto_collection' is turned 'on', otherwise the resulting invoice will be created as 'Payment Due'.

Sample subscription [ JSON ]

{ "id": "8avVGOkx8U1MX", "plan_id": "basic", "plan_quantity": 1, "status": "non_renewing", "trial_start": 1317407411, "trial_end": 1320085811, "current_term_start": 1435689011, "current_term_end": 1438367411, "remaining_billing_cycles": 0, "created_at": 1317407411, "started_at": 1317407411, "activated_at": 1320085811, "cancelled_at": 1438367411, "has_scheduled_changes": true, "object": "subscription", "due_invoices_count": 2, "due_since": 1343759411, "total_dues": 1800, "shipping_address": { "first_name": "Benjamin", "last_name": "Ross", "company": "Acme Inc", "phone": "+1 (614) 226-4809", "line1": "345, Redington Av", "line2": "Suite 1200", "city": "Los Angeles", "state_code": "CA", "state": "California", "country": "US", "object": "shipping_address" } }

Model Class

ChargeBee_Subscription
id
A unique identifier to identify the subscription. You will use this to perform all operations on this subscription.
string, max chars=50
planId
Identifier of the plan for this subscription.
string, max chars=100
planQuantity
Represents the plan quantity for this subscription.
integer, default=1, min=1
status
Current state of the subscription.
enumerated string
Possible values are:
future :The Subscription is scheduled to start in a future date.in_trial :The subscription is in trial.active :The subscription is in active state and will be charged at start of each term based on the recurring items(plan & addons etc.,).non_renewing :The subscription will be cancelled at end of the current term.cancelled :The subscription has been cancelled. No new recurring actions will take place, but any pending payments will be collected.
startDate
Applicable only for 'future' subscriptions. The scheduled start time of the 'future' subscription.
optional, timestamp(UTC) in seconds
trialStart
Start of the trial period for the subscription. Presence of this value for 'future' subscription implies the subscription will go into 'trial' state when it starts.
optional, timestamp(UTC) in seconds
trialEnd
End of the trial period for the subscription. Presence of this value for 'future' subscription implies the subscription will go into 'trial' state when it starts.
optional, timestamp(UTC) in seconds
currentTermStart
Start of the current billing term.
optional, timestamp(UTC) in seconds
currentTermEnd
End of the current billing term. Subscription is renewed immediately after this.
optional, timestamp(UTC) in seconds
remainingBillingCycles
The number of billing cycles this subscription will run.
optional, integer, min=0
poNumber
Purchase Order Number for this subscription.
optional, string, max chars=100
createdAt
Subscription created time.
optional, timestamp(UTC) in seconds
startedAt
Time at which the subscription got started. Will be null for 'future' subscriptions as it is yet to be started.
optional, timestamp(UTC) in seconds
activatedAt
Time at which the subscription moved from in_trial state to active state.
optional, timestamp(UTC) in seconds
cancelledAt
Subscription cancelled time.
optional, timestamp(UTC) in seconds
cancelReason
Possible reason the subscription might be cancelled.
optional, enumerated string
Possible values are:
not_paid :Not Paid.no_card :No Card.fraud_review_failed :Fraud Review Failed.non_compliant_eu_customer :Non Compliant EU Customer.
affiliateToken
A unique token (such as shopping cart id). Used in refersion integration (a affiliate management service). This token should be same as the id that is passed to the tracking pixel url.
optional, string, max chars=250
createdFromIp
The IP address of the user. Used primarly in refersion integration. Refersion uses this field to track/log affiliate subscription.
optional, string, max chars=50
dueInvoicesCount
Total number of invoices that are due for payment.
optional, integer
dueSince
Time since this subscription has unpaid invoices.
optional, timestamp(UTC) in seconds
totalDues
Outstanding balance amount for this subscription.
optional, in cents, min=0
hasScheduledChanges
If true, there are subscription changes scheduled on next renewal.
optional, boolean
invoiceNotes
Invoice Notes for this resource. Read More.
optional, string, max chars=1000
List of addons for this subscription with quantity(if applicable).
optional, list of addon
Addon attributes
id
Identifier of the addon. Multiple addons can be passed.
string, max chars=100
quantity
Addon quantity. Applicable only for the quantity based addons. Should be passed with the same index as that of associated addon id.
optional, integer, default=1, min=1
List of coupons for this subscription.
optional, list of coupon
Coupon attributes
couponId
Used to uniquely identify the coupon.
string, max chars=50
applyTill
The date till the coupon is to be applied. Applicable for "limited months" coupons.
optional, timestamp(UTC) in seconds
appliedCount
Number of times this coupon has been applied for this subscription.
integer, default=0
couponCode
The coupon code used to redeem the coupon. Will be present only when associated code for a coupon is used.
optional, string, max chars=50
shippingAddress
Show attributes[+]
Shipping address for the subscription.
optional, shipping_address
Shipping addres attributes
firstName
First name.
optional, string, max chars=150
lastName
Last name.
optional, string, max chars=150
email
Email.
optional, string, max chars=70
company
Company name.
optional, string, max chars=250
phone
Phone number.
optional, string, max chars=50
line1
Address line 1.
optional, string, max chars=180
line2
Address line 2.
optional, string, max chars=150
line3
Address line 3.
optional, string, max chars=150
city
City.
optional, string, max chars=50
stateCode
The ISO 3166-2 state/province code. Supported only for countries US and Canada.
optional, string, max chars=50
state
The state/province name.
optional, string, max chars=50
country
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
zip
Zip or Postal code.
optional, string, max chars=20

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 explictly 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. Please refer this 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.
You can also use our Hosted Pages based integration.

Billing Address

The Billing Address is significant especially when EU VAT taxes are involved, for tax calculations will be based on this address. For customers without Billing Address, EU VAT taxes will not be included. Thus ensure to set this properly if you have configured EU VAT Tax.

Note: For the sites created before 1st Mar 2014, customer's billing address and 'vat_number' will be replaced automatically whenever the associated card gets updated. i.e existing values for billing address and 'vat_number' will be cleared and the new values will be set. This behaviour is changed now - The VAT number should always be passed along billing address and not with card address. Both the addresses have to be dealt separately.

Billing Address attributes shall be explicitly passed for customers paying offline(Cash, Check, Bank Transfer etc).

Related Tutorials

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::create(array(
  "planId" => "basic", 
  "customer" => array(
    "email" => "john@user.com", 
    "firstName" => "John", 
    "lastName" => "Doe", 
    "phone" => "+1-949-999-9999"
  ), 
  "billingAddress" => array(
    "firstName" => "John", 
    "lastName" => "Doe", 
    "line1" => "PO Box 9999", 
    "city" => "Walnut", 
    "state" => "California", 
    "zip" => "91789", 
    "country" => "US"
  )));
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::create(array(
  "planId" => "basic", 
  "customer" => array(
    "email" => "john@user.com", 
    "firstName" => "John", 
    "lastName" => "Doe", 
    "phone" => "+1-949-999-9999"
  ), 
  "billingAddress" => array(
    "firstName" => "John", 
    "lastName" => "Doe", 
    "line1" => "PO Box 9999", 
    "city" => "Walnut", 
    "state" => "California", 
    "zip" => "91789", 
    "country" => "US"
  )));
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();

Sample Result [ JSON ]

{ "subscription": { "id": "KyVrKRPHl5UT33q", "plan_id": "basic", "plan_quantity": 1, "status": "in_trial", "trial_start": 1436275944, "trial_end": 1438954344, "created_at": 1436275944, "started_at": 1436275944, "has_scheduled_changes": false, "object": "subscription", "due_invoices_count": 0 }, "customer": { "id": "KyVrKRPHl5UT33q", "first_name": "John", "last_name": "Doe", "email": "john@user.com", "phone": "+1-949-999-9999", "auto_collection": "on", "created_at": 1436275944, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 0 } }

Method

ChargeBee_Subscription::create(array(<param name> => <value>,<param name> => <value> ...))
id
Id for the new subscription. If not given, this will be auto-generated.
optional, string, max chars=50
planId
Identifier of the plan for this subscription.
required, string, max chars=100
planQuantity
Plan quantity for this subscription.
optional, integer, default=1, min=1
startDate
Specify this if you want to start the subscription at a future date instead of starting it immediately.
optional, timestamp(UTC) in seconds
trialEnd
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.
optional, timestamp(UTC) in seconds
billingCycles
Number of cycles(plan interval) this subscription should be charged. After the billing cycles exhausted, the subscription will be cancelled.
optional, integer, min=0
coupon

The id of the coupon. For validating the coupon code provided by the user , use the following codes in combination with the param attribute in the error response.

  • resource_not_found : Returned if the coupon is not present.
  • resource_limit_exhausted : Returned if the coupon has expired or the maximum redemption for the coupon has already been reached.
  • invalid_request : Returned if the coupon is not applicable for the particular plan/addon.

optional, string, max chars=50
poNumber
Purchase Order Number for this subscription.
optional, string, max chars=100
affiliateToken
A unique token (such as shopping cart id). Used in refersion integration (a affiliate management service). This token should be same as the id that is passed to the tracking pixel url.
optional, string, max chars=250
createdFromIp
The IP address of the user. Used primarly in refersion integration. Refersion uses this field to track/log affiliate subscription.
optional, string, max chars=50
invoiceNotes
Invoice Notes for this resource. Read More.
optional, string, max chars=1000
customer
Associative array of parameters for customer
pass parameters as customer => array("<param name>" => "<value>",...)
id
Id for the new customer. If not given, this will be same as the subscription id.
optional, string, max chars=50
email
Email of the customer. Configured email notifications will be sent to this email.
optional, string, max chars=70
firstName
First name of the customer.
optional, string, max chars=150
lastName
Last name of the customer.
optional, string, max chars=150
company
Company name of the customer.
optional, string, max chars=250
phone
Phone number of the customer.
optional, string, max chars=50
autoCollection
Whether payments needs to be collected automatically for this customer.
optional, enumerated string, default=on
Possible values are:
on :Whenever an invoice is created, an automatic attempt to charge the customer's payment method is made.off :Whenever a new invoice is created, there will no attempt made to charge the customer. All payment reconciliations must be recorded offline.
vatNumber
VAT number of this customer. Will be validated using the VIES service. To disable this validation, go to 'Settings -> Site Info' page and select the checkbox 'Disable VAT validation'.
optional, string, max chars=20
card
Associative array of parameters for card
pass parameters as card => array("<param name>" => "<value>",...)
gateway
Name of the gateway this card is stored with.
optional, enumerated string
Possible values are:
chargebee :ChargeBee test gateway.stripe :Stripe payment gateway.braintree :Braintree payment gateway.authorize_net :Authorize.net payment gateway.
paypal_pro :Paypal Pro Account.pin :Pin payment gateway.eway :eWAy Account.eway_rapid :eWAy Rapid gateway.worldpay :WorldPay payment gateway.balanced_payments :Balanced payment gateway.beanstream :Beanstream Account.bluepay :BluePay payment gateway.elavon :Elavon Virtual Merchant.first_data_global :First Data Global Gateway Virtual Terminal Account.hdfc :HDFC Account.migs :MasterCard Internet Gateway Service.nmi :NMI gateway.ogone :Ogone Account.paymill :Paymill payment gateway.paypal_payflow_pro :Paypal Payflow Pro gateway.sage_pay :Sage Pay gateway.tco :2Checkout payment gateway.wirecard :WireCard Account.not_applicable :Indicates that payment gateway is not applicable for this resource.
Show all values[+]
tmpToken
The single-use card token returned by vaults like Stripe which acts as a substitute for your card detail. Before calling this API, you should have submitted your card details to the gateway (Stripe) and got this token in return.
Note: Supported only for Stripe gateway and with this value specified there is no need to specify other card details(like number, cvv etc).
optional, string, max chars=50
firstName
Cardholder's first name.
optional, string, max chars=50
lastName
Cardholder's last name.
optional, string, max chars=50
number
The credit card number without any format. If you are using Braintree.js, you can specify the Braintree encrypted card number here.
required if card provided, string, max chars=520
expiryMonth
Card expiry month.
required if card provided, integer, min=1, max=12
expiryYear
Card expiry year.
required if card provided, integer
cvv
The card verification value. If you are using Braintree.js, you can specify the Braintree encrypted cvv here.
optional, string, max chars=520
billingAddr1
Address line 1, as in card billing address.
optional, string, max chars=150
billingAddr2
Address line 2, as in card billing address.
optional, string, max chars=150
billingCity
City, as in card billing address.
optional, string, max chars=50
billingStateCode
The ISO 3166-2 state/province code. The recommended way of passing the state/province information. Supported for US and Canada now. Further if this is specified, 'state' attribute should not be specified as it will be set automatically.
optional, string, max chars=50
billingState
The state/province name. Use this to pass the state/province information for cases where 'state_code' is not supported or cannot be passed.
optional, string, max chars=50
billingZip
Postal or Zip code, as in card billing address.
optional, string, max chars=20
billingCountry
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
ipAddress
The IP address from where the payment method is created or updated. Used primarly for EU VAT validation.
optional, string, max chars=50
paymentMethod
Associative array of parameters for paymentMethod
pass parameters as paymentMethod => array("<param name>" => "<value>",...)
type
The type of payment method. For more details refer Update payment method for a customer API under Customer resource.
optional, enumerated string
Possible values are:
card :Card based payment inluding credit cards and debit cards. Details about the card can be obtained from the card resource.paypal_express_checkout :Paypal Express Checkout based payment.amazon_payments :Amazon login and pay based payment.
gateway
Name of the gateway the card is associated with. Applicable only if the type is card.
optional, enumerated string
Possible values are:
stripe :Stripe payment gateway.braintree :Braintree payment gateway.authorize_net :Authorize.net payment gateway.
paypal_pro :Paypal Pro Account.pin :Pin payment gateway.eway :eWAy Account.eway_rapid :eWAy Rapid gateway.worldpay :WorldPay payment gateway.balanced_payments :Balanced payment gateway.beanstream :Beanstream Account.bluepay :BluePay payment gateway.elavon :Elavon Virtual Merchant.first_data_global :First Data Global Gateway Virtual Terminal Account.hdfc :HDFC Account.migs :MasterCard Internet Gateway Service.nmi :NMI gateway.ogone :Ogone Account.paymill :Paymill payment gateway.paypal_payflow_pro :Paypal Payflow Pro gateway.sage_pay :Sage Pay gateway.tco :2Checkout payment gateway.wirecard :WireCard Account.not_applicable :Indicates that payment gateway is not applicable for this resource.
Show all values[+]
referenceId
The reference id. In the case of Amazon and Paypal this will be the billing agreement id. In the case of card this will be the identifier provided by the gateway/card vault for the specific payment method resource. Note: This is not the one time temporary token provided by gateways like Stripe.
For more details refer Update payment method for a customer API under Customer resource.
optional, string, max chars=50
billingAddress
Associative array of parameters for billingAddress
pass parameters as billingAddress => array("<param name>" => "<value>",...)
firstName
First name.
optional, string, max chars=150
lastName
Last name.
optional, string, max chars=150
email
Email.
optional, string, max chars=70
company
Company name.
optional, string, max chars=250
phone
Phone number.
optional, string, max chars=50
line1
Address line 1.
optional, string, max chars=150
line2
Address line 2.
optional, string, max chars=150
line3
Address line 3.
optional, string, max chars=150
city
City.
optional, string, max chars=50
stateCode
The ISO 3166-2 state/province code. The recommended way of passing the state/province information. Supported for US and Canada now. Further if this is specified, 'state' attribute should not be specified as it will be set automatically.
optional, string, max chars=50
state
The state/province name. Use this to pass the state/province information for cases where 'state_code' is not supported or cannot be passed.
optional, string, max chars=50
zip
Zip or Postal code.
optional, string, max chars=20
country
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
shippingAddress
Associative array of parameters for shippingAddress
pass parameters as shippingAddress => array("<param name>" => "<value>",...)
firstName
First name.
optional, string, max chars=150
lastName
Last name.
optional, string, max chars=150
email
Email.
optional, string, max chars=70
company
Company name.
optional, string, max chars=250
phone
Phone number.
optional, string, max chars=50
line1
Address line 1.
optional, string, max chars=180
line2
Address line 2.
optional, string, max chars=150
line3
Address line 3.
optional, string, max chars=150
city
City.
optional, string, max chars=50
stateCode
The ISO 3166-2 state/province code. The recommended way of passing the state/province information. Supported for US and Canada now. Further if this is specified, 'state' attribute should not be specified as it will be set automatically.
optional, string, max chars=50
state
The state/province name. Use this to pass the state/province information for cases where 'state_code' is not supported or cannot be passed.
optional, string, max chars=50
zip
Zip or Postal code.
optional, string, max chars=20
country
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
addons
Array containing associative arrays of parameters for addons
pass parameters as addons => array(array("<param name>" => "<value>",...), array(..)...)
id
Identifier of the addon. Multiple addons can be passed.
optional, string, max chars=100
quantity
Addon quantity. Applicable only for the quantity based addons. Should be passed with the same index as that of associated addon id.
optional, integer, default=1, min=1
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional
Resource object representing invoice.
optional

Creates a new subscription for an existing customer. You can attach a plan, plan quantity, one or more addons and coupon while creating this subscription.

If the plan does not have a trial period and if any of the recurring-item has charges, then the customer is charged immediately if auto_collection is turned 'on'. In that case, subscription is created only if the customer has a payment method on file and attempted payment is successful.

Notes

Any available Account Credits will automatically be applied when an invoice gets generated.
Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::createForCustomer("8avVGOkx8U1MX", array(
  "planId" => "basic"));
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::createForCustomer("8avVGOkx8U1MX", array(
  "planId" => "basic"));
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();

Sample Result [ JSON ]

{ "subscription": { "id": "KyVrKRPHl5UTe3u", "plan_id": "basic", "plan_quantity": 1, "status": "in_trial", "trial_start": 1436275944, "trial_end": 1438954344, "created_at": 1436275944, "started_at": 1436275944, "has_scheduled_changes": false, "object": "subscription", "due_invoices_count": 0 }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 } }

Method

ChargeBee_Subscription::createForCustomer(<customer_id>,array(<param name> => <value>,<param name> => <value> ...))
id
Id for the new subscription. If not given, this will be auto-generated.
optional, string, max chars=50
planId
Identifier of the plan for this subscription.
required, string, max chars=100
planQuantity
Plan quantity for this subscription.
optional, integer, default=1, min=1
startDate
Specify this if you want to start the subscription at a future date instead of starting it immediately.
optional, timestamp(UTC) in seconds
trialEnd
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.
optional, timestamp(UTC) in seconds
billingCycles
Number of cycles(plan interval) this subscription should be charged. After the billing cycles exhausted, the subscription will be cancelled.
optional, integer, min=0
coupon

The id of the coupon. For validating the coupon code provided by the user , use the following codes in combination with the param attribute in the error response.

  • resource_not_found : Returned if the coupon is not present.
  • resource_limit_exhausted : Returned if the coupon has expired or the maximum redemption for the coupon has already been reached.
  • invalid_request : Returned if the coupon is not applicable for the particular plan/addon.

optional, string, max chars=50
poNumber
Purchase Order Number for this subscription.
optional, string, max chars=100
invoiceNotes
Invoice Notes for this resource. Read More.
optional, string, max chars=1000
shippingAddress
Associative array of parameters for shippingAddress
pass parameters as shippingAddress => array("<param name>" => "<value>",...)
firstName
First name.
optional, string, max chars=150
lastName
Last name.
optional, string, max chars=150
email
Email.
optional, string, max chars=70
company
Company name.
optional, string, max chars=250
phone
Phone number.
optional, string, max chars=50
line1
Address line 1.
optional, string, max chars=180
line2
Address line 2.
optional, string, max chars=150
line3
Address line 3.
optional, string, max chars=150
city
City.
optional, string, max chars=50
stateCode
The ISO 3166-2 state/province code. The recommended way of passing the state/province information. Supported for US and Canada now. Further if this is specified, 'state' attribute should not be specified as it will be set automatically.
optional, string, max chars=50
state
The state/province name. Use this to pass the state/province information for cases where 'state_code' is not supported or cannot be passed.
optional, string, max chars=50
zip
Zip or Postal code.
optional, string, max chars=20
country
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
addons
Array containing associative arrays of parameters for addons
pass parameters as addons => array(array("<param name>" => "<value>",...), array(..)...)
id
Identifier of the addon. Multiple addons can be passed.
optional, string, max chars=100
quantity
Addon quantity. Applicable only for the quantity based addons. Should be passed with the same index as that of associated addon id.
optional, integer, default=1, min=1
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional
Resource object representing invoice.
optional
Retrieves the list of subscriptions sorted by recent created ones on top.
Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$all = ChargeBee_Subscription::all(array(
  "limit" => 5));
foreach($all as $entry){
  $subscription = $entry->subscription();
  $customer = $entry->customer();
  $card = $entry->card();
}
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$all = ChargeBee_Subscription::all(array(
  "limit" => 5));
foreach($all as $entry){
  $subscription = $entry->subscription();
  $customer = $entry->customer();
  $card = $entry->card();
}

Sample Result [ JSON ]

{ "list": [ { "subscription": { "id": "KyVrKRPHl5UTe3u", "plan_id": "basic", "plan_quantity": 1, "status": "in_trial", "trial_start": 1436275944, "trial_end": 1438954344, "created_at": 1436275944, "started_at": 1436275944, "has_scheduled_changes": false, "object": "subscription", "due_invoices_count": 0 }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 } }, {..} ], "next_offset": "[\"1436275944000\",\"83000000112\"]" }

Method

ChargeBee_Subscription::all(array(<param name> => <value>,<param name> => <value> ...))
limit
Limits the number of resources to be returned.
optional, integer, default=10, min=1, max=100
offset
Allows you to fetch the next set of resources. The value used for this parameter must be the value returned for next_offset parameter in the previous API call.
optional, string, max chars=1000
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional
next_offset
This attribute is returned only if more resources are present. To fetch the next set of resources use this value for the input parameter “offset”.
optional, string, max chars=1000
Retrieves the list of subscriptions for a customer sorted by recent created ones on top.
Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$all = ChargeBee_Subscription::subscriptionsForCustomer("8avVGOkx8U1MX", array(
  "limit" => 5));
foreach($all as $entry){
  $subscription = $entry->subscription();
}
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$all = ChargeBee_Subscription::subscriptionsForCustomer("8avVGOkx8U1MX", array(
  "limit" => 5));
foreach($all as $entry){
  $subscription = $entry->subscription();
}

Sample Result [ JSON ]

{ "list": [ { "subscription": { "id": "KyVrKRPHl5UTe3u", "plan_id": "basic", "plan_quantity": 1, "status": "in_trial", "trial_start": 1436275944, "trial_end": 1438954344, "created_at": 1436275944, "started_at": 1436275944, "has_scheduled_changes": false, "object": "subscription", "due_invoices_count": 0 }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 } }, {..} ], "next_offset": "[\"1436275944000\",\"83000000112\"]" }

Method

ChargeBee_Subscription::subscriptionsForCustomer(<customer_id>,array(<param name> => <value>,<param name> => <value> ...))
limit
Limits the number of resources to be returned.
optional, integer, default=10, min=1, max=100
offset
Allows you to fetch the next set of resources. The value used for this parameter must be the value returned for next_offset parameter in the previous API call.
optional, string, max chars=1000
Resource object representing subscription.
always returned
next_offset
This attribute is returned only if more resources are present. To fetch the next set of resources use this value for the input parameter “offset”.
optional, string, max chars=1000
Retrieves the subscription identified by the 'subscription id' specified in the url.
Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::retrieve("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::retrieve("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();

Sample Result [ JSON ]

{ "subscription": { "id": "8avVGOkx8U1MX", "plan_id": "basic", "plan_quantity": 1, "status": "non_renewing", "trial_start": 1317407411, "trial_end": 1320085811, "current_term_start": 1435689011, "current_term_end": 1438367411, "remaining_billing_cycles": 0, "created_at": 1317407411, "started_at": 1317407411, "activated_at": 1320085811, "cancelled_at": 1438367411, "has_scheduled_changes": true, "object": "subscription", "due_invoices_count": 1, "due_since": 1346437811, "total_dues": 900, "shipping_address": { "first_name": "Benjamin", "last_name": "Ross", "line1": "PO Box 9999", "city": "Walnut", "state": "California", "country": "United States", "zip": "91789", "object": "shipping_address" } }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 } }

Method

ChargeBee_Subscription::retrieve(<subscription_id>)
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional

Retrieves a subscription with the scheduled changes applied.
Note: Only the following attributes are changed

  • plan_id
  • plan_quantity
  • remaining_billing_cycles
  • addons
  • coupons
Other attributes such as status, next_billing_at are not changed and will reflect the current subscription values.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::retrieveWithScheduledChanges("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::retrieveWithScheduledChanges("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();

Sample Result [ JSON ]

{ "subscription": { "id": "8avVGOkx8U1MX", "plan_id": "no_trial", "plan_quantity": 7, "status": "non_renewing", "trial_start": 1317407411, "trial_end": 1320085811, "current_term_start": 1435689011, "current_term_end": 1438367411, "remaining_billing_cycles": 4, "created_at": 1317407411, "started_at": 1317407411, "activated_at": 1320085811, "cancelled_at": 1438367411, "has_scheduled_changes": true, "object": "subscription", "due_invoices_count": 1, "due_since": 1346437811, "total_dues": 900, "shipping_address": { "first_name": "Benjamin", "last_name": "Ross", "line1": "PO Box 9999", "city": "Walnut", "state": "California", "country": "United States", "zip": "91789", "object": "shipping_address" } }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 } }

Method

ChargeBee_Subscription::retrieveWithScheduledChanges(<subscription_id>)
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional
Removes the subscription changes scheduled on next renewal.
Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::removeScheduledChanges("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::removeScheduledChanges("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();

Sample Result [ JSON ]

{ "subscription": { "id": "8avVGOkx8U1MX", "plan_id": "basic", "plan_quantity": 1, "status": "non_renewing", "trial_start": 1317407411, "trial_end": 1320085811, "current_term_start": 1435689011, "current_term_end": 1438367411, "remaining_billing_cycles": 0, "created_at": 1317407411, "started_at": 1317407411, "activated_at": 1320085811, "cancelled_at": 1438367411, "has_scheduled_changes": false, "object": "subscription", "due_invoices_count": 1, "due_since": 1346437811, "total_dues": 900, "shipping_address": { "first_name": "Benjamin", "last_name": "Ross", "line1": "PO Box 9999", "city": "Walnut", "state": "California", "country": "United States", "zip": "91789", "object": "shipping_address" } }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 } }

Method

ChargeBee_Subscription::removeScheduledChanges(<subscription_id>)
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional

If the subscription is in Non Renewing or In Trial state and is also scheduled to cancel at the end of current term, then this API can be used to remove the scheduled cancellation. When a scheduled cancellation is removed, the subscription will revert to Active or In Trial state, whichever is the state before cancellation was scheduled.

While removing the scheduled cancellation, you may specify the number of billing cycles. If the billing cycle is not specified, the default billing cycle from the plan will be applied on the subscription.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::removeScheduledCancellation("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::removeScheduledCancellation("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();

Sample Result [ JSON ]

{ "subscription": { "id": "8avVGOkx8U1MX", "plan_id": "basic", "plan_quantity": 1, "status": "active", "trial_start": 1317407411, "trial_end": 1320085811, "current_term_start": 1435689011, "current_term_end": 1438367411, "created_at": 1317407411, "started_at": 1317407411, "activated_at": 1320085811, "has_scheduled_changes": false, "object": "subscription", "due_invoices_count": 1, "due_since": 1346437811, "total_dues": 900, "shipping_address": { "first_name": "Benjamin", "last_name": "Ross", "line1": "PO Box 9999", "city": "Walnut", "state": "California", "country": "United States", "zip": "91789", "object": "shipping_address" } }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 } }

Method

ChargeBee_Subscription::removeScheduledCancellation(<subscription_id>,array(<param name> => <value>,<param name> => <value> ...))
billingCycles
Number of cycles(plan interval) this subscription should be charged. After the billing cycles exhausted, the subscription will be cancelled.
optional, integer, min=0
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional

You can modify the plan, plan quantity and add or remove addons for the subscription. By default the changes are applied immediately and the charges (/credits) are prorated and adjusted with the next billing term. You may also choose to effect the changes at the end of the current term by passing end_of_term as "true". In this case proration will not be done.

Only the parameters that are passed are modified for the subscription. Rest will reflect the existing values.

By default, the addons passed are appended to the existing list of addons for this subscription. In case a passed addon already exists for this subscription, quantity value is replaced. If you want to completely replace the addons for this subscription, pass replace_addon_list as "true".

Card and 'vat_number' attributes can also be passed during subscription update. If they are passed, corresponding Billing Info attributes - the Billing Address and 'vat_number' - will be replaced automatically.

Passing credit card details to this API involves PCI liability at your end as sensitive card info 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. Please refer this tutorial for more details.
  • If you are using Braintree gateway, you can use Braintree.js with your checkout form.
  • You can also use our Hosted Pages based integration.

Notes

Proration Scenario: A customer changes from a $15 plan to $30 plan after 15 days of a monthly term. He will be billed a total of $7.50 immediately. Calculation will be as follows:

Prorated Charge(New Plan) $15.00
Prorated Credit(Old Plan) for unused period ($7.50)
Total prorated amount $7.50

Downgrading will result in credit being created which will be applied when the subscription is charged on start of the next term.

Billing Cycle: The billing period for a subscription does not change if the plans intervals of both old and new are same. However, if a customer changes to a plan that has different billing interval(say monthly to yearly), the billing period is reset. Customer is charged immediately for the modified subscription after applying credit for the unused period for the old subscription.

Card and VAT number Input: If they are passed, corresponding Billing Address attributes and vat_number will be replaced. i.e existing values for Billing Address and 'vat_number' will be cleared and the new values will be set.

Any available Account Credits will automatically be applied when an invoice gets generated.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::update("8avVGOkx8U1MX", array(
  "planId" => "basic", 
  "billingAddress" => array(
    "firstName" => "John", 
    "lastName" => "Doe", 
    "line1" => "PO Box 9999", 
    "city" => "Walnut", 
    "state" => "California", 
    "zip" => "91789", 
    "country" => "US"
  )));
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::update("8avVGOkx8U1MX", array(
  "planId" => "basic", 
  "billingAddress" => array(
    "firstName" => "John", 
    "lastName" => "Doe", 
    "line1" => "PO Box 9999", 
    "city" => "Walnut", 
    "state" => "California", 
    "zip" => "91789", 
    "country" => "US"
  )));
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();

Sample Result [ JSON ]

{ "subscription": { "id": "8avVGOkx8U1MX", "plan_id": "basic", "plan_quantity": 1, "status": "active", "trial_start": 1317407411, "trial_end": 1320085811, "current_term_start": 1435689011, "current_term_end": 1438367411, "created_at": 1317407411, "started_at": 1317407411, "activated_at": 1320085811, "has_scheduled_changes": false, "object": "subscription", "due_invoices_count": 1, "due_since": 1346437811, "total_dues": 900, "shipping_address": { "first_name": "Benjamin", "last_name": "Ross", "line1": "PO Box 9999", "city": "Walnut", "state": "California", "country": "United States", "zip": "91789", "object": "shipping_address" } }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 } }

Method

ChargeBee_Subscription::update(<subscription_id>,array(<param name> => <value>,<param name> => <value> ...))
planId
Identifier of the plan for this subscription.
optional, string, max chars=100
planQuantity
Represents the plan quantity for this subscription.
optional, integer, default=1, min=1
startDate
Applicable only for 'future' subscriptions. The new start date of the 'future' subscription.
optional, timestamp(UTC) in seconds
trialEnd
The time at which the trial should end for this subscription. Can be specified to override the default trial period defined in plan. If '0' is passed, the subscription will be activated immediately.
optional, timestamp(UTC) in seconds
billingCycles
Number of cycles(plan interval) this subscription should be charged. After the billing cycles exhausted, the subscription will be cancelled.
optional, integer, min=0
replaceAddonList
Should be true if the existing addons should be replaced with the ones that are being passed.
optional, boolean, default=false
coupon
Used to uniquely identify the coupon in your website(/application) and to integrate with ChargeBee.
optional, string, max chars=50
poNumber
Purchase Order Number for this subscription.
optional, string, max chars=100
prorate
Add Prorated Credits and Charges, if applicable, during this updation.
optional, boolean, default=true
endOfTerm
You can specify when you want to update the subscription.
optional, boolean, default=false
invoiceNotes
Invoice Notes for this resource. Read More.
optional, string, max chars=1000
card
Associative array of parameters for card
pass parameters as card => array("<param name>" => "<value>",...)
gateway
Name of the gateway this card is stored with.
optional, enumerated string
Possible values are:
chargebee :ChargeBee test gateway.stripe :Stripe payment gateway.braintree :Braintree payment gateway.authorize_net :Authorize.net payment gateway.
paypal_pro :Paypal Pro Account.pin :Pin payment gateway.eway :eWAy Account.eway_rapid :eWAy Rapid gateway.worldpay :WorldPay payment gateway.balanced_payments :Balanced payment gateway.beanstream :Beanstream Account.bluepay :BluePay payment gateway.elavon :Elavon Virtual Merchant.first_data_global :First Data Global Gateway Virtual Terminal Account.hdfc :HDFC Account.migs :MasterCard Internet Gateway Service.nmi :NMI gateway.ogone :Ogone Account.paymill :Paymill payment gateway.paypal_payflow_pro :Paypal Payflow Pro gateway.sage_pay :Sage Pay gateway.tco :2Checkout payment gateway.wirecard :WireCard Account.not_applicable :Indicates that payment gateway is not applicable for this resource.
Show all values[+]
tmpToken
The single-use card token returned by vaults like Stripe which acts as a substitute for your card detail. Before calling this API, you should have submitted your card details to the gateway (Stripe) and got this token in return.
Note: Supported only for Stripe gateway and with this value specified there is no need to specify other card details(like number, cvv etc).
optional, string, max chars=50
firstName
Cardholder's first name.
optional, string, max chars=50
lastName
Cardholder's last name.
optional, string, max chars=50
number
The credit card number without any format. If you are using Braintree.js, you can specify the Braintree encrypted card number here.
required if card provided, string, max chars=520
expiryMonth
Card expiry month.
required if card provided, integer, min=1, max=12
expiryYear
Card expiry year.
required if card provided, integer
cvv
The card verification value. If you are using Braintree.js, you can specify the Braintree encrypted cvv here.
optional, string, max chars=520
billingAddr1
Address line 1, as in card billing address.
optional, string, max chars=150
billingAddr2
Address line 2, as in card billing address.
optional, string, max chars=150
billingCity
City, as in card billing address.
optional, string, max chars=50
billingStateCode
The ISO 3166-2 state/province code. The recommended way of passing the state/province information. Supported for US and Canada now. Further if this is specified, 'state' attribute should not be specified as it will be set automatically.
optional, string, max chars=50
billingState
The state/province name. Use this to pass the state/province information for cases where 'state_code' is not supported or cannot be passed.
optional, string, max chars=50
billingZip
Postal or Zip code, as in card billing address.
optional, string, max chars=20
billingCountry
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
ipAddress
The IP address from where the payment method is created or updated. Used primarly for EU VAT validation.
optional, string, max chars=50
paymentMethod
Associative array of parameters for paymentMethod
pass parameters as paymentMethod => array("<param name>" => "<value>",...)
type
The type of payment method. For more details refer Update payment method for a customer API under Customer resource.
optional, enumerated string
Possible values are:
card :Card based payment inluding credit cards and debit cards. Details about the card can be obtained from the card resource.paypal_express_checkout :Paypal Express Checkout based payment.amazon_payments :Amazon login and pay based payment.
gateway
Name of the gateway the card is associated with. Applicable only if the type is card.
optional, enumerated string
Possible values are:
stripe :Stripe payment gateway.braintree :Braintree payment gateway.authorize_net :Authorize.net payment gateway.
paypal_pro :Paypal Pro Account.pin :Pin payment gateway.eway :eWAy Account.eway_rapid :eWAy Rapid gateway.worldpay :WorldPay payment gateway.balanced_payments :Balanced payment gateway.beanstream :Beanstream Account.bluepay :BluePay payment gateway.elavon :Elavon Virtual Merchant.first_data_global :First Data Global Gateway Virtual Terminal Account.hdfc :HDFC Account.migs :MasterCard Internet Gateway Service.nmi :NMI gateway.ogone :Ogone Account.paymill :Paymill payment gateway.paypal_payflow_pro :Paypal Payflow Pro gateway.sage_pay :Sage Pay gateway.tco :2Checkout payment gateway.wirecard :WireCard Account.not_applicable :Indicates that payment gateway is not applicable for this resource.
Show all values[+]
referenceId
The reference id. In the case of Amazon and Paypal this will be the billing agreement id. In the case of card this will be the identifier provided by the gateway/card vault for the specific payment method resource. Note: This is not the one time temporary token provided by gateways like Stripe.
For more details refer Update payment method for a customer API under Customer resource.
optional, string, max chars=50
billingAddress
Associative array of parameters for billingAddress
pass parameters as billingAddress => array("<param name>" => "<value>",...)
firstName
First name.
optional, string, max chars=150
lastName
Last name.
optional, string, max chars=150
email
Email.
optional, string, max chars=70
company
Company name.
optional, string, max chars=250
phone
Phone number.
optional, string, max chars=50
line1
Address line 1.
optional, string, max chars=150
line2
Address line 2.
optional, string, max chars=150
line3
Address line 3.
optional, string, max chars=150
city
City.
optional, string, max chars=50
stateCode
The ISO 3166-2 state/province code. The recommended way of passing the state/province information. Supported for US and Canada now. Further if this is specified, 'state' attribute should not be specified as it will be set automatically.
optional, string, max chars=50
state
The state/province name. Use this to pass the state/province information for cases where 'state_code' is not supported or cannot be passed.
optional, string, max chars=50
zip
Zip or Postal code.
optional, string, max chars=20
country
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
shippingAddress
Associative array of parameters for shippingAddress
pass parameters as shippingAddress => array("<param name>" => "<value>",...)
firstName
First name.
optional, string, max chars=150
lastName
Last name.
optional, string, max chars=150
email
Email.
optional, string, max chars=70
company
Company name.
optional, string, max chars=250
phone
Phone number.
optional, string, max chars=50
line1
Address line 1.
optional, string, max chars=180
line2
Address line 2.
optional, string, max chars=150
line3
Address line 3.
optional, string, max chars=150
city
City.
optional, string, max chars=50
stateCode
The ISO 3166-2 state/province code. The recommended way of passing the state/province information. Supported for US and Canada now. Further if this is specified, 'state' attribute should not be specified as it will be set automatically.
optional, string, max chars=50
state
The state/province name. Use this to pass the state/province information for cases where 'state_code' is not supported or cannot be passed.
optional, string, max chars=50
zip
Zip or Postal code.
optional, string, max chars=20
country
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
customer
Associative array of parameters for customer
pass parameters as customer => array("<param name>" => "<value>",...)
vatNumber
VAT number of this customer. Will be validated using the VIES service. To disable this validation, go to 'Settings -> Site Info' page and select the checkbox 'Disable VAT validation'.
optional, string, max chars=20
addons
Array containing associative arrays of parameters for addons
pass parameters as addons => array(array("<param name>" => "<value>",...), array(..)...)
id
Identifier of the addon. Multiple addons can be passed.
optional, string, max chars=100
quantity
Addon quantity. Applicable only for the quantity based addons. Should be passed with the same index as that of associated addon id.
optional, integer, default=1, min=1
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional
Resource object representing invoice.
optional

Changes the subscription's current term end date. Depending on the "status" of the subscription, "term end date" has different effects.

  • If the Subscription is in trial, it affects trial end date.
  • If the Subscription is active, it affects the next billing date.
  • If the Subscription's status is non_renewing, this affects the upcoming cancellation date.

When changing the current term there won't be any prorations calculated. All future renewals(if applicable) of the subscription will be shifted based on the new date.

Tip: To cycle through a couple of billing cycles and test webhooks, you may use this API.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::changeTermEnd("8avVGOkx8U1MX", array(
  "termEndsAt" => 1609459199));
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::changeTermEnd("8avVGOkx8U1MX", array(
  "termEndsAt" => 1609459199));
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();

Sample Result [ JSON ]

{ "subscription": { "id": "8avVGOkx8U1MX", "plan_id": "basic", "plan_quantity": 1, "status": "active", "trial_start": 1317407411, "trial_end": 1320085811, "current_term_start": 1435689011, "current_term_end": 1609459199, "created_at": 1317407411, "started_at": 1317407411, "activated_at": 1320085811, "has_scheduled_changes": false, "object": "subscription", "due_invoices_count": 1, "due_since": 1346437811, "total_dues": 900, "shipping_address": { "first_name": "Benjamin", "last_name": "Ross", "line1": "PO Box 9999", "city": "Walnut", "state": "California", "country": "United States", "zip": "91789", "object": "shipping_address" } }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 } }

Method

ChargeBee_Subscription::changeTermEnd(<subscription_id>,array(<param name> => <value>,<param name> => <value> ...))
termEndsAt
The time at which the current term should end for this subscription.
required, timestamp(UTC) in seconds
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional

Cancelling a subscription will move the current state of the subscription to the cancelled state and will stop all recurring actions.

You could schedule the cancellation by passing end_of_term parameter as true. If scheduled, the subscription status will be set to non_renewing if it is in active state until the end of term and then cancelled. Subscription's state will not change if it is in in_trial state. However, cancellation will be scheduled at the trial end date.

While cancelling a subscription, we try to collect all pending amount against the current and old invoices. No refund for the unused period is processed (let us know if you need have specific refund scenarios).

If the collection of pending charges fails while cancelling, it will still be moved to cancelled status. We will continue to retry collecting the payment based on the configured retry settings until it is manually overridden.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::cancel("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::cancel("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();

Sample Result [ JSON ]

{ "subscription": { "id": "8avVGOkx8U1MX", "plan_id": "basic", "plan_quantity": 1, "status": "cancelled", "trial_start": 1317407411, "trial_end": 1320085811, "current_term_start": 1435689011, "current_term_end": 1436275944, "created_at": 1317407411, "started_at": 1317407411, "activated_at": 1320085811, "cancelled_at": 1436275944, "has_scheduled_changes": false, "object": "subscription", "due_invoices_count": 1, "due_since": 1346437811, "total_dues": 900, "shipping_address": { "first_name": "Benjamin", "last_name": "Ross", "line1": "PO Box 9999", "city": "Walnut", "state": "California", "country": "United States", "zip": "91789", "object": "shipping_address" } }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 } }

Method

ChargeBee_Subscription::cancel(<subscription_id>,array(<param name> => <value>,<param name> => <value> ...))
endOfTerm
You can specify when you want to cancel the subscription.
optional, boolean, default=false
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional
Resource object representing invoice.
optional

This API is used to reactivate a cancelled subscription. You may also optionally specify a trial end date, to move the subscription to In Trial state. If trial end is not specified, the subscription will be activated and any applicable charges will be initiated.

Unless the billing cycle is specified, it will be set to plan's default billing cycle.

During an in-term reactivation++, unless the billing cycle is specified, the subscription's remaining billing cycles will be restored. If a trial end date is specified, then the plan's default billing cycle is used.

++What is an "in-term reactivation"?
If a reactivation is initiated within the same billing term as the recent invoice of the subscription, then it is considered an in-term reactivation. Let us say, a Subscription was billed from 1st to 31st of a month and it was canceled on 20th of the month due to dunning. If the reactivation happens on 25th then it is considered an in-term reactivation.

This scenario happens only if the subscription's cancellation was initiated automatically due to dunning (payment failure retry settings).

Notes

Reactivation of a subscription in non_renewing state has been deprecated. To remove a scheduled cancellation of a non_renewing Subscription, use Remove Scheduled Cancellation API.

However, if you use reactivate API to remove scheduled cancellation for a non_renewing Subscription, then the status will be set to active and the billing cycle will be set to forever. If any value is passed for trial_end or billing cycle, an error will be thrown.

Any available Account Credits will automatically be applied when an invoice gets generated during this operation.

Additional Error Scenarios: If there is a need to create an immediate charge and the collection fails, an error is thrown.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::reactivate("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::reactivate("8avVGOkx8U1MX");
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();

Sample Result [ JSON ]

{ "subscription": { "id": "8avVGOkx8U1MX", "plan_id": "basic", "plan_quantity": 1, "status": "active", "trial_start": 1317407411, "trial_end": 1320085811, "current_term_start": 1436275944, "current_term_end": 1438954344, "created_at": 1317407411, "started_at": 1317407411, "activated_at": 1436275944, "has_scheduled_changes": false, "object": "subscription", "due_invoices_count": 1, "due_since": 1346437811, "total_dues": 900, "shipping_address": { "first_name": "Benjamin", "last_name": "Ross", "line1": "PO Box 9999", "city": "Walnut", "state": "California", "country": "United States", "zip": "91789", "object": "shipping_address" } }, "customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407411, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 300 }, "invoice": { "id": "51", "customer_id": "8avVGOkx8U1MX", "subscription_id": "8avVGOkx8U1MX", "recurring": true, "status": "paid", "start_date": 1436275944, "end_date": 1436275944, "amount": 0, "amount_due": 0, "paid_on": 1436275944, "object": "invoice", "sub_total": 0, "tax": 0, "line_items": [ { "date_from": 1436275944, "date_to": 1438954344, "unit_amount": 900, "quantity": 1, "tax": 0, "object": "line_item", "amount": 900, "description": "Basic", "type": "charge", "entity_type": "plan", "entity_id": "basic" }, {..} ], "discounts": [ { "object": "discount", "type": "account_credits", "description": "Account Credits", "amount": 900 }, {..} ], "linked_transactions": [], "linked_orders": [], "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "shipping_address": { "first_name": "Benjamin", "last_name": "Ross", "line1": "PO Box 9999", "city": "Walnut", "state": "California", "country": "United States", "zip": "91789", "object": "shipping_address" } } }

Method

ChargeBee_Subscription::reactivate(<subscription_id>,array(<param name> => <value>,<param name> => <value> ...))
trialEnd
The time at which the trial should end for this subscription.
optional, timestamp(UTC) in seconds
billingCycles
Number of cycles(plan interval) this subscription should be charged. After the billing cycles exhausted, the subscription will be cancelled.
optional, integer, min=0
Resource object representing subscription.
always returned
Resource object representing customer.
always returned
Resource object representing card.
optional
Resource object representing invoice.
optional

Adds a one time charge to the subscription which will be added to the invoice generated at the end of the current term. If there are any applicable coupons in the subscription, an appropriate discount will be applied.

To collect a charge immediately, use this API.

Notes

If any subscription changes happen before the end of the current term, these charges will be collected along with it.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::addChargeAtTermEnd("8avVGOkx8U1MX", array(
  "amount" => 1000, 
  "description" => "Support charge"));
$estimate = $result->estimate();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::addChargeAtTermEnd("8avVGOkx8U1MX", array(
  "amount" => 1000, 
  "description" => "Support charge"));
$estimate = $result->estimate();

Sample Result [ JSON ]

{"estimate": { "created_at": 1436275944, "recurring": true, "subscription_id": "8avVGOkx8U1MX", "subscription_status": "active", "term_ends_at": 1438954344, "collect_now": false, "amount": 1900, "object": "estimate", "sub_total": 1900, "line_items": [ { "date_from": 1436275944, "date_to": 1436275944, "unit_amount": 1000, "quantity": 1, "tax": 0, "object": "line_item", "amount": 1000, "description": "Support charge", "type": "charge", "entity_type": "adhoc" }, {..} ] }}

Method

ChargeBee_Subscription::addChargeAtTermEnd(<subscription_id>,array(<param name> => <value>,<param name> => <value> ...))
amount
The amount to be charged.
required, in cents, min=1
description
Description for this charge.
required, string, max chars=250
Resource object representing estimate.
always returned

Adds a "non-recurring addon" charge to a subscription which will be added to the invoice generated at the end of the current term. If there are any applicable coupons in the subscription, an appropriate discount will be applied.

To collect the charges for the non-recurring addon immediately, use this API.

Notes

If any subscription changes happen before the end of the current term, these charges will be collected along with it.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::chargeAddonAtTermEnd("8avVGOkx8U1MX", array(
  "addonId" => "ssl"));
$estimate = $result->estimate();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Subscription::chargeAddonAtTermEnd("8avVGOkx8U1MX", array(
  "addonId" => "ssl"));
$estimate = $result->estimate();

Sample Result [ JSON ]

{"estimate": { "created_at": 1436275945, "recurring": true, "subscription_id": "8avVGOkx8U1MX", "subscription_status": "active", "term_ends_at": 1438954344, "collect_now": false, "amount": 2900, "object": "estimate", "sub_total": 2900, "line_items": [ { "date_from": 1436275944, "date_to": 1436275944, "unit_amount": 1000, "quantity": 1, "tax": 0, "object": "line_item", "amount": 1000, "description": "Support charge", "type": "charge", "entity_type": "adhoc" }, {..} ] }}

Method

ChargeBee_Subscription::chargeAddonAtTermEnd(<subscription_id>,array(<param name> => <value>,<param name> => <value> ...))
addonId
The ID of the non-recurring addon to be charged.
required, string, max chars=100
addonQuantity
The number of addon units to be charged. Mandatory for quantity based addons.
optional, integer, min=1
Resource object representing estimate.
always returned