stripe 3.3.1 → 5.38.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +962 -0
  3. data/CODE_OF_CONDUCT.md +77 -0
  4. data/Gemfile +24 -22
  5. data/History.txt +1 -689
  6. data/README.md +202 -55
  7. data/Rakefile +18 -12
  8. data/VERSION +1 -1
  9. data/bin/stripe-console +5 -3
  10. data/lib/stripe/api_operations/create.rb +4 -2
  11. data/lib/stripe/api_operations/delete.rb +31 -3
  12. data/lib/stripe/api_operations/list.rb +4 -13
  13. data/lib/stripe/api_operations/nested_resource.rb +73 -0
  14. data/lib/stripe/api_operations/request.rb +84 -17
  15. data/lib/stripe/api_operations/save.rb +25 -13
  16. data/lib/stripe/api_resource.rb +70 -11
  17. data/lib/stripe/connection_manager.rb +179 -0
  18. data/lib/stripe/error_object.rb +93 -0
  19. data/lib/stripe/errors.rb +47 -19
  20. data/lib/stripe/instrumentation.rb +84 -0
  21. data/lib/stripe/list_object.rb +54 -22
  22. data/lib/stripe/multipart_encoder.rb +131 -0
  23. data/lib/stripe/oauth.rb +29 -20
  24. data/lib/stripe/object_types.rb +107 -0
  25. data/lib/stripe/{account.rb → resources/account.rb} +70 -36
  26. data/lib/stripe/resources/account_link.rb +10 -0
  27. data/lib/stripe/resources/alipay_account.rb +34 -0
  28. data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +5 -2
  29. data/lib/stripe/resources/application_fee.rb +14 -0
  30. data/lib/stripe/resources/application_fee_refund.rb +31 -0
  31. data/lib/stripe/resources/balance.rb +8 -0
  32. data/lib/stripe/resources/balance_transaction.rb +10 -0
  33. data/lib/stripe/resources/bank_account.rb +43 -0
  34. data/lib/stripe/resources/billing_portal/configuration.rb +14 -0
  35. data/lib/stripe/resources/billing_portal/session.rb +12 -0
  36. data/lib/stripe/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +7 -5
  37. data/lib/stripe/resources/bitcoin_transaction.rb +16 -0
  38. data/lib/stripe/resources/capability.rb +34 -0
  39. data/lib/stripe/resources/card.rb +38 -0
  40. data/lib/stripe/resources/charge.rb +23 -0
  41. data/lib/stripe/resources/checkout/session.rb +16 -0
  42. data/lib/stripe/resources/country_spec.rb +10 -0
  43. data/lib/stripe/{coupon.rb → resources/coupon.rb} +5 -2
  44. data/lib/stripe/resources/credit_note.rb +33 -0
  45. data/lib/stripe/resources/credit_note_line_item.rb +8 -0
  46. data/lib/stripe/resources/customer.rb +41 -0
  47. data/lib/stripe/resources/customer_balance_transaction.rb +31 -0
  48. data/lib/stripe/resources/discount.rb +7 -0
  49. data/lib/stripe/resources/dispute.rb +22 -0
  50. data/lib/stripe/resources/ephemeral_key.rb +20 -0
  51. data/lib/stripe/resources/event.rb +10 -0
  52. data/lib/stripe/resources/exchange_rate.rb +10 -0
  53. data/lib/stripe/resources/file.rb +36 -0
  54. data/lib/stripe/resources/file_link.rb +12 -0
  55. data/lib/stripe/resources/identity/verification_report.rb +12 -0
  56. data/lib/stripe/resources/identity/verification_session.rb +35 -0
  57. data/lib/stripe/resources/invoice.rb +74 -0
  58. data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +5 -2
  59. data/lib/stripe/resources/invoice_line_item.rb +8 -0
  60. data/lib/stripe/resources/issuing/authorization.rb +34 -0
  61. data/lib/stripe/resources/issuing/card.rb +25 -0
  62. data/lib/stripe/resources/issuing/card_details.rb +9 -0
  63. data/lib/stripe/resources/issuing/cardholder.rb +14 -0
  64. data/lib/stripe/resources/issuing/dispute.rb +25 -0
  65. data/lib/stripe/resources/issuing/transaction.rb +13 -0
  66. data/lib/stripe/resources/line_item.rb +8 -0
  67. data/lib/stripe/resources/login_link.rb +15 -0
  68. data/lib/stripe/resources/mandate.rb +8 -0
  69. data/lib/stripe/resources/order.rb +33 -0
  70. data/lib/stripe/resources/order_return.rb +10 -0
  71. data/lib/stripe/resources/payment_intent.rb +43 -0
  72. data/lib/stripe/resources/payment_method.rb +33 -0
  73. data/lib/stripe/resources/payout.rb +33 -0
  74. data/lib/stripe/resources/person.rb +32 -0
  75. data/lib/stripe/{plan.rb → resources/plan.rb} +4 -1
  76. data/lib/stripe/resources/price.rb +12 -0
  77. data/lib/stripe/{product.rb → resources/product.rb} +6 -3
  78. data/lib/stripe/resources/promotion_code.rb +12 -0
  79. data/lib/stripe/resources/quote.rb +105 -0
  80. data/lib/stripe/resources/radar/early_fraud_warning.rb +12 -0
  81. data/lib/stripe/resources/radar/value_list.rb +15 -0
  82. data/lib/stripe/resources/radar/value_list_item.rb +14 -0
  83. data/lib/stripe/resources/recipient.rb +14 -0
  84. data/lib/stripe/resources/recipient_transfer.rb +7 -0
  85. data/lib/stripe/{refund.rb → resources/refund.rb} +4 -1
  86. data/lib/stripe/resources/reporting/report_run.rb +13 -0
  87. data/lib/stripe/resources/reporting/report_type.rb +13 -0
  88. data/lib/stripe/resources/reversal.rb +30 -0
  89. data/lib/stripe/resources/review.rb +21 -0
  90. data/lib/stripe/resources/setup_attempt.rb +10 -0
  91. data/lib/stripe/resources/setup_intent.rb +33 -0
  92. data/lib/stripe/resources/sigma/scheduled_query_run.rb +16 -0
  93. data/lib/stripe/{sku.rb → resources/sku.rb} +6 -3
  94. data/lib/stripe/resources/source.rb +47 -0
  95. data/lib/stripe/resources/source_transaction.rb +7 -0
  96. data/lib/stripe/resources/subscription.rb +26 -0
  97. data/lib/stripe/resources/subscription_item.rb +26 -0
  98. data/lib/stripe/resources/subscription_schedule.rb +33 -0
  99. data/lib/stripe/resources/tax_code.rb +10 -0
  100. data/lib/stripe/resources/tax_id.rb +27 -0
  101. data/lib/stripe/resources/tax_rate.rb +12 -0
  102. data/lib/stripe/resources/terminal/connection_token.rb +12 -0
  103. data/lib/stripe/resources/terminal/location.rb +15 -0
  104. data/lib/stripe/resources/terminal/reader.rb +15 -0
  105. data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +4 -1
  106. data/lib/stripe/resources/token.rb +10 -0
  107. data/lib/stripe/resources/topup.rb +23 -0
  108. data/lib/stripe/resources/transfer.rb +27 -0
  109. data/lib/stripe/resources/usage_record.rb +8 -0
  110. data/lib/stripe/resources/usage_record_summary.rb +8 -0
  111. data/lib/stripe/{recipient.rb → resources/webhook_endpoint.rb} +6 -7
  112. data/lib/stripe/resources.rb +90 -0
  113. data/lib/stripe/singleton_api_resource.rb +10 -4
  114. data/lib/stripe/stripe_client.rb +798 -346
  115. data/lib/stripe/stripe_configuration.rb +194 -0
  116. data/lib/stripe/stripe_object.rb +271 -126
  117. data/lib/stripe/stripe_response.rb +89 -27
  118. data/lib/stripe/util.rb +134 -194
  119. data/lib/stripe/version.rb +3 -1
  120. data/lib/stripe/webhook.rb +57 -18
  121. data/lib/stripe.rb +74 -186
  122. data/stripe.gemspec +35 -16
  123. metadata +110 -165
  124. data/.gitattributes +0 -4
  125. data/.github/ISSUE_TEMPLATE.md +0 -5
  126. data/.gitignore +0 -5
  127. data/.travis.yml +0 -38
  128. data/lib/stripe/alipay_account.rb +0 -22
  129. data/lib/stripe/application_fee.rb +0 -22
  130. data/lib/stripe/application_fee_refund.rb +0 -20
  131. data/lib/stripe/balance.rb +0 -5
  132. data/lib/stripe/balance_transaction.rb +0 -11
  133. data/lib/stripe/bank_account.rb +0 -30
  134. data/lib/stripe/bitcoin_transaction.rb +0 -11
  135. data/lib/stripe/card.rb +0 -27
  136. data/lib/stripe/charge.rb +0 -82
  137. data/lib/stripe/country_spec.rb +0 -11
  138. data/lib/stripe/customer.rb +0 -79
  139. data/lib/stripe/dispute.rb +0 -17
  140. data/lib/stripe/ephemeral_key.rb +0 -18
  141. data/lib/stripe/event.rb +0 -7
  142. data/lib/stripe/file_upload.rb +0 -33
  143. data/lib/stripe/invoice.rb +0 -29
  144. data/lib/stripe/invoice_line_item.rb +0 -5
  145. data/lib/stripe/login_link.rb +0 -9
  146. data/lib/stripe/order.rb +0 -29
  147. data/lib/stripe/order_return.rb +0 -11
  148. data/lib/stripe/payout.rb +0 -18
  149. data/lib/stripe/recipient_transfer.rb +0 -6
  150. data/lib/stripe/reversal.rb +0 -20
  151. data/lib/stripe/source.rb +0 -23
  152. data/lib/stripe/subscription.rb +0 -33
  153. data/lib/stripe/subscription_item.rb +0 -14
  154. data/lib/stripe/token.rb +0 -7
  155. data/lib/stripe/transfer.rb +0 -18
  156. data/test/api_stub_helpers.rb +0 -0
  157. data/test/stripe/account_test.rb +0 -202
  158. data/test/stripe/alipay_account_test.rb +0 -17
  159. data/test/stripe/api_operations_test.rb +0 -31
  160. data/test/stripe/api_resource_test.rb +0 -558
  161. data/test/stripe/apple_pay_domain_test.rb +0 -31
  162. data/test/stripe/application_fee_refund_test.rb +0 -35
  163. data/test/stripe/application_fee_test.rb +0 -12
  164. data/test/stripe/balance_test.rb +0 -11
  165. data/test/stripe/bank_account_test.rb +0 -36
  166. data/test/stripe/bitcoin_receiver_test.rb +0 -67
  167. data/test/stripe/bitcoin_transaction_test.rb +0 -19
  168. data/test/stripe/charge_test.rb +0 -57
  169. data/test/stripe/country_spec_test.rb +0 -18
  170. data/test/stripe/coupon_test.rb +0 -42
  171. data/test/stripe/customer_card_test.rb +0 -46
  172. data/test/stripe/customer_test.rb +0 -114
  173. data/test/stripe/dispute_test.rb +0 -40
  174. data/test/stripe/ephemeral_key_test.rb +0 -84
  175. data/test/stripe/errors_test.rb +0 -18
  176. data/test/stripe/file_upload_test.rb +0 -66
  177. data/test/stripe/invoice_item_test.rb +0 -53
  178. data/test/stripe/invoice_line_item_test.rb +0 -6
  179. data/test/stripe/invoice_test.rb +0 -110
  180. data/test/stripe/list_object_test.rb +0 -170
  181. data/test/stripe/login_link_test.rb +0 -35
  182. data/test/stripe/oauth_test.rb +0 -85
  183. data/test/stripe/order_return_test.rb +0 -19
  184. data/test/stripe/order_test.rb +0 -57
  185. data/test/stripe/payout_test.rb +0 -48
  186. data/test/stripe/plan_test.rb +0 -50
  187. data/test/stripe/product_test.rb +0 -45
  188. data/test/stripe/recipient_card_test.rb +0 -44
  189. data/test/stripe/recipient_test.rb +0 -48
  190. data/test/stripe/refund_test.rb +0 -37
  191. data/test/stripe/reversal_test.rb +0 -41
  192. data/test/stripe/sku_test.rb +0 -48
  193. data/test/stripe/source_test.rb +0 -68
  194. data/test/stripe/stripe_client_test.rb +0 -750
  195. data/test/stripe/stripe_object_test.rb +0 -398
  196. data/test/stripe/stripe_response_test.rb +0 -46
  197. data/test/stripe/subscription_item_test.rb +0 -52
  198. data/test/stripe/subscription_test.rb +0 -58
  199. data/test/stripe/three_d_secure_test.rb +0 -21
  200. data/test/stripe/transfer_test.rb +0 -41
  201. data/test/stripe/util_test.rb +0 -414
  202. data/test/stripe/webhook_test.rb +0 -92
  203. data/test/stripe_test.rb +0 -59
  204. data/test/test_data.rb +0 -59
  205. data/test/test_helper.rb +0 -56
@@ -1,558 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path('../../test_helper', __FILE__)
3
-
4
- module Stripe
5
- class ApiResourceTest < Test::Unit::TestCase
6
- class NestedTestAPIResource < Stripe::APIResource
7
- save_nested_resource :external_account
8
- end
9
-
10
- context ".save_nested_resource" do
11
- should "can have a scalar set" do
12
- r = NestedTestAPIResource.new("test_resource")
13
- r.external_account = "tok_123"
14
- assert_equal "tok_123", r.external_account
15
- end
16
-
17
- should "set a flag if given an object source" do
18
- r = NestedTestAPIResource.new("test_resource")
19
- r.external_account = {
20
- :object => 'card'
21
- }
22
- assert_equal true, r.external_account.save_with_parent
23
- end
24
- end
25
-
26
- should "creating a new APIResource should not fetch over the network" do
27
- Stripe::Customer.new("someid")
28
- assert_not_requested :get, %r{#{Stripe.api_base}/.*}
29
- end
30
-
31
- should "creating a new APIResource from a hash should not fetch over the network" do
32
- Stripe::Customer.construct_from({
33
- :id => "somecustomer",
34
- :card => {:id => "somecard", :object => "card"},
35
- :object => "customer"
36
- })
37
- assert_not_requested :get, %r{#{Stripe.api_base}/.*}
38
- end
39
-
40
- should "setting an attribute should not cause a network request" do
41
- c = Stripe::Customer.new("cus_123");
42
- c.card = {:id => "somecard", :object => "card"}
43
- assert_not_requested :get, %r{#{Stripe.api_base}/.*}
44
- assert_not_requested :post, %r{#{Stripe.api_base}/.*}
45
- end
46
-
47
- should "accessing id should not issue a fetch" do
48
- c = Stripe::Customer.new("cus_123")
49
- c.id
50
- assert_not_requested :get, %r{#{Stripe.api_base}/.*}
51
- end
52
-
53
- should "not specifying api credentials should raise an exception" do
54
- Stripe.api_key = nil
55
- assert_raises Stripe::AuthenticationError do
56
- Stripe::Customer.new("cus_123").refresh
57
- end
58
- end
59
-
60
- should "using a nil api key should raise an exception" do
61
- assert_raises TypeError do
62
- Stripe::Customer.list({}, nil)
63
- end
64
- assert_raises TypeError do
65
- Stripe::Customer.list({}, { :api_key => nil })
66
- end
67
- end
68
-
69
- should "specifying api credentials containing whitespace should raise an exception" do
70
- Stripe.api_key = "key "
71
- assert_raises Stripe::AuthenticationError do
72
- Stripe::Customer.new("cus_123").refresh
73
- end
74
- end
75
-
76
- should "send expand on fetch properly" do
77
- stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_123").
78
- with(query: { "expand" => ["customer"] }).
79
- to_return(body: JSON.generate(charge_fixture))
80
-
81
- Stripe::Charge.retrieve({:id => 'ch_123', :expand => [:customer]})
82
- end
83
-
84
- should "preserve expand across refreshes" do
85
- stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_123").
86
- with(query: { "expand" => ["customer"] }).
87
- to_return(body: JSON.generate(charge_fixture))
88
-
89
- ch = Stripe::Charge.retrieve({:id => 'ch_123', :expand => :customer})
90
- ch.refresh
91
- end
92
-
93
- should "send expand when fetching through ListObject" do
94
- stub_request(:get, "#{Stripe.api_base}/v1/customers/cus_123").
95
- to_return(body: JSON.generate(customer_fixture))
96
-
97
- stub_request(:get, "#{Stripe.api_base}/v1/customers/cus_123/sources/cc_test_card").
98
- with(query: { "expand" => ["customer"] }).
99
- to_return(body: JSON.generate(customer_fixture))
100
-
101
- customer = Stripe::Customer.retrieve('cus_123')
102
- customer.sources.retrieve({:id => 'cc_test_card', :expand => :customer})
103
- end
104
-
105
- context "when specifying per-object credentials" do
106
- context "with no global API key set" do
107
- should "use the per-object credential when creating" do
108
- stub_request(:post, "#{Stripe.api_base}/v1/charges").
109
- with(headers: {"Authorization" => "Bearer sk_test_local"}).
110
- to_return(body: JSON.generate(charge_fixture))
111
-
112
- Stripe::Charge.create({:source => 'tok_visa'},
113
- 'sk_test_local')
114
- end
115
- end
116
-
117
- context "with a global API key set" do
118
- setup do
119
- Stripe.api_key = "global"
120
- end
121
-
122
- teardown do
123
- Stripe.api_key = nil
124
- end
125
-
126
- should "use the per-object credential when creating" do
127
- stub_request(:post, "#{Stripe.api_base}/v1/charges").
128
- with(headers: {"Authorization" => "Bearer sk_test_local"}).
129
- to_return(body: JSON.generate(charge_fixture))
130
-
131
- Stripe::Charge.create({:source => 'tok_visa'},
132
- 'sk_test_local')
133
- end
134
-
135
- should "use the per-object credential when retrieving and making other calls" do
136
- stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_123").
137
- with(headers: {"Authorization" => "Bearer sk_test_local"}).
138
- to_return(body: JSON.generate(charge_fixture))
139
- stub_request(:post, "#{Stripe.api_base}/v1/charges/ch_123/refunds").
140
- with(headers: {"Authorization" => "Bearer sk_test_local"}).
141
- to_return(body: "{}")
142
-
143
- ch = Stripe::Charge.retrieve('ch_123', 'sk_test_local')
144
- ch.refunds.create
145
- end
146
- end
147
- end
148
-
149
- context "with valid credentials" do
150
- should "urlencode values in GET params" do
151
- stub_request(:get, "#{Stripe.api_base}/v1/charges").
152
- with(query: { customer: "test customer" }).
153
- to_return(body: JSON.generate({
154
- data: [charge_fixture]
155
- }))
156
- charges = Stripe::Charge.list(:customer => 'test customer').data
157
- assert charges.kind_of? Array
158
- end
159
-
160
- should "construct URL properly with base query parameters" do
161
- stub_request(:get, "#{Stripe.api_base}/v1/charges").
162
- with(query: { customer: "cus_123" }).
163
- to_return(body: JSON.generate({
164
- data: [charge_fixture],
165
- url: "/v1/charges"
166
- }))
167
- charges = Stripe::Invoice.list(:customer => 'cus_123')
168
-
169
- stub_request(:get, "#{Stripe.api_base}/v1/charges").
170
- with(query: { customer: "cus_123", created: "123" }).
171
- to_return(body: JSON.generate({
172
- data: [charge_fixture],
173
- url: "/v1/charges"
174
- }))
175
- charges.list(:created => 123)
176
- end
177
-
178
- should "setting a nil value for a param should exclude that param from the request" do
179
- stub_request(:get, "#{Stripe.api_base}/v1/charges").
180
- with(query: { offset: 5, sad: false }).
181
- to_return(body: JSON.generate({ :count => 1, :data => [charge_fixture] }))
182
- Stripe::Charge.list(:count => nil, :offset => 5, :sad => false)
183
-
184
- stub_request(:post, "#{Stripe.api_base}/v1/charges").
185
- with(body: { 'amount' => '50', 'currency' => 'usd' }).
186
- to_return(body: JSON.generate({ :count => 1, :data => [charge_fixture] }))
187
- Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
188
- end
189
-
190
- should "not trigger a warning if a known opt, such as idempotency_key, is in opts" do
191
- stub_request(:post, "#{Stripe.api_base}/v1/charges").
192
- to_return(body: JSON.generate(charge_fixture))
193
- old_stderr = $stderr
194
- $stderr = StringIO.new
195
- begin
196
- Stripe::Charge.create({ :amount => 100, :currency => 'usd', :card => 'sc_token' }, { :idempotency_key => '12345' })
197
- assert $stderr.string.empty?
198
- ensure
199
- $stderr = old_stderr
200
- end
201
- end
202
-
203
- should "trigger a warning if a known opt, such as idempotency_key, is in params" do
204
- stub_request(:post, "#{Stripe.api_base}/v1/charges").
205
- to_return(body: JSON.generate(charge_fixture))
206
- old_stderr = $stderr
207
- $stderr = StringIO.new
208
- begin
209
- Stripe::Charge.create({ :amount => 100, :currency => 'usd', :card => 'sc_token', :idempotency_key => '12345' })
210
- assert_match Regexp.new('WARNING:'), $stderr.string
211
- ensure
212
- $stderr = old_stderr
213
- end
214
- end
215
-
216
- should "requesting with a unicode ID should result in a request" do
217
- stub_request(:get, "#{Stripe.api_base}/v1/customers/%E2%98%83").
218
- to_return(body: JSON.generate(make_missing_id_error), status: 404)
219
- c = Stripe::Customer.new("☃")
220
- assert_raises(Stripe::InvalidRequestError) { c.refresh }
221
- end
222
-
223
- should "requesting with no ID should result in an InvalidRequestError with no request" do
224
- c = Stripe::Customer.new
225
- assert_raises(Stripe::InvalidRequestError) { c.refresh }
226
- end
227
-
228
- should "making a GET request with parameters should have a query string and no body" do
229
- stub_request(:get, "#{Stripe.api_base}/v1/charges").
230
- with(query: { limit: 1 }).
231
- to_return(body: JSON.generate({ :data => [charge_fixture] }))
232
- Stripe::Charge.list({ :limit => 1 })
233
- end
234
-
235
- should "making a POST request with parameters should have a body and no query string" do
236
- stub_request(:post, "#{Stripe.api_base}/v1/charges").
237
- with(body: {'amount' => '100', 'currency' => 'usd', 'card' => 'sc_token'}).
238
- to_return(body: JSON.generate(charge_fixture))
239
- Stripe::Charge.create({ :amount => 100, :currency => 'usd', :card => 'sc_token' })
240
- end
241
-
242
- should "loading an object should issue a GET request" do
243
- stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_123").
244
- to_return(body: JSON.generate(charge_fixture))
245
- c = Stripe::Charge.new("ch_123")
246
- c.refresh
247
- end
248
-
249
- should "using array accessors should be the same as the method interface" do
250
- stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_123").
251
- to_return(body: JSON.generate(charge_fixture))
252
- c = Stripe::Charge.new("cus_123")
253
- c.refresh
254
- assert_equal c.created, c[:created]
255
- assert_equal c.created, c['created']
256
- c['created'] = 12345
257
- assert_equal c.created, 12345
258
- end
259
-
260
- should "accessing a property other than id or parent on an unfetched object should fetch it" do
261
- stub_request(:get, "#{Stripe.api_base}/v1/charges").
262
- with(query: { customer: "cus_123" }).
263
- to_return(body: JSON.generate(customer_fixture))
264
- c = Stripe::Customer.new("cus_123")
265
- c.charges
266
- end
267
-
268
- should "updating an object should issue a POST request with only the changed properties" do
269
- stub_request(:post, "#{Stripe.api_base}/v1/customers/cus_123").
270
- with(body: { 'description' => 'another_mn' }).
271
- to_return(body: JSON.generate(customer_fixture))
272
- c = Stripe::Customer.construct_from(customer_fixture)
273
- c.description = "another_mn"
274
- c.save
275
- end
276
-
277
- should "updating should merge in returned properties" do
278
- stub_request(:post, "#{Stripe.api_base}/v1/customers/cus_123").
279
- with(body: { 'description' => 'another_mn' }).
280
- to_return(body: JSON.generate(customer_fixture))
281
- c = Stripe::Customer.new("cus_123")
282
- c.description = "another_mn"
283
- c.save
284
- assert_equal false, c.livemode
285
- end
286
-
287
- should "updating should fail if api_key is overwritten with nil" do
288
- c = Stripe::Customer.new
289
- assert_raises TypeError do
290
- c.save({}, { :api_key => nil })
291
- end
292
- end
293
-
294
- should "updating should use the supplied api_key" do
295
- stub_request(:post, "#{Stripe.api_base}/v1/customers").
296
- with(headers: {"Authorization" => "Bearer sk_test_local"}).
297
- to_return(body: JSON.generate(customer_fixture))
298
- c = Stripe::Customer.new
299
- c.save({}, { :api_key => 'sk_test_local' })
300
- assert_equal false, c.livemode
301
- end
302
-
303
- should "deleting should send no props and result in an object that has no props other deleted" do
304
- stub_request(:delete, "#{Stripe.api_base}/v1/customers/cus_123").
305
- to_return(body: JSON.generate({ "id" => "cus_123", "deleted" => true }))
306
- c = Stripe::Customer.construct_from(customer_fixture)
307
- c.delete
308
- end
309
-
310
- should "loading all of an APIResource should return an array of recursively instantiated objects" do
311
- stub_request(:get, "#{Stripe.api_base}/v1/charges").
312
- to_return(body: JSON.generate({
313
- data: [charge_fixture]
314
- }))
315
- charges = Stripe::Charge.list.data
316
- assert charges.kind_of? Array
317
- assert charges[0].kind_of? Stripe::Charge
318
- assert charges[0].source.kind_of?(Stripe::StripeObject)
319
- end
320
-
321
- should "passing in a stripe_account header should pass it through on call" do
322
- stub_request(:get, "#{Stripe.api_base}/v1/customers/cus_123").
323
- with(headers: {"Stripe-Account" => "acct_123"}).
324
- to_return(body: JSON.generate(customer_fixture))
325
- Stripe::Customer.retrieve("cus_123", {:stripe_account => 'acct_123'})
326
- end
327
-
328
- should "passing in a stripe_account header should pass it through on save" do
329
- stub_request(:get, "#{Stripe.api_base}/v1/customers/cus_123").
330
- with(headers: {"Stripe-Account" => "acct_123"}).
331
- to_return(body: JSON.generate(customer_fixture))
332
- c = Stripe::Customer.retrieve("cus_123", {:stripe_account => 'acct_123'})
333
-
334
- stub_request(:post, "#{Stripe.api_base}/v1/customers/cus_123").
335
- with(headers: {"Stripe-Account" => "acct_123"}).
336
- to_return(body: JSON.generate(customer_fixture))
337
- c.description = 'FOO'
338
- c.save
339
- end
340
-
341
- should 'add key to nested objects' do
342
- acct = Stripe::Account.construct_from({
343
- :id => 'myid',
344
- :legal_entity => {
345
- :size => 'l',
346
- :score => 4,
347
- :height => 10
348
- }
349
- })
350
-
351
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid").
352
- with(body: { legal_entity: { first_name: "Bob" } }).
353
- to_return(body: JSON.generate({ "id" => "myid" }))
354
-
355
- acct.legal_entity.first_name = 'Bob'
356
- acct.save
357
- end
358
-
359
- should 'save nothing if nothing changes' do
360
- acct = Stripe::Account.construct_from({
361
- :id => 'acct_id',
362
- :metadata => {
363
- :key => 'value'
364
- }
365
- })
366
-
367
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_id").
368
- with(body: {}).
369
- to_return(body: JSON.generate({ "id" => "acct_id" }))
370
-
371
- acct.save
372
- end
373
-
374
- should 'not save nested API resources' do
375
- ch = Stripe::Charge.construct_from({
376
- :id => 'ch_id',
377
- :customer => {
378
- :object => 'customer',
379
- :id => 'customer_id'
380
- }
381
- })
382
-
383
- stub_request(:post, "#{Stripe.api_base}/v1/charges/ch_id").
384
- with(body: {}).
385
- to_return(body: JSON.generate({ "id" => "ch_id" }))
386
-
387
- ch.customer.description = 'Bob'
388
- ch.save
389
- end
390
-
391
- should 'correctly handle replaced nested objects' do
392
- acct = Stripe::Account.construct_from({
393
- :id => 'myid',
394
- :legal_entity => {
395
- :last_name => 'Smith',
396
- :address => {
397
- :line1 => "test",
398
- :city => "San Francisco"
399
- }
400
- }
401
- })
402
-
403
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid").
404
- with(body: { legal_entity: { address: { line1: "Test2", city: "" } } }).
405
- to_return(body: JSON.generate({ "id" => "my_id" }))
406
-
407
- acct.legal_entity.address = {:line1 => 'Test2'}
408
- acct.save
409
- end
410
-
411
- should 'correctly handle array setting' do
412
- acct = Stripe::Account.construct_from({
413
- :id => 'myid',
414
- :legal_entity => {}
415
- })
416
-
417
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid").
418
- with(body: { legal_entity: { additional_owners: [{ first_name: "Bob" }] } }).
419
- to_return(body: JSON.generate({ "id" => "myid" }))
420
-
421
- acct.legal_entity.additional_owners = [{:first_name => 'Bob'}]
422
- acct.save
423
- end
424
-
425
- should 'correctly handle array insertion' do
426
- acct = Stripe::Account.construct_from({
427
- :id => 'myid',
428
- :legal_entity => {
429
- :additional_owners => []
430
- }
431
- })
432
-
433
- # Note that this isn't a perfect check because we're using webmock's
434
- # data decoding, which isn't aware of the Stripe array encoding that we
435
- # use here.
436
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid").
437
- with(body: { legal_entity: { additional_owners: [{ first_name: "Bob" }] } }).
438
- to_return(body: JSON.generate({ "id" => "myid" }))
439
-
440
- acct.legal_entity.additional_owners << {:first_name => 'Bob'}
441
- acct.save
442
- end
443
-
444
- should 'correctly handle array updates' do
445
- acct = Stripe::Account.construct_from({
446
- :id => 'myid',
447
- :legal_entity => {
448
- :additional_owners => [{:first_name => 'Bob'}, {:first_name => 'Jane'}]
449
- }
450
- })
451
-
452
- # Note that this isn't a perfect check because we're using webmock's
453
- # data decoding, which isn't aware of the Stripe array encoding that we
454
- # use here.
455
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid").
456
- with(body: { legal_entity: { additional_owners: [{ first_name: "Janet" }] } }).
457
- to_return(body: JSON.generate({ "id" => "myid" }))
458
-
459
- acct.legal_entity.additional_owners[1].first_name = 'Janet'
460
- acct.save
461
- end
462
-
463
- should 'correctly handle array noops' do
464
- acct = Stripe::Account.construct_from({
465
- :id => 'myid',
466
- :legal_entity => {
467
- :additional_owners => [{:first_name => 'Bob'}]
468
- },
469
- :currencies_supported => ['usd', 'cad']
470
- })
471
-
472
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid").
473
- with(body: {}).
474
- to_return(body: JSON.generate({ "id" => "myid" }))
475
-
476
- acct.save
477
- end
478
-
479
- should 'correctly handle hash noops' do
480
- acct = Stripe::Account.construct_from({
481
- :id => 'myid',
482
- :legal_entity => {
483
- :address => {:line1 => '1 Two Three'}
484
- }
485
- })
486
-
487
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid").
488
- with(body: {}).
489
- to_return(body: JSON.generate({ "id" => "myid" }))
490
-
491
- acct.save
492
- end
493
-
494
- should 'should create a new resource when an object without an id is saved' do
495
- account = Stripe::Account.construct_from({
496
- :id => nil,
497
- :display_name => nil,
498
- })
499
-
500
- stub_request(:post, "#{Stripe.api_base}/v1/accounts").
501
- with(body: { display_name: "stripe" }).
502
- to_return(body: JSON.generate({ "id" => "acct_123" }))
503
-
504
- account.display_name = 'stripe'
505
- account.save
506
- end
507
-
508
- should 'set attributes as part of save' do
509
- account = Stripe::Account.construct_from({
510
- :id => nil,
511
- :display_name => nil,
512
- })
513
-
514
- stub_request(:post, "#{Stripe.api_base}/v1/accounts").
515
- with(body: { display_name: "stripe", metadata: { key: "value" } }).
516
- to_return(body: JSON.generate({ "id" => "acct_123" }))
517
-
518
- account.save(:display_name => 'stripe', :metadata => {:key => 'value' })
519
- end
520
- end
521
-
522
- @@fixtures = {}
523
- setup do
524
- if @@fixtures.empty?
525
- set_fixture(:charge) do
526
- Charge.retrieve("ch_123")
527
- end
528
- set_fixture(:customer) do
529
- Customer.retrieve("cus_123")
530
- end
531
- end
532
- end
533
-
534
- private
535
-
536
- def charge_fixture
537
- @@fixtures[:charge]
538
- end
539
-
540
- def customer_fixture
541
- @@fixtures[:customer]
542
- end
543
-
544
- def get_fixture(key)
545
- @@fixtures.fetch(key)
546
- end
547
-
548
- # Expects to retrieve a fixture from stripe-mock (an API call should be
549
- # included in the block to yield to) and does very simple memoization.
550
- def set_fixture(key)
551
- return @@fixtures[key] if @@fixtures.key?(key)
552
-
553
- obj = yield
554
- @@fixtures[key] = obj.instance_variable_get(:@values).freeze
555
- @@fixtures[key]
556
- end
557
- end
558
- end
@@ -1,31 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class ApplePayDomainTest < Test::Unit::TestCase
5
- should "be listable" do
6
- domains = Stripe::ApplePayDomain.list
7
- assert_requested :get, "#{Stripe.api_base}/v1/apple_pay/domains"
8
- assert domains.data.kind_of?(Array)
9
- assert domains.data[0].kind_of?(Stripe::ApplePayDomain)
10
- end
11
-
12
- should "be retrievable" do
13
- domain = Stripe::ApplePayDomain.retrieve("apwc_123")
14
- assert_requested :get, "#{Stripe.api_base}/v1/apple_pay/domains/apwc_123"
15
- assert domain.kind_of?(Stripe::ApplePayDomain)
16
- end
17
-
18
- should "be creatable" do
19
- domain = Stripe::ApplePayDomain.create(:domain_name => "example.com")
20
- assert_requested :post, "#{Stripe.api_base}/v1/apple_pay/domains"
21
- assert domain.kind_of?(Stripe::ApplePayDomain)
22
- end
23
-
24
- should "be deletable" do
25
- domain = Stripe::ApplePayDomain.retrieve("apwc_123")
26
- domain = domain.delete
27
- assert_requested :delete, "#{Stripe.api_base}/v1/apple_pay/domains/#{domain.id}"
28
- assert domain.kind_of?(Stripe::ApplePayDomain)
29
- end
30
- end
31
- end
@@ -1,35 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class ApplicationFeeRefundTest < Test::Unit::TestCase
5
- setup do
6
- @fee = Stripe::ApplicationFee.retrieve("fee_123")
7
- end
8
-
9
- should "be listable" do
10
- refunds = @fee.refunds
11
-
12
- # notably this *doesn't* make an API call
13
- assert_not_requested :get,
14
- "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds"
15
-
16
- assert refunds.data.kind_of?(Array)
17
- assert refunds.first.kind_of?(Stripe::ApplicationFeeRefund)
18
- end
19
-
20
- should "be creatable" do
21
- refund = @fee.refunds.create
22
- assert_requested :post,
23
- "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds"
24
- assert refund.kind_of?(Stripe::ApplicationFeeRefund)
25
- end
26
-
27
- should "be saveable" do
28
- refund = @fee.refunds.first
29
- refund.metadata['key'] = 'value'
30
- refund.save
31
- assert_requested :post,
32
- "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds/#{refund.id}"
33
- end
34
- end
35
- end
@@ -1,12 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class ApplicationFeeTest < Test::Unit::TestCase
5
- should "be listable" do
6
- fees = Stripe::ApplicationFee.list
7
- assert_requested :get, "#{Stripe.api_base}/v1/application_fees"
8
- assert fees.data.kind_of?(Array)
9
- assert fees.data[0].kind_of?(Stripe::ApplicationFee)
10
- end
11
- end
12
- end
@@ -1,11 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class BalanceTest < Test::Unit::TestCase
5
- should "be retrievable" do
6
- balance = Stripe::Balance.retrieve
7
- assert_requested :get, "#{Stripe.api_base}/v1/balance"
8
- assert balance.kind_of?(Stripe::Balance)
9
- end
10
- end
11
- end
@@ -1,36 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class BankAccountTest < Test::Unit::TestCase
5
- context "#resource_url" do
6
- should "return an external account URL" do
7
- bank_account = Stripe::BankAccount.construct_from(
8
- account: "acct_123",
9
- id: "ba_123"
10
- )
11
- assert_equal "/v1/accounts/acct_123/external_accounts/ba_123",
12
- bank_account.resource_url
13
- end
14
-
15
- should "return a customer URL" do
16
- bank_account = Stripe::BankAccount.construct_from(
17
- customer: "cus_123",
18
- id: "ba_123",
19
- )
20
- assert_equal "/v1/customers/cus_123/sources/ba_123",
21
- bank_account.resource_url
22
- end
23
- end
24
-
25
- context "#verify" do
26
- should 'verify the account' do
27
- bank_account = Stripe::BankAccount.construct_from({
28
- customer: "cus_123",
29
- id: "ba_123",
30
- })
31
- bank_account = bank_account.verify(amounts: [1,2])
32
- assert bank_account.kind_of?(Stripe::BankAccount)
33
- end
34
- end
35
- end
36
- end