recurly 0.4.16 → 2.0.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.

Files changed (78) hide show
  1. data/README.markdown +118 -0
  2. data/bin/recurly +78 -0
  3. data/lib/rails/generators/recurly/config_generator.rb +16 -0
  4. data/lib/rails/recurly.rb +13 -0
  5. data/lib/recurly.rb +64 -139
  6. data/lib/recurly/account.rb +52 -111
  7. data/lib/recurly/add_on.rb +20 -0
  8. data/lib/recurly/adjustment.rb +51 -0
  9. data/lib/recurly/api.rb +73 -0
  10. data/lib/recurly/api/errors.rb +205 -0
  11. data/lib/recurly/api/net_http.rb +77 -0
  12. data/lib/recurly/billing_info.rb +45 -42
  13. data/lib/recurly/coupon.rb +63 -8
  14. data/lib/recurly/helper.rb +39 -0
  15. data/lib/recurly/invoice.rb +38 -16
  16. data/lib/recurly/js.rb +113 -0
  17. data/lib/recurly/money.rb +105 -0
  18. data/lib/recurly/plan.rb +26 -15
  19. data/lib/recurly/redemption.rb +34 -0
  20. data/lib/recurly/resource.rb +925 -0
  21. data/lib/recurly/resource/pager.rb +210 -0
  22. data/lib/recurly/subscription.rb +90 -67
  23. data/lib/recurly/subscription/add_ons.rb +73 -0
  24. data/lib/recurly/transaction.rb +65 -53
  25. data/lib/recurly/transaction/errors.rb +98 -0
  26. data/lib/recurly/version.rb +16 -2
  27. data/lib/recurly/xml.rb +85 -0
  28. data/lib/recurly/xml/nokogiri.rb +49 -0
  29. data/lib/recurly/xml/rexml.rb +50 -0
  30. metadata +76 -165
  31. data/LICENSE +0 -21
  32. data/README.md +0 -104
  33. data/init.rb +0 -1
  34. data/lib/patches/rails2/active_resource/base.rb +0 -35
  35. data/lib/patches/rails2/active_resource/connection.rb +0 -10
  36. data/lib/patches/rails3/active_model/serializers/xml.rb +0 -28
  37. data/lib/patches/rails3/active_resource/connection.rb +0 -10
  38. data/lib/recurly/account_base.rb +0 -35
  39. data/lib/recurly/base.rb +0 -195
  40. data/lib/recurly/charge.rb +0 -39
  41. data/lib/recurly/config_parser.rb +0 -31
  42. data/lib/recurly/credit.rb +0 -28
  43. data/lib/recurly/exceptions.rb +0 -32
  44. data/lib/recurly/formats/xml_with_errors.rb +0 -132
  45. data/lib/recurly/formats/xml_with_pagination.rb +0 -47
  46. data/lib/recurly/rails2/compatibility.rb +0 -8
  47. data/lib/recurly/rails3/railtie.rb +0 -21
  48. data/lib/recurly/rails3/recurly.rake +0 -28
  49. data/lib/recurly/transparent.rb +0 -148
  50. data/lib/recurly/verification.rb +0 -83
  51. data/spec/config/recurly.yml +0 -6
  52. data/spec/config/test1.yml +0 -4
  53. data/spec/config/test2.yml +0 -7
  54. data/spec/integration/account_spec.rb +0 -286
  55. data/spec/integration/add_on_spec.rb +0 -84
  56. data/spec/integration/billing_info_spec.rb +0 -148
  57. data/spec/integration/charge_spec.rb +0 -176
  58. data/spec/integration/coupon_spec.rb +0 -49
  59. data/spec/integration/credit_spec.rb +0 -106
  60. data/spec/integration/invoice_spec.rb +0 -86
  61. data/spec/integration/plan_spec.rb +0 -87
  62. data/spec/integration/subscription_spec.rb +0 -221
  63. data/spec/integration/transaction_spec.rb +0 -154
  64. data/spec/integration/transparent_spec.rb +0 -99
  65. data/spec/spec_helper.rb +0 -34
  66. data/spec/support/factory.rb +0 -211
  67. data/spec/support/vcr.rb +0 -11
  68. data/spec/unit/account_spec.rb +0 -19
  69. data/spec/unit/billing_info_spec.rb +0 -39
  70. data/spec/unit/charge_spec.rb +0 -20
  71. data/spec/unit/config_spec.rb +0 -42
  72. data/spec/unit/coupon_spec.rb +0 -13
  73. data/spec/unit/credit_spec.rb +0 -20
  74. data/spec/unit/plan_spec.rb +0 -18
  75. data/spec/unit/subscription_spec.rb +0 -25
  76. data/spec/unit/transaction_spec.rb +0 -32
  77. data/spec/unit/transparent_spec.rb +0 -152
  78. data/spec/unit/verification_spec.rb +0 -82
@@ -1,99 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Transparent do
5
- # version accounts based on this current files modification dates
6
- timestamp = File.mtime(__FILE__).to_i
7
-
8
- describe ".url" do
9
-
10
- use_vcr_cassette "transparent/post-url/#{timestamp}"
11
-
12
- it "should not change after calling account.find()" do
13
-
14
- original_transparent_url = "#{Recurly::Base.site}/transparent/#{Recurly.subdomain}/subscription"
15
- Transparent.url.should == original_transparent_url
16
-
17
- account_code = "account-get-#{timestamp}"
18
- Factory.create_account("account-get-#{timestamp}")
19
- r = Account.find("account-get-#{timestamp}")
20
-
21
- Transparent.url.should == original_transparent_url
22
-
23
- end
24
- end
25
-
26
- it "should parse errors on nested objects" do
27
- response_xml = <<END
28
- <?xml version="1.0" encoding="UTF-8"?>
29
- <subscription>
30
- <id nil="true"></id>
31
- <account_code>2345</account_code>
32
- <account>
33
- <account_code>12345</account_code>
34
- <username></username>
35
- <email>verena@test.com</email>
36
- <first_name>Verena</first_name>
37
- <last_name>Test User</last_name>
38
- <company_name></company_name>
39
- <closed type="boolean">false</closed>
40
- <hosted_login_token>abcd1234123412341234123412341234</hosted_login_token>
41
- <created_at type="datetime">2011-07-20T01:49:24Z</created_at>
42
- <state>active</state>
43
- <billing_info>
44
- <account_code>12345</account_code>
45
- <first_name>Verena</first_name>
46
- <last_name>Test User</last_name>
47
- <address1></address1>
48
- <address2></address2>
49
- <city></city>
50
- <state></state>
51
- <country></country>
52
- <zip></zip>
53
- <phone></phone>
54
- <vat_number></vat_number>
55
- <ip_address>127.0.0.1</ip_address>
56
- <credit_card>
57
- <type></type>
58
- <last_four></last_four>
59
- <month type="integer">7</month>
60
- <year type="integer">2011</year>
61
- </credit_card>
62
- <updated_at type="datetime">2011-07-20T01:49:35Z</updated_at>
63
- <errors>
64
- <error field="number">is required</error>
65
- <error field="verification_value">is required</error>
66
- </errors>
67
- </billing_info>
68
- </account>
69
- <plan>
70
- <plan_code>gold-plan</plan_code>
71
- <name>Gold Plan</name>
72
- </plan>
73
- <state>pending</state>
74
- <quantity type="integer">1</quantity>
75
- <total_amount_in_cents type="integer">1200</total_amount_in_cents>
76
- <activated_at nil="true" type="datetime"></activated_at>
77
- <canceled_at nil="true" type="datetime"></canceled_at>
78
- <expires_at nil="true" type="datetime"></expires_at>
79
- <current_period_started_at type="datetime">2011-07-20T01:49:35Z</current_period_started_at>
80
- <current_period_ends_at type="datetime">2011-07-20T01:49:35Z</current_period_ends_at>
81
- <trial_started_at nil="true" type="datetime"></trial_started_at>
82
- <trial_ends_at nil="true" type="datetime"></trial_ends_at>
83
- <add_ons type="array">
84
- </add_ons>
85
- </subscription>
86
- END
87
-
88
- response = mock
89
- response.should_receive(:[]).at_least(:once).with('Content-Length').and_return '123'
90
- response.should_receive(:body).at_least(:once).and_return response_xml
91
-
92
- subscription = Subscription.new.from_transparent_results(response)
93
- subscription.account.billing_info.credit_card.errors[:number].should_not be_empty
94
- subscription.account.billing_info.credit_card.errors[:number].should include('is required')
95
- subscription.account.billing_info.credit_card.errors[:verification_value].should_not be_empty
96
- subscription.account.billing_info.credit_card.errors[:verification_value].should include('is required')
97
- end
98
- end
99
- end
@@ -1,34 +0,0 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
- require "bundler"
4
- Bundler.setup
5
-
6
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
7
- require 'recurly'
8
-
9
- # Requires supporting files with custom matchers and macros, etc,
10
- # in ./support/ and its subdirectories.
11
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
-
13
- module SpecHelper
14
- # add helper methods here
15
- end
16
-
17
- class Rails
18
- def self.env
19
- "test"
20
- end
21
- end
22
-
23
- RSpec.configure do |config|
24
- config.include SpecHelper
25
-
26
- config.mock_with :rspec
27
-
28
- config.before(:each) do
29
- Recurly.settings_path = "#{File.dirname(__FILE__)}/config/recurly.yml"
30
- Recurly.configure_from_yaml
31
- end
32
-
33
- end
34
-
@@ -1,211 +0,0 @@
1
- module Recurly
2
- module Factory
3
-
4
-
5
- # creates an account
6
- def self.create_account(account_code, overrides = {})
7
- account = Account.new(account_attributes(account_code, overrides))
8
- account.save!
9
- account
10
- end
11
-
12
- def self.account_attributes(account_code, overrides = {})
13
- attributes = {
14
- # version is used to avoid duplicate account errors on recurly's api, pass in a different one every time
15
- :account_code => account_code,
16
- :first_name => 'Verena',
17
- :last_name => 'Test',
18
- :email => 'verena@test.com',
19
- :company_name => 'Recurly Ruby Gem'
20
- }
21
-
22
- # add overrides
23
- overrides.each do |key, val|
24
- attributes[key] = val
25
- end
26
-
27
- attributes
28
- end
29
-
30
- # creates an account with associated billing information
31
- def self.create_account_with_billing_info(account_code, address_overrides = {}, credit_card_overrides = {})
32
- account = Factory.create_account(account_code)
33
-
34
- # create billing info
35
- billing_info = BillingInfo.new(billing_attributes(address_overrides, credit_card_overrides))
36
- billing_info.account_code = account_code
37
- billing_info.first_name = account.first_name unless billing_info.respond_to?(:first_name)
38
- billing_info.last_name = account.last_name unless billing_info.respond_to?(:last_name)
39
- billing_info.save!
40
-
41
- # return account
42
- account
43
- end
44
-
45
- # returns a hash of billing information
46
- def self.billing_attributes(address_overrides = {}, credit_card_overrides = {})
47
- attributes = {
48
- :first_name => 'Verena',
49
- :last_name => 'Test',
50
- :address1 => '123 Test St',
51
- :city => 'San Francisco',
52
- :state => 'CA',
53
- :zip => '94115',
54
- :country => "US",
55
- :credit_card => {
56
- :number => '4111111111111111',
57
- :year => Time.now.year + 1,
58
- :month => Time.now.month,
59
- :verification_value => '123'
60
- }
61
- }
62
-
63
- # overrides for address
64
- address_overrides.each do |key, val|
65
- attributes[key] = val
66
- end
67
-
68
- # overrides for credit cards
69
- credit_card_overrides.each do |key, val|
70
- attributes[:credit_card][key] = val
71
- end
72
-
73
- attributes
74
- end
75
-
76
- # Creates a subscription for an account
77
- def self.create_subscription(account, plan, overrides={})
78
- plan = self.send("#{plan}_plan") if plan.is_a?(Symbol)
79
-
80
- # default to paid plan if none specified
81
- plan ||= paid_plan
82
-
83
- account.billing_info = BillingInfo.new(billing_attributes)
84
-
85
- # set account information
86
- account.billing_info.first_name = account.first_name
87
- account.billing_info.last_name = account.last_name
88
-
89
- attributes = {
90
- :account_code => account.account_code,
91
- :plan_code => (plan || paid_plan).plan_code,
92
- :quantity => 1,
93
- :account => account
94
- }
95
-
96
- overrides.each do |key,val|
97
- attributes[key] = val
98
- end
99
-
100
- subscription = Subscription.new(attributes)
101
- subscription.save!
102
- return subscription
103
- end
104
-
105
- def self.create_charge(account_code, attributes = {})
106
- charge = Charge.new({
107
- :account_code => account_code,
108
- :amount => 10.00,
109
- :description => "charge description"
110
- }.merge(attributes))
111
- charge.save!
112
- charge
113
- end
114
-
115
- def self.create_transaction(account_code, overrides = {})
116
- attributes = {
117
- :account => {
118
- :account_code => account_code
119
- }
120
- }
121
-
122
- overrides.each do |key, val|
123
- attributes[key] = val
124
- end
125
-
126
- transaction = Transaction.new(attributes)
127
- transaction.save!
128
-
129
- transaction
130
- end
131
-
132
- # creates a full transaction from scratch
133
- def self.create_full_transaction(account_code, overrides = {}, address_overrides = {}, credit_card_overrides = {})
134
- attributes = {
135
- :account => {
136
- :account_code => account_code,
137
- :first_name => 'Verena',
138
- :last_name => 'Test',
139
- :email => 'verena@test.com',
140
- :company_name => 'Recurly Ruby Gem',
141
- :billing_info => billing_attributes(address_overrides, credit_card_overrides)
142
- }
143
- }
144
-
145
- overrides.each do |key, val|
146
- attributes[key] = val
147
- end
148
-
149
- transaction = Transaction.new(attributes)
150
- transaction.save!
151
-
152
- transaction
153
- end
154
-
155
- def self.create_credit(account_code, attributes = {})
156
- credit = Credit.new({
157
- :account_code => account_code,
158
- :amount_in_cents => 1000,
159
- :description => "free moniez"
160
- }.merge(attributes))
161
- credit.save!
162
- credit
163
- end
164
-
165
- def self.trial_plan
166
- find_or_create_plan({
167
- :plan_code => "trial",
168
- :name => "Trial",
169
-
170
- # 10 dollars a month
171
- :amount_in_cents => 1000,
172
-
173
- # 1 month intervals
174
- :plan_interval_length => 1,
175
- :plan_interval_unit => "months",
176
-
177
- # 1 month trial
178
- :trial_interval_length => 1,
179
- :trial_interval_unit => "months"
180
- })
181
- end
182
-
183
- def self.paid_plan
184
- find_or_create_plan({
185
- :plan_code => "paid",
186
- :name => "Paid",
187
-
188
- # 10 dollars a month
189
- :amount_in_cents => 1000,
190
-
191
- # 1 month intervals
192
- :plan_interval_length => 1,
193
- :plan_interval_unit => "months",
194
-
195
- # 0 trial
196
- :trial_interval_length => 0,
197
- :trial_interval_unit => "months"
198
- })
199
- end
200
-
201
- def self.find_or_create_plan(data)
202
- begin
203
- return Plan.find(data[:plan_code])
204
- rescue ActiveResource::ResourceNotFound => e
205
- plan = Plan.new(data)
206
- plan.save!
207
- return plan
208
- end
209
- end
210
- end
211
- end
@@ -1,11 +0,0 @@
1
- require 'vcr'
2
-
3
- VCR.config do |c|
4
- c.cassette_library_dir = 'spec/vcr'
5
- c.stub_with :webmock
6
- c.default_cassette_options = { :record => :new_episodes }
7
- end
8
-
9
- RSpec.configure do |c|
10
- c.extend VCR::RSpec::Macros
11
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Account do
5
- context "new record" do
6
- subject{Account.new}
7
-
8
- it { should respond_to(:account_code)}
9
- it { should respond_to(:username)}
10
- it { should respond_to(:first_name)}
11
- it { should respond_to(:last_name)}
12
- it { should respond_to(:email)}
13
- it { should respond_to(:company_name)}
14
- it { should respond_to(:hosted_login_token)}
15
- it { should respond_to(:accept_language)}
16
- end
17
-
18
- end
19
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe BillingInfo do
5
- context "new record" do
6
- subject{BillingInfo.new}
7
-
8
- it { should respond_to(:first_name)}
9
- it { should respond_to(:last_name)}
10
- it { should respond_to(:address1)}
11
- it { should respond_to(:address2)}
12
- it { should respond_to(:city)}
13
- it { should respond_to(:state)}
14
- it { should respond_to(:zip)}
15
- it { should respond_to(:country)}
16
- it { should respond_to(:phone)}
17
- it { should respond_to(:ip_address)}
18
- it { should respond_to(:vat_number)}
19
-
20
- context "embedded credit card" do
21
- before(:each) do
22
- @credit_card = subject.credit_card
23
- end
24
-
25
- it{ @credit_card.should respond_to(:number)}
26
- it{ @credit_card.should respond_to(:last_four)}
27
- it{ @credit_card.should respond_to(:type)}
28
- it{ @credit_card.should respond_to(:verification_value)}
29
- it{ @credit_card.should respond_to(:month)}
30
- it{ @credit_card.should respond_to(:year)}
31
- it{ @credit_card.should respond_to(:start_month)}
32
- it{ @credit_card.should respond_to(:start_year)}
33
- it{ @credit_card.should respond_to(:issue_number)}
34
-
35
- end
36
-
37
- end
38
- end
39
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Charge do
5
- context "new record" do
6
- subject{Charge.new}
7
-
8
- it { should respond_to(:id)}
9
- it { should respond_to(:account_code)}
10
- it { should respond_to(:quantity)}
11
- it { should respond_to(:unit_amount_in_cents)}
12
- it { should respond_to(:amount_in_cents)}
13
- it { should respond_to(:start_date)}
14
- it { should respond_to(:end_date)}
15
- it { should respond_to(:description)}
16
- it { should respond_to(:created_at)}
17
- end
18
-
19
- end
20
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "RecurlyConfig" do
4
-
5
- context "loading from YML" do
6
- it "should load traditional configuration from a YML file" do
7
- Recurly.configure_from_yaml("#{File.dirname(__FILE__)}/../config/test1.yml")
8
- Recurly.api_key.should == "asdf4jk31"
9
- Recurly.subdomain.should == "site1"
10
- end
11
-
12
- it "should load configuration from a YML file based on running environment" do
13
- Recurly.configure_from_yaml("#{File.dirname(__FILE__)}/../config/test2.yml")
14
- Recurly.api_key.should == "asdf4jk32"
15
- Recurly.subdomain.should == "site2"
16
- end
17
- end
18
-
19
- context "loading from json" do
20
- it "should load configuration from a json config string" do
21
- Recurly.configure_from_json({
22
- :api_key => "somepass",
23
- :subdomain => 'recurlytest3-test',
24
- }.to_json)
25
- Recurly.api_key.should == "somepass"
26
- Recurly.subdomain.should == 'recurlytest3-test'
27
- Recurly::Base.site.to_s.should == "https://api.recurly.com"
28
-
29
- # test with some crazy chars in the password
30
- Recurly.configure_from_json({
31
- :api_key => "*$&!!::@&!)*)*_",
32
- :subdomain => "recurlytest3-test",
33
- }.to_json)
34
-
35
- Recurly.api_key.should == "*$&!!::@&!)*)*_"
36
- Recurly::Base.user.should == Recurly.api_key
37
- Recurly.subdomain.should == 'recurlytest3-test'
38
- Recurly::Base.site.to_s.should == "https://api.recurly.com"
39
- end
40
-
41
- end
42
- end