Chargebee Webhook
This integration will make sure that your customer purchases are tracked.
If you use Chargebee to track customer purchases, you can set up a webhook integration so PartnerStack can listen for events relating to charges and subscriptions. Once we receive information about a customer paying for your product, we can record that payment in PartnerStack and ensure your partners are properly attributed!
Supported Chargebee Events
PartnerStack supports listening for the following events from Chargebee per their developer documentation. Please note we only listen for V2 webhooks at this time.
| Event Category | Events | Summary |
|---|---|---|
| Customer Events | customer_created, customer_changed | When we receive these events, a customer is either created or updated in PartnerStack. |
| Payment Events | payment_succeeded | When we receive this event, a transaction is recorded under the associated customer in PartnerStack. |
| Refund Events | payment_refunded, payment_failed | When we receive these events, the original transaction is deleted in PartnerStack (if it exists), and a new transaction may be created reflecting the refunded amount. |
Customer Events
customer_created, customer_changed
customer_created, customer_changedWhen PartnerStack receives one of these events, it attempts to create or update a customer record. The following fields are read and matched from the Chargebee customer object:
| PartnerStack Field | Source in Chargebee | Notes |
|---|---|---|
provider_key | id | This is the Chargebee Customer ID. |
email | email | |
name | first_name, last_name | |
customer_key | meta_data.customer_key or cf_customer_id if using Chargebee Hosted Pages | Optional but recommended. Required to auto-create a customer if one doesn't exist. |
partner_key | meta_data.partner_key or cf_partner_key if using Chargebee Hosted Pages | Optional. Required to auto-create a customer if one doesn't exist. |
Here's how PartnerStack processes these events:
- Search for a matching customer in PartnerStack by
customer_key, thenprovider_key, thenemail. - Resolve the customer:
- If a matching customer is found:
- Update the
provider_keyif one doesn't already exist. - Update the
emailif the email in Chargebee is different from what's stored. - Update the
nameif the name in Chargebee is different from what's stored. If the customer's name in PartnerStack was previously set to their email, and the email in Chargebee is different, update thenameto match the email in Chargebee.
- Update the
- If a matching customer is not found, a new customer is created if both
customer_keyandpartner_keyare available.
- If a matching customer is found:
Payment Events
payment_succeeded
payment_succeededWhen PartnerStack receives this event, it attempts to record a transaction under the associated customer. The following fields are read and matched from the Chargebee customer, transaction, invoice, and subscription objects:
| PartnerStack Field | Source in Chargebee | Notes |
|---|---|---|
provider_key | customer.id | This is the Chargebee Customer ID. |
email | customer.email | |
name | customer.first_name, customer.last_name | |
customer_key | meta_data.customer_key or cf_customer_id if using Chargebee Hosted Pages | Optional but recommended. Required to auto-create a customer if one doesn't exist. |
partner_key | meta_data.partner_key or cf_partner_key if using Chargebee Hosted Pages | Optional. Required to auto-create a customer if one doesn't exist. |
transaction_key | transaction.id | Required. |
amount | invoice.amount_paid - invoice.tax or transaction.amount | invoice amount takes precedence if available |
currency | transaction.currency_code | |
product_key | subscription.plan_id or subscription.subscription_items.item_price_id (first one found where item_type is 'plan') | Optional. Required to use product-specific reward triggers. subscription.plan_idtakes precedence if provided. |
Here's how PartnerStack processes this event:
- Check if a transaction exists with the same
transaction_key. If found, the transaction is skipped. - Search for a matching customer in PartnerStack by
customer_key, thenprovider_key, thenemail. - Resolve the customer:
- If a matching customer is found, PartnerStack will use the existing record and update the
provider_keyif one doesn't already exist. - If a matching customer is not found, a new customer is created if both
customer_keyandpartner_keyare available.
- If a matching customer is found, PartnerStack will use the existing record and update the
- Create a new transaction in PartnerStack tied to the resolved customer.
The transaction amount recorded in PartnerStack differs depending on which fields are populated on the event payload. If an
invoiceobject is present, PartnerStack usesamount_paidminus thetaxamount. Otherwise, PartnerStack falls back to theamountfield on thetransactionobject.
Refund Events
payment_refunded, payment_failed
payment_refunded, payment_failedWhen PartnerStack receives one of these events, it processes a refund against the original transaction. The following fields are read from the Chargebee customer and transaction objects:
| PartnerStack Field | Source in Chargebee | Notes |
|---|---|---|
provider_key | customer.id | This is the Chargebee Customer ID. |
email | customer.email | |
name | customer.first_name, customer.last_name | |
transaction_key | transaction.id or transaction.refunded_txn_id (if transaction.type is 'refund') | Required. |
amount_refunded | transaction.amount | |
currency | transaction.currency_code |
Here's how PartnerStack processes these events:
- Search for a matching transaction in PartnerStack using the
transaction_key. - If no matching transaction is found, nothing happens.
- If a matching transaction is found, it checks the refunded amount against the original transaction amount:
- For full refunds, PartnerStack will delete the original transaction.
- For partial refunds, PartnerStack will delete the original transaction and create a new transaction record with
amount_refundedsubtracted from the original amount.
Integration
Get your Webhook URL
Navigate to Settings > Integrations > Webhooks and look for Chargebee from the Supported integrations.
Click the Copy button to save the URL to your clipboard.
Create the Webhook on the Chargebee Dashboard
- Log in to your Chargebee dashboard.
- From the sidebar, select Settings > Configure Chargebee and click on Webhooks.
- Click on "+ Add Webhook" and fill out the URL you copied in your PartnerStack dashboard as the Webhook URL.
- Select the events you want to send under "Events to Send." The most important ones to track purchases are Customer Created, Customer Changed and Payment Succeeded.
- Make sure to select "Exclude card information from webhook call" -- we don't need any credit card information to record transactions on our platform!
Add customer key to Chargebee Metadata
This section is intended to be completed by your development team, or whoever is able to make changes to your site's back-end code. It varies depending on how your product interacts with Chargebee.
Whenever you interact with Chargebee to record transactions under a customer, you need to let PartnerStack know which customer you're referring to. At PartnerStack, we identify customers using their customer key. This can be any value that uniquely identifies customers on your platform, for example their email address.
If you're using PartnerStackJS, this would be the value you used for growsumo.data.customer_key when the customer signed up. If you used our PartnerStack API to create the customer record, this would be the value you passed as the key.
When PartnerStack receives the webhook from Chargebee, the platform tries to find a customer with the same customer_key as the one listed in the customer meta_data in Chargebee. Please ensure these match, or the transaction will not be properly recorded. This is an example of how the metadata object can be set when creating the customer through your backend. The implementation varies depending on how you've integrated with Chargebee in your product!
ADD `meta_data` containing the `customer_key`
MAKE SURE it matches the one used with PartnerStackJS
`partner_key` is required if not using PartnerStackJS
chargebee.configure("test_2L7HV...", "your-site...")
chargebee.Customer.create({
"first_name" : "John",
"last_name" : "Doe",
"email" : "[email protected]",
"meta_data": {
"customer_key": <YOUR_CUSTOMERS_KEY>,
"partner_key": <partner_key>
}
# })ADD `metadata` containing the `customer_key`
MAKE SURE it matches the one used with GrowSumoJS
# require 'chargebee'
# ChargeBee.configure(:site => "{site}", :api_key => "{site_api_key}")
# result = ChargeBee::Customer.create({
:meta_data => {"customer_key" => <YOUR_CUSTOMERS_KEY>),
# :first_name => "John",
# :last_name => "Doe",
# ...
# })
# customer = result.customer
# card = result.cardADD `metadata` containing the `customer_key`
MAKE SURE it matches the one used with GrowSumoJS
<?
// require 'ChargeBee.php';
// ChargeBee_Environment::configure("{site}","{site_api_key}");
// $result = ChargeBee_Customer::create(array(
// "firstName" => "John",
// "lastName" => "Doe",
"metaData" => array("customer_key" => <YOUR_CUSTOMERS_KEY>)
// ...
// ));
// $customer = $result->customer();
// $card = $result->card();ADD `metadata` containing the `customer_key`
MAKE SURE it matches the one used with GrowSumoJS
// Environment.configure("{site}","{site_api_key}");
// Result result = Customer.create()
// .firstName("John")
// .lastName("Doe")
.metaData("customer_key", <YOUR_CUSTOMERS_KEY>)
// ...
// Customer customer = result.customer();
// Card card = result.card();ADD `metadata` containing the `customer_key`
MAKE SURE it matches the one used with GrowSumoJS
// var chargebee = require("chargebee");
// chargebee.configure({site : "{site}", api_key : "{site_api_key}"});
// chargebee.customer.create({
// first_name : "John",
// last_name : "Doe",
meta_data: { "customer_key": <YOUR_CUSTOMERS_KEY> },
// ..
// })For Chargebee Hosted Pages, the
customer_keymust be passed as aCustom Field. It should be passed ascf_customer_id. Thepartner_keyshould also be passed as aCustom Field:cf_partner_key.
Updated 5 days ago

