You can download the latest source code from GitHub. There's also instructions on how to use this without CodeIgniter.
The following guide outlines the functions available in the Chargify API class for CodeIgniter. You will need a Chargify account with API access enabled.
Creates a charge on a valid, active subscription. The subscription must be referenced by the subscription ID.
The following will create a charge for 10.00 on the subscription with ID 1000:
$charge_array = array( 'amount' => '10.00', 'memo' => 'This is the description for a one-time charge.' ); $this->chargify->create_charge(1000, $charge_array);
If you want to create a charge with a cents value, you will need to use amount_in_cents:
$charge_array = array( 'amount_in_cents' => '1000', 'memo' => 'This is the description for a one-time charge.' ); $this->chargify->create_charge(1000, $charge_array);
If a chage is successful, you will receive the following array back:
stdClass Object ( [success] => true [memo] => 'This is the description for a one-time charge.' [amount] => 10.00 )
If the subscription ID does not exist, a false value will be returned.
Below are the error messages that can be returned:
| Error Message | Explanation |
|---|---|
| Memo: cannot be blank. | The memo attribute is empty. |
| Amount: is not a number. | The amount attribute is not an integer. |
| This subscription is not eligible to accept charges. | The subscription is not active, e.g. it has been canceled. |
| Bogus Gateway: Forced failure (Payment for: This is the description of the one time charge.) | The charge has been declined by the payment gateway. |
Gets a list of all the metered components for a particular product family.
The following will list all the components for a product family with ID 100:
$this->chargify->get_components(100);
If the product family exists and has at least one component, something similar to the following array will be returned:
Array ( [0] => stdClass Object ( [id] => AUTO_GENERATED_ID [name] => COMPONENT NAME [unit_name] => UNIT NAME [product_family_id] => 100 [kind] => quantity_based_component // metered_component, quantity_based_component [pricing_scheme] => per_unit // per_unit, volume, tiered, stairstep (only available for quantity based components) [price_per_unit_in_cents] => 100 [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 ) )
If the product family does not exist, a false value will be returned.
Gets the component usage(s) for a particular subscription and component.
The following will list the component usage(s) for a subscription, where the subscription ID is 1000, and the component ID is 100:
$this->chargify->get_component_usage(1000, 100);
If the product family exists and has at least one metered component, and the subscription is active and has a product assigned to it with a metered component, something similar to the following array will be returned:
Array ( [0] => stdClass Object ( [id] => 100 [subscriptions_component_id] => 10000 [quantity] => 10 [memo] => An optional description of the usage set when you create a usage [recorded] => ) )
If the above scenario is not true, a false value will be returned.
Creates a usage for a subscription.
The following will record a new metered usage of 10 units for a subscription, where the subscription ID is 1000, and the component ID is 100:
$usage_array = array( 'quantity' => '10', 'memo' => 'An optional description of the usage' ); $this->chargify->create_component_usage(1000, 100, $usage_array);
If the product family exists and has a metered component, and the subscription is active and has a product assigned to it with a metered component, something similar to the following array will be returned:
stdClass Object ( [id] => AUTO_GENERATED_ID [quantity] => 10 [memo] => An optional description of the usage )
If the above scenario is not true, a false value will be returned.
Gets a coupon's information. Useful for validating a coupon ID or code.
The following will get all the information for a coupon with ID 100 that is in the product family with ID 1000:
$this->chargify->get_coupon(1000, 100);
If you prefer to get a coupon based on the name rather than the ID, simply do this:
$this->chargify->get_coupon(1000, 'NOSETUP');
If you are looking up a coupon based on the code, but it only contains numbers, you will need to do this:
$this->chargify->get_coupon(1000, 999, false);
Assuming the product family exists and has a coupon available, the following array will be returned:
stdClass Object ( [start_date] => YYYY-MM-DDTHH:MM:SS-04:00 [name] => COUPON NAME [end_date] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [code] => COUPON_CODE [id] => AUTO_GENERATED_ID [product_family_id] => 1000 [description] => Coupon description displayed to customers [amount_in_cents] => 2000 [percentage] => // A value of 1-100 if the coupon takes a percentage off [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 )
If a coupon cannot be found, a false value will be returned.
Add a credit to a valid, active subscription
The following will add a credit of 10.00 on the subscription with ID 1000:
$credit_array = array( 'amount' => '10.00', 'memo' => 'This is the description for a credit.' ); $this->chargify->add_credit(1000, $credit_array);
If you want to add a credit with a cents value, you will need to use amount_in_cents:
$credit_array = array( 'amount_in_cents' => '1000', 'memo' => 'This is the description for a credit.' ); $this->chargify->add_credit(1000, $credit_array);
If a credit has been successfully added, you will receive the following array back:
stdClass Object ( [type] => Credit [memo] => This is the description for a credit. [id] => AUTO_GENERATED_ID [ending_balance_in_cents] => 1000 // A negative or positive value [amount_in_cents] => 1000 [success] => 1 [subscription_id] => 1000 [product_id] => 100 [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 )
If the subscription ID does not exist, a false value will be returned.
Below are the error messages that can be returned:
| Error Message | Explanation |
|---|---|
| Memo: cannot be blank. | The memo attribute is empty. |
| Amount: is not a number. | The amount attribute is not an integer. |
| Amount: must be greater than or equal to 0. | The amount must be a positive integer. |
| This subscription is not eligible to accept credits. | The subscription is not active, e.g. it has been canceled. |
| [Gateway response if a gateway fail] ([Your original memo]) | The credit has been declined by the payment gateway. |
Get a single customer's information.
The following will get the customer information with a Chargify ID of 1000:
$this->chargify->get_customer(1000);
If you want to look up a customer by a reference ID, you would do the following:
$this->chargify->get_customer('REFERENCE_ID', 'local');
If a customer with the Chargify or reference ID exists, the following array will be returned:
stdClass Object ( [id] => 1000 [first_name] => FIRST NAME [last_name] => LAST NAME [organization] => COMPANY / ORGANIZATION [address] => ADDRESS LINE 1 [address_2] => ADDRESS LINE 2 [city] => CITY [state] => STATE [zip] => ZIP [country] => COUNTRY CODE [email] => email@address.com [phone] => 1234567890 [reference] => REFERENCE_ID [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 )
If the customer ID does not exist, a false value will be returned.
Get multiple customers' information.
The following will get a list of customers, up to 50 per page:
$this->chargify->get_customers();
If you want to get customers on a different page, you would do the following:
$this->chargify->get_customers(10);
Where 10 would be the page number.
Assuming you have at least one customer, the following array will be returned:
Array ( [0] => stdClass Object ( [id] => 1000 [first_name] => FIRST NAME [last_name] => LAST NAME [organization] => COMPANY / ORGANIZATION [address] => ADDRESS LINE 1 [address_2] => ADDRESS LINE 2 [city] => CITY [state] => STATE [zip] => ZIP [country] => COUNTRY CODE [email] => email@address.com [phone] => 1234567890 [reference] => REFERENCE_ID [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 ) )
If no customers exist, a false value will be returned.
Get a single customer's subscription(s).
The follwing will return the subscriptions for a single customer with a Chargify ID of 1000:
$this->chargify->get_customer_subscriptions(1000);
If the customer has at least one subscription, the following array will be returned:
Array ( [0] => stdClass Object ( [id] => 1000 [state] => The subscription state (trialing, assessing, active, soft_failure, past_due, suspended, canceled, expired) [balance_in_cents] => 0 [customer] => stdClass Object ( [id] => 1000 [first_name] => FIRST NAME [last_name] => LAST NAME [organization] => ORGANIZTION / COMPANY NAME [address] => ADDRESS LINE 1 [address_2] => ADDRESS LINE 2 [city] => CITY [state] => STATE [zip] => ZIP [country] => COUNTRY CODE [email] => email@address.com [phone] => 1234567890 [reference] => REFERENCE_ID [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 ) [product] => stdClass Object ( [id] => 100 [name] => The product name [handle] => The product API handle [description] => The product description [product_family] => stdClass Object ( [id] => 1000 [name] => The product family name [handle] => The product family API handle [description] => The product family description [accounting_code] => The product family account code (used with your own application) ) [price_in_cents] => The product price in cents [initial_charge_in_cents] => The up front charge in cents [trial_price_in_cents] => The price of the trial period for a subscription to this product [interval] => The numerical interval [interval_unit] => The interval unit (day, month) [trial_interval] => A numerical interval for the length of the trial period of a subscription to this product [trial_interval_unit] => The trial interval unit (day, month) [expiration_interval] => The numerical interval for the length a subscription should run before it expires [expiration_interval_unit] => The expiration interval unit (never, day, month) [return_url] => The URL a buyer is returned to after purchase [return_params] => Paramaters string that will be used when constructing the return URL [require_credit_card] => (1/0) [request_credit_card] => (1/0) [accounting_code] => Local accounting code [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [archived_at] => YYYY-MM-DDTHH:MM:SS-04:00 (if archived) ) [credit_card] => stdClass Object ( [first_name] => FIRST NAME [last_name] => LAST NAME [billing_address] => ADDRESS LINE 1 [billing_address_2] => ADDRESS LINE 2 [billing_city] => CITY [billing_state] => STATE [billing_zip] => ZIP [billing_country] => COUNTRY CODE [current_vault] => bogus [vault_token] => 1 [customer_vault_token] => [card_type] => bogus [masked_card_number] => XXXX-XXXX-XXXX-XXXX [expiration_month] => M [expiration_year] => YYYY ) [next_assessment_at] => YYYY-MM-DDTHH:MM:SS-04:00 [current_period_started_at] => YYYY-MM-DDTHH:MM:SS-04:00 [current_period_ends_at] => YYYY-MM-DDTHH:MM:SS-04:00 [trial_started_at] => YYYY-MM-DDTHH:MM:SS-04:00 [trial_ended_at] => YYYY-MM-DDTHH:MM:SS-04:00 [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [activated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [expires_at] => YYYY-MM-DDTHH:MM:SS-04:00 [cancellation_message] => If the subscription has been canceled (now or at one point), the message will go here ) )
If no customers exist, a false value will be returned.
Create a new customer.
If you want to create a new customer you would do the following:
$customer_array = array( 'first_name' => 'John', 'last_name' => 'Doe', 'organization' => 'Acme Products, Inc', 'address' => '123 Happy St', 'address_2' => 'Ste 420', 'city' => 'New York', 'state' => 'NY', 'zip' => '11111', 'country' => 'US', 'email' => 'john.doe@domain.com', 'phone' => '1234567890', 'reference' => 'MY_REF_1000' ); $this->chargify->create_customer($customer_array);
Only the first_name, last_name, and email are required. The rest are optional, though the reference ID is strongly encouraged.
If the customer has been created, the following array will be returned:
stdClass Object ( [id] => AUTO_GENERATED_ID [first_name] => John [last_name] => Doe [organization] => Acme Products, Inc [address] => 123 Happy St [address_2] => Ste 420 [city] => New York [state] => NY [zip] => 11111 [country] => US [email] => john.doe@domain.com [phone] => 1234567890 [reference] => MY_REF_1009 [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 )
Edit customer information.
The following will update the email address on a customer with ID 1000:
$customer_array = array( 'email' => 'new.email@address.com' ); $this->chargify->edit_customer(1000, $customer_array);
If the customer's information has been edited, the following array will be returned:
stdClass Object ( [id] => 1000 [first_name] => John [last_name] => Doe [organization] => Acme Products, Inc [address] => 123 Happy St [address_2] => Ste 420 [city] => New York [state] => NY [zip] => 11111 [country] => US [email] => new.email@address.com [phone] => 1234567890 [reference] => MY_REF_1000 [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 )
If the customer you're trying to edit does not exist, a false value will be returned.
Deletes a customer.
If you want to delete a customer with ID 1000, you would do the following:
$this->chargify->delete_customer(1000);
NOTE: You can not delete a customer at this time. You will receive a 403 response code back.
Gets a single product's information.
The following will get the product information with a Chargify ID of 100:
$this->chargify->get_product(100);
If you want to look up a product by a reference ID, you would do the following:
$this->chargify->get_product('REFERENCE_ID', 'local');
If a product with the Chargify or reference ID exists, the following array will be returned:
stdClass Object ( [id] => 100 [name] => The product name [handle] => The product API handle [description] => The product description [product_family] => stdClass Object ( [id] => 1000 [name] => The product family name [handle] => The product family API handle [description] => The product family description [accounting_code] => The product family account code (used with your own application) ) [price_in_cents] => The product price in cents [initial_charge_in_cents] => The up front charge in cents [trial_price_in_cents] => The price of the trial period for a subscription to this product [interval] => The numerical interval [interval_unit] => The interval unit (day, month) [trial_interval] => A numerical interval for the length of the trial period of a subscription to this product [trial_interval_unit] => The trial interval unit (day, month) [expiration_interval] => The numerical interval for the length a subscription should run before it expires [expiration_interval_unit] => The expiration interval unit (never, day, month) [return_url] => The URL a buyer is returned to after purchase [return_params] => Paramaters string that will be used when constructing the return URL [require_credit_card] => (1/0) [request_credit_card] => (1/0) [accounting_code] => Local accounting code [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [archived_at] => YYYY-MM-DDTHH:MM:SS-04:00 (if archived) )
If the product you're trying to lookup does not exist, a false value will be returned.
Get a list of all products.
The following will get a list of products:
$this->chargify->get_products();
If at least one product exists, the following array will be returned:
Array ( [0] => stdClass Object ( [id] => 100 [name] => The product name [handle] => The product API handle [description] => The product description [product_family] => stdClass Object ( [id] => 1000 [name] => The product family name [handle] => The product family API handle [description] => The product family description [accounting_code] => The product family account code (used with your own application) ) [price_in_cents] => The product price in cents [initial_charge_in_cents] => The up front charge in cents [trial_price_in_cents] => The price of the trial period for a subscription to this product [interval] => The numerical interval [interval_unit] => The interval unit (day, month) [trial_interval] => A numerical interval for the length of the trial period of a subscription to this product [trial_interval_unit] => The trial interval unit (day, month) [expiration_interval] => The numerical interval for the length a subscription should run before it expires [expiration_interval_unit] => The expiration interval unit (never, day, month) [return_url] => The URL a buyer is returned to after purchase [return_params] => Paramaters string that will be used when constructing the return URL [require_credit_card] => (1/0) [request_credit_card] => (1/0) [accounting_code] => Local accounting code [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [archived_at] => YYYY-MM-DDTHH:MM:SS-04:00 (if archived) ) )
If no products exist, a false value will be returned.
Issue a refund on a transaction.
This only works with the Authorize.Net payment gateway.
The following will issue a $10.00 refund on subscription with ID 100:
$refund_array = array( 'payment_id' => 12345, 'amount' => '10.00', 'memo' => 'A helpful explanation for the refund. This amount will remind you and your customer for the reason for the refund.' ); $this->chargify->refund(100, $refund_array);
If the refund is issued, the following array will be returned:
stdClass Object ( [payment_id] => The ID of the transaction/payment that the refund will be applied to [success] => Either 'true' or 'false', depending on the success of the refund [amount_in_cents] => The amount of the refund and captured payment, represented in cents [memo] => The memo created for the refund )
Get a single subscription's information.
The following will get the subscription information with a subscription ID of 1000:
$this->chargify->get_subscription(1000);
If a subscription exists, the following array will be returned:
stdClass Object ( [id] => 1000 [state] => The subscription state (trialing, assessing, active, soft_failure, past_due, suspended, canceled, expired) [balance_in_cents] => 0 [customer] => stdClass Object ( [id] => 1000 [first_name] => FIRST NAME [last_name] => LAST NAME [organization] => ORGANIZTION / COMPANY NAME [address] => ADDRESS LINE 1 [address_2] => ADDRESS LINE 2 [city] => CITY [state] => STATE [zip] => ZIP [country] => COUNTRY CODE [email] => email@address.com [phone] => 1234567890 [reference] => REFERENCE_ID [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 ) [product] => stdClass Object ( [id] => 100 [name] => The product name [handle] => The product API handle [description] => The product description [product_family] => stdClass Object ( [id] => 1000 [name] => The product family name [handle] => The product family API handle [description] => The product family description [accounting_code] => The product family account code (used with your own application) ) [price_in_cents] => The product price in cents [initial_charge_in_cents] => The up front charge in cents [trial_price_in_cents] => The price of the trial period for a subscription to this product [interval] => The numerical interval [interval_unit] => The interval unit (day, month) [trial_interval] => A numerical interval for the length of the trial period of a subscription to this product [trial_interval_unit] => The trial interval unit (day, month) [expiration_interval] => The numerical interval for the length a subscription should run before it expires [expiration_interval_unit] => The expiration interval unit (never, day, month) [return_url] => The URL a buyer is returned to after purchase [return_params] => Paramaters string that will be used when constructing the return URL [require_credit_card] => (1/0) [request_credit_card] => (1/0) [accounting_code] => Local accounting code [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [archived_at] => YYYY-MM-DDTHH:MM:SS-04:00 (if archived) ) [credit_card] => stdClass Object ( [first_name] => FIRST NAME [last_name] => LAST NAME [billing_address] => ADDRESS LINE 1 [billing_address_2] => ADDRESS LINE 2 [billing_city] => CITY [billing_state] => STATE [billing_zip] => ZIP [billing_country] => COUNTRY CODE [current_vault] => bogus [vault_token] => 1 [customer_vault_token] => [card_type] => bogus [masked_card_number] => XXXX-XXXX-XXXX-XXXX [expiration_month] => M [expiration_year] => YYYY ) [next_assessment_at] => YYYY-MM-DDTHH:MM:SS-04:00 [current_period_started_at] => YYYY-MM-DDTHH:MM:SS-04:00 [current_period_ends_at] => YYYY-MM-DDTHH:MM:SS-04:00 [trial_started_at] => YYYY-MM-DDTHH:MM:SS-04:00 [trial_ended_at] => YYYY-MM-DDTHH:MM:SS-04:00 [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [activated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [expires_at] => YYYY-MM-DDTHH:MM:SS-04:00 [cancellation_message] => If the subscription has been canceled (now or at one point), the message will go here )
If no subscription exists, a false value will be returned.
Get multiple subscriptions' information.
The following will return an array of 2000 subscriptions, the default setting:
$this->chargify->get_subscriptions();
If you want to specify a page number or increase the results per page, you would do the following:
$this->chargify->get_subscriptions(10, 5000);
Where 10 is the page number, and 5000 is the results per page.
If at least one subscription exists, the following array will be returned:
Array ( [0] => stdClass Object ( [id] => 1000 [state] => The subscription state (trialing, assessing, active, soft_failure, past_due, suspended, canceled, expired) [balance_in_cents] => 0 [customer] => stdClass Object ( [id] => 1000 [first_name] => FIRST NAME [last_name] => LAST NAME [organization] => ORGANIZTION / COMPANY NAME [address] => ADDRESS LINE 1 [address_2] => ADDRESS LINE 2 [city] => CITY [state] => STATE [zip] => ZIP [country] => COUNTRY CODE [email] => email@address.com [phone] => 1234567890 [reference] => REFERENCE_ID [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 ) [product] => stdClass Object ( [id] => 100 [name] => The product name [handle] => The product API handle [description] => The product description [product_family] => stdClass Object ( [id] => 1000 [name] => The product family name [handle] => The product family API handle [description] => The product family description [accounting_code] => The product family account code (used with your own application) ) [price_in_cents] => The product price in cents [initial_charge_in_cents] => The up front charge in cents [trial_price_in_cents] => The price of the trial period for a subscription to this product [interval] => The numerical interval [interval_unit] => The interval unit (day, month) [trial_interval] => A numerical interval for the length of the trial period of a subscription to this product [trial_interval_unit] => The trial interval unit (day, month) [expiration_interval] => The numerical interval for the length a subscription should run before it expires [expiration_interval_unit] => The expiration interval unit (never, day, month) [return_url] => The URL a buyer is returned to after purchase [return_params] => Paramaters string that will be used when constructing the return URL [require_credit_card] => (1/0) [request_credit_card] => (1/0) [accounting_code] => Local accounting code [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [archived_at] => YYYY-MM-DDTHH:MM:SS-04:00 (if archived) ) [credit_card] => stdClass Object ( [first_name] => FIRST NAME [last_name] => LAST NAME [billing_address] => ADDRESS LINE 1 [billing_address_2] => ADDRESS LINE 2 [billing_city] => CITY [billing_state] => STATE [billing_zip] => ZIP [billing_country] => COUNTRY CODE [current_vault] => bogus [vault_token] => 1 [customer_vault_token] => [card_type] => bogus [masked_card_number] => XXXX-XXXX-XXXX-XXXX [expiration_month] => M [expiration_year] => YYYY ) [next_assessment_at] => YYYY-MM-DDTHH:MM:SS-04:00 [current_period_started_at] => YYYY-MM-DDTHH:MM:SS-04:00 [current_period_ends_at] => YYYY-MM-DDTHH:MM:SS-04:00 [trial_started_at] => YYYY-MM-DDTHH:MM:SS-04:00 [trial_ended_at] => YYYY-MM-DDTHH:MM:SS-04:00 [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [activated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [expires_at] => YYYY-MM-DDTHH:MM:SS-04:00 [cancellation_message] => If the subscription has been canceled (now or at one point), the message will go here ) )
If no subscriptions exist, a false value will be returned.
Creates a subscription on a new or existing customer.
The following will create a new subscription on an existing customer:
$subscription_array = array( 'product_id' => 100, 'customer_id' => 1000, 'credit_card_attributes' => array( 'first_name' => 'John', 'last_name' => 'Doe', 'billing_address' => '123 Happy St', 'billing_address_2' => 'Ste 420', 'billing_city' => 'New York', 'billing_state' => 'NY', 'billing_zip' => '11111', 'billing_country' => 'US', 'full_number' => The full credit card number 'expiration_month' => The 1- or 2-digit credit card expiration month, as an integer 'expiration_year' => The 4-digit credit card expiration year, as an integer 'cvv' => The 3- or 4-digit Card Verification Value ) ); $this->chargify->create_subscription($subscription_array);
You can reference the existing customer using either the Chargify ID or local reference handle. If you want to use a reference handle, you would use the customer_reference key instead of customer_id:
$subscription_array = array( 'product_id' => 100, 'customer_reference' => 'MY_REF_1000', 'credit_card_attributes' => array( 'first_name' => 'John', 'last_name' => 'Doe', 'billing_address' => '123 Happy St', 'billing_address_2' => 'Ste 420', 'billing_city' => 'New York', 'billing_state' => 'NY', 'billing_zip' => '11111', 'billing_country' => 'US', 'full_number' => The full credit card number 'expiration_month' => The 1- or 2-digit credit card expiration month, as an integer 'expiration_year' => The 4-digit credit card expiration year, as an integer 'cvv' => The 3- or 4-digit Card Verification Value ) ); $this->chargify->create_subscription($subsription_array);
If the subscription has been created, the following array will be returned:
Array ( [0] => stdClass Object ( [id] => 1000 [state] => The subscription state (trialing, assessing, active, soft_failure, past_due, suspended, canceled, expired) [balance_in_cents] => 0 [customer] => stdClass Object ( [id] => 1000 [first_name] => FIRST NAME [last_name] => LAST NAME [organization] => ORGANIZTION / COMPANY NAME [address] => ADDRESS LINE 1 [address_2] => ADDRESS LINE 2 [city] => CITY [state] => STATE [zip] => ZIP [country] => COUNTRY CODE [email] => email@address.com [phone] => 1234567890 [reference] => REFERENCE_ID [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 ) [product] => stdClass Object ( [id] => 100 [name] => The product name [handle] => The product API handle [description] => The product description [product_family] => stdClass Object ( [id] => 1000 [name] => The product family name [handle] => The product family API handle [description] => The product family description [accounting_code] => The product family account code (used with your own application) ) [price_in_cents] => The product price in cents [initial_charge_in_cents] => The up front charge in cents [trial_price_in_cents] => The price of the trial period for a subscription to this product [interval] => The numerical interval [interval_unit] => The interval unit (day, month) [trial_interval] => A numerical interval for the length of the trial period of a subscription to this product [trial_interval_unit] => The trial interval unit (day, month) [expiration_interval] => The numerical interval for the length a subscription should run before it expires [expiration_interval_unit] => The expiration interval unit (never, day, month) [return_url] => The URL a buyer is returned to after purchase [return_params] => Paramaters string that will be used when constructing the return URL [require_credit_card] => (1/0) [request_credit_card] => (1/0) [accounting_code] => Local accounting code [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [archived_at] => YYYY-MM-DDTHH:MM:SS-04:00 (if archived) ) [credit_card] => stdClass Object ( [first_name] => FIRST NAME [last_name] => LAST NAME [billing_address] => ADDRESS LINE 1 [billing_address_2] => ADDRESS LINE 2 [billing_city] => CITY [billing_state] => STATE [billing_zip] => ZIP [billing_country] => COUNTRY CODE [current_vault] => bogus [vault_token] => 1 [customer_vault_token] => [card_type] => bogus [masked_card_number] => XXXX-XXXX-XXXX-XXXX [expiration_month] => M [expiration_year] => YYYY ) [next_assessment_at] => YYYY-MM-DDTHH:MM:SS-04:00 [current_period_started_at] => YYYY-MM-DDTHH:MM:SS-04:00 [current_period_ends_at] => YYYY-MM-DDTHH:MM:SS-04:00 [trial_started_at] => YYYY-MM-DDTHH:MM:SS-04:00 [trial_ended_at] => YYYY-MM-DDTHH:MM:SS-04:00 [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [activated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [expires_at] => YYYY-MM-DDTHH:MM:SS-04:00 [cancellation_message] => If the subscription has been canceled (now or at one point), the message will go here ) )
If you want to create a new customer and subscription at the same time, you would do the following:
$subscription_array = array( 'product_id' => 100, 'customer_attributes' => array( 'first_name' => 'John', 'last_name' => 'Doe', 'organization' => 'Acme Products, Inc', 'address' => '123 Happy St', 'address_2' => 'Ste 420', 'city' => 'New York', 'state' => 'NY', 'zip' => '11111', 'country' => 'US', 'email' => 'john.doe@domain.com', 'phone' => '1234567890', 'reference' => 'MY_REF_1000' ), 'credit_card_attributes' => array( 'first_name' => 'John', 'last_name' => 'Doe', 'billing_address' => '123 Happy St', 'billing_address_2' => 'Ste 420', 'billing_city' => 'New York', 'billing_state' => 'NY', 'billing_zip' => '11111', 'billing_country' => 'US', 'full_number' => The full credit card number 'expiration_month' => The 1- or 2-digit credit card expiration month, as an integer 'expiration_year' => The 4-digit credit card expiration year, as an integer 'cvv' => The 3- or 4-digit Card Verification Value ) ); $this->chargify->create_subscription($subscription_array);
If the subscription and customer have been created, the following array will be returned:
Array ( [0] => stdClass Object ( [id] => 1000 [state] => The subscription state (trialing, assessing, active, soft_failure, past_due, suspended, canceled, expired) [balance_in_cents] => 0 [customer] => stdClass Object ( [id] => 1000 [first_name] => FIRST NAME [last_name] => LAST NAME [organization] => ORGANIZTION / COMPANY NAME [address] => ADDRESS LINE 1 [address_2] => ADDRESS LINE 2 [city] => CITY [state] => STATE [zip] => ZIP [country] => COUNTRY CODE [email] => email@address.com [phone] => 1234567890 [reference] => REFERENCE_ID [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 ) [product] => stdClass Object ( [id] => 100 [name] => The product name [handle] => The product API handle [description] => The product description [product_family] => stdClass Object ( [id] => 1000 [name] => The product family name [handle] => The product family API handle [description] => The product family description [accounting_code] => The product family account code (used with your own application) ) [price_in_cents] => The product price in cents [initial_charge_in_cents] => The up front charge in cents [trial_price_in_cents] => The price of the trial period for a subscription to this product [interval] => The numerical interval [interval_unit] => The interval unit (day, month) [trial_interval] => A numerical interval for the length of the trial period of a subscription to this product [trial_interval_unit] => The trial interval unit (day, month) [expiration_interval] => The numerical interval for the length a subscription should run before it expires [expiration_interval_unit] => The expiration interval unit (never, day, month) [return_url] => The URL a buyer is returned to after purchase [return_params] => Paramaters string that will be used when constructing the return URL [require_credit_card] => (1/0) [request_credit_card] => (1/0) [accounting_code] => Local accounting code [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [archived_at] => YYYY-MM-DDTHH:MM:SS-04:00 (if archived) ) [credit_card] => stdClass Object ( [first_name] => FIRST NAME [last_name] => LAST NAME [billing_address] => ADDRESS LINE 1 [billing_address_2] => ADDRESS LINE 2 [billing_city] => CITY [billing_state] => STATE [billing_zip] => ZIP [billing_country] => COUNTRY CODE [current_vault] => bogus [vault_token] => 1 [customer_vault_token] => [card_type] => bogus [masked_card_number] => XXXX-XXXX-XXXX-XXXX [expiration_month] => M [expiration_year] => YYYY ) [next_assessment_at] => YYYY-MM-DDTHH:MM:SS-04:00 [current_period_started_at] => YYYY-MM-DDTHH:MM:SS-04:00 [current_period_ends_at] => YYYY-MM-DDTHH:MM:SS-04:00 [trial_started_at] => YYYY-MM-DDTHH:MM:SS-04:00 [trial_ended_at] => YYYY-MM-DDTHH:MM:SS-04:00 [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [activated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [updated_at] => YYYY-MM-DDTHH:MM:SS-04:00 [expires_at] => YYYY-MM-DDTHH:MM:SS-04:00 [cancellation_message] => If the subscription has been canceled (now or at one point), the message will go here ) )
Updates an existing subscription.
The following will update the credit card details on an existing subscription with a subscription ID of 100:
$subscription_array = array( 'credit_card_attributes' => array( 'full_number' => 2 'expiration_month' => 12 'expiration_year' => 2012 'cvv' => 123 ) ); $this->chargify->edit_subscription(100, $subscription_array);
If the update was successful, you'll get the same array returned as in previous examples for the Subscription section.
The following will update (migrate) an existing subscription:
Cancels an existing subscription.
The following will cancel an active subscription with a subscription ID of 100:
$this->chargify->cancel_subscription(100);
If you want to leave a cancellation message, you would do the following:
$subscription_array = array( 'cancellation_message' => 'The reason why this subscription was canceled.' ); $this->chargify->cancel_subscription(100, $subscription_array);
If the cancellation was successful, you'll get the same array returned as in previous examples for the Subscription section.
Reactivates a subscription.
The following will reactivate a previously canceled subscription with a subscription ID of 100:
$this->chargify->reactivate_subscription(100);
If the subscription was reactivated, you'll get the same array returned as in previous examples for the Subscription section.
Resets a subscription's balance.
The following will reset the balance to zero (0) on a subscription with an ID of 100 (assuming it has a positive balance):
$this->chargify->reset_subscription_balance(100);
If the balance was reset, you'll get the same array returned as in previous examples for the Subscription section.
Get a list of all transactions for a subscription.
The following will get all transaction for a subscription with ID 100:
$this->chargify->get_subscription_transactions(100);
An array returned similar to this will be returned:
Array ( [0] => stdClass Object ( [id] => TRANSACTION_ID [subscription_id] => SUBSCRIPTION_ID [product_id] => PRODUCT_ID [type] => The transaction type (charge, refund, payment, credit, payment_authorization, info, adjustment) [memo] => A note about the transaction [ending_balance_in_cents] => The remaining balance on the subscription after the transaction has been processed (can be negative too) [amount_in_cents] => The transaction amount [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [success] => Whether the transaction was successful or not (0, 1) ) )
If no transactions exist, a false value will be returned.
Get a list of all transactions or search for specific transactions based on transaction type (charge, refund, payment, credit, payment authorization, info, adjustment), starting and ending ID, or starting and ending date.
By default, results are limited to 20 per page, as follows:
$this->chargify->get_transactions();
If you want to start on a specific page or increase the number of results per page, you would do the following:
$this->chargify->get_transactions(10, 100);
Where 10 is the page number, and 100 is the results per page.
If you want to list a certain type of transaction, or only a couple different kinds, you would do this:
$types_array = array( 'charge', 'refund', 'credit' ); $this->chargify->get_transactions(1, 20, $types_array);
That would return 20 results of only charges, refunds, and credits.
If you wanted to limit the results down by a starting and ending transaction ID, you would do the following:
$types_array = array( 'charge', 'refund', 'credit' ); $this->chargify->get_transactions(1, 20, $types_array, 100, 1000);
That would return 20 results of only charges, refunds, and credits that had transaction IDs between 100 and 1000.
If you wanted to limit the results down by a starting and ending date, you would do the following:
$types_array = array( 'charge', 'refund', 'credit' ); $this->chargify->get_transactions(1, 20, $types_array, 100, 1000, '2009-01-01', '2009-12-31');
That would return 20 results of only charges, refunds, and credits that had transaction IDs between 100 and 1000 that occurred between January 1, 2009, and December 31, 2009.
You can leave off a starting or ending ID or date to include everything up until or everything before, for example:
$this->chargify->get_transactions(1, 100, '', '', '', '2009-01-01', '');
That would return 100 results of all transaction types starting from January 1, 2009.
The full function can be seen here:
$this->chargify->get_transactions(PAGE_NUMBER, RESULTS_PER_PAGE, TRANSACTION_TYPES, STARTING_TRANSACTION_ID, ENDING_TRANSACTION_ID, START_DATE, END_DATE);
The date must be in the following format: YYYY-MM-DD.
Depending on how you limit the transaction search, you'll have an array returned similar to this:
Array ( [0] => stdClass Object ( [id] => TRANSACTION_ID [subscription_id] => SUBSCRIPTION_ID [product_id] => PRODUCT_ID [type] => The transaction type (charge, refund, payment, credit, payment_authorization, info, adjustment) [memo] => A note about the transaction [ending_balance_in_cents] => The remaining balance on the subscription after the transaction has been processed (can be negative too) [amount_in_cents] => The transaction amount [created_at] => YYYY-MM-DDTHH:MM:SS-04:00 [success] => Whether the transaction was successful or not (0, 1) ) )
If no transactions exist, a false value will be returned.
get_chargify_id($customer_id)
get_reference_id($customer_id)
get_first_name($customer_id, $source = 'remote')
get_last_name($customer_id, $source = 'remote')
get_organization($customer_id, $source = 'remote')
get_address($customer_id, $source = 'remote')
get_address_2($customer_id, $source = 'remote')
get_city($customer_id, $source = 'remote')
get_state($customer_id, $source = 'remote')
get_zip($customer_id, $source = 'remote')
get_country($customer_id, $source = 'remote')
get_email($customer_id, $source = 'remote')
get_phone($customer_id, $source = 'remote')
get_timestamp($customer_id, $source = 'remote', $timestamp = array('created', 'updated'))
get_product_name($product_id, $source = 'remote')
get_product_handle($product_id, $source = 'remote')
get_product_price($product_id, $source = 'remote', $convert_to_dollars = true)
get_product_description($product_id, $source = 'remote')
get_product_timestamp($product_id, $timestamp = array('created', 'updated', 'archived'))
get_subscription_status($subscription_id)
get_subscription_balance($subscription_id, $convert_to_dollars = true)
get_subscription_timestamp($subscription_id, $timestamp = array('created', 'activated', 'updated', 'expiration'))
get_subscription_cancellation_message($subscription_id)
get_card_number($subscription_id)
get_card_type($subscription_id)
get_card_expiration_month($subscription_id, $add_zero = true)
get_card_expiration_year($subscription_id)
get_card_details($subscription_id)
get_charges($page_number = 1, $results_per_page = 20)
get_refunds($page_number = 1, $results_per_page = 20)
get_payments($page_number = 1, $results_per_page = 20)
get_credits($page_number = 1, $results_per_page = 20)
get_payment_authorizations($page_number = 1, $results_per_page = 20)
get_adjustments($page_number = 1, $results_per_page = 20)