stripe-ruby-mock 2.3.1 → 2.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.env +2 -0
  3. data/.travis.yml +8 -4
  4. data/README.md +12 -5
  5. data/lib/stripe_mock/api/account_balance.rb +14 -0
  6. data/lib/stripe_mock/api/client.rb +4 -4
  7. data/lib/stripe_mock/api/conversion_rate.rb +14 -0
  8. data/lib/stripe_mock/api/errors.rb +25 -13
  9. data/lib/stripe_mock/api/instance.rb +16 -6
  10. data/lib/stripe_mock/api/webhooks.rb +8 -1
  11. data/lib/stripe_mock/client.rb +18 -2
  12. data/lib/stripe_mock/data/list.rb +14 -2
  13. data/lib/stripe_mock/data.rb +398 -58
  14. data/lib/stripe_mock/instance.rb +105 -9
  15. data/lib/stripe_mock/request_handlers/accounts.rb +41 -2
  16. data/lib/stripe_mock/request_handlers/balance.rb +17 -0
  17. data/lib/stripe_mock/request_handlers/balance_transactions.rb +18 -2
  18. data/lib/stripe_mock/request_handlers/charges.rb +44 -33
  19. data/lib/stripe_mock/request_handlers/country_spec.rb +22 -0
  20. data/lib/stripe_mock/request_handlers/coupons.rb +5 -4
  21. data/lib/stripe_mock/request_handlers/customers.rb +29 -11
  22. data/lib/stripe_mock/request_handlers/ephemeral_key.rb +13 -0
  23. data/lib/stripe_mock/request_handlers/external_accounts.rb +55 -0
  24. data/lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb +1 -1
  25. data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +9 -7
  26. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +10 -6
  27. data/lib/stripe_mock/request_handlers/helpers/external_account_helpers.rb +49 -0
  28. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +59 -16
  29. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +3 -2
  30. data/lib/stripe_mock/request_handlers/invoices.rb +93 -14
  31. data/lib/stripe_mock/request_handlers/orders.rb +5 -5
  32. data/lib/stripe_mock/request_handlers/payouts.rb +32 -0
  33. data/lib/stripe_mock/request_handlers/plans.rb +1 -0
  34. data/lib/stripe_mock/request_handlers/products.rb +43 -0
  35. data/lib/stripe_mock/request_handlers/recipients.rb +12 -0
  36. data/lib/stripe_mock/request_handlers/refunds.rb +91 -0
  37. data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
  38. data/lib/stripe_mock/request_handlers/subscriptions.rb +101 -39
  39. data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
  40. data/lib/stripe_mock/request_handlers/tokens.rb +9 -3
  41. data/lib/stripe_mock/request_handlers/transfers.rb +11 -5
  42. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +15 -1
  43. data/lib/stripe_mock/server.rb +14 -1
  44. data/lib/stripe_mock/test_strategies/base.rb +10 -5
  45. data/lib/stripe_mock/test_strategies/live.rb +5 -0
  46. data/lib/stripe_mock/test_strategies/mock.rb +8 -0
  47. data/lib/stripe_mock/util.rb +8 -2
  48. data/lib/stripe_mock/version.rb +1 -1
  49. data/lib/stripe_mock/webhook_fixtures/account.external_account.created.json +27 -0
  50. data/lib/stripe_mock/webhook_fixtures/account.external_account.deleted.json +27 -0
  51. data/lib/stripe_mock/webhook_fixtures/account.external_account.updated.json +27 -0
  52. data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
  53. data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
  54. data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
  55. data/lib/stripe_mock/webhook_fixtures/charge.updated.json +58 -0
  56. data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +40 -10
  57. data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +39 -10
  58. data/lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json +39 -10
  59. data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +40 -11
  60. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +3 -2
  61. data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +1 -1
  62. data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +92 -85
  63. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +3 -2
  64. data/lib/stripe_mock/webhook_fixtures/plan.created.json +1 -1
  65. data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +1 -1
  66. data/lib/stripe_mock/webhook_fixtures/plan.updated.json +1 -1
  67. data/lib/stripe_mock.rb +15 -0
  68. data/spec/api/instance_spec.rb +30 -0
  69. data/spec/instance_spec.rb +54 -4
  70. data/spec/integration_examples/prepare_error_examples.rb +6 -6
  71. data/spec/list_spec.rb +27 -10
  72. data/spec/readme_spec.rb +2 -0
  73. data/spec/server_spec.rb +7 -3
  74. data/spec/shared_stripe_examples/account_examples.rb +46 -0
  75. data/spec/shared_stripe_examples/balance_examples.rb +11 -0
  76. data/spec/shared_stripe_examples/balance_transaction_examples.rb +28 -0
  77. data/spec/shared_stripe_examples/bank_examples.rb +28 -1
  78. data/spec/shared_stripe_examples/card_examples.rb +23 -5
  79. data/spec/shared_stripe_examples/card_token_examples.rb +1 -0
  80. data/spec/shared_stripe_examples/charge_examples.rb +131 -26
  81. data/spec/shared_stripe_examples/country_specs_examples.rb +18 -0
  82. data/spec/shared_stripe_examples/coupon_examples.rb +8 -2
  83. data/spec/shared_stripe_examples/customer_examples.rb +90 -0
  84. data/spec/shared_stripe_examples/dispute_examples.rb +19 -8
  85. data/spec/shared_stripe_examples/ephemeral_key_examples.rb +17 -0
  86. data/spec/shared_stripe_examples/error_mock_examples.rb +15 -5
  87. data/spec/shared_stripe_examples/external_account_examples.rb +170 -0
  88. data/spec/shared_stripe_examples/extra_features_examples.rb +2 -0
  89. data/spec/shared_stripe_examples/invoice_examples.rb +314 -51
  90. data/spec/shared_stripe_examples/payout_examples.rb +68 -0
  91. data/spec/shared_stripe_examples/plan_examples.rb +47 -4
  92. data/spec/shared_stripe_examples/product_example.rb +65 -0
  93. data/spec/shared_stripe_examples/recipient_examples.rb +13 -7
  94. data/spec/shared_stripe_examples/refund_examples.rb +453 -84
  95. data/spec/shared_stripe_examples/subscription_examples.rb +477 -32
  96. data/spec/shared_stripe_examples/subscription_items_examples.rb +75 -0
  97. data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
  98. data/spec/shared_stripe_examples/transfer_examples.rb +72 -23
  99. data/spec/shared_stripe_examples/webhook_event_examples.rb +74 -5
  100. data/spec/spec_helper.rb +7 -6
  101. data/spec/stripe_mock_spec.rb +16 -3
  102. data/spec/support/stripe_examples.rb +8 -1
  103. data/spec/util_spec.rb +35 -1
  104. data/stripe-ruby-mock.gemspec +1 -1
  105. metadata +44 -8
  106. data/ChangeLog.rdoc +0 -4
@@ -3,6 +3,7 @@ module StripeMock
3
3
 
4
4
  def self.mock_account(params = {})
5
5
  id = params[:id] || 'acct_103ED82ePvKYlo2C'
6
+ currency = params[:currency] || StripeMock.default_currency
6
7
  {
7
8
  id: id,
8
9
  email: "bob@example.com",
@@ -11,11 +12,11 @@ module StripeMock
11
12
  timezone: "US/Pacific",
12
13
  details_submitted: false,
13
14
  charges_enabled: false,
14
- transfers_enabled: false,
15
+ payouts_enabled: false,
15
16
  currencies_supported: [
16
17
  "usd"
17
18
  ],
18
- default_currency: "usd",
19
+ default_currency: currency,
19
20
  country: "US",
20
21
  object: "account",
21
22
  business_name: "Stripe.com",
@@ -47,6 +48,15 @@ module StripeMock
47
48
  date: nil,
48
49
  user_agent: nil
49
50
  },
51
+ external_accounts: {
52
+ object: "list",
53
+ data: [
54
+
55
+ ],
56
+ has_more: false,
57
+ total_count: 0,
58
+ url: "/v1/accounts/#{id}/external_accounts"
59
+ },
50
60
  legal_entity: {
51
61
  type: nil,
52
62
  business_name: nil,
@@ -91,8 +101,25 @@ module StripeMock
91
101
  }.merge(params)
92
102
  end
93
103
 
104
+ def self.mock_tax_rate(params)
105
+ {
106
+ id: 'test_cus_default',
107
+ object: 'tax_rate',
108
+ active: true,
109
+ created: 1559079603,
110
+ description: nil,
111
+ display_name: 'VAT',
112
+ inclusive: false,
113
+ jurisdiction: 'EU',
114
+ livemode: false,
115
+ metadata: {},
116
+ percentage: 21.0
117
+ }.merge(params)
118
+ end
119
+
94
120
  def self.mock_customer(sources, params)
95
121
  cus_id = params[:id] || "test_cus_default"
122
+ currency = params[:currency] || StripeMock.default_currency
96
123
  sources.each {|source| source[:customer] = cus_id}
97
124
  {
98
125
  email: 'stripe_mock@example.com',
@@ -100,11 +127,12 @@ module StripeMock
100
127
  object: "customer",
101
128
  created: 1372126710,
102
129
  id: cus_id,
130
+ name: nil,
103
131
  livemode: false,
104
132
  delinquent: false,
105
133
  discount: nil,
106
134
  account_balance: 0,
107
- currency: nil,
135
+ currency: currency,
108
136
  sources: {
109
137
  object: "list",
110
138
  total_count: sources.size,
@@ -123,6 +151,7 @@ module StripeMock
123
151
 
124
152
  def self.mock_charge(params={})
125
153
  charge_id = params[:id] || "ch_1fD6uiR9FAA2zc"
154
+ currency = params[:currency] || StripeMock.default_currency
126
155
  {
127
156
  id: charge_id,
128
157
  object: "charge",
@@ -131,7 +160,7 @@ module StripeMock
131
160
  paid: true,
132
161
  amount: 0,
133
162
  application_fee: nil,
134
- currency: "usd",
163
+ currency: currency,
135
164
  destination: nil,
136
165
  fraud_details: {},
137
166
  receipt_email: nil,
@@ -184,17 +213,19 @@ module StripeMock
184
213
  end
185
214
 
186
215
  def self.mock_refund(params={})
216
+ currency = params[:currency] || StripeMock.default_currency
187
217
  {
188
218
  id: "re_4fWhgUh5si7InF",
189
219
  amount: 1,
190
- currency: "usd",
220
+ currency: currency,
191
221
  created: 1409165988,
192
222
  object: "refund",
193
223
  balance_transaction: "txn_4fWh2RKvgxcXqV",
194
224
  metadata: {},
195
225
  charge: "ch_4fWhYjzQ23UFWT",
196
226
  receipt_number: nil,
197
- status: "succeeded"
227
+ status: "succeeded",
228
+ reason: "requested_by_customer"
198
229
  }.merge(params)
199
230
  end
200
231
 
@@ -228,23 +259,28 @@ module StripeMock
228
259
  address_country: nil,
229
260
  cvc_check: nil,
230
261
  address_line1_check: nil,
231
- address_zip_check: nil
262
+ address_zip_check: nil,
263
+ tokenization_method: nil,
264
+ metadata: {}
232
265
  }, params)
233
266
  end
234
267
 
235
268
  def self.mock_bank_account(params={})
269
+ currency = params[:currency] || StripeMock.default_currency
236
270
  {
271
+ id: "test_ba_default",
237
272
  object: "bank_account",
238
273
  bank_name: "STRIPEMOCK TEST BANK",
239
274
  last4: "6789",
240
275
  routing_number: '110000000',
241
276
  country: "US",
242
- currency: "usd",
277
+ currency: currency,
243
278
  validated: false,
244
279
  status: 'new',
245
280
  account_holder_name: 'John Doe',
246
281
  account_holder_type: 'individual',
247
- fingerprint: "aBcFinGerPrINt123"
282
+ fingerprint: "aBcFinGerPrINt123",
283
+ metadata: {}
248
284
  }.merge(params)
249
285
  end
250
286
 
@@ -267,37 +303,59 @@ module StripeMock
267
303
  #FIXME nested overrides would be better than hardcoding plan_id
268
304
  def self.mock_subscription(params={})
269
305
  StripeMock::Util.rmerge({
270
- :current_period_start => 1308595038,
271
- :current_period_end => 1308681468,
272
- :status => "trialing",
273
- :plan => {
274
- :interval => "month",
275
- :amount => 7500,
276
- :trial_period_days => 30,
277
- :object => "plan",
278
- :id => '__test_plan_id__'
306
+ created: 1478204116,
307
+ billing: 'charge_automatically',
308
+ current_period_start: 1308595038,
309
+ current_period_end: 1308681468,
310
+ status: 'trialing',
311
+ trial_from_plan: false,
312
+ plan: {
313
+ interval: 'month',
314
+ amount: 7500,
315
+ trial_period_days: 30,
316
+ object: 'plan',
317
+ id: '__test_plan_id__'
318
+ },
319
+ items: {
320
+ object: 'list',
321
+ data: [{
322
+ id: 'si_1AwFf62eZvKYlo2C9u6Dhf9',
323
+ created: 1504035973,
324
+ metadata: {},
325
+ object: 'subscription_item',
326
+ plan: {
327
+ amount: 999,
328
+ created: 1504035972,
329
+ currency: StripeMock.default_currency
330
+ },
331
+ quantity: 1
332
+ }]
279
333
  },
280
- :cancel_at_period_end => false,
281
- :canceled_at => nil,
282
- :ended_at => nil,
283
- :start => 1308595038,
284
- :object => "subscription",
285
- :trial_start => 1308595038,
286
- :trial_end => 1308681468,
287
- :customer => "c_test_customer",
288
- :quantity => 1,
289
- :tax_percent => nil,
290
- :discount => nil,
291
- :metadata => {}
334
+ cancel_at_period_end: false,
335
+ canceled_at: nil,
336
+ ended_at: nil,
337
+ start: 1308595038,
338
+ object: 'subscription',
339
+ trial_start: 1308595038,
340
+ trial_end: 1308681468,
341
+ customer: 'c_test_customer',
342
+ quantity: 1,
343
+ tax_percent: nil,
344
+ discount: nil,
345
+ metadata: {}
292
346
  }, params)
293
347
  end
294
348
 
295
349
  def self.mock_invoice(lines, params={})
296
350
  in_id = params[:id] || "test_in_default"
351
+ currency = params[:currency] || StripeMock.default_currency
297
352
  lines << Data.mock_line_item() if lines.empty?
298
- {
353
+ invoice = {
299
354
  id: 'in_test_invoice',
300
- date: 1349738950,
355
+ status: 'open',
356
+ invoice_pdf: 'pdf_url',
357
+ hosted_invoice_url: 'hosted_invoice_url',
358
+ created: 1349738950,
301
359
  period_end: 1349738950,
302
360
  period_start: 1349738950,
303
361
  lines: {
@@ -307,7 +365,6 @@ module StripeMock
307
365
  data: lines
308
366
  },
309
367
  subtotal: lines.map {|line| line[:amount]}.reduce(0, :+),
310
- total: lines.map {|line| line[:amount]}.reduce(0, :+),
311
368
  customer: "test_customer",
312
369
  object: 'invoice',
313
370
  attempted: false,
@@ -319,13 +376,14 @@ module StripeMock
319
376
  paid: false,
320
377
  receipt_number: nil,
321
378
  statement_descriptor: nil,
322
- tax: nil,
379
+ tax: 10,
323
380
  tax_percent: nil,
324
381
  webhooks_delivered_at: 1349825350,
325
382
  livemode: false,
326
383
  attempt_count: 0,
327
- amount_due: lines.map {|line| line[:amount]}.reduce(0, :+),
328
- currency: 'usd',
384
+ amount_due: 100,
385
+ amount_paid: 0,
386
+ currency: currency,
329
387
  starting_balance: 0,
330
388
  ending_balance: nil,
331
389
  next_payment_attempt: 1349825350,
@@ -333,22 +391,37 @@ module StripeMock
333
391
  discount: nil,
334
392
  subscription: nil
335
393
  }.merge(params)
394
+ if invoice[:discount]
395
+ invoice[:total] = [0, invoice[:subtotal] - invoice[:discount][:coupon][:amount_off]].max if invoice[:discount][:coupon][:amount_off]
396
+ invoice[:total] = invoice[:subtotal] * invoice[:discount][:coupon][:percent_off] / 100 if invoice[:discount][:coupon][:percent_off]
397
+ else
398
+ invoice[:total] = invoice[:subtotal]
399
+ end
400
+ due = invoice[:total] + invoice[:starting_balance]
401
+ invoice[:amount_due] = due < 0 ? 0 : due
402
+ invoice
336
403
  end
337
404
 
338
405
  def self.mock_line_item(params = {})
406
+ currency = params[:currency] || StripeMock.default_currency
339
407
  {
340
408
  id: "ii_test",
341
409
  object: "line_item",
342
410
  type: "invoiceitem",
343
411
  livemode: false,
344
412
  amount: 1000,
345
- currency: "usd",
413
+ currency: currency,
346
414
  discountable: false,
347
415
  proration: false,
348
416
  period: {
349
417
  start: 1349738920,
350
418
  end: 1349738920
351
419
  },
420
+ tax_amounts: [
421
+ {
422
+ amount: 10
423
+ }
424
+ ],
352
425
  quantity: nil,
353
426
  subscription: nil,
354
427
  plan: nil,
@@ -358,14 +431,15 @@ module StripeMock
358
431
  end
359
432
 
360
433
  def self.mock_invoice_item(params = {})
434
+ currency = params[:currency] || StripeMock.default_currency
361
435
  {
362
436
  id: "test_ii",
363
437
  object: "invoiceitem",
364
- date: 1349738920,
438
+ created: 1349738920,
365
439
  amount: 1099,
366
440
  livemode: false,
367
441
  proration: false,
368
- currency: "usd",
442
+ currency: currency,
369
443
  customer: "cus_test",
370
444
  description: "invoice item desc",
371
445
  metadata: {},
@@ -396,6 +470,7 @@ module StripeMock
396
470
 
397
471
  def self.mock_order(order_items, params)
398
472
  or_id = params[:id] || "test_or_default"
473
+ currency = params[:currency] || 'eur'
399
474
  order_items << Data.mock_order_item if order_items.empty?
400
475
  {
401
476
  id: or_id,
@@ -405,7 +480,7 @@ module StripeMock
405
480
  application_fee: nil,
406
481
  charge: nil,
407
482
  created: 1448272783,
408
- currency: "eur",
483
+ currency: currency,
409
484
  customer: nil,
410
485
  email: nil,
411
486
  items: order_items,
@@ -431,10 +506,11 @@ module StripeMock
431
506
  end
432
507
 
433
508
  def self.mock_order_item(params={})
509
+ currency = params[:currency] || 'eur'
434
510
  {
435
511
  object: "order_item",
436
512
  amount: 5000,
437
- currency: "eur",
513
+ currency: currency,
438
514
  description: "Anyitem",
439
515
  parent: "sku_parent",
440
516
  quantity: 1,
@@ -443,12 +519,13 @@ module StripeMock
443
519
  end
444
520
 
445
521
  def self.mock_plan(params={})
522
+ currency = params[:currency] || StripeMock.default_currency
446
523
  {
447
524
  id: "2",
448
525
  object: "plan",
449
526
  amount: 2300,
450
527
  created: 1466698898,
451
- currency: "usd",
528
+ currency: currency,
452
529
  interval: "month",
453
530
  interval_count: 1,
454
531
  livemode: false,
@@ -459,6 +536,21 @@ module StripeMock
459
536
  }.merge(params)
460
537
  end
461
538
 
539
+ def self.mock_product(params = {})
540
+ {
541
+ id: "default_test_prod",
542
+ object: "product",
543
+ active: true,
544
+ created: 1556896214,
545
+ livemode: false,
546
+ metadata: {},
547
+ name: "Default Test Product",
548
+ statement_descriptor: "PRODUCT",
549
+ type: "service",
550
+ updated: 1556918200,
551
+ }.merge(params)
552
+ end
553
+
462
554
  def self.mock_recipient(cards, params={})
463
555
  rp_id = params[:id] || "test_rp_default"
464
556
  cards.each {|card| card[:recipient] = rp_id}
@@ -543,32 +635,47 @@ module StripeMock
543
635
  end
544
636
 
545
637
  def self.mock_transfer(params={})
638
+ currency = params[:currency] || StripeMock.default_currency
546
639
  id = params[:id] || 'tr_test_transfer'
547
640
  {
548
- :status => 'pending',
549
641
  :amount => 100,
550
- :account => {
551
- :object => 'bank_account',
552
- :country => 'US',
553
- :bank_name => 'STRIPE TEST BANK',
554
- :last4 => '6789'
555
- },
556
- :recipient => 'test_recipient',
557
- :fee => 0,
558
- :fee_details => [],
642
+ :amount_reversed => 0,
643
+ :balance_transaction => "txn_2dyYXXP90MN26R",
559
644
  :id => id,
560
645
  :livemode => false,
561
- :currency => "usd",
646
+ :metadata => {},
647
+ :currency => currency,
562
648
  :object => "transfer",
563
- :date => 1304114826,
649
+ :created => 1304114826,
564
650
  :description => "Transfer description",
565
651
  :reversed => false,
566
652
  :reversals => {
567
653
  :object => "list",
654
+ :data => [],
568
655
  :total_count => 0,
569
656
  :has_more => false,
570
657
  :url => "/v1/transfers/#{id}/reversals"
571
658
  },
659
+ :destination => "acct_164wxjKbnvuxQXGu",
660
+ :destination_payment => "py_164xRvKbnvuxQXGuVFV2pZo1",
661
+ :source_transaction => "ch_164xRv2eZvKYlo2Clu1sIJWB",
662
+ :source_type => "card",
663
+ :transfer_group => "group_ch_164xRv2eZvKYlo2Clu1sIJWB",
664
+ }.merge(params)
665
+ end
666
+
667
+ def self.mock_payout(params={})
668
+ currency = params[:currency] || StripeMock.default_currency
669
+ id = params[:id] || 'po_test_payout'
670
+ {
671
+ :amount => 100,
672
+ :id => id,
673
+ :livemode => false,
674
+ :metadata => {},
675
+ :currency => currency,
676
+ :object => "payout",
677
+ :date => 1304114826,
678
+ :description => "Payout description",
572
679
  }.merge(params)
573
680
  end
574
681
 
@@ -581,6 +688,8 @@ module StripeMock
581
688
  end
582
689
 
583
690
  def self.mock_dispute(params={})
691
+ @timestamp ||= Time.now.to_i
692
+ currency = params[:currency] || StripeMock.default_currency
584
693
  id = params[:id] || "dp_test_dispute"
585
694
  {
586
695
  :id => id,
@@ -588,8 +697,8 @@ module StripeMock
588
697
  :amount => 195,
589
698
  :balance_transactions => [],
590
699
  :charge => "ch_15RsQR2eZvKYlo2CA8IfzCX0",
591
- :created => 1422915137,
592
- :currency => "usd",
700
+ :created => @timestamp += 1,
701
+ :currency => currency,
593
702
  :evidence => self.mock_dispute_evidence,
594
703
  :evidence_details => self.mock_dispute_evidence_details,
595
704
  :is_charge_refundable => false,
@@ -705,6 +814,192 @@ module StripeMock
705
814
  list.to_h
706
815
  end
707
816
 
817
+ def self.mock_country_spec(country_code)
818
+ id = country_code || "US"
819
+ {
820
+ "id"=> "US",
821
+ "object"=> "country_spec",
822
+ "default_currency"=> "usd",
823
+ "supported_bank_account_currencies"=> {"usd"=>["US"]},
824
+ "supported_payment_currencies"=> [
825
+ "usd",
826
+ "aed",
827
+ "afn",
828
+ "all",
829
+ "amd",
830
+ "ang",
831
+ "aoa",
832
+ "ars",
833
+ "aud",
834
+ "awg",
835
+ "azn",
836
+ "bam",
837
+ "bbd",
838
+ "bdt",
839
+ "bgn",
840
+ "bif",
841
+ "bmd",
842
+ "bnd",
843
+ "bob",
844
+ "brl",
845
+ "bsd",
846
+ "bwp",
847
+ "bzd",
848
+ "cad",
849
+ "cdf",
850
+ "chf",
851
+ "clp",
852
+ "cny",
853
+ "cop",
854
+ "crc",
855
+ "cve",
856
+ "czk",
857
+ "djf",
858
+ "dkk",
859
+ "dop",
860
+ "dzd",
861
+ "egp",
862
+ "etb",
863
+ "eur",
864
+ "fjd",
865
+ "fkp",
866
+ "gbp",
867
+ "gel",
868
+ "gip",
869
+ "gmd",
870
+ "gnf",
871
+ "gtq",
872
+ "gyd",
873
+ "hkd",
874
+ "hnl",
875
+ "hrk",
876
+ "htg",
877
+ "huf",
878
+ "idr",
879
+ "ils",
880
+ "inr",
881
+ "isk",
882
+ "jmd",
883
+ "jpy",
884
+ "kes",
885
+ "kgs",
886
+ "khr",
887
+ "kmf",
888
+ "krw",
889
+ "kyd",
890
+ "kzt",
891
+ "lak",
892
+ "lbp",
893
+ "lkr",
894
+ "lrd",
895
+ "lsl",
896
+ "ltl",
897
+ "mad",
898
+ "mdl",
899
+ "mga",
900
+ "mkd",
901
+ "mnt",
902
+ "mop",
903
+ "mro",
904
+ "mur",
905
+ "mvr",
906
+ "mwk",
907
+ "mxn",
908
+ "myr",
909
+ "mzn",
910
+ "nad",
911
+ "ngn",
912
+ "nio",
913
+ "nok",
914
+ "npr",
915
+ "nzd",
916
+ "pab",
917
+ "pen",
918
+ "pgk",
919
+ "php",
920
+ "pkr",
921
+ "pln",
922
+ "pyg",
923
+ "qar",
924
+ "ron",
925
+ "rsd",
926
+ "rub",
927
+ "rwf",
928
+ "sar",
929
+ "sbd",
930
+ "scr",
931
+ "sek",
932
+ "sgd",
933
+ "shp",
934
+ "sll",
935
+ "sos",
936
+ "srd",
937
+ "std",
938
+ "svc",
939
+ "szl",
940
+ "thb",
941
+ "tjs",
942
+ "top",
943
+ "try",
944
+ "ttd",
945
+ "twd",
946
+ "tzs",
947
+ "uah",
948
+ "ugx",
949
+ "uyu",
950
+ "uzs",
951
+ "vnd",
952
+ "vuv",
953
+ "wst",
954
+ "xaf",
955
+ "xcd",
956
+ "xof",
957
+ "xpf",
958
+ "yer",
959
+ "zar",
960
+ "zmw"
961
+ ],
962
+ "supported_payment_methods"=> [
963
+ "alipay",
964
+ "card",
965
+ "stripe"
966
+ ],
967
+ "verification_fields"=> {"individual"=>{"minimum"=>["external_account","legal_entity.address.city","legal_entity.address.line1","legal_entity.address.postal_code","legal_entity.address.state","legal_entity.dob.day","legal_entity.dob.month","legal_entity.dob.year","legal_entity.first_name","legal_entity.last_name","legal_entity.personal_id_number","legal_entity.ssn_last_4","legal_entity.type","tos_acceptance.date","tos_acceptance.ip"],"additional"=>["legal_entity.personal_id_number","legal_entity.verification.document"]},"company"=>{"minimum"=>["external_account","legal_entity.address.city","legal_entity.address.line1","legal_entity.address.postal_code","legal_entity.address.state","legal_entity.business_name","legal_entity.business_tax_id","legal_entity.dob.day","legal_entity.dob.month","legal_entity.dob.year","legal_entity.first_name","legal_entity.last_name","legal_entity.ssn_last_4","legal_entity.type","tos_acceptance.date","tos_acceptance.ip"],"additional"=>["legal_entity.personal_id_number","legal_entity.verification.document"]}}
968
+ }
969
+ end
970
+
971
+ def self.mock_balance(usd_balance = 10000)
972
+ {
973
+ object: "balance",
974
+ available: [
975
+ {
976
+ currency: "usd",
977
+ amount: usd_balance,
978
+ source_types: {
979
+ card: 25907032203,
980
+ bank_account: 108476658,
981
+ bitcoin_receiver: 1545182
982
+ }
983
+ }],
984
+ connect_reserved: [
985
+ {
986
+ currency: "usd",
987
+ amount: 4700
988
+ }],
989
+ livemode: false,
990
+ pending: [
991
+ {
992
+ currency: "usd",
993
+ amount: 22738833554,
994
+ source_types: {
995
+ card: 22738826610,
996
+ bank_account: 0,
997
+ bitcoin_receiver: 6944
998
+ }
999
+ }]
1000
+ }
1001
+ end
1002
+
708
1003
  def self.mock_balance_transactions(ids=[])
709
1004
  bts = {}
710
1005
  ids.each do |id|
@@ -714,6 +1009,7 @@ module StripeMock
714
1009
  end
715
1010
 
716
1011
  def self.mock_balance_transaction(params = {})
1012
+ currency = params[:currency] || StripeMock.default_currency
717
1013
  bt_id = params[:id] || 'test_txn_default'
718
1014
  source = params[:source] || 'ch_test_charge'
719
1015
  {
@@ -722,14 +1018,14 @@ module StripeMock
722
1018
  amount: 10000,
723
1019
  available_on: 1462406400,
724
1020
  created: 1461880226,
725
- currency: "usd",
1021
+ currency: currency,
726
1022
  description: nil,
727
1023
  fee: 320,
728
1024
  fee_details: [
729
1025
  {
730
1026
  amount: 320,
731
1027
  application: nil,
732
- currency: "usd",
1028
+ currency: currency,
733
1029
  description: "Stripe processing fees",
734
1030
  type: "stripe_fee"
735
1031
  }
@@ -748,5 +1044,49 @@ module StripeMock
748
1044
  }.merge(params)
749
1045
  end
750
1046
 
1047
+ def self.mock_subscription_item(params = {})
1048
+ iid = params[:id] || 'test_txn_default'
1049
+ {
1050
+ id: iid,
1051
+ object: 'subscription_item',
1052
+ created: 1504716183,
1053
+ metadata: {
1054
+ },
1055
+ plan: {
1056
+ id: 'PER_USER_PLAN1',
1057
+ object: 'plan',
1058
+ amount: 1337,
1059
+ created: 1504716177,
1060
+ currency: StripeMock.default_currency,
1061
+ interval: 'month',
1062
+ interval_count: 1,
1063
+ livemode: false,
1064
+ metadata: {},
1065
+ name: 'StripeMock Default Plan ID',
1066
+ statement_descriptor: nil,
1067
+ trial_period_days: nil
1068
+ },
1069
+ quantity: 2
1070
+ }.merge(params)
1071
+ end
1072
+
1073
+ def self.mock_ephemeral_key(**params)
1074
+ created = Time.now.to_i
1075
+ expires = created + 34_000
1076
+ {
1077
+ id: "ephkey_default",
1078
+ object: "ephemeral_key",
1079
+ associated_objects: [
1080
+ {
1081
+ id: params[:customer],
1082
+ type: "customer"
1083
+ }
1084
+ ],
1085
+ created: created,
1086
+ expires: expires,
1087
+ livemode: false,
1088
+ secret: "ek_test_default"
1089
+ }
1090
+ end
751
1091
  end
752
1092
  end