recurly 0.3.1 → 0.3.2

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 (61) hide show
  1. data/lib/recurly.rb +8 -0
  2. data/lib/recurly/account.rb +5 -0
  3. data/lib/recurly/rails3/railtie.rb +9 -0
  4. data/lib/recurly/version.rb +1 -1
  5. data/spec/integration/account_spec.rb +29 -1
  6. data/spec/integration/add_on_spec.rb +84 -0
  7. data/spec/vcr/account/accept-language-account/1294473653.yml +68 -0
  8. data/spec/vcr/account/accept-language-account/1294473761.yml +68 -0
  9. data/spec/vcr/account/accept-language/1294473117.yml +167 -0
  10. data/spec/vcr/account/close/{1288381765.yml → 1294473761.yml} +26 -25
  11. data/spec/vcr/account/create-blank/{1288381765.yml → 1294473761.yml} +5 -4
  12. data/spec/vcr/account/create-duplicate/{1288381765.yml → 1294473761.yml} +13 -11
  13. data/spec/vcr/account/create-min/{1288381765.yml → 1294473761.yml} +12 -11
  14. data/spec/vcr/account/create/{1288381765.yml → 1294473761.yml} +12 -11
  15. data/spec/vcr/account/find/{1288381765.yml → 1294473761.yml} +25 -24
  16. data/spec/vcr/account/list/{1288381765.yml → 1294473761.yml} +328 -287
  17. data/spec/vcr/account/update/{1288381765.yml → 1294473761.yml} +47 -45
  18. data/spec/vcr/billing/create/1286682213.yml +28 -27
  19. data/spec/vcr/billing/destroy/1286682213.yml +42 -41
  20. data/spec/vcr/billing/find/1286682213.yml +38 -37
  21. data/spec/vcr/billing/update/1286682213.yml +40 -39
  22. data/spec/vcr/charge/create/1287465632.yml +36 -35
  23. data/spec/vcr/charge/delete-uninvoiced/1287465632.yml +36 -35
  24. data/spec/vcr/charge/list-all/1287465632.yml +43 -42
  25. data/spec/vcr/charge/list-invoiced/1287465632.yml +70 -69
  26. data/spec/vcr/charge/list-pending/1287465632.yml +43 -42
  27. data/spec/vcr/charge/lookup/1287465632.yml +22 -21
  28. data/spec/vcr/credit/create/1287461400.yml +23 -22
  29. data/spec/vcr/credit/delete/1287461400.yml +33 -32
  30. data/spec/vcr/credit/list/1287461400.yml +43 -42
  31. data/spec/vcr/credit/lookup/1287461400.yml +24 -23
  32. data/spec/vcr/invoice/create-no-charges/1287167121.yml +23 -22
  33. data/spec/vcr/invoice/create/1287167121.yml +48 -47
  34. data/spec/vcr/invoice/list/1287167121.yml +67 -66
  35. data/spec/vcr/invoice/lookup/1287167121.yml +50 -49
  36. data/spec/vcr/plan/all.yml +29 -17
  37. data/spec/vcr/plan/delete/1286677585.yml +21 -21
  38. data/spec/vcr/plan/find.yml +42 -18
  39. data/spec/vcr/plan/update.yml +17 -17
  40. data/spec/vcr/subscription/addons/add/1292420980.yml +479 -0
  41. data/spec/vcr/subscription/addons/create/1292420980.yml +318 -0
  42. data/spec/vcr/subscription/addons/remove/1292420980.yml +448 -0
  43. data/spec/vcr/subscription/cancel-with-code/1287455769.yml +93 -69
  44. data/spec/vcr/subscription/cancel/1287455769.yml +80 -58
  45. data/spec/vcr/subscription/change1/1287455769.yml +77 -55
  46. data/spec/vcr/subscription/change2/1287455769.yml +77 -55
  47. data/spec/vcr/subscription/create/1287455769.yml +43 -27
  48. data/spec/vcr/subscription/find/1287455769.yml +54 -36
  49. data/spec/vcr/subscription/reactivate/1287455769.yml +83 -61
  50. data/spec/vcr/subscription/refund-full/1287455769.yml +69 -51
  51. data/spec/vcr/subscription/refund-none/1287455769.yml +70 -52
  52. data/spec/vcr/subscription/refund-partial/1287455769.yml +70 -52
  53. data/spec/vcr/transaction/all/1289558212.yml +46 -46
  54. data/spec/vcr/transaction/create-no-account/1289558212.yml +11 -11
  55. data/spec/vcr/transaction/create-with-account/1289558212.yml +27 -26
  56. data/spec/vcr/transaction/list-filled/1289558212.yml +54 -53
  57. data/spec/vcr/transaction/list-initial/1289558212.yml +27 -26
  58. data/spec/vcr/transaction/lookup/1289558212.yml +64 -63
  59. data/spec/vcr/transaction/refund/1289558212.yml +35 -34
  60. data/spec/vcr/transaction/void/1289558212.yml +71 -70
  61. metadata +34 -20
data/lib/recurly.rb CHANGED
@@ -86,5 +86,13 @@ module Recurly
86
86
  c.site = config_data['site']
87
87
  end
88
88
  end
89
+
90
+ def current_accept_language
91
+ Thread.current[:recurly_accept_language]
92
+ end
93
+
94
+ def current_accept_language=(accept_language)
95
+ Thread.current[:recurly_accept_language] = accept_language
96
+ end
89
97
  end
90
98
  end
@@ -13,6 +13,11 @@ module Recurly
13
13
  account_code_was || account_code
14
14
  end
15
15
 
16
+ def encode(options={})
17
+ attributes[:accept_language] ||= Recurly.current_accept_language
18
+ super
19
+ end
20
+
16
21
  # Maps the
17
22
  SHOW_PARAMS = {
18
23
  :active => "active_subscribers",
@@ -8,5 +8,14 @@ module Recurly
8
8
  Recurly.configure unless Recurly.configured?
9
9
  end
10
10
 
11
+ initializer :recurly_set_accept_language do
12
+ ActionController::Base.class_eval do
13
+ prepend_before_filter do
14
+ # used to default the current accept language to the latest request
15
+ Recurly.current_accept_language = request.env["HTTP_ACCEPT_LANGUAGE"]
16
+ end
17
+ end
18
+ end
19
+
11
20
  end
12
21
  end
@@ -1,3 +1,3 @@
1
1
  module Recurly #:nodoc
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -131,7 +131,7 @@ module Recurly
131
131
 
132
132
  it "should return a list of accounts with matching criteria" do
133
133
  Account.list(:all).total_entries.should >= 8
134
- Account.list(:paid).total_entries.should >= 4
134
+ Account.list(:active).total_entries.should >= 4
135
135
  Account.list(:free).total_entries.should >= 4
136
136
  end
137
137
 
@@ -242,5 +242,33 @@ module Recurly
242
242
  end
243
243
  end
244
244
 
245
+ describe "defaulting account's accept_language to Recurly.current_accept_language" do
246
+
247
+ context "user is from france" do
248
+ # wrap these example runs, setting current_accept_language properly
249
+ around(:each) do |example|
250
+ old_setting = Recurly.current_accept_language
251
+ Recurly.current_accept_language = "fr"
252
+ example.run
253
+ Recurly.current_accept_language = old_setting
254
+ end
255
+
256
+ context "user creates an account" do
257
+ use_vcr_cassette "account/accept-language-account/#{timestamp}"
258
+ let(:attributes) { Factory.account_attributes("account1-french-#{timestamp}") }
259
+
260
+ before(:each) do
261
+ @account = Account.create(attributes)
262
+ end
263
+
264
+ it "should automaticaly set the accounts accept_language" do
265
+ @account.attributes[:accept_language].should == "fr"
266
+ end
267
+ end
268
+
269
+ end
270
+
271
+ end
272
+
245
273
  end
246
274
  end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ module Recurly
4
+ describe "Subscription Addons" do
5
+ # version accounts based on this current files modification dates
6
+ timestamp = File.mtime(__FILE__).to_i
7
+
8
+ describe "create a subscription with addons" do
9
+ use_vcr_cassette "subscription/addons/create/#{timestamp}"
10
+
11
+ let(:account){ Factory.create_account("subscription-addons-create-#{timestamp}") }
12
+
13
+ before(:each) do
14
+ Factory.create_subscription(account, :paid, :add_ons => [
15
+ {
16
+ :add_on_code => "special",
17
+ :quantity => 1,
18
+ :unit_amount => 10,
19
+ }
20
+ ])
21
+ end
22
+
23
+ it "should return the subscription addons" do
24
+ subscription = Subscription.find(account.account_code)
25
+ subscription.add_ons.count == 1
26
+ end
27
+ end
28
+
29
+ describe "add an addon to a subscription" do
30
+ use_vcr_cassette "subscription/addons/add/#{timestamp}"
31
+
32
+ let(:account){ Factory.create_account("subscription-addons-add-#{timestamp}") }
33
+
34
+ before(:each) do
35
+ Factory.create_subscription(account, :paid, :add_ons => [
36
+ {
37
+ :add_on_code => "special",
38
+ :quantity => 1,
39
+ :unit_amount => 10,
40
+ }
41
+ ])
42
+ end
43
+
44
+ it "should allow adding a new addon" do
45
+ subscription = Subscription.find(account.account_code)
46
+ subscription.add_ons << {
47
+ :add_on_code => "special2",
48
+ :quantity => 2,
49
+ :unit_amount => 500
50
+ }
51
+ subscription.change('now', :add_ons => subscription.add_ons)
52
+
53
+ subscription = Subscription.find(account.account_code)
54
+ subscription.add_ons.count == 2
55
+ end
56
+ end
57
+
58
+ describe "remove an addon from a subscription" do
59
+ use_vcr_cassette "subscription/addons/remove/#{timestamp}"
60
+
61
+ let(:account){ Factory.create_account("subscription-addons-remove-#{timestamp}") }
62
+
63
+ before(:each) do
64
+ Factory.create_subscription(account, :paid, :add_ons => [
65
+ {
66
+ :add_on_code => "special",
67
+ :quantity => 1,
68
+ :unit_amount => 1000,
69
+ }
70
+ ])
71
+ end
72
+
73
+ it "should allow removing an addon" do
74
+ subscription = Subscription.find(account.account_code)
75
+ subscription.change('now', :add_ons => [])
76
+
77
+ subscription = Subscription.find(account.account_code)
78
+ subscription.add_ons.count == 0
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,68 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://railsjedi%40sogetthis.com:7PCB2mZC@recurlytest3-test.recurly.com:443/accounts.xml
6
+ body: |
7
+ <?xml version="1.0" encoding="UTF-8"?>
8
+ <account>
9
+ <company-name>Recurly Ruby Gem</company-name>
10
+ <account-code>account1-french-1294473653</account-code>
11
+ <last-name>Test</last-name>
12
+ <accept-language>fr</accept-language>
13
+ <email>verena@test.com</email>
14
+ <first-name>Verena</first-name>
15
+ </account>
16
+
17
+ headers:
18
+ accept:
19
+ - "*/*"
20
+ connection:
21
+ - close
22
+ content-type:
23
+ - application/xml
24
+ authorization:
25
+ - Basic cmFpbHNqZWRpQHNvZ2V0dGhpcy5jb206N1BDQjJtWkM=
26
+ response: !ruby/struct:VCR::Response
27
+ status: !ruby/struct:VCR::ResponseStatus
28
+ code: 201
29
+ message: Created
30
+ headers:
31
+ location:
32
+ - https://recurlytest3-test.recurly.com/accounts/account1-french-1294473653
33
+ connection:
34
+ - close
35
+ content-type:
36
+ - application/xml; charset=utf-8
37
+ x-runtime:
38
+ - "358"
39
+ date:
40
+ - Sat, 08 Jan 2011 08:01:01 GMT
41
+ server:
42
+ - nginx/0.8.53
43
+ content-length:
44
+ - "585"
45
+ set-cookie:
46
+ - account_credentials=5efb585021cad50f5041bf437711e958e99e6854065d72cc582483bd506398b356b79593ccb3742f7b88c0d283d71c9d4577d5e1a3ebf419d125a668471d8933%3A%3A; domain=.recurly.com; path=/
47
+ - ""
48
+ - _recurly_session=f3db85de64b4022a045ffb442afc32ea; domain=.recurly.com; path=/; secure; HttpOnly
49
+ cache-control:
50
+ - no-cache
51
+ body: |
52
+ <?xml version="1.0" encoding="UTF-8"?>
53
+ <account>
54
+ <id>account1-french-1294473653</id>
55
+ <account_code>account1-french-1294473653</account_code>
56
+ <username></username>
57
+ <email>verena@test.com</email>
58
+ <first_name>Verena</first_name>
59
+ <last_name>Test</last_name>
60
+ <company_name>Recurly Ruby Gem</company_name>
61
+ <balance_in_cents type="integer">0</balance_in_cents>
62
+ <closed type="boolean">false</closed>
63
+ <hosted_login_token>eeae5cb20fcd4b059f4e33d0dfe94cab</hosted_login_token>
64
+ <created_at type="datetime">2011-01-08T08:01:01Z</created_at>
65
+ <state>active</state>
66
+ </account>
67
+
68
+ http_version: "1.1"
@@ -0,0 +1,68 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://railsjedi%40sogetthis.com:7PCB2mZC@recurlytest3-test.recurly.com:443/accounts.xml
6
+ body: |
7
+ <?xml version="1.0" encoding="UTF-8"?>
8
+ <account>
9
+ <company-name>Recurly Ruby Gem</company-name>
10
+ <account-code>account1-french-1294473761</account-code>
11
+ <last-name>Test</last-name>
12
+ <accept-language>fr</accept-language>
13
+ <email>verena@test.com</email>
14
+ <first-name>Verena</first-name>
15
+ </account>
16
+
17
+ headers:
18
+ accept:
19
+ - "*/*"
20
+ connection:
21
+ - close
22
+ content-type:
23
+ - application/xml
24
+ authorization:
25
+ - Basic cmFpbHNqZWRpQHNvZ2V0dGhpcy5jb206N1BDQjJtWkM=
26
+ response: !ruby/struct:VCR::Response
27
+ status: !ruby/struct:VCR::ResponseStatus
28
+ code: 201
29
+ message: Created
30
+ headers:
31
+ location:
32
+ - https://recurlytest3-test.recurly.com/accounts/account1-french-1294473761
33
+ connection:
34
+ - close
35
+ content-type:
36
+ - application/xml; charset=utf-8
37
+ x-runtime:
38
+ - "346"
39
+ date:
40
+ - Sat, 08 Jan 2011 08:03:28 GMT
41
+ server:
42
+ - nginx/0.8.53
43
+ content-length:
44
+ - "585"
45
+ set-cookie:
46
+ - account_credentials=0698802063b183bb20df9484ab1c0d5be4fb7f1fbd4c3d74f281dc7a4875b6f3fb10363f5d05b61feda85060f09d1802a327fd6ea8a5d378326cca9ebd4dbc7e%3A%3A; domain=.recurly.com; path=/
47
+ - ""
48
+ - _recurly_session=80bb998351fb4c4751d41318f92d7f3d; domain=.recurly.com; path=/; secure; HttpOnly
49
+ cache-control:
50
+ - no-cache
51
+ body: |
52
+ <?xml version="1.0" encoding="UTF-8"?>
53
+ <account>
54
+ <id>account1-french-1294473761</id>
55
+ <account_code>account1-french-1294473761</account_code>
56
+ <username></username>
57
+ <email>verena@test.com</email>
58
+ <first_name>Verena</first_name>
59
+ <last_name>Test</last_name>
60
+ <company_name>Recurly Ruby Gem</company_name>
61
+ <balance_in_cents type="integer">0</balance_in_cents>
62
+ <closed type="boolean">false</closed>
63
+ <hosted_login_token>72cf579d8ef84a78a54117d97e1a5c11</hosted_login_token>
64
+ <created_at type="datetime">2011-01-08T08:03:28Z</created_at>
65
+ <state>active</state>
66
+ </account>
67
+
68
+ http_version: "1.1"
@@ -0,0 +1,167 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://railsjedi%40sogetthis.com:7PCB2mZC@recurlytest3-test.recurly.com:443/company/plans/paid.xml
6
+ body:
7
+ headers:
8
+ accept:
9
+ - application/xml
10
+ connection:
11
+ - close
12
+ authorization:
13
+ - Basic cmFpbHNqZWRpQHNvZ2V0dGhpcy5jb206N1BDQjJtWkM=
14
+ response: !ruby/struct:VCR::Response
15
+ status: !ruby/struct:VCR::ResponseStatus
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ x-ua-compatible:
20
+ - IE=Edge
21
+ etag:
22
+ - "\"47a9e8e85691ef0600a2dd39f113a21e\""
23
+ connection:
24
+ - close
25
+ content-type:
26
+ - application/xml; charset=utf-8
27
+ x-runtime:
28
+ - "27"
29
+ date:
30
+ - Sat, 08 Jan 2011 07:58:06 GMT
31
+ server:
32
+ - nginx/0.8.53
33
+ content-length:
34
+ - "1564"
35
+ set-cookie:
36
+ - _recurly_session=db99a487d1f0e1eabe733c2987356ddc; domain=.recurly.com; path=/; secure; HttpOnly
37
+ cache-control:
38
+ - private, max-age=0, must-revalidate
39
+ body: |
40
+ <?xml version="1.0" encoding="UTF-8"?>
41
+ <plan>
42
+ <plan_code>paid</plan_code>
43
+ <name>Paid</name>
44
+ <description></description>
45
+ <success_url></success_url>
46
+ <cancel_url></cancel_url>
47
+ <created_at type="datetime">2010-09-19T00:56:05Z</created_at>
48
+ <unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
49
+ <setup_fee_in_cents type="integer">0</setup_fee_in_cents>
50
+ <plan_interval_length type="integer">1</plan_interval_length>
51
+ <plan_interval_unit>months</plan_interval_unit>
52
+ <trial_interval_length type="integer">0</trial_interval_length>
53
+ <trial_interval_unit>months</trial_interval_unit>
54
+ <latest_version depreciated="true">
55
+ <version type="integer">1</version>
56
+ <unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
57
+ <setup_fee_in_cents type="integer">0</setup_fee_in_cents>
58
+ <plan_interval_length type="integer">1</plan_interval_length>
59
+ <plan_interval_unit>months</plan_interval_unit>
60
+ <trial_interval_length type="integer">0</trial_interval_length>
61
+ <trial_interval_unit>months</trial_interval_unit>
62
+ <created_at type="datetime">2010-12-10T19:19:03Z</created_at>
63
+ </latest_version>
64
+ <add_ons type="collection">
65
+ <add_on>
66
+ <add_on_code>special</add_on_code>
67
+ <default_unit_amount_in_cents>1000</default_unit_amount_in_cents>
68
+ <default_quantity>1</default_quantity>
69
+ </add_on>
70
+ <add_on>
71
+ <add_on_code>special2</add_on_code>
72
+ <default_unit_amount_in_cents>1500</default_unit_amount_in_cents>
73
+ <default_quantity>1</default_quantity>
74
+ </add_on>
75
+ </add_ons>
76
+ </plan>
77
+
78
+ http_version: "1.1"
79
+ - !ruby/struct:VCR::HTTPInteraction
80
+ request: !ruby/struct:VCR::Request
81
+ method: :post
82
+ uri: https://railsjedi%40sogetthis.com:7PCB2mZC@recurlytest3-test.recurly.com:443/accounts/account-french-1294473117/subscription.xml
83
+ body: |
84
+ <?xml version="1.0" encoding="UTF-8"?>
85
+ <subscription>
86
+ <quantity type="integer">1</quantity>
87
+ <plan-code>paid</plan-code>
88
+ <account>
89
+ <company-name>Recurly Ruby Gem</company-name>
90
+ <account-code>account-french-1294473117</account-code>
91
+ <last-name>Test</last-name>
92
+ <billing-info>
93
+ <city>San Francisco</city>
94
+ <address1>123 Test St</address1>
95
+ <zip>94115</zip>
96
+ <country>US</country>
97
+ <credit-card>
98
+ <number>1</number>
99
+ <month type="integer">1</month>
100
+ <year type="integer">2012</year>
101
+ <verification-value>123</verification-value>
102
+ </credit-card>
103
+ <last-name>Test</last-name>
104
+ <first-name>Verena</first-name>
105
+ <state>CA</state>
106
+ </billing-info>
107
+ <email>verena@test.com</email>
108
+ <first-name>Verena</first-name>
109
+ </account>
110
+ </subscription>
111
+
112
+ headers:
113
+ accept:
114
+ - "*/*"
115
+ connection:
116
+ - close
117
+ content-type:
118
+ - application/xml
119
+ authorization:
120
+ - Basic cmFpbHNqZWRpQHNvZ2V0dGhpcy5jb206N1BDQjJtWkM=
121
+ response: !ruby/struct:VCR::Response
122
+ status: !ruby/struct:VCR::ResponseStatus
123
+ code: 201
124
+ message: Created
125
+ headers:
126
+ connection:
127
+ - close
128
+ content-type:
129
+ - application/xml; charset=utf-8
130
+ x-runtime:
131
+ - "10955"
132
+ date:
133
+ - Sat, 08 Jan 2011 07:58:17 GMT
134
+ server:
135
+ - nginx/0.8.53
136
+ content-length:
137
+ - "898"
138
+ set-cookie:
139
+ - account_credentials=6cba421d09e204c2bfd53ed49c5f577d3c448e8f5c1cecb1c5e6749a01a19aa16bfebd18747805c433a01b10d05302472320eaac8b5804de67160e98bc62c35b%3A%3A; domain=.recurly.com; path=/
140
+ - ""
141
+ - _recurly_session=058b42e7f16161577a325998a32ce06b; domain=.recurly.com; path=/; secure; HttpOnly
142
+ cache-control:
143
+ - no-cache
144
+ body: |
145
+ <?xml version="1.0" encoding="UTF-8"?>
146
+ <subscription>
147
+ <id>account-french-1294473117</id>
148
+ <account_code>account-french-1294473117</account_code>
149
+ <plan>
150
+ <plan_code>paid</plan_code>
151
+ <name>Paid</name>
152
+ </plan>
153
+ <state>active</state>
154
+ <quantity type="integer">1</quantity>
155
+ <total_amount_in_cents type="integer">1000</total_amount_in_cents>
156
+ <activated_at type="datetime">2011-01-08T07:58:07Z</activated_at>
157
+ <canceled_at nil="true" type="datetime"></canceled_at>
158
+ <expires_at nil="true" type="datetime"></expires_at>
159
+ <current_period_started_at type="datetime">2011-01-08T07:58:07Z</current_period_started_at>
160
+ <current_period_ends_at type="datetime">2011-02-08T07:58:07Z</current_period_ends_at>
161
+ <trial_started_at nil="true" type="datetime"></trial_started_at>
162
+ <trial_ends_at nil="true" type="datetime"></trial_ends_at>
163
+ <add_ons type="array">
164
+ </add_ons>
165
+ </subscription>
166
+
167
+ http_version: "1.1"