recurly 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of recurly might be problematic. Click here for more details.
- data/LICENSE +21 -0
- data/Manifest +21 -0
- data/README.md +50 -0
- data/Rakefile +14 -0
- data/init.rb +1 -0
- data/lib/recurly.rb +9 -0
- data/lib/recurly/account.rb +13 -0
- data/lib/recurly/base.rb +68 -0
- data/lib/recurly/billing_info.rb +11 -0
- data/lib/recurly/charge.rb +10 -0
- data/lib/recurly/credit.rb +10 -0
- data/lib/recurly/plan.rb +5 -0
- data/lib/recurly/subscription.rb +41 -0
- data/recurly.gemspec +31 -0
- data/test/account_test.rb +45 -0
- data/test/billing_info_test.rb +28 -0
- data/test/charge_test.rb +30 -0
- data/test/credit_test.rb +30 -0
- data/test/plan_test.rb +18 -0
- data/test/subscription_test.rb +84 -0
- data/test/test_helper.rb +20 -0
- metadata +95 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Recurly, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Manifest
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
LICENSE
|
2
|
+
Manifest
|
3
|
+
README.md
|
4
|
+
Rakefile
|
5
|
+
init.rb
|
6
|
+
lib/recurly.rb
|
7
|
+
lib/recurly/account.rb
|
8
|
+
lib/recurly/base.rb
|
9
|
+
lib/recurly/billing_info.rb
|
10
|
+
lib/recurly/charge.rb
|
11
|
+
lib/recurly/credit.rb
|
12
|
+
lib/recurly/plan.rb
|
13
|
+
lib/recurly/subscription.rb
|
14
|
+
recurly.gemspec
|
15
|
+
test/account_test.rb
|
16
|
+
test/billing_info_test.rb
|
17
|
+
test/charge_test.rb
|
18
|
+
test/credit_test.rb
|
19
|
+
test/plan_test.rb
|
20
|
+
test/subscription_test.rb
|
21
|
+
test/test_helper.rb
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
Recurly Ruby Client
|
2
|
+
===================
|
3
|
+
|
4
|
+
The Recurly Ruby Client library is an open source library to interact with Recurly's subscription management from your Ruby on Rails website. The library interacts with Recurly's [REST API](http://support.recurly.com/faqs/api).
|
5
|
+
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-----
|
9
|
+
|
10
|
+
Please see the [documentation](http://support.recurly.com/faqs/api/ruby-client) and
|
11
|
+
[support forums](http://support.recurly.com/discussions) for more information.
|
12
|
+
|
13
|
+
|
14
|
+
Installation
|
15
|
+
------------
|
16
|
+
|
17
|
+
This library can be installed as a gem or a plugin. Your choice.
|
18
|
+
|
19
|
+
**Gem Installation:**
|
20
|
+
|
21
|
+
gem install recurly --source=http://gemcutter.org
|
22
|
+
|
23
|
+
**Plugin Installation:**
|
24
|
+
|
25
|
+
script/plugin install git@github.com:recurly/recurly-client-ruby.git
|
26
|
+
|
27
|
+
|
28
|
+
Authentication
|
29
|
+
--------------
|
30
|
+
|
31
|
+
The Recurly Ruby Client requires a username and password to connect. We recommend creating a user just for your API. Please see the [Authentication](http://support.recurly.com/faqs/api/authentication) documentation for more information.
|
32
|
+
|
33
|
+
Create a file in your Rails app at __/config/initializers/recurly_config.rb__ with contents like:
|
34
|
+
|
35
|
+
Recurly.configure do |c|
|
36
|
+
c.username = 'api@yourcompany.com'
|
37
|
+
c.password = 'super_secret_password'
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
Examples
|
42
|
+
--------
|
43
|
+
|
44
|
+
All the functionality is demonstrated by the unit tests in the __test__ directory.
|
45
|
+
|
46
|
+
|
47
|
+
API Documentation
|
48
|
+
-----------------
|
49
|
+
|
50
|
+
Please see the [Recurly API](http://support.recurly.com/faqs/api/) for more information.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('recurly', '0.1.0') do |p|
|
6
|
+
p.description = "A Ruby API wrapper for Recurly. Super Simple Subscription billing."
|
7
|
+
p.url = "http://github.com/recurly/recurly-client-ruby"
|
8
|
+
p.author = "Isaac Hall"
|
9
|
+
p.email = "support@recurly.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'recurly'
|
data/lib/recurly.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require "active_resource"
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/recurly/base'
|
4
|
+
require File.dirname(__FILE__) + '/recurly/account'
|
5
|
+
require File.dirname(__FILE__) + '/recurly/billing_info'
|
6
|
+
require File.dirname(__FILE__) + '/recurly/charge'
|
7
|
+
require File.dirname(__FILE__) + '/recurly/credit'
|
8
|
+
require File.dirname(__FILE__) + '/recurly/plan'
|
9
|
+
require File.dirname(__FILE__) + '/recurly/subscription'
|
data/lib/recurly/base.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "active_resource"
|
3
|
+
|
4
|
+
# See http://github.com/rails/rails/commit/1488c6cc9e6237ce794e3c4a6201627b9fd4ca09
|
5
|
+
# Errors in Rails 2.3.4 are not parsed correctly.
|
6
|
+
module ActiveResource
|
7
|
+
class Base
|
8
|
+
def save
|
9
|
+
save_without_validation
|
10
|
+
true
|
11
|
+
rescue ResourceInvalid => error
|
12
|
+
case error.response['Content-Type']
|
13
|
+
when /application\/xml/
|
14
|
+
errors.from_xml(error.response.body)
|
15
|
+
when /application\/json/
|
16
|
+
errors.from_json(error.response.body)
|
17
|
+
end
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Recurly
|
24
|
+
|
25
|
+
VERSION = '0.1.0'
|
26
|
+
|
27
|
+
class << self
|
28
|
+
attr_accessor :username, :password
|
29
|
+
|
30
|
+
def configure
|
31
|
+
yield self
|
32
|
+
|
33
|
+
RecurlyBase.user = username
|
34
|
+
RecurlyBase.password = password
|
35
|
+
true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class RecurlyBase < ActiveResource::Base
|
40
|
+
self.site = "https://app.recurly.com"
|
41
|
+
|
42
|
+
# Add User-Agent to headers
|
43
|
+
def headers
|
44
|
+
super
|
45
|
+
@headers['User-Agent'] = "Recurly Ruby Client v#{VERSION}"
|
46
|
+
@headers
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# ActiveRecord treats resources as plural by default. Some resources are singular.
|
51
|
+
class RecurlySingularResourceBase < RecurlyBase
|
52
|
+
|
53
|
+
# Override element_path because this is a singular resource
|
54
|
+
def self.element_path(id, prefix_options = {}, query_options = nil)
|
55
|
+
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
|
56
|
+
# original: "#{prefix(prefix_options)}#{collection_name}/#{id}.#{format.extension}#{query_string(query_options)}"
|
57
|
+
"#{prefix(prefix_options)}#{CGI::escape(id || '')}/#{element_name}.#{format.extension}#{query_string(query_options)}"
|
58
|
+
end
|
59
|
+
|
60
|
+
# Override collection_path because this is a singular resource
|
61
|
+
def self.collection_path(prefix_options = {}, query_options = nil)
|
62
|
+
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
|
63
|
+
# original: "#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}"
|
64
|
+
"#{prefix(prefix_options)}/#{element_name}.#{format.extension}#{query_string(query_options)}"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
data/lib/recurly/plan.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Recurly
|
2
|
+
class Subscription < RecurlySingularResourceBase
|
3
|
+
self.element_name = "subscription"
|
4
|
+
self.prefix = "/accounts/:account_code"
|
5
|
+
|
6
|
+
def self.refund(account_code, refund_type = :partial)
|
7
|
+
raise "Refund type must be :full or :partial." unless refund_type == :full or refund_type == :partial
|
8
|
+
Subscription.delete(nil, {:account_code => account_code, :refund => refund_type})
|
9
|
+
end
|
10
|
+
|
11
|
+
# Stops the subscription from renewing. The subscription remains valid until the end of
|
12
|
+
# the current term (current_period_ends_at).
|
13
|
+
def cancel
|
14
|
+
Subscription.delete(self.subscription_account_code)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Terminates the subscription immediately and processes a full or partial refund
|
18
|
+
def refund(refund_type)
|
19
|
+
raise "Refund type must be :full or :partial." unless refund_type == :full or refund_type == :partial
|
20
|
+
Subscription.delete(nil, {:account_code => self.subscription_account_code, :refund => refund_type})
|
21
|
+
end
|
22
|
+
|
23
|
+
# Valid timeframe: :now or :renewal
|
24
|
+
# Valid options: plan_code, quantity, unit_amount
|
25
|
+
def change(timeframe, options = {})
|
26
|
+
raise "Timeframe must be :full or :partial." unless timeframe == 'now' or timeframe == 'renewal'
|
27
|
+
options[:timeframe] = timeframe
|
28
|
+
connection.put(element_path(:account_code => self.subscription_account_code),
|
29
|
+
self.class.format.encode(options, :root => :subscription),
|
30
|
+
self.class.headers)
|
31
|
+
end
|
32
|
+
|
33
|
+
def subscription_account_code
|
34
|
+
acct_code = self.account_code if defined?(self.account_code)
|
35
|
+
acct_code ||= account.account_code unless account.nil?
|
36
|
+
acct_code ||= self.primary_key if defined?(self.primary_key)
|
37
|
+
acct_code
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
data/recurly.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{recurly}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Isaac Hall"]
|
9
|
+
s.date = %q{2009-11-22}
|
10
|
+
s.description = %q{A Ruby API wrapper for Recurly. Super Simple Subscription billing.}
|
11
|
+
s.email = %q{support@recurly.com}
|
12
|
+
s.extra_rdoc_files = ["LICENSE", "README.md", "lib/recurly.rb", "lib/recurly/account.rb", "lib/recurly/base.rb", "lib/recurly/billing_info.rb", "lib/recurly/charge.rb", "lib/recurly/credit.rb", "lib/recurly/plan.rb", "lib/recurly/subscription.rb"]
|
13
|
+
s.files = ["LICENSE", "Manifest", "README.md", "Rakefile", "init.rb", "lib/recurly.rb", "lib/recurly/account.rb", "lib/recurly/base.rb", "lib/recurly/billing_info.rb", "lib/recurly/charge.rb", "lib/recurly/credit.rb", "lib/recurly/plan.rb", "lib/recurly/subscription.rb", "recurly.gemspec", "test/account_test.rb", "test/billing_info_test.rb", "test/charge_test.rb", "test/credit_test.rb", "test/plan_test.rb", "test/subscription_test.rb", "test/test_helper.rb"]
|
14
|
+
s.homepage = %q{http://github.com/recurly/recurly-client-ruby}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Recurly", "--main", "README.md"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{recurly}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{A Ruby API wrapper for Recurly. Super Simple Subscription billing.}
|
20
|
+
s.test_files = ["test/account_test.rb", "test/billing_info_test.rb", "test/charge_test.rb", "test/credit_test.rb", "test/plan_test.rb", "test/subscription_test.rb", "test/test_helper.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AccountTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_create
|
6
|
+
account = create_account('create')
|
7
|
+
assert_not_nil account.created_at
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_get_account
|
11
|
+
account = create_account('get')
|
12
|
+
|
13
|
+
get_acct = Recurly::Account.find(account.account_code)
|
14
|
+
assert_not_nil get_acct
|
15
|
+
assert_not_nil get_acct.created_at
|
16
|
+
assert_equal account.account_code, get_acct.account_code
|
17
|
+
assert_equal account.email, get_acct.email
|
18
|
+
assert_equal account.first_name, get_acct.first_name
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_update_account
|
22
|
+
account = create_account('update')
|
23
|
+
|
24
|
+
account = Recurly::Account.find(account.account_code)
|
25
|
+
account.last_name = 'Update Test'
|
26
|
+
account.company_name = 'Recurly Ruby Gem -- Update'
|
27
|
+
account.save
|
28
|
+
|
29
|
+
updated_acct = Recurly::Account.find(account.account_code)
|
30
|
+
assert_equal account.email, updated_acct.email
|
31
|
+
assert_not_equal account.last_name, updated_acct.last_name
|
32
|
+
assert_not_equal account.company_name, updated_acct.company_name
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_close_account
|
36
|
+
account = create_account('close')
|
37
|
+
|
38
|
+
account.close_account
|
39
|
+
|
40
|
+
assert_raises ActiveResource::ResourceNotFound do
|
41
|
+
get_acct = Recurly::Account.find(account.account_code)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BillingInfoTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_update_billing_info
|
6
|
+
account = create_account('billing')
|
7
|
+
|
8
|
+
billing_info = Recurly::BillingInfo.create(
|
9
|
+
:account_code => account.account_code,
|
10
|
+
:first_name => account.first_name,
|
11
|
+
:last_name => account.last_name,
|
12
|
+
:address1 => '123 Test St',
|
13
|
+
:city => 'San Francisco',
|
14
|
+
:state => 'CA',
|
15
|
+
:zip => '94115',
|
16
|
+
:credit_card => {
|
17
|
+
:number => '1',
|
18
|
+
:year => Time.now.year + 1,
|
19
|
+
:month => Time.now.month,
|
20
|
+
:verification_value => '123'
|
21
|
+
}
|
22
|
+
)
|
23
|
+
|
24
|
+
assert_instance_of Recurly::BillingInfo, billing_info
|
25
|
+
assert_not_nil billing_info.updated_at
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/test/charge_test.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ChargeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_charge_account
|
6
|
+
account = create_account('charge')
|
7
|
+
|
8
|
+
charge = Recurly::Charge.create(
|
9
|
+
:account_code => account.account_code,
|
10
|
+
:amount => 9.50
|
11
|
+
)
|
12
|
+
|
13
|
+
assert_not_nil charge.id
|
14
|
+
assert_equal charge.amount_in_cents, 950
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_list_charges
|
18
|
+
account = create_account('charge-list')
|
19
|
+
|
20
|
+
charge = Recurly::Charge.create(
|
21
|
+
:account_code => account.account_code,
|
22
|
+
:amount => 9.23
|
23
|
+
)
|
24
|
+
|
25
|
+
charge_list = Recurly::Charge.list(account.account_code)
|
26
|
+
assert_not_nil charge_list
|
27
|
+
assert_instance_of Array, charge_list
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/test/credit_test.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CreditTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_credit_account
|
6
|
+
account = create_account('credit')
|
7
|
+
|
8
|
+
credit = Recurly::Credit.create(
|
9
|
+
:account_code => account.account_code,
|
10
|
+
:amount => 9.50
|
11
|
+
)
|
12
|
+
|
13
|
+
assert_not_nil credit.id
|
14
|
+
assert_equal credit.amount_in_cents, -950 # Credits are negative
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_list_credits
|
18
|
+
account = create_account('credit-list')
|
19
|
+
|
20
|
+
credit = Recurly::Credit.create(
|
21
|
+
:account_code => account.account_code,
|
22
|
+
:amount => 9.23
|
23
|
+
)
|
24
|
+
|
25
|
+
credit_list = Recurly::Credit.list(account.account_code)
|
26
|
+
assert_not_nil credit_list
|
27
|
+
assert_instance_of Array, credit_list
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/test/plan_test.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PlanTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_list_plans
|
6
|
+
plans = Recurly::Plan.find(:all)
|
7
|
+
|
8
|
+
assert_not_nil plans
|
9
|
+
assert_instance_of Array, plans
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_plan
|
13
|
+
plan = Recurly::Plan.find('trial')
|
14
|
+
assert_not_nil plan
|
15
|
+
assert_not_nil plan.name
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SubscriptionTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_create_subscription_new_account
|
6
|
+
account = Recurly::Account.new(
|
7
|
+
:account_code => "#{Time.now.to_i}-new-sub-new-account",
|
8
|
+
:first_name => 'Verena',
|
9
|
+
:last_name => 'Test',
|
10
|
+
:email => 'verena@test.com',
|
11
|
+
:company_name => 'Recurly Ruby Gem')
|
12
|
+
|
13
|
+
sub = create_subscription(account, TEST_PLAN_CODE)
|
14
|
+
assert_not_nil sub
|
15
|
+
assert_nil sub.canceled_at
|
16
|
+
assert_equal sub.state, 'active'
|
17
|
+
assert_not_nil sub.current_period_started_at
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_create_subscription_existing_account
|
21
|
+
account = create_account('existing-account')
|
22
|
+
sub = create_subscription(account, TEST_PLAN_CODE)
|
23
|
+
|
24
|
+
assert_equal sub.state, 'active'
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_update_subscription
|
28
|
+
account = create_account('update-subscription')
|
29
|
+
sub = create_subscription(account, TEST_PLAN_CODE)
|
30
|
+
|
31
|
+
sub.change('now', :quantity => 2)
|
32
|
+
sub.reload
|
33
|
+
assert_equal sub.quantity, 2
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_cancel_subscription
|
37
|
+
account = create_account('cancel-subscription')
|
38
|
+
subscription = create_subscription(account, TEST_PLAN_CODE)
|
39
|
+
|
40
|
+
subscription.cancel
|
41
|
+
|
42
|
+
sub = Recurly::Subscription.find(account.account_code)
|
43
|
+
assert_equal sub.state, 'canceled'
|
44
|
+
assert_not_nil sub.canceled_at
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_refund_subscription
|
48
|
+
account = create_account('refund-subscription')
|
49
|
+
subscription = create_subscription(account, TEST_PLAN_CODE)
|
50
|
+
|
51
|
+
subscription.refund(:full)
|
52
|
+
|
53
|
+
assert_raises ActiveResource::ResourceNotFound do
|
54
|
+
get_sub = Recurly::Subscription.find(account.account_code)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_subscription(account, plan_code, quantity = 1)
|
59
|
+
account.billing_info = Recurly::BillingInfo.new(
|
60
|
+
:first_name => account.first_name,
|
61
|
+
:last_name => account.last_name,
|
62
|
+
:address1 => '123 Test St',
|
63
|
+
:city => 'San Francisco',
|
64
|
+
:state => 'CA',
|
65
|
+
:country => 'US',
|
66
|
+
:zip => '94103',
|
67
|
+
:credit_card => {
|
68
|
+
:number => '1',
|
69
|
+
:year => Time.now.year + 1,
|
70
|
+
:month => Time.now.month,
|
71
|
+
:verification_value => '123'
|
72
|
+
},
|
73
|
+
:ip_address => '127.0.0.1'
|
74
|
+
)
|
75
|
+
|
76
|
+
sub = Recurly::Subscription.create(
|
77
|
+
:account_code => account.account_code,
|
78
|
+
:plan_code => plan_code,
|
79
|
+
:quantity => quantity,
|
80
|
+
:account => account
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../lib/recurly'
|
5
|
+
|
6
|
+
Recurly.configure do |c|
|
7
|
+
c.username = ''
|
8
|
+
c.password = ''
|
9
|
+
end
|
10
|
+
|
11
|
+
TEST_PLAN_CODE = 'trial'
|
12
|
+
|
13
|
+
def create_account(account_code)
|
14
|
+
account = Recurly::Account.create(
|
15
|
+
:account_code => "#{Time.now.to_i}-#{account_code}",
|
16
|
+
:first_name => 'Verena',
|
17
|
+
:last_name => 'Test',
|
18
|
+
:email => 'verena@test.com',
|
19
|
+
:company_name => 'Recurly Ruby Gem')
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: recurly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Isaac Hall
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-22 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Ruby API wrapper for Recurly. Super Simple Subscription billing.
|
17
|
+
email: support@recurly.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- lib/recurly.rb
|
26
|
+
- lib/recurly/account.rb
|
27
|
+
- lib/recurly/base.rb
|
28
|
+
- lib/recurly/billing_info.rb
|
29
|
+
- lib/recurly/charge.rb
|
30
|
+
- lib/recurly/credit.rb
|
31
|
+
- lib/recurly/plan.rb
|
32
|
+
- lib/recurly/subscription.rb
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- Manifest
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- init.rb
|
39
|
+
- lib/recurly.rb
|
40
|
+
- lib/recurly/account.rb
|
41
|
+
- lib/recurly/base.rb
|
42
|
+
- lib/recurly/billing_info.rb
|
43
|
+
- lib/recurly/charge.rb
|
44
|
+
- lib/recurly/credit.rb
|
45
|
+
- lib/recurly/plan.rb
|
46
|
+
- lib/recurly/subscription.rb
|
47
|
+
- recurly.gemspec
|
48
|
+
- test/account_test.rb
|
49
|
+
- test/billing_info_test.rb
|
50
|
+
- test/charge_test.rb
|
51
|
+
- test/credit_test.rb
|
52
|
+
- test/plan_test.rb
|
53
|
+
- test/subscription_test.rb
|
54
|
+
- test/test_helper.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/recurly/recurly-client-ruby
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --line-numbers
|
62
|
+
- --inline-source
|
63
|
+
- --title
|
64
|
+
- Recurly
|
65
|
+
- --main
|
66
|
+
- README.md
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "1.2"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: recurly
|
84
|
+
rubygems_version: 1.3.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: A Ruby API wrapper for Recurly. Super Simple Subscription billing.
|
88
|
+
test_files:
|
89
|
+
- test/account_test.rb
|
90
|
+
- test/billing_info_test.rb
|
91
|
+
- test/charge_test.rb
|
92
|
+
- test/credit_test.rb
|
93
|
+
- test/plan_test.rb
|
94
|
+
- test/subscription_test.rb
|
95
|
+
- test/test_helper.rb
|