stripe-ruby-mock 4.0.0 → 4.1.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.
- checksums.yaml +4 -4
- data/.github/workflows/rspec_tests.yml +7 -10
- data/CHANGELOG.md +16 -0
- data/bin/stripe-mock-server +1 -0
- data/lib/stripe_mock/data.rb +53 -9
- data/lib/stripe_mock/instance.rb +3 -1
- data/lib/stripe_mock/request_handlers/checkout_session.rb +12 -11
- data/lib/stripe_mock/request_handlers/invoices.rb +8 -2
- data/lib/stripe_mock/request_handlers/payment_intents.rb +1 -1
- data/lib/stripe_mock/request_handlers/payment_methods.rb +5 -1
- data/lib/stripe_mock/request_handlers/payouts.rb +10 -3
- data/lib/stripe_mock/request_handlers/subscriptions.rb +1 -1
- data/lib/stripe_mock/request_handlers/tax_ids.rb +66 -0
- data/lib/stripe_mock/server.rb +9 -4
- data/lib/stripe_mock/test_strategies/base.rb +0 -1
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock.rb +1 -0
- data/spec/shared_stripe_examples/checkout_session_examples.rb +0 -5
- data/spec/shared_stripe_examples/payment_intent_examples.rb +13 -13
- data/spec/shared_stripe_examples/payment_method_examples.rb +10 -0
- data/spec/shared_stripe_examples/payout_examples.rb +26 -6
- data/spec/shared_stripe_examples/product_examples.rb +3 -0
- data/stripe-ruby-mock.gemspec +2 -1
- metadata +26 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 148628f00d214cfaa405f65529b1b8155da9475063166370b0b287084afcd0d4
|
4
|
+
data.tar.gz: ac5f7249f7a83d1fe2ac9f7a1eb4ff007465b404289f1f8bd60d277fe110d4d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8627e73ab695f6a0403d8438abb979a3b4b241d1b04419a2e82844225426dbd19a02eef3ac95a719f644ece575090e46f68b504ab83d5a865e46d1e14f353099
|
7
|
+
data.tar.gz: 9ea4b6e5b061a0d8342f4459fd558df25df4888bf713142e21263e73029411e6f226baa86eb6341de726891cb4245a34ef0c0d744e21b378d6afe0dcae64eda8
|
@@ -18,21 +18,18 @@ permissions:
|
|
18
18
|
|
19
19
|
jobs:
|
20
20
|
test:
|
21
|
-
|
22
21
|
runs-on: ubuntu-latest
|
23
22
|
strategy:
|
24
23
|
matrix:
|
25
|
-
ruby
|
26
|
-
|
24
|
+
ruby: ['3.1', '3.2', '3.3']
|
27
25
|
steps:
|
28
|
-
- uses: actions/checkout@
|
29
|
-
- name:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
|
26
|
+
- uses: actions/checkout@v4
|
27
|
+
- name: Install Ruby and gems
|
28
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
29
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
30
|
+
uses: ruby/setup-ruby@v1
|
34
31
|
with:
|
35
|
-
ruby-version: ${{ matrix.ruby
|
32
|
+
ruby-version: ${{ matrix.ruby }}
|
36
33
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
37
34
|
- name: Run tests
|
38
35
|
run: bundle exec rspec
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
### Unreleased
|
2
2
|
|
3
|
+
### 4.1.0 (2025-04-24)
|
4
|
+
- [#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)
|
5
|
+
- [#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)
|
6
|
+
- [#929](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/929) Actions uses only supported ruby versions [@alexmamonchik](https://github.com/alexmamonchik)
|
7
|
+
- [#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)
|
8
|
+
- [#928](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/928) Add tax ID endpoints and data [@lfittl](https://github.com/lfittl)
|
9
|
+
- [#835](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/835) Account: replace deprecated verification hash by requirements [@fabianoarruda](https://github.com/fabianoarruda)
|
10
|
+
- [#903](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/903) Add require option to require additional file [@stevenharman](https://github.com/stevenharman)
|
11
|
+
- [#904](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/904) Add has_more to Subscription.items data [@stevenharman](https://github.com/stevenharman)
|
12
|
+
- [#843](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/843) Some updates around subscriptions [@donnguyen](https://github.com/donnguyen)
|
13
|
+
- [#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)
|
14
|
+
- [#916](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/916) Better tests for payout [@espen](https://github.com/espen)
|
15
|
+
- [#862](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/862) Add simple support for us bank accounts [@smtlaissezfaire](https://github.com/smtlaissezfaire)
|
16
|
+
- [#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)
|
17
|
+
- [#908](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/908) Add update_payout [@espen](https://github.com/espen)
|
18
|
+
|
3
19
|
### 4.0.0 (2024-08-07)
|
4
20
|
- [#905](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/905) Allow Stripe SDK v11 by [@stevenharman ](https://github.com/stevenharman)
|
5
21
|
- [#830](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/830) Implement search API by [@adamstegman](https://github.com/adamstegman)
|
data/bin/stripe-mock-server
CHANGED
@@ -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'
|
data/lib/stripe_mock/data.rb
CHANGED
@@ -34,10 +34,15 @@ module StripeMock
|
|
34
34
|
|
35
35
|
]
|
36
36
|
},
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
requirements: {
|
38
|
+
alternatives: [],
|
39
|
+
current_deadline: nil,
|
40
|
+
currently_due: [],
|
41
|
+
disabled_reason: nil,
|
42
|
+
errors: [],
|
43
|
+
eventually_due: [],
|
44
|
+
past_due: [],
|
45
|
+
pending_verification: []
|
41
46
|
},
|
42
47
|
transfer_schedule: {
|
43
48
|
delay_days: 7,
|
@@ -122,6 +127,25 @@ module StripeMock
|
|
122
127
|
}.merge(params)
|
123
128
|
end
|
124
129
|
|
130
|
+
def self.mock_tax_id(params)
|
131
|
+
{
|
132
|
+
id: 'test_cus_default',
|
133
|
+
object: 'tax_id',
|
134
|
+
country: 'DE',
|
135
|
+
created: 1559079603,
|
136
|
+
customer: nil,
|
137
|
+
livemode: false,
|
138
|
+
type: 'eu_vat',
|
139
|
+
value: 'DE123456789',
|
140
|
+
verification: nil,
|
141
|
+
owner: {
|
142
|
+
type: 'self',
|
143
|
+
customer: nil
|
144
|
+
},
|
145
|
+
metadata: {}
|
146
|
+
}.merge(params)
|
147
|
+
end
|
148
|
+
|
125
149
|
def self.mock_tax_rate(params)
|
126
150
|
{
|
127
151
|
id: 'test_cus_default',
|
@@ -382,7 +406,8 @@ module StripeMock
|
|
382
406
|
currency: StripeMock.default_currency
|
383
407
|
},
|
384
408
|
quantity: 1
|
385
|
-
}]
|
409
|
+
}],
|
410
|
+
has_more: false
|
386
411
|
},
|
387
412
|
cancel_at_period_end: false,
|
388
413
|
canceled_at: nil,
|
@@ -401,7 +426,12 @@ module StripeMock
|
|
401
426
|
default_payment_method: nil,
|
402
427
|
pending_invoice_item_interval: nil,
|
403
428
|
next_pending_invoice_item_invoice: nil,
|
404
|
-
|
429
|
+
pending_setup_intent: nil,
|
430
|
+
latest_invoice: nil,
|
431
|
+
application_fee_percent: nil,
|
432
|
+
cancel_at: nil,
|
433
|
+
end_at: nil,
|
434
|
+
pause_collection: nil
|
405
435
|
}, params)
|
406
436
|
end
|
407
437
|
|
@@ -642,15 +672,18 @@ module StripeMock
|
|
642
672
|
attributes:[],
|
643
673
|
caption: nil,
|
644
674
|
created: 1466698000,
|
675
|
+
default_price: nil,
|
645
676
|
deactivate_on: [],
|
646
677
|
description: nil,
|
647
678
|
images: [],
|
679
|
+
marketing_features: [],
|
648
680
|
livemode: false,
|
649
681
|
metadata: {},
|
650
682
|
name: "The Mock Product",
|
651
683
|
package_dimensions: nil,
|
652
684
|
shippable: nil,
|
653
685
|
statement_descriptor: nil,
|
686
|
+
tax_code: nil,
|
654
687
|
type: "service",
|
655
688
|
unit_label: "my_unit",
|
656
689
|
updated: 1537939442,
|
@@ -1221,7 +1254,8 @@ module StripeMock
|
|
1221
1254
|
statement_descriptor: nil,
|
1222
1255
|
trial_period_days: nil
|
1223
1256
|
},
|
1224
|
-
quantity: 2
|
1257
|
+
quantity: 2,
|
1258
|
+
price: mock_price
|
1225
1259
|
}.merge(params)
|
1226
1260
|
end
|
1227
1261
|
|
@@ -1336,7 +1370,17 @@ module StripeMock
|
|
1336
1370
|
country: 'DE',
|
1337
1371
|
fingerprint: 'FD81kbVPe7M05BMj',
|
1338
1372
|
last4: params.dig(:sepa_debit, :iban)&.[](-4..) || '3000'
|
1339
|
-
}
|
1373
|
+
},
|
1374
|
+
us_bank_account: {
|
1375
|
+
account_holder_type: "individual",
|
1376
|
+
account_type: "checking",
|
1377
|
+
bank_name: "STRIPE TEST BANK",
|
1378
|
+
financial_connections_account: "fca_0614042384b19afec4474940",
|
1379
|
+
fingerprint: "7bc48d016359a45a",
|
1380
|
+
last4: "6789",
|
1381
|
+
networks: {"preferred"=>"ach", "supported"=>["ach"]},
|
1382
|
+
routing_number: "110000000"
|
1383
|
+
},
|
1340
1384
|
}
|
1341
1385
|
|
1342
1386
|
{
|
@@ -1396,7 +1440,7 @@ module StripeMock
|
|
1396
1440
|
id: cs_id,
|
1397
1441
|
object: 'checkout.session',
|
1398
1442
|
billing_address_collection: nil,
|
1399
|
-
cancel_url:
|
1443
|
+
cancel_url: nil,
|
1400
1444
|
client_reference_id: nil,
|
1401
1445
|
customer: nil,
|
1402
1446
|
customer_email: nil,
|
data/lib/stripe_mock/instance.rb
CHANGED
@@ -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 = {}
|
@@ -12,16 +12,17 @@ module StripeMock
|
|
12
12
|
def new_session(route, method_url, params, headers)
|
13
13
|
id = params[:id] || new_id('cs')
|
14
14
|
|
15
|
-
|
16
|
-
require_param(p) if params[p].nil? || params[p].empty?
|
17
|
-
end
|
15
|
+
require_param(:success_url) if params[:success_url].nil? || params[:success_url].empty?
|
18
16
|
|
19
17
|
line_items = nil
|
20
18
|
if params[:line_items]
|
21
19
|
line_items = params[:line_items].each_with_index.map do |line_item, i|
|
22
|
-
|
20
|
+
unless line_item[:quantity]
|
21
|
+
raise Stripe::InvalidRequestError.new("Quantity is required. Add `quantity` to `line_items[#{i}]`", :line_items)
|
22
|
+
end
|
23
|
+
|
23
24
|
unless line_item[:price] || line_item[:price_data] || (line_item[:amount] && line_item[:currency] && line_item[:name])
|
24
|
-
|
25
|
+
raise Stripe::InvalidRequestError.new("Price or amount and currency is required. Add `price`, `price_data`, or `amount`, `currency` and `name` to `line_items[#{i}]`", :line_items)
|
25
26
|
end
|
26
27
|
{
|
27
28
|
id: new_id("li"),
|
@@ -48,11 +49,11 @@ module StripeMock
|
|
48
49
|
if line_items
|
49
50
|
amount = 0
|
50
51
|
|
51
|
-
line_items.each do |line_item|
|
52
|
+
line_items.each do |line_item|
|
52
53
|
price = prices[line_item[:price]]
|
53
54
|
|
54
55
|
if price.nil?
|
55
|
-
raise StripeMock::StripeMockError.new("Price not found for ID: #{line_item[:price]}")
|
56
|
+
raise StripeMock::StripeMockError.new("Price not found for ID: #{line_item[:price]}", :line_items)
|
56
57
|
end
|
57
58
|
|
58
59
|
amount += (price[:unit_amount] * line_item[:quantity])
|
@@ -78,7 +79,7 @@ module StripeMock
|
|
78
79
|
checkout_session_line_items[id] = line_items
|
79
80
|
when "setup"
|
80
81
|
if !params[:line_items].nil? && !params[:line_items].empty?
|
81
|
-
|
82
|
+
raise Stripe::InvalidRequestError.new("You cannot pass `line_items` in `setup` mode", :line_items, http_status: 400)
|
82
83
|
end
|
83
84
|
setup_intent = new_setup_intent(nil, nil, {
|
84
85
|
customer: params[:customer],
|
@@ -91,7 +92,7 @@ module StripeMock
|
|
91
92
|
require_param(:line_items) if params[:line_items].nil? || params[:line_items].empty?
|
92
93
|
checkout_session_line_items[id] = line_items
|
93
94
|
else
|
94
|
-
|
95
|
+
raise Stripe::InvalidRequestError.new("Invalid mode: must be one of payment, setup, or subscription", :mode, http_status: 400)
|
95
96
|
end
|
96
97
|
|
97
98
|
checkout_sessions[id] = {
|
@@ -156,7 +157,7 @@ module StripeMock
|
|
156
157
|
price = prices[line_item[:price]].clone
|
157
158
|
|
158
159
|
if price.nil?
|
159
|
-
raise StripeMock::StripeMockError.new("Price not found for ID: #{line_item[:price]}")
|
160
|
+
raise StripeMock::StripeMockError.new("Price not found for ID: #{line_item[:price]}", :line_items)
|
160
161
|
end
|
161
162
|
|
162
163
|
{
|
@@ -170,7 +171,7 @@ module StripeMock
|
|
170
171
|
}
|
171
172
|
end
|
172
173
|
else
|
173
|
-
|
174
|
+
raise Stripe::InvalidRequestError.new("Only payment and subscription sessions have line items", :line_items)
|
174
175
|
end
|
175
176
|
end
|
176
177
|
end
|
@@ -77,6 +77,9 @@ module StripeMock
|
|
77
77
|
raise Stripe::InvalidRequestError.new('When previewing changes to a subscription, you must specify either `subscription` or `subscription_items`', nil, http_status: 400) if !params[:subscription_proration_date].nil? && params[:subscription].nil? && params[:subscription_plan].nil?
|
78
78
|
raise Stripe::InvalidRequestError.new('Cannot specify proration date without specifying a subscription', nil, http_status: 400) if !params[:subscription_proration_date].nil? && params[:subscription].nil?
|
79
79
|
|
80
|
+
if params[:subscription] && params[:customer].nil?
|
81
|
+
params[:customer] = subscriptions[params[:subscription]][:customer]
|
82
|
+
end
|
80
83
|
customer = customers[stripe_account][params[:customer]]
|
81
84
|
assert_existence :customer, params[:customer], customer
|
82
85
|
|
@@ -114,8 +117,9 @@ module StripeMock
|
|
114
117
|
invoice_lines = []
|
115
118
|
|
116
119
|
if prorating
|
120
|
+
plan_amount = subscription[:plan][:amount] || subscription[:plan][:unit_amount]
|
117
121
|
unused_amount = (
|
118
|
-
|
122
|
+
plan_amount.to_f *
|
119
123
|
subscription[:quantity] *
|
120
124
|
(subscription[:current_period_end] - subscription_proration_date.to_i) / (subscription[:current_period_end] - subscription[:current_period_start])
|
121
125
|
).ceil
|
@@ -169,11 +173,13 @@ module StripeMock
|
|
169
173
|
private
|
170
174
|
|
171
175
|
def get_mock_subscription_line_item(subscription)
|
176
|
+
plan_amount = subscription[:plan][:amount] || subscription[:plan][:unit_amount]
|
177
|
+
|
172
178
|
Data.mock_line_item(
|
173
179
|
id: subscription[:id],
|
174
180
|
type: "subscription",
|
175
181
|
plan: subscription[:plan],
|
176
|
-
amount: subscription[:status] == 'trialing' ? 0 :
|
182
|
+
amount: subscription[:status] == 'trialing' ? 0 : plan_amount * subscription[:quantity],
|
177
183
|
discountable: true,
|
178
184
|
quantity: subscription[:quantity],
|
179
185
|
period: {
|
@@ -116,8 +116,12 @@ module StripeMock
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
+
def valid_types
|
120
|
+
%w(card ideal sepa_debit us_bank_account)
|
121
|
+
end
|
122
|
+
|
119
123
|
def invalid_type?(type)
|
120
|
-
|
124
|
+
!valid_types.include?(type)
|
121
125
|
end
|
122
126
|
end
|
123
127
|
end
|
@@ -4,18 +4,25 @@ module StripeMock
|
|
4
4
|
|
5
5
|
def Payouts.included(klass)
|
6
6
|
klass.add_handler 'post /v1/payouts', :new_payout
|
7
|
+
klass.add_handler 'post /v1/payouts/(.*)', :update_payout
|
7
8
|
klass.add_handler 'get /v1/payouts', :list_payouts
|
8
9
|
klass.add_handler 'get /v1/payouts/(.*)', :get_payout
|
9
10
|
end
|
10
11
|
|
11
12
|
def new_payout(route, method_url, params, headers)
|
12
|
-
id
|
13
|
+
params[:id] ||= new_id("po")
|
13
14
|
|
14
|
-
unless params[:amount].is_a?(Integer) || (params[:amount].is_a?(String) && /^\d+$/.match(params[:amount]))
|
15
|
+
unless (params[:amount].is_a?(Integer) && params[:amount].positive?) || (params[:amount].is_a?(String) && /^\d+$/.match(params[:amount]))
|
15
16
|
raise Stripe::InvalidRequestError.new("Invalid integer: #{params[:amount]}", 'amount', http_status: 400)
|
16
17
|
end
|
17
18
|
|
18
|
-
payouts[id] = Data.mock_payout(params.merge :id => id)
|
19
|
+
payouts[params[:id]] = Data.mock_payout(params.merge :id => params[:id])
|
20
|
+
end
|
21
|
+
|
22
|
+
def update_payout(route, method_url, params, headers)
|
23
|
+
route =~ method_url
|
24
|
+
assert_existence :payout, $1, payouts[$1]
|
25
|
+
payouts[$1].merge!(params)
|
19
26
|
end
|
20
27
|
|
21
28
|
def list_payouts(route, method_url, params, headers)
|
@@ -167,7 +167,7 @@ module StripeMock
|
|
167
167
|
end
|
168
168
|
|
169
169
|
if params[:transfer_data] && !params[:transfer_data].empty?
|
170
|
-
|
170
|
+
raise Stripe::InvalidRequestError.new(missing_param_message("transfer_data[destination]")) unless params[:transfer_data][:destination]
|
171
171
|
subscription[:transfer_data] = params[:transfer_data].dup
|
172
172
|
subscription[:transfer_data][:amount_percent] ||= 100
|
173
173
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module TaxIds
|
4
|
+
def TaxIds.included(klass)
|
5
|
+
klass.add_handler 'post /v1/tax_ids', :new_tax_id
|
6
|
+
klass.add_handler 'post /v1/customers/(.*)/tax_ids', :new_customer_tax_id
|
7
|
+
klass.add_handler 'get /v1/tax_ids/([^/]*)', :get_tax_id
|
8
|
+
klass.add_handler 'get /v1/customers/(.*)/tax_ids/([^/]*)', :get_customer_tax_id
|
9
|
+
klass.add_handler 'get /v1/tax_ids', :list_tax_ids
|
10
|
+
klass.add_handler 'get /v1/customers/(.*)/tax_ids', :list_customer_tax_ids
|
11
|
+
klass.add_handler 'delete /v1/tax_ids/([^/]*)', :delete_tax_id
|
12
|
+
klass.add_handler 'delete /v1/customers/(.*)/tax_ids/([^/]*)', :delete_customer_tax_id
|
13
|
+
end
|
14
|
+
|
15
|
+
def new_tax_id(route, method_url, params, headers)
|
16
|
+
params[:id] ||= new_id('txi')
|
17
|
+
tax_ids[ params[:id] ] = Data.mock_tax_id(params)
|
18
|
+
tax_ids[ params[:id] ]
|
19
|
+
end
|
20
|
+
def new_customer_tax_id(route, method_url, params, headers)
|
21
|
+
new_tax_id(route, method_url, params.merge(customer: $1))
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_tax_id(route, method_url, params, headers)
|
25
|
+
route =~ method_url
|
26
|
+
tax_id = assert_existence :tax_id, $1, tax_ids[$1]
|
27
|
+
tax_id.clone
|
28
|
+
end
|
29
|
+
def get_customer_tax_id(route, method_url, params, headers)
|
30
|
+
route =~ method_url
|
31
|
+
tax_id = tax_ids[$2]
|
32
|
+
tax_id = nil if tax_id[:customer] != $1
|
33
|
+
tax_id = assert_existence :tax_id, $2, tax_id
|
34
|
+
tax_id.clone
|
35
|
+
end
|
36
|
+
|
37
|
+
def list_tax_ids(route, method_url, params, headers)
|
38
|
+
Data.mock_list_object(tax_ids.values, params)
|
39
|
+
end
|
40
|
+
def list_customer_tax_ids(route, method_url, params, headers)
|
41
|
+
Data.mock_list_object(tax_ids.values.select { |t| t[:customer] == $1 }, params)
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete_tax_id(route, method_url, params, headers)
|
45
|
+
route =~ method_url
|
46
|
+
assert_existence :tax_id, $1, tax_ids[$1]
|
47
|
+
|
48
|
+
tax_ids[$1] = {
|
49
|
+
id: tax_ids[$1][:id],
|
50
|
+
deleted: true
|
51
|
+
}
|
52
|
+
end
|
53
|
+
def delete_customer_tax_id(route, method_url, params, headers)
|
54
|
+
route =~ method_url
|
55
|
+
tax_id = tax_ids[$2]
|
56
|
+
tax_id = nil if tax_id[:customer] != $1
|
57
|
+
tax_id = assert_existence :tax_id, $2, tax_id
|
58
|
+
|
59
|
+
tax_ids[$2] = {
|
60
|
+
id: tax_ids[$2][:id],
|
61
|
+
deleted: true
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/stripe_mock/server.rb
CHANGED
@@ -3,10 +3,16 @@ require 'drb/drb'
|
|
3
3
|
module StripeMock
|
4
4
|
class Server
|
5
5
|
def self.start_new(opts)
|
6
|
-
|
6
|
+
host = opts.fetch(:host, "0.0.0.0")
|
7
|
+
port = opts.fetch(:port, 4999)
|
8
|
+
extra_requires = opts.fetch(:require, [])
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
extra_requires.each do |path|
|
11
|
+
puts "Requiring additional path: #{path}"
|
12
|
+
require(path)
|
13
|
+
end
|
14
|
+
|
15
|
+
puts "Starting StripeMock server on port #{port}"
|
10
16
|
|
11
17
|
DRb.start_service "druby://#{host}:#{port}", Server.new
|
12
18
|
DRb.thread.join
|
@@ -88,6 +94,5 @@ module StripeMock
|
|
88
94
|
def upsert_stripe_object(object, attributes)
|
89
95
|
@instance.upsert_stripe_object(object, attributes)
|
90
96
|
end
|
91
|
-
|
92
97
|
end
|
93
98
|
end
|
data/lib/stripe_mock/version.rb
CHANGED
data/lib/stripe_mock.rb
CHANGED
@@ -80,6 +80,7 @@ require 'stripe_mock/request_handlers/tokens.rb'
|
|
80
80
|
require 'stripe_mock/request_handlers/country_spec.rb'
|
81
81
|
require 'stripe_mock/request_handlers/ephemeral_key.rb'
|
82
82
|
require 'stripe_mock/request_handlers/products.rb'
|
83
|
+
require 'stripe_mock/request_handlers/tax_ids.rb'
|
83
84
|
require 'stripe_mock/request_handlers/tax_rates.rb'
|
84
85
|
require 'stripe_mock/request_handlers/checkout_session.rb'
|
85
86
|
require 'stripe_mock/instance'
|
@@ -11,7 +11,6 @@ shared_examples "Checkout Session API" do
|
|
11
11
|
session = Stripe::Checkout::Session.create(
|
12
12
|
payment_method_types: ["card"],
|
13
13
|
line_items: line_items,
|
14
|
-
cancel_url: "https://example.com/cancel",
|
15
14
|
success_url: "https://example.com/success"
|
16
15
|
)
|
17
16
|
|
@@ -28,7 +27,6 @@ shared_examples "Checkout Session API" do
|
|
28
27
|
session = Stripe::Checkout::Session.create(
|
29
28
|
customer: "customer_id",
|
30
29
|
success_url: "localhost/nada",
|
31
|
-
cancel_url: "localhost/nada",
|
32
30
|
payment_method_types: ["card"],
|
33
31
|
)
|
34
32
|
end.to raise_error(Stripe::InvalidRequestError, /line_items/i)
|
@@ -40,7 +38,6 @@ shared_examples "Checkout Session API" do
|
|
40
38
|
session = Stripe::Checkout::Session.create(
|
41
39
|
mode: "setup",
|
42
40
|
payment_method_types: ["card"],
|
43
|
-
cancel_url: "https://example.com/cancel",
|
44
41
|
success_url: "https://example.com/success"
|
45
42
|
)
|
46
43
|
|
@@ -55,7 +52,6 @@ shared_examples "Checkout Session API" do
|
|
55
52
|
session = Stripe::Checkout::Session.create(
|
56
53
|
customer: "customer_id",
|
57
54
|
success_url: "localhost/nada",
|
58
|
-
cancel_url: "localhost/nada",
|
59
55
|
payment_method_types: ["card"],
|
60
56
|
mode: "subscription",
|
61
57
|
)
|
@@ -86,7 +82,6 @@ shared_examples "Checkout Session API" do
|
|
86
82
|
it "can expand setup_intent" do
|
87
83
|
initial_session = Stripe::Checkout::Session.create(
|
88
84
|
mode: "setup",
|
89
|
-
cancel_url: "https://example.com",
|
90
85
|
success_url: "https://example.com",
|
91
86
|
payment_method_types: ["card"]
|
92
87
|
)
|
@@ -90,9 +90,9 @@ shared_examples 'PaymentIntent API' do
|
|
90
90
|
amount: 100, currency: 'usd', confirm: true
|
91
91
|
)
|
92
92
|
expect(payment_intent.status).to eq('succeeded')
|
93
|
-
|
94
|
-
expect(
|
95
|
-
balance_txn =
|
93
|
+
charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
|
94
|
+
expect(charge.object).to eq('charge')
|
95
|
+
balance_txn = charge.balance_transaction
|
96
96
|
expect(balance_txn).to match(/^test_txn/)
|
97
97
|
expect(Stripe::BalanceTransaction.retrieve(balance_txn).id).to eq(balance_txn)
|
98
98
|
end
|
@@ -104,7 +104,7 @@ shared_examples 'PaymentIntent API' do
|
|
104
104
|
customer: customer,
|
105
105
|
payment_method: customer.sources.first
|
106
106
|
|
107
|
-
charge = payment_intent.
|
107
|
+
charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
|
108
108
|
expect(charge.amount).to eq(payment_intent.amount)
|
109
109
|
expect(charge.payment_intent).to eq(payment_intent.id)
|
110
110
|
expect(charge.description).to be_nil
|
@@ -121,17 +121,17 @@ shared_examples 'PaymentIntent API' do
|
|
121
121
|
amount: 100, currency: "usd", confirm: true, payment_method: "test_pm_1"
|
122
122
|
)
|
123
123
|
expect(payment_intent.status).to eq("succeeded")
|
124
|
-
|
125
|
-
expect(
|
126
|
-
expect(
|
124
|
+
charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
|
125
|
+
expect(charge.object).to eq("charge")
|
126
|
+
expect(charge.payment_method).to eq("test_pm_1")
|
127
127
|
end
|
128
128
|
|
129
129
|
it "confirms a stripe payment_intent" do
|
130
130
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
131
131
|
confirmed_payment_intent = payment_intent.confirm()
|
132
132
|
expect(confirmed_payment_intent.status).to eq("succeeded")
|
133
|
-
|
134
|
-
expect(
|
133
|
+
charge = Stripe::Charge.retrieve(confirmed_payment_intent.latest_charge)
|
134
|
+
expect(charge.object).to eq('charge')
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'creates a charge for a confirmed stripe payment_intent' do
|
@@ -141,7 +141,7 @@ shared_examples 'PaymentIntent API' do
|
|
141
141
|
payment_method: customer.sources.first
|
142
142
|
|
143
143
|
confirmed_payment_intent = payment_intent.confirm
|
144
|
-
charge =
|
144
|
+
charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
|
145
145
|
expect(charge.amount).to eq(confirmed_payment_intent.amount)
|
146
146
|
expect(charge.payment_intent).to eq(confirmed_payment_intent.id)
|
147
147
|
expect(charge.description).to be_nil
|
@@ -157,8 +157,8 @@ shared_examples 'PaymentIntent API' do
|
|
157
157
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
158
158
|
confirmed_payment_intent = payment_intent.capture()
|
159
159
|
expect(confirmed_payment_intent.status).to eq("succeeded")
|
160
|
-
|
161
|
-
expect(
|
160
|
+
charge = Stripe::Charge.retrieve(confirmed_payment_intent.latest_charge)
|
161
|
+
expect(charge.object).to eq('charge')
|
162
162
|
end
|
163
163
|
|
164
164
|
it 'creates a charge for a captured stripe payment_intent' do
|
@@ -170,7 +170,7 @@ shared_examples 'PaymentIntent API' do
|
|
170
170
|
capture_method: 'manual'
|
171
171
|
|
172
172
|
captured_payment_intent = payment_intent.capture
|
173
|
-
charge = captured_payment_intent.
|
173
|
+
charge = Stripe::Charge.retrieve(captured_payment_intent.latest_charge)
|
174
174
|
expect(charge.amount).to eq(captured_payment_intent.amount)
|
175
175
|
expect(charge.payment_intent).to eq(captured_payment_intent.id)
|
176
176
|
expect(charge.description).to be_nil
|
@@ -450,5 +450,15 @@ shared_examples 'PaymentMethod API' do
|
|
450
450
|
end.to raise_error(Stripe::InvalidRequestError)
|
451
451
|
end
|
452
452
|
end
|
453
|
+
|
454
|
+
context 'with us_bank_account' do
|
455
|
+
let(:payment_method) do
|
456
|
+
Stripe::PaymentMethod.create(type: 'us_bank_account')
|
457
|
+
end
|
458
|
+
|
459
|
+
it 'works' do
|
460
|
+
expect(payment_method.type).to eq('us_bank_account')
|
461
|
+
end
|
462
|
+
end
|
453
463
|
end
|
454
464
|
end
|
@@ -3,10 +3,10 @@ require 'spec_helper'
|
|
3
3
|
shared_examples 'Payout API' do
|
4
4
|
|
5
5
|
it "creates a stripe payout" do
|
6
|
-
payout = Stripe::Payout.create(amount:
|
6
|
+
payout = Stripe::Payout.create(amount: 100, currency: "usd")
|
7
7
|
|
8
8
|
expect(payout.id).to match(/^test_po/)
|
9
|
-
expect(payout.amount).to eq(
|
9
|
+
expect(payout.amount).to eq(100)
|
10
10
|
expect(payout.currency).to eq('usd')
|
11
11
|
expect(payout.metadata.to_hash).to eq({})
|
12
12
|
end
|
@@ -14,7 +14,7 @@ shared_examples 'Payout API' do
|
|
14
14
|
describe "listing payouts" do
|
15
15
|
before do
|
16
16
|
3.times do
|
17
|
-
Stripe::Payout.create(amount:
|
17
|
+
Stripe::Payout.create(amount: 100, currency: "usd")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -28,7 +28,7 @@ shared_examples 'Payout API' do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "retrieves a stripe payout" do
|
31
|
-
original = Stripe::Payout.create(amount:
|
31
|
+
original = Stripe::Payout.create(amount: 100, currency: "usd")
|
32
32
|
payout = Stripe::Payout.retrieve(original.id)
|
33
33
|
|
34
34
|
expect(payout.id).to eq(original.id)
|
@@ -37,6 +37,25 @@ shared_examples 'Payout API' do
|
|
37
37
|
expect(payout.metadata.to_hash).to eq(original.metadata.to_hash)
|
38
38
|
end
|
39
39
|
|
40
|
+
it "updates a stripe payout using method" do
|
41
|
+
original = Stripe::Payout.create(amount: 100, currency: "usd")
|
42
|
+
updated = Stripe::Payout.update(original.id, amount: 1337)
|
43
|
+
payout = Stripe::Payout.retrieve(original.id)
|
44
|
+
expect(payout.amount).to eq(1337)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "updates a stripe payout object" do
|
48
|
+
original = Stripe::Payout.create(amount: 100, currency: "usd")
|
49
|
+
payout = Stripe::Payout.retrieve(original.id)
|
50
|
+
|
51
|
+
expect(payout.id).to eq(original.id)
|
52
|
+
|
53
|
+
payout.amount = 1337
|
54
|
+
payout.save
|
55
|
+
payout = Stripe::Payout.retrieve(original.id)
|
56
|
+
expect(payout.amount).to eq(1337)
|
57
|
+
end
|
58
|
+
|
40
59
|
it "cannot retrieve a payout that doesn't exist" do
|
41
60
|
expect { Stripe::Payout.retrieve('nope') }.to raise_error {|e|
|
42
61
|
expect(e).to be_a Stripe::InvalidRequestError
|
@@ -46,17 +65,18 @@ shared_examples 'Payout API' do
|
|
46
65
|
end
|
47
66
|
|
48
67
|
it 'when amount is not integer', live: true do
|
49
|
-
expect { Stripe::Payout.create(amount:
|
68
|
+
expect { Stripe::Payout.create(amount: 400.2,
|
50
69
|
currency: 'usd',
|
51
70
|
description: 'Payout for test@example.com') }.to raise_error { |e|
|
52
71
|
expect(e).to be_a Stripe::InvalidRequestError
|
53
72
|
expect(e.param).to eq('amount')
|
73
|
+
expect(e.message).to match(/^Invalid.*integer/)
|
54
74
|
expect(e.http_status).to eq(400)
|
55
75
|
}
|
56
76
|
end
|
57
77
|
|
58
78
|
it 'when amount is negative', live: true do
|
59
|
-
expect { Stripe::Payout.create(amount:
|
79
|
+
expect { Stripe::Payout.create(amount: -400,
|
60
80
|
currency: 'usd',
|
61
81
|
description: 'Payout for test@example.com') }.to raise_error { |e|
|
62
82
|
expect(e).to be_a Stripe::InvalidRequestError
|
@@ -192,15 +192,18 @@ shared_examples "Product API" do
|
|
192
192
|
:attributes,
|
193
193
|
:caption,
|
194
194
|
:created,
|
195
|
+
:default_price,
|
195
196
|
:deactivate_on,
|
196
197
|
:description,
|
197
198
|
:images,
|
199
|
+
:marketing_features,
|
198
200
|
:livemode,
|
199
201
|
:metadata,
|
200
202
|
:name,
|
201
203
|
:package_dimensions,
|
202
204
|
:shippable,
|
203
205
|
:statement_descriptor,
|
206
|
+
:tax_code,
|
204
207
|
:type,
|
205
208
|
:unit_label,
|
206
209
|
:updated,
|
data/stripe-ruby-mock.gemspec
CHANGED
@@ -22,9 +22,10 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
23
23
|
gem.require_paths = ['lib']
|
24
24
|
|
25
|
-
gem.add_dependency 'stripe', '> 5', '<
|
25
|
+
gem.add_dependency 'stripe', '> 5', '< 13'
|
26
26
|
gem.add_dependency 'multi_json', '~> 1.0'
|
27
27
|
gem.add_dependency 'dante', '>= 0.2.0'
|
28
|
+
gem.add_dependency 'drb', '>= 2.0.4', '< 3'
|
28
29
|
|
29
30
|
gem.add_development_dependency 'rspec', '~> 3.13.0'
|
30
31
|
gem.add_development_dependency 'thin', '~> 1.8.1'
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe-ruby-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilbert
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: stripe
|
@@ -19,7 +18,7 @@ dependencies:
|
|
19
18
|
version: '5'
|
20
19
|
- - "<"
|
21
20
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
21
|
+
version: '13'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +28,7 @@ dependencies:
|
|
29
28
|
version: '5'
|
30
29
|
- - "<"
|
31
30
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
31
|
+
version: '13'
|
33
32
|
- !ruby/object:Gem::Dependency
|
34
33
|
name: multi_json
|
35
34
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +57,26 @@ dependencies:
|
|
58
57
|
- - ">="
|
59
58
|
- !ruby/object:Gem::Version
|
60
59
|
version: 0.2.0
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: drb
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.0.4
|
67
|
+
- - "<"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.0.4
|
77
|
+
- - "<"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '3'
|
61
80
|
- !ruby/object:Gem::Dependency
|
62
81
|
name: rspec
|
63
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,6 +186,7 @@ files:
|
|
167
186
|
- lib/stripe_mock/request_handlers/sources.rb
|
168
187
|
- lib/stripe_mock/request_handlers/subscription_items.rb
|
169
188
|
- lib/stripe_mock/request_handlers/subscriptions.rb
|
189
|
+
- lib/stripe_mock/request_handlers/tax_ids.rb
|
170
190
|
- lib/stripe_mock/request_handlers/tax_rates.rb
|
171
191
|
- lib/stripe_mock/request_handlers/tokens.rb
|
172
192
|
- lib/stripe_mock/request_handlers/transfers.rb
|
@@ -329,7 +349,6 @@ metadata:
|
|
329
349
|
bug_tracker_uri: https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues
|
330
350
|
changelog_uri: https://github.com/stripe-ruby-mock/stripe-ruby-mock/blob/master/CHANGELOG.md
|
331
351
|
source_code_uri: https://github.com/stripe-ruby-mock/stripe-ruby-mock
|
332
|
-
post_install_message:
|
333
352
|
rdoc_options: []
|
334
353
|
require_paths:
|
335
354
|
- lib
|
@@ -344,8 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
344
363
|
- !ruby/object:Gem::Version
|
345
364
|
version: '0'
|
346
365
|
requirements: []
|
347
|
-
rubygems_version: 3.
|
348
|
-
signing_key:
|
366
|
+
rubygems_version: 3.6.7
|
349
367
|
specification_version: 4
|
350
368
|
summary: TDD with stripe
|
351
369
|
test_files:
|