Start a new topic
Implemented

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 "customer.id" 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 invoice.id 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:

{{customer.id}} - Identifier of the customer.
{{subscription.id}} - Identifier of the subscription.
{{subscription.status}} - Current state of the subscription (In Trial, Active, Non Renewing, Cancelled).
{{plan.id}} - Identifier of the plan.
{{plan.name}} - The display name used in admin console for identifying the plan.
{{plan.quantity}} - Plan quantity subscribed.
{{plan.price}} - The price of the plan.
{{invoice.id}} - 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 support@chargebee.com. 

1 person likes this idea

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: https://acmeinc.com/success.html?cus_id={{customer.id}}&sub_id={{subscription.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: https://www.chargebee.com/docs/advanced_hosted_page_sign_up.html#getting-subscription-details-from-the-redirect-url


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. 

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

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. 
https://apidocs.chargebee.com/docs/api/hosted_pages#checkout_new_subscription
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).
https://apidocs.chargebee.com/docs/api/hosted_pages#retrieve_a_hosted_page

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

{
   "hosted_page":{
      "id":"twuHzUF82HEskGZ7qd9sDPjtBs4ONpzV",
      "type":"checkout_new",
      "url":"https://bpath-test.chargebee.com/pages/twuHzUF82HEskGZ7qd9sDPjtBs4ONpzV/checkout",
      "state":"succeeded",
      "embed":false,
      "created_at":1382426085,
      "expires_at":1382436885,
      "object":"hosted_page",
      "content":{
         "subscription":{
            "id":"B51XvFOKykyM84r7",
            "plan_id":"basic_no_trial",
            "plan_quantity":1,
            "status":"active",
            "current_term_start":1382426101,
            "current_term_end":1385104501,
            "created_at":1382426101,
            "activated_at":1382426101,
            "due_invoices_count":0,
            "object":"subscription",
            "addons":[
               {
                  "id":"on_call_support",
                  "quantity":1,
                  "object":"addon"
               }
            ]
         },
         "customer":{
            "id":"B51XvFOKykyM84r7",
            "first_name":"John",
            "last_name":"Wayne",
            "email":"john@user.com",
            "phone":"1-949-305-6900",
            "auto_collection":"on",
            "created_at":1382426101,
            "object":"customer",
            "card_status":"valid"
         },
         "card":{
            "customer_id":"B51XvFOKykyM84r7",
            "status":"valid",
            "gateway":"chargebee",
            "first_name":"John",
            "last_name":"Wayne",
            "iin":"411111",
            "last4":"1111",
            "card_type":"visa",
            "expiry_month":10,
            "expiry_year":2014,
            "object":"card",
            "masked_number":"************1111"
         },
         "invoice":{
            "id":"6369",
            "subscription_id":"B51XvFOKykyM84r7",
            "recurring":true,
            "status":"paid",
            "start_date":1382426101,
            "end_date":1382426101,
            "amount":10900,
            "paid_on":1382426101,
            "object":"invoice",
            "sub_total":10900,
            "tax":0,
            "line_items":[
               {
                  "date_from":1382426101,
                  "date_to":1385104501,
                  "unit_amount":1000,
                  "quantity":1,
                  "tax":0,
                  "object":"line_item",
                  "amount":1000,
                  "description":"Basic No Trial",
                  "type":"charge",
                  "entity_type":"plan",
                  "entity_id":"basic_no_trial"
               },
               {
                  "date_from":1382426101,
                  "date_to":1385104501,
                  "unit_amount":9900,
                  "quantity":1,
                  "tax":0,
                  "object":"line_item",
                  "amount":9900,
                  "description":"On Call Support",
                  "type":"charge",
                  "entity_type":"addon",
                  "entity_id":"on_call_support"
               }
            ]
         }
      }
   }
}

Does this work for the API return URL as well?

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.

Login or Signup to post a comment