stripe 5.31.0 → 5.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/VERSION +1 -1
  4. data/lib/stripe/version.rb +1 -1
  5. data/stripe.gemspec +9 -2
  6. metadata +3 -195
  7. data/.editorconfig +0 -10
  8. data/.gitattributes +0 -4
  9. data/.github/ISSUE_TEMPLATE.md +0 -5
  10. data/.github/workflows/ci.yml +0 -34
  11. data/.gitignore +0 -8
  12. data/.rubocop.yml +0 -81
  13. data/.rubocop_todo.yml +0 -33
  14. data/.travis.yml +0 -38
  15. data/.vscode/extensions.json +0 -7
  16. data/.vscode/settings.json +0 -8
  17. data/test/openapi/README.md +0 -9
  18. data/test/stripe/account_link_test.rb +0 -18
  19. data/test/stripe/account_test.rb +0 -412
  20. data/test/stripe/alipay_account_test.rb +0 -37
  21. data/test/stripe/api_operations_test.rb +0 -80
  22. data/test/stripe/api_resource_test.rb +0 -646
  23. data/test/stripe/apple_pay_domain_test.rb +0 -46
  24. data/test/stripe/application_fee_refund_test.rb +0 -37
  25. data/test/stripe/application_fee_test.rb +0 -58
  26. data/test/stripe/balance_test.rb +0 -13
  27. data/test/stripe/balance_transaction_test.rb +0 -20
  28. data/test/stripe/bank_account_test.rb +0 -36
  29. data/test/stripe/billing_portal/configuration_test.rb +0 -37
  30. data/test/stripe/billing_portal/session_test.rb +0 -18
  31. data/test/stripe/capability_test.rb +0 -45
  32. data/test/stripe/charge_test.rb +0 -64
  33. data/test/stripe/checkout/session_test.rb +0 -53
  34. data/test/stripe/connection_manager_test.rb +0 -210
  35. data/test/stripe/country_spec_test.rb +0 -20
  36. data/test/stripe/coupon_test.rb +0 -61
  37. data/test/stripe/credit_note_test.rb +0 -90
  38. data/test/stripe/customer_balance_transaction_test.rb +0 -37
  39. data/test/stripe/customer_card_test.rb +0 -48
  40. data/test/stripe/customer_test.rb +0 -226
  41. data/test/stripe/dispute_test.rb +0 -51
  42. data/test/stripe/ephemeral_key_test.rb +0 -93
  43. data/test/stripe/errors_test.rb +0 -53
  44. data/test/stripe/exchange_rate_test.rb +0 -20
  45. data/test/stripe/file_link_test.rb +0 -41
  46. data/test/stripe/file_test.rb +0 -87
  47. data/test/stripe/instrumentation_test.rb +0 -74
  48. data/test/stripe/invoice_item_test.rb +0 -66
  49. data/test/stripe/invoice_line_item_test.rb +0 -8
  50. data/test/stripe/invoice_test.rb +0 -229
  51. data/test/stripe/issuing/authorization_test.rb +0 -72
  52. data/test/stripe/issuing/card_test.rb +0 -74
  53. data/test/stripe/issuing/cardholder_test.rb +0 -53
  54. data/test/stripe/issuing/dispute_test.rb +0 -54
  55. data/test/stripe/issuing/transaction_test.rb +0 -48
  56. data/test/stripe/list_object_test.rb +0 -202
  57. data/test/stripe/login_link_test.rb +0 -37
  58. data/test/stripe/mandate_test.rb +0 -14
  59. data/test/stripe/multipart_encoder_test.rb +0 -130
  60. data/test/stripe/oauth_test.rb +0 -149
  61. data/test/stripe/order_return_test.rb +0 -21
  62. data/test/stripe/order_test.rb +0 -82
  63. data/test/stripe/payment_intent_test.rb +0 -107
  64. data/test/stripe/payment_method_test.rb +0 -84
  65. data/test/stripe/payout_test.rb +0 -72
  66. data/test/stripe/person_test.rb +0 -46
  67. data/test/stripe/plan_test.rb +0 -98
  68. data/test/stripe/price_test.rb +0 -48
  69. data/test/stripe/product_test.rb +0 -58
  70. data/test/stripe/promotion_code_test.rb +0 -42
  71. data/test/stripe/radar/early_fraud_warning_test.rb +0 -22
  72. data/test/stripe/radar/value_list_item_test.rb +0 -48
  73. data/test/stripe/radar/value_list_test.rb +0 -61
  74. data/test/stripe/recipient_test.rb +0 -62
  75. data/test/stripe/refund_test.rb +0 -39
  76. data/test/stripe/reporting/report_run_test.rb +0 -33
  77. data/test/stripe/reporting/report_type_test.rb +0 -22
  78. data/test/stripe/reversal_test.rb +0 -43
  79. data/test/stripe/review_test.rb +0 -27
  80. data/test/stripe/setup_attempt_test.rb +0 -16
  81. data/test/stripe/setup_intent_test.rb +0 -84
  82. data/test/stripe/sigma/scheduled_query_run_test.rb +0 -22
  83. data/test/stripe/sku_test.rb +0 -60
  84. data/test/stripe/source_test.rb +0 -119
  85. data/test/stripe/stripe_client_test.rb +0 -1456
  86. data/test/stripe/stripe_configuration_test.rb +0 -159
  87. data/test/stripe/stripe_object_test.rb +0 -510
  88. data/test/stripe/stripe_response_test.rb +0 -95
  89. data/test/stripe/subscription_item_test.rb +0 -84
  90. data/test/stripe/subscription_schedule_test.rb +0 -82
  91. data/test/stripe/subscription_test.rb +0 -80
  92. data/test/stripe/tax_id_test.rb +0 -31
  93. data/test/stripe/tax_rate_test.rb +0 -43
  94. data/test/stripe/terminal/connection_token_test.rb +0 -16
  95. data/test/stripe/terminal/location_test.rb +0 -68
  96. data/test/stripe/terminal/reader_test.rb +0 -62
  97. data/test/stripe/three_d_secure_test.rb +0 -23
  98. data/test/stripe/topup_test.rb +0 -62
  99. data/test/stripe/transfer_test.rb +0 -88
  100. data/test/stripe/usage_record_summary_test.rb +0 -29
  101. data/test/stripe/util_test.rb +0 -402
  102. data/test/stripe/webhook_endpoint_test.rb +0 -59
  103. data/test/stripe/webhook_test.rb +0 -135
  104. data/test/stripe_mock.rb +0 -78
  105. data/test/stripe_test.rb +0 -137
  106. data/test/test_data.rb +0 -61
  107. data/test/test_helper.rb +0 -74
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require ::File.expand_path("../test_helper", __dir__)
4
-
5
- module Stripe
6
- class WebhookEndpointTest < Test::Unit::TestCase
7
- should "be listable" do
8
- webhook_endpoints = Stripe::WebhookEndpoint.list
9
- assert_requested :get, "#{Stripe.api_base}/v1/webhook_endpoints"
10
- assert webhook_endpoints.data.is_a?(Array)
11
- assert webhook_endpoints.first.is_a?(Stripe::WebhookEndpoint)
12
- end
13
-
14
- should "be retrievable" do
15
- webhook_endpoint = Stripe::WebhookEndpoint.retrieve("we_123")
16
- assert_requested :get, "#{Stripe.api_base}/v1/webhook_endpoints/we_123"
17
- assert webhook_endpoint.is_a?(Stripe::WebhookEndpoint)
18
- end
19
-
20
- should "be creatable" do
21
- webhook_endpoint = Stripe::WebhookEndpoint.create(
22
- enabled_events: ["charge.succeeded"],
23
- url: "https://stripe.com"
24
- )
25
- assert_requested :post, "#{Stripe.api_base}/v1/webhook_endpoints"
26
- assert webhook_endpoint.is_a?(Stripe::WebhookEndpoint)
27
- end
28
-
29
- should "be saveable" do
30
- webhook_endpoint = Stripe::WebhookEndpoint.retrieve("we_123")
31
- webhook_endpoint.enabled_events = ["charge.succeeded"]
32
- webhook_endpoint.save
33
- assert_requested :post, "#{Stripe.api_base}/v1/webhook_endpoints/#{webhook_endpoint.id}"
34
- end
35
-
36
- should "be updateable" do
37
- webhook_endpoint = Stripe::WebhookEndpoint.update("we_123", enabled_events: ["charge.succeeded"])
38
- assert_requested :post, "#{Stripe.api_base}/v1/webhook_endpoints/we_123"
39
- assert webhook_endpoint.is_a?(Stripe::WebhookEndpoint)
40
- end
41
-
42
- context "#delete" do
43
- should "be deletable" do
44
- webhook_endpoint = Stripe::WebhookEndpoint.retrieve("we_123")
45
- webhook_endpoint = webhook_endpoint.delete
46
- assert_requested :delete, "#{Stripe.api_base}/v1/webhook_endpoints/#{webhook_endpoint.id}"
47
- assert webhook_endpoint.is_a?(Stripe::WebhookEndpoint)
48
- end
49
- end
50
-
51
- context ".delete" do
52
- should "be deletable" do
53
- webhook_endpoint = Stripe::WebhookEndpoint.delete("we_123")
54
- assert_requested :delete, "#{Stripe.api_base}/v1/webhook_endpoints/we_123"
55
- assert webhook_endpoint.is_a?(Stripe::WebhookEndpoint)
56
- end
57
- end
58
- end
59
- end
@@ -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,137 +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 api_version to be configured" do
118
- Stripe.api_version = "2018-02-28"
119
- assert_equal "2018-02-28", Stripe.api_version
120
- end
121
-
122
- should "allow connect_base to be configured" do
123
- Stripe.connect_base = "https://other.stripe.com"
124
- assert_equal "https://other.stripe.com", Stripe.connect_base
125
- end
126
-
127
- should "allow verify_ssl_certs to be configured" do
128
- Stripe.verify_ssl_certs = false
129
- assert_equal false, Stripe.verify_ssl_certs
130
- end
131
-
132
- should "allow client_id to be configured" do
133
- Stripe.client_id = "client"
134
- assert_equal "client", Stripe.client_id
135
- end
136
- end
137
- 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