stripe-ruby-mock 3.0.0 → 3.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 +5 -5
- data/.github/workflows/rspec_tests.yml +38 -0
- data/.rspec +2 -1
- data/CHANGELOG.md +69 -0
- data/Gemfile +1 -0
- data/README.md +13 -5
- data/lib/stripe_mock/api/client.rb +1 -1
- data/lib/stripe_mock/api/errors.rb +3 -0
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +66 -25
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data/list.rb +42 -9
- data/lib/stripe_mock/data.rb +242 -31
- data/lib/stripe_mock/instance.rb +14 -3
- data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
- data/lib/stripe_mock/request_handlers/charges.rb +11 -4
- data/lib/stripe_mock/request_handlers/checkout_session.rb +179 -0
- data/lib/stripe_mock/request_handlers/customers.rb +35 -18
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
- data/lib/stripe_mock/request_handlers/events.rb +30 -3
- data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +6 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +36 -12
- data/lib/stripe_mock/request_handlers/invoices.rb +10 -4
- data/lib/stripe_mock/request_handlers/payment_intents.rb +19 -1
- data/lib/stripe_mock/request_handlers/payment_methods.rb +10 -24
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/prices.rb +62 -0
- 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/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscriptions.rb +120 -21
- data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
- data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +33 -4
- data/lib/stripe_mock/server.rb +2 -2
- data/lib/stripe_mock/test_strategies/base.rb +62 -10
- 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 +27 -15
- 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 +225 -0
- 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 +196 -0
- 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 +7 -0
- data/spec/instance_spec.rb +7 -7
- data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
- data/spec/list_spec.rb +38 -0
- data/spec/readme_spec.rb +1 -1
- data/spec/server_spec.rb +4 -2
- data/spec/shared_stripe_examples/account_examples.rb +9 -1
- data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
- data/spec/shared_stripe_examples/balance_examples.rb +6 -0
- data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/customer_examples.rb +49 -23
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +29 -8
- data/spec/shared_stripe_examples/payment_intent_examples.rb +84 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +336 -67
- data/spec/shared_stripe_examples/price_examples.rb +223 -0
- data/spec/shared_stripe_examples/product_examples.rb +1 -9
- 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 +361 -9
- 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 +4 -0
- data/spec/stripe_mock_spec.rb +2 -2
- data/spec/support/stripe_examples.rb +8 -1
- data/stripe-ruby-mock.gemspec +7 -2
- metadata +73 -12
- data/.travis.yml +0 -28
data/lib/stripe_mock/data.rb
CHANGED
@@ -101,6 +101,27 @@ module StripeMock
|
|
101
101
|
}.merge(params)
|
102
102
|
end
|
103
103
|
|
104
|
+
def self.mock_account_link(params = {})
|
105
|
+
now = Time.now.to_i
|
106
|
+
{
|
107
|
+
object: 'account_link',
|
108
|
+
created: now,
|
109
|
+
expires_at: now + 300,
|
110
|
+
url: 'https://connect.stripe.com/setup/c/iB0ph1cPnRLY',
|
111
|
+
data: {}
|
112
|
+
}.merge(params)
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.mock_express_login_link(params = {})
|
116
|
+
now = Time.now.to_i
|
117
|
+
{
|
118
|
+
object: 'login_link',
|
119
|
+
created: now,
|
120
|
+
url: 'https://connect.stripe.com/express/Ln7FfnNpUcCU',
|
121
|
+
data: {}
|
122
|
+
}.merge(params)
|
123
|
+
end
|
124
|
+
|
104
125
|
def self.mock_tax_rate(params)
|
105
126
|
{
|
106
127
|
id: 'test_cus_default',
|
@@ -119,7 +140,7 @@ module StripeMock
|
|
119
140
|
|
120
141
|
def self.mock_customer(sources, params)
|
121
142
|
cus_id = params[:id] || "test_cus_default"
|
122
|
-
currency = params[:currency]
|
143
|
+
currency = params[:currency]
|
123
144
|
sources.each {|source| source[:customer] = cus_id}
|
124
145
|
{
|
125
146
|
email: 'stripe_mock@example.com',
|
@@ -142,12 +163,14 @@ module StripeMock
|
|
142
163
|
sources: {
|
143
164
|
object: "list",
|
144
165
|
total_count: sources.size,
|
166
|
+
has_more: false,
|
145
167
|
url: "/v1/customers/#{cus_id}/sources",
|
146
168
|
data: sources
|
147
169
|
},
|
148
170
|
subscriptions: {
|
149
171
|
object: "list",
|
150
172
|
total_count: 0,
|
173
|
+
has_more: false,
|
151
174
|
url: "/v1/customers/#{cus_id}/subscriptions",
|
152
175
|
data: []
|
153
176
|
},
|
@@ -166,11 +189,34 @@ module StripeMock
|
|
166
189
|
paid: true,
|
167
190
|
amount: 0,
|
168
191
|
application_fee: nil,
|
192
|
+
application_fee_amount: nil,
|
169
193
|
currency: currency,
|
170
194
|
destination: nil,
|
171
195
|
fraud_details: {},
|
196
|
+
payment_method_details: {
|
197
|
+
card: {
|
198
|
+
brand: "visa",
|
199
|
+
checks: {
|
200
|
+
address_line1_check: nil,
|
201
|
+
address_postal_code_check: nil,
|
202
|
+
cvc_check: "pass"
|
203
|
+
},
|
204
|
+
country: "US",
|
205
|
+
exp_month: 12,
|
206
|
+
exp_year: 2013,
|
207
|
+
fingerprint: "3TQGpK9JoY1GgXPw",
|
208
|
+
funding: "credit",
|
209
|
+
installments: nil,
|
210
|
+
last4: "4242",
|
211
|
+
network: "visa",
|
212
|
+
three_d_secure: nil,
|
213
|
+
wallet: nil
|
214
|
+
},
|
215
|
+
type: "card"
|
216
|
+
},
|
172
217
|
receipt_email: nil,
|
173
218
|
receipt_number: nil,
|
219
|
+
receipt_url: nil,
|
174
220
|
refunded: false,
|
175
221
|
shipping: {},
|
176
222
|
statement_descriptor: "Charge #{charge_id}",
|
@@ -231,7 +277,8 @@ module StripeMock
|
|
231
277
|
charge: "ch_4fWhYjzQ23UFWT",
|
232
278
|
receipt_number: nil,
|
233
279
|
status: "succeeded",
|
234
|
-
reason: "requested_by_customer"
|
280
|
+
reason: "requested_by_customer",
|
281
|
+
receipt_url: nil
|
235
282
|
}.merge(params)
|
236
283
|
end
|
237
284
|
|
@@ -339,8 +386,9 @@ module StripeMock
|
|
339
386
|
},
|
340
387
|
cancel_at_period_end: false,
|
341
388
|
canceled_at: nil,
|
389
|
+
collection_method: 'charge_automatically',
|
342
390
|
ended_at: nil,
|
343
|
-
|
391
|
+
start_date: 1308595038,
|
344
392
|
object: 'subscription',
|
345
393
|
trial_start: 1308595038,
|
346
394
|
trial_end: 1308681468,
|
@@ -349,7 +397,11 @@ module StripeMock
|
|
349
397
|
tax_percent: nil,
|
350
398
|
discount: nil,
|
351
399
|
metadata: {},
|
352
|
-
default_tax_rates: nil
|
400
|
+
default_tax_rates: nil,
|
401
|
+
default_payment_method: nil,
|
402
|
+
pending_invoice_item_interval: nil,
|
403
|
+
next_pending_invoice_item_invoice: nil,
|
404
|
+
latest_invoice: nil
|
353
405
|
}, params)
|
354
406
|
end
|
355
407
|
|
@@ -369,6 +421,7 @@ module StripeMock
|
|
369
421
|
lines: {
|
370
422
|
object: "list",
|
371
423
|
total_count: lines.count,
|
424
|
+
has_more: false,
|
372
425
|
url: "/v1/invoices/#{in_id}/lines",
|
373
426
|
data: lines
|
374
427
|
},
|
@@ -397,7 +450,8 @@ module StripeMock
|
|
397
450
|
next_payment_attempt: 1349825350,
|
398
451
|
charge: nil,
|
399
452
|
discount: nil,
|
400
|
-
subscription: nil
|
453
|
+
subscription: nil,
|
454
|
+
number: "6C41730-0001"
|
401
455
|
}.merge(params)
|
402
456
|
if invoice[:discount]
|
403
457
|
invoice[:total] = [0, invoice[:subtotal] - invoice[:discount][:coupon][:amount_off]].max if invoice[:discount][:coupon][:amount_off]
|
@@ -552,6 +606,34 @@ module StripeMock
|
|
552
606
|
}.merge(params)
|
553
607
|
end
|
554
608
|
|
609
|
+
def self.mock_price(params={})
|
610
|
+
currency = params[:currency] || StripeMock.default_currency
|
611
|
+
{
|
612
|
+
id: "mock_price_123",
|
613
|
+
object: "price",
|
614
|
+
active: true,
|
615
|
+
billing_scheme: "per_unit",
|
616
|
+
created: 1593044959,
|
617
|
+
currency: currency,
|
618
|
+
livemode: false,
|
619
|
+
lookup_key: nil,
|
620
|
+
metadata: {},
|
621
|
+
nickname: 'My Mock Price',
|
622
|
+
product: "mock_prod_NONEXIST", # override this with your own existing product id
|
623
|
+
recurring: {
|
624
|
+
aggregate_usage: nil,
|
625
|
+
interval: "month",
|
626
|
+
interval_count: 1,
|
627
|
+
usage_type: "licensed"
|
628
|
+
},
|
629
|
+
tiers_mode: nil,
|
630
|
+
transform_quantity: nil,
|
631
|
+
type: "recurring",
|
632
|
+
unit_amount: 2000,
|
633
|
+
unit_amount_decimal: "2000"
|
634
|
+
}.merge(params)
|
635
|
+
end
|
636
|
+
|
555
637
|
def self.mock_product(params={})
|
556
638
|
{
|
557
639
|
id: "mock_prod_abc123",
|
@@ -576,6 +658,44 @@ module StripeMock
|
|
576
658
|
}.merge(params)
|
577
659
|
end
|
578
660
|
|
661
|
+
def self.mock_promotion_code(params={})
|
662
|
+
{
|
663
|
+
id: "mock_promo_abc123",
|
664
|
+
object: "promotion_code",
|
665
|
+
active: true,
|
666
|
+
code: "TESTCODE",
|
667
|
+
coupon: {
|
668
|
+
id: "mock_coupon_abc123",
|
669
|
+
object: "coupon",
|
670
|
+
amount_off: nil,
|
671
|
+
created: 1665773498,
|
672
|
+
currency: "usd",
|
673
|
+
duration: "repeating",
|
674
|
+
duration_in_months: 1,
|
675
|
+
livemode: false,
|
676
|
+
max_redemptions: nil,
|
677
|
+
metadata: {},
|
678
|
+
name: "Mock Coupon",
|
679
|
+
percent_off: 10.0,
|
680
|
+
redeem_by: nil,
|
681
|
+
times_redeemed: 0,
|
682
|
+
valid: true
|
683
|
+
},
|
684
|
+
created: 1665773499,
|
685
|
+
customer: nil,
|
686
|
+
expires_at: nil,
|
687
|
+
livemode: false,
|
688
|
+
max_redemptions: nil,
|
689
|
+
metadata: {},
|
690
|
+
restrictions: {
|
691
|
+
first_time_transaction: false,
|
692
|
+
minimum_amount: nil,
|
693
|
+
minimum_amount_currency: nil
|
694
|
+
},
|
695
|
+
times_redeemed: 0
|
696
|
+
}.merge(params)
|
697
|
+
end
|
698
|
+
|
579
699
|
def self.mock_recipient(cards, params={})
|
580
700
|
rp_id = params[:id] || "test_rp_default"
|
581
701
|
cards.each {|card| card[:recipient] = rp_id}
|
@@ -599,6 +719,7 @@ module StripeMock
|
|
599
719
|
object: "list",
|
600
720
|
url: "/v1/recipients/#{rp_id}/cards",
|
601
721
|
data: cards,
|
722
|
+
has_more: false,
|
602
723
|
total_count: cards.count
|
603
724
|
},
|
604
725
|
default_card: nil
|
@@ -1006,6 +1127,16 @@ module StripeMock
|
|
1006
1127
|
bitcoin_receiver: 1545182
|
1007
1128
|
}
|
1008
1129
|
}],
|
1130
|
+
instant_available: [
|
1131
|
+
{
|
1132
|
+
currency: "usd",
|
1133
|
+
amount: usd_balance,
|
1134
|
+
source_types: {
|
1135
|
+
card: 25907032203,
|
1136
|
+
bank_account: 108476658,
|
1137
|
+
bitcoin_receiver: 1545182
|
1138
|
+
}
|
1139
|
+
}],
|
1009
1140
|
connect_reserved: [
|
1010
1141
|
{
|
1011
1142
|
currency: "usd",
|
@@ -1070,13 +1201,12 @@ module StripeMock
|
|
1070
1201
|
end
|
1071
1202
|
|
1072
1203
|
def self.mock_subscription_item(params = {})
|
1073
|
-
|
1204
|
+
id = params[:id] || 'test_si_default'
|
1074
1205
|
{
|
1075
|
-
id:
|
1206
|
+
id: id,
|
1076
1207
|
object: 'subscription_item',
|
1077
1208
|
created: 1504716183,
|
1078
|
-
metadata: {
|
1079
|
-
},
|
1209
|
+
metadata: {},
|
1080
1210
|
plan: {
|
1081
1211
|
id: 'PER_USER_PLAN1',
|
1082
1212
|
object: 'plan',
|
@@ -1165,29 +1295,72 @@ module StripeMock
|
|
1165
1295
|
end
|
1166
1296
|
|
1167
1297
|
def self.mock_payment_method(params = {})
|
1168
|
-
payment_method_id = params[:id] ||
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1298
|
+
payment_method_id = params[:id] || 'pm_1ExEuFL2DI6wht39WNJgbybl'
|
1299
|
+
|
1300
|
+
type = params[:type].to_sym
|
1301
|
+
last4 = params.dig(:card, :number)
|
1302
|
+
data = {
|
1303
|
+
card: {
|
1304
|
+
brand: case last4&.to_s
|
1305
|
+
when /^4/, nil
|
1306
|
+
'visa'
|
1307
|
+
when /^5[1-5]/
|
1308
|
+
'mastercard'
|
1309
|
+
else
|
1310
|
+
'unknown'
|
1311
|
+
end,
|
1312
|
+
checks: {
|
1313
|
+
address_line1_check: nil,
|
1314
|
+
address_postal_code_check: nil,
|
1315
|
+
cvc_check: 'pass'
|
1184
1316
|
},
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1317
|
+
country: 'FR',
|
1318
|
+
exp_month: params.dig(:card, :exp_month) || 2,
|
1319
|
+
exp_year: params.dig(:card, :exp_year) || 2022,
|
1320
|
+
fingerprint: 'Hr3Ly5z5IYxsokWA',
|
1321
|
+
funding: 'credit',
|
1322
|
+
generated_from: nil,
|
1323
|
+
last4: last4.nil? ? '3155' : last4.to_s[-4..],
|
1324
|
+
three_d_secure_usage: { supported: true },
|
1325
|
+
wallet: nil
|
1326
|
+
},
|
1327
|
+
ideal: {
|
1328
|
+
bank: 'ing',
|
1329
|
+
bic: 'INGBNL2A',
|
1330
|
+
iban_last4: '****',
|
1331
|
+
verified_name: 'JENNY ROSEN'
|
1332
|
+
},
|
1333
|
+
sepa_debit: {
|
1334
|
+
bank_code: '37040044',
|
1335
|
+
branch_code: '',
|
1336
|
+
country: 'DE',
|
1337
|
+
fingerprint: 'FD81kbVPe7M05BMj',
|
1338
|
+
last4: params.dig(:sepa_debit, :iban)&.[](-4..) || '3000'
|
1339
|
+
}
|
1340
|
+
}
|
1189
1341
|
|
1190
|
-
|
1342
|
+
{
|
1343
|
+
id: payment_method_id,
|
1344
|
+
object: 'payment_method',
|
1345
|
+
type: params[:type],
|
1346
|
+
billing_details: {
|
1347
|
+
address: {
|
1348
|
+
city: 'New Orleans',
|
1349
|
+
country: 'US',
|
1350
|
+
line1: 'Bourbon Street 23',
|
1351
|
+
line2: nil,
|
1352
|
+
postal_code: '10000',
|
1353
|
+
state: nil
|
1354
|
+
},
|
1355
|
+
email: 'foo@bar.com',
|
1356
|
+
name: 'John Dolton',
|
1357
|
+
phone: nil
|
1358
|
+
},
|
1359
|
+
customer: params[:customer] || nil,
|
1360
|
+
metadata: {
|
1361
|
+
order_id: '123456789'
|
1362
|
+
}
|
1363
|
+
}.merge(params).merge(type => data[type])
|
1191
1364
|
end
|
1192
1365
|
|
1193
1366
|
def self.mock_setup_intent(params = {})
|
@@ -1208,12 +1381,50 @@ module StripeMock
|
|
1208
1381
|
:on_behalf_of => nil,
|
1209
1382
|
:payment_method => nil,
|
1210
1383
|
:payment_method_options => {
|
1211
|
-
|
1384
|
+
card: {request_three_d_secure: "automatic"}
|
1212
1385
|
},
|
1213
1386
|
:payment_method_types => ["card"],
|
1214
1387
|
:status => "requires_payment_method",
|
1215
1388
|
:usage => "off_session"
|
1216
1389
|
}.merge(params)
|
1217
1390
|
end
|
1391
|
+
|
1392
|
+
def self.mock_checkout_session(params = {})
|
1393
|
+
cs_id = params[:id] || "test_cs_default"
|
1394
|
+
currency = params[:currency] || StripeMock.default_currency
|
1395
|
+
{
|
1396
|
+
id: cs_id,
|
1397
|
+
object: 'checkout.session',
|
1398
|
+
billing_address_collection: nil,
|
1399
|
+
cancel_url: 'https://example.com/cancel',
|
1400
|
+
client_reference_id: nil,
|
1401
|
+
customer: nil,
|
1402
|
+
customer_email: nil,
|
1403
|
+
display_items: [
|
1404
|
+
{
|
1405
|
+
amount: 1500,
|
1406
|
+
currency: currency,
|
1407
|
+
custom: {
|
1408
|
+
description: 'Comfortable cotton t-shirt',
|
1409
|
+
images: nil,
|
1410
|
+
name: 'T-shirt'
|
1411
|
+
},
|
1412
|
+
quantity: 2,
|
1413
|
+
type: 'custom'
|
1414
|
+
}
|
1415
|
+
],
|
1416
|
+
livemode: false,
|
1417
|
+
locale: nil,
|
1418
|
+
mode: nil,
|
1419
|
+
payment_intent: mock_payment_intent[:id],
|
1420
|
+
payment_method_types: [
|
1421
|
+
'card'
|
1422
|
+
],
|
1423
|
+
setup_intent: nil,
|
1424
|
+
submit_type: nil,
|
1425
|
+
subscription: nil,
|
1426
|
+
success_url: 'https://example.com/success'
|
1427
|
+
}.merge(params)
|
1428
|
+
end
|
1218
1429
|
end
|
1219
1430
|
end
|
data/lib/stripe_mock/instance.rb
CHANGED
@@ -24,6 +24,8 @@ module StripeMock
|
|
24
24
|
include StripeMock::RequestHandlers::PaymentMethods
|
25
25
|
include StripeMock::RequestHandlers::SetupIntents
|
26
26
|
include StripeMock::RequestHandlers::ExternalAccounts
|
27
|
+
include StripeMock::RequestHandlers::AccountLinks
|
28
|
+
include StripeMock::RequestHandlers::ExpressLoginLinks
|
27
29
|
include StripeMock::RequestHandlers::Accounts
|
28
30
|
include StripeMock::RequestHandlers::Balance
|
29
31
|
include StripeMock::RequestHandlers::BalanceTransactions
|
@@ -40,7 +42,9 @@ module StripeMock
|
|
40
42
|
include StripeMock::RequestHandlers::InvoiceItems
|
41
43
|
include StripeMock::RequestHandlers::Orders
|
42
44
|
include StripeMock::RequestHandlers::Plans
|
45
|
+
include StripeMock::RequestHandlers::Prices
|
43
46
|
include StripeMock::RequestHandlers::Products
|
47
|
+
include StripeMock::RequestHandlers::PromotionCodes
|
44
48
|
include StripeMock::RequestHandlers::Refunds
|
45
49
|
include StripeMock::RequestHandlers::Recipients
|
46
50
|
include StripeMock::RequestHandlers::Transfers
|
@@ -49,11 +53,14 @@ module StripeMock
|
|
49
53
|
include StripeMock::RequestHandlers::Payouts
|
50
54
|
include StripeMock::RequestHandlers::EphemeralKey
|
51
55
|
include StripeMock::RequestHandlers::TaxRates
|
56
|
+
include StripeMock::RequestHandlers::Checkout
|
57
|
+
include StripeMock::RequestHandlers::Checkout::Session
|
52
58
|
|
53
59
|
attr_reader :accounts, :balance, :balance_transactions, :bank_tokens, :charges, :coupons, :customers,
|
54
60
|
:disputes, :events, :invoices, :invoice_items, :orders, :payment_intents, :payment_methods,
|
55
|
-
:setup_intents, :plans, :
|
56
|
-
:subscriptions_items, :products, :tax_rates
|
61
|
+
:setup_intents, :plans, :prices, :promotion_codes, :recipients, :refunds, :transfers, :payouts,
|
62
|
+
:subscriptions, :country_spec, :subscriptions_items, :products, :tax_rates, :checkout_sessions,
|
63
|
+
:checkout_session_line_items
|
57
64
|
|
58
65
|
attr_accessor :error_queue, :debug, :conversion_rate, :account_balance
|
59
66
|
|
@@ -63,7 +70,7 @@ module StripeMock
|
|
63
70
|
@balance_transactions = Data.mock_balance_transactions(['txn_05RsQX2eZvKYlo2C0FRTGSSA','txn_15RsQX2eZvKYlo2C0ERTYUIA', 'txn_25RsQX2eZvKYlo2C0ZXCVBNM', 'txn_35RsQX2eZvKYlo2C0QAZXSWE', 'txn_45RsQX2eZvKYlo2C0EDCVFRT', 'txn_55RsQX2eZvKYlo2C0OIKLJUY', 'txn_65RsQX2eZvKYlo2C0ASDFGHJ', 'txn_75RsQX2eZvKYlo2C0EDCXSWQ', 'txn_85RsQX2eZvKYlo2C0UJMCDET', 'txn_95RsQX2eZvKYlo2C0EDFRYUI'])
|
64
71
|
@bank_tokens = {}
|
65
72
|
@card_tokens = {}
|
66
|
-
@customers = {}
|
73
|
+
@customers = { Stripe.api_key => {} }
|
67
74
|
@charges = {}
|
68
75
|
@payment_intents = {}
|
69
76
|
@payment_methods = {}
|
@@ -76,7 +83,9 @@ module StripeMock
|
|
76
83
|
@orders = {}
|
77
84
|
@payment_methods = {}
|
78
85
|
@plans = {}
|
86
|
+
@prices = {}
|
79
87
|
@products = {}
|
88
|
+
@promotion_codes = {}
|
80
89
|
@recipients = {}
|
81
90
|
@refunds = {}
|
82
91
|
@transfers = {}
|
@@ -85,6 +94,8 @@ module StripeMock
|
|
85
94
|
@subscriptions_items = {}
|
86
95
|
@country_spec = {}
|
87
96
|
@tax_rates = {}
|
97
|
+
@checkout_sessions = {}
|
98
|
+
@checkout_session_line_items = {}
|
88
99
|
|
89
100
|
@debug = false
|
90
101
|
@error_queue = ErrorQueue.new
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module AccountLinks
|
4
|
+
|
5
|
+
def AccountLinks.included(klass)
|
6
|
+
klass.add_handler 'post /v1/account_links', :new_account_link
|
7
|
+
end
|
8
|
+
|
9
|
+
def new_account_link(route, method_url, params, headers)
|
10
|
+
route =~ method_url
|
11
|
+
Data.mock_account_link(params)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -4,12 +4,13 @@ module StripeMock
|
|
4
4
|
VALID_START_YEAR = 2009
|
5
5
|
|
6
6
|
def Accounts.included(klass)
|
7
|
-
klass.add_handler 'post /v1/accounts',
|
8
|
-
klass.add_handler 'get /v1/account',
|
9
|
-
klass.add_handler 'get /v1/accounts/(.*)',
|
10
|
-
klass.add_handler 'post /v1/accounts/(.*)',
|
11
|
-
klass.add_handler 'get /v1/accounts',
|
12
|
-
klass.add_handler 'post /oauth/deauthorize'
|
7
|
+
klass.add_handler 'post /v1/accounts', :new_account
|
8
|
+
klass.add_handler 'get /v1/account', :get_account
|
9
|
+
klass.add_handler 'get /v1/accounts/(.*)', :get_account
|
10
|
+
klass.add_handler 'post /v1/accounts/(.*)', :update_account
|
11
|
+
klass.add_handler 'get /v1/accounts', :list_accounts
|
12
|
+
klass.add_handler 'post /oauth/deauthorize', :deauthorize
|
13
|
+
klass.add_handler 'delete /v1/accounts/(.*)', :delete_account
|
13
14
|
end
|
14
15
|
|
15
16
|
def new_account(route, method_url, params, headers)
|
@@ -48,6 +49,16 @@ module StripeMock
|
|
48
49
|
Stripe::StripeObject.construct_from(:stripe_user_id => params[:stripe_user_id])
|
49
50
|
end
|
50
51
|
|
52
|
+
def delete_account(route, method_url, params, headers)
|
53
|
+
init_account
|
54
|
+
route =~ method_url
|
55
|
+
assert_existence :account, $1, accounts[$1]
|
56
|
+
accounts[$1] = {
|
57
|
+
id: accounts[$1][:id],
|
58
|
+
deleted: true
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
51
62
|
private
|
52
63
|
|
53
64
|
def init_account
|
@@ -12,7 +12,9 @@ module StripeMock
|
|
12
12
|
klass.add_handler 'post /v1/charges/(.*)', :update_charge
|
13
13
|
end
|
14
14
|
|
15
|
-
def new_charge(route, method_url, params, headers)
|
15
|
+
def new_charge(route, method_url, params, headers = {})
|
16
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
17
|
+
|
16
18
|
if headers && headers[:idempotency_key]
|
17
19
|
params[:idempotency_key] = headers[:idempotency_key]
|
18
20
|
if charges.any?
|
@@ -29,7 +31,7 @@ module StripeMock
|
|
29
31
|
# card id, not a token. in this case we'll find the card in the customer
|
30
32
|
# object and return that.
|
31
33
|
if params[:customer]
|
32
|
-
params[:source] = get_card(customers[params[:customer]], params[:source])
|
34
|
+
params[:source] = get_card(customers[stripe_account][params[:customer]], params[:source])
|
33
35
|
else
|
34
36
|
params[:source] = get_card_or_bank_by_token(params[:source])
|
35
37
|
end
|
@@ -37,7 +39,7 @@ module StripeMock
|
|
37
39
|
raise Stripe::InvalidRequestError.new("Invalid token id: #{params[:source]}", 'card', http_status: 400)
|
38
40
|
end
|
39
41
|
elsif params[:customer]
|
40
|
-
customer = customers[params[:customer]]
|
42
|
+
customer = customers[stripe_account][params[:customer]]
|
41
43
|
if customer && customer[:default_source]
|
42
44
|
params[:source] = get_card(customer, customer[:default_source])
|
43
45
|
end
|
@@ -146,7 +148,7 @@ module StripeMock
|
|
146
148
|
elsif non_positive_charge_amount?(params)
|
147
149
|
raise Stripe::InvalidRequestError.new('Invalid positive integer', 'amount', http_status: 400)
|
148
150
|
elsif params[:source].nil? && params[:customer].nil?
|
149
|
-
raise Stripe::InvalidRequestError.new('Must provide source or customer.', http_status: nil)
|
151
|
+
raise Stripe::InvalidRequestError.new('Must provide source or customer.', nil, http_status: nil)
|
150
152
|
end
|
151
153
|
end
|
152
154
|
|
@@ -169,6 +171,11 @@ module StripeMock
|
|
169
171
|
params[:refunds].has_key?(:data) && params[:refunds][:data].nil?)
|
170
172
|
allowed << :refunds
|
171
173
|
end
|
174
|
+
if params.has_key?(:payment_method_details) && (params[:payment_method_details].empty? ||
|
175
|
+
params[:payment_method_details].has_key?(:card) && (params[:payment_method_details][:card].empty? ||
|
176
|
+
params[:payment_method_details][:card].has_key?(:checks) && params[:payment_method_details][:card][:checks].empty?))
|
177
|
+
allowed << :payment_method_details
|
178
|
+
end
|
172
179
|
|
173
180
|
allowed
|
174
181
|
end
|