stripe-ruby-mock 2.3.0 → 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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +5 -0
- data/README.md +1 -1
- data/lib/stripe_mock/api/errors.rb +2 -1
- data/lib/stripe_mock/api/instance.rb +10 -0
- data/lib/stripe_mock/api/webhooks.rb +3 -0
- data/lib/stripe_mock/data.rb +203 -21
- data/lib/stripe_mock/instance.rb +14 -3
- data/lib/stripe_mock/request_handlers/accounts.rb +7 -0
- data/lib/stripe_mock/request_handlers/charges.rb +29 -21
- data/lib/stripe_mock/request_handlers/country_spec.rb +22 -0
- data/lib/stripe_mock/request_handlers/customers.rb +3 -3
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +5 -2
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +2 -1
- data/lib/stripe_mock/request_handlers/recipients.rb +12 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +88 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +48 -23
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +5 -0
- data/lib/stripe_mock/test_strategies/base.rb +7 -4
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/account.external_account.created.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.deleted.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.updated.json +27 -0
- data/lib/stripe_mock.rb +2 -0
- data/spec/api/instance_spec.rb +30 -0
- data/spec/list_spec.rb +11 -7
- data/spec/server_spec.rb +1 -1
- data/spec/shared_stripe_examples/account_examples.rb +11 -0
- data/spec/shared_stripe_examples/card_examples.rb +13 -2
- data/spec/shared_stripe_examples/card_token_examples.rb +1 -0
- data/spec/shared_stripe_examples/charge_examples.rb +90 -14
- data/spec/shared_stripe_examples/country_specs_examples.rb +18 -0
- data/spec/shared_stripe_examples/customer_examples.rb +38 -0
- data/spec/shared_stripe_examples/error_mock_examples.rb +12 -2
- data/spec/shared_stripe_examples/plan_examples.rb +19 -0
- data/spec/shared_stripe_examples/recipient_examples.rb +7 -1
- data/spec/shared_stripe_examples/refund_examples.rb +447 -84
- data/spec/shared_stripe_examples/subscription_examples.rb +28 -0
- data/spec/support/stripe_examples.rb +1 -0
- data/stripe-ruby-mock.gemspec +3 -3
- metadata +24 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dc4a01998c2f9e1cd85aee1281cf75d5b4aa436
|
4
|
+
data.tar.gz: 045708a8af619fc7b299055f0822eed79f8cae1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 918999885f3cf5e32133f85b535e76ecbe7c482b106b4fe70e9a8de03fcd95132bfd4d43496bc397492da84bfb5eded5c46807e70c2562ee38923e202bf6dd89
|
7
|
+
data.tar.gz: b9ab01a438f10f7148470641a0b0fddcd32b0fedfc28969a8f52020d483ed64e045e384f1acda6ec422680c54f34c36ace6dcb89b2a01949053e96269e9953a6
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -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',
|
data/lib/stripe_mock/data.rb
CHANGED
@@ -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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
459
|
+
currency: currency,
|
438
460
|
description: "Anyitem",
|
439
461
|
parent: "sku_parent",
|
440
462
|
quantity: 1,
|
@@ -443,15 +465,19 @@ module StripeMock
|
|
443
465
|
end
|
444
466
|
|
445
467
|
def self.mock_plan(params={})
|
468
|
+
currency = params[:currency] || 'usd'
|
446
469
|
{
|
447
|
-
interval: "month",
|
448
|
-
name: "The Basic Plan",
|
449
|
-
amount: 2300,
|
450
|
-
currency: "usd",
|
451
470
|
id: "2",
|
452
471
|
object: "plan",
|
453
|
-
|
472
|
+
amount: 2300,
|
473
|
+
created: 1466698898,
|
474
|
+
currency: currency,
|
475
|
+
interval: "month",
|
454
476
|
interval_count: 1,
|
477
|
+
livemode: false,
|
478
|
+
metadata: {},
|
479
|
+
name: "The Basic Plan",
|
480
|
+
statement_descriptor: nil,
|
455
481
|
trial_period_days: nil
|
456
482
|
}.merge(params)
|
457
483
|
end
|
@@ -540,6 +566,7 @@ module StripeMock
|
|
540
566
|
end
|
541
567
|
|
542
568
|
def self.mock_transfer(params={})
|
569
|
+
currency = params[:currency] || 'usd'
|
543
570
|
id = params[:id] || 'tr_test_transfer'
|
544
571
|
{
|
545
572
|
:status => 'pending',
|
@@ -555,7 +582,7 @@ module StripeMock
|
|
555
582
|
:fee_details => [],
|
556
583
|
:id => id,
|
557
584
|
:livemode => false,
|
558
|
-
:currency =>
|
585
|
+
:currency => currency,
|
559
586
|
:object => "transfer",
|
560
587
|
:date => 1304114826,
|
561
588
|
:description => "Transfer description",
|
@@ -578,6 +605,7 @@ module StripeMock
|
|
578
605
|
end
|
579
606
|
|
580
607
|
def self.mock_dispute(params={})
|
608
|
+
currency = params[:currency] || 'usd'
|
581
609
|
id = params[:id] || "dp_test_dispute"
|
582
610
|
{
|
583
611
|
:id => id,
|
@@ -586,7 +614,7 @@ module StripeMock
|
|
586
614
|
:balance_transactions => [],
|
587
615
|
:charge => "ch_15RsQR2eZvKYlo2CA8IfzCX0",
|
588
616
|
:created => 1422915137,
|
589
|
-
:currency =>
|
617
|
+
:currency => currency,
|
590
618
|
:evidence => self.mock_dispute_evidence,
|
591
619
|
:evidence_details => self.mock_dispute_evidence_details,
|
592
620
|
:is_charge_refundable => false,
|
@@ -702,6 +730,160 @@ module StripeMock
|
|
702
730
|
list.to_h
|
703
731
|
end
|
704
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
|
+
|
705
887
|
def self.mock_balance_transactions(ids=[])
|
706
888
|
bts = {}
|
707
889
|
ids.each do |id|
|
@@ -711,6 +893,7 @@ module StripeMock
|
|
711
893
|
end
|
712
894
|
|
713
895
|
def self.mock_balance_transaction(params = {})
|
896
|
+
currency = params[:currency] || 'usd'
|
714
897
|
bt_id = params[:id] || 'test_txn_default'
|
715
898
|
source = params[:source] || 'ch_test_charge'
|
716
899
|
{
|
@@ -719,14 +902,14 @@ module StripeMock
|
|
719
902
|
amount: 10000,
|
720
903
|
available_on: 1462406400,
|
721
904
|
created: 1461880226,
|
722
|
-
currency:
|
905
|
+
currency: currency,
|
723
906
|
description: nil,
|
724
907
|
fee: 320,
|
725
908
|
fee_details: [
|
726
909
|
{
|
727
910
|
amount: 320,
|
728
911
|
application: nil,
|
729
|
-
currency:
|
912
|
+
currency: currency,
|
730
913
|
description: "Stripe processing fees",
|
731
914
|
type: "stripe_fee"
|
732
915
|
}
|
@@ -744,6 +927,5 @@ module StripeMock
|
|
744
927
|
type: "charge"
|
745
928
|
}.merge(params)
|
746
929
|
end
|
747
|
-
|
748
930
|
end
|
749
931
|
end
|
data/lib/stripe_mock/instance.rb
CHANGED
@@ -34,14 +34,16 @@ module StripeMock
|
|
34
34
|
include StripeMock::RequestHandlers::InvoiceItems
|
35
35
|
include StripeMock::RequestHandlers::Orders
|
36
36
|
include StripeMock::RequestHandlers::Plans
|
37
|
+
include StripeMock::RequestHandlers::Refunds
|
37
38
|
include StripeMock::RequestHandlers::Recipients
|
38
39
|
include StripeMock::RequestHandlers::Transfers
|
39
40
|
include StripeMock::RequestHandlers::Tokens
|
41
|
+
include StripeMock::RequestHandlers::CountrySpec
|
40
42
|
|
41
43
|
|
42
44
|
attr_reader :accounts, :balance_transactions, :bank_tokens, :charges, :coupons, :customers,
|
43
45
|
:disputes, :events, :invoices, :invoice_items, :orders, :plans, :recipients,
|
44
|
-
:transfers, :subscriptions
|
46
|
+
:refunds, :transfers, :subscriptions, :country_spec
|
45
47
|
|
46
48
|
attr_accessor :error_queue, :debug
|
47
49
|
|
@@ -60,8 +62,10 @@ module StripeMock
|
|
60
62
|
@orders = {}
|
61
63
|
@plans = {}
|
62
64
|
@recipients = {}
|
65
|
+
@refunds = {}
|
63
66
|
@transfers = {}
|
64
67
|
@subscriptions = {}
|
68
|
+
@country_spec = {}
|
65
69
|
|
66
70
|
@debug = false
|
67
71
|
@error_queue = ErrorQueue.new
|
@@ -124,9 +128,16 @@ module StripeMock
|
|
124
128
|
"#{StripeMock.global_id_prefix}#{prefix}_#{@id_counter += 1}"
|
125
129
|
end
|
126
130
|
|
127
|
-
def new_balance_transaction(prefix)
|
131
|
+
def new_balance_transaction(prefix, params = {})
|
128
132
|
# balance transaction ids must be strings
|
129
|
-
"#{StripeMock.global_id_prefix}#{prefix}_#{@balance_transaction_counter += 1}"
|
133
|
+
id = "#{StripeMock.global_id_prefix}#{prefix}_#{@balance_transaction_counter += 1}"
|
134
|
+
amount = params[:amount]
|
135
|
+
unless amount.nil?
|
136
|
+
# Fee calculation
|
137
|
+
params[:fee] ||= (30 + (amount.abs * 0.029).ceil) * (amount > 0 ? 1 : -1)
|
138
|
+
end
|
139
|
+
@balance_transactions[id] = Data.mock_balance_transaction(params.merge(id: id))
|
140
|
+
id
|
130
141
|
end
|
131
142
|
|
132
143
|
def symbolize_names(hash)
|
@@ -8,6 +8,7 @@ module StripeMock
|
|
8
8
|
klass.add_handler 'get /v1/accounts/(.*)', :get_account
|
9
9
|
klass.add_handler 'post /v1/accounts/(.*)', :update_account
|
10
10
|
klass.add_handler 'get /v1/accounts', :list_accounts
|
11
|
+
klass.add_handler 'post /oauth/deauthorize',:deauthorize
|
11
12
|
end
|
12
13
|
|
13
14
|
def new_account(route, method_url, params, headers)
|
@@ -34,6 +35,12 @@ module StripeMock
|
|
34
35
|
Data.mock_list_object(accounts.values, params)
|
35
36
|
end
|
36
37
|
|
38
|
+
def deauthorize(route, method_url, params, headers)
|
39
|
+
init_account
|
40
|
+
route =~ method_url
|
41
|
+
Stripe::StripeObject.construct_from(:stripe_user_id => params[:stripe_user_id])
|
42
|
+
end
|
43
|
+
|
37
44
|
private
|
38
45
|
|
39
46
|
def init_account
|
@@ -8,11 +8,16 @@ module StripeMock
|
|
8
8
|
klass.add_handler 'get /v1/charges/(.*)', :get_charge
|
9
9
|
klass.add_handler 'post /v1/charges/(.*)/capture', :capture_charge
|
10
10
|
klass.add_handler 'post /v1/charges/(.*)/refund', :refund_charge
|
11
|
-
klass.add_handler 'post /v1/charges/(.*)/refunds', :
|
11
|
+
klass.add_handler 'post /v1/charges/(.*)/refunds', :refund_charge
|
12
12
|
klass.add_handler 'post /v1/charges/(.*)', :update_charge
|
13
13
|
end
|
14
14
|
|
15
15
|
def new_charge(route, method_url, params, headers)
|
16
|
+
if params[:idempotency_key] && charges.any?
|
17
|
+
original_charge = charges.values.find { |c| c[:idempotency_key] == params[:idempotency_key]}
|
18
|
+
return charges[original_charge[:id]] if original_charge
|
19
|
+
end
|
20
|
+
|
16
21
|
id = new_id('ch')
|
17
22
|
|
18
23
|
if params[:source]
|
@@ -23,7 +28,7 @@ module StripeMock
|
|
23
28
|
if params[:customer]
|
24
29
|
params[:source] = get_card(customers[params[:customer]], params[:source])
|
25
30
|
else
|
26
|
-
params[:source] =
|
31
|
+
params[:source] = get_card_or_bank_by_token(params[:source])
|
27
32
|
end
|
28
33
|
elsif params[:source][:id]
|
29
34
|
raise Stripe::InvalidRequestError.new("Invalid token id: #{params[:source]}", 'card', 400)
|
@@ -36,8 +41,20 @@ module StripeMock
|
|
36
41
|
end
|
37
42
|
|
38
43
|
ensure_required_params(params)
|
44
|
+
bal_trans_params = { amount: params[:amount], source: params[:source] }
|
45
|
+
|
46
|
+
balance_transaction_id = new_balance_transaction('txn', bal_trans_params)
|
47
|
+
|
48
|
+
charges[id] = Data.mock_charge(
|
49
|
+
params.merge :id => id,
|
50
|
+
:balance_transaction => balance_transaction_id)
|
51
|
+
|
52
|
+
if params[:expand] == ['balance_transaction']
|
53
|
+
charges[id][:balance_transaction] =
|
54
|
+
balance_transactions[balance_transaction_id]
|
55
|
+
end
|
39
56
|
|
40
|
-
charges[id]
|
57
|
+
charges[id]
|
41
58
|
end
|
42
59
|
|
43
60
|
def update_charge(route, method_url, params, headers)
|
@@ -69,7 +86,8 @@ module StripeMock
|
|
69
86
|
|
70
87
|
def get_charge(route, method_url, params, headers)
|
71
88
|
route =~ method_url
|
72
|
-
|
89
|
+
charge_id = $1 || params[:charge]
|
90
|
+
assert_existence :charge, charge_id, charges[charge_id]
|
73
91
|
end
|
74
92
|
|
75
93
|
def capture_charge(route, method_url, params, headers)
|
@@ -96,24 +114,12 @@ module StripeMock
|
|
96
114
|
def refund_charge(route, method_url, params, headers)
|
97
115
|
charge = get_charge(route, method_url, params, headers)
|
98
116
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
charge
|
105
|
-
end
|
106
|
-
|
107
|
-
def create_refund(route, method_url, params, headers)
|
108
|
-
charge = get_charge(route, method_url, params, headers)
|
109
|
-
|
110
|
-
refund = Data.mock_refund params.merge(
|
111
|
-
:balance_transaction => new_balance_transaction('txn'),
|
112
|
-
:id => new_id('re'),
|
113
|
-
:charge => charge[:id]
|
117
|
+
new_refund(
|
118
|
+
route,
|
119
|
+
method_url,
|
120
|
+
params.merge(:charge => charge[:id]),
|
121
|
+
headers
|
114
122
|
)
|
115
|
-
add_refund_to_charge(refund, charge)
|
116
|
-
refund
|
117
123
|
end
|
118
124
|
|
119
125
|
private
|
@@ -127,6 +133,8 @@ module StripeMock
|
|
127
133
|
raise Stripe::InvalidRequestError.new("Invalid integer: #{params[:amount]}", 'amount', 400)
|
128
134
|
elsif non_positive_charge_amount?(params)
|
129
135
|
raise Stripe::InvalidRequestError.new('Invalid positive integer', 'amount', 400)
|
136
|
+
elsif params[:source].nil? && params[:customer].nil?
|
137
|
+
raise Stripe::InvalidRequestError.new('Must provide source or customer.', nil)
|
130
138
|
end
|
131
139
|
end
|
132
140
|
|