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,398 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class StripeObjectTest < Test::Unit::TestCase
5
- should "implement #==" do
6
- obj1 = Stripe::StripeObject.construct_from({ :id => 1, :foo => "bar" })
7
- obj2 = Stripe::StripeObject.construct_from({ :id => 1, :foo => "bar" })
8
- obj3 = Stripe::StripeObject.construct_from({ :id => 1, :foo => "rab" })
9
-
10
- assert obj1 == obj2
11
- refute obj1 == obj3
12
- end
13
-
14
- should "implement #deleted?" do
15
- obj = Stripe::StripeObject.construct_from({})
16
- refute obj.deleted?
17
-
18
- obj = Stripe::StripeObject.construct_from({ :deleted => false })
19
- refute obj.deleted?
20
-
21
- obj = Stripe::StripeObject.construct_from({ :deleted => true })
22
- assert obj.deleted?
23
- end
24
-
25
- should "implement #respond_to" do
26
- obj = Stripe::StripeObject.construct_from({ :id => 1, :foo => 'bar' })
27
- assert obj.respond_to?(:id)
28
- assert obj.respond_to?(:foo)
29
- assert !obj.respond_to?(:baz)
30
- end
31
-
32
- should "marshal be insensitive to strings vs. symbols when constructin" do
33
- obj = Stripe::StripeObject.construct_from({ :id => 1, 'name' => 'Stripe' })
34
- assert_equal 1, obj[:id]
35
- assert_equal 'Stripe', obj[:name]
36
- end
37
-
38
- should "marshal a stripe object correctly" do
39
- obj = Stripe::StripeObject.construct_from(
40
- { :id => 1, :name => 'Stripe' },
41
- {
42
- :api_key => 'apikey',
43
- # StripeClient is not serializable and is expected to be removed
44
- # when marshalling StripeObjects
45
- :client => StripeClient.active_client,
46
- }
47
- )
48
- m = Marshal.load(Marshal.dump(obj))
49
- assert_equal 1, m.id
50
- assert_equal 'Stripe', m.name
51
- expected_hash = {:api_key => 'apikey'}
52
- assert_equal expected_hash, m.instance_variable_get('@opts')
53
- end
54
-
55
- should "recursively call to_hash on its values" do
56
- # deep nested hash (when contained in an array) or StripeObject
57
- nested_hash = { :id => 7, :foo => 'bar' }
58
- nested = Stripe::StripeObject.construct_from(nested_hash)
59
-
60
- obj = Stripe::StripeObject.construct_from({
61
- :id => 1,
62
- # simple hash that contains a StripeObject to help us test deep
63
- # recursion
64
- :nested => { :object => 'list', :data => [nested] },
65
- :list => [nested]
66
- })
67
-
68
- expected_hash = {
69
- :id => 1,
70
- :nested => { :object => 'list', :data => [nested_hash] },
71
- :list => [nested_hash]
72
- }
73
- assert_equal expected_hash, obj.to_hash
74
- end
75
-
76
- should "assign question mark accessors for booleans" do
77
- obj = Stripe::StripeObject.construct_from({ :id => 1, :bool => true, :not_bool => 'bar' })
78
- assert obj.respond_to?(:bool?)
79
- assert obj.bool?
80
- refute obj.respond_to?(:not_bool?)
81
- end
82
-
83
- should "assign question mark accessors for booleans added after initialization" do
84
- obj = Stripe::StripeObject.new
85
- obj.bool = true
86
- assert obj.respond_to?(:bool?)
87
- assert obj.bool?
88
- end
89
-
90
- should "mass assign values with #update_attributes" do
91
- obj = Stripe::StripeObject.construct_from({ :id => 1, :name => 'Stripe' })
92
- obj.update_attributes(:name => 'STRIPE')
93
- assert_equal "STRIPE", obj.name
94
-
95
- # unfortunately, we even assign unknown properties to duplicate the
96
- # behavior that we currently have via magic accessors with
97
- # method_missing
98
- obj.update_attributes(:unknown => 'foo')
99
- assert_equal "foo", obj.unknown
100
- end
101
-
102
- should "#update_attributes with a hash" do
103
- obj = Stripe::StripeObject.construct_from({})
104
- obj.update_attributes(:metadata => { :foo => 'bar' })
105
- assert_equal Stripe::StripeObject, obj.metadata.class
106
- end
107
-
108
- should "create accessors when #update_attributes is called" do
109
- obj = Stripe::StripeObject.construct_from({})
110
- assert_equal false, obj.send(:metaclass).method_defined?(:foo)
111
- obj.update_attributes(:foo => 'bar')
112
- assert_equal true, obj.send(:metaclass).method_defined?(:foo)
113
- end
114
-
115
- should "warn that #refresh_from is deprecated" do
116
- old_stderr = $stderr
117
- $stderr = StringIO.new
118
- begin
119
- obj = Stripe::StripeObject.construct_from({})
120
- obj.refresh_from({}, {})
121
- message = "NOTE: Stripe::StripeObject#refresh_from is " +
122
- "deprecated; use #update_attributes instead"
123
- assert_match Regexp.new(message), $stderr.string
124
- ensure
125
- $stderr = old_stderr
126
- end
127
- end
128
-
129
- should "pass opts down to children when initializing" do
130
- opts = { :custom => "opts" }
131
-
132
- # customer comes with a `sources` list that makes a convenient object to
133
- # perform tests on
134
- obj = Stripe::StripeObject.construct_from({
135
- sources: [
136
- {}
137
- ]
138
- }, opts)
139
-
140
- source = obj.sources.first
141
- # Pulling `@opts` as an instance variable here is not ideal, but it's
142
- # important enough argument that the test here is worth it. we should
143
- # consider exposing it publicly on a future pull (and possibly renaming
144
- # it to something more useful).
145
- assert_equal opts, source.instance_variable_get(:@opts)
146
- end
147
-
148
- should "#serialize_params on an empty object" do
149
- obj = Stripe::StripeObject.construct_from({})
150
- assert_equal({}, obj.serialize_params)
151
- end
152
-
153
- should "#serialize_params on a new object with a subobject" do
154
- obj = Stripe::StripeObject.new
155
- obj.metadata = { :foo => "bar" }
156
- assert_equal({ :metadata => { :foo => "bar" } },
157
- obj.serialize_params)
158
- end
159
-
160
- should "#serialize_params on a basic object" do
161
- obj = Stripe::StripeObject.construct_from({ :foo => nil })
162
- obj.update_attributes(:foo => "bar")
163
- assert_equal({ :foo => "bar" }, obj.serialize_params)
164
- end
165
-
166
- should "#serialize_params on a more complex object" do
167
- obj = Stripe::StripeObject.construct_from({
168
- :foo => Stripe::StripeObject.construct_from({
169
- :bar => nil,
170
- :baz => nil,
171
- }),
172
- })
173
- obj.foo.bar = "newbar"
174
- assert_equal({ :foo => { :bar => "newbar" } },
175
- obj.serialize_params)
176
- end
177
-
178
- should "#serialize_params on an array" do
179
- obj = Stripe::StripeObject.construct_from({
180
- :foo => nil,
181
- })
182
- obj.foo = ["new-value"]
183
- assert_equal({ :foo => ["new-value"] },
184
- obj.serialize_params)
185
- end
186
-
187
- should "#serialize_params on an array that shortens" do
188
- obj = Stripe::StripeObject.construct_from({
189
- :foo => ["0-index", "1-index", "2-index"],
190
- })
191
- obj.foo = ["new-value"]
192
- assert_equal({ :foo => ["new-value"] },
193
- obj.serialize_params)
194
- end
195
-
196
- should "#serialize_params on an array that lengthens" do
197
- obj = Stripe::StripeObject.construct_from({
198
- :foo => ["0-index", "1-index", "2-index"],
199
- })
200
- obj.foo = ["new-value"] * 4
201
- assert_equal({ :foo => ["new-value"] * 4 },
202
- obj.serialize_params)
203
- end
204
-
205
- should "#serialize_params on an array of hashes" do
206
- obj = Stripe::StripeObject.construct_from({
207
- :foo => nil,
208
- })
209
- obj.foo = [
210
- Stripe::StripeObject.construct_from({
211
- :bar => nil
212
- })
213
- ]
214
- obj.foo[0].bar = "baz"
215
- assert_equal({ :foo => [{ :bar => "baz" }] },
216
- obj.serialize_params)
217
- end
218
-
219
- should "#serialize_params doesn't include unchanged values" do
220
- obj = Stripe::StripeObject.construct_from({ :foo => nil })
221
- assert_equal({}, obj.serialize_params)
222
- end
223
-
224
- should "#serialize_params on an array that is unchanged" do
225
- obj = Stripe::StripeObject.construct_from({
226
- :foo => ["0-index", "1-index", "2-index"],
227
- })
228
- obj.foo = ["0-index", "1-index", "2-index"]
229
- assert_equal({}, obj.serialize_params)
230
- end
231
-
232
- should "#serialize_params with a StripeObject" do
233
- obj = Stripe::StripeObject.construct_from({})
234
-
235
- # using an #update_attributes will end up converting a Hash into a
236
- # StripeObject
237
- obj.metadata =
238
- Stripe::StripeObject.construct_from({ :foo => 'bar' })
239
-
240
- serialized = obj.serialize_params
241
- assert_equal({ :foo => "bar" }, serialized[:metadata])
242
- end
243
-
244
- should "#serialize_params with a StripeObject that's been replaced" do
245
- obj = Stripe::StripeObject.construct_from({
246
- :metadata => Stripe::StripeObject.construct_from({ :bar => 'foo' })
247
- })
248
-
249
- # Here we replace the object wholesale which means that the client must
250
- # be able to blank out the values that were in the old object, but which
251
- # are no longer present in the new one.
252
- obj.metadata =
253
- Stripe::StripeObject.construct_from({ :baz => 'foo' })
254
-
255
- serialized = obj.serialize_params
256
- assert_equal({ :bar => "", :baz => 'foo' }, serialized[:metadata])
257
- end
258
-
259
- should "#serialize_params with an array of StripeObjects" do
260
- obj = Stripe::StripeObject.construct_from({})
261
- obj.metadata = [
262
- Stripe::StripeObject.construct_from({ :foo => 'bar' })
263
- ]
264
-
265
- serialized = obj.serialize_params
266
- assert_equal([{ :foo => "bar" }], serialized[:metadata])
267
- end
268
-
269
- should "#serialize_params and embed an API resource that's been set and has an ID" do
270
- customer = Customer.construct_from({ :id => "cus_123" })
271
- obj = Stripe::StripeObject.construct_from({})
272
-
273
- # the key here is that the property is set explicitly (and therefore
274
- # marked as unsaved), which is why it gets included below
275
- obj.customer = customer
276
-
277
- serialized = obj.serialize_params
278
- assert_equal({ :customer => customer }, serialized)
279
- end
280
-
281
- should "#serialize_params and not include API resources that have not been set" do
282
- customer = Customer.construct_from({ :id => "cus_123" })
283
- obj = Stripe::StripeObject.construct_from({
284
- :customer => customer
285
- })
286
-
287
- serialized = obj.serialize_params
288
- assert_equal({}, serialized)
289
- end
290
-
291
- should "#serialize_params serializes API resources flagged with save_with_parent" do
292
- c = Customer.construct_from({})
293
- c.save_with_parent = true
294
-
295
- obj = Stripe::StripeObject.construct_from({
296
- :customer => c,
297
- })
298
-
299
- serialized = obj.serialize_params
300
- assert_equal({ :customer => {} }, serialized)
301
- end
302
-
303
- should "#serialize_params should raise an error on other embedded API resources" do
304
- # This customer doesn't have an ID and therefore the library doesn't know
305
- # what to do with it and throws an ArgumentError because it's probably
306
- # not what the user expected to happen.
307
- customer = Customer.construct_from({})
308
-
309
- obj = Stripe::StripeObject.construct_from({})
310
- obj.customer = customer
311
-
312
- e = assert_raises(ArgumentError) do
313
- obj.serialize_params
314
- end
315
- assert_equal "Cannot save property `customer` containing " \
316
- "an API resource. It doesn't appear to be persisted and is " \
317
- "not marked as `save_with_parent`.", e.message
318
- end
319
-
320
- should "#serialize_params takes a force option" do
321
- obj = Stripe::StripeObject.construct_from({
322
- :id => 'id',
323
- :metadata => Stripe::StripeObject.construct_from({ :foo => 'bar' })
324
- })
325
-
326
- serialized = obj.serialize_params(:force => true)
327
- assert_equal({ :id => 'id', :metadata => { :foo => 'bar' } }, serialized)
328
- end
329
-
330
- should "#dirty! forces an object and its subobjects to be saved" do
331
- obj = Stripe::StripeObject.construct_from({
332
- :id => 'id',
333
- :metadata => Stripe::StripeObject.construct_from({ :foo => 'bar' })
334
- })
335
-
336
- # note that `force` and `dirty!` are for different things, but are
337
- # functionally equivalent
338
- obj.dirty!
339
-
340
- serialized = obj.serialize_params
341
- assert_equal({ :id => 'id', :metadata => { :foo => 'bar' } }, serialized)
342
- end
343
-
344
- should "#to_s will call to_s for all embedded stripe objects" do
345
- obj = Stripe::StripeObject.construct_from({
346
- id: 'id',
347
- #embeded list object
348
- refunds: Stripe::ListObject.construct_from({ data: [
349
- #embedded object in list
350
- Stripe::StripeObject.construct_from({
351
- id: 'id',
352
- #embedded object in an object in a list object
353
- metadata: Stripe::StripeObject.construct_from({
354
- foo: 'bar',
355
- })
356
- })
357
- ]}),
358
- # embeded stripe object
359
- metadata: Stripe::StripeObject.construct_from({
360
- foo: 'bar',
361
- })
362
- })
363
- expected = JSON.pretty_generate({
364
- id: 'id',
365
- refunds: {
366
- data: [
367
- {id: 'id', metadata: {foo: 'bar'}}
368
- ]
369
- },
370
- metadata: { foo: 'bar' }
371
- })
372
-
373
- assert_equal(expected, obj.to_s)
374
- end
375
-
376
- should "warn that .serialize_params is deprecated" do
377
- old_stderr = $stderr
378
- $stderr = StringIO.new
379
- begin
380
- obj = Stripe::StripeObject.construct_from({})
381
- Stripe::StripeObject.serialize_params(obj)
382
- message = "NOTE: Stripe::StripeObject.serialize_params is " +
383
- "deprecated; use #serialize_params instead"
384
- assert_match Regexp.new(message), $stderr.string
385
- ensure
386
- $stderr = old_stderr
387
- end
388
- end
389
-
390
- should "error on setting a property to an empty string" do
391
- obj = Stripe::StripeObject.construct_from({ :foo => 'bar' })
392
- e = assert_raises ArgumentError do
393
- obj.foo = ""
394
- end
395
- assert_match %r{\(object\).foo = nil}, e.message
396
- end
397
- end
398
- end
@@ -1,46 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class StripeResponseTest < Test::Unit::TestCase
5
- context ".from_faraday_hash" do
6
- should "converts to StripeResponse" do
7
- body = '{"foo": "bar"}'
8
- headers = { "Request-Id" => "request-id" }
9
-
10
- http_resp = {
11
- body: body,
12
- headers: headers,
13
- status: 200,
14
- }
15
-
16
- resp = StripeResponse.from_faraday_hash(http_resp)
17
-
18
- assert_equal JSON.parse(body, symbolize_names: true), resp.data
19
- assert_equal body, resp.http_body
20
- assert_equal headers, resp.http_headers
21
- assert_equal 200, resp.http_status
22
- assert_equal "request-id", resp.request_id
23
- end
24
- end
25
-
26
- context ".from_faraday_response" do
27
- should "converts to StripeResponse" do
28
- body = '{"foo": "bar"}'
29
- headers = { "Request-Id" => "request-id" }
30
-
31
- env = Faraday::Env.from(
32
- :status => 200, :body => body,
33
- :response_headers => headers)
34
- http_resp = Faraday::Response.new(env)
35
-
36
- resp = StripeResponse.from_faraday_response(http_resp)
37
-
38
- assert_equal JSON.parse(body, symbolize_names: true), resp.data
39
- assert_equal body, resp.http_body
40
- assert_equal headers, resp.http_headers
41
- assert_equal 200, resp.http_status
42
- assert_equal "request-id", resp.request_id
43
- end
44
- end
45
- end
46
- end
@@ -1,52 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class SubscriptionItemTest < Test::Unit::TestCase
5
- should "be listable" do
6
- items = Stripe::SubscriptionItem.list(
7
- subscription: "sub_123",
8
- )
9
- assert_requested :get, "#{Stripe.api_base}/v1/subscription_items",
10
- query: { subscription: "sub_123" }
11
- assert items.data.kind_of?(Array)
12
- assert items.data[0].kind_of?(Stripe::SubscriptionItem)
13
- end
14
-
15
- should "be retrievable" do
16
- item = Stripe::SubscriptionItem.retrieve("si_123")
17
- assert_requested :get, "#{Stripe.api_base}/v1/subscription_items/si_123"
18
- assert item.kind_of?(Stripe::SubscriptionItem)
19
- end
20
-
21
- should "be creatable" do
22
- item = Stripe::SubscriptionItem.create(
23
- item: 'silver',
24
- plan: "sapphire-elite",
25
- quantity: 3,
26
- subscription: "sub_123"
27
- )
28
- assert_requested :post, "#{Stripe.api_base}/v1/subscription_items"
29
- assert item.kind_of?(Stripe::SubscriptionItem)
30
- end
31
-
32
- should "be saveable" do
33
- item = Stripe::SubscriptionItem.retrieve("si_123")
34
- item.quantity = 4
35
- item.save
36
- assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/#{item.id}"
37
- end
38
-
39
- should "be updateable" do
40
- item = Stripe::SubscriptionItem.update("si_123", metadata: {foo: 'bar'})
41
- assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/si_123"
42
- assert item.kind_of?(Stripe::SubscriptionItem)
43
- end
44
-
45
- should "be deletable" do
46
- item = Stripe::SubscriptionItem.retrieve("si_123")
47
- item = item.delete
48
- assert_requested :delete, "#{Stripe.api_base}/v1/subscription_items/#{item.id}"
49
- assert item.kind_of?(Stripe::SubscriptionItem)
50
- end
51
- end
52
- end
@@ -1,58 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class SubscriptionTest < Test::Unit::TestCase
5
- should "be listable" do
6
- subscriptions = Stripe::Subscription.list
7
- assert_requested :get, "#{Stripe.api_base}/v1/subscriptions"
8
- assert subscriptions.data.kind_of?(Array)
9
- assert subscriptions.data[0].kind_of?(Stripe::Subscription)
10
- end
11
-
12
- should "be retrievable" do
13
- subscription = Stripe::Subscription.retrieve("sub_123")
14
- assert_requested :get,
15
- "#{Stripe.api_base}/v1/subscriptions/sub_123"
16
- assert subscription.kind_of?(Stripe::Subscription)
17
- end
18
-
19
- should "be creatable" do
20
- subscription = Stripe::Subscription.create(
21
- customer: "cus_123"
22
- )
23
- assert_requested :post, "#{Stripe.api_base}/v1/subscriptions"
24
- assert subscription.kind_of?(Stripe::Subscription)
25
- end
26
-
27
- should "be saveable" do
28
- subscription = Stripe::Subscription.retrieve("sub_123")
29
- subscription.metadata['key'] = 'value'
30
- subscription.save
31
- assert_requested :post,
32
- "#{Stripe.api_base}/v1/subscriptions/#{subscription.id}"
33
- end
34
-
35
- should "be updateable" do
36
- subscription = Stripe::Subscription.update("sub_123", metadata: {foo: 'bar'})
37
- assert_requested :post,
38
- "#{Stripe.api_base}/v1/subscriptions/sub_123"
39
- assert subscription.kind_of?(Stripe::Subscription)
40
- end
41
-
42
- should "be deletable" do
43
- subscription = Stripe::Subscription.retrieve("sub_123")
44
- subscription = subscription.delete
45
- assert_requested :delete,
46
- "#{Stripe.api_base}/v1/subscriptions/#{subscription.id}"
47
- assert subscription.kind_of?(Stripe::Subscription)
48
- end
49
-
50
- context "#delete_discount" do
51
- should "be able to delete a subscriptions's discount" do
52
- subscription = Stripe::Subscription.retrieve("sub_123")
53
- subscription = subscription.delete_discount
54
- assert subscription.kind_of?(Stripe::Subscription)
55
- end
56
- end
57
- end
58
- end
@@ -1,21 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class ThreeDSecureTest < Test::Unit::TestCase
5
- should "be retrievable" do
6
- secure = Stripe::ThreeDSecure.retrieve("tdsrc_123")
7
- assert_requested :get, "#{Stripe.api_base}/v1/3d_secure/tdsrc_123"
8
- assert secure.kind_of?(Stripe::ThreeDSecure)
9
- end
10
-
11
- should "be creatable" do
12
- _ = Stripe::ThreeDSecure.create(
13
- card: "tok_123",
14
- amount: 1500,
15
- currency: "usd",
16
- return_url: "https://example.org/3d-secure-result"
17
- )
18
- assert_requested :post, "#{Stripe.api_base}/v1/3d_secure"
19
- end
20
- end
21
- end
@@ -1,41 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class TransferTest < Test::Unit::TestCase
5
- should "be listable" do
6
- transfers = Stripe::Transfer.list
7
- assert_requested :get, "#{Stripe.api_base}/v1/transfers"
8
- assert transfers.data.kind_of?(Array)
9
- assert transfers.data[0].kind_of?(Stripe::Transfer)
10
- end
11
-
12
- should "be retrievable" do
13
- transfer = Stripe::Transfer.retrieve("tr_123")
14
- assert_requested :get, "#{Stripe.api_base}/v1/transfers/tr_123"
15
- assert transfer.kind_of?(Stripe::Transfer)
16
- end
17
-
18
- should "be creatable" do
19
- transfer = Stripe::Transfer.create(
20
- amount: 100,
21
- currency: "USD",
22
- destination: "acct_123"
23
- )
24
- assert_requested :post, "#{Stripe.api_base}/v1/transfers"
25
- assert transfer.kind_of?(Stripe::Transfer)
26
- end
27
-
28
- should "be saveable" do
29
- transfer = Stripe::Transfer.retrieve("tr_123")
30
- transfer.metadata['key'] = 'value'
31
- transfer.save
32
- assert_requested :post, "#{Stripe.api_base}/v1/transfers/#{transfer.id}"
33
- end
34
-
35
- should "be updateable" do
36
- transfer = Stripe::Transfer.update("tr_123", metadata: {foo: 'bar'})
37
- assert_requested :post, "#{Stripe.api_base}/v1/transfers/tr_123"
38
- assert transfer.kind_of?(Stripe::Transfer)
39
- end
40
- end
41
- end