All Collections
Developer
How to set up Chargebee with Tolt
How to set up Chargebee with Tolt
Valentin avatar
Written by Valentin
Updated over a week ago

There are a few steps that you have to do to set up your SaaS and Chargebee with Tolt.

You can find the integration set up in your Tolt dashboard within Account Settings.

First, you'll need to add our tracking script:

<script async src="https://cdn.tolt.io/tolt.js" data-tolt="YOUR-ID"></script>

The script needs to be added on your landing page, or even better, on every page, so we never miss a referral. This script will add a global variable called "tolt" to your window object. The size of the script is around 4KB.

Send Referral ID to Chargebee:

You'll need to send the Tolt-generated unique ID to Chargebee, either via custom field if using drop-in script or meta_data if using their APIs.

The user's Tolt ID can be received from the script that was added in the previous step. To access the unique ID, use window.tolt_referral

Drop-In Script

If you are integrating Chargebee with their drop-in script, then you'll first need to create a custom field.

To do that, go to Settings > Configure Chargebee > Custom Fields and create a field with the API value of cf_tolt_referral. The field needs to be created for the customer.

After creating the custom field, add the following script to your page where your Chargebee subscription lives.

if(window.tolt_referral) { 
var cbInstance = Chargebee.getInstance();
var cart = cbInstance.getCart();
cart.setCustomer({
cf_tolt_referral: window.tolt_referral
})
}

Make sure the Tolt script has been fully loaded to your page, that way the referral ID will exist under window.tolt_referral

The above code is just an example, your integration might be different. You just need to send the referral ID window.tolt_referral to Chargebee as a value to the custom field cf_tolt_referral.

API Based

If you are integrating Chargebee with their API, then you'll need to send the window.tolt_referral to your backend API and include that value inside meta_data when creating the user.

import { ChargeBee, _customer } from 'chargebee-typescript'; 
var chargebee = new ChargeBee();

chargebee.configure({site: "{site}", api_key: "{site_api_key}"});

chargebee.customer.create({
first_name: "John",
last_name: "Doe",
email: "[email protected]",
locale: "fr-CA",
billing_address: {
first_name: "John",
last_name: "Doe",
line1: "PO Box 9999",
city: "Walnut",
state: "California"
},
meta_data: {
tolt_referral: "REFERRAL_ID_RECEIVED_FROM_window.tolt_referral"
}
})

The example above shows implementation in Typescript, the same can be done in any other language. The code snippet is taken from Chargebee's documentation, and on that added the meta_data field with the tolt_referral value.

The value for tolt_referral needs to be received from the frontend, from window.tolt_referral, and that value needs to be sent to the API that creates the customer.

Webhook Setup

You'll need to add a new endpoint for Chargebee to send webhooks to, this can be done by navigating to Settings > Configure Chargebee > Webhooks > Add Webhook
Set the following details:
โ€‹Webhook Name: Tolt Integration

The Tolt ID can be found on the integration page.

API Version: Version 2

Enable the "Exclude card information from webhook call." option

The following webhook events need to be selected:

  • Subscription Created

  • Subscription Started

  • Subscription Activated

  • Subscription Deleted

  • Subscription Canceled

  • Payment Succeeded

  • Payment Refunded

You can always contact us via live chat and we can set up Chargebee together!

Signup a Referral

Did this answer your question?