stripe 3.8.2 → 5.45.0

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