stripe 1.58.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/.travis.yml +1 -2
  4. data/Gemfile +11 -12
  5. data/History.txt +8 -0
  6. data/README.md +44 -31
  7. data/Rakefile +1 -1
  8. data/VERSION +1 -1
  9. data/lib/stripe.rb +4 -344
  10. data/lib/stripe/account.rb +4 -4
  11. data/lib/stripe/api_operations/create.rb +2 -2
  12. data/lib/stripe/api_operations/delete.rb +2 -2
  13. data/lib/stripe/api_operations/list.rb +2 -2
  14. data/lib/stripe/api_operations/request.rb +9 -3
  15. data/lib/stripe/api_operations/save.rb +4 -6
  16. data/lib/stripe/api_resource.rb +2 -2
  17. data/lib/stripe/bank_account.rb +2 -2
  18. data/lib/stripe/bitcoin_receiver.rb +1 -1
  19. data/lib/stripe/charge.rb +12 -12
  20. data/lib/stripe/customer.rb +6 -6
  21. data/lib/stripe/dispute.rb +2 -3
  22. data/lib/stripe/errors.rb +20 -10
  23. data/lib/stripe/invoice.rb +4 -4
  24. data/lib/stripe/list_object.rb +2 -2
  25. data/lib/stripe/order.rb +4 -4
  26. data/lib/stripe/reversal.rb +1 -1
  27. data/lib/stripe/source.rb +2 -2
  28. data/lib/stripe/stripe_client.rb +396 -0
  29. data/lib/stripe/stripe_response.rb +48 -0
  30. data/lib/stripe/transfer.rb +2 -2
  31. data/lib/stripe/util.rb +6 -6
  32. data/lib/stripe/version.rb +1 -1
  33. data/spec/fixtures.json +0 -0
  34. data/spec/fixtures.yaml +0 -0
  35. data/spec/spec.json +0 -0
  36. data/spec/spec.yaml +0 -0
  37. data/stripe.gemspec +1 -1
  38. data/test/api_fixtures.rb +29 -0
  39. data/test/api_stub_helpers.rb +125 -0
  40. data/test/stripe/account_test.rb +153 -247
  41. data/test/stripe/alipay_account_test.rb +10 -2
  42. data/test/stripe/api_operations_test.rb +3 -3
  43. data/test/stripe/api_resource_test.rb +139 -499
  44. data/test/stripe/apple_pay_domain_test.rb +22 -23
  45. data/test/stripe/application_fee_refund_test.rb +22 -31
  46. data/test/stripe/application_fee_test.rb +6 -17
  47. data/test/stripe/balance_test.rb +3 -3
  48. data/test/stripe/bank_account_test.rb +31 -11
  49. data/test/stripe/bitcoin_receiver_test.rb +51 -42
  50. data/test/stripe/bitcoin_transaction_test.rb +11 -19
  51. data/test/stripe/charge_test.rb +39 -126
  52. data/test/stripe/country_spec_test.rb +7 -30
  53. data/test/stripe/coupon_test.rb +33 -17
  54. data/test/stripe/customer_card_test.rb +25 -46
  55. data/test/stripe/customer_test.rb +86 -81
  56. data/test/stripe/dispute_test.rb +27 -38
  57. data/test/stripe/errors_test.rb +2 -2
  58. data/test/stripe/file_upload_test.rb +32 -24
  59. data/test/stripe/invoice_item_test.rb +46 -10
  60. data/test/stripe/invoice_test.rb +48 -48
  61. data/test/stripe/list_object_test.rb +22 -31
  62. data/test/stripe/order_return_test.rb +11 -15
  63. data/test/stripe/order_test.rb +38 -51
  64. data/test/stripe/plan_test.rb +39 -18
  65. data/test/stripe/product_test.rb +29 -33
  66. data/test/stripe/recipient_card_test.rb +23 -40
  67. data/test/stripe/recipient_test.rb +39 -10
  68. data/test/stripe/refund_test.rb +20 -45
  69. data/test/stripe/reversal_test.rb +27 -31
  70. data/test/stripe/sku_test.rb +36 -19
  71. data/test/stripe/source_test.rb +26 -66
  72. data/test/stripe/stripe_client_test.rb +428 -0
  73. data/test/stripe/stripe_object_test.rb +6 -2
  74. data/test/stripe/stripe_response_test.rb +46 -0
  75. data/test/stripe/subscription_item_test.rb +37 -59
  76. data/test/stripe/subscription_test.rb +40 -176
  77. data/test/stripe/three_d_secure_test.rb +13 -12
  78. data/test/stripe/transfer_test.rb +36 -19
  79. data/test/stripe_test.rb +3 -36
  80. data/test/test_data.rb +5 -931
  81. data/test/test_helper.rb +21 -25
  82. metadata +22 -17
  83. data/test/stripe/charge_refund_test.rb +0 -67
  84. data/test/stripe/metadata_test.rb +0 -129
@@ -1,45 +1,41 @@
1
+ require 'committee'
2
+ require 'sinatra'
1
3
  require 'stripe'
2
4
  require 'test/unit'
3
5
  require 'mocha/setup'
4
6
  require 'stringio'
5
7
  require 'shoulda/context'
6
- require File.expand_path('../test_data', __FILE__)
7
-
8
- # monkeypatch request methods
9
- module Stripe
10
- @mock_rest_client = nil
11
-
12
- def self.mock_rest_client=(mock_client)
13
- @mock_rest_client = mock_client
14
- end
8
+ require 'webmock/test_unit'
15
9
 
16
- class << self
17
- remove_method :execute_request
18
- end
10
+ PROJECT_ROOT = File.expand_path("../../", __FILE__)
19
11
 
20
- def self.execute_request(opts)
21
- get_params = (opts[:headers] || {})[:params]
22
- post_params = opts[:payload]
23
- case opts[:method]
24
- when :get then @mock_rest_client.get opts[:url], get_params, post_params
25
- when :post then @mock_rest_client.post opts[:url], get_params, post_params
26
- when :delete then @mock_rest_client.delete opts[:url], get_params, post_params
27
- end
28
- end
29
- end
12
+ require File.expand_path('../api_fixtures', __FILE__)
13
+ require File.expand_path('../api_stub_helpers', __FILE__)
14
+ require File.expand_path('../test_data', __FILE__)
30
15
 
31
16
  class Test::Unit::TestCase
17
+ include APIStubHelpers
32
18
  include Stripe::TestData
33
19
  include Mocha
34
20
 
21
+ # Fixtures are available in tests using something like:
22
+ #
23
+ # API_FIXTURES[:charge][:id]
24
+ #
25
+ API_FIXTURES = APIFixtures.new
26
+
35
27
  setup do
36
- @mock = mock
37
- Stripe.mock_rest_client = @mock
38
28
  Stripe.api_key = "foo"
29
+
30
+ # Stub the Stripe API with a default stub. Note that this method can be
31
+ # called again in test bodies in order to override responses on particular
32
+ # endpoints.
33
+ stub_api
34
+
35
+ stub_connect
39
36
  end
40
37
 
41
38
  teardown do
42
- Stripe.mock_rest_client = nil
43
39
  Stripe.api_key = nil
44
40
  end
45
41
  end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.58.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-19 00:00:00.000000000 Z
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rest-client
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.4'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '4.0'
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '1.4'
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '4.0'
26
+ version: '0'
33
27
  description: Stripe is the easiest way to accept payments online. See https://stripe.com
34
28
  for details.
35
29
  email: support@stripe.com
@@ -38,6 +32,7 @@ executables:
38
32
  extensions: []
39
33
  extra_rdoc_files: []
40
34
  files:
35
+ - ".gitattributes"
41
36
  - ".github/ISSUE_TEMPLATE.md"
42
37
  - ".gitignore"
43
38
  - ".travis.yml"
@@ -89,7 +84,9 @@ files:
89
84
  - lib/stripe/singleton_api_resource.rb
90
85
  - lib/stripe/sku.rb
91
86
  - lib/stripe/source.rb
87
+ - lib/stripe/stripe_client.rb
92
88
  - lib/stripe/stripe_object.rb
89
+ - lib/stripe/stripe_response.rb
93
90
  - lib/stripe/subscription.rb
94
91
  - lib/stripe/subscription_item.rb
95
92
  - lib/stripe/three_d_secure.rb
@@ -97,7 +94,13 @@ files:
97
94
  - lib/stripe/transfer.rb
98
95
  - lib/stripe/util.rb
99
96
  - lib/stripe/version.rb
97
+ - spec/fixtures.json
98
+ - spec/fixtures.yaml
99
+ - spec/spec.json
100
+ - spec/spec.yaml
100
101
  - stripe.gemspec
102
+ - test/api_fixtures.rb
103
+ - test/api_stub_helpers.rb
101
104
  - test/stripe/account_test.rb
102
105
  - test/stripe/alipay_account_test.rb
103
106
  - test/stripe/api_operations_test.rb
@@ -109,7 +112,6 @@ files:
109
112
  - test/stripe/bank_account_test.rb
110
113
  - test/stripe/bitcoin_receiver_test.rb
111
114
  - test/stripe/bitcoin_transaction_test.rb
112
- - test/stripe/charge_refund_test.rb
113
115
  - test/stripe/charge_test.rb
114
116
  - test/stripe/country_spec_test.rb
115
117
  - test/stripe/coupon_test.rb
@@ -121,7 +123,6 @@ files:
121
123
  - test/stripe/invoice_item_test.rb
122
124
  - test/stripe/invoice_test.rb
123
125
  - test/stripe/list_object_test.rb
124
- - test/stripe/metadata_test.rb
125
126
  - test/stripe/order_return_test.rb
126
127
  - test/stripe/order_test.rb
127
128
  - test/stripe/plan_test.rb
@@ -132,7 +133,9 @@ files:
132
133
  - test/stripe/reversal_test.rb
133
134
  - test/stripe/sku_test.rb
134
135
  - test/stripe/source_test.rb
136
+ - test/stripe/stripe_client_test.rb
135
137
  - test/stripe/stripe_object_test.rb
138
+ - test/stripe/stripe_response_test.rb
136
139
  - test/stripe/subscription_item_test.rb
137
140
  - test/stripe/subscription_test.rb
138
141
  - test/stripe/three_d_secure_test.rb
@@ -166,6 +169,8 @@ signing_key:
166
169
  specification_version: 4
167
170
  summary: Ruby bindings for the Stripe API
168
171
  test_files:
172
+ - test/api_fixtures.rb
173
+ - test/api_stub_helpers.rb
169
174
  - test/stripe/account_test.rb
170
175
  - test/stripe/alipay_account_test.rb
171
176
  - test/stripe/api_operations_test.rb
@@ -177,7 +182,6 @@ test_files:
177
182
  - test/stripe/bank_account_test.rb
178
183
  - test/stripe/bitcoin_receiver_test.rb
179
184
  - test/stripe/bitcoin_transaction_test.rb
180
- - test/stripe/charge_refund_test.rb
181
185
  - test/stripe/charge_test.rb
182
186
  - test/stripe/country_spec_test.rb
183
187
  - test/stripe/coupon_test.rb
@@ -189,7 +193,6 @@ test_files:
189
193
  - test/stripe/invoice_item_test.rb
190
194
  - test/stripe/invoice_test.rb
191
195
  - test/stripe/list_object_test.rb
192
- - test/stripe/metadata_test.rb
193
196
  - test/stripe/order_return_test.rb
194
197
  - test/stripe/order_test.rb
195
198
  - test/stripe/plan_test.rb
@@ -200,7 +203,9 @@ test_files:
200
203
  - test/stripe/reversal_test.rb
201
204
  - test/stripe/sku_test.rb
202
205
  - test/stripe/source_test.rb
206
+ - test/stripe/stripe_client_test.rb
203
207
  - test/stripe/stripe_object_test.rb
208
+ - test/stripe/stripe_response_test.rb
204
209
  - test/stripe/subscription_item_test.rb
205
210
  - test/stripe/subscription_test.rb
206
211
  - test/stripe/three_d_secure_test.rb
@@ -1,67 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class ChargeRefundTest < Test::Unit::TestCase
5
- should "refunds should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_charge))
7
-
8
- charge = Stripe::Charge.retrieve('test_charge')
9
-
10
- assert charge.refunds.first.kind_of?(Stripe::Refund)
11
- end
12
-
13
- should "refunds should be refreshable" do
14
- @mock.expects(:get).twice.returns(make_response(make_charge), make_response(make_refund(:id => 'refreshed_refund')))
15
-
16
- charge = Stripe::Charge.retrieve('test_charge')
17
- refund = charge.refunds.first
18
- refund.refresh
19
-
20
- assert_equal 'refreshed_refund', refund.id
21
- end
22
-
23
- should "refunds should be updateable" do
24
- @mock.expects(:get).
25
- with("#{Stripe.api_base}/v1/charges/test_charge", nil, nil).
26
- once.returns(make_response(make_charge))
27
- @mock.expects(:post).
28
- with("#{Stripe.api_base}/v1/refunds/ref_test_refund", nil, 'metadata[key]=value').
29
- once.returns(make_response(make_refund(:metadata => {'key' => 'value'})))
30
-
31
- charge = Stripe::Charge.retrieve('test_charge')
32
- refund = charge.refunds.first
33
-
34
- assert_equal nil, refund.metadata['key']
35
-
36
- refund.metadata['key'] = 'value'
37
- refund.save
38
-
39
- assert_equal 'value', refund.metadata['key']
40
- end
41
-
42
- should "create should return a new refund" do
43
- @mock.expects(:get).
44
- with("#{Stripe.api_base}/v1/charges/test_charge", nil, nil).
45
- once.returns(make_response(make_charge(:id => 'test_charge')))
46
- @mock.expects(:post).
47
- with("#{Stripe.api_base}/v1/charges/test_charge/refunds", nil, 'amount=20').
48
- once.returns(make_response(make_refund(:id => 'test_new_refund')))
49
-
50
- charge = Stripe::Charge.retrieve('test_charge')
51
- refund = charge.refunds.create(:amount => 20)
52
- assert_equal 'test_new_refund', refund.id
53
- end
54
-
55
- should "should refund a charge with given amount" do
56
- @mock.expects(:get).
57
- with("#{Stripe.api_base}/v1/charges/test_charge", nil, nil).
58
- twice.returns(make_response(make_charge(:id => 'test_charge')))
59
- @mock.expects(:post).
60
- with("#{Stripe.api_base}/v1/charges/test_charge/refunds", nil, 'amount=20').
61
- once.returns(make_response(make_refund(:amount => 20)))
62
-
63
- charge = Stripe::Charge.retrieve('test_charge')
64
- charge.refund(:amount => 20)
65
- end
66
- end
67
- end
@@ -1,129 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class MetadataTest < Test::Unit::TestCase
5
- setup do
6
- @metadata_supported = {
7
- :charge => {
8
- :new => Stripe::Charge.method(:new),
9
- :test => method(:make_charge),
10
- :url => "/v1/charges/#{make_charge()[:id]}"
11
- },
12
- :customer => {
13
- :new => Stripe::Customer.method(:new),
14
- :test => method(:make_customer),
15
- :url => "/v1/customers/#{make_customer()[:id]}"
16
- },
17
- :recipient => {
18
- :new => Stripe::Recipient.method(:new),
19
- :test => method(:make_recipient),
20
- :url => "/v1/recipients/#{make_recipient()[:id]}"
21
- },
22
- :transfer => {
23
- :new => Stripe::Transfer.method(:new),
24
- :test => method(:make_transfer),
25
- :url => "/v1/transfers/#{make_transfer()[:id]}"
26
- },
27
- :product => {
28
- :new => Stripe::Product.method(:new),
29
- :test => method(:make_product),
30
- :url => "/v1/products/#{make_product()[:id]}"
31
- },
32
- :order => {
33
- :new => Stripe::Order.method(:new),
34
- :test => method(:make_order),
35
- :url => "/v1/orders/#{make_order()[:id]}"
36
- },
37
- :sku => {
38
- :new => Stripe::SKU.method(:new),
39
- :test => method(:make_sku),
40
- :url => "/v1/skus/#{make_sku()[:id]}"
41
- },
42
- }
43
-
44
- @base_url = 'https://api.stripe.com'
45
- end
46
-
47
- should "not touch metadata" do
48
- update_actions = lambda {|obj| obj.description = 'test'}
49
- check_metadata({:metadata => {'initial' => 'true'}},
50
- 'description=test',
51
- update_actions)
52
- end
53
-
54
-
55
- should "update metadata as a whole" do
56
- update_actions = lambda {|obj| obj.metadata = {'uuid' => '6735'}}
57
- check_metadata({:metadata => {}},
58
- 'metadata[uuid]=6735',
59
- update_actions)
60
-
61
- if is_greater_than_ruby_1_9?
62
- check_metadata({:metadata => {:initial => 'true'}},
63
- 'metadata[initial]=&metadata[uuid]=6735',
64
- update_actions)
65
- end
66
- end
67
-
68
- should "update metadata keys individually" do
69
- update_actions = lambda {|obj| obj.metadata['txn_id'] = '134a13'}
70
- check_metadata({:metadata => {'initial' => 'true'}},
71
- 'metadata[txn_id]=134a13',
72
- update_actions)
73
- end
74
-
75
- should "clear metadata as a whole" do
76
- update_actions = lambda {|obj| obj.metadata = nil}
77
- check_metadata({:metadata => {'initial' => 'true'}},
78
- 'metadata=',
79
- update_actions)
80
- end
81
-
82
- should "clear metadata keys individually" do
83
- update_actions = lambda {|obj| obj.metadata['initial'] = nil}
84
- check_metadata({:metadata => {'initial' => 'true'}},
85
- 'metadata[initial]=',
86
- update_actions)
87
- end
88
-
89
- should "handle combinations of whole and partial metadata updates" do
90
- if is_greater_than_ruby_1_9?
91
- update_actions = lambda do |obj|
92
- obj.metadata = {'type' => 'summer'}
93
- obj.metadata['uuid'] = '6735'
94
- end
95
- params = {:metadata => {'type' => 'summer', 'uuid' => '6735'}}
96
- curl_args = Stripe::Util.encode_parameters(params)
97
- check_metadata({:metadata => {'type' => 'christmas'}},
98
- curl_args,
99
- update_actions)
100
- end
101
- end
102
-
103
- def check_metadata (initial_params, curl_args, metadata_update)
104
- @metadata_supported.each do |name, methods|
105
- neu = methods[:new]
106
- test = methods[:test]
107
- url = @base_url + methods[:url]
108
-
109
- initial_test_obj = test.call(initial_params)
110
- @mock.expects(:get).once.returns(make_response(initial_test_obj))
111
-
112
- final_test_obj = test.call()
113
- @mock.expects(:post).once.
114
- returns(make_response(final_test_obj)).
115
- with(url, nil, curl_args)
116
-
117
- obj = neu.call("test")
118
- obj.refresh()
119
- metadata_update.call(obj)
120
- obj.save
121
- end
122
- end
123
-
124
- def is_greater_than_ruby_1_9?
125
- version = RUBY_VERSION.dup # clone preserves frozen state
126
- Gem::Version.new(version) >= Gem::Version.new('1.9')
127
- end
128
- end
129
- end