stripe 5.28.0 → 8.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +286 -0
  3. data/Gemfile +5 -3
  4. data/Makefile +13 -0
  5. data/OPENAPI_VERSION +1 -0
  6. data/README.md +43 -5
  7. data/VERSION +1 -1
  8. data/lib/data/ca-certificates.crt +1241 -1937
  9. data/lib/stripe/api_operations/create.rb +6 -2
  10. data/lib/stripe/api_operations/delete.rb +12 -7
  11. data/lib/stripe/api_operations/list.rb +6 -9
  12. data/lib/stripe/api_operations/nested_resource.rb +62 -34
  13. data/lib/stripe/api_operations/request.rb +45 -2
  14. data/lib/stripe/api_operations/save.rb +13 -3
  15. data/lib/stripe/api_operations/search.rb +16 -0
  16. data/lib/stripe/api_resource.rb +11 -18
  17. data/lib/stripe/api_resource_test_helpers.rb +49 -0
  18. data/lib/stripe/api_version.rb +8 -0
  19. data/lib/stripe/connection_manager.rb +49 -11
  20. data/lib/stripe/error_object.rb +2 -3
  21. data/lib/stripe/instrumentation.rb +46 -6
  22. data/lib/stripe/oauth.rb +4 -3
  23. data/lib/stripe/object_types.rb +36 -10
  24. data/lib/stripe/resources/account.rb +39 -17
  25. data/lib/stripe/resources/account_link.rb +4 -0
  26. data/lib/stripe/resources/application_fee_refund.rb +7 -1
  27. data/lib/stripe/resources/apps/secret.rb +40 -0
  28. data/lib/stripe/resources/balance.rb +11 -0
  29. data/lib/stripe/resources/balance_transaction.rb +4 -0
  30. data/lib/stripe/resources/bank_account.rb +7 -0
  31. data/lib/stripe/resources/billing_portal/configuration.rb +15 -0
  32. data/lib/stripe/resources/billing_portal/session.rb +14 -0
  33. data/lib/stripe/resources/capability.rb +5 -1
  34. data/lib/stripe/resources/card.rb +6 -3
  35. data/lib/stripe/resources/cash_balance.rb +23 -0
  36. data/lib/stripe/resources/charge.rb +23 -3
  37. data/lib/stripe/resources/checkout/session.rb +49 -2
  38. data/lib/stripe/resources/country_spec.rb +6 -0
  39. data/lib/stripe/resources/coupon.rb +3 -0
  40. data/lib/stripe/resources/credit_note.rb +27 -9
  41. data/lib/stripe/resources/credit_note_line_item.rb +2 -0
  42. data/lib/stripe/resources/customer.rb +132 -4
  43. data/lib/stripe/resources/customer_balance_transaction.rb +9 -2
  44. data/lib/stripe/resources/customer_cash_balance_transaction.rb +14 -0
  45. data/lib/stripe/resources/discount.rb +5 -0
  46. data/lib/stripe/resources/dispute.rb +17 -3
  47. data/lib/stripe/resources/event.rb +29 -0
  48. data/lib/stripe/resources/exchange_rate.rb +11 -0
  49. data/lib/stripe/resources/file.rb +9 -1
  50. data/lib/stripe/resources/file_link.rb +3 -0
  51. data/lib/stripe/resources/financial_connections/account.rb +67 -0
  52. data/lib/stripe/resources/financial_connections/account_owner.rb +11 -0
  53. data/lib/stripe/resources/financial_connections/account_ownership.rb +11 -0
  54. data/lib/stripe/resources/financial_connections/session.rb +13 -0
  55. data/lib/stripe/resources/funding_instructions.rb +21 -0
  56. data/lib/stripe/resources/identity/verification_report.rb +23 -0
  57. data/lib/stripe/resources/identity/verification_session.rb +61 -0
  58. data/lib/stripe/resources/invoice.rb +105 -17
  59. data/lib/stripe/resources/invoice_item.rb +11 -0
  60. data/lib/stripe/resources/invoice_line_item.rb +1 -0
  61. data/lib/stripe/resources/issuing/authorization.rb +25 -5
  62. data/lib/stripe/resources/issuing/card.rb +78 -8
  63. data/lib/stripe/resources/issuing/cardholder.rb +3 -0
  64. data/lib/stripe/resources/issuing/dispute.rb +13 -3
  65. data/lib/stripe/resources/issuing/transaction.rb +5 -0
  66. data/lib/stripe/resources/line_item.rb +2 -0
  67. data/lib/stripe/resources/login_link.rb +2 -0
  68. data/lib/stripe/resources/mandate.rb +1 -0
  69. data/lib/stripe/resources/payment_intent.rb +103 -6
  70. data/lib/stripe/resources/payment_link.rb +35 -0
  71. data/lib/stripe/resources/payment_method.rb +25 -5
  72. data/lib/stripe/resources/payout.rb +28 -5
  73. data/lib/stripe/resources/person.rb +7 -0
  74. data/lib/stripe/resources/plan.rb +8 -0
  75. data/lib/stripe/resources/price.rb +15 -0
  76. data/lib/stripe/resources/product.rb +17 -0
  77. data/lib/stripe/resources/promotion_code.rb +2 -0
  78. data/lib/stripe/resources/quote.rb +128 -0
  79. data/lib/stripe/resources/radar/early_fraud_warning.rb +4 -0
  80. data/lib/stripe/resources/radar/value_list.rb +3 -0
  81. data/lib/stripe/resources/radar/value_list_item.rb +3 -0
  82. data/lib/stripe/resources/refund.rb +49 -0
  83. data/lib/stripe/resources/reporting/report_run.rb +8 -0
  84. data/lib/stripe/resources/reporting/report_type.rb +8 -1
  85. data/lib/stripe/resources/reversal.rb +16 -2
  86. data/lib/stripe/resources/review.rb +14 -3
  87. data/lib/stripe/resources/setup_attempt.rb +4 -0
  88. data/lib/stripe/resources/setup_intent.rb +60 -5
  89. data/lib/stripe/resources/shipping_rate.rb +14 -0
  90. data/lib/stripe/resources/sigma/scheduled_query_run.rb +4 -0
  91. data/lib/stripe/resources/source.rb +26 -6
  92. data/lib/stripe/resources/source_transaction.rb +5 -0
  93. data/lib/stripe/resources/subscription.rb +57 -3
  94. data/lib/stripe/resources/subscription_item.rb +2 -7
  95. data/lib/stripe/resources/subscription_schedule.rb +23 -5
  96. data/lib/stripe/resources/tax/calculation.rb +33 -0
  97. data/lib/stripe/resources/tax/calculation_line_item.rb +10 -0
  98. data/lib/stripe/resources/tax/settings.rb +15 -0
  99. data/lib/stripe/resources/tax/transaction.rb +49 -0
  100. data/lib/stripe/resources/tax/transaction_line_item.rb +10 -0
  101. data/lib/stripe/resources/tax_code.rb +11 -0
  102. data/lib/stripe/resources/tax_id.rb +5 -0
  103. data/lib/stripe/resources/tax_rate.rb +3 -0
  104. data/lib/stripe/resources/terminal/configuration.rb +16 -0
  105. data/lib/stripe/resources/terminal/connection_token.rb +3 -0
  106. data/lib/stripe/resources/terminal/location.rb +3 -0
  107. data/lib/stripe/resources/terminal/reader.rb +119 -0
  108. data/lib/stripe/resources/test_helpers/test_clock.rb +35 -0
  109. data/lib/stripe/resources/token.rb +20 -0
  110. data/lib/stripe/resources/topup.rb +15 -3
  111. data/lib/stripe/resources/transfer.rb +10 -11
  112. data/lib/stripe/resources/treasury/credit_reversal.rb +14 -0
  113. data/lib/stripe/resources/treasury/debit_reversal.rb +14 -0
  114. data/lib/stripe/resources/treasury/financial_account.rb +52 -0
  115. data/lib/stripe/resources/treasury/financial_account_features.rb +12 -0
  116. data/lib/stripe/resources/treasury/inbound_transfer.rb +94 -0
  117. data/lib/stripe/resources/treasury/outbound_payment.rb +96 -0
  118. data/lib/stripe/resources/treasury/outbound_transfer.rb +100 -0
  119. data/lib/stripe/resources/treasury/received_credit.rb +30 -0
  120. data/lib/stripe/resources/treasury/received_debit.rb +30 -0
  121. data/lib/stripe/resources/treasury/transaction.rb +13 -0
  122. data/lib/stripe/resources/treasury/transaction_entry.rb +17 -0
  123. data/lib/stripe/resources/usage_record.rb +5 -0
  124. data/lib/stripe/resources/usage_record_summary.rb +1 -0
  125. data/lib/stripe/resources/webhook_endpoint.rb +7 -0
  126. data/lib/stripe/resources.rb +34 -10
  127. data/lib/stripe/search_result_object.rb +86 -0
  128. data/lib/stripe/stripe_client.rb +267 -121
  129. data/lib/stripe/stripe_configuration.rb +29 -10
  130. data/lib/stripe/stripe_object.rb +25 -2
  131. data/lib/stripe/stripe_response.rb +80 -52
  132. data/lib/stripe/util.rb +100 -9
  133. data/lib/stripe/version.rb +1 -1
  134. data/lib/stripe.rb +27 -23
  135. data/stripe.gemspec +12 -5
  136. metadata +46 -204
  137. data/.editorconfig +0 -10
  138. data/.gitattributes +0 -4
  139. data/.github/ISSUE_TEMPLATE.md +0 -5
  140. data/.gitignore +0 -8
  141. data/.rubocop.yml +0 -80
  142. data/.rubocop_todo.yml +0 -33
  143. data/.travis.yml +0 -38
  144. data/.vscode/extensions.json +0 -7
  145. data/.vscode/settings.json +0 -8
  146. data/lib/stripe/resources/bitcoin_receiver.rb +0 -24
  147. data/lib/stripe/resources/bitcoin_transaction.rb +0 -15
  148. data/lib/stripe/resources/issuing/card_details.rb +0 -9
  149. data/lib/stripe/resources/order.rb +0 -33
  150. data/lib/stripe/resources/order_return.rb +0 -10
  151. data/lib/stripe/resources/recipient.rb +0 -14
  152. data/lib/stripe/resources/sku.rb +0 -13
  153. data/lib/stripe/resources/three_d_secure.rb +0 -14
  154. data/test/openapi/README.md +0 -9
  155. data/test/stripe/account_link_test.rb +0 -18
  156. data/test/stripe/account_test.rb +0 -412
  157. data/test/stripe/alipay_account_test.rb +0 -37
  158. data/test/stripe/api_operations_test.rb +0 -80
  159. data/test/stripe/api_resource_test.rb +0 -646
  160. data/test/stripe/apple_pay_domain_test.rb +0 -46
  161. data/test/stripe/application_fee_refund_test.rb +0 -37
  162. data/test/stripe/application_fee_test.rb +0 -58
  163. data/test/stripe/balance_test.rb +0 -13
  164. data/test/stripe/balance_transaction_test.rb +0 -20
  165. data/test/stripe/bank_account_test.rb +0 -36
  166. data/test/stripe/billing_portal/session_test.rb +0 -18
  167. data/test/stripe/capability_test.rb +0 -45
  168. data/test/stripe/charge_test.rb +0 -64
  169. data/test/stripe/checkout/session_test.rb +0 -53
  170. data/test/stripe/connection_manager_test.rb +0 -167
  171. data/test/stripe/country_spec_test.rb +0 -20
  172. data/test/stripe/coupon_test.rb +0 -61
  173. data/test/stripe/credit_note_test.rb +0 -90
  174. data/test/stripe/customer_balance_transaction_test.rb +0 -37
  175. data/test/stripe/customer_card_test.rb +0 -48
  176. data/test/stripe/customer_test.rb +0 -226
  177. data/test/stripe/dispute_test.rb +0 -51
  178. data/test/stripe/ephemeral_key_test.rb +0 -93
  179. data/test/stripe/errors_test.rb +0 -53
  180. data/test/stripe/exchange_rate_test.rb +0 -20
  181. data/test/stripe/file_link_test.rb +0 -41
  182. data/test/stripe/file_test.rb +0 -87
  183. data/test/stripe/instrumentation_test.rb +0 -74
  184. data/test/stripe/invoice_item_test.rb +0 -66
  185. data/test/stripe/invoice_line_item_test.rb +0 -8
  186. data/test/stripe/invoice_test.rb +0 -229
  187. data/test/stripe/issuing/authorization_test.rb +0 -72
  188. data/test/stripe/issuing/card_test.rb +0 -74
  189. data/test/stripe/issuing/cardholder_test.rb +0 -53
  190. data/test/stripe/issuing/dispute_test.rb +0 -54
  191. data/test/stripe/issuing/transaction_test.rb +0 -48
  192. data/test/stripe/list_object_test.rb +0 -202
  193. data/test/stripe/login_link_test.rb +0 -37
  194. data/test/stripe/mandate_test.rb +0 -14
  195. data/test/stripe/multipart_encoder_test.rb +0 -130
  196. data/test/stripe/oauth_test.rb +0 -104
  197. data/test/stripe/order_return_test.rb +0 -21
  198. data/test/stripe/order_test.rb +0 -82
  199. data/test/stripe/payment_intent_test.rb +0 -107
  200. data/test/stripe/payment_method_test.rb +0 -84
  201. data/test/stripe/payout_test.rb +0 -72
  202. data/test/stripe/person_test.rb +0 -46
  203. data/test/stripe/plan_test.rb +0 -98
  204. data/test/stripe/price_test.rb +0 -48
  205. data/test/stripe/product_test.rb +0 -58
  206. data/test/stripe/promotion_code_test.rb +0 -42
  207. data/test/stripe/radar/early_fraud_warning_test.rb +0 -22
  208. data/test/stripe/radar/value_list_item_test.rb +0 -48
  209. data/test/stripe/radar/value_list_test.rb +0 -61
  210. data/test/stripe/recipient_test.rb +0 -62
  211. data/test/stripe/refund_test.rb +0 -39
  212. data/test/stripe/reporting/report_run_test.rb +0 -33
  213. data/test/stripe/reporting/report_type_test.rb +0 -22
  214. data/test/stripe/reversal_test.rb +0 -43
  215. data/test/stripe/review_test.rb +0 -27
  216. data/test/stripe/setup_attempt_test.rb +0 -16
  217. data/test/stripe/setup_intent_test.rb +0 -84
  218. data/test/stripe/sigma/scheduled_query_run_test.rb +0 -22
  219. data/test/stripe/sku_test.rb +0 -60
  220. data/test/stripe/source_test.rb +0 -119
  221. data/test/stripe/stripe_client_test.rb +0 -1291
  222. data/test/stripe/stripe_configuration_test.rb +0 -131
  223. data/test/stripe/stripe_object_test.rb +0 -500
  224. data/test/stripe/stripe_response_test.rb +0 -95
  225. data/test/stripe/subscription_item_test.rb +0 -84
  226. data/test/stripe/subscription_schedule_test.rb +0 -82
  227. data/test/stripe/subscription_test.rb +0 -80
  228. data/test/stripe/tax_id_test.rb +0 -31
  229. data/test/stripe/tax_rate_test.rb +0 -43
  230. data/test/stripe/terminal/connection_token_test.rb +0 -16
  231. data/test/stripe/terminal/location_test.rb +0 -68
  232. data/test/stripe/terminal/reader_test.rb +0 -62
  233. data/test/stripe/three_d_secure_test.rb +0 -23
  234. data/test/stripe/topup_test.rb +0 -62
  235. data/test/stripe/transfer_test.rb +0 -88
  236. data/test/stripe/usage_record_summary_test.rb +0 -29
  237. data/test/stripe/util_test.rb +0 -402
  238. data/test/stripe/webhook_endpoint_test.rb +0 -59
  239. data/test/stripe/webhook_test.rb +0 -135
  240. data/test/stripe_mock.rb +0 -78
  241. data/test/stripe_test.rb +0 -132
  242. data/test/test_data.rb +0 -61
  243. data/test/test_helper.rb +0 -77
@@ -1,135 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require ::File.expand_path("../test_helper", __dir__)
4
-
5
- module Stripe
6
- class WebhookTest < Test::Unit::TestCase
7
- EVENT_PAYLOAD = <<~PAYLOAD
8
- {
9
- "id": "evt_test_webhook",
10
- "object": "event"
11
- }
12
- PAYLOAD
13
- SECRET = "whsec_test_secret"
14
-
15
- def generate_header(opts = {})
16
- opts[:timestamp] ||= Time.now
17
- opts[:payload] ||= EVENT_PAYLOAD
18
- opts[:secret] ||= SECRET
19
- opts[:scheme] ||= Stripe::Webhook::Signature::EXPECTED_SCHEME
20
- opts[:signature] ||= Stripe::Webhook::Signature.compute_signature(
21
- opts[:timestamp],
22
- opts[:payload],
23
- opts[:secret]
24
- )
25
- Stripe::Webhook::Signature.generate_header(
26
- opts[:timestamp],
27
- opts[:signature],
28
- scheme: opts[:scheme]
29
- )
30
- end
31
-
32
- context ".compute_signature" do
33
- should "compute a signature which can then be verified" do
34
- timestamp = Time.now
35
- signature = Stripe::Webhook::Signature.compute_signature(
36
- timestamp,
37
- EVENT_PAYLOAD,
38
- SECRET
39
- )
40
- header = generate_header(timestamp: timestamp, signature: signature)
41
- assert(Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET))
42
- end
43
- end
44
-
45
- context ".generate_header" do
46
- should "generate a header in valid format" do
47
- timestamp = Time.now
48
- signature = Stripe::Webhook::Signature.compute_signature(
49
- timestamp,
50
- EVENT_PAYLOAD,
51
- SECRET
52
- )
53
- scheme = "v1"
54
- header = Stripe::Webhook::Signature.generate_header(
55
- timestamp,
56
- signature,
57
- scheme: scheme
58
- )
59
- assert_equal("t=#{timestamp.to_i},#{scheme}=#{signature}", header)
60
- end
61
- end
62
-
63
- context ".construct_event" do
64
- should "return an Event instance from a valid JSON payload and valid signature header" do
65
- header = generate_header
66
- event = Stripe::Webhook.construct_event(EVENT_PAYLOAD, header, SECRET)
67
- assert event.is_a?(Stripe::Event)
68
- end
69
-
70
- should "raise a JSON::ParserError from an invalid JSON payload" do
71
- assert_raises JSON::ParserError do
72
- payload = "this is not valid JSON"
73
- header = generate_header(payload: payload)
74
- Stripe::Webhook.construct_event(payload, header, SECRET)
75
- end
76
- end
77
-
78
- should "raise a SignatureVerificationError from a valid JSON payload and an invalid signature header" do
79
- header = "bad_header"
80
- assert_raises Stripe::SignatureVerificationError do
81
- Stripe::Webhook.construct_event(EVENT_PAYLOAD, header, SECRET)
82
- end
83
- end
84
- end
85
-
86
- context ".verify_signature_header" do
87
- should "raise a SignatureVerificationError when the header does not have the expected format" do
88
- header = "i'm not even a real signature header"
89
- e = assert_raises(Stripe::SignatureVerificationError) do
90
- Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, "secret")
91
- end
92
- assert_match("Unable to extract timestamp and signatures from header", e.message)
93
- end
94
-
95
- should "raise a SignatureVerificationError when there are no signatures with the expected scheme" do
96
- header = generate_header(scheme: "v0")
97
- e = assert_raises(Stripe::SignatureVerificationError) do
98
- Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, "secret")
99
- end
100
- assert_match("No signatures found with expected scheme", e.message)
101
- end
102
-
103
- should "raise a SignatureVerificationError when there are no valid signatures for the payload" do
104
- header = generate_header(signature: "bad_signature")
105
- e = assert_raises(Stripe::SignatureVerificationError) do
106
- Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, "secret")
107
- end
108
- assert_match("No signatures found matching the expected signature for payload", e.message)
109
- end
110
-
111
- should "raise a SignatureVerificationError when the timestamp is not within the tolerance" do
112
- header = generate_header(timestamp: Time.now - 15)
113
- e = assert_raises(Stripe::SignatureVerificationError) do
114
- Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET, tolerance: 10)
115
- end
116
- assert_match("Timestamp outside the tolerance zone", e.message)
117
- end
118
-
119
- should "return true when the header contains a valid signature and the timestamp is within the tolerance" do
120
- header = generate_header
121
- assert(Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET, tolerance: 10))
122
- end
123
-
124
- should "return true when the header contains at least one valid signature" do
125
- header = generate_header + ",v1=bad_signature"
126
- assert(Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET, tolerance: 10))
127
- end
128
-
129
- should "return true when the header contains a valid signature and the timestamp is off but no tolerance is provided" do
130
- header = generate_header(timestamp: Time.at(12_345))
131
- assert(Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET))
132
- end
133
- end
134
- end
135
- end
data/test/stripe_mock.rb DELETED
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stripe
4
- class StripeMock
5
- include Singleton
6
-
7
- PATH_SPEC = "#{::File.dirname(__FILE__)}/openapi/spec3.json"
8
- PATH_FIXTURES = "#{::File.dirname(__FILE__)}/openapi/fixtures3.json"
9
-
10
- @pid = nil
11
- @port = -1
12
-
13
- # Starts stripe-mock, if necessary. Returns the port on which stripe-mock is listening.
14
- def self.start
15
- unless ::File.exist?(PATH_SPEC)
16
- port = ENV["STRIPE_MOCK_PORT"] || 12_111
17
- puts("No custom spec file found, assuming stripe-mock is already running on port #{port}")
18
- return port
19
- end
20
-
21
- unless @pid.nil?
22
- puts("stripe-mock already running on port #{@port}")
23
- return @port
24
- end
25
-
26
- puts("Starting stripe-mock...")
27
-
28
- @stdout, @child_stdout = ::IO.pipe
29
- @stderr, @child_stderr = ::IO.pipe
30
-
31
- @pid = ::Process.spawn(
32
- %w[stripe-mock stripe-mock],
33
- "-http-port",
34
- "0", # have stripe-mock select a port
35
- "-spec",
36
- PATH_SPEC,
37
- "-fixtures",
38
- PATH_FIXTURES,
39
- out: @child_stdout,
40
- err: @child_stderr
41
- )
42
-
43
- [@child_stdout, @child_stderr].each(&:close)
44
-
45
- # Look for port in "Listening for HTTP on port: 50602"
46
- buffer = ""
47
- loop do
48
- buffer += @stdout.readpartial(4096)
49
- if (matches = buffer.match(/ port: (\d+)/))
50
- @port = matches[1]
51
- break
52
- end
53
- sleep(0.1)
54
- end
55
-
56
- status = (::Process.wait2(@pid, ::Process::WNOHANG) || []).last
57
- if status.nil?
58
- puts("Started stripe-mock; PID = #{@pid}, port = #{@port}")
59
- else
60
- abort("stripe-mock terminated early: #{status}")
61
- end
62
-
63
- @port
64
- end
65
-
66
- # Stops stripe-mock, if necessary.
67
- def self.stop
68
- return if @pid.nil?
69
-
70
- puts("Stopping stripe-mock...")
71
- ::Process.kill(:SIGTERM, @pid)
72
- ::Process.waitpid2(@pid)
73
- @pid = nil
74
- @port = -1
75
- puts("Stopped stripe-mock")
76
- end
77
- end
78
- end
data/test/stripe_test.rb DELETED
@@ -1,132 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require ::File.expand_path("test_helper", __dir__)
4
-
5
- class StripeTest < Test::Unit::TestCase
6
- should "allow app_info to be configured" do
7
- begin
8
- old = Stripe.app_info
9
- Stripe.set_app_info(
10
- "MyAwesomePlugin",
11
- partner_id: "partner_1234",
12
- url: "https://myawesomeplugin.info",
13
- version: "1.2.34"
14
- )
15
- assert_equal({
16
- name: "MyAwesomePlugin",
17
- partner_id: "partner_1234",
18
- url: "https://myawesomeplugin.info",
19
- version: "1.2.34",
20
- }, Stripe.app_info)
21
- ensure
22
- Stripe.app_info = old
23
- end
24
- end
25
-
26
- context "forwardable configurations" do
27
- context "internal configurations" do
28
- should "return the certificate store" do
29
- assert Stripe.ca_store.is_a?(OpenSSL::X509::Store)
30
- end
31
-
32
- should "return the max_network_retry_delay" do
33
- assert_equal 2, Stripe.max_network_retry_delay
34
- end
35
-
36
- should "return the initial_network_retry_delay" do
37
- assert_equal 0.5, Stripe.initial_network_retry_delay
38
- end
39
- end
40
-
41
- should "allow ca_bundle_path to be configured" do
42
- Stripe::StripeClient.expects(:clear_all_connection_managers)
43
- Stripe.ca_bundle_path = "/path/to/ca/bundle"
44
- assert_equal "/path/to/ca/bundle", Stripe.ca_bundle_path
45
- end
46
-
47
- should "allow open timeout to be configured" do
48
- Stripe.open_timeout = 10
49
- assert_equal 10, Stripe.open_timeout
50
- end
51
-
52
- should "allow read timeout to be configured" do
53
- Stripe.read_timeout = 10
54
- assert_equal 10, Stripe.read_timeout
55
- end
56
-
57
- if WRITE_TIMEOUT_SUPPORTED
58
- should "allow write timeout to be configured" do
59
- Stripe.write_timeout = 10
60
- assert_equal 10, Stripe.write_timeout
61
- end
62
- else
63
- should "raise when write timeout to be configured is not supported" do
64
- assert_raises NotImplementedError do
65
- Stripe.write_timeout = 10
66
- end
67
- end
68
- end
69
-
70
- should "allow api_key to be configured" do
71
- Stripe.api_key = "sk_local_test"
72
- assert_equal "sk_local_test", Stripe.api_key
73
- end
74
-
75
- should "allow stripe_account to be configured" do
76
- Stripe.stripe_account = "acct_1234"
77
- assert_equal "acct_1234", Stripe.stripe_account
78
- end
79
-
80
- should "allow enable_telemetry to be configured" do
81
- begin
82
- old = Stripe.enable_telemetry?
83
-
84
- Stripe.enable_telemetry = false
85
- assert_equal false, Stripe.enable_telemetry?
86
- ensure
87
- Stripe.enable_telemetry = old
88
- end
89
- end
90
-
91
- should "allow log_level to be configured" do
92
- Stripe.log_level = "debug"
93
- assert_equal ::Logger::DEBUG, Stripe.log_level
94
- end
95
-
96
- should "allow logger to be configured" do
97
- logger = Object.new
98
- Stripe.logger = logger
99
- assert_equal logger, Stripe.logger
100
- end
101
-
102
- should "allow proxy to be configured" do
103
- Stripe.proxy = "http://proxy"
104
- assert_equal "http://proxy", Stripe.proxy
105
- end
106
-
107
- should "allow uploads_base to be configured" do
108
- Stripe.uploads_base = "https://other.stripe.com"
109
- assert_equal "https://other.stripe.com", Stripe.uploads_base
110
- end
111
-
112
- should "allow api_base to be configured" do
113
- Stripe.api_base = "https://other.stripe.com"
114
- assert_equal "https://other.stripe.com", Stripe.api_base
115
- end
116
-
117
- should "allow connect_base to be configured" do
118
- Stripe.connect_base = "https://other.stripe.com"
119
- assert_equal "https://other.stripe.com", Stripe.connect_base
120
- end
121
-
122
- should "allow verify_ssl_certs to be configured" do
123
- Stripe.verify_ssl_certs = false
124
- assert_equal false, Stripe.verify_ssl_certs
125
- end
126
-
127
- should "allow client_id to be configured" do
128
- Stripe.client_id = "client"
129
- assert_equal "client", Stripe.client_id
130
- end
131
- end
132
- end
data/test/test_data.rb DELETED
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stripe
4
- module TestData
5
- def make_error(type, message)
6
- {
7
- error: {
8
- type: type,
9
- message: message,
10
- },
11
- }
12
- end
13
-
14
- def make_invalid_api_key_error
15
- {
16
- error: {
17
- type: "invalid_request_error",
18
- message: "Invalid API Key provided: invalid",
19
- },
20
- }
21
- end
22
-
23
- def make_invalid_exp_year_error
24
- {
25
- error: {
26
- code: "invalid_expiry_year",
27
- param: "exp_year",
28
- type: "card_error",
29
- message: "Your card's expiration year is invalid",
30
- },
31
- }
32
- end
33
-
34
- def make_missing_id_error
35
- {
36
- error: {
37
- param: "id",
38
- type: "invalid_request_error",
39
- message: "Missing id",
40
- },
41
- }
42
- end
43
-
44
- def make_rate_limit_error
45
- {
46
- error: {
47
- type: "invalid_request_error",
48
- message: "Too many requests in a period of time.",
49
- },
50
- }
51
- end
52
-
53
- def make_api_error
54
- {
55
- error: {
56
- type: "api_error",
57
- },
58
- }
59
- end
60
- end
61
- end
data/test/test_helper.rb DELETED
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "coveralls"
4
- Coveralls.wear!("test_frameworks")
5
-
6
- require "stripe"
7
- require "test/unit"
8
- require "mocha/setup"
9
- require "stringio"
10
- require "shoulda/context"
11
- require "webmock/test_unit"
12
-
13
- PROJECT_ROOT = ::File.expand_path("../", __dir__)
14
-
15
- require ::File.expand_path("test_data", __dir__)
16
- require ::File.expand_path("stripe_mock", __dir__)
17
-
18
- # If changing this number, please also change it in `.travis.yml`.
19
- MOCK_MINIMUM_VERSION = "0.101.0"
20
- MOCK_PORT = Stripe::StripeMock.start
21
-
22
- # Disable all real network connections except those that are outgoing to
23
- # stripe-mock.
24
- WebMock.disable_net_connect!(allow: "localhost:#{MOCK_PORT}")
25
-
26
- # Try one initial test connection to stripe-mock so that if there's a problem
27
- # we can print one error and fail fast so that it's more clear to the user how
28
- # they should fix the problem.
29
- begin
30
- resp = Net::HTTP.get_response(URI("http://localhost:#{MOCK_PORT}/"))
31
- version = resp["Stripe-Mock-Version"]
32
-
33
- if version.nil?
34
- abort("Couldn't find `Stripe-Mock-Version` in response from " \
35
- "`localhost:#{MOCK_PORT}`. Is the service running there stripe-mock?")
36
- end
37
-
38
- if version != "master" &&
39
- Gem::Version.new(version) < Gem::Version.new(MOCK_MINIMUM_VERSION)
40
- abort("Your version of stripe-mock (#{version}) is too old. The minimum " \
41
- "version to run this test suite is #{MOCK_MINIMUM_VERSION}. Please " \
42
- "see its repository for upgrade instructions.")
43
- end
44
- rescue Errno::ECONNREFUSED
45
- abort("Couldn't reach stripe-mock at `localhost:#{MOCK_PORT}`. Is " \
46
- "it running? Please see README for setup instructions.")
47
- end
48
-
49
- Test::Unit.at_exit do
50
- Stripe::StripeMock.stop
51
- end
52
-
53
- module Test
54
- module Unit
55
- class TestCase
56
- include Stripe::TestData
57
- include Mocha
58
-
59
- WRITE_TIMEOUT_SUPPORTED = Net::HTTP.instance_methods.include?(:write_timeout=)
60
-
61
- setup do
62
- Stripe.api_key = "sk_test_123"
63
- Stripe.api_base = "http://localhost:#{MOCK_PORT}"
64
-
65
- stub_connect
66
- end
67
-
68
- teardown do
69
- Stripe.api_key = nil
70
- end
71
-
72
- private def stub_connect
73
- stub_request(:any, /^#{Stripe.connect_base}/).to_return(body: "{}")
74
- end
75
- end
76
- end
77
- end