The Chargebee API offers additional features such as custom HTTP request headers, custom fields, metadata. Moreover, the ability to set up multiple business entities, payment sources, and gateway accounts is also available. The sections below describe how to use these features.
If your site has multiple business entities, you can pass the chargebee-business-entity-id: <business-entity-id>
custom HTTP header to specify the business entity for which Chargebee should perform the operation. Here <business-entity-id>
is the unique identifier of a business entity.
The following sample shows how to create a customer within a business entity:
curl https://{site}.chargebee.com/api/v2/customers \ -H chargebee-business-entity-id:__dev__8at09TEfAyAk2\ -u {api-key}: \ -d customer[email]="sarah@acme.com"
As an alternative to passing the request header, for some create operations, you can specify the business_entity_id
using a query string parameter. See the create customer endpoint for example.
If the header and query string parameter are passed together in an API call, their values must be the same or an error is returned.
Passing user details like IP address, email address, and device information from your website to Chargebee is always useful. IP address information is routed to the payment gateway, where it is validated against active fraud detection filters, and used for EU tax validation, referral integration, and event reports. Email addresses and device information, even more ubiquitous, are used for identification. Chargebee supports the following custom HTTP request headers for providing such user details:
chargebee-request-origin-ip
: Used to provide the IP address, of your customer/user, from where the request originated. For example, 202.170.207.70
.chargebee-request-origin-user
: Used to provide the email address of your customer/user. Use this when the email address has only ASCII characters. For example, amara@acme.com
.chargebee-request-origin-user-encoded
: Used to provide the Base64-encoded email address of your customer/user. Use this if the email address has UTF-8 characters (such as user.квіточка@example.com
). When this header is provided, the header chargebee-request-origin-user
is ignored.chargebee-request-origin-device
: Used to provide a string indicating the device from which the request was made. For example, Android
, Ubuntu
, or iOS
.When making API calls to Chargebee, including the chargebee-request-origin-ip
and chargebee-request-origin-device
details can provide valuable context about the user initiating the request. This information can enhance fraud detection and may be required by certain payment gateways. This document outlines the advantages of providing chargebee-request-origin-ip
and chargebee-request-origin-device
data and explains what happens if these details are omitted.
Information about Origin IP and Device Data
When you make a Chargebee API call, sending the chargebee-request-origin-ip
and chargebee-request-origin-device
details add more context about the user making the request. This additional information can be crucial for payment gateways to assess transaction legitimacy. However, if you're using Chargebee's frontend capabilities or hosted pages, this information is automatically managed, and you don't need to provide it separately.
Advantages of providing this information
chargebee-request-origin-ip
and chargebee-request-origin-device
details to process transactions.What happens if these details are missing?
If you don't provide the chargebee-request-origin-ip
and chargebee-request-origin-device
details when making a Chargebee API call such as when using the create_subscription_for_items API, you can still proceed with the transaction. However, for API calls involving payments from end customers, it's recommended to include this information to:
chargebee-request-origin-ip
and chargebee-request-origin-device
are mandatory. Failing to provide these parameters will cause the flow to fail.Providing user details with the email address containing only ASCII characters:
curl https://mysite.chargebee.com/api/v2/customers \ -H chargebee-request-origin-ip:192.168.1.2\ -H chargebee-request-origin-user:user@example.com\ -H chargebee-request-origin-device:Android\ -u myapikey: \ -d customer[email]="john@user.com" \
Providing user details with the email address containing UTF-8 characters (here user.квіточка@example.com
):
curl https://{my-site}.chargebee.com/api/v2/customers \
-H chargebee-request-origin-ip:202.170.207.70\
-H chargebee-request-origin-user-encoded:dXNlci7QutCy0ZbRgtC+0YfQutCwQGV4YW1wbGUuY29t\
-H chargebee-request-origin-device:Android\
-u {my-api-key}: \
-d customer[email]="user.квіточка@example.com" \
Sometimes you would want to disable emails or webhooks for the events that are generated for a particular api call. Typically you would need this when you are migrating customers from your system to Chargebee via api. One option would be to disable all the emails(/webhooks) for all events during the import process. But then you would still want to send emails for new customers who are signing up.
Chargebee supports custom http headers on each api request that allow you to control the actions that are triggered on the events generated by that particular api call.
curl https://mysite.chargebee.com/api/v2/customers \ -H chargebee-event-actions:all-disabled \ -u myapikey: \ -d customer[email]="john@user.com" \
Chargebee gives you the option of creating custom fields to track additional information about Customers and their Subscriptions. You can create custom fields for customers, subscriptions, item families, and items. Once the custom fields are created, they can be added to the hosted checkout pages and invoices. They can be accessed through the web interface and API. More on Custom Fields here.
curl https://{site}.chargebee.com/api/v2/customers \ -u {site_api_key}: \ -d first_name="John" \ -d last_name="Doe" \ -d email="john@test.com" \ -d "cf_gender"="sample"
Some resources in Chargebee support an attribute called metadata
or meta_data
that can be used to store additional information for the resource. The data can be stored in JSON format. The following resources support this:
Metadata can be passed in both the "create" as well as "update" operations against the resource.
You can use custom fields instead of metadata to overcome the above limitations.
Chargebee supports configuring multiple gateway accounts for a gateway type. For example, you can configure multiple Authorize.net accounts to process different currencies.
The default Gateway account to use for each currency can be configured using Smart Routing. However, you can override the selected gateway for each transaction in Chargebee. To do this pass the gateway_account_id
parameter when calling the following APIs:
Passing gateway
, card[gateway]
, payment_method[gateway]
parameters would result in an error in this case since those parameters only resolve the gateway and not the specific account for that gateway.
Chargebee supports multiple payment methods/sources for a customer. So a customer can have a Card and a Paypal Account linked to them, or they can have multiple cards. Moreover, you can mark one of them as Primary and one as Backup payment source.
The purpose of a Backup payment source is that if a charge made via the Primary payment source fails, then the backup payment source will be automatically used for processing the transaction.
Updating a payment source:
An optional parameter, payment_source_id, is available in the following APIs:
If you want to attach a particular payment source to a specific subscription, then pass the parameter in the following APIs:
Pass this parameter in the following APIs to collect the payment using a specific payment source:
Notes:
Some of the resources have a corresponding details page in the Chargebee's admin console. In some cases you might want to construct the admin console url for easy access from your app (or from exported xls sheets). As the admin console urls are based on internal ids you need to construct the url in the below given format.
Here is an example of a constructed url for a subscription with id 123xyz