百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

chargify_api_ares

> 编程语言
开源

一个使用 ActiveResource 为 Ruby 编写的 Chargify API 封装

158 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个使用 ActiveResource 为 Ruby 编写的 Chargify API 封装

Notice: As of Aug 30, 2022, this wrapper is no longer updated or maintained.

Chargify API wrapper for Ruby (using ActiveResource)

This is a community-maintained Ruby wrapper for the Chargify API that leverages ActiveResource.

Though we do not proactively maintain it, Chargify is happy to review pull requests and manage the release process for the gem. We encourage community contributions to make the wrapper even more comprehensive and powerful.

If you notice an endpoint or method that is missing, please feel free to add it by submitting a pull request. We appreciate your support!

Note: we have bumped to v1.0.0 to indicate a backwards incompatible change to the responses from Chargify::Subscription.charge and Chargify::Subscription.migrate. Please see the HISTORY.md for more information.

Please see important compatibility information at the bottom of this file.

Installation

This library can be installed as a gem. It is hosted on Rubygems.

You can install this library as a gem using the following command:

bash
$ gem install chargify_api_ares

Usage

Simply require this library before you use it:

ruby
require 'chargify_api_ares'

If you're using Rails 3.x, you could include this gem in your Gemfile.

ruby
gem 'chargify_api_ares'

Install the gem using the following command: $ bundle install

If you're using Rails 2 you could include this gem in your configuration, i.e. in environment.rb

ruby
config.gem 'chargify_api_ares'

To configure api key, site, domain, and protocol you can do the following. Please note that this step is required.

Most common usage

ruby
  Chargify.configure do |c|
    c.api_key   = "your_key_goes_here"
    c.subdomain = "test-site"
  end

Overriding the endpoint

ruby
  Chargify.configure do |c|
    c.api_key   = "your_key_goes_here"
    c.site      = "https://test-site.some-domain.com"
  end

Available configuration options

Name Description Default Required
api_key The api_key credentials that are used to access your chargify account. N/A Yes
subdomain The subdomain (site name) of the chargify endpoint you are trying to interact with test Yes (unless site was used)
domain The domain of the endpoint, in which you want to interact with. chargify.com No
protocol The endpoint protocol that you wish to use (http / https) https No
site This is meant to override all three of the previous settings eg: http://foo.bar.com N/A No
format The format of the request and response type that you want to deal with xml No
timeout The time in seconds for a request to be valid. Will raise a timeout error if exceeds time limit. N/A No

Now you'll have access to classes the interact with the Chargify API, such as:

  • Chargify::Product
  • Chargify::Customer
  • Chargify::Subscription

It allows you to interface with the Chargify API using simple ActiveRecord-like syntax, i.e.:

ruby
Chargify::Subscription.create(
  :customer_reference => 'moklett',
  :product_handle => 'chargify-api-ares-test',
  :credit_card_attributes => {
    :first_name => "Michael",
    :last_name => "Klett",
    :expiration_month => 1,
    :expiration_year => 2010,
    :full_number => "1234-1234-1234-1234"
  }
)

subscription.credit_card_attributes = { :expiration_year => 2013 }
subscription.save

subscription.cancel
Note

Updating nested resources is not supported nor recommended. If you wish to update a subscriptions customer please do so by updating the customer object itself.

Bad:

ruby
subscription = Chargify::Subscription.find(123)
subscription.customer.first_name = 'fred'
subscription.customer.save

Good:

ruby
subscription = Chargify::Subscription.find(123)
customer     = Chargify::Customer.find(subscription.customer.id)
customer.first_name = 'fred'
customer.save

Check out the examples in the examples directory. If you're not familiar with how ActiveResource works, you may be interested in some ActiveResource Documentation

Duplicate Prevention

Duplicate Prevention is supported by including the uniqueness_token attribute, for example:

ruby
subscription = Chargify::Subscription.create(
  :product_handle => 'product-with-trial',
  :customer_attributes => {
    :first_name => "Test",
    :last_name => "Customer",
    :email => "[email protected]"
  },
  :uniqueness_token => "abc-123-def-456"
)

Statements PDF retrieving

ruby
File.open(file_path, 'wb+') do |f|
  f.write Chargify::Statement.find_pdf(statement.id)
end

Compatibility

  • Rails/ActiveResource 2.3.x, use 0.5.x
  • Rails/ActiveResource 3.x, use 0.6 and up
chargify_api_ares Rails 2.3.x Rails 3.0.0 - 3.0.19 Rails 3.0.20 and up
0.5.x OK Incompatible OK
0.6.x Incompatible OK (Monkey-patched) OK

The problem with Rails/ActiveResource/ActiveModel 3.0.0 - 3.0.19

Prior to Feb 12, 2013, Chargify would silently refuse to parse XML which contained data specified as YAML, such as:

xml

  John
  

After Feb 12, 2013, Chargify returns a 400 Bad Request response if your XML contains any type="yaml" attribute, since there is no valid reason to send YAML serialized data to Chargify and doing so smells strongly of an attempt to exploit CVE-2013-0156.

However, Rails/ActiveModel versions 3.0.0 to 3.0.19 had a bug (see ) where any nil attribute would have a type="yaml" attribute added during XML serialization.

Using ActiveResource 3.0.0 - 3.0.19 along with 0.5.x or lower of this gem may result in your sending type="yaml" XML to Chargify. Thus, your requests will be rejected.

Version 0.6.x of this gem will attempt to patch your ActiveModel if you have an incompatible version. To avoid this patch, you should use 3.0.20 or higher of ActiveResource.

Contributing

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for the feature/bugfix
  • Please squash your commits.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate it to its own commit so we can cherry-pick around it.

Contributors

We would like to publicly thank everyone who has contributed their time and talents to developing this gem. Thank you!

Issues· 28 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言