Answered

Create new subscription for the existing customer using hosted page

Hi there!


I'm integretaing Chargbee into our application. Our requirements are:

1. Each user gets free subscription on signup

2. User can purchase additional subscription (in addition to free subscription)

3. We want use hosted pages to avoid possible security issues on custom implementation of the billing pages.


I found two methods on HostedPage class those look promising: CheckoutNew and CheckoutExisting.

In our case we want to create new subscription thus I've first tried CheckoutNew method. But it seems that it creates new chargebee customer. At that moment we already have it for each user.

In contrary, CheckoutExisting does not create new customer but modifies existing subscription of the existing customer. This also does not fit our requirements.


Is there any way to create new subscription for the existing customer using hosted pages?


Best Answer

Hey Pavel,


1} If you’d like your users to get a free subscription on signup, you could create a $0 plan {with desired number of billing cycles} in Chargebee and make them subscribe to it using ‘Create a subscription’ API.


2} If you’d like to give users the option to purchase additional products/services, you could create addons {preferably recurring type} in Chargebee and associate them with the free subscription. If it’s one time payment for these additional purchases, you could go for non-recurring addons.


3} Apart from this, if you'd like to create a new subscription {with no trial period} for an existing customer {with a valid card on file}, you could make use of 'Create Subscription for Customer' API. Since they have a card already, there’s no need to use the hosted pages again.


If you want customers to update their card details, you can use the ‘Update Payment Method' API to get the card details using the hosted pages.


'Checkout existing Subscription' API would not help since it is used only for updating an existing subscription. This is normally used to collect the card details (if there is no card on file) and the customer is upgrading from a trial subscription to an active one.


Answer

Hey Pavel,


1} If you’d like your users to get a free subscription on signup, you could create a $0 plan {with desired number of billing cycles} in Chargebee and make them subscribe to it using ‘Create a subscription’ API.


2} If you’d like to give users the option to purchase additional products/services, you could create addons {preferably recurring type} in Chargebee and associate them with the free subscription. If it’s one time payment for these additional purchases, you could go for non-recurring addons.


3} Apart from this, if you'd like to create a new subscription {with no trial period} for an existing customer {with a valid card on file}, you could make use of 'Create Subscription for Customer' API. Since they have a card already, there’s no need to use the hosted pages again.


If you want customers to update their card details, you can use the ‘Update Payment Method' API to get the card details using the hosted pages.


'Checkout existing Subscription' API would not help since it is used only for updating an existing subscription. This is normally used to collect the card details (if there is no card on file) and the customer is upgrading from a trial subscription to an active one.

 FYI I asked this question recently to the support department and it is possible. I use the v3 checkout API. According to the support department:


There has been an update on this feature and now you can create a subscription for an existing customer using the checkout new subscription API. To change the existing subscription to a different plan, you can use the checkout existing subscription API. You just have to pass the customer ID and subscription ID respectively.


Hope this helps someone out in the future.

@Bono de Visser


How do u create a subscription for an existing customer using the checkout new subscription? Just pass the existing customer_id in the parameter?

 @Asnawi Saharuddin Yes, but you have to beware to pass it as part of a customer dict in the json. So your data will look something like this:

 

{
  ...  # Other data
  "customer": {
    "id": "your_customer_id"
  }
}

 Please note that if you pass this data wrong the Chargebee API will most likely still return a 200 instead of a 400 (they don't check if passed in parameters are valid or not, it will always say everything is okay, even if you give it nonsense data). So check very carefully that the right data is being passed in. This is how we've implemented it for our site. If you run into something more I might be able to help, since we already went through all the troubles of figuring it out ;)

Login or Signup to post a comment
×