stripe-ruby-mock 2.5.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/rspec_tests.yml +38 -0
- data/.gitignore +1 -1
- data/.rspec +2 -1
- data/CHANGELOG.md +77 -0
- data/Gemfile +1 -5
- data/README.md +19 -11
- data/lib/stripe_mock/api/client.rb +2 -2
- data/lib/stripe_mock/api/errors.rb +34 -28
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +68 -24
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data/list.rb +42 -9
- data/lib/stripe_mock/data.rb +359 -21
- data/lib/stripe_mock/instance.rb +23 -5
- 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/balance_transactions.rb +2 -2
- data/lib/stripe_mock/request_handlers/charges.rb +31 -5
- data/lib/stripe_mock/request_handlers/checkout_session.rb +179 -0
- data/lib/stripe_mock/request_handlers/customers.rb +47 -19
- 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/search_helpers.rb +67 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +36 -12
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/invoices.rb +26 -6
- data/lib/stripe_mock/request_handlers/payment_intents.rb +202 -0
- data/lib/stripe_mock/request_handlers/payment_methods.rb +124 -0
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/prices.rb +71 -0
- data/lib/stripe_mock/request_handlers/products.rb +15 -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 +100 -0
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscriptions.rb +146 -25
- 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 +124 -9
- data/lib/stripe_mock/server.rb +2 -2
- data/lib/stripe_mock/test_strategies/base.rb +98 -12
- data/lib/stripe_mock/test_strategies/live.rb +23 -12
- data/lib/stripe_mock/test_strategies/mock.rb +6 -2
- 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 +101 -44
- 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 -45
- 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 -46
- 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 +40 -0
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +47 -0
- 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 +11 -0
- data/spec/instance_spec.rb +13 -13
- 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 +6 -3
- data/spec/shared_stripe_examples/account_examples.rb +10 -2
- 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/balance_transaction_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_token_examples.rb +5 -7
- data/spec/shared_stripe_examples/card_examples.rb +4 -4
- data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/charge_examples.rb +106 -22
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +149 -53
- data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
- data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
- data/spec/shared_stripe_examples/invoice_examples.rb +148 -40
- data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
- data/spec/shared_stripe_examples/payment_intent_examples.rb +283 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +454 -0
- data/spec/shared_stripe_examples/payout_examples.rb +2 -2
- data/spec/shared_stripe_examples/plan_examples.rb +135 -92
- data/spec/shared_stripe_examples/price_examples.rb +292 -0
- data/spec/shared_stripe_examples/product_examples.rb +215 -0
- data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
- data/spec/shared_stripe_examples/refund_examples.rb +38 -21
- data/spec/shared_stripe_examples/setup_intent_examples.rb +85 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +706 -324
- data/spec/shared_stripe_examples/subscription_items_examples.rb +3 -2
- data/spec/shared_stripe_examples/transfer_examples.rb +16 -7
- data/spec/shared_stripe_examples/webhook_event_examples.rb +62 -16
- data/spec/spec_helper.rb +8 -5
- data/spec/stripe_mock_spec.rb +4 -4
- data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
- data/spec/support/stripe_examples.rb +11 -1
- data/stripe-ruby-mock.gemspec +9 -5
- metadata +115 -47
- data/.travis.yml +0 -28
- data/spec/shared_stripe_examples/product_example.rb +0 -65
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',
|
@@ -128,20 +149,28 @@ module StripeMock
|
|
128
149
|
created: 1372126710,
|
129
150
|
id: cus_id,
|
130
151
|
name: nil,
|
152
|
+
preferred_locales: [],
|
131
153
|
livemode: false,
|
132
154
|
delinquent: false,
|
133
155
|
discount: nil,
|
134
156
|
account_balance: 0,
|
135
157
|
currency: currency,
|
158
|
+
invoice_settings: {
|
159
|
+
default_payment_method: nil,
|
160
|
+
custom_fields: nil,
|
161
|
+
footer: nil
|
162
|
+
},
|
136
163
|
sources: {
|
137
164
|
object: "list",
|
138
165
|
total_count: sources.size,
|
166
|
+
has_more: false,
|
139
167
|
url: "/v1/customers/#{cus_id}/sources",
|
140
168
|
data: sources
|
141
169
|
},
|
142
170
|
subscriptions: {
|
143
171
|
object: "list",
|
144
172
|
total_count: 0,
|
173
|
+
has_more: false,
|
145
174
|
url: "/v1/customers/#{cus_id}/subscriptions",
|
146
175
|
data: []
|
147
176
|
},
|
@@ -160,11 +189,34 @@ module StripeMock
|
|
160
189
|
paid: true,
|
161
190
|
amount: 0,
|
162
191
|
application_fee: nil,
|
192
|
+
application_fee_amount: nil,
|
163
193
|
currency: currency,
|
164
194
|
destination: nil,
|
165
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
|
+
},
|
166
217
|
receipt_email: nil,
|
167
218
|
receipt_number: nil,
|
219
|
+
receipt_url: nil,
|
168
220
|
refunded: false,
|
169
221
|
shipping: {},
|
170
222
|
statement_descriptor: "Charge #{charge_id}",
|
@@ -199,7 +251,7 @@ module StripeMock
|
|
199
251
|
data: []
|
200
252
|
},
|
201
253
|
transfer: nil,
|
202
|
-
balance_transaction: "txn_2dyYXXP90MN26R",
|
254
|
+
balance_transaction: params[:balance_transaction] || "txn_2dyYXXP90MN26R",
|
203
255
|
failure_message: nil,
|
204
256
|
failure_code: nil,
|
205
257
|
amount_refunded: 0,
|
@@ -225,7 +277,8 @@ module StripeMock
|
|
225
277
|
charge: "ch_4fWhYjzQ23UFWT",
|
226
278
|
receipt_number: nil,
|
227
279
|
status: "succeeded",
|
228
|
-
reason: "requested_by_customer"
|
280
|
+
reason: "requested_by_customer",
|
281
|
+
receipt_url: nil
|
229
282
|
}.merge(params)
|
230
283
|
end
|
231
284
|
|
@@ -333,8 +386,9 @@ module StripeMock
|
|
333
386
|
},
|
334
387
|
cancel_at_period_end: false,
|
335
388
|
canceled_at: nil,
|
389
|
+
collection_method: 'charge_automatically',
|
336
390
|
ended_at: nil,
|
337
|
-
|
391
|
+
start_date: 1308595038,
|
338
392
|
object: 'subscription',
|
339
393
|
trial_start: 1308595038,
|
340
394
|
trial_end: 1308681468,
|
@@ -342,7 +396,12 @@ module StripeMock
|
|
342
396
|
quantity: 1,
|
343
397
|
tax_percent: nil,
|
344
398
|
discount: nil,
|
345
|
-
metadata: {}
|
399
|
+
metadata: {},
|
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
|
346
405
|
}, params)
|
347
406
|
end
|
348
407
|
|
@@ -358,9 +417,11 @@ module StripeMock
|
|
358
417
|
created: 1349738950,
|
359
418
|
period_end: 1349738950,
|
360
419
|
period_start: 1349738950,
|
420
|
+
due_date: nil,
|
361
421
|
lines: {
|
362
422
|
object: "list",
|
363
423
|
total_count: lines.count,
|
424
|
+
has_more: false,
|
364
425
|
url: "/v1/invoices/#{in_id}/lines",
|
365
426
|
data: lines
|
366
427
|
},
|
@@ -385,11 +446,12 @@ module StripeMock
|
|
385
446
|
amount_paid: 0,
|
386
447
|
currency: currency,
|
387
448
|
starting_balance: 0,
|
388
|
-
ending_balance:
|
449
|
+
ending_balance: 0,
|
389
450
|
next_payment_attempt: 1349825350,
|
390
451
|
charge: nil,
|
391
452
|
discount: nil,
|
392
|
-
subscription: nil
|
453
|
+
subscription: nil,
|
454
|
+
number: "6C41730-0001"
|
393
455
|
}.merge(params)
|
394
456
|
if invoice[:discount]
|
395
457
|
invoice[:total] = [0, invoice[:subtotal] - invoice[:discount][:coupon][:amount_off]].max if invoice[:discount][:coupon][:amount_off]
|
@@ -399,6 +461,7 @@ module StripeMock
|
|
399
461
|
end
|
400
462
|
due = invoice[:total] + invoice[:starting_balance]
|
401
463
|
invoice[:amount_due] = due < 0 ? 0 : due
|
464
|
+
invoice[:ending_balance] = invoice[:starting_balance] + invoice[:total] if invoice[:amount_due] == 0
|
402
465
|
invoice
|
403
466
|
end
|
404
467
|
|
@@ -521,33 +584,115 @@ module StripeMock
|
|
521
584
|
def self.mock_plan(params={})
|
522
585
|
currency = params[:currency] || StripeMock.default_currency
|
523
586
|
{
|
524
|
-
id: "
|
587
|
+
id: "mock_plan_123",
|
525
588
|
object: "plan",
|
589
|
+
active: true,
|
590
|
+
aggregate_usage: nil,
|
526
591
|
amount: 2300,
|
592
|
+
billing_scheme: "per_unit",
|
527
593
|
created: 1466698898,
|
528
594
|
currency: currency,
|
529
595
|
interval: "month",
|
530
596
|
interval_count: 1,
|
531
597
|
livemode: false,
|
532
598
|
metadata: {},
|
533
|
-
|
534
|
-
|
535
|
-
|
599
|
+
nickname: "My Mock Plan",
|
600
|
+
product: "mock_prod_NONEXIST", # override this with your own existing product id
|
601
|
+
tiers: nil,
|
602
|
+
tiers_mode: nil,
|
603
|
+
transform_usage: nil,
|
604
|
+
trial_period_days: nil,
|
605
|
+
usage_type: "licensed"
|
536
606
|
}.merge(params)
|
537
607
|
end
|
538
608
|
|
539
|
-
def self.
|
609
|
+
def self.mock_price(params={})
|
610
|
+
currency = params[:currency] || StripeMock.default_currency
|
540
611
|
{
|
541
|
-
id: "
|
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
|
+
|
637
|
+
def self.mock_product(params={})
|
638
|
+
{
|
639
|
+
id: "mock_prod_abc123",
|
542
640
|
object: "product",
|
543
641
|
active: true,
|
544
|
-
|
642
|
+
attributes:[],
|
643
|
+
caption: nil,
|
644
|
+
created: 1466698000,
|
645
|
+
deactivate_on: [],
|
646
|
+
description: nil,
|
647
|
+
images: [],
|
545
648
|
livemode: false,
|
546
649
|
metadata: {},
|
547
|
-
name: "
|
548
|
-
|
650
|
+
name: "The Mock Product",
|
651
|
+
package_dimensions: nil,
|
652
|
+
shippable: nil,
|
653
|
+
statement_descriptor: nil,
|
549
654
|
type: "service",
|
550
|
-
|
655
|
+
unit_label: "my_unit",
|
656
|
+
updated: 1537939442,
|
657
|
+
url: nil
|
658
|
+
}.merge(params)
|
659
|
+
end
|
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
|
551
696
|
}.merge(params)
|
552
697
|
end
|
553
698
|
|
@@ -574,6 +719,7 @@ module StripeMock
|
|
574
719
|
object: "list",
|
575
720
|
url: "/v1/recipients/#{rp_id}/cards",
|
576
721
|
data: cards,
|
722
|
+
has_more: false,
|
577
723
|
total_count: cards.count
|
578
724
|
},
|
579
725
|
default_card: nil
|
@@ -981,6 +1127,16 @@ module StripeMock
|
|
981
1127
|
bitcoin_receiver: 1545182
|
982
1128
|
}
|
983
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
|
+
}],
|
984
1140
|
connect_reserved: [
|
985
1141
|
{
|
986
1142
|
currency: "usd",
|
@@ -1045,13 +1201,12 @@ module StripeMock
|
|
1045
1201
|
end
|
1046
1202
|
|
1047
1203
|
def self.mock_subscription_item(params = {})
|
1048
|
-
|
1204
|
+
id = params[:id] || 'test_si_default'
|
1049
1205
|
{
|
1050
|
-
id:
|
1206
|
+
id: id,
|
1051
1207
|
object: 'subscription_item',
|
1052
1208
|
created: 1504716183,
|
1053
|
-
metadata: {
|
1054
|
-
},
|
1209
|
+
metadata: {},
|
1055
1210
|
plan: {
|
1056
1211
|
id: 'PER_USER_PLAN1',
|
1057
1212
|
object: 'plan',
|
@@ -1088,5 +1243,188 @@ module StripeMock
|
|
1088
1243
|
secret: "ek_test_default"
|
1089
1244
|
}
|
1090
1245
|
end
|
1246
|
+
|
1247
|
+
def self.mock_payment_intent(params = {})
|
1248
|
+
payment_intent_id = params[:id] || "pi_1EwXFB2eZvKYlo2CggNnFBo8"
|
1249
|
+
amount = params[:amount] || 49900
|
1250
|
+
currency = params[:currency] || StripeMock.default_currency
|
1251
|
+
{
|
1252
|
+
id: payment_intent_id,
|
1253
|
+
object: "payment_intent",
|
1254
|
+
amount: amount,
|
1255
|
+
amount_capturable: 0,
|
1256
|
+
amount_received: 0,
|
1257
|
+
application: nil,
|
1258
|
+
application_fee_amount: nil,
|
1259
|
+
canceled_at: nil,
|
1260
|
+
cancellation_reason: nil,
|
1261
|
+
capture_method: "automatic",
|
1262
|
+
charges: {
|
1263
|
+
object: "list",
|
1264
|
+
data: [],
|
1265
|
+
has_more: false,
|
1266
|
+
total_count: 1,
|
1267
|
+
url: "/v1/charges?payment_intent=pi_1EwXFB2eZvKYlo2CggNnFBo8"
|
1268
|
+
},
|
1269
|
+
client_secret: "pi_1EwXFB2eZvKYlo2CggNnFBo8_secret_vOMkpqZu8ca7hxhfiO80tpT3v",
|
1270
|
+
confirmation_method: "manual",
|
1271
|
+
created: 1563208901,
|
1272
|
+
currency: currency,
|
1273
|
+
customer: nil,
|
1274
|
+
description: nil,
|
1275
|
+
invoice: nil,
|
1276
|
+
last_payment_error: nil,
|
1277
|
+
livemode: false,
|
1278
|
+
metadata: {},
|
1279
|
+
next_action: { type: "use_stripe_sdk" },
|
1280
|
+
on_behalf_of: nil,
|
1281
|
+
payment_method: nil,
|
1282
|
+
payment_method_types: [
|
1283
|
+
"card"
|
1284
|
+
],
|
1285
|
+
receipt_email: nil,
|
1286
|
+
review: nil,
|
1287
|
+
setup_future_usage: nil,
|
1288
|
+
shipping: nil,
|
1289
|
+
source: nil,
|
1290
|
+
statement_descriptor: nil,
|
1291
|
+
status: "requires_action",
|
1292
|
+
transfer_data: nil,
|
1293
|
+
transfer_group: nil
|
1294
|
+
}.merge(params)
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
def self.mock_payment_method(params = {})
|
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'
|
1316
|
+
},
|
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
|
+
}
|
1341
|
+
|
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])
|
1364
|
+
end
|
1365
|
+
|
1366
|
+
def self.mock_setup_intent(params = {})
|
1367
|
+
setup_intent_id = params[:id] || "seti_1F96eK2aLAadsDqo0AVIyPmC"
|
1368
|
+
{
|
1369
|
+
:id => setup_intent_id,
|
1370
|
+
:object => "setup_intent",
|
1371
|
+
:application => nil,
|
1372
|
+
:cancellation_reason => nil,
|
1373
|
+
:client_secret => "seti_1F96eK2aLAadsDqo0AVIyPmC_secret_FePTYgOoPFxDOUL53fFMSoTAyiXsWAV",
|
1374
|
+
:created => 1566204936,
|
1375
|
+
:customer => nil,
|
1376
|
+
:description => nil,
|
1377
|
+
:last_setup_error => nil,
|
1378
|
+
:livemode => false,
|
1379
|
+
:metadata => {},
|
1380
|
+
:next_action => nil,
|
1381
|
+
:on_behalf_of => nil,
|
1382
|
+
:payment_method => nil,
|
1383
|
+
:payment_method_options => {
|
1384
|
+
card: {request_three_d_secure: "automatic"}
|
1385
|
+
},
|
1386
|
+
:payment_method_types => ["card"],
|
1387
|
+
:status => "requires_payment_method",
|
1388
|
+
:usage => "off_session"
|
1389
|
+
}.merge(params)
|
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
|
1091
1429
|
end
|
1092
1430
|
end
|
data/lib/stripe_mock/instance.rb
CHANGED
@@ -20,7 +20,12 @@ module StripeMock
|
|
20
20
|
@@handlers.find {|h| method_url =~ h[:route] }
|
21
21
|
end
|
22
22
|
|
23
|
+
include StripeMock::RequestHandlers::PaymentIntents
|
24
|
+
include StripeMock::RequestHandlers::PaymentMethods
|
25
|
+
include StripeMock::RequestHandlers::SetupIntents
|
23
26
|
include StripeMock::RequestHandlers::ExternalAccounts
|
27
|
+
include StripeMock::RequestHandlers::AccountLinks
|
28
|
+
include StripeMock::RequestHandlers::ExpressLoginLinks
|
24
29
|
include StripeMock::RequestHandlers::Accounts
|
25
30
|
include StripeMock::RequestHandlers::Balance
|
26
31
|
include StripeMock::RequestHandlers::BalanceTransactions
|
@@ -37,7 +42,9 @@ module StripeMock
|
|
37
42
|
include StripeMock::RequestHandlers::InvoiceItems
|
38
43
|
include StripeMock::RequestHandlers::Orders
|
39
44
|
include StripeMock::RequestHandlers::Plans
|
45
|
+
include StripeMock::RequestHandlers::Prices
|
40
46
|
include StripeMock::RequestHandlers::Products
|
47
|
+
include StripeMock::RequestHandlers::PromotionCodes
|
41
48
|
include StripeMock::RequestHandlers::Refunds
|
42
49
|
include StripeMock::RequestHandlers::Recipients
|
43
50
|
include StripeMock::RequestHandlers::Transfers
|
@@ -46,11 +53,14 @@ module StripeMock
|
|
46
53
|
include StripeMock::RequestHandlers::Payouts
|
47
54
|
include StripeMock::RequestHandlers::EphemeralKey
|
48
55
|
include StripeMock::RequestHandlers::TaxRates
|
56
|
+
include StripeMock::RequestHandlers::Checkout
|
57
|
+
include StripeMock::RequestHandlers::Checkout::Session
|
49
58
|
|
50
59
|
attr_reader :accounts, :balance, :balance_transactions, :bank_tokens, :charges, :coupons, :customers,
|
51
|
-
:disputes, :events, :invoices, :invoice_items, :orders, :
|
52
|
-
:
|
53
|
-
:products, :tax_rates
|
60
|
+
:disputes, :events, :invoices, :invoice_items, :orders, :payment_intents, :payment_methods,
|
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
|
54
64
|
|
55
65
|
attr_accessor :error_queue, :debug, :conversion_rate, :account_balance
|
56
66
|
|
@@ -60,16 +70,22 @@ module StripeMock
|
|
60
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'])
|
61
71
|
@bank_tokens = {}
|
62
72
|
@card_tokens = {}
|
63
|
-
@customers = {}
|
73
|
+
@customers = { Stripe.api_key => {} }
|
64
74
|
@charges = {}
|
75
|
+
@payment_intents = {}
|
76
|
+
@payment_methods = {}
|
77
|
+
@setup_intents = {}
|
65
78
|
@coupons = {}
|
66
79
|
@disputes = Data.mock_disputes(['dp_05RsQX2eZvKYlo2C0FRTGSSA','dp_15RsQX2eZvKYlo2C0ERTYUIA', 'dp_25RsQX2eZvKYlo2C0ZXCVBNM', 'dp_35RsQX2eZvKYlo2C0QAZXSWE', 'dp_45RsQX2eZvKYlo2C0EDCVFRT', 'dp_55RsQX2eZvKYlo2C0OIKLJUY', 'dp_65RsQX2eZvKYlo2C0ASDFGHJ', 'dp_75RsQX2eZvKYlo2C0EDCXSWQ', 'dp_85RsQX2eZvKYlo2C0UJMCDET', 'dp_95RsQX2eZvKYlo2C0EDFRYUI'])
|
67
80
|
@events = {}
|
68
81
|
@invoices = {}
|
69
82
|
@invoice_items = {}
|
70
83
|
@orders = {}
|
84
|
+
@payment_methods = {}
|
71
85
|
@plans = {}
|
86
|
+
@prices = {}
|
72
87
|
@products = {}
|
88
|
+
@promotion_codes = {}
|
73
89
|
@recipients = {}
|
74
90
|
@refunds = {}
|
75
91
|
@transfers = {}
|
@@ -78,6 +94,8 @@ module StripeMock
|
|
78
94
|
@subscriptions_items = {}
|
79
95
|
@country_spec = {}
|
80
96
|
@tax_rates = {}
|
97
|
+
@checkout_sessions = {}
|
98
|
+
@checkout_session_line_items = {}
|
81
99
|
|
82
100
|
@debug = false
|
83
101
|
@error_queue = ErrorQueue.new
|
@@ -91,7 +109,7 @@ module StripeMock
|
|
91
109
|
@base_strategy = TestStrategies::Base.new
|
92
110
|
end
|
93
111
|
|
94
|
-
def mock_request(method, url, api_key: nil, api_base: nil, params: {}, headers: {})
|
112
|
+
def mock_request(method, url, api_key: nil, api_base: nil, usage: [], params: {}, headers: {})
|
95
113
|
return {} if method == :xtest
|
96
114
|
|
97
115
|
api_key ||= (Stripe.api_key || DUMMY_API_KEY)
|
@@ -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
|
@@ -3,8 +3,8 @@ module StripeMock
|
|
3
3
|
module BalanceTransactions
|
4
4
|
|
5
5
|
def BalanceTransactions.included(klass)
|
6
|
-
klass.add_handler 'get /v1/
|
7
|
-
klass.add_handler 'get /v1/
|
6
|
+
klass.add_handler 'get /v1/balance_transactions/(.*)', :get_balance_transaction
|
7
|
+
klass.add_handler 'get /v1/balance_transactions', :list_balance_transactions
|
8
8
|
end
|
9
9
|
|
10
10
|
def get_balance_transaction(route, method_url, params, headers)
|