stripe 4.21.3 → 5.52.0

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