chargebee chatChat with us

Represents a customer. Subscriptions, Card and Billing Address are associated with the customer resource. Customer resource will be created along with subscription via "Create a Subscription" API. The id of the customer will be same as that of associated subscription id if not explictly set.

The Billing Address is significant especially when EU VAT taxes are involved, for tax calculations will be based on this address. For customers without Billing Address, EU VAT taxes will not be included. Thus ensure to set this properly if you have configured EU VAT Tax.

Note: For the customers who signed up before 1st Mar 2014, Customer's Billing Address and 'vat_number' will be replaced automatically whenever the associated Card gets updated. i.e existing values for Billing Address and 'vat_number' will be cleared and the new values will be set. This behaviour is changed now - The VAT Number should always be passed along Billing Address and not with Card address. Both the addresses have to be dealt separately.

Sample customer [ JSON ]

{ "id": "8avVGOkx8U1MX", "first_name": "Benjamin", "last_name": "Ross", "email": "Benjamin@test.com", "auto_collection": "on", "created_at": 1317407453, "object": "customer", "card_status": "valid", "payment_method": { "object": "payment_method", "type": "card", "gateway": "chargebee", "reference_id": "tok_8avaNPGeKA8B1", "status": "valid" }, "account_credits": 0 }

Model Class

ChargeBee_Customer
id
Identifier of the customer.
string, max chars=50
firstName
First name of the customer.
optional, string, max chars=150
lastName
Last name of the customer.
optional, string, max chars=150
email
Email of the customer. Configured email notifications will be sent to this email.
optional, string, max chars=70
phone
Phone number of the customer.
optional, string, max chars=50
company
Company name of the customer.
optional, string, max chars=250
vatNumber
VAT number of this customer. Will be validated using the VIES service. To disable this validation, go to 'Settings -> Site Info' page and select the checkbox 'Disable VAT validation'.
optional, string, max chars=20
autoCollection
Whether payments needs to be collected automatically for this customer.
enumerated string, default=on
Possible values are:
on :Whenever an invoice is created, an automatic attempt to charge the customer's payment method is made.off :Whenever a new invoice is created, there will no attempt made to charge the customer. All payment reconciliations must be recorded offline.
createdAt
Timestamp indicating when this customer resource is created.
timestamp(UTC) in seconds
createdFromIp
The IP address of the customer. Used primarly for referral integration and EU VAT validation.
optional, string, max chars=50
cardStatus
Status of the card on file for this customer.
optional, enumerated string
Possible values are:
no_card :No credit card is associated with the customer.valid :There is a valid card available for this customer.expiring :The credit card is expiring soon. Indicates that the customer has to update the card soon.expired :The card is expired and cannot be used to charge the subscriptions anymore.
invoiceNotes
Invoice Notes for this resource. Read More.
optional, string, max chars=1000
accountCredits
Account credit balance of this customer.
in cents, min=0
billingAddress
Show attributes[+]
Billing address for a customer.
optional, billing_address
Billing addres attributes
firstName
First name.
optional, string, max chars=150
lastName
Last name.
optional, string, max chars=150
email
Email.
optional, string, max chars=70
company
Company name.
optional, string, max chars=250
phone
Phone number.
optional, string, max chars=50
line1
Address line 1.
optional, string, max chars=150
line2
Address line 2.
optional, string, max chars=150
line3
Address line 3.
optional, string, max chars=150
city
City.
optional, string, max chars=50
stateCode
The ISO 3166-2 state/province code. Supported only for countries US and Canada.
optional, string, max chars=50
state
State or Province.
optional, string, max chars=50
country
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
zip
Zip or Postal code.
optional, string, max chars=20
paymentMethod
Show attributes[+]
Payment method of a customer.
optional, payment_method
Payment method attributes
type
Type of payment method.
optional, enumerated string
Possible values are:
card :Card based payment. Both credit cards and debit cards included.In case it is card then details about the card can be got from card resource.paypal_express_checkout :Paypal Express Checkout based payment.amazon_payments :Amazon login and pay based payment.
gateway
Name of the gateway this card is stored with.
enumerated string
Possible values are:
chargebee :ChargeBee test gateway.stripe :Stripe payment gateway.braintree :Braintree payment gateway.authorize_net :Authorize.net payment gateway.
paypal_pro :Paypal Pro Account.pin :Pin payment gateway.eway :eWAy Account.eway_rapid :eWAy Rapid gateway.worldpay :WorldPay payment gateway.balanced_payments :Balanced payment gateway.beanstream :Beanstream Account.bluepay :BluePay payment gateway.elavon :Elavon Virtual Merchant.first_data_global :First Data Global Gateway Virtual Terminal Account.hdfc :HDFC Account.migs :MasterCard Internet Gateway Service.nmi :NMI gateway.ogone :Ogone Account.paymill :Paymill payment gateway.paypal_payflow_pro :Paypal Payflow Pro gateway.sage_pay :Sage Pay gateway.tco :2Checkout payment gateway.wirecard :WireCard Account.not_applicable :Indicates that payment gateway is not applicable for this resource.
Show all values[+]
status
Current status of the payment method.
enumerated string, default=valid
Possible values are:
valid :A payment method that is valid and active.expiring :A payment method that is expiring (like card).expired :A payment method that has expired.invalid :The billing agreement cannot be used. It might become valid again either automatically or due to customer action.
referenceId
The reference id. Incase of amazon and paypal it is billing agreement id. Incase of card it is the token provided by the gateway/card vault.
optional, string, max chars=50

Creates a customer. You can create a customer and then create subscriptions for the customer when required. When creating a customer, you can pass along the billing address and card details.

Passing credit card details to through the API involves PCI liability at your end as sensitive card information passes through your servers. If you wish to avoid that, you can use one of the following integration methodologies if applicable:

  • If you are using Stripe gateway, you can use Stripe.js with your checkout form. Please refer this tutorial for more details.
  • If you are using Braintree gateway, you can use Braintree.js with your checkout form.
  • You can also use our Hosted Pages based integration.

The Billing Address is significant especially when EU VAT taxes are involved, for tax calculations will be based on this address. For customers without a billing address, EU VAT taxes will not be included. Thus ensure to set this properly if you have configured EU VAT Tax.

Billing Address attributes shall be explicitly passed for customers paying offline(Cash, Check, Bank Transfer etc).

Note: When an invoice is generated for a customer, the billing address provided for the customer will be stored with the invoice. If the First Name, Last Name, and Company fields do not contain any information under Billing Info, the same will be picked from Customer Details if the same is available there.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::create(array(
  "firstName" => "John", 
  "lastName" => "Doe", 
  "email" => "john@test.com", 
  "billingAddress" => array(
    "firstName" => "John", 
    "lastName" => "Doe", 
    "line1" => "PO Box 9999", 
    "city" => "Walnut", 
    "state" => "California", 
    "zip" => "91789", 
    "country" => "US"
  )));
$customer = $result->customer();
$card = $result->card();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::create(array(
  "firstName" => "John", 
  "lastName" => "Doe", 
  "email" => "john@test.com", 
  "billingAddress" => array(
    "firstName" => "John", 
    "lastName" => "Doe", 
    "line1" => "PO Box 9999", 
    "city" => "Walnut", 
    "state" => "California", 
    "zip" => "91789", 
    "country" => "US"
  )));
$customer = $result->customer();
$card = $result->card();

Sample Result [ JSON ]

{"customer": { "id": "8avYnPGeKaXr1r", "first_name": "John", "last_name": "Doe", "email": "john@test.com", "auto_collection": "on", "created_at": 1435259975, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 0 }}

Method

ChargeBee_Customer::create(array(<param name> => <value>,<param name> => <value> ...))
id
Id for the new customer. If not given, this will be auto-generated.
optional, string, max chars=50
firstName
First name of the customer.
optional, string, max chars=150
lastName
Last name of the customer.
optional, string, max chars=150
email
Email of the customer. Configured email notifications will be sent to this email.
optional, string, max chars=70
phone
Phone number of the customer.
optional, string, max chars=50
company
Company name of the customer.
optional, string, max chars=250
autoCollection
Whether payments needs to be collected automatically for this customer.
optional, enumerated string, default=on
Possible values are:
on :Whenever an invoice is created, an automatic attempt to charge the customer's payment method is made.off :Whenever a new invoice is created, there will no attempt made to charge the customer. All payment reconciliations must be recorded offline.
vatNumber
VAT number of this customer. Will be validated using the VIES service. To disable this validation, go to 'Settings -> Site Info' page and select the checkbox 'Disable VAT validation'.
optional, string, max chars=20
createdFromIp
The IP address of the customer. Used primarly for referral integration and EU VAT validation.
optional, string, max chars=50
invoiceNotes
Invoice Notes for this resource. Read More.
optional, string, max chars=1000
card
Associative array of parameters for card
pass parameters as card => array("<param name>" => "<value>",...)
gateway
Name of the gateway this card is stored with.
optional, enumerated string
Possible values are:
chargebee :ChargeBee test gateway.stripe :Stripe payment gateway.braintree :Braintree payment gateway.authorize_net :Authorize.net payment gateway.
paypal_pro :Paypal Pro Account.pin :Pin payment gateway.eway :eWAy Account.eway_rapid :eWAy Rapid gateway.worldpay :WorldPay payment gateway.balanced_payments :Balanced payment gateway.beanstream :Beanstream Account.bluepay :BluePay payment gateway.elavon :Elavon Virtual Merchant.first_data_global :First Data Global Gateway Virtual Terminal Account.hdfc :HDFC Account.migs :MasterCard Internet Gateway Service.nmi :NMI gateway.ogone :Ogone Account.paymill :Paymill payment gateway.paypal_payflow_pro :Paypal Payflow Pro gateway.sage_pay :Sage Pay gateway.tco :2Checkout payment gateway.wirecard :WireCard Account.not_applicable :Indicates that payment gateway is not applicable for this resource.
Show all values[+]
tmpToken
The single-use card token returned by vaults like Stripe which acts as a substitute for your card detail. Before calling this API, you should have submitted your card details to the gateway (Stripe) and got this token in return.
Note: Supported only for Stripe gateway and with this value specified there is no need to specify other card details(like number, cvv etc).
optional, string, max chars=50
firstName
Cardholder's first name.
optional, string, max chars=50
lastName
Cardholder's last name.
optional, string, max chars=50
number
The credit card number without any format. If you are using Braintree.js, you can specify the Braintree encrypted card number here.
required if card provided, string, max chars=520
expiryMonth
Card expiry month.
required if card provided, integer, min=1, max=12
expiryYear
Card expiry year.
required if card provided, integer
cvv
The card verification value. If you are using Braintree.js, you can specify the Braintree encrypted cvv here.
optional, string, max chars=520
billingAddr1
Address line 1, as in card billing address.
optional, string, max chars=150
billingAddr2
Address line 2, as in card billing address.
optional, string, max chars=150
billingCity
City, as in card billing address.
optional, string, max chars=50
billingStateCode
The ISO 3166-2 state/province code. The recommended way of passing the state/province information. Supported for US and Canada now. Further if this is specified, 'state' attribute should not be specified as it will be set automatically.
optional, string, max chars=50
billingState
The state/province name. Use this to pass the state/province information for cases where 'state_code' is not supported or cannot be passed.
optional, string, max chars=50
billingZip
Postal or Zip code, as in card billing address.
optional, string, max chars=20
billingCountry
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
ipAddress
The IP address from where the payment method is created or updated. Used primarly for EU VAT validation.
optional, string, max chars=50
paymentMethod
Associative array of parameters for paymentMethod
pass parameters as paymentMethod => array("<param name>" => "<value>",...)
type
Type of payment method.
optional, enumerated string
Possible values are:
card :Card based payment. Both credit cards and debit cards included.In case it is card then details about the card can be got from card resource.paypal_express_checkout :Paypal Express Checkout based payment.amazon_payments :Amazon login and pay based payment.
gateway
Name of the gateway this card is stored with.
optional, enumerated string
Possible values are:
stripe :Stripe payment gateway.braintree :Braintree payment gateway.authorize_net :Authorize.net payment gateway.
paypal_pro :Paypal Pro Account.pin :Pin payment gateway.eway :eWAy Account.eway_rapid :eWAy Rapid gateway.worldpay :WorldPay payment gateway.balanced_payments :Balanced payment gateway.beanstream :Beanstream Account.bluepay :BluePay payment gateway.elavon :Elavon Virtual Merchant.first_data_global :First Data Global Gateway Virtual Terminal Account.hdfc :HDFC Account.migs :MasterCard Internet Gateway Service.nmi :NMI gateway.ogone :Ogone Account.paymill :Paymill payment gateway.paypal_payflow_pro :Paypal Payflow Pro gateway.sage_pay :Sage Pay gateway.tco :2Checkout payment gateway.wirecard :WireCard Account.not_applicable :Indicates that payment gateway is not applicable for this resource.
Show all values[+]
referenceId
The reference id. Incase of amazon and paypal it is billing agreement id. Incase of card it is the token provided by the gateway/card vault.
optional, string, max chars=50
billingAddress
Associative array of parameters for billingAddress
pass parameters as billingAddress => array("<param name>" => "<value>",...)
firstName
First name.
optional, string, max chars=150
lastName
Last name.
optional, string, max chars=150
email
Email.
optional, string, max chars=70
company
Company name.
optional, string, max chars=250
phone
Phone number.
optional, string, max chars=50
line1
Address line 1.
optional, string, max chars=150
line2
Address line 2.
optional, string, max chars=150
line3
Address line 3.
optional, string, max chars=150
city
City.
optional, string, max chars=50
stateCode
The ISO 3166-2 state/province code. The recommended way of passing the state/province information. Supported for US and Canada now. Further if this is specified, 'state' attribute should not be specified as it will be set automatically.
optional, string, max chars=50
state
The state/province name. Use this to pass the state/province information for cases where 'state_code' is not supported or cannot be passed.
optional, string, max chars=50
zip
Zip or Postal code.
optional, string, max chars=20
country
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
Resource object representing customer.
always returned
Resource object representing card.
optional
Retrieves the list of customers with the recent ones on top.
Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$all = ChargeBee_Customer::all(array(
  "limit" => 5));
foreach($all as $entry){
  $customer = $entry->customer();
  $card = $entry->card();
}
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$all = ChargeBee_Customer::all(array(
  "limit" => 5));
foreach($all as $entry){
  $customer = $entry->customer();
  $card = $entry->card();
}

Sample Result [ JSON ]

{ "list": [ {"customer": { "id": "8avYnPGeKaXr1r", "first_name": "John", "last_name": "Doe", "email": "john@test.com", "auto_collection": "on", "created_at": 1435259975, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 0 }}, {..} ], "next_offset": "[\"1435259975000\",\"15\"]" }

Method

ChargeBee_Customer::all(array(<param name> => <value>,<param name> => <value> ...))
limit
Limits the number of resources to be returned.
optional, integer, default=10, min=1, max=100
offset
Allows you to fetch the next set of resources. The value used for this parameter must be the value returned for next_offset parameter in the previous API call.
optional, string, max chars=1000
Resource object representing customer.
always returned
Resource object representing card.
optional
next_offset
This attribute is returned only if more resources are present. To fetch the next set of resources use this value for the input parameter “offset”.
optional, string, max chars=1000
Retrieves the customer identified by the unique identifier.
Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::retrieve("8avVGOkx8U1MX");
$customer = $result->customer();
$card = $result->card();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::retrieve("8avVGOkx8U1MX");
$customer = $result->customer();
$card = $result->card();

Sample Result [ JSON ]

{"customer": { "id": "8avVGOkx8U1MX", "first_name": "Benjamin", "last_name": "Ross", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407453, "object": "customer", "card_status": "no_card", "account_credits": 0 }}

Method

ChargeBee_Customer::retrieve(<customer_id>)
Resource object representing customer.
always returned
Resource object representing card.
optional

Updates the customer resource. However this method cannot be used for updating the 'Billing Info' - the Billing Address and 'vat_number' attributes - of the customer. To update the same, use our Update Billing Info API.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::update("8avVGOkx8U1MX", array(
  "firstName" => "Denise", 
  "lastName" => "Barone"));
$customer = $result->customer();
$card = $result->card();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::update("8avVGOkx8U1MX", array(
  "firstName" => "Denise", 
  "lastName" => "Barone"));
$customer = $result->customer();
$card = $result->card();

Sample Result [ JSON ]

{"customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407453, "object": "customer", "card_status": "no_card", "account_credits": 0 }}

Method

ChargeBee_Customer::update(<customer_id>,array(<param name> => <value>,<param name> => <value> ...))
firstName
First name of the customer.
optional, string, max chars=150
lastName
Last name of the customer.
optional, string, max chars=150
email
Email of the customer. Configured email notifications will be sent to this email.
optional, string, max chars=70
phone
Phone number of the customer.
optional, string, max chars=50
company
Company name of the customer.
optional, string, max chars=250
autoCollection
Whether payments needs to be collected automatically for this customer.
optional, enumerated string, default=on
Possible values are:
on :Whenever an invoice is created, an automatic attempt to charge the customer's payment method is made.off :Whenever a new invoice is created, there will no attempt made to charge the customer. All payment reconciliations must be recorded offline.
invoiceNotes
Invoice Notes for this resource. Read More.
optional, string, max chars=1000
Resource object representing customer.
always returned
Resource object representing card.
optional

Updates payment method details for a customer.

PayPal Express Checkout
You can use this API only if you are using your own hosted pages for PayPal Express Checkout. When your customer updates PayPal Express Checkout as a payment method from your hosted pages, you will be provided with the Billing Agreement ID by PayPal. You can update the Billing Agreement ID in Chargebee by passing "payment_method[type]" as "paypal_express_checkout" and "payment_method[reference_id]" with the Billing Agreement ID.

Amazon Payments
You can use this API only if you are using your own hosted pages for Amazon Payments. When your customer updates Amazon Payments as a payment method from your hosted pages, you will be provided with the Billing Agreement ID by Amazon. You can update the Billing Agreement ID in Chargebee by passing "payment_method[type]" as "amazon_payments" and "payment_method[reference_id]" with the Billing Agreement ID.

Card Payments
When the card details of your customer are stored in the vault of gateways such as Stripe or Braintree, you can use this API to update in Chargebee the token provided by them. To use this API for card payments, pass
  • payment_method[type] as "card".
  • payment_method[gateway] with the preferred gateway. If the gateway is not specified, the default gateway will be used.
  • payment_method[reference_id] with the token provided by the gateway.
How to pass payment_method[reference_id]?
  • In case of Stripe, the reference_id consists of Stripe Customer ID and Stripe Card ID. The format to be passed in payment_method[reference_id] is Stripe Customer ID/Stripe Card ID. If you are passing Stripe Customer ID alone, then ChargeBee will fetch all the cards mapped to the Stripe Customer ID and store only the active Card ID of that customer.
  • In case of Braintree, the reference_id consists of Braintree Customer ID and Braintree Payment Method Token. The format to be passed in payment_method[reference_id] is Braintree Customer ID/Braintree Payment Method Token. If you are passing Braintree Customer ID alone, then Chargebee will fetch all the Payment Methods mapped to the Braintree Customer ID and store only the default Payment Method Token of that customer.
  • If the card details are stored in Spreedly vault, then you need to provide the Spreedly token in payment_method[reference_id].

Note: If you wish to pass the card number, CVV, or the single-use card token provided by the gateway, then use the "Update Card for a customer" API.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::updatePaymentMethod("8avVGOkx8U1MX", array(
  "paymentMethod" => array(
    "type" => "paypal_express_checkout", 
    "referenceId" => "B-09u9343Sde24D"
  )));
$customer = $result->customer();
$card = $result->card();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::updatePaymentMethod("8avVGOkx8U1MX", array(
  "paymentMethod" => array(
    "type" => "paypal_express_checkout", 
    "referenceId" => "B-09u9343Sde24D"
  )));
$customer = $result->customer();
$card = $result->card();

Sample Result [ JSON ]

{"customer": { "id": "8avaNPGeKPyo4M", "first_name": "John", "last_name": "Doe", "email": "john@test.com", "auto_collection": "on", "created_at": 1435259934, "object": "customer", "billing_address": { "first_name": "Saravanan", "last_name": "KP", "phone": "123456", "line1": "1 Main St", "city": "San Jose", "state_code": "CA", "state": "California", "country": "US", "zip": "95131", "object": "billing_address" }, "payment_method": { "object": "payment_method", "type": "paypal_express_checkout", "reference_id": "B-65K743363W456623Y", "status": "valid" }, "account_credits": 0 }}

Method

ChargeBee_Customer::updatePaymentMethod(<customer_id>,array(<param name> => <value>,<param name> => <value> ...))
paymentMethod
Associative array of parameters for paymentMethod
pass parameters as paymentMethod => array("<param name>" => "<value>",...)
type
Type of payment method.
required, enumerated string
Possible values are:
card :Card based payment. Both credit cards and debit cards included.In case it is card then details about the card can be got from card resource.paypal_express_checkout :Paypal Express Checkout based payment.amazon_payments :Amazon login and pay based payment.
gateway
Name of the gateway this card is stored with.
optional, enumerated string
Possible values are:
stripe :Stripe payment gateway.braintree :Braintree payment gateway.authorize_net :Authorize.net payment gateway.
paypal_pro :Paypal Pro Account.pin :Pin payment gateway.eway :eWAy Account.eway_rapid :eWAy Rapid gateway.worldpay :WorldPay payment gateway.balanced_payments :Balanced payment gateway.beanstream :Beanstream Account.bluepay :BluePay payment gateway.elavon :Elavon Virtual Merchant.first_data_global :First Data Global Gateway Virtual Terminal Account.hdfc :HDFC Account.migs :MasterCard Internet Gateway Service.nmi :NMI gateway.ogone :Ogone Account.paymill :Paymill payment gateway.paypal_payflow_pro :Paypal Payflow Pro gateway.sage_pay :Sage Pay gateway.tco :2Checkout payment gateway.wirecard :WireCard Account.not_applicable :Indicates that payment gateway is not applicable for this resource.
Show all values[+]
referenceId
The reference id. Incase of amazon and paypal it is billing agreement id. Incase of card it is the token provided by the gateway/card vault.
required, string, max chars=50
Resource object representing customer.
always returned
Resource object representing card.
optional

This method is used for updating the 'Billing Info' - the Billing Address and 'vat_number' attributes - of the customer. For updating the other customer attributes use our Update Customer API.

During this operation if Billing Info(Billing Address and vat_number) is not already present it will get added. Whereas if it is present already, the existing values will be replaced. i.e existing values for Billing Address and vat_number will be cleared and the new values will be set.

Note: When an invoice is generated for a customer, the billing address provided for the customer will be stored with the invoice. If the First Name, Last Name, and Company fields do not contain any information under Billing Info, the same will be picked from Customer Details if the same is available there.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::updateBillingInfo("8avVGOkx8U1MX", array(
  "billingAddress" => array(
    "firstName" => "John", 
    "lastName" => "Doe", 
    "line1" => "PO Box 9999", 
    "city" => "Walnut", 
    "state" => "California", 
    "zip" => "91789", 
    "country" => "US"
  )));
$customer = $result->customer();
$card = $result->card();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::updateBillingInfo("8avVGOkx8U1MX", array(
  "billingAddress" => array(
    "firstName" => "John", 
    "lastName" => "Doe", 
    "line1" => "PO Box 9999", 
    "city" => "Walnut", 
    "state" => "California", 
    "zip" => "91789", 
    "country" => "US"
  )));
$customer = $result->customer();
$card = $result->card();

Sample Result [ JSON ]

{"customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407453, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 0 }}

Method

ChargeBee_Customer::updateBillingInfo(<customer_id>,array(<param name> => <value>,<param name> => <value> ...))
vatNumber
VAT number of this customer. Will be validated using the VIES service. To disable this validation, go to 'Settings -> Site Info' page and select the checkbox 'Disable VAT validation'.
optional, string, max chars=20
billingAddress
Associative array of parameters for billingAddress
pass parameters as billingAddress => array("<param name>" => "<value>",...)
firstName
First name.
optional, string, max chars=150
lastName
Last name.
optional, string, max chars=150
email
Email.
optional, string, max chars=70
company
Company name.
optional, string, max chars=250
phone
Phone number.
optional, string, max chars=50
line1
Address line 1.
optional, string, max chars=150
line2
Address line 2.
optional, string, max chars=150
line3
Address line 3.
optional, string, max chars=150
city
City.
optional, string, max chars=50
stateCode
The ISO 3166-2 state/province code. The recommended way of passing the state/province information. Supported for US and Canada now. Further if this is specified, 'state' attribute should not be specified as it will be set automatically.
optional, string, max chars=50
state
The state/province name. Use this to pass the state/province information for cases where 'state_code' is not supported or cannot be passed.
optional, string, max chars=50
zip
Zip or Postal code.
optional, string, max chars=20
country
2-letter ISO 3166 alpha-2 country code.
optional, string, max chars=50
Resource object representing customer.
always returned
Resource object representing card.
optional

This API call can be used to add credits to a customer. Learn more about Account Credits.

For example, if a customer has credits of $10, if you pass the amount as $10, then the customer’s credit balance would become $20.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::addAccountCredits("8avVGOkx8U1MX", array(
  "amount" => 500, 
  "description" => "Loyalty credits"));
$customer = $result->customer();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::addAccountCredits("8avVGOkx8U1MX", array(
  "amount" => 500, 
  "description" => "Loyalty credits"));
$customer = $result->customer();

Sample Result [ JSON ]

{"customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407453, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 500 }}

Method

ChargeBee_Customer::addAccountCredits(<customer_id>,array(<param name> => <value>,<param name> => <value> ...))
amount
Credit amount to be added.
required, in cents, min=1
description
Description for this credit.
required, string, max chars=250
Resource object representing customer.
always returned

This API call can be used to deduct credits for a customer. Learn more about Account Credits.

For example, if a customer has a credit balance of $20, if you pass the amount as $5, then the customer’s credit balance would become $15.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::deductAccountCredits("8avVGOkx8U1MX", array(
  "amount" => 200, 
  "description" => "Correcting credits given by mistake"));
$customer = $result->customer();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::deductAccountCredits("8avVGOkx8U1MX", array(
  "amount" => 200, 
  "description" => "Correcting credits given by mistake"));
$customer = $result->customer();

Sample Result [ JSON ]

{"customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407453, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 300 }}

Method

ChargeBee_Customer::deductAccountCredits(<customer_id>,array(<param name> => <value>,<param name> => <value> ...))
amount
Credit amount to be deducted.
required, in cents, min=1
description
Description for this credit.
required, string, max chars=250
Resource object representing customer.
always returned

This API call can be used to set credits for a customer. Learn more about Account Credits.

For example, if a customer has a credit balance of $10 and if you would like to set the balance to $100, you could pass the amount as $100.

Sample Code
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::setAccountCredits("8avVGOkx8U1MX", array(
  "amount" => 1200, 
  "description" => "Correcting credits given by mistake"));
$customer = $result->customer();
copy
require 'ChargeBee.php';
ChargeBee_Environment::configure("{site}","{site_api_key}");
$result = ChargeBee_Customer::setAccountCredits("8avVGOkx8U1MX", array(
  "amount" => 1200, 
  "description" => "Correcting credits given by mistake"));
$customer = $result->customer();

Sample Result [ JSON ]

{"customer": { "id": "8avVGOkx8U1MX", "first_name": "Denise", "last_name": "Barone", "email": "Benjamin@test.com", "auto_collection": "off", "created_at": 1317407453, "object": "customer", "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state_code": "CA", "state": "California", "country": "US", "zip": "91789", "object": "billing_address" }, "card_status": "no_card", "account_credits": 1200 }}

Method

ChargeBee_Customer::setAccountCredits(<customer_id>,array(<param name> => <value>,<param name> => <value> ...))
amount
Credit amount to be set.
required, in cents, min=0
description
Description for this credit.
required, string, max chars=250
Resource object representing customer.
always returned