stripe-ruby-mock 2.3.1 → 2.4.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/stripe_mock.rb +2 -0
  4. data/lib/stripe_mock/api/errors.rb +2 -1
  5. data/lib/stripe_mock/api/instance.rb +10 -0
  6. data/lib/stripe_mock/api/webhooks.rb +3 -0
  7. data/lib/stripe_mock/data.rb +196 -17
  8. data/lib/stripe_mock/instance.rb +14 -3
  9. data/lib/stripe_mock/request_handlers/accounts.rb +7 -0
  10. data/lib/stripe_mock/request_handlers/charges.rb +24 -21
  11. data/lib/stripe_mock/request_handlers/country_spec.rb +22 -0
  12. data/lib/stripe_mock/request_handlers/customers.rb +3 -3
  13. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +5 -2
  14. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +2 -1
  15. data/lib/stripe_mock/request_handlers/recipients.rb +12 -0
  16. data/lib/stripe_mock/request_handlers/refunds.rb +88 -0
  17. data/lib/stripe_mock/request_handlers/subscriptions.rb +7 -6
  18. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +5 -0
  19. data/lib/stripe_mock/test_strategies/base.rb +7 -4
  20. data/lib/stripe_mock/version.rb +1 -1
  21. data/lib/stripe_mock/webhook_fixtures/account.external_account.created.json +27 -0
  22. data/lib/stripe_mock/webhook_fixtures/account.external_account.deleted.json +27 -0
  23. data/lib/stripe_mock/webhook_fixtures/account.external_account.updated.json +27 -0
  24. data/spec/api/instance_spec.rb +30 -0
  25. data/spec/list_spec.rb +11 -7
  26. data/spec/server_spec.rb +1 -1
  27. data/spec/shared_stripe_examples/account_examples.rb +11 -0
  28. data/spec/shared_stripe_examples/card_examples.rb +13 -2
  29. data/spec/shared_stripe_examples/card_token_examples.rb +1 -0
  30. data/spec/shared_stripe_examples/charge_examples.rb +64 -15
  31. data/spec/shared_stripe_examples/country_specs_examples.rb +18 -0
  32. data/spec/shared_stripe_examples/customer_examples.rb +38 -0
  33. data/spec/shared_stripe_examples/error_mock_examples.rb +12 -2
  34. data/spec/shared_stripe_examples/plan_examples.rb +11 -0
  35. data/spec/shared_stripe_examples/recipient_examples.rb +7 -1
  36. data/spec/shared_stripe_examples/refund_examples.rb +447 -84
  37. data/spec/shared_stripe_examples/subscription_examples.rb +15 -0
  38. data/spec/support/stripe_examples.rb +1 -0
  39. metadata +12 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7c2b8715ff3b25f019be501ef40f6d246448d39
4
- data.tar.gz: bbb68394eeb61334c49ce3f86d37ea44b513e516
3
+ metadata.gz: 2dc4a01998c2f9e1cd85aee1281cf75d5b4aa436
4
+ data.tar.gz: 045708a8af619fc7b299055f0822eed79f8cae1f
5
5
  SHA512:
6
- metadata.gz: 14dc5c186dc169b310d38e5639ee801863d3f856d36c7f9522c62608cd8d8667c8a69b7ddc6c80023537cb6b65866904fa2f5660c5f59e6c8290f5f3d918d4d3
7
- data.tar.gz: 1c8f4d5fcb31c4e8f1716e379b2aed29538a59d43ec2bc96e52751bae4c21a14e5265a6003fca7b12768c61061ad200d122a930461b04b1863d6c8c61cab2d30
6
+ metadata.gz: 918999885f3cf5e32133f85b535e76ecbe7c482b106b4fe70e9a8de03fcd95132bfd4d43496bc397492da84bfb5eded5c46807e70c2562ee38923e202bf6dd89
7
+ data.tar.gz: b9ab01a438f10f7148470641a0b0fddcd32b0fedfc28969a8f52020d483ed64e045e384f1acda6ec422680c54f34c36ace6dcb89b2a01949053e96269e9953a6
data/README.md CHANGED
@@ -12,7 +12,7 @@ This gem has unexpectedly grown in popularity and I've gotten pretty busy, so I'
12
12
 
13
13
  In your gemfile:
14
14
 
15
- gem 'stripe-ruby-mock', '~> 2.3.1', :require => 'stripe_mock'
15
+ gem 'stripe-ruby-mock', '~> 2.4.0', :require => 'stripe_mock'
16
16
 
17
17
  ## Features
18
18
 
@@ -57,9 +57,11 @@ require 'stripe_mock/request_handlers/invoice_items.rb'
57
57
  require 'stripe_mock/request_handlers/orders.rb'
58
58
  require 'stripe_mock/request_handlers/plans.rb'
59
59
  require 'stripe_mock/request_handlers/recipients.rb'
60
+ require 'stripe_mock/request_handlers/refunds.rb'
60
61
  require 'stripe_mock/request_handlers/transfers.rb'
61
62
  require 'stripe_mock/request_handlers/subscriptions.rb'
62
63
  require 'stripe_mock/request_handlers/tokens.rb'
64
+ require 'stripe_mock/request_handlers/country_spec.rb'
63
65
  require 'stripe_mock/instance'
64
66
 
65
67
  require 'stripe_mock/test_strategies/base.rb'
@@ -34,7 +34,8 @@ module StripeMock
34
34
  card_declined: add_json_body(["The card was declined", nil, 'card_declined', 402]),
35
35
  missing: add_json_body(["There is no card on a customer that is being charged.", nil, 'missing', 402]),
36
36
  processing_error: add_json_body(["An error occurred while processing the card", nil, 'processing_error', 402]),
37
- card_error: add_json_body(['The card number is not a valid credit card number.', 'number', 'invalid_number', 402])
37
+ card_error: add_json_body(['The card number is not a valid credit card number.', 'number', 'invalid_number', 402]),
38
+ incorrect_zip: add_json_body(['The zip code you supplied failed validation.', 'address_zip', 'incorrect_zip', 402])
38
39
  }
39
40
  end
40
41
 
@@ -18,6 +18,16 @@ module StripeMock
18
18
  @state = 'ready'
19
19
  end
20
20
 
21
+ # Yield the given block between StripeMock.start and StripeMock.stop
22
+ def self.mock(&block)
23
+ begin
24
+ self.start
25
+ yield
26
+ ensure
27
+ self.stop
28
+ end
29
+ end
30
+
21
31
  def self.alias_stripe_method(new_name, method_object)
22
32
  Stripe.define_singleton_method(new_name) {|*args| method_object.call(*args) }
23
33
  end
@@ -38,6 +38,9 @@ module StripeMock
38
38
  @__list = [
39
39
  'account.updated',
40
40
  'account.application.deauthorized',
41
+ 'account.external_account.created',
42
+ 'account.external_account.updated',
43
+ 'account.external_account.deleted',
41
44
  'balance.available',
42
45
  'charge.succeeded',
43
46
  'charge.failed',
@@ -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] || 'usd'
6
7
  {
7
8
  id: id,
8
9
  email: "bob@example.com",
@@ -15,7 +16,7 @@ module StripeMock
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,
@@ -93,6 +103,7 @@ module StripeMock
93
103
 
94
104
  def self.mock_customer(sources, params)
95
105
  cus_id = params[:id] || "test_cus_default"
106
+ currency = params[:currency] || nil
96
107
  sources.each {|source| source[:customer] = cus_id}
97
108
  {
98
109
  email: 'stripe_mock@example.com',
@@ -104,7 +115,7 @@ module StripeMock
104
115
  delinquent: false,
105
116
  discount: nil,
106
117
  account_balance: 0,
107
- currency: nil,
118
+ currency: currency,
108
119
  sources: {
109
120
  object: "list",
110
121
  total_count: sources.size,
@@ -123,6 +134,7 @@ module StripeMock
123
134
 
124
135
  def self.mock_charge(params={})
125
136
  charge_id = params[:id] || "ch_1fD6uiR9FAA2zc"
137
+ currency = params[:currency] || 'usd'
126
138
  {
127
139
  id: charge_id,
128
140
  object: "charge",
@@ -131,7 +143,7 @@ module StripeMock
131
143
  paid: true,
132
144
  amount: 0,
133
145
  application_fee: nil,
134
- currency: "usd",
146
+ currency: currency,
135
147
  destination: nil,
136
148
  fraud_details: {},
137
149
  receipt_email: nil,
@@ -184,10 +196,11 @@ module StripeMock
184
196
  end
185
197
 
186
198
  def self.mock_refund(params={})
199
+ currency = params[:currency] || 'usd'
187
200
  {
188
201
  id: "re_4fWhgUh5si7InF",
189
202
  amount: 1,
190
- currency: "usd",
203
+ currency: currency,
191
204
  created: 1409165988,
192
205
  object: "refund",
193
206
  balance_transaction: "txn_4fWh2RKvgxcXqV",
@@ -228,18 +241,21 @@ module StripeMock
228
241
  address_country: nil,
229
242
  cvc_check: nil,
230
243
  address_line1_check: nil,
231
- address_zip_check: nil
244
+ address_zip_check: nil,
245
+ tokenization_method: nil
232
246
  }, params)
233
247
  end
234
248
 
235
249
  def self.mock_bank_account(params={})
250
+ currency = params[:currency] || 'usd'
236
251
  {
252
+ id: "test_ba_default",
237
253
  object: "bank_account",
238
254
  bank_name: "STRIPEMOCK TEST BANK",
239
255
  last4: "6789",
240
256
  routing_number: '110000000',
241
257
  country: "US",
242
- currency: "usd",
258
+ currency: currency,
243
259
  validated: false,
244
260
  status: 'new',
245
261
  account_holder_name: 'John Doe',
@@ -267,6 +283,7 @@ module StripeMock
267
283
  #FIXME nested overrides would be better than hardcoding plan_id
268
284
  def self.mock_subscription(params={})
269
285
  StripeMock::Util.rmerge({
286
+ :created => 1478204116,
270
287
  :current_period_start => 1308595038,
271
288
  :current_period_end => 1308681468,
272
289
  :status => "trialing",
@@ -294,6 +311,7 @@ module StripeMock
294
311
 
295
312
  def self.mock_invoice(lines, params={})
296
313
  in_id = params[:id] || "test_in_default"
314
+ currency = params[:currency] || 'usd'
297
315
  lines << Data.mock_line_item() if lines.empty?
298
316
  {
299
317
  id: 'in_test_invoice',
@@ -325,7 +343,7 @@ module StripeMock
325
343
  livemode: false,
326
344
  attempt_count: 0,
327
345
  amount_due: lines.map {|line| line[:amount]}.reduce(0, :+),
328
- currency: 'usd',
346
+ currency: currency,
329
347
  starting_balance: 0,
330
348
  ending_balance: nil,
331
349
  next_payment_attempt: 1349825350,
@@ -336,13 +354,14 @@ module StripeMock
336
354
  end
337
355
 
338
356
  def self.mock_line_item(params = {})
357
+ currency = params[:currency] || 'usd'
339
358
  {
340
359
  id: "ii_test",
341
360
  object: "line_item",
342
361
  type: "invoiceitem",
343
362
  livemode: false,
344
363
  amount: 1000,
345
- currency: "usd",
364
+ currency: currency,
346
365
  discountable: false,
347
366
  proration: false,
348
367
  period: {
@@ -358,6 +377,7 @@ module StripeMock
358
377
  end
359
378
 
360
379
  def self.mock_invoice_item(params = {})
380
+ currency = params[:currency] || 'usd'
361
381
  {
362
382
  id: "test_ii",
363
383
  object: "invoiceitem",
@@ -365,7 +385,7 @@ module StripeMock
365
385
  amount: 1099,
366
386
  livemode: false,
367
387
  proration: false,
368
- currency: "usd",
388
+ currency: currency,
369
389
  customer: "cus_test",
370
390
  description: "invoice item desc",
371
391
  metadata: {},
@@ -396,6 +416,7 @@ module StripeMock
396
416
 
397
417
  def self.mock_order(order_items, params)
398
418
  or_id = params[:id] || "test_or_default"
419
+ currency = params[:currency] || 'eur'
399
420
  order_items << Data.mock_order_item if order_items.empty?
400
421
  {
401
422
  id: or_id,
@@ -405,7 +426,7 @@ module StripeMock
405
426
  application_fee: nil,
406
427
  charge: nil,
407
428
  created: 1448272783,
408
- currency: "eur",
429
+ currency: currency,
409
430
  customer: nil,
410
431
  email: nil,
411
432
  items: order_items,
@@ -431,10 +452,11 @@ module StripeMock
431
452
  end
432
453
 
433
454
  def self.mock_order_item(params={})
455
+ currency = params[:currency] || 'eur'
434
456
  {
435
457
  object: "order_item",
436
458
  amount: 5000,
437
- currency: "eur",
459
+ currency: currency,
438
460
  description: "Anyitem",
439
461
  parent: "sku_parent",
440
462
  quantity: 1,
@@ -443,12 +465,13 @@ module StripeMock
443
465
  end
444
466
 
445
467
  def self.mock_plan(params={})
468
+ currency = params[:currency] || 'usd'
446
469
  {
447
470
  id: "2",
448
471
  object: "plan",
449
472
  amount: 2300,
450
473
  created: 1466698898,
451
- currency: "usd",
474
+ currency: currency,
452
475
  interval: "month",
453
476
  interval_count: 1,
454
477
  livemode: false,
@@ -543,6 +566,7 @@ module StripeMock
543
566
  end
544
567
 
545
568
  def self.mock_transfer(params={})
569
+ currency = params[:currency] || 'usd'
546
570
  id = params[:id] || 'tr_test_transfer'
547
571
  {
548
572
  :status => 'pending',
@@ -558,7 +582,7 @@ module StripeMock
558
582
  :fee_details => [],
559
583
  :id => id,
560
584
  :livemode => false,
561
- :currency => "usd",
585
+ :currency => currency,
562
586
  :object => "transfer",
563
587
  :date => 1304114826,
564
588
  :description => "Transfer description",
@@ -581,6 +605,7 @@ module StripeMock
581
605
  end
582
606
 
583
607
  def self.mock_dispute(params={})
608
+ currency = params[:currency] || 'usd'
584
609
  id = params[:id] || "dp_test_dispute"
585
610
  {
586
611
  :id => id,
@@ -589,7 +614,7 @@ module StripeMock
589
614
  :balance_transactions => [],
590
615
  :charge => "ch_15RsQR2eZvKYlo2CA8IfzCX0",
591
616
  :created => 1422915137,
592
- :currency => "usd",
617
+ :currency => currency,
593
618
  :evidence => self.mock_dispute_evidence,
594
619
  :evidence_details => self.mock_dispute_evidence_details,
595
620
  :is_charge_refundable => false,
@@ -705,6 +730,160 @@ module StripeMock
705
730
  list.to_h
706
731
  end
707
732
 
733
+ def self.mock_country_spec(country_code)
734
+ id = country_code || "US"
735
+ {
736
+ "id"=> "US",
737
+ "object"=> "country_spec",
738
+ "default_currency"=> "usd",
739
+ "supported_bank_account_currencies"=> {"usd"=>["US"]},
740
+ "supported_payment_currencies"=> [
741
+ "usd",
742
+ "aed",
743
+ "afn",
744
+ "all",
745
+ "amd",
746
+ "ang",
747
+ "aoa",
748
+ "ars",
749
+ "aud",
750
+ "awg",
751
+ "azn",
752
+ "bam",
753
+ "bbd",
754
+ "bdt",
755
+ "bgn",
756
+ "bif",
757
+ "bmd",
758
+ "bnd",
759
+ "bob",
760
+ "brl",
761
+ "bsd",
762
+ "bwp",
763
+ "bzd",
764
+ "cad",
765
+ "cdf",
766
+ "chf",
767
+ "clp",
768
+ "cny",
769
+ "cop",
770
+ "crc",
771
+ "cve",
772
+ "czk",
773
+ "djf",
774
+ "dkk",
775
+ "dop",
776
+ "dzd",
777
+ "egp",
778
+ "etb",
779
+ "eur",
780
+ "fjd",
781
+ "fkp",
782
+ "gbp",
783
+ "gel",
784
+ "gip",
785
+ "gmd",
786
+ "gnf",
787
+ "gtq",
788
+ "gyd",
789
+ "hkd",
790
+ "hnl",
791
+ "hrk",
792
+ "htg",
793
+ "huf",
794
+ "idr",
795
+ "ils",
796
+ "inr",
797
+ "isk",
798
+ "jmd",
799
+ "jpy",
800
+ "kes",
801
+ "kgs",
802
+ "khr",
803
+ "kmf",
804
+ "krw",
805
+ "kyd",
806
+ "kzt",
807
+ "lak",
808
+ "lbp",
809
+ "lkr",
810
+ "lrd",
811
+ "lsl",
812
+ "ltl",
813
+ "mad",
814
+ "mdl",
815
+ "mga",
816
+ "mkd",
817
+ "mnt",
818
+ "mop",
819
+ "mro",
820
+ "mur",
821
+ "mvr",
822
+ "mwk",
823
+ "mxn",
824
+ "myr",
825
+ "mzn",
826
+ "nad",
827
+ "ngn",
828
+ "nio",
829
+ "nok",
830
+ "npr",
831
+ "nzd",
832
+ "pab",
833
+ "pen",
834
+ "pgk",
835
+ "php",
836
+ "pkr",
837
+ "pln",
838
+ "pyg",
839
+ "qar",
840
+ "ron",
841
+ "rsd",
842
+ "rub",
843
+ "rwf",
844
+ "sar",
845
+ "sbd",
846
+ "scr",
847
+ "sek",
848
+ "sgd",
849
+ "shp",
850
+ "sll",
851
+ "sos",
852
+ "srd",
853
+ "std",
854
+ "svc",
855
+ "szl",
856
+ "thb",
857
+ "tjs",
858
+ "top",
859
+ "try",
860
+ "ttd",
861
+ "twd",
862
+ "tzs",
863
+ "uah",
864
+ "ugx",
865
+ "uyu",
866
+ "uzs",
867
+ "vnd",
868
+ "vuv",
869
+ "wst",
870
+ "xaf",
871
+ "xcd",
872
+ "xof",
873
+ "xpf",
874
+ "yer",
875
+ "zar",
876
+ "zmw"
877
+ ],
878
+ "supported_payment_methods"=> [
879
+ "alipay",
880
+ "card",
881
+ "stripe"
882
+ ],
883
+ "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"]}}
884
+ }
885
+ end
886
+
708
887
  def self.mock_balance_transactions(ids=[])
709
888
  bts = {}
710
889
  ids.each do |id|
@@ -714,6 +893,7 @@ module StripeMock
714
893
  end
715
894
 
716
895
  def self.mock_balance_transaction(params = {})
896
+ currency = params[:currency] || 'usd'
717
897
  bt_id = params[:id] || 'test_txn_default'
718
898
  source = params[:source] || 'ch_test_charge'
719
899
  {
@@ -722,14 +902,14 @@ module StripeMock
722
902
  amount: 10000,
723
903
  available_on: 1462406400,
724
904
  created: 1461880226,
725
- currency: "usd",
905
+ currency: currency,
726
906
  description: nil,
727
907
  fee: 320,
728
908
  fee_details: [
729
909
  {
730
910
  amount: 320,
731
911
  application: nil,
732
- currency: "usd",
912
+ currency: currency,
733
913
  description: "Stripe processing fees",
734
914
  type: "stripe_fee"
735
915
  }
@@ -747,6 +927,5 @@ module StripeMock
747
927
  type: "charge"
748
928
  }.merge(params)
749
929
  end
750
-
751
930
  end
752
931
  end