API User Guide, Sample Code, Gems, etc.
The Chargify API allows you to keep the customer purchase flow on your own site, while passing the billing information to us for processing. The API attempts to conform to the RESTful design principles. It accepts method calls via HTTP and returns responses as JSON or XML.
In addition to querying, creating, and modifying resources such as your Customers and Subscriptions, you can also use the Chargify API to "authenticate" your users. In this way, you can determine whether a particular user has access to a particular resource on your site. In other words, does User X have access to Plan Y?
The Chargify API also supports callbacks to your own site, so you may be notified of important changes. This allows you to cache subscription data on your site, only making new requests for subscription data from us when we have notified you of a change.
API Wrappers, Sample Code, Gems, etc.
The following wrappers are available for the API. If you have usage examples or code libraries in other languages, we will happily accept your input and can help you host the repositories.
Please note that these samples were graciously given to us by our users, but we don't offer official support for them. Of course, we help where we can, but our internal knowledge is Ruby.
.Net
- http://chargify.codeplex.com: A .Net API wrapper and complete sample app by one of our active beta testers (Kori Francis, @Djbyter)
Java / Scala
- http://github.com/IntroSpectrum/chargify-scala: A Scala API wrapper by one of our active beta testers.
PHP
- http://github.com/jforrest/Chargify-PHP-Client: A PHP API wrapper from Jason at RigBooks
- http://github.com/lewsid/chargify_api_php: A PHP API wrapper by one of our active beta testers.
- http://github.com/abraham/chargify: Sample PHP app by Abraham Williams. http://abrah.am, @abraham
- http://chargeigniter.com: CodeIgniter PHP code by Kyle Anderson
Python
- http://github.com/getyouridx/pychargify: A Python API wrapper by one of our active beta testers.
- http://github.com/hindsightlabs/chargify-python: A simple Python API wrapper.
Ruby/ActiveResource (Rails)
-
http://github.com/grasshopperlabs/chargify_api_ares: This is the "official" gem by the Chargify team. It uses ActiveResource, which is built into Rails, and is a good option for easy integration.
-
http://github.com/pengwynn/chargify: This is a Chargify gem that uses HTTParty. It was created by @pengwynn, who is one of our active beta testers. It has tests by using a Chargify "mock".
-
http://github.com/jsmestad/chargify: This is a Chargify gem by @jsmestad, another of our active users.
Resources Available
The following resources are available via the API
| Customers | Customers in Chargify are the resources that have access to your Products via a Subscription. These will usually map to the Users in your application. | View Documentation |
|---|---|---|
| Subscriptions | Subscriptions in Chargify give access to a particular Product for a particular Customer. They are usually recurring in nature, and all of the complexities of renewal, dunning, and expiration management are handled by Chargify. | View Documentation |
| Products | Products are the things which you sell. | View Documentation |
Response Codes
An HTTP Response Code is sent for every request to the API, and will be one of the following
| 200 OK | The request succeeded and a response was sent. Usually in response to a GET (read) request, but also for successful PUT (update) requests. |
|---|---|
| 201 Created | The resource was successfully created. Sent in response to a POST (create) request with valid data. |
| 401 Unauthorized | Returned when API authentication has failed. |
| 403 Forbidden | Returned by valid endpoints in our application that have not been enabled for API use. |
| 404 Not Found | The requested resource was not found. |
| 422 Unprocessable Entity | Sent in response to a POST (create) or PUT (update) request that is invalid. |
| 500 Internal Server Error | Signals some other error |
Response Data
Response data is sent as either XML or JSON, depending on the type of data requested.
Request Data
POST and PUT request data may be formatted as XML (application/xml) or JSON (application/json).
When sending data to Chargify (PUT and POST method requests), make sure you specify the HTTP Content-Type header accordingly or else you will trigger Cross Site Request Forgery protections.
For example, with curl:
curl -u <api_key>:x -H Content-Type:application/json --verbose --data-binary @subscription.json https://subdomain.chargify.com/subscriptions.json
When performing requests that do not send data to Chargify (i.e. GET or DELETE method requests) the type of data requested should be inferred from the URL suffix (i.e. either .xml or .json). If you are having difficulty, it cannot hurt to specify the type of data you accept via the HTTP Accept header, i.e.
curl -u <api_key>:x -H Accept:application/json --verbose https://subdomain.chargify.com/subscriptions.json
-
General Questions
-
Features
-
Billing & Payment
- Can I pay by check or money order?
- Can I try it out before buying?
- Do I still have to pay the transaction fees that my merchant account requires?
- Does Chargify charge a percentage or per transaction fee like PayPal or Google Checkout?
- Does Chargify support collecting foreign currencies?
- View all (7 more)
-
API
-
What makes Chargify different?
-
Technical
-
Payment Gateways & Merchant Accounts
- How do I set my Payment Gateway in Chargify?
- General Payment Gateway Troubleshooting
- Can I change my Merchant Account after I sign up for Chargify?
- Details about PayPal Website Payments Pro (US/UK/Canadian payment gateway)
- Can I use my existing Payment Gateway or do I need to get a new one?
- View all (9 more)
-
Product Types