stripe-ruby-mock 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec_tests.yml +16 -16
  3. data/Appraisals +7 -0
  4. data/CHANGELOG.md +20 -0
  5. data/Gemfile +2 -0
  6. data/README.md +9 -3
  7. data/bin/stripe-mock-server +1 -0
  8. data/gemfiles/.bundle/config +2 -0
  9. data/gemfiles/stripe_12.gemfile +13 -0
  10. data/gemfiles/stripe_12.gemfile.lock +60 -0
  11. data/gemfiles/stripe_13.gemfile +13 -0
  12. data/gemfiles/stripe_13.gemfile.lock +60 -0
  13. data/lib/stripe_mock/api/client.rb +12 -4
  14. data/lib/stripe_mock/api/instance.rb +5 -3
  15. data/lib/stripe_mock/client.rb +2 -3
  16. data/lib/stripe_mock/compat.rb +29 -0
  17. data/lib/stripe_mock/data.rb +61 -9
  18. data/lib/stripe_mock/instance.rb +47 -4
  19. data/lib/stripe_mock/request_handlers/checkout_session.rb +12 -11
  20. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +1 -0
  21. data/lib/stripe_mock/request_handlers/invoices.rb +8 -2
  22. data/lib/stripe_mock/request_handlers/payment_intents.rb +1 -1
  23. data/lib/stripe_mock/request_handlers/payment_methods.rb +5 -1
  24. data/lib/stripe_mock/request_handlers/payouts.rb +10 -3
  25. data/lib/stripe_mock/request_handlers/subscriptions.rb +1 -1
  26. data/lib/stripe_mock/request_handlers/tax_ids.rb +66 -0
  27. data/lib/stripe_mock/server.rb +9 -4
  28. data/lib/stripe_mock/test_strategies/base.rb +0 -1
  29. data/lib/stripe_mock/util.rb +6 -0
  30. data/lib/stripe_mock/version.rb +1 -1
  31. data/lib/stripe_mock.rb +2 -1
  32. data/spec/instance_spec.rb +7 -2
  33. data/spec/list_spec.rb +1 -1
  34. data/spec/server_spec.rb +12 -3
  35. data/spec/shared_stripe_examples/account_examples.rb +1 -1
  36. data/spec/shared_stripe_examples/checkout_session_examples.rb +0 -5
  37. data/spec/shared_stripe_examples/customer_examples.rb +1 -1
  38. data/spec/shared_stripe_examples/payment_intent_examples.rb +13 -13
  39. data/spec/shared_stripe_examples/payment_method_examples.rb +10 -0
  40. data/spec/shared_stripe_examples/payout_examples.rb +26 -6
  41. data/spec/shared_stripe_examples/product_examples.rb +3 -0
  42. data/spec/shared_stripe_examples/setup_intent_examples.rb +5 -1
  43. data/spec/shared_stripe_examples/subscription_examples.rb +1 -1
  44. data/spec/shared_stripe_examples/transfer_examples.rb +10 -3
  45. data/spec/spec_helper.rb +1 -0
  46. data/spec/stripe_mock_spec.rb +35 -13
  47. data/stripe-ruby-mock.gemspec +2 -1
  48. metadata +33 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be25dafb9048c0f9fea9671c8dfa3c25f51121afcd11e2a83fb28033d84fb609
4
- data.tar.gz: 5ccd183891c8ee2a67aa21b7be2508226850a514b9d1f5c8bbe994e374b832df
3
+ metadata.gz: 25863512f9198c5d281a21813ce21357d94d9cb39a346a65006135ba3baafd7d
4
+ data.tar.gz: 718a79b250972169ba5fa7f4c6c766cfee25038b1b730cb39758086a0f40c557
5
5
  SHA512:
6
- metadata.gz: d3be1ba24da98944abb23977d94ab25205ef5458fbe1504bff4293fa55b6d0ae57f922ede65d28f80872c60e66086fd68a32f5b4a96dd5c23ab59a20639f1c74
7
- data.tar.gz: b06bea97f9417cfaf61e4c4a4dc86c914ef1dc76ec170bda9514fd782eddabeceac62b60a65fef771220b59c7b83aeba0c60a809a641c0b02984c1fa8378ce15
6
+ metadata.gz: d2aac810a519355990df689750f9103f4c44b1ca95de9ba2a23155c61338d48ed7322290ab0fcb322def1a49b80b51b9bbba9632f3f26bc36ca5faf70e034dd7
7
+ data.tar.gz: 14a7042d3391b7aabfaf7912f88fd57fd2b808985e26cad37fd51cd2e320981fd4f3a51f6e045caed56a9644a2bbae47232d9f553bd950e49f55b537f7401050
@@ -9,30 +9,30 @@ name: Tests
9
9
 
10
10
  on:
11
11
  push:
12
- branches: [ "master" ]
12
+ branches: ["master"]
13
13
  pull_request:
14
- branches: [ "master" ]
14
+ branches: ["master"]
15
15
 
16
16
  permissions:
17
17
  contents: read
18
18
 
19
19
  jobs:
20
20
  test:
21
-
22
21
  runs-on: ubuntu-latest
23
22
  strategy:
23
+ fail-fast: false
24
24
  matrix:
25
- ruby-version: ['2.7', '3.0', '3.2']
26
-
25
+ ruby: ["3.1", "3.2", "3.3"]
26
+ gemfile: ["stripe_12", "stripe_13"]
27
+ env:
28
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
27
29
  steps:
28
- - uses: actions/checkout@v3
29
- - name: Set up Ruby
30
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
- # uses: ruby/setup-ruby@v1
33
- uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
34
- with:
35
- ruby-version: ${{ matrix.ruby-version }}
36
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
- - name: Run tests
38
- run: bundle exec rspec
30
+ - uses: actions/checkout@v4
31
+ - name: Set up Ruby ${{ matrix.ruby }}
32
+ uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+ - name: Install dependencies
36
+ run: bundle install
37
+ - name: Run tests
38
+ run: bundle exec rspec
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise "stripe-13" do
2
+ gem "stripe", "13.4.0"
3
+ end
4
+
5
+ appraise "stripe-12" do
6
+ gem "stripe", "12.6.0"
7
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  ### Unreleased
2
2
 
3
+ ### 5.0.0
4
+ - [#919](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/919) Add capabilities to mock account data [@cazwazacz](https://github.com/cazwazacz)
5
+ - [#931](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/931) Support Stripe version 13 + 12 [@gabrieltaylor](https://github.com/gabrieltaylor)
6
+
7
+ ### 4.1.0 (2025-04-24)
8
+ - [#920](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/920) Adds DRB as a dependency in preparation to Ruby 3.4.0 [@lucascppessoa](https://github.com/lucascppessoa)
9
+ - [#927](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/927) Allow :cancel_url nil in create Checkout Session [@shu-illy](https://github.com/shu-illy)
10
+ - [#929](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/929) Actions uses only supported ruby versions [@alexmamonchik](https://github.com/alexmamonchik)
11
+ - [#925](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/925) Fix github actions and add missing product attributes [@bettysteger](https://github.com/bettysteger)
12
+ - [#928](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/928) Add tax ID endpoints and data [@lfittl](https://github.com/lfittl)
13
+ - [#835](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/835) Account: replace deprecated verification hash by requirements [@fabianoarruda](https://github.com/fabianoarruda)
14
+ - [#903](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/903) Add require option to require additional file [@stevenharman](https://github.com/stevenharman)
15
+ - [#904](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/904) Add has_more to Subscription.items data [@stevenharman](https://github.com/stevenharman)
16
+ - [#843](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/843) Some updates around subscriptions [@donnguyen](https://github.com/donnguyen)
17
+ - [#917](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/917) Removed charges on PI and added latest_charge [@espen](https://github.com/espen)
18
+ - [#916](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/916) Better tests for payout [@espen](https://github.com/espen)
19
+ - [#862](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/862) Add simple support for us bank accounts [@smtlaissezfaire](https://github.com/smtlaissezfaire)
20
+ - [#907](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/907) Fix calls to use raise instead of throw [@smtlaissezfaire](https://github.com/smtlaissezfaire)
21
+ - [#908](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/908) Add update_payout [@espen](https://github.com/espen)
22
+
3
23
  ### 4.0.0 (2024-08-07)
4
24
  - [#905](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/905) Allow Stripe SDK v11 by [@stevenharman ](https://github.com/stevenharman)
5
25
  - [#830](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/830) Implement search API by [@adamstegman](https://github.com/adamstegman)
data/Gemfile CHANGED
@@ -6,3 +6,5 @@ group :test do
6
6
  end
7
7
 
8
8
  gemspec
9
+
10
+ gem 'appraisal'
data/README.md CHANGED
@@ -18,6 +18,8 @@ In your gemfile:
18
18
 
19
19
  We have [changelog](https://github.com/stripe-ruby-mock/stripe-ruby-mock/blob/master/CHANGELOG.md). It's first attempt. Feel free to update it and suggest to a new format of it.
20
20
 
21
+ version `5.0.0` has [breaking changes](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/931) - we support stripe > 5 and <= 13 for now and try to follow the newest API version.
22
+
21
23
  version `3.0.0` has [breaking changes](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) - we support stripe > 5 and < 6 for now and try to follow the newest API version. But if you still use older versions please [read](https://github.com/stripe-ruby-mock/stripe-ruby-mock#specifications).
22
24
 
23
25
  ## Features
@@ -29,12 +31,12 @@ version `3.0.0` has [breaking changes](https://github.com/stripe-ruby-mock/strip
29
31
 
30
32
  ### Requirements
31
33
 
32
- * ruby >= 2.7.0
33
- * stripe > 5 & < 11
34
+ * ruby >= 3.0.0
35
+ * stripe > 5 & <= 13
34
36
 
35
37
  ### Specifications
36
38
 
37
- **STRIPE API TARGET VERSION:** 2019-08-20 (master) - we try, but some features are not implemented yet.
39
+ **STRIPE API TARGET VERSION:** 2024-06-20 (master) - we try, but some features are not implemented yet.
38
40
 
39
41
  Older API version branches:
40
42
 
@@ -408,6 +410,10 @@ This will help ensure that the problem remains fixed in future updates.
408
410
 
409
411
  Note: You may need to `ulimit -n 4048` before running the test suite to get all tests to pass.
410
412
 
413
+ ### Dependency updates
414
+
415
+ When modifications are made to dependencies in addition to the changes to the Gemfile, Gemfile.lock and stripe-ruby-mock.gemspec you must also run `bundle exec appraisal update` to update the gemfiles specific to Stripe version 12 and Stripe version 13.
416
+
411
417
  ## Copyright
412
418
 
413
419
  Copyright (c) 2013 Gilbert
@@ -11,6 +11,7 @@ opts = Trollop::options do
11
11
  opt :server, "Server to use", :type => :string, :default => 'thin'
12
12
  opt :debug, "Request and response output", :default => true
13
13
  opt :pid_path, "Location to put server pid file", :type => :string, :default => './stripe-mock-server.pid'
14
+ opt :require, "Extra path to require when loading the server; can be specified multiple times", :type => :string, :multi => true
14
15
  end
15
16
 
16
17
  require 'stripe_mock'
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "stripe", "12.6.0"
7
+
8
+ group :test do
9
+ gem "rake"
10
+ gem "dotenv"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ stripe-ruby-mock (4.0.0)
5
+ dante (>= 0.2.0)
6
+ drb (>= 2.0.4, < 3)
7
+ multi_json (~> 1.0)
8
+ stripe (> 5, < 14)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ appraisal (2.5.0)
14
+ bundler
15
+ rake
16
+ thor (>= 0.14.0)
17
+ daemons (1.4.1)
18
+ dante (0.2.0)
19
+ diff-lcs (1.6.1)
20
+ dotenv (2.8.1)
21
+ drb (2.2.1)
22
+ eventmachine (1.2.7)
23
+ multi_json (1.15.0)
24
+ rack (2.2.13)
25
+ rake (13.2.1)
26
+ rspec (3.13.0)
27
+ rspec-core (~> 3.13.0)
28
+ rspec-expectations (~> 3.13.0)
29
+ rspec-mocks (~> 3.13.0)
30
+ rspec-core (3.13.3)
31
+ rspec-support (~> 3.13.0)
32
+ rspec-expectations (3.13.3)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.13.0)
35
+ rspec-mocks (3.13.2)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.13.0)
38
+ rspec-support (3.13.2)
39
+ stripe (12.6.0)
40
+ thin (1.8.2)
41
+ daemons (~> 1.0, >= 1.0.9)
42
+ eventmachine (~> 1.0, >= 1.0.4)
43
+ rack (>= 1, < 3)
44
+ thor (1.3.2)
45
+
46
+ PLATFORMS
47
+ ruby
48
+ x86_64-darwin-22
49
+
50
+ DEPENDENCIES
51
+ appraisal
52
+ dotenv
53
+ rake
54
+ rspec (~> 3.13.0)
55
+ stripe (= 12.6.0)
56
+ stripe-ruby-mock!
57
+ thin (~> 1.8.1)
58
+
59
+ BUNDLED WITH
60
+ 2.6.8
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "stripe", "13.4.0"
7
+
8
+ group :test do
9
+ gem "rake"
10
+ gem "dotenv"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ stripe-ruby-mock (4.0.0)
5
+ dante (>= 0.2.0)
6
+ drb (>= 2.0.4, < 3)
7
+ multi_json (~> 1.0)
8
+ stripe (> 5, < 14)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ appraisal (2.5.0)
14
+ bundler
15
+ rake
16
+ thor (>= 0.14.0)
17
+ daemons (1.4.1)
18
+ dante (0.2.0)
19
+ diff-lcs (1.6.1)
20
+ dotenv (2.8.1)
21
+ drb (2.2.1)
22
+ eventmachine (1.2.7)
23
+ multi_json (1.15.0)
24
+ rack (2.2.13)
25
+ rake (13.2.1)
26
+ rspec (3.13.0)
27
+ rspec-core (~> 3.13.0)
28
+ rspec-expectations (~> 3.13.0)
29
+ rspec-mocks (~> 3.13.0)
30
+ rspec-core (3.13.3)
31
+ rspec-support (~> 3.13.0)
32
+ rspec-expectations (3.13.3)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.13.0)
35
+ rspec-mocks (3.13.2)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.13.0)
38
+ rspec-support (3.13.2)
39
+ stripe (13.4.0)
40
+ thin (1.8.2)
41
+ daemons (~> 1.0, >= 1.0.9)
42
+ eventmachine (~> 1.0, >= 1.0.4)
43
+ rack (>= 1, < 3)
44
+ thor (1.3.2)
45
+
46
+ PLATFORMS
47
+ ruby
48
+ x86_64-darwin-22
49
+
50
+ DEPENDENCIES
51
+ appraisal
52
+ dotenv
53
+ rake
54
+ rspec (~> 3.13.0)
55
+ stripe (= 13.4.0)
56
+ stripe-ruby-mock!
57
+ thin (~> 1.8.1)
58
+
59
+ BUNDLED WITH
60
+ 2.6.8
@@ -8,7 +8,9 @@ module StripeMock
8
8
  return false if @state == 'live'
9
9
  return @client unless @client.nil?
10
10
 
11
- Stripe::StripeClient.send(:define_method, :execute_request) { |*args, **keyword_args| StripeMock.redirect_to_mock_server(*args, **keyword_args) }
11
+ Compat.client.send(:define_method, Compat.method) do |*args, **keyword_args|
12
+ StripeMock.redirect_to_mock_server(*args, **keyword_args)
13
+ end
12
14
  @client = StripeMock::Client.new(port)
13
15
  @state = 'remote'
14
16
  @client
@@ -27,7 +29,14 @@ module StripeMock
27
29
 
28
30
  private
29
31
 
30
- def self.redirect_to_mock_server(method, url, api_key: nil, api_base: nil, usage: [], params: {}, headers: {})
32
+ def self.redirect_to_mock_server(*args, **kwargs)
33
+ if args.length == 2 && kwargs.key?(:api_key) # Legacy signature
34
+ method, url = args
35
+ elsif args.length == 6 # New signature
36
+ method, url, _base_address, _params, _opts, _usage = args
37
+ else
38
+ raise ArgumentError, "Invalid arguments for mock_request"
39
+ end
31
40
  handler = Instance.handler_for_method_url("#{method} #{url}")
32
41
 
33
42
  if mock_error = client.error_queue.error_for_handler_name(handler[:name])
@@ -35,7 +44,6 @@ module StripeMock
35
44
  raise mock_error
36
45
  end
37
46
 
38
- Stripe::Util.symbolize_names client.mock_request(method, url, api_key: api_key, params: params, headers: headers)
47
+ Stripe::Util.symbolize_names client.mock_request(*args, **kwargs)
39
48
  end
40
-
41
49
  end
@@ -2,12 +2,14 @@ module StripeMock
2
2
 
3
3
  @state = 'ready'
4
4
  @instance = nil
5
- @original_execute_request_method = Stripe::StripeClient.instance_method(:execute_request)
5
+ @original_execute_request_method = Compat.client.instance_method(Compat.method)
6
6
 
7
7
  def self.start
8
8
  return false if @state == 'live'
9
9
  @instance = instance = Instance.new
10
- Stripe::StripeClient.send(:define_method, :execute_request) { |*args, **keyword_args| instance.mock_request(*args, **keyword_args) }
10
+ Compat.client.send(:define_method, Compat.method) { |*args, **keyword_args|
11
+ instance.mock_request(*args, **keyword_args)
12
+ }
11
13
  @state = 'local'
12
14
  end
13
15
 
@@ -29,7 +31,7 @@ module StripeMock
29
31
  end
30
32
 
31
33
  def self.restore_stripe_execute_request_method
32
- Stripe::StripeClient.send(:define_method, :execute_request, @original_execute_request_method)
34
+ Compat.client.send(:define_method, Compat.method, @original_execute_request_method)
33
35
  end
34
36
 
35
37
  def self.instance; @instance; end
@@ -13,9 +13,9 @@ module StripeMock
13
13
  @state = 'ready'
14
14
  end
15
15
 
16
- def mock_request(method, url, api_key: nil, params: {}, headers: {})
16
+ def mock_request(*args, **kwargs)
17
17
  timeout_wrap do
18
- @pipe.mock_request(method, url, api_key: api_key, params: params, headers: headers).tap {|result|
18
+ @pipe.mock_request(*args, **kwargs).tap {|result|
19
19
  response, api_key = result
20
20
  if response.is_a?(Hash) && response[:error_raised] == 'invalid_request'
21
21
  args, keyword_args = response[:error_params].first(2), response[:error_params].last
@@ -124,5 +124,4 @@ module StripeMock
124
124
  end
125
125
  end
126
126
  end
127
-
128
127
  end
@@ -0,0 +1,29 @@
1
+ module StripeMock
2
+ module Compat
3
+ def self.stripe_gte_13?
4
+ Gem::Version.new(Stripe::VERSION) >= Gem::Version.new('13.0.0')
5
+ end
6
+
7
+ def self.method
8
+ return :execute_request unless stripe_gte_13?
9
+
10
+ :execute_request_internal
11
+ end
12
+
13
+ def self.client
14
+ return Stripe::StripeClient unless stripe_gte_13?
15
+
16
+ Stripe::APIRequestor
17
+ end
18
+
19
+ def self.client_instance
20
+ @client ||= client.new
21
+ end
22
+
23
+ def self.active_client
24
+ return client.active_client unless stripe_gte_13?
25
+
26
+ client.active_requestor
27
+ end
28
+ end
29
+ end
@@ -11,6 +11,14 @@ module StripeMock
11
11
  display_name: "Stripe.com",
12
12
  timezone: "US/Pacific",
13
13
  details_submitted: false,
14
+ capabilities: {
15
+ bank_transfer_payments: "active",
16
+ card_payments: "active",
17
+ ideal_payments: "active",
18
+ sepa_bank_transfer_payments: "active",
19
+ sepa_debit_payments:"active",
20
+ transfers:"active"
21
+ },
14
22
  charges_enabled: false,
15
23
  payouts_enabled: false,
16
24
  currencies_supported: [
@@ -34,10 +42,15 @@ module StripeMock
34
42
 
35
43
  ]
36
44
  },
37
- verification: {
38
- fields_needed: [],
39
- due_by: nil,
40
- contacted: false
45
+ requirements: {
46
+ alternatives: [],
47
+ current_deadline: nil,
48
+ currently_due: [],
49
+ disabled_reason: nil,
50
+ errors: [],
51
+ eventually_due: [],
52
+ past_due: [],
53
+ pending_verification: []
41
54
  },
42
55
  transfer_schedule: {
43
56
  delay_days: 7,
@@ -122,6 +135,25 @@ module StripeMock
122
135
  }.merge(params)
123
136
  end
124
137
 
138
+ def self.mock_tax_id(params)
139
+ {
140
+ id: 'test_cus_default',
141
+ object: 'tax_id',
142
+ country: 'DE',
143
+ created: 1559079603,
144
+ customer: nil,
145
+ livemode: false,
146
+ type: 'eu_vat',
147
+ value: 'DE123456789',
148
+ verification: nil,
149
+ owner: {
150
+ type: 'self',
151
+ customer: nil
152
+ },
153
+ metadata: {}
154
+ }.merge(params)
155
+ end
156
+
125
157
  def self.mock_tax_rate(params)
126
158
  {
127
159
  id: 'test_cus_default',
@@ -382,7 +414,8 @@ module StripeMock
382
414
  currency: StripeMock.default_currency
383
415
  },
384
416
  quantity: 1
385
- }]
417
+ }],
418
+ has_more: false
386
419
  },
387
420
  cancel_at_period_end: false,
388
421
  canceled_at: nil,
@@ -401,7 +434,12 @@ module StripeMock
401
434
  default_payment_method: nil,
402
435
  pending_invoice_item_interval: nil,
403
436
  next_pending_invoice_item_invoice: nil,
404
- latest_invoice: nil
437
+ pending_setup_intent: nil,
438
+ latest_invoice: nil,
439
+ application_fee_percent: nil,
440
+ cancel_at: nil,
441
+ end_at: nil,
442
+ pause_collection: nil
405
443
  }, params)
406
444
  end
407
445
 
@@ -642,15 +680,18 @@ module StripeMock
642
680
  attributes:[],
643
681
  caption: nil,
644
682
  created: 1466698000,
683
+ default_price: nil,
645
684
  deactivate_on: [],
646
685
  description: nil,
647
686
  images: [],
687
+ marketing_features: [],
648
688
  livemode: false,
649
689
  metadata: {},
650
690
  name: "The Mock Product",
651
691
  package_dimensions: nil,
652
692
  shippable: nil,
653
693
  statement_descriptor: nil,
694
+ tax_code: nil,
654
695
  type: "service",
655
696
  unit_label: "my_unit",
656
697
  updated: 1537939442,
@@ -1221,7 +1262,8 @@ module StripeMock
1221
1262
  statement_descriptor: nil,
1222
1263
  trial_period_days: nil
1223
1264
  },
1224
- quantity: 2
1265
+ quantity: 2,
1266
+ price: mock_price
1225
1267
  }.merge(params)
1226
1268
  end
1227
1269
 
@@ -1336,7 +1378,17 @@ module StripeMock
1336
1378
  country: 'DE',
1337
1379
  fingerprint: 'FD81kbVPe7M05BMj',
1338
1380
  last4: params.dig(:sepa_debit, :iban)&.[](-4..) || '3000'
1339
- }
1381
+ },
1382
+ us_bank_account: {
1383
+ account_holder_type: "individual",
1384
+ account_type: "checking",
1385
+ bank_name: "STRIPE TEST BANK",
1386
+ financial_connections_account: "fca_0614042384b19afec4474940",
1387
+ fingerprint: "7bc48d016359a45a",
1388
+ last4: "6789",
1389
+ networks: {"preferred"=>"ach", "supported"=>["ach"]},
1390
+ routing_number: "110000000"
1391
+ },
1340
1392
  }
1341
1393
 
1342
1394
  {
@@ -1396,7 +1448,7 @@ module StripeMock
1396
1448
  id: cs_id,
1397
1449
  object: 'checkout.session',
1398
1450
  billing_address_collection: nil,
1399
- cancel_url: 'https://example.com/cancel',
1451
+ cancel_url: nil,
1400
1452
  client_reference_id: nil,
1401
1453
  customer: nil,
1402
1454
  customer_email: nil,
@@ -52,6 +52,7 @@ module StripeMock
52
52
  include StripeMock::RequestHandlers::CountrySpec
53
53
  include StripeMock::RequestHandlers::Payouts
54
54
  include StripeMock::RequestHandlers::EphemeralKey
55
+ include StripeMock::RequestHandlers::TaxIds
55
56
  include StripeMock::RequestHandlers::TaxRates
56
57
  include StripeMock::RequestHandlers::Checkout
57
58
  include StripeMock::RequestHandlers::Checkout::Session
@@ -59,7 +60,7 @@ module StripeMock
59
60
  attr_reader :accounts, :balance, :balance_transactions, :bank_tokens, :charges, :coupons, :customers,
60
61
  :disputes, :events, :invoices, :invoice_items, :orders, :payment_intents, :payment_methods,
61
62
  :setup_intents, :plans, :prices, :promotion_codes, :recipients, :refunds, :transfers, :payouts,
62
- :subscriptions, :country_spec, :subscriptions_items, :products, :tax_rates, :checkout_sessions,
63
+ :subscriptions, :country_spec, :subscriptions_items, :products, :tax_ids, :tax_rates, :checkout_sessions,
63
64
  :checkout_session_line_items
64
65
 
65
66
  attr_accessor :error_queue, :debug, :conversion_rate, :account_balance
@@ -93,6 +94,7 @@ module StripeMock
93
94
  @subscriptions = {}
94
95
  @subscriptions_items = {}
95
96
  @country_spec = {}
97
+ @tax_ids = {}
96
98
  @tax_rates = {}
97
99
  @checkout_sessions = {}
98
100
  @checkout_session_line_items = {}
@@ -109,7 +111,23 @@ module StripeMock
109
111
  @base_strategy = TestStrategies::Base.new
110
112
  end
111
113
 
112
- def mock_request(method, url, api_key: nil, api_base: nil, usage: [], params: {}, headers: {})
114
+ def mock_request(*args, **kwargs)
115
+ if args.length == 2 && kwargs.key?(:api_key) # Legacy signature
116
+ method, url = args
117
+ api_key = kwargs[:api_key]
118
+ params = kwargs[:params] || {}
119
+ headers = kwargs[:headers] || {}
120
+ elsif args.length == 6 # New signature
121
+ method, url, base_address, params, opts, usage = args
122
+ client = Compat.client_instance
123
+ config = client.send(:config)
124
+ opts = Stripe::RequestOptions.merge_config_and_opts(config, opts)
125
+ headers = client.send(:request_headers, method, Stripe::Util.get_api_mode(url), opts)
126
+ headers = headers.transform_keys { |key| Util.snake_case(key).to_sym }
127
+ else
128
+ raise ArgumentError, "Invalid arguments for mock_request"
129
+ end
130
+
113
131
  return {} if method == :xtest
114
132
 
115
133
  api_key ||= (Stripe.api_key || DUMMY_API_KEY)
@@ -132,12 +150,21 @@ module StripeMock
132
150
  else
133
151
  res = self.send(handler[:name], handler[:route], method_url, params, headers)
134
152
  puts " [res] #{res}" if @debug == true
135
- [to_faraday_hash(res), api_key]
153
+
154
+ if Compat.stripe_gte_13?
155
+ [to_net_http(res, headers), opts]
156
+ else
157
+ [to_faraday_hash(res), api_key]
158
+ end
136
159
  end
137
160
  else
138
161
  puts "[StripeMock] Warning : Unrecognized endpoint + method : [#{method} #{url}]"
139
162
  puts "[StripeMock] params: #{params}" unless params.empty?
140
- [{}, api_key]
163
+ if Compat.stripe_gte_13?
164
+ [{}, opts]
165
+ else
166
+ [{}, api_key]
167
+ end
141
168
  end
142
169
  end
143
170
 
@@ -222,6 +249,22 @@ module StripeMock
222
249
  response.new(hash)
223
250
  end
224
251
 
252
+ def to_net_http(hash, headers)
253
+ headers = headers.slice(*%w[request-id stripe-account-id stripe-version stripe-version-stabl idempotency-key content-type])
254
+ fake_net_http_response(code: "200", message: "OK", body: hash.to_json, headers: headers)
255
+ end
256
+
257
+ def fake_net_http_response(code: "200", message: "OK", body: "{}", headers: {})
258
+ response_class = Net::HTTPResponse::CODE_TO_OBJ[code]
259
+ response = response_class.new("1.1", code, message)
260
+ headers.each { |k, v| response[k] = v }
261
+ response.instance_variable_set(:@body, body)
262
+ response.instance_variable_set(:@read, true)
263
+
264
+ response
265
+ end
266
+
267
+
225
268
  def calculate_fees(params)
226
269
  application_fee = params[:application_fee] || 0
227
270
  params[:fee] = processing_fee(params[:amount]) + application_fee