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