ChargebeeAPI

Checkout new subscription

Idempotency Supported

Hosted page to accept card details from the subscriber and create a new subscription. This is similar to our server to server API Create a Subscription.

When the redirect URL is notified of the result, we would advise you to retrieve the subscription and verify the details.

As mentioned before this behavior is very similar to the create subscription API call. All the web hook events will be fired only after the submission of payment details by the customer and successful creation of subscription. Any errors related to the payment form that is submitted is handled as a response within the form so that the user is kept informed about the reason for failure to take corrective action.

Sample Request

URL Format

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

Input Parameters

billing_cycles
optional, integer, min=0

Number of cycles(plan interval) this subscription should be charged. After the billing cycles exhausted, the subscription will be cancelled.

mandatory_addons_to_remove
optional, string, max chars=100

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

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.

coupon_ids
optional, string, max chars=100

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

redirect_url
optional, string, max chars=250

The customers will be redirected to this URL upon successful checkout. The hosted page id and state will be passed as parameters to this URL.

Note :

  • Although the customer will be redirected to the redirect_url after successful checkout, we do not recommend relying on it for completing critical post-checkout actions. This is because redirection may not happen due to unforeseen reasons such as user closing the tab, or exiting the browser, and so on. If there is any synchronization that you are doing after the redirection, you will have to have a backup. Chargebee recommends listening to appropriate webhooks such as subscription_created or invoice_generated to verify a successful checkout.
  • Redirect URL configured in Settings > Hosted Pages Settings would be overriden by this redirect URL.
  • Eg : http://yoursite.com?id=**&state=succeeded
  • This parameter is not applicable for iframe messaging.
cancel_url
optional, string, max chars=250

The customers will be redirected to this URL upon canceling checkout. The hosted page id and state will be passed as parameters to this URL.

Note : - Cancel URL configured in Settings > Hosted Pages Settings would be overriden by this cancel URL.
Eg : http://yoursite.com?id=&state=cancelled

  • This parameter is not applicable for iframe messaging and in-app checkout.
pass_thru_content
optional, string, max chars=2048

This attribute allows you to store custom information with the hosted_page object. You can use it to associate specific data with a hosted page session. For example, you can store the ID of the marketing campaign that initiated the user session. After a successful checkout, when the customer is redirected, you can retrieve the hosted page ID from the redirect URL's query parameters. Using this ID, you can fetch the hosted page and perform actions related to the success of the marketing campaign.

embed
optional, boolean, default=true

If true then hosted page formatted to be shown in iframe. If false, it is formatted to be shown as a separate page.

Note : For in-app checkout, default is false.

iframe_messaging
optional, boolean, default=false

If true then iframe will communicate with the parent window. Applicable only for embedded(iframe) hosted pages. If you're using iframe_messaging you need to implement onSuccess & onCancel callbacks.

Note : This parameter is not applicable for in-app checkout.

allow_offline_payment_methods
optional, boolean

Allow the customer to select an offline payment method during checkout. The choice of payment methods can be configured via the Chargebee UI.

subscription[0..n]
Parameters for subscription
pass parameters as subscription[<param name>]
customer[0..n]
Parameters for customer
pass parameters as customer[<param name>]
card[0..n]
Parameters for card
pass parameters as card[<param name>]
billing_address[0..n]
Parameters for billing_address
pass parameters as billing_address[<param name>]
shipping_address[0..n]
Parameters for shipping_address
pass parameters as shipping_address[<param name>]
contract_term[0..n]
Parameters for contract_term
pass parameters as contract_term[<param name>]
addons[0..n]
Parameters for addons. Multiple addons can be passed by specifying unique indices.
pass parameters as addons[<param name>][<idx:0..n>]
event_based_addons[0..n]
Parameters for event_based_addons. Multiple event_based_addons can be passed by specifying unique indices.
pass parameters as event_based_addons[<param name>][<idx:0..n>]

Returns

hosted_pageHosted page object
Resource object representing hosted_page