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,86 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Invoice do
5
- # version accounts based on this current files modification dates
6
- timestamp = File.mtime(__FILE__).to_i
7
-
8
- def create_sample_charges(account)
9
- Factory.create_charge(account.account_code, :amount => 10.00)
10
- Factory.create_charge(account.account_code, :amount => 15.00)
11
- end
12
-
13
- describe "creating an invoice" do
14
- context "with charges" do
15
- use_vcr_cassette "invoice/create/#{timestamp}"
16
-
17
- let(:account) { Factory.create_account_with_billing_info("invoice-create-#{timestamp}") }
18
- before(:each) do
19
- create_sample_charges(account)
20
- @invoice = Invoice.create(:account_code => account.account_code)
21
- end
22
-
23
- it "should save successfully" do
24
- @invoice.total_in_cents.should == 2500
25
- @invoice.line_items.length.should == 2
26
- end
27
- end
28
-
29
- context "without charges" do
30
- use_vcr_cassette "invoice/create-no-charges/#{timestamp}"
31
-
32
- let(:account) { Factory.create_account_with_billing_info("invoice-create-no-charges-#{timestamp}") }
33
-
34
- it "should not be created since no charges were posted" do
35
- @invoice = Invoice.create(:account_code => account.account_code)
36
- @invoice.should_not be_valid
37
- end
38
- end
39
- end
40
-
41
- describe "listing invoices" do
42
- use_vcr_cassette "invoice/list/#{timestamp}"
43
-
44
- let(:account) { Factory.create_account_with_billing_info("invoice-list-#{timestamp}") }
45
- before(:each) do
46
- Factory.create_charge(account.account_code, :amount => 1.00)
47
- invoice = Invoice.create(:account_code => account.account_code)
48
-
49
- Factory.create_charge(account.account_code, :amount => 3.00)
50
- invoice = Invoice.create(:account_code => account.account_code)
51
-
52
- @invoices = Invoice.list(account.account_code)
53
- end
54
-
55
- it "should return the list of invoices" do
56
- @invoices.length.should == 2
57
- end
58
-
59
- it "should also be available via Account#invoices" do
60
- account.invoices.should == @invoices
61
- end
62
-
63
- end
64
-
65
- describe "looking up an invoice" do
66
- use_vcr_cassette "invoice/lookup/#{timestamp}"
67
-
68
- let(:account) { Factory.create_account_with_billing_info("invoice-lookup-#{timestamp}") }
69
- before(:each) do
70
- Factory.create_charge(account.account_code, :amount => 15.00)
71
- invoice = Invoice.create(:account_code => account.account_code)
72
- @invoice = Invoice.lookup(account.account_code, invoice.id)
73
- end
74
-
75
- it "should return the invoice" do
76
- @invoice.total_in_cents.should == 1500
77
- @invoice.line_items.length.should == 1
78
- end
79
-
80
- it "should also be available via Account#lookup_invoice" do
81
- account.lookup_invoice(@invoice.id).should == @invoice
82
- end
83
-
84
- end
85
- end
86
- end
@@ -1,87 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Plan do
5
- # version accounts based on this current files modification dates
6
- timestamp = File.mtime(__FILE__).to_i
7
-
8
- describe "list all plans" do
9
- use_vcr_cassette "plan/all"
10
-
11
- before(:each) do
12
- @paid = Factory.paid_plan
13
- @trial = Factory.trial_plan
14
- @plans = Plan.all
15
- end
16
-
17
- it "should return a list result" do
18
- @plans.should be_an_instance_of(Array)
19
- end
20
-
21
- it "should return the paid plan" do
22
- @plans.should include(@paid)
23
- end
24
-
25
- it "should return the trial plan" do
26
- @plans.should include(@trial)
27
- end
28
-
29
- end
30
-
31
- describe "find plan" do
32
- use_vcr_cassette 'plan/find'
33
- before(:each) do
34
- @paid = Factory.paid_plan
35
- @trial = Factory.trial_plan
36
- end
37
-
38
- it "should return the paid plan" do
39
- plan = Plan.find(@paid.plan_code)
40
- plan.should_not be_nil
41
- plan.should == @paid
42
- end
43
-
44
- it "should return the trial plan" do
45
- plan = Plan.find(@trial.plan_code)
46
- plan.should_not be_nil
47
- plan.should == @trial
48
- end
49
- end
50
-
51
- describe "update a plan" do
52
- use_vcr_cassette 'plan/update'
53
-
54
- # grabs a fresh test_plan
55
- def test_plan
56
- Plan.find("test")
57
- end
58
-
59
- # setup test plan
60
- before(:each) do
61
- begin
62
- @test_plan = test_plan
63
- rescue ActiveResource::ResourceNotFound => e
64
- Plan.new({
65
- :plan_code => "test",
66
- :name => "Test Plan",
67
- :unit_amount_in_cents => 100,
68
- :plan_interval_length => 1,
69
- :plan_interval_unit => "months",
70
- :trial_interval_length => 0,
71
- :trial_interval_unit => "months"
72
- }).save!
73
- @test_plan = test_plan
74
- end
75
- end
76
-
77
- it "should update the plan" do
78
- @test_plan.unit_amount_in_cents = 200
79
- @test_plan.save!
80
-
81
- @test_plan = test_plan
82
- @test_plan.unit_amount_in_cents.should == 200
83
- end
84
- end
85
-
86
- end
87
- end
@@ -1,221 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'test/unit'
4
- require 'active_support/testing/deprecation'
5
-
6
- module Recurly
7
- describe Subscription do
8
- # version accounts based on this current files modification dates
9
- timestamp = File.mtime(__FILE__).to_i
10
-
11
- describe "look up a subscription" do
12
- use_vcr_cassette "subscription/find/#{timestamp}"
13
-
14
- let(:account){ Factory.create_account("subscription-find-#{timestamp}") }
15
-
16
- before(:each) do
17
- Factory.create_subscription(account, :paid)
18
- end
19
-
20
- it "should return the subscription" do
21
- subscription = Subscription.find(account.account_code)
22
- subscription.state.should == "active"
23
- subscription.plan.plan_code.should == "paid"
24
- subscription.plan_code.should == "paid"
25
- end
26
- end
27
-
28
- describe "create a new subscription" do
29
- use_vcr_cassette "subscription/create/#{timestamp}"
30
-
31
- let(:account){ Factory.create_account("subscription-create-#{timestamp}") }
32
-
33
- before(:each) do
34
- @subscription = Factory.create_subscription(account, :paid)
35
- end
36
-
37
- it "should create the subscription successfully" do
38
- @subscription.should_not be_nil
39
- end
40
-
41
- it "should not be canceled" do
42
- @subscription.canceled_at.should be_nil
43
- end
44
-
45
- it "should be active" do
46
- @subscription.state.should == "active"
47
- end
48
-
49
- it "should be started" do
50
- @subscription.current_period_started_at.should_not be_nil
51
- end
52
-
53
- end
54
-
55
- describe "updates and downgrades" do
56
-
57
- context "normal case" do
58
- use_vcr_cassette "subscription/change1/#{timestamp}"
59
-
60
- let(:account){ Factory.create_account("subscription-change1-#{timestamp}") }
61
-
62
- before(:each) do
63
- Factory.create_subscription(account, :paid)
64
- @subscription = Subscription.find(account.account_code)
65
-
66
- @subscription.change('now', :quantity => 2)
67
- end
68
-
69
- it "should update the subscription quantity" do
70
- Subscription.find(account.account_code).quantity.should == 2
71
- end
72
- end
73
-
74
- context "when account code is an integer (issue GH-4)" do
75
- use_vcr_cassette "subscription/change2/#{timestamp}"
76
-
77
- let(:account){ Factory.create_account(timestamp) }
78
-
79
- before(:each) do
80
- Factory.create_subscription(account, :paid)
81
- @subscription = Subscription.find(account.account_code)
82
-
83
- @subscription.id = account.account_code.to_i
84
- @subscription.change('now', :quantity => 2)
85
- end
86
-
87
- it "should update the subscription quantity" do
88
- Subscription.find(account.account_code).quantity.should == 2
89
- end
90
- end
91
- end
92
-
93
- describe "reactivate a subscription" do
94
- use_vcr_cassette "subscription/reactivate/#{timestamp}"
95
-
96
- let(:account){ Factory.create_account("subscription-reactivate-#{timestamp}") }
97
- before(:each) do
98
- Factory.create_subscription(account, :paid)
99
- @subscription = Subscription.find(account.account_code)
100
- @subscription.cancel
101
-
102
- Subscription.reactivate(account.account_code)
103
- end
104
-
105
- it "should mark the subscription as active" do
106
- subscription = Subscription.find(account.account_code)
107
- subscription.state.should == "active"
108
- end
109
-
110
- end
111
-
112
- describe "cancel a subscription" do
113
- context "without account_code" do
114
-
115
- use_vcr_cassette "subscription/cancel/#{timestamp}"
116
-
117
- let(:account){ Factory.create_account("subscription-cancel-#{timestamp}") }
118
- before(:each) do
119
- Factory.create_subscription(account, :paid)
120
- @subscription = Subscription.find(account.account_code)
121
-
122
- # cancel subscription
123
- @subscription.cancel
124
- end
125
-
126
- it "should mark the subscription state as canceled" do
127
- Subscription.find(account.account_code).state.should == "canceled"
128
- end
129
-
130
- it "should mark the subscription canceled_at" do
131
- Subscription.find(account.account_code).canceled_at.should_not be_nil
132
- end
133
-
134
- end
135
-
136
- context "with account_code (backward compat)" do
137
- use_vcr_cassette "subscription/cancel-with-code/#{timestamp}"
138
-
139
- include ActiveSupport::Testing::Deprecation
140
-
141
- # ghetto workaround for rspec2 (till i figure out how to use test/unit helpers within rspec)
142
- def assert(value, msg = nil)
143
- raise "#{value} should have been true" unless value
144
- end
145
-
146
- let(:account){ Factory.create_account("subscription-cancel-with-code-#{timestamp}") }
147
- before(:each) do
148
- Factory.create_subscription(account, :paid)
149
- @subscription = Subscription.find(account.account_code)
150
-
151
- assert_deprecated("Calling Recurly::Subscription#cancel with an account_code has been deprecated. Use the static method Recurly::Subscription.cancel(account_code) instead") do
152
- # cancel subscription
153
- @subscription.cancel(account.account_code)
154
- end
155
- end
156
-
157
- it "should mark the subscription state as canceled" do
158
- Subscription.find(account.account_code).state.should == "canceled"
159
- Subscription.find(account.account_code).canceled_at.should_not be_nil
160
- end
161
- end
162
- end
163
-
164
- describe "refund a subscription" do
165
- context "full refund" do
166
- use_vcr_cassette "subscription/refund-full/#{timestamp}"
167
-
168
- let(:account){ Factory.create_account("subscription-refund-full-#{timestamp}") }
169
-
170
- before(:each) do
171
- Factory.create_subscription(account, :paid)
172
- @subscription = Subscription.find(account.account_code)
173
- end
174
-
175
- it "should remove the subscription entry and post a full refund" do
176
- @subscription.refund(:full)
177
- expect {
178
- Subscription.find(account.account_code)
179
- }.to raise_error(ActiveResource::ResourceNotFound)
180
- end
181
- end
182
-
183
- context "partial refund" do
184
- use_vcr_cassette "subscription/refund-partial/#{timestamp}"
185
-
186
- let(:account){ Factory.create_account("subscription-refund-partial-#{timestamp}") }
187
-
188
- before(:each) do
189
- Factory.create_subscription(account, :paid)
190
- @subscription = Subscription.find(account.account_code)
191
- end
192
-
193
- it "should remove the subscription entry and post a partial refund" do
194
- @subscription.refund(:partial)
195
- expect {
196
- Subscription.find(account.account_code)
197
- }.to raise_error(ActiveResource::ResourceNotFound)
198
- end
199
- end
200
-
201
- context "no refund" do
202
- use_vcr_cassette "subscription/refund-none/#{timestamp}"
203
-
204
- let(:account){ Factory.create_account("subscription-refund-none-#{timestamp}") }
205
-
206
- before(:each) do
207
- Factory.create_subscription(account, :paid)
208
- @subscription = Subscription.find(account.account_code)
209
- end
210
-
211
- it "should remove the subscription entry and not post a refund" do
212
- @subscription.refund(:none)
213
- expect {
214
- Subscription.find(account.account_code)
215
- }.to raise_error(ActiveResource::ResourceNotFound)
216
- end
217
- end
218
-
219
- end
220
- end
221
- end
@@ -1,154 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Transaction do
5
- # version accounts based on this current files modification dates
6
- timestamp = File.mtime(__FILE__).to_i
7
-
8
- describe "create new transaction" do
9
- context "on an new account" do
10
- use_vcr_cassette "transaction/create-no-account/#{timestamp}"
11
- let(:account_code) { "transaction-create-with-accout-#{timestamp}" }
12
-
13
- before(:each) do
14
- @transaction = Factory.create_full_transaction account_code,
15
- :amount_in_cents => 700,
16
- :description => "setup fee of 7 dollarz"
17
- end
18
-
19
- it "should save successfully" do
20
- @transaction.status.should == "success"
21
- @transaction.errors.should be_empty
22
- end
23
- end
24
-
25
- context "with an existing account" do
26
- use_vcr_cassette "transaction/create-with-account/#{timestamp}"
27
- let(:account) { Factory.create_account_with_billing_info("transaction-create-with-account-#{timestamp}") }
28
-
29
- before(:each) do
30
- @transaction = Factory.create_transaction account.account_code,
31
- :amount_in_cents => 700,
32
- :description => "test transaction for $7"
33
- end
34
-
35
- it "should save successfully" do
36
- @transaction.status.should == "success"
37
- @transaction.errors.should be_empty
38
- end
39
- end
40
- end
41
-
42
- describe "find all transactions" do
43
- use_vcr_cassette "transaction/all/#{timestamp}"
44
-
45
- before(:each) do
46
- @transactions = Transaction.all
47
- end
48
-
49
- it "should be successful" do
50
- @transactions.should be_an_instance_of(Array)
51
- end
52
- end
53
-
54
- describe "list account transactions" do
55
- context "initial void transaction" do
56
- use_vcr_cassette "transaction/list-initial/#{timestamp}"
57
- let(:account) { Factory.create_account_with_billing_info("transaction-list-initial-#{timestamp}") }
58
-
59
- before(:each) do
60
- @transactions = Transaction.list_for_account(account.account_code)
61
- end
62
-
63
- it "should create one transaction after registering" do
64
- @transactions.count.should eql(1)
65
- end
66
-
67
- it "should be in void state" do
68
- @transactions.first.amount_in_cents.should == 0
69
- @transactions.first.status.should == 'success'
70
- end
71
- end
72
-
73
- context "with transactions" do
74
- use_vcr_cassette "transaction/list-filled/#{timestamp}"
75
- let(:account) { Factory.create_account_with_billing_info("transaction-list-filled-#{timestamp}") }
76
-
77
- before(:each) do
78
- Factory.create_transaction account.account_code, :amount_in_cents => 100, :description => "one"
79
- Factory.create_transaction account.account_code, :amount_in_cents => 200, :description => "two"
80
- Factory.create_transaction account.account_code, :amount_in_cents => 300, :description => "three"
81
-
82
- @successful_transactions = Transaction.list_for_account(account.account_code, :success)
83
- @total_transactions = Transaction.list_for_account(account.account_code)
84
- end
85
-
86
- it "should return a list of transactions made on the account" do
87
- # one authorization and three transactions
88
- @successful_transactions.length.should == 4
89
- @total_transactions.length.should == 4
90
- end
91
-
92
- it "should also be available via Account#transactions" do
93
- account.transactions(:success).should == @successful_transactions
94
- end
95
-
96
- end
97
- end
98
-
99
- describe "lookup account transaction" do
100
- use_vcr_cassette "transaction/lookup/#{timestamp}"
101
- let(:account) { Factory.create_account_with_billing_info("transaction-lookup-#{timestamp}") }
102
-
103
- before(:each) do
104
- t1 = Factory.create_transaction account.account_code, :amount_in_cents => 100, :description => "one"
105
- t2 = Factory.create_transaction account.account_code, :amount_in_cents => 200, :description => "two"
106
- t3 = Factory.create_transaction account.account_code, :amount_in_cents => 300, :description => "three"
107
-
108
- @transaction1 = Transaction.lookup(account.account_code, t1.id)
109
- @transaction2 = Transaction.lookup(account.account_code, t2.id)
110
- @transaction3 = Transaction.lookup(account.account_code, t3.id)
111
- end
112
-
113
- it "should the transaction details" do
114
- @transaction2.amount_in_cents.should == 200
115
- end
116
-
117
- it "should also be available via Account#lookup_transaction" do
118
- account.lookup_transaction(@transaction3.id).should == @transaction3
119
- end
120
- end
121
-
122
- describe "void a transaction" do
123
- use_vcr_cassette "transaction/void/#{timestamp}"
124
- let(:account) { Factory.create_account_with_billing_info("transaction-void-#{timestamp}") }
125
-
126
- before(:each) do
127
- @transaction = Factory.create_transaction account.account_code, :amount_in_cents => 100, :description => "one"
128
- end
129
-
130
- it "should void a transaction" do
131
- @transaction.void
132
- Transaction.list(:voided).should include(@transaction)
133
- end
134
- end
135
-
136
- describe "refund a transaction" do
137
- use_vcr_cassette "transaction/refund/#{timestamp}"
138
- let(:account) { Factory.create_account_with_billing_info("transaction-refund-#{timestamp}") }
139
-
140
- before(:each) do
141
- @transaction = Factory.create_transaction account.account_code, :amount_in_cents => 1000, :description => "one"
142
- end
143
-
144
- it "should refund the transaction" do
145
- @transaction.refund(1000)
146
-
147
- pending "not showing up in the refunds list for some reason..."
148
- Transaction.list(:refunds).map(&:id).should include(@transaction.id)
149
- end
150
- end
151
-
152
-
153
- end
154
- end