stripe 3.2.0 → 5.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +10 -0
  3. data/.gitignore +3 -0
  4. data/.rubocop.yml +80 -0
  5. data/.rubocop_todo.yml +33 -0
  6. data/.travis.yml +9 -7
  7. data/.vscode/extensions.json +7 -0
  8. data/.vscode/settings.json +8 -0
  9. data/CHANGELOG.md +876 -0
  10. data/CODE_OF_CONDUCT.md +77 -0
  11. data/Gemfile +21 -21
  12. data/History.txt +1 -678
  13. data/README.md +195 -53
  14. data/Rakefile +18 -12
  15. data/VERSION +1 -1
  16. data/bin/stripe-console +5 -3
  17. data/lib/stripe/api_operations/create.rb +3 -1
  18. data/lib/stripe/api_operations/delete.rb +26 -2
  19. data/lib/stripe/api_operations/list.rb +3 -12
  20. data/lib/stripe/api_operations/nested_resource.rb +72 -0
  21. data/lib/stripe/api_operations/request.rb +33 -15
  22. data/lib/stripe/api_operations/save.rb +18 -9
  23. data/lib/stripe/api_resource.rb +60 -10
  24. data/lib/stripe/connection_manager.rb +159 -0
  25. data/lib/stripe/error_object.rb +94 -0
  26. data/lib/stripe/errors.rb +39 -19
  27. data/lib/stripe/instrumentation.rb +82 -0
  28. data/lib/stripe/list_object.rb +54 -22
  29. data/lib/stripe/multipart_encoder.rb +131 -0
  30. data/lib/stripe/oauth.rb +22 -14
  31. data/lib/stripe/object_types.rb +96 -0
  32. data/lib/stripe/{account.rb → resources/account.rb} +72 -34
  33. data/lib/stripe/resources/account_link.rb +9 -0
  34. data/lib/stripe/resources/alipay_account.rb +34 -0
  35. data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +4 -2
  36. data/lib/stripe/resources/application_fee.rb +13 -0
  37. data/lib/stripe/resources/application_fee_refund.rb +30 -0
  38. data/lib/stripe/{balance.rb → resources/balance.rb} +3 -1
  39. data/lib/stripe/{balance_transaction.rb → resources/balance_transaction.rb} +3 -5
  40. data/lib/stripe/resources/bank_account.rb +42 -0
  41. data/lib/stripe/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +6 -5
  42. data/lib/stripe/resources/bitcoin_transaction.rb +15 -0
  43. data/lib/stripe/resources/capability.rb +33 -0
  44. data/lib/stripe/resources/card.rb +37 -0
  45. data/lib/stripe/resources/charge.rb +22 -0
  46. data/lib/stripe/resources/checkout/session.rb +12 -0
  47. data/lib/stripe/{country_spec.rb → resources/country_spec.rb} +3 -5
  48. data/lib/stripe/{coupon.rb → resources/coupon.rb} +4 -2
  49. data/lib/stripe/resources/credit_note.rb +32 -0
  50. data/lib/stripe/resources/credit_note_line_item.rb +7 -0
  51. data/lib/stripe/resources/customer.rb +35 -0
  52. data/lib/stripe/resources/customer_balance_transaction.rb +30 -0
  53. data/lib/stripe/resources/discount.rb +7 -0
  54. data/lib/stripe/resources/dispute.rb +21 -0
  55. data/lib/stripe/resources/ephemeral_key.rb +19 -0
  56. data/lib/stripe/{event.rb → resources/event.rb} +3 -1
  57. data/lib/stripe/resources/exchange_rate.rb +9 -0
  58. data/lib/stripe/resources/file.rb +34 -0
  59. data/lib/stripe/resources/file_link.rb +11 -0
  60. data/lib/stripe/resources/invoice.rb +73 -0
  61. data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +4 -2
  62. data/lib/stripe/{invoice_line_item.rb → resources/invoice_line_item.rb} +3 -1
  63. data/lib/stripe/resources/issuing/authorization.rb +33 -0
  64. data/lib/stripe/resources/issuing/card.rb +24 -0
  65. data/lib/stripe/resources/issuing/card_details.rb +9 -0
  66. data/lib/stripe/resources/issuing/cardholder.rb +13 -0
  67. data/lib/stripe/resources/issuing/dispute.rb +13 -0
  68. data/lib/stripe/resources/issuing/transaction.rb +12 -0
  69. data/lib/stripe/resources/login_link.rb +14 -0
  70. data/lib/stripe/resources/mandate.rb +7 -0
  71. data/lib/stripe/resources/order.rb +32 -0
  72. data/lib/stripe/{order_return.rb → resources/order_return.rb} +3 -5
  73. data/lib/stripe/resources/payment_intent.rb +42 -0
  74. data/lib/stripe/resources/payment_method.rb +32 -0
  75. data/lib/stripe/resources/payout.rb +22 -0
  76. data/lib/stripe/resources/person.rb +31 -0
  77. data/lib/stripe/{plan.rb → resources/plan.rb} +3 -1
  78. data/lib/stripe/{product.rb → resources/product.rb} +5 -3
  79. data/lib/stripe/resources/radar/early_fraud_warning.rb +11 -0
  80. data/lib/stripe/resources/radar/value_list.rb +14 -0
  81. data/lib/stripe/resources/radar/value_list_item.rb +13 -0
  82. data/lib/stripe/{recipient.rb → resources/recipient.rb} +5 -6
  83. data/lib/stripe/resources/recipient_transfer.rb +7 -0
  84. data/lib/stripe/{refund.rb → resources/refund.rb} +3 -1
  85. data/lib/stripe/resources/reporting/report_run.rb +12 -0
  86. data/lib/stripe/resources/reporting/report_type.rb +12 -0
  87. data/lib/stripe/resources/reversal.rb +29 -0
  88. data/lib/stripe/resources/review.rb +20 -0
  89. data/lib/stripe/resources/setup_intent.rb +32 -0
  90. data/lib/stripe/resources/sigma/scheduled_query_run.rb +15 -0
  91. data/lib/stripe/{sku.rb → resources/sku.rb} +5 -3
  92. data/lib/stripe/resources/source.rb +46 -0
  93. data/lib/stripe/resources/source_transaction.rb +7 -0
  94. data/lib/stripe/resources/subscription.rb +25 -0
  95. data/lib/stripe/resources/subscription_item.rb +25 -0
  96. data/lib/stripe/resources/subscription_schedule.rb +32 -0
  97. data/lib/stripe/resources/tax_id.rb +26 -0
  98. data/lib/stripe/resources/tax_rate.rb +11 -0
  99. data/lib/stripe/resources/terminal/connection_token.rb +11 -0
  100. data/lib/stripe/resources/terminal/location.rb +14 -0
  101. data/lib/stripe/resources/terminal/reader.rb +14 -0
  102. data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +3 -1
  103. data/lib/stripe/{token.rb → resources/token.rb} +3 -1
  104. data/lib/stripe/resources/topup.rb +22 -0
  105. data/lib/stripe/resources/transfer.rb +26 -0
  106. data/lib/stripe/resources/usage_record.rb +7 -0
  107. data/lib/stripe/resources/usage_record_summary.rb +7 -0
  108. data/lib/stripe/resources/webhook_endpoint.rb +12 -0
  109. data/lib/stripe/resources.rb +79 -0
  110. data/lib/stripe/singleton_api_resource.rb +10 -4
  111. data/lib/stripe/stripe_client.rb +658 -337
  112. data/lib/stripe/stripe_object.rb +248 -126
  113. data/lib/stripe/stripe_response.rb +55 -21
  114. data/lib/stripe/util.rb +145 -187
  115. data/lib/stripe/version.rb +3 -1
  116. data/lib/stripe/webhook.rb +27 -16
  117. data/lib/stripe.rb +139 -90
  118. data/stripe.gemspec +26 -14
  119. data/test/openapi/README.md +9 -0
  120. data/test/stripe/account_link_test.rb +18 -0
  121. data/test/stripe/account_test.rb +311 -101
  122. data/test/stripe/alipay_account_test.rb +21 -1
  123. data/test/stripe/api_operations_test.rb +57 -8
  124. data/test/stripe/api_resource_test.rb +359 -271
  125. data/test/stripe/apple_pay_domain_test.rb +26 -11
  126. data/test/stripe/application_fee_refund_test.rb +10 -8
  127. data/test/stripe/application_fee_test.rb +49 -3
  128. data/test/stripe/balance_test.rb +4 -2
  129. data/test/stripe/balance_transaction_test.rb +20 -0
  130. data/test/stripe/bank_account_test.rb +11 -11
  131. data/test/stripe/capability_test.rb +45 -0
  132. data/test/stripe/charge_test.rb +25 -18
  133. data/test/stripe/checkout/session_test.rb +41 -0
  134. data/test/stripe/connection_manager_test.rb +163 -0
  135. data/test/stripe/country_spec_test.rb +6 -4
  136. data/test/stripe/coupon_test.rb +29 -10
  137. data/test/stripe/credit_note_test.rb +90 -0
  138. data/test/stripe/customer_balance_transaction_test.rb +37 -0
  139. data/test/stripe/customer_card_test.rb +13 -17
  140. data/test/stripe/customer_test.rb +161 -49
  141. data/test/stripe/dispute_test.rb +19 -8
  142. data/test/stripe/ephemeral_key_test.rb +23 -14
  143. data/test/stripe/errors_test.rb +32 -9
  144. data/test/stripe/exchange_rate_test.rb +20 -0
  145. data/test/stripe/file_link_test.rb +41 -0
  146. data/test/stripe/file_test.rb +87 -0
  147. data/test/stripe/instrumentation_test.rb +74 -0
  148. data/test/stripe/invoice_item_test.rb +31 -18
  149. data/test/stripe/invoice_line_item_test.rb +3 -1
  150. data/test/stripe/invoice_test.rb +158 -39
  151. data/test/stripe/issuing/authorization_test.rb +72 -0
  152. data/test/stripe/issuing/card_test.rb +62 -0
  153. data/test/stripe/issuing/cardholder_test.rb +53 -0
  154. data/test/stripe/issuing/dispute_test.rb +45 -0
  155. data/test/stripe/issuing/transaction_test.rb +48 -0
  156. data/test/stripe/list_object_test.rb +120 -88
  157. data/test/stripe/login_link_test.rb +16 -14
  158. data/test/stripe/mandate_test.rb +14 -0
  159. data/test/stripe/multipart_encoder_test.rb +130 -0
  160. data/test/stripe/oauth_test.rb +69 -50
  161. data/test/stripe/order_return_test.rb +7 -5
  162. data/test/stripe/order_test.rb +39 -14
  163. data/test/stripe/payment_intent_test.rb +107 -0
  164. data/test/stripe/payment_method_test.rb +84 -0
  165. data/test/stripe/payout_test.rb +18 -9
  166. data/test/stripe/person_test.rb +46 -0
  167. data/test/stripe/plan_test.rb +67 -19
  168. data/test/stripe/product_test.rb +28 -14
  169. data/test/stripe/radar/early_fraud_warning_test.rb +22 -0
  170. data/test/stripe/radar/value_list_item_test.rb +48 -0
  171. data/test/stripe/radar/value_list_test.rb +61 -0
  172. data/test/stripe/recipient_test.rb +27 -13
  173. data/test/stripe/refund_test.rb +11 -9
  174. data/test/stripe/reporting/report_run_test.rb +33 -0
  175. data/test/stripe/reporting/report_type_test.rb +22 -0
  176. data/test/stripe/reversal_test.rb +12 -10
  177. data/test/stripe/review_test.rb +27 -0
  178. data/test/stripe/setup_intent_test.rb +84 -0
  179. data/test/stripe/sigma/scheduled_query_run_test.rb +22 -0
  180. data/test/stripe/sku_test.rb +24 -12
  181. data/test/stripe/source_test.rb +70 -19
  182. data/test/stripe/stripe_client_test.rb +867 -326
  183. data/test/stripe/stripe_object_test.rb +284 -182
  184. data/test/stripe/stripe_response_test.rb +73 -24
  185. data/test/stripe/subscription_item_test.rb +47 -15
  186. data/test/stripe/subscription_schedule_test.rb +82 -0
  187. data/test/stripe/subscription_test.rb +41 -19
  188. data/test/stripe/tax_id_test.rb +31 -0
  189. data/test/stripe/tax_rate_test.rb +43 -0
  190. data/test/stripe/terminal/connection_token_test.rb +16 -0
  191. data/test/stripe/terminal/location_test.rb +68 -0
  192. data/test/stripe/terminal/reader_test.rb +62 -0
  193. data/test/stripe/three_d_secure_test.rb +4 -2
  194. data/test/stripe/topup_test.rb +62 -0
  195. data/test/stripe/transfer_test.rb +55 -8
  196. data/test/stripe/usage_record_summary_test.rb +29 -0
  197. data/test/stripe/util_test.rb +173 -84
  198. data/test/stripe/webhook_endpoint_test.rb +59 -0
  199. data/test/stripe/webhook_test.rb +21 -17
  200. data/test/stripe_mock.rb +78 -0
  201. data/test/stripe_test.rb +6 -15
  202. data/test/test_data.rb +28 -26
  203. data/test/test_helper.rb +48 -29
  204. metadata +183 -70
  205. data/lib/stripe/alipay_account.rb +0 -22
  206. data/lib/stripe/application_fee.rb +0 -22
  207. data/lib/stripe/application_fee_refund.rb +0 -20
  208. data/lib/stripe/bank_account.rb +0 -30
  209. data/lib/stripe/bitcoin_transaction.rb +0 -11
  210. data/lib/stripe/card.rb +0 -27
  211. data/lib/stripe/charge.rb +0 -82
  212. data/lib/stripe/customer.rb +0 -79
  213. data/lib/stripe/dispute.rb +0 -17
  214. data/lib/stripe/ephemeral_key.rb +0 -18
  215. data/lib/stripe/file_upload.rb +0 -33
  216. data/lib/stripe/invoice.rb +0 -29
  217. data/lib/stripe/login_link.rb +0 -9
  218. data/lib/stripe/order.rb +0 -29
  219. data/lib/stripe/payout.rb +0 -18
  220. data/lib/stripe/recipient_transfer.rb +0 -6
  221. data/lib/stripe/reversal.rb +0 -20
  222. data/lib/stripe/source.rb +0 -23
  223. data/lib/stripe/subscription.rb +0 -33
  224. data/lib/stripe/subscription_item.rb +0 -14
  225. data/lib/stripe/transfer.rb +0 -18
  226. data/test/api_stub_helpers.rb +0 -0
  227. data/test/stripe/bitcoin_receiver_test.rb +0 -67
  228. data/test/stripe/bitcoin_transaction_test.rb +0 -19
  229. data/test/stripe/file_upload_test.rb +0 -66
  230. data/test/stripe/recipient_card_test.rb +0 -44
@@ -1,31 +1,46 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
2
4
 
3
5
  module Stripe
4
6
  class ApplePayDomainTest < Test::Unit::TestCase
5
7
  should "be listable" do
6
8
  domains = Stripe::ApplePayDomain.list
7
9
  assert_requested :get, "#{Stripe.api_base}/v1/apple_pay/domains"
8
- assert domains.data.kind_of?(Array)
9
- assert domains.data[0].kind_of?(Stripe::ApplePayDomain)
10
+ assert domains.data.is_a?(Array)
11
+ assert domains.data[0].is_a?(Stripe::ApplePayDomain)
10
12
  end
11
13
 
12
14
  should "be retrievable" do
13
15
  domain = Stripe::ApplePayDomain.retrieve("apwc_123")
14
- assert_requested :get, "#{Stripe.api_base}/v1/apple_pay/domains/apwc_123"
15
- assert domain.kind_of?(Stripe::ApplePayDomain)
16
+ assert_requested :get, "#{Stripe.api_base}/v1/apple_pay/domains/apwc_123"
17
+ assert domain.is_a?(Stripe::ApplePayDomain)
16
18
  end
17
19
 
18
20
  should "be creatable" do
19
- domain = Stripe::ApplePayDomain.create(:domain_name => "example.com")
21
+ domain = Stripe::ApplePayDomain.create(domain_name: "example.com")
20
22
  assert_requested :post, "#{Stripe.api_base}/v1/apple_pay/domains"
21
- assert domain.kind_of?(Stripe::ApplePayDomain)
23
+ assert domain.is_a?(Stripe::ApplePayDomain)
22
24
  end
23
25
 
24
26
  should "be deletable" do
25
- domain = Stripe::ApplePayDomain.retrieve("apwc_123")
26
- domain = domain.delete
27
- assert_requested :delete, "#{Stripe.api_base}/v1/apple_pay/domains/#{domain.id}"
28
- assert domain.kind_of?(Stripe::ApplePayDomain)
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
29
44
  end
30
45
  end
31
46
  end
@@ -1,4 +1,6 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
2
4
 
3
5
  module Stripe
4
6
  class ApplicationFeeRefundTest < Test::Unit::TestCase
@@ -11,25 +13,25 @@ module Stripe
11
13
 
12
14
  # notably this *doesn't* make an API call
13
15
  assert_not_requested :get,
14
- "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds"
16
+ "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds"
15
17
 
16
- assert refunds.data.kind_of?(Array)
17
- assert refunds.first.kind_of?(Stripe::ApplicationFeeRefund)
18
+ assert refunds.data.is_a?(Array)
19
+ assert refunds.first.is_a?(Stripe::ApplicationFeeRefund)
18
20
  end
19
21
 
20
22
  should "be creatable" do
21
23
  refund = @fee.refunds.create
22
24
  assert_requested :post,
23
- "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds"
24
- assert refund.kind_of?(Stripe::ApplicationFeeRefund)
25
+ "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds"
26
+ assert refund.is_a?(Stripe::ApplicationFeeRefund)
25
27
  end
26
28
 
27
29
  should "be saveable" do
28
30
  refund = @fee.refunds.first
29
- refund.metadata['key'] = 'value'
31
+ refund.metadata["key"] = "value"
30
32
  refund.save
31
33
  assert_requested :post,
32
- "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds/#{refund.id}"
34
+ "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds/#{refund.id}"
33
35
  end
34
36
  end
35
37
  end
@@ -1,12 +1,58 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
2
4
 
3
5
  module Stripe
4
6
  class ApplicationFeeTest < Test::Unit::TestCase
5
7
  should "be listable" do
6
8
  fees = Stripe::ApplicationFee.list
7
9
  assert_requested :get, "#{Stripe.api_base}/v1/application_fees"
8
- assert fees.data.kind_of?(Array)
9
- assert fees.data[0].kind_of?(Stripe::ApplicationFee)
10
+ 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
10
56
  end
11
57
  end
12
58
  end
@@ -1,11 +1,13 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
2
4
 
3
5
  module Stripe
4
6
  class BalanceTest < Test::Unit::TestCase
5
7
  should "be retrievable" do
6
8
  balance = Stripe::Balance.retrieve
7
9
  assert_requested :get, "#{Stripe.api_base}/v1/balance"
8
- assert balance.kind_of?(Stripe::Balance)
10
+ assert balance.is_a?(Stripe::Balance)
9
11
  end
10
12
  end
11
13
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
4
+
5
+ module Stripe
6
+ class BalanceTransactionTest < Test::Unit::TestCase
7
+ should "be listable" do
8
+ balance_transactions = Stripe::BalanceTransaction.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/balance_transactions"
10
+ assert balance_transactions.data.is_a?(Array)
11
+ assert balance_transactions.first.is_a?(Stripe::BalanceTransaction)
12
+ end
13
+
14
+ should "be retrievable" do
15
+ balance_transaction = Stripe::BalanceTransaction.retrieve("txn_123")
16
+ assert_requested :get, "#{Stripe.api_base}/v1/balance_transactions/txn_123"
17
+ assert balance_transaction.is_a?(Stripe::BalanceTransaction)
18
+ end
19
+ end
20
+ end
@@ -1,4 +1,6 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
2
4
 
3
5
  module Stripe
4
6
  class BankAccountTest < Test::Unit::TestCase
@@ -9,27 +11,25 @@ module Stripe
9
11
  id: "ba_123"
10
12
  )
11
13
  assert_equal "/v1/accounts/acct_123/external_accounts/ba_123",
12
- bank_account.resource_url
14
+ bank_account.resource_url
13
15
  end
14
16
 
15
17
  should "return a customer URL" do
16
18
  bank_account = Stripe::BankAccount.construct_from(
17
19
  customer: "cus_123",
18
- id: "ba_123",
20
+ id: "ba_123"
19
21
  )
20
22
  assert_equal "/v1/customers/cus_123/sources/ba_123",
21
- bank_account.resource_url
23
+ bank_account.resource_url
22
24
  end
23
25
  end
24
26
 
25
27
  context "#verify" do
26
- should 'verify the account' do
27
- bank_account = Stripe::BankAccount.construct_from({
28
- customer: "cus_123",
29
- id: "ba_123",
30
- })
31
- bank_account = bank_account.verify(amounts: [1,2])
32
- assert bank_account.kind_of?(Stripe::BankAccount)
28
+ should "verify the account" do
29
+ bank_account = Stripe::BankAccount.construct_from(customer: "cus_123",
30
+ id: "ba_123")
31
+ bank_account = bank_account.verify(amounts: [1, 2])
32
+ assert bank_account.is_a?(Stripe::BankAccount)
33
33
  end
34
34
  end
35
35
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
4
+
5
+ module Stripe
6
+ class CapabilityTest < Test::Unit::TestCase
7
+ context "#resource_url" do
8
+ should "return a resource URL" do
9
+ capability = Stripe::Capability.construct_from(
10
+ id: "acap_123",
11
+ account: "acct_123"
12
+ )
13
+ assert_equal "/v1/accounts/acct_123/capabilities/acap_123",
14
+ capability.resource_url
15
+ end
16
+
17
+ should "raise without an account" do
18
+ capability = Stripe::Capability.construct_from(id: "acap_123")
19
+ assert_raises NotImplementedError do
20
+ capability.resource_url
21
+ end
22
+ end
23
+ end
24
+
25
+ should "raise on #retrieve" do
26
+ assert_raises NotImplementedError do
27
+ Stripe::Capability.retrieve("acap_123")
28
+ end
29
+ end
30
+
31
+ should "raise on #update" do
32
+ assert_raises NotImplementedError do
33
+ Stripe::Capability.update("acap_123", {})
34
+ end
35
+ end
36
+
37
+ should "be saveable" do
38
+ capability = Stripe::Account.retrieve_capability("acct_123", "acap_123")
39
+ capability.requested = true
40
+ capability.save
41
+ assert_requested :post,
42
+ "#{Stripe.api_base}/v1/accounts/#{capability.account}/capabilities/#{capability.id}"
43
+ end
44
+ end
45
+ end
@@ -1,56 +1,63 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
2
4
 
3
5
  module Stripe
4
6
  class ChargeTest < Test::Unit::TestCase
5
7
  should "be listable" do
6
8
  charges = Stripe::Charge.list
7
9
  assert_requested :get, "#{Stripe.api_base}/v1/charges"
8
- assert charges.data.kind_of?(Array)
9
- assert charges.data[0].kind_of?(Stripe::Charge)
10
+ assert charges.data.is_a?(Array)
11
+ assert charges.data[0].is_a?(Stripe::Charge)
10
12
  end
11
13
 
12
14
  should "be retrievable" do
13
15
  charge = Stripe::Charge.retrieve("ch_123")
14
16
  assert_requested :get, "#{Stripe.api_base}/v1/charges/ch_123"
15
- assert charge.kind_of?(Stripe::Charge)
17
+ assert charge.is_a?(Stripe::Charge)
16
18
  end
17
19
 
18
20
  should "be creatable" do
19
21
  charge = Stripe::Charge.create(
20
22
  amount: 100,
21
23
  currency: "USD",
22
- source: "src_123",
24
+ source: "src_123"
23
25
  )
24
26
  assert_requested :post, "#{Stripe.api_base}/v1/charges"
25
- assert charge.kind_of?(Stripe::Charge)
27
+ assert charge.is_a?(Stripe::Charge)
26
28
  end
27
29
 
28
30
  should "be saveable" do
29
31
  charge = Stripe::Charge.retrieve("ch_123")
30
- charge.metadata['key'] = 'value'
32
+ charge.metadata["key"] = "value"
31
33
  charge.save
32
34
  assert_requested :post, "#{Stripe.api_base}/v1/charges/#{charge.id}"
33
35
  end
34
36
 
35
37
  should "be updateable" do
36
- charge = Stripe::Charge.update("ch_123", metadata: {foo: 'bar'})
38
+ charge = Stripe::Charge.update("ch_123", metadata: { foo: "bar" })
37
39
  assert_requested :post, "#{Stripe.api_base}/v1/charges/ch_123"
38
- assert charge.kind_of?(Stripe::Charge)
40
+ assert charge.is_a?(Stripe::Charge)
39
41
  end
40
42
 
41
- context "#mark_as_fraudulent" do
42
- should "charges should be able to be marked as fraudulent" do
43
+ context "#capture" do
44
+ should "capture the charge" do
43
45
  charge = Stripe::Charge.retrieve("ch_123")
44
- charge = charge.mark_as_fraudulent
45
- assert charge.kind_of?(Stripe::Charge)
46
+ charge = charge.capture(amount: 100)
47
+ assert_requested :post,
48
+ "#{Stripe.api_base}/v1/charges/ch_123/capture",
49
+ body: { amount: 100 }
50
+ assert charge.is_a?(Stripe::Charge)
46
51
  end
47
52
  end
48
53
 
49
- context "#mark_as_safe" do
50
- should "charges should be able to be marked as safe" do
51
- charge = Stripe::Charge.retrieve("ch_123")
52
- charge = charge.mark_as_safe
53
- assert charge.kind_of?(Stripe::Charge)
54
+ context ".capture" do
55
+ should "capture the charge" do
56
+ charge = Stripe::Charge.capture("ch_123", amount: 100)
57
+ assert_requested :post,
58
+ "#{Stripe.api_base}/v1/charges/ch_123/capture",
59
+ body: { amount: 100 }
60
+ assert charge.is_a?(Stripe::Charge)
54
61
  end
55
62
  end
56
63
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../../test_helper", __dir__)
4
+
5
+ module Stripe
6
+ module Checkout
7
+ class SessionTest < Test::Unit::TestCase
8
+ should "be creatable" do
9
+ session = Stripe::Checkout::Session.create(
10
+ cancel_url: "https://stripe.com/cancel",
11
+ client_reference_id: "1234",
12
+ line_items: [
13
+ {
14
+ amount: 123,
15
+ currency: "usd",
16
+ description: "item 1",
17
+ images: [
18
+ "https://stripe.com/img1",
19
+ ],
20
+ name: "name",
21
+ quantity: 2,
22
+ },
23
+ ],
24
+ payment_intent_data: [
25
+ receipt_email: "test@stripe.com",
26
+ ],
27
+ payment_method_types: ["card"],
28
+ success_url: "https://stripe.com/success"
29
+ )
30
+ assert_requested :post, "#{Stripe.api_base}/v1/checkout/sessions"
31
+ assert session.is_a?(Stripe::Checkout::Session)
32
+ end
33
+
34
+ should "be retrievable" do
35
+ charge = Stripe::Checkout::Session.retrieve("cs_123")
36
+ assert_requested :get, "#{Stripe.api_base}/v1/checkout/sessions/cs_123"
37
+ assert charge.is_a?(Stripe::Checkout::Session)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
4
+
5
+ module Stripe
6
+ class ConnectionManagerTest < Test::Unit::TestCase
7
+ setup do
8
+ @manager = Stripe::ConnectionManager.new
9
+ end
10
+
11
+ context "#initialize" do
12
+ should "set #last_used to current time" do
13
+ t = 123.0
14
+ Util.stubs(:monotonic_time).returns(t)
15
+ assert_equal t, Stripe::ConnectionManager.new.last_used
16
+ end
17
+ end
18
+
19
+ context "#clear" do
20
+ should "clear any active connections" do
21
+ stub_request(:post, "#{Stripe.api_base}/path")
22
+ .to_return(body: JSON.generate(object: "account"))
23
+
24
+ # Making a request lets us know that at least one connection is open.
25
+ @manager.execute_request(:post, "#{Stripe.api_base}/path")
26
+
27
+ # Now clear the manager.
28
+ @manager.clear
29
+
30
+ # This check isn't great, but it's otherwise difficult to tell that
31
+ # anything happened with just the public-facing API.
32
+ assert_equal({}, @manager.instance_variable_get(:@active_connections))
33
+ end
34
+ end
35
+
36
+ context "#connection_for" do
37
+ should "correctly initialize a connection" do
38
+ old_proxy = Stripe.proxy
39
+
40
+ old_open_timeout = Stripe.open_timeout
41
+ old_read_timeout = Stripe.read_timeout
42
+
43
+ begin
44
+ # Make sure any global initialization here is undone in the `ensure`
45
+ # block below.
46
+ Stripe.proxy = "http://user:pass@localhost:8080"
47
+
48
+ Stripe.open_timeout = 123
49
+ Stripe.read_timeout = 456
50
+
51
+ conn = @manager.connection_for("https://stripe.com")
52
+
53
+ # Host/port
54
+ assert_equal "stripe.com", conn.address
55
+ assert_equal 443, conn.port
56
+
57
+ # Proxy
58
+ assert_equal "localhost", conn.proxy_address
59
+ assert_equal 8080, conn.proxy_port
60
+ assert_equal "user", conn.proxy_user
61
+ assert_equal "pass", conn.proxy_pass
62
+
63
+ # Timeouts
64
+ assert_equal 123, conn.open_timeout
65
+ assert_equal 456, conn.read_timeout
66
+
67
+ assert_equal true, conn.use_ssl?
68
+ assert_equal OpenSSL::SSL::VERIFY_PEER, conn.verify_mode
69
+ assert_equal Stripe.ca_store, conn.cert_store
70
+ ensure
71
+ Stripe.proxy = old_proxy
72
+
73
+ Stripe.open_timeout = old_open_timeout
74
+ Stripe.read_timeout = old_read_timeout
75
+ end
76
+ end
77
+
78
+ should "produce the same connection multiple times" do
79
+ conn1 = @manager.connection_for("https://stripe.com")
80
+ conn2 = @manager.connection_for("https://stripe.com")
81
+
82
+ assert_equal conn1, conn2
83
+ end
84
+
85
+ should "produce different connections for different hosts" do
86
+ conn1 = @manager.connection_for("https://example.com")
87
+ conn2 = @manager.connection_for("https://stripe.com")
88
+
89
+ refute_equal conn1, conn2
90
+ end
91
+
92
+ should "produce different connections for different ports" do
93
+ conn1 = @manager.connection_for("https://stripe.com:80")
94
+ conn2 = @manager.connection_for("https://stripe.com:443")
95
+
96
+ refute_equal conn1, conn2
97
+ end
98
+ end
99
+
100
+ context "#execute_request" do
101
+ should "make a request" do
102
+ stub_request(:post, "#{Stripe.api_base}/path?query=bar")
103
+ .with(
104
+ body: "body=foo",
105
+ headers: { "Stripe-Account" => "bar" }
106
+ )
107
+ .to_return(body: JSON.generate(object: "account"))
108
+
109
+ @manager.execute_request(:post, "#{Stripe.api_base}/path",
110
+ body: "body=foo",
111
+ headers: { "Stripe-Account" => "bar" },
112
+ query: "query=bar")
113
+ end
114
+
115
+ should "perform basic argument validation" do
116
+ e = assert_raises ArgumentError do
117
+ @manager.execute_request("POST", "#{Stripe.api_base}/path")
118
+ end
119
+ assert_equal e.message, "method should be a symbol"
120
+
121
+ e = assert_raises ArgumentError do
122
+ @manager.execute_request(:post, :uri)
123
+ end
124
+ assert_equal e.message, "uri should be a string"
125
+
126
+ e = assert_raises ArgumentError do
127
+ @manager.execute_request(:post, "#{Stripe.api_base}/path",
128
+ body: {})
129
+ end
130
+ assert_equal e.message, "body should be a string"
131
+
132
+ e = assert_raises ArgumentError do
133
+ @manager.execute_request(:post, "#{Stripe.api_base}/path",
134
+ headers: "foo")
135
+ end
136
+ assert_equal e.message, "headers should be a hash"
137
+
138
+ e = assert_raises ArgumentError do
139
+ @manager.execute_request(:post, "#{Stripe.api_base}/path",
140
+ query: {})
141
+ end
142
+ assert_equal e.message, "query should be a string"
143
+ end
144
+
145
+ should "set #last_used to current time" do
146
+ stub_request(:post, "#{Stripe.api_base}/path")
147
+ .to_return(body: JSON.generate(object: "account"))
148
+
149
+ t = 123.0
150
+ Util.stubs(:monotonic_time).returns(t)
151
+
152
+ manager = Stripe::ConnectionManager.new
153
+
154
+ # `#last_used` is also set by the constructor, so make sure we get a
155
+ # new value for it.
156
+ Util.stubs(:monotonic_time).returns(t + 1.0)
157
+
158
+ manager.execute_request(:post, "#{Stripe.api_base}/path")
159
+ assert_equal t + 1.0, manager.last_used
160
+ end
161
+ end
162
+ end
163
+ end
@@ -1,18 +1,20 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
2
4
 
3
5
  module Stripe
4
6
  class CountrySpecTest < Test::Unit::TestCase
5
7
  should "be listable" do
6
8
  c = Stripe::CountrySpec.list
7
9
  assert_requested :get, "#{Stripe.api_base}/v1/country_specs"
8
- assert c.data.kind_of?(Array)
9
- assert c.data[0].kind_of?(Stripe::CountrySpec)
10
+ assert c.data.is_a?(Array)
11
+ assert c.data[0].is_a?(Stripe::CountrySpec)
10
12
  end
11
13
 
12
14
  should "be retrievable" do
13
15
  s = Stripe::CountrySpec.retrieve("US")
14
16
  assert_requested :get, "#{Stripe.api_base}/v1/country_specs/US"
15
- assert(s.kind_of?(Stripe::CountrySpec))
17
+ assert(s.is_a?(Stripe::CountrySpec))
16
18
  end
17
19
  end
18
20
  end
@@ -1,42 +1,61 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
2
4
 
3
5
  module Stripe
4
6
  class CouponTest < Test::Unit::TestCase
5
7
  should "be listable" do
6
8
  coupons = Stripe::Coupon.list
7
9
  assert_requested :get, "#{Stripe.api_base}/v1/coupons"
8
- assert coupons.data.kind_of?(Array)
9
- assert coupons.first.kind_of?(Stripe::Coupon)
10
+ assert coupons.data.is_a?(Array)
11
+ assert coupons.first.is_a?(Stripe::Coupon)
10
12
  end
11
13
 
12
14
  should "be retrievable" do
13
15
  coupon = Stripe::Coupon.retrieve("25OFF")
14
16
  assert_requested :get, "#{Stripe.api_base}/v1/coupons/25OFF"
15
- assert coupon.kind_of?(Stripe::Coupon)
17
+ assert coupon.is_a?(Stripe::Coupon)
16
18
  end
17
19
 
18
20
  should "be creatable" do
19
21
  coupon = Stripe::Coupon.create(
20
22
  percent_off: 25,
21
- duration: 'repeating',
23
+ duration: "repeating",
22
24
  duration_in_months: 3,
23
- id: '25OFF'
25
+ id: "25OFF"
24
26
  )
25
27
  assert_requested :post, "#{Stripe.api_base}/v1/coupons"
26
- assert coupon.kind_of?(Stripe::Coupon)
28
+ assert coupon.is_a?(Stripe::Coupon)
27
29
  end
28
30
 
29
31
  should "be saveable" do
30
32
  coupon = Stripe::Coupon.retrieve("25OFF")
31
- coupon.metadata['key'] = 'value'
33
+ coupon.metadata["key"] = "value"
32
34
  coupon.save
33
35
  assert_requested :post, "#{Stripe.api_base}/v1/coupons/#{coupon.id}"
34
36
  end
35
37
 
36
38
  should "be updateable" do
37
- coupon = Stripe::Coupon.update("25OFF", metadata: { key: 'value' })
39
+ coupon = Stripe::Coupon.update("25OFF", metadata: { key: "value" })
38
40
  assert_requested :post, "#{Stripe.api_base}/v1/coupons/25OFF"
39
- assert coupon.kind_of?(Stripe::Coupon)
41
+ assert coupon.is_a?(Stripe::Coupon)
42
+ end
43
+
44
+ context "#delete" do
45
+ should "be deletable" do
46
+ coupon = Stripe::Coupon.delete("25OFF")
47
+ assert_requested :delete, "#{Stripe.api_base}/v1/coupons/#{coupon.id}"
48
+ assert coupon.is_a?(Stripe::Coupon)
49
+ end
50
+ end
51
+
52
+ context ".delete" do
53
+ should "be deletable" do
54
+ coupon = Stripe::Coupon.retrieve("25OFF")
55
+ coupon = coupon.delete
56
+ assert_requested :delete, "#{Stripe.api_base}/v1/coupons/25OFF"
57
+ assert coupon.is_a?(Stripe::Coupon)
58
+ end
40
59
  end
41
60
  end
42
61
  end