Start a new topic

How to get customer and subscription data in the return URL of a plan specific hosted payment page?

Our hosted payment pages are mobile compatible and secure checkout pages with customizable theme support to match your website's look and feel. 

For users integrating with ChargeBee using the hosted payment pages, it would be super useful if the return URL includes details of the subscription that a customer just signed up for. You can use this information to personalize the success message you would display to the customers or to store it in your database for reference if needed (affiliate tracking).

For example, during sign up, you won't have any information of the person like their name or the plan quantity, etc. So when a "John Doe" signs up, you can use the values returned in the redirect URL of the newly created subscription. Using these values you can create an actionable dynamic web page on your site to display a custom message based on the subscription details.

So when the customer successfully signs up, you could display something like "Thank you for signing up with us! Your customer ID is 112233". The customer id is captured from the "" value in the redirect URL.

We internally call this feature as MERGEVAR support for hosted payment pages. 

Here is how to set it up:

1. Build your redirect URL using your webpage along with the required return variables.

Note: If there are no values present for a specific MERGEVAR in ChargeBee, then the value would be empty. So, if a customer is signing up for a trial plan, no invoice would be generated, and in the example above, the value would be empty.

2. Configure the "Redirect URL" when creating a new plan or by editing an existing plan.

To test this:

1. Click on the "Hosted Page URL" link of the plan you configured the redirect URL for.
2. Complete a successful checkout. On the next page, you will see the values on the URL.
Here is a list of all the MERGEVAR parameters that can be used with the redirect URL:

{{}} - Identifier of the customer.
{{}} - Identifier of the subscription.
{{subscription.status}} - Current state of the subscription (In Trial, Active, Non Renewing, Cancelled).
{{}} - Identifier of the plan.
{{}} - The display name used in admin console for identifying the plan.
{{plan.quantity}} - Plan quantity subscribed.
{{plan.price}} - The price of the plan.
{{}} - The invoice number. Acts as a identifier for the invoice and is typically generated sequentially.
{{invoice.amount}} - Invoice amount in cents.
{{invoice.sub_total}} - The invoice amount before applying discount(s), if any.

Have a suggestion? Email us at 

1 person likes this idea

Does this work for the API return URL as well?

Yes. But works in a slightly different way. Since you are using API, you have full access to the object already. 
Here is how this can be accomplished in the case of API for hosted pages.

1. You will be using checkout a new subscription to generate the URL.
You will receive the hosted page URL ID in the redirecturl as id. 

2. You can use this to retrieve the details of the checkout along with subscription & customer details using theretrieve a hosted page API. 
(assuming the checkout was completed successfully - State of response will be "Succeeded" for a completed checkout).

The response will contain full object details of customer, subscription and invoice.
Here is a sample of a plan without trial.

                  "description":"Basic No Trial",
                  "description":"On Call Support",

Oh, very handy! Thanks for that.

Maybe you should add that to the API documentation. Currently there's no hint of that functionality in there.

Thank you Oakley. We will udpate our API documentation to include this.

This doesn't appear to be working anymore. I've added a URL and whitelisted it but it says the return url is invalid. Even if I use your documentation example:{{}}&sub_id={{}}

The field validation still won't allow this url. 

Hi Alex,

Apologies for the delay in addressing this. This was missed by accident. I see that you've found the solution in our documentation already:

We've also taken your feedback about improving the user friendliness of the documentation and we'll continue working on it to make it easier. 

Hi there,

How can I get the hostedpage ID after the redirectURL is fired?

I need the hostedpageID so I can get the hostpageURL for a specific Customer/Subscription.

My goal is to use an iframe to display the customer's portal so, my customers can self-manage their payment method and download their subscription.

Login or Signup to post a comment