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,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Coupon do
5
- context "new record" do
6
- subject{Coupon.new}
7
-
8
- it { should respond_to(:coupon_code)}
9
- it { should respond_to(:redeemed_at)}
10
- end
11
-
12
- end
13
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Credit do
5
- context "new record" do
6
- subject{Credit.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,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Plan do
5
- context "new record" do
6
- subject{Plan.new}
7
-
8
- it { should respond_to(:plan_code)}
9
- it { should respond_to(:name)}
10
- it { should respond_to(:description)}
11
- it { should respond_to(:success_url)}
12
- it { should respond_to(:cancel_url)}
13
- it { should respond_to(:created_at)}
14
-
15
- end
16
-
17
- end
18
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Subscription do
5
- context "new record" do
6
- subject{Subscription.new}
7
-
8
- it { should respond_to(:plan_code)}
9
- it { should respond_to(:coupon_code)}
10
- it { should respond_to(:unit_amount_in_cents)}
11
- it { should respond_to(:quantity)}
12
- it { should respond_to(:trial_ends_at)}
13
-
14
- # TODO: embedded account
15
-
16
- # TODO: embedded billing_info
17
-
18
- # TODO: embedded credit_card
19
-
20
- # TODO: embedded addons list
21
-
22
- end
23
-
24
- end
25
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Transaction do
5
- context "new record" do
6
- subject{Transaction.new}
7
-
8
- it { should respond_to(:id)}
9
- it { should respond_to(:account_code)}
10
- it { should respond_to(:type)}
11
- it { should respond_to(:action)}
12
- it { should respond_to(:date)}
13
- it { should respond_to(:amount_in_cents)}
14
- it { should respond_to(:status)}
15
- it { should respond_to(:message)}
16
- it { should respond_to(:reference)}
17
- it { should respond_to(:ccv_result)}
18
- it { should respond_to(:avs_result)}
19
- it { should respond_to(:avs_result_street)}
20
- it { should respond_to(:avs_result_postal)}
21
- it { should respond_to(:test)}
22
- it { should respond_to(:voidable)}
23
- it { should respond_to(:refundable)}
24
-
25
- # TODO: embedded account
26
- # TODO: embedded billing_info
27
- # TODO: embedded credit_card
28
-
29
- end
30
-
31
- end
32
- end
@@ -1,152 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Transparent do
5
- before(:each) do
6
- Recurly.configure_from_yaml("#{File.dirname(__FILE__)}/../config/recurly.yml")
7
- end
8
-
9
- describe ".url" do
10
- it "should return the url for the configured Recurly site" do
11
- Transparent.url.should == "#{Recurly::Base.site}/transparent/#{Recurly.subdomain}/subscription"
12
- end
13
-
14
- it "should allow passing in the type of action" do
15
- Transparent.url(Action::CreateSubscription).should == "#{Recurly::Base.site}/transparent/#{Recurly.subdomain}/subscription"
16
- Transparent.url(Action::UpdateBilling).should == "#{Recurly::Base.site}/transparent/#{Recurly.subdomain}/billing_info"
17
- Transparent.url(Action::CreateTransaction).should == "#{Recurly::Base.site}/transparent/#{Recurly.subdomain}/transaction"
18
- end
19
- end
20
-
21
- describe ".encrypt_string" do
22
- it "should encrypt the data using the configured private key" do
23
- Recurly.configure do |config|
24
- config.private_key = '986bfa2bec61479ca560dbaaec345820'
25
- end
26
- result = Transparent.encrypt_string("d00d")
27
-
28
- # hashed manually
29
- result.should == "790a4038fb9047889a767baadf8edc3e07b6e66b"
30
-
31
- result2 = Transparent.encrypt_string("d00d2")
32
- result2.should_not eq(result)
33
-
34
- result3 = Transparent.encrypt_string("d00d")
35
- result3.should eq(result)
36
- end
37
- end
38
-
39
- describe "#encoded_data" do
40
- it "should return a data string for use within an input hidden field" do
41
-
42
- transparent = Transparent.new({
43
- :redirect_url => "http://example.com/",
44
- :account => { :account_code => 'howdy' },
45
- :value => "hello"
46
- })
47
-
48
- query_string = Transparent.query_string({
49
- :redirect_url => "http://example.com/",
50
- :account => { :account_code => 'howdy' },
51
- :value => "hello"
52
- })
53
-
54
- transparent.encoded_data.split("|").last.should eq(query_string)
55
- end
56
-
57
- it "should allow fixnums" do
58
- transparent = Transparent.new({
59
- :redirect_url => "http://example.com/",
60
- :account => { :account_code => '123' },
61
- :amount => 10
62
- })
63
-
64
- query_string = Transparent.query_string({
65
- :redirect_url => "http://example.com/",
66
- :account => { :account_code => '123' },
67
- :amount => 10
68
- })
69
-
70
- transparent.encoded_data.split("|").last.should == query_string
71
- end
72
-
73
- it "should allow nested fixnums" do
74
- transparent = Transparent.new({
75
- :redirect_url => "http://example.com/",
76
- :account => { :account_code => '123' },
77
- :transaction => {
78
- :amount => 10
79
- }
80
- })
81
-
82
- query_string = Transparent.query_string({
83
- :redirect_url => "http://example.com/",
84
- :account => { :account_code => '123' },
85
- :transaction => {
86
- :amount => 10
87
- }
88
- })
89
-
90
- transparent.encoded_data.split("|").last.should == query_string
91
- end
92
-
93
- it "should prepend the validation string" do
94
- transparent = Transparent.new({
95
- :redirect_url => "http://example.com/",
96
- :account => { :account_code => '123' },
97
- :transaction => {
98
- :amount => 10
99
- }
100
- })
101
-
102
- query_string = Transparent.query_string({
103
- :redirect_url => "http://example.com/",
104
- :account => { :account_code => '123' },
105
- :transaction => {
106
- :amount => 10
107
- }
108
- })
109
-
110
- validation_string = Transparent.encrypt_string(query_string)
111
-
112
- transparent.encoded_data.split("|").first.should == validation_string
113
- end
114
- end
115
-
116
- describe "#hidden_field" do
117
- it "should return a string of a HTML hidden input element" do
118
-
119
- transparent = Transparent.new({
120
- :redirect_url => "http://example.com/",
121
- :account => { :account_code => 'howdy' },
122
- :value => "hello"
123
- })
124
-
125
- transparent.hidden_field.class.should eq(String)
126
- end
127
-
128
- it "should return a string of a HTML hidden input element" do
129
- transparent = Transparent.new({
130
- :redirect_url => "http://example.com/",
131
- :account => { :account_code => '123' },
132
- :amount => 10
133
- })
134
-
135
- transparent.hidden_field.class.should eq(String)
136
- end
137
-
138
- it "should return a string of a HTML hidden input element" do
139
- transparent = Transparent.new({
140
- :redirect_url => "http://example.com/",
141
- :account => { :account_code => '123' },
142
- :transaction => {
143
- :amount => 10
144
- }
145
- })
146
-
147
- transparent.hidden_field.class.should eq(String)
148
- end
149
- end
150
-
151
- end
152
- end
@@ -1,82 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Recurly
4
- describe Verification do
5
- origin_time = 1312806801
6
- test_sig = 'fb5194a51aa97996cdb995a89064764c5c1bfd93-1312806801'
7
-
8
- before(:each) do
9
- Recurly.configure_from_yaml("#{File.dirname(__FILE__)}/../config/recurly.yml")
10
- Recurly::private_key = '0123456789abcdef0123456789abcdef' # Used for testing
11
- end
12
-
13
- it "should ignore empty arrays, hashes, strings, and nil" do
14
- Verification::digest_data([
15
- [], {}, '', nil
16
- ]).should == '[]'
17
- end
18
-
19
- it "should encode nested arrays and hashes" do
20
- Verification::digest_data(
21
- {:a => [1,2,3], :b => {:c => '123', :d => '456'}}
22
- ).should == '[a:[1,2,3],b:[c:123,d:456]]'
23
- end
24
-
25
- it "should alphabetize keys" do
26
- Verification::digest_data(
27
- {:a => 1, :c => 3, :b => 2}
28
- ).should == '[a:1,b:2,c:3]'
29
- end
30
-
31
- it "should treat hashes with numeric indexes as arrays" do
32
- Verification::digest_data(
33
- {'1' => 4, '2' => 5, '3' => 6}
34
- ).should == '[4,5,6]'
35
- end
36
-
37
- it "should escape syntax characters" do
38
- Verification::digest_data(
39
- { :syntaxchars => ' \\ [ ] : , '}
40
- ).should == '[syntaxchars: \\\\ \[ \] \: \, ]'
41
- end
42
-
43
- it "should generate proper signatures" do
44
- Time.stub!(:now).and_return(origin_time) # gen at origin time
45
- sig = Verification.generate_signature('update',{ :a => 'foo', :b => 'bar'})
46
- sig.should == test_sig
47
- end
48
-
49
- it "should validate proper signatures" do
50
- Time.stub!(:now).and_return(Time.at(origin_time+60)) # one minute passed
51
- lambda {
52
- good = Verification.verify_params!('update',
53
- { :a => 'foo', :b => 'bar', :signature => test_sig})
54
- }.should_not raise_error
55
- end
56
-
57
- it "should reject invalid signature" do
58
- Time.stub!(:now).and_return(Time.at(origin_time+60)) # one minute passed
59
- lambda {
60
- good = Verification.verify_params!('update',
61
- { :a => 'foo', :b => 'bar', :signature => 'badsig'})
62
- }.should raise_error(Recurly::ForgedQueryString)
63
- end
64
-
65
- it "should reject expired signature" do
66
- Time.stub!(:now).and_return(Time.at(origin_time+7200)) # two hours passed
67
- lambda {
68
- good = Verification.verify_params!('update',
69
- { :a => 'foo', :b => 'bar', :signature => test_sig})
70
- }.should raise_error(Recurly::ForgedQueryString)
71
- end
72
-
73
- it "should reject time traveling signatures from the future (with 1 hour grace period)" do
74
- Time.stub!(:now).and_return(Time.at(origin_time-7200)) # two hours earlier
75
- lambda {
76
- good = Verification.verify_params!('update',
77
- { :a => 'foo', :b => 'bar', :signature => test_sig})
78
- }.should raise_error(Recurly::ForgedQueryString)
79
- end
80
- end
81
-
82
- end