stripe-ruby-mock 3.1.0.rc3 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec_tests.yml +38 -0
- data/.rspec +2 -1
- data/CHANGELOG.md +36 -0
- data/Gemfile +0 -5
- data/README.md +6 -4
- data/lib/stripe_mock/api/client.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +65 -26
- data/lib/stripe_mock/data.rb +80 -11
- data/lib/stripe_mock/instance.rb +7 -3
- data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
- data/lib/stripe_mock/request_handlers/charges.rb +25 -1
- data/lib/stripe_mock/request_handlers/checkout_session.rb +158 -1
- data/lib/stripe_mock/request_handlers/customers.rb +12 -1
- data/lib/stripe_mock/request_handlers/events.rb +30 -3
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +1 -0
- data/lib/stripe_mock/request_handlers/helpers/search_helpers.rb +67 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +28 -9
- data/lib/stripe_mock/request_handlers/invoices.rb +16 -2
- data/lib/stripe_mock/request_handlers/payment_intents.rb +23 -3
- data/lib/stripe_mock/request_handlers/payment_methods.rb +5 -1
- data/lib/stripe_mock/request_handlers/prices.rb +31 -4
- data/lib/stripe_mock/request_handlers/products.rb +14 -5
- data/lib/stripe_mock/request_handlers/promotion_codes.rb +43 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +13 -2
- data/lib/stripe_mock/request_handlers/setup_intents.rb +16 -9
- data/lib/stripe_mock/request_handlers/subscriptions.rb +103 -5
- data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +5 -4
- data/lib/stripe_mock/test_strategies/base.rb +51 -24
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/balance.available.json +26 -20
- data/lib/stripe_mock/webhook_fixtures/charge.captured.json +143 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +63 -16
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +49 -120
- data/lib/stripe_mock/webhook_fixtures/charge.refund.updated.json +35 -0
- data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +145 -50
- data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +114 -43
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.json +79 -0
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.payment_mode.json +53 -0
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.setup_mode.json +45 -0
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +37 -46
- data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +36 -32
- data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +31 -22
- data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -25
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +135 -47
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +134 -45
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +135 -56
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +38 -47
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +176 -49
- data/lib/stripe_mock/webhook_fixtures/invoice.finalized.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.paid.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_action_required.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +149 -83
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +149 -90
- data/lib/stripe_mock/webhook_fixtures/invoice.upcoming.json +70 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +178 -50
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +87 -13
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +88 -14
- data/lib/stripe_mock/webhook_fixtures/mandate.updated.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.amount_capturable_updated.json +170 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.canceled.json +73 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.created.json +86 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +118 -79
- data/lib/stripe_mock/webhook_fixtures/payment_intent.processing.json +162 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.requires_action.json +191 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +85 -53
- data/lib/stripe_mock/webhook_fixtures/payment_link.created.json +47 -0
- data/lib/stripe_mock/webhook_fixtures/payment_link.updated.json +50 -0
- data/lib/stripe_mock/webhook_fixtures/payment_method.attached.json +63 -0
- data/lib/stripe_mock/webhook_fixtures/payment_method.detached.json +62 -0
- data/lib/stripe_mock/webhook_fixtures/payout.created.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/payout.paid.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/payout.updated.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/plan.created.json +30 -13
- data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +30 -13
- data/lib/stripe_mock/webhook_fixtures/plan.updated.json +34 -14
- data/lib/stripe_mock/webhook_fixtures/price.created.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/price.deleted.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/price.updated.json +48 -0
- data/lib/stripe_mock/webhook_fixtures/product.created.json +19 -13
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +20 -14
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +24 -15
- data/lib/stripe_mock/webhook_fixtures/quote.accepted.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.canceled.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.created.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.finalized.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.canceled.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.created.json +51 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.setup_failed.json +100 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.succeeded.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.canceled.json +119 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.created.json +114 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.released.json +111 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.updated.json +125 -0
- data/lib/stripe_mock/webhook_fixtures/tax_rate.created.json +32 -0
- data/lib/stripe_mock/webhook_fixtures/tax_rate.updated.json +37 -0
- data/lib/stripe_mock.rb +4 -1
- data/spec/instance_spec.rb +3 -1
- data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
- data/spec/readme_spec.rb +1 -1
- data/spec/shared_stripe_examples/account_examples.rb +9 -1
- data/spec/shared_stripe_examples/bank_token_examples.rb +5 -7
- data/spec/shared_stripe_examples/charge_examples.rb +97 -0
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/customer_examples.rb +56 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +107 -1
- data/spec/shared_stripe_examples/payment_intent_examples.rb +136 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +32 -27
- data/spec/shared_stripe_examples/price_examples.rb +111 -2
- data/spec/shared_stripe_examples/product_examples.rb +68 -0
- data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
- data/spec/shared_stripe_examples/refund_examples.rb +13 -0
- data/spec/shared_stripe_examples/setup_intent_examples.rb +17 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +276 -6
- data/spec/shared_stripe_examples/transfer_examples.rb +10 -1
- data/spec/shared_stripe_examples/webhook_event_examples.rb +51 -5
- data/spec/spec_helper.rb +1 -1
- data/spec/support/stripe_examples.rb +3 -1
- data/stripe-ruby-mock.gemspec +3 -4
- metadata +59 -29
- data/.travis.yml +0 -25
- data/lib/stripe_mock/request_handlers/checkout.rb +0 -15
- data/spec/shared_stripe_examples/checkout_examples.rb +0 -47
@@ -15,20 +15,22 @@ module StripeMock
|
|
15
15
|
]
|
16
16
|
|
17
17
|
def SetupIntents.included(klass)
|
18
|
-
klass.add_handler 'post /v1/setup_intents',
|
19
|
-
klass.add_handler 'get /v1/setup_intents',
|
20
|
-
klass.add_handler 'get /v1/setup_intents/(.*)',
|
21
|
-
klass.add_handler 'post /v1/setup_intents/(.*)/confirm',
|
22
|
-
klass.add_handler 'post /v1/setup_intents/(.*)/cancel',
|
23
|
-
klass.add_handler 'post /v1/setup_intents/(.*)',
|
18
|
+
klass.add_handler 'post /v1/setup_intents', :new_setup_intent
|
19
|
+
klass.add_handler 'get /v1/setup_intents', :get_setup_intents
|
20
|
+
klass.add_handler 'get /v1/setup_intents/(.*)', :get_setup_intent
|
21
|
+
klass.add_handler 'post /v1/setup_intents/(.*)/confirm', :confirm_setup_intent
|
22
|
+
klass.add_handler 'post /v1/setup_intents/(.*)/cancel', :cancel_setup_intent
|
23
|
+
klass.add_handler 'post /v1/setup_intents/(.*)', :update_setup_intent
|
24
24
|
end
|
25
25
|
|
26
26
|
def new_setup_intent(route, method_url, params, headers)
|
27
27
|
id = new_id('si')
|
28
|
+
status = params[:payment_method] ? 'requires_action' : 'requires_payment_method'
|
28
29
|
|
29
30
|
setup_intents[id] = Data.mock_setup_intent(
|
30
31
|
params.merge(
|
31
|
-
id: id
|
32
|
+
id: id,
|
33
|
+
status: status
|
32
34
|
)
|
33
35
|
)
|
34
36
|
|
@@ -40,7 +42,7 @@ module StripeMock
|
|
40
42
|
id = $1
|
41
43
|
|
42
44
|
setup_intent = assert_existence :setup_intent, id, setup_intents[id]
|
43
|
-
setup_intents[id] = Util.rmerge(setup_intent, params.select{ |k,v| ALLOWED_PARAMS.include?(k)})
|
45
|
+
setup_intents[id] = Util.rmerge(setup_intent, params.select { |k, v| ALLOWED_PARAMS.include?(k) })
|
44
46
|
end
|
45
47
|
|
46
48
|
def get_setup_intents(route, method_url, params, headers)
|
@@ -50,7 +52,7 @@ module StripeMock
|
|
50
52
|
clone = setup_intents.clone
|
51
53
|
|
52
54
|
if params[:customer]
|
53
|
-
clone.delete_if { |k,v| v[:customer] != params[:customer] }
|
55
|
+
clone.delete_if { |k, v| v[:customer] != params[:customer] }
|
54
56
|
end
|
55
57
|
|
56
58
|
Data.mock_list_object(clone.values, params)
|
@@ -62,6 +64,11 @@ module StripeMock
|
|
62
64
|
setup_intent = assert_existence :setup_intent, setup_intent_id, setup_intents[setup_intent_id]
|
63
65
|
|
64
66
|
setup_intent = setup_intent.clone
|
67
|
+
|
68
|
+
if params[:expand]&.include?("payment_method")
|
69
|
+
setup_intent[:payment_method] = assert_existence :payment_method, setup_intent[:payment_method], payment_methods[setup_intent[:payment_method]]
|
70
|
+
end
|
71
|
+
|
65
72
|
setup_intent
|
66
73
|
end
|
67
74
|
|
@@ -5,8 +5,9 @@ module StripeMock
|
|
5
5
|
def Subscriptions.included(klass)
|
6
6
|
klass.add_handler 'get /v1/subscriptions', :retrieve_subscriptions
|
7
7
|
klass.add_handler 'post /v1/subscriptions', :create_subscription
|
8
|
-
klass.add_handler 'get /v1/subscriptions/(.*)', :retrieve_subscription
|
8
|
+
klass.add_handler 'get /v1/subscriptions/((?!search).*)', :retrieve_subscription
|
9
9
|
klass.add_handler 'post /v1/subscriptions/(.*)', :update_subscription
|
10
|
+
klass.add_handler 'get /v1/subscriptions/search', :search_subscriptions
|
10
11
|
klass.add_handler 'delete /v1/subscriptions/(.*)', :cancel_subscription
|
11
12
|
|
12
13
|
klass.add_handler 'post /v1/customers/(.*)/subscription(?:s)?', :create_customer_subscription
|
@@ -69,6 +70,16 @@ module StripeMock
|
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
73
|
+
if params[:promotion_code]
|
74
|
+
promotion_code_id = params[:promotion_code]
|
75
|
+
|
76
|
+
promotion_code = promotion_codes[promotion_code_id]
|
77
|
+
|
78
|
+
unless promotion_code
|
79
|
+
raise Stripe::InvalidRequestError.new("No such promotion code: #{promotion_code_id}", 'promotion_code', http_status: 400)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
72
83
|
subscriptions[subscription[:id]] = subscription
|
73
84
|
add_subscription_to_customer(customer, subscription)
|
74
85
|
|
@@ -97,7 +108,7 @@ module StripeMock
|
|
97
108
|
customer[:default_source] = new_card[:id]
|
98
109
|
end
|
99
110
|
|
100
|
-
allowed_params = %w(customer application_fee_percent coupon items metadata plan quantity source tax_percent trial_end trial_period_days current_period_start created prorate billing_cycle_anchor billing days_until_due idempotency_key enable_incomplete_payments cancel_at_period_end default_tax_rates payment_behavior pending_invoice_item_interval default_payment_method collection_method off_session trial_from_plan expand)
|
111
|
+
allowed_params = %w(id customer application_fee_percent coupon items metadata plan quantity source tax_percent trial_end trial_period_days current_period_start created prorate billing_cycle_anchor billing days_until_due idempotency_key enable_incomplete_payments cancel_at_period_end default_tax_rates payment_behavior pending_invoice_item_interval default_payment_method collection_method off_session trial_from_plan proration_behavior backdate_start_date transfer_data expand automatic_tax payment_settings trial_settings promotion_code)
|
101
112
|
unknown_params = params.keys - allowed_params.map(&:to_sym)
|
102
113
|
if unknown_params.length > 0
|
103
114
|
raise Stripe::InvalidRequestError.new("Received unknown parameter: #{unknown_params.join}", unknown_params.first.to_s, http_status: 400)
|
@@ -113,6 +124,10 @@ module StripeMock
|
|
113
124
|
# Note: needs updating for subscriptions with multiple plans
|
114
125
|
verify_card_present(customer, subscription_plans.first, subscription, params)
|
115
126
|
|
127
|
+
if params[:coupon] && params[:promotion_code]
|
128
|
+
raise Stripe::InvalidRequestError.new("You may only specify one of these parameters: coupon, promotion_code", "coupon", http_status: 400)
|
129
|
+
end
|
130
|
+
|
116
131
|
if params[:coupon]
|
117
132
|
coupon_id = params[:coupon]
|
118
133
|
|
@@ -128,15 +143,50 @@ module StripeMock
|
|
128
143
|
end
|
129
144
|
end
|
130
145
|
|
146
|
+
if params[:promotion_code]
|
147
|
+
promotion_code_id = params[:promotion_code]
|
148
|
+
|
149
|
+
promotion_code = promotion_codes[promotion_code_id]
|
150
|
+
|
151
|
+
unless promotion_code
|
152
|
+
raise Stripe::InvalidRequestError.new("No such promotion code: #{promotion_code_id}", 'promotion_code', http_status: 400)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
131
156
|
if params[:trial_period_days]
|
132
157
|
subscription[:status] = 'trialing'
|
133
158
|
end
|
134
159
|
|
160
|
+
if params[:payment_behavior] == 'default_incomplete'
|
161
|
+
subscription[:status] = 'incomplete'
|
162
|
+
end
|
163
|
+
|
135
164
|
if params[:cancel_at_period_end]
|
136
165
|
subscription[:cancel_at_period_end] = true
|
137
166
|
subscription[:canceled_at] = Time.now.utc.to_i
|
138
167
|
end
|
139
168
|
|
169
|
+
if params[:transfer_data] && !params[:transfer_data].empty?
|
170
|
+
throw Stripe::InvalidRequestError.new(missing_param_message("transfer_data[destination]")) unless params[:transfer_data][:destination]
|
171
|
+
subscription[:transfer_data] = params[:transfer_data].dup
|
172
|
+
subscription[:transfer_data][:amount_percent] ||= 100
|
173
|
+
end
|
174
|
+
|
175
|
+
if (s = params[:expand]&.find { |s| s.start_with? 'latest_invoice' })
|
176
|
+
payment_intent = nil
|
177
|
+
unless subscription[:status] == 'trialing'
|
178
|
+
intent_status = subscription[:status] == 'incomplete' ? 'requires_payment_method' : 'succeeded'
|
179
|
+
intent = Data.mock_payment_intent({
|
180
|
+
status: intent_status,
|
181
|
+
amount: subscription[:plan][:amount],
|
182
|
+
currency: subscription[:plan][:currency]
|
183
|
+
})
|
184
|
+
payment_intent = s.include?('latest_invoice.payment_intent') ? intent : intent.id
|
185
|
+
end
|
186
|
+
invoice = Data.mock_invoice([], { payment_intent: payment_intent })
|
187
|
+
subscription[:latest_invoice] = invoice
|
188
|
+
end
|
189
|
+
|
140
190
|
subscriptions[subscription[:id]] = subscription
|
141
191
|
add_subscription_to_customer(customer, subscription)
|
142
192
|
|
@@ -153,15 +203,34 @@ module StripeMock
|
|
153
203
|
# stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
154
204
|
route =~ method_url
|
155
205
|
|
156
|
-
|
157
|
-
|
158
|
-
|
206
|
+
subs = subscriptions.values
|
207
|
+
|
208
|
+
case params[:status]
|
209
|
+
when nil
|
210
|
+
subs = subs.filter {|subscription| subscription[:status] != "canceled"}
|
211
|
+
when "all"
|
212
|
+
# Include all subscriptions
|
213
|
+
else
|
214
|
+
subs = subs.filter {|subscription| subscription[:status] == params[:status]}
|
215
|
+
end
|
216
|
+
if params[:current_period_end]
|
217
|
+
subs = filter_by_timestamp(subs, field: :current_period_end, value: params[:current_period_end])
|
218
|
+
end
|
219
|
+
if params[:current_period_start]
|
220
|
+
subs = filter_by_timestamp(subs, field: :current_period_start, value: params[:current_period_start])
|
221
|
+
end
|
222
|
+
|
223
|
+
Data.mock_list_object(subs, params)
|
159
224
|
end
|
160
225
|
|
161
226
|
def update_subscription(route, method_url, params, headers)
|
162
227
|
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
163
228
|
route =~ method_url
|
164
229
|
|
230
|
+
if params[:billing_cycle_anchor] == 'now'
|
231
|
+
params[:billing_cycle_anchor] = Time.now.utc.to_i
|
232
|
+
end
|
233
|
+
|
165
234
|
subscription_id = $2 ? $2 : $1
|
166
235
|
subscription = assert_existence :subscription, subscription_id, subscriptions[subscription_id]
|
167
236
|
verify_active_status(subscription)
|
@@ -198,6 +267,26 @@ module StripeMock
|
|
198
267
|
end
|
199
268
|
end
|
200
269
|
|
270
|
+
if params[:promotion_code]
|
271
|
+
promotion_code_id = params[:promotion_code]
|
272
|
+
|
273
|
+
promotion_code = promotion_codes[promotion_code_id]
|
274
|
+
|
275
|
+
if promotion_code
|
276
|
+
# You can't apply a promotion code with amount restrictions on the Customer object or on a subscription
|
277
|
+
# update API call
|
278
|
+
if promotion_code[:restrictions][:minimum_amount]
|
279
|
+
raise Stripe::InvalidRequestError.new(
|
280
|
+
"This promotion code cannot be redeemed on a subcription update because it uses the `minimum_amount` restriction.",
|
281
|
+
"promotion_code",
|
282
|
+
http_status: 400
|
283
|
+
)
|
284
|
+
end
|
285
|
+
else
|
286
|
+
raise Stripe::InvalidRequestError.new("No such promotion code: #{promotion_code_id}", 'promotion_code', http_status: 400)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
201
290
|
if params[:trial_period_days]
|
202
291
|
subscription[:status] = 'trialing'
|
203
292
|
end
|
@@ -255,6 +344,14 @@ module StripeMock
|
|
255
344
|
subscription
|
256
345
|
end
|
257
346
|
|
347
|
+
SEARCH_FIELDS = ["status"].freeze
|
348
|
+
def search_subscriptions(route, method_url, params, headers)
|
349
|
+
require_param(:query) unless params[:query]
|
350
|
+
|
351
|
+
results = search_results(subscriptions.values, params[:query], fields: SEARCH_FIELDS, resource_name: "subscriptions")
|
352
|
+
Data.mock_list_object(results, params)
|
353
|
+
end
|
354
|
+
|
258
355
|
private
|
259
356
|
|
260
357
|
def get_subscription_plans_from_params(params)
|
@@ -285,6 +382,7 @@ module StripeMock
|
|
285
382
|
return if customer[:invoice_settings][:default_payment_method]
|
286
383
|
return if customer[:trial_end]
|
287
384
|
return if params[:trial_end]
|
385
|
+
return if params[:payment_behavior] == 'default_incomplete'
|
288
386
|
return if subscription[:default_payment_method]
|
289
387
|
|
290
388
|
plan_trial_period_days = plan[:trial_period_days] || 0
|
@@ -45,7 +45,18 @@ module StripeMock
|
|
45
45
|
raise Stripe::InvalidRequestError.new("Invalid integer: #{params[:amount]}", 'amount', http_status: 400)
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
bal_trans_params = { amount: params[:amount].to_i, source: id }
|
49
|
+
|
50
|
+
balance_transaction_id = new_balance_transaction('txn', bal_trans_params)
|
51
|
+
|
52
|
+
transfers[id] = Data.mock_transfer(params.merge(id: id, balance_transaction: balance_transaction_id))
|
53
|
+
|
54
|
+
transfer = transfers[id].clone
|
55
|
+
if params[:expand] == ['balance_transaction']
|
56
|
+
transfer[:balance_transaction] = balance_transactions[balance_transaction_id]
|
57
|
+
end
|
58
|
+
|
59
|
+
transfer
|
49
60
|
end
|
50
61
|
|
51
62
|
def get_transfer(route, method_url, params, headers)
|
@@ -108,13 +108,14 @@ module StripeMock
|
|
108
108
|
|
109
109
|
def validate_create_price_params(params)
|
110
110
|
price_id = params[:id].to_s
|
111
|
-
product_id = params[:product]
|
112
111
|
|
113
|
-
|
114
|
-
|
115
|
-
raise Stripe::InvalidRequestError
|
112
|
+
require_param(:currency) unless params[:currency]
|
113
|
+
unless params[:product] || params[:product_data]
|
114
|
+
raise Stripe::InvalidRequestError("Requires product or product_data")
|
116
115
|
end
|
117
116
|
|
117
|
+
product_id = params[:product] || create_product(nil, nil, params[:product_data], nil).id
|
118
|
+
|
118
119
|
if prices[price_id]
|
119
120
|
message = already_exists_message(Stripe::Price)
|
120
121
|
raise Stripe::InvalidRequestError.new(message, :id)
|
@@ -10,7 +10,7 @@ module StripeMock
|
|
10
10
|
Stripe::Product.create create_product_params(params)
|
11
11
|
end
|
12
12
|
|
13
|
-
def create_product_params(params={})
|
13
|
+
def create_product_params(params = {})
|
14
14
|
{
|
15
15
|
:id => 'stripe_mock_default_product_id',
|
16
16
|
:name => 'Default Product',
|
@@ -21,16 +21,15 @@ module StripeMock
|
|
21
21
|
Stripe::Product.retrieve(product_id)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
24
|
def list_plans(limit)
|
26
25
|
Stripe::Plan.list(limit: limit)
|
27
26
|
end
|
28
27
|
|
29
|
-
def create_plan(params={})
|
28
|
+
def create_plan(params = {})
|
30
29
|
Stripe::Plan.create create_plan_params(params)
|
31
30
|
end
|
32
31
|
|
33
|
-
def create_plan_params(params={})
|
32
|
+
def create_plan_params(params = {})
|
34
33
|
{
|
35
34
|
:id => 'stripe_mock_default_plan_id',
|
36
35
|
:interval => 'month',
|
@@ -40,23 +39,28 @@ module StripeMock
|
|
40
39
|
}.merge(params)
|
41
40
|
end
|
42
41
|
|
43
|
-
def create_price(params={})
|
42
|
+
def create_price(params = {})
|
44
43
|
Stripe::Price.create create_price_params(params)
|
45
44
|
end
|
46
45
|
|
47
|
-
def create_price_params(params={})
|
48
|
-
{
|
49
|
-
:
|
46
|
+
def create_price_params(params = {})
|
47
|
+
price_params = {
|
48
|
+
currency: StripeMock.default_currency,
|
50
49
|
}.merge(params)
|
50
|
+
unless price_params.key?(:product) || price_params.key?(:product_data)
|
51
|
+
price_params[:product_data] = {
|
52
|
+
name: 'Product created for price'
|
53
|
+
}
|
54
|
+
end
|
55
|
+
price_params
|
51
56
|
end
|
52
57
|
|
53
58
|
def list_subscriptions(limit)
|
54
59
|
Stripe::Subscription.list(limit: limit)
|
55
60
|
end
|
56
61
|
|
57
|
-
|
58
|
-
|
59
|
-
card_data = { :number => "4242424242424242", :exp_month => 9, :exp_year => (Time.now.year + 5), :cvc => "999", :tokenization_method => nil }
|
62
|
+
def generate_card_token(card_params = {})
|
63
|
+
card_data = {:number => "4242424242424242", :exp_month => 9, :exp_year => (Time.now.year + 5), :cvc => "999", :tokenization_method => nil}
|
60
64
|
card = StripeMock::Util.card_merge(card_data, card_params)
|
61
65
|
card[:fingerprint] = StripeMock::Util.fingerprint(card[:number]) if StripeMock.state == 'local'
|
62
66
|
|
@@ -64,7 +68,7 @@ module StripeMock
|
|
64
68
|
stripe_token.id
|
65
69
|
end
|
66
70
|
|
67
|
-
def generate_bank_token(bank_account_params={})
|
71
|
+
def generate_bank_token(bank_account_params = {})
|
68
72
|
currency = bank_account_params[:currency] || StripeMock.default_currency
|
69
73
|
bank_account = {
|
70
74
|
:country => "US",
|
@@ -80,7 +84,6 @@ module StripeMock
|
|
80
84
|
stripe_token.id
|
81
85
|
end
|
82
86
|
|
83
|
-
|
84
87
|
def create_coupon_params(params = {})
|
85
88
|
currency = params[:currency] || StripeMock.default_currency
|
86
89
|
{
|
@@ -105,27 +108,51 @@ module StripeMock
|
|
105
108
|
}.merge(params)
|
106
109
|
end
|
107
110
|
|
111
|
+
def create_checkout_session(params = {})
|
112
|
+
Stripe::Checkout::Session.create create_checkout_session_params(params)
|
113
|
+
end
|
114
|
+
|
108
115
|
def create_checkout_session_params(params = {})
|
109
116
|
{
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
+
payment_method_types: ['card'],
|
118
|
+
line_items: params[:mode] == "setup" ? nil : [{
|
119
|
+
name: 'T-shirt',
|
120
|
+
quantity: 1,
|
121
|
+
amount: 500,
|
122
|
+
currency: 'usd',
|
123
|
+
}],
|
124
|
+
cancel_url: "https://example.com/cancel",
|
125
|
+
success_url: "https://example.com/success",
|
117
126
|
}.merge(params)
|
118
127
|
end
|
119
128
|
|
129
|
+
def complete_checkout_session(session, payment_method)
|
130
|
+
session = session.is_a?(Stripe::Checkout::Session) ? session : Stripe::Checkout::Session.retrieve(session)
|
131
|
+
payment_method = payment_method.is_a?(Stripe::PaymentMethod) ? payment_method : Stripe::PaymentMethod.retrieve(payment_method)
|
132
|
+
case session.mode
|
133
|
+
when "payment"
|
134
|
+
Stripe::PaymentIntent.retrieve(session.payment_intent).confirm(payment_method: payment_method.id)
|
135
|
+
when "setup"
|
136
|
+
Stripe::SetupIntent.update(session.setup_intent, {payment_method: payment_method.id})
|
137
|
+
when "subscription"
|
138
|
+
line_items = Stripe::Checkout::Session.list_line_items(session.id)
|
139
|
+
Stripe::Subscription.create({
|
140
|
+
customer: session.customer,
|
141
|
+
items: line_items.map do |line_item|
|
142
|
+
{
|
143
|
+
price: line_item.price.id,
|
144
|
+
quantity: line_item.quantity
|
145
|
+
}
|
146
|
+
end,
|
147
|
+
default_payment_method: payment_method.id
|
148
|
+
})
|
149
|
+
end
|
150
|
+
end
|
120
151
|
|
121
152
|
def create_coupon(params = {})
|
122
153
|
Stripe::Coupon.create create_coupon_params(params)
|
123
154
|
end
|
124
155
|
|
125
|
-
def create_checkout_session(params = {})
|
126
|
-
Stripe::Checkout::Session.create create_checkout_session_params(params)
|
127
|
-
end
|
128
|
-
|
129
156
|
def delete_all_coupons
|
130
157
|
coupons = Stripe::Coupon.list
|
131
158
|
coupons.data.map(&:delete) if coupons.data.count > 0
|
data/lib/stripe_mock/version.rb
CHANGED
@@ -1,31 +1,37 @@
|
|
1
1
|
{
|
2
|
-
"
|
3
|
-
"livemode": false,
|
4
|
-
"id": "evt_00000000000000",
|
5
|
-
"type": "balance.available",
|
2
|
+
"id": "evt_000000000000000000000000",
|
6
3
|
"object": "event",
|
4
|
+
"api_version": "2020-08-27",
|
5
|
+
"created": 1648319937,
|
7
6
|
"data": {
|
8
7
|
"object": {
|
9
|
-
"
|
10
|
-
{
|
11
|
-
"amount": 2217,
|
12
|
-
"currency": "usd"
|
13
|
-
}
|
14
|
-
],
|
8
|
+
"object": "balance",
|
15
9
|
"available": [
|
16
10
|
{
|
17
|
-
"amount":
|
18
|
-
"currency": "usd"
|
11
|
+
"amount": 7648,
|
12
|
+
"currency": "usd",
|
13
|
+
"source_types": {
|
14
|
+
"card": 7648
|
15
|
+
}
|
19
16
|
}
|
20
17
|
],
|
21
|
-
"
|
18
|
+
"livemode": false,
|
19
|
+
"pending": [
|
22
20
|
{
|
23
|
-
"amount":
|
24
|
-
"currency": "usd"
|
21
|
+
"amount": 37734,
|
22
|
+
"currency": "usd",
|
23
|
+
"source_types": {
|
24
|
+
"card": 37734
|
25
|
+
}
|
25
26
|
}
|
26
|
-
]
|
27
|
-
"livemode": false,
|
28
|
-
"object": "balance"
|
27
|
+
]
|
29
28
|
}
|
30
|
-
}
|
31
|
-
|
29
|
+
},
|
30
|
+
"livemode": false,
|
31
|
+
"pending_webhooks": 2,
|
32
|
+
"request": {
|
33
|
+
"id": null,
|
34
|
+
"idempotency_key": null
|
35
|
+
},
|
36
|
+
"type": "balance.available"
|
37
|
+
}
|
@@ -0,0 +1,143 @@
|
|
1
|
+
{
|
2
|
+
"id": "evt_000000000000000000000000",
|
3
|
+
"object": "event",
|
4
|
+
"api_version": "2020-08-27",
|
5
|
+
"created": 1648319938,
|
6
|
+
"data": {
|
7
|
+
"object": {
|
8
|
+
"id": "ch_000000000000000000000000",
|
9
|
+
"object": "charge",
|
10
|
+
"amount": 100,
|
11
|
+
"amount_captured": 100,
|
12
|
+
"amount_refunded": 0,
|
13
|
+
"application": null,
|
14
|
+
"application_fee": null,
|
15
|
+
"application_fee_amount": null,
|
16
|
+
"balance_transaction": "txn_000000000000000000000000",
|
17
|
+
"billing_details": {
|
18
|
+
"address": {
|
19
|
+
"city": null,
|
20
|
+
"country": null,
|
21
|
+
"line1": null,
|
22
|
+
"line2": null,
|
23
|
+
"postal_code": null,
|
24
|
+
"state": null
|
25
|
+
},
|
26
|
+
"email": null,
|
27
|
+
"name": null,
|
28
|
+
"phone": null
|
29
|
+
},
|
30
|
+
"calculated_statement_descriptor": "EXAMPLECOMPANY",
|
31
|
+
"captured": true,
|
32
|
+
"created": 1648319937,
|
33
|
+
"currency": "usd",
|
34
|
+
"customer": null,
|
35
|
+
"description": "(created by Stripe CLI)",
|
36
|
+
"destination": null,
|
37
|
+
"dispute": null,
|
38
|
+
"disputed": false,
|
39
|
+
"failure_code": null,
|
40
|
+
"failure_message": null,
|
41
|
+
"fraud_details": {
|
42
|
+
},
|
43
|
+
"invoice": null,
|
44
|
+
"livemode": false,
|
45
|
+
"metadata": {
|
46
|
+
},
|
47
|
+
"on_behalf_of": null,
|
48
|
+
"order": null,
|
49
|
+
"outcome": {
|
50
|
+
"network_status": "approved_by_network",
|
51
|
+
"reason": null,
|
52
|
+
"risk_level": "normal",
|
53
|
+
"risk_score": 64,
|
54
|
+
"seller_message": "Payment complete.",
|
55
|
+
"type": "authorized"
|
56
|
+
},
|
57
|
+
"paid": true,
|
58
|
+
"payment_intent": null,
|
59
|
+
"payment_method": "card_000000000000000000000000",
|
60
|
+
"payment_method_details": {
|
61
|
+
"card": {
|
62
|
+
"brand": "visa",
|
63
|
+
"checks": {
|
64
|
+
"address_line1_check": null,
|
65
|
+
"address_postal_code_check": null,
|
66
|
+
"cvc_check": null
|
67
|
+
},
|
68
|
+
"country": "US",
|
69
|
+
"exp_month": 3,
|
70
|
+
"exp_year": 2023,
|
71
|
+
"fingerprint": "ZoVSX2dK5igWt2SB",
|
72
|
+
"funding": "credit",
|
73
|
+
"installments": null,
|
74
|
+
"last4": "4242",
|
75
|
+
"mandate": null,
|
76
|
+
"network": "visa",
|
77
|
+
"three_d_secure": null,
|
78
|
+
"wallet": null
|
79
|
+
},
|
80
|
+
"type": "card"
|
81
|
+
},
|
82
|
+
"receipt_email": null,
|
83
|
+
"receipt_number": null,
|
84
|
+
"receipt_url": "https://pay.stripe.com/receipts/acct_0000000000000000/ch_000000000000000000000000/rcpt_0000000000000000000000000000000",
|
85
|
+
"refunded": false,
|
86
|
+
"refunds": {
|
87
|
+
"object": "list",
|
88
|
+
"data": [
|
89
|
+
|
90
|
+
],
|
91
|
+
"has_more": false,
|
92
|
+
"total_count": 0,
|
93
|
+
"url": "/v1/charges/ch_000000000000000000000000/refunds"
|
94
|
+
},
|
95
|
+
"review": null,
|
96
|
+
"shipping": null,
|
97
|
+
"source": {
|
98
|
+
"id": "card_000000000000000000000000",
|
99
|
+
"object": "card",
|
100
|
+
"address_city": null,
|
101
|
+
"address_country": null,
|
102
|
+
"address_line1": null,
|
103
|
+
"address_line1_check": null,
|
104
|
+
"address_line2": null,
|
105
|
+
"address_state": null,
|
106
|
+
"address_zip": null,
|
107
|
+
"address_zip_check": null,
|
108
|
+
"brand": "Visa",
|
109
|
+
"country": "US",
|
110
|
+
"customer": null,
|
111
|
+
"cvc_check": null,
|
112
|
+
"dynamic_last4": null,
|
113
|
+
"exp_month": 3,
|
114
|
+
"exp_year": 2023,
|
115
|
+
"fingerprint": "ZoVSX2dK5igWt2SB",
|
116
|
+
"funding": "credit",
|
117
|
+
"last4": "4242",
|
118
|
+
"metadata": {
|
119
|
+
},
|
120
|
+
"name": null,
|
121
|
+
"tokenization_method": null
|
122
|
+
},
|
123
|
+
"source_transfer": null,
|
124
|
+
"statement_descriptor": null,
|
125
|
+
"statement_descriptor_suffix": null,
|
126
|
+
"status": "succeeded",
|
127
|
+
"transfer_data": null,
|
128
|
+
"transfer_group": null
|
129
|
+
},
|
130
|
+
"previous_attributes": {
|
131
|
+
"amount_captured": 0,
|
132
|
+
"balance_transaction": null,
|
133
|
+
"captured": false
|
134
|
+
}
|
135
|
+
},
|
136
|
+
"livemode": false,
|
137
|
+
"pending_webhooks": 2,
|
138
|
+
"request": {
|
139
|
+
"id": "req_00000000000000",
|
140
|
+
"idempotency_key": "d67cfb41-4cc5-47d0-b2ca-c571e6420952"
|
141
|
+
},
|
142
|
+
"type": "charge.captured"
|
143
|
+
}
|