stripe-ruby-mock 2.2.3 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/stripe_mock/data.rb +21 -1
- data/lib/stripe_mock/request_handlers/customers.rb +3 -3
- data/lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb +14 -0
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +6 -1
- data/lib/stripe_mock/request_handlers/sources.rb +9 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +1 -1
- data/lib/stripe_mock/request_handlers/tokens.rb +3 -3
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock.rb +1 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +18 -0
- data/stripe-ruby-mock.gemspec +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 907a296926746f9f85a5971db9272ffe4c7cd8e7
|
4
|
+
data.tar.gz: 41deab127c933031f4e08fe4b54d0e62b5268cdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55104b30501886b7a11efbef32fb28eb1c5eb2c2d130bd9370e532f2ef417ee9a4338e0a08d1993f6bc62fe1a659ac7596aa51ff7a851c225b1054d228cd1b61
|
7
|
+
data.tar.gz: 430679dd30c713bd45a8ae8831c855862848706c01f46c871e66a2ae3e906a85944f11179dc596d6d729705287193ecb9146cc960636f4bf69434faf06794914
|
data/README.md
CHANGED
data/lib/stripe_mock/data.rb
CHANGED
@@ -235,9 +235,13 @@ module StripeMock
|
|
235
235
|
object: "bank_account",
|
236
236
|
bank_name: "STRIPEMOCK TEST BANK",
|
237
237
|
last4: "6789",
|
238
|
+
routing_number: '110000000',
|
238
239
|
country: "US",
|
239
240
|
currency: "usd",
|
240
241
|
validated: false,
|
242
|
+
status: 'new',
|
243
|
+
account_holder_name: 'John Doe',
|
244
|
+
account_holder_type: 'individual',
|
241
245
|
fingerprint: "aBcFinGerPrINt123"
|
242
246
|
}.merge(params)
|
243
247
|
end
|
@@ -487,7 +491,7 @@ module StripeMock
|
|
487
491
|
}
|
488
492
|
end
|
489
493
|
|
490
|
-
def self.
|
494
|
+
def self.mock_card_token(params={})
|
491
495
|
{
|
492
496
|
:id => 'tok_default',
|
493
497
|
:livemode => false,
|
@@ -517,6 +521,22 @@ module StripeMock
|
|
517
521
|
}.merge(params)
|
518
522
|
end
|
519
523
|
|
524
|
+
def self.mock_bank_account_token(params={})
|
525
|
+
{
|
526
|
+
:id => 'tok_default',
|
527
|
+
:livemode => false,
|
528
|
+
:used => false,
|
529
|
+
:object => 'token',
|
530
|
+
:type => 'bank_account',
|
531
|
+
:bank_account => {
|
532
|
+
:id => 'bank_account_default',
|
533
|
+
:object => 'bank_account',
|
534
|
+
:last4 => '2222',
|
535
|
+
:fingerprint => 'JRRLXGh38NiYygM7',
|
536
|
+
}
|
537
|
+
}.merge(params)
|
538
|
+
end
|
539
|
+
|
520
540
|
def self.mock_transfer(params={})
|
521
541
|
id = params[:id] || 'tr_test_transfer'
|
522
542
|
{
|
@@ -22,7 +22,7 @@ module StripeMock
|
|
22
22
|
end
|
23
23
|
card_from_params(params[:source])
|
24
24
|
else
|
25
|
-
|
25
|
+
get_card_or_bank_by_token(params.delete(:source))
|
26
26
|
end
|
27
27
|
sources << new_card
|
28
28
|
params[:default_source] = sources.first[:id]
|
@@ -71,9 +71,9 @@ module StripeMock
|
|
71
71
|
end
|
72
72
|
cus.merge!(params)
|
73
73
|
|
74
|
-
if params[:source]
|
74
|
+
if params[:source]
|
75
75
|
if params[:source].is_a?(String)
|
76
|
-
new_card =
|
76
|
+
new_card = get_card_or_bank_by_token(params.delete(:source))
|
77
77
|
elsif params[:source].is_a?(Hash)
|
78
78
|
unless params[:source][:object] && params[:source][:number] && params[:source][:exp_month] && params[:source][:exp_year]
|
79
79
|
raise Stripe::InvalidRequestError.new('You must supply a valid card', nil, 400)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
def verify_bank_account(object, bank_account_id, class_name='Customer')
|
6
|
+
bank_accounts = object[:bank_accounts] || object[:sources]
|
7
|
+
bank_account = bank_accounts[:data].find{|acc| acc[:id] == bank_account_id }
|
8
|
+
return if bank_account.nil?
|
9
|
+
bank_account['status'] = 'verified'
|
10
|
+
bank_account
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -4,6 +4,7 @@ module StripeMock
|
|
4
4
|
|
5
5
|
def generate_bank_token(bank_params)
|
6
6
|
token = new_id 'btok'
|
7
|
+
bank_params[:id] = new_id 'bank_account'
|
7
8
|
@bank_tokens[token] = Data.mock_bank_account bank_params
|
8
9
|
token
|
9
10
|
end
|
@@ -33,6 +34,10 @@ module StripeMock
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
37
|
+
def get_card_or_bank_by_token(token)
|
38
|
+
@card_tokens[token] || @bank_tokens[token] || raise(Stripe::InvalidRequestError.new("Invalid token id: #{token}", 'tok', 404))
|
39
|
+
end
|
40
|
+
|
36
41
|
end
|
37
42
|
end
|
38
|
-
end
|
43
|
+
end
|
@@ -5,6 +5,7 @@ module StripeMock
|
|
5
5
|
def Sources.included(klass)
|
6
6
|
klass.add_handler 'get /v1/customers/(.*)/sources', :retrieve_sources
|
7
7
|
klass.add_handler 'post /v1/customers/(.*)/sources', :create_source
|
8
|
+
klass.add_handler 'post /v1/customers/(.*)/sources/(.*)/verify', :verify_source
|
8
9
|
klass.add_handler 'get /v1/customers/(.*)/sources/(.*)', :retrieve_source
|
9
10
|
klass.add_handler 'delete /v1/customers/(.*)/sources/(.*)', :delete_source
|
10
11
|
klass.add_handler 'post /v1/customers/(.*)/sources/(.*)', :update_source
|
@@ -41,6 +42,14 @@ module StripeMock
|
|
41
42
|
card
|
42
43
|
end
|
43
44
|
|
45
|
+
def verify_source(route, method_url, params, headers)
|
46
|
+
route =~ method_url
|
47
|
+
customer = assert_existence :customer, $1, customers[$1]
|
48
|
+
|
49
|
+
bank_account = assert_existence :bank_account, $2, verify_bank_account(customer, $2)
|
50
|
+
bank_account
|
51
|
+
end
|
52
|
+
|
44
53
|
end
|
45
54
|
end
|
46
55
|
end
|
@@ -39,7 +39,7 @@ module StripeMock
|
|
39
39
|
token_id = generate_card_token(customer_card)
|
40
40
|
card = @card_tokens[token_id]
|
41
41
|
|
42
|
-
Data.
|
42
|
+
Data.mock_card_token(params.merge :id => token_id, :card => card)
|
43
43
|
end
|
44
44
|
|
45
45
|
def get_token(route, method_url, params, headers)
|
@@ -49,9 +49,9 @@ module StripeMock
|
|
49
49
|
assert_existence :token, $1, bank_or_card
|
50
50
|
|
51
51
|
if bank_or_card[:object] == 'card'
|
52
|
-
Data.
|
52
|
+
Data.mock_card_token(:id => $1, :card => bank_or_card)
|
53
53
|
elsif bank_or_card[:object] == 'bank_account'
|
54
|
-
Data.
|
54
|
+
Data.mock_bank_account_token(:id => $1, :bank_account => bank_or_card)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
data/lib/stripe_mock/version.rb
CHANGED
data/lib/stripe_mock.rb
CHANGED
@@ -34,6 +34,7 @@ require 'stripe_mock/api/live'
|
|
34
34
|
require 'stripe_mock/api/test_helpers'
|
35
35
|
require 'stripe_mock/api/webhooks'
|
36
36
|
|
37
|
+
require 'stripe_mock/request_handlers/helpers/bank_account_helpers.rb'
|
37
38
|
require 'stripe_mock/request_handlers/helpers/card_helpers.rb'
|
38
39
|
require 'stripe_mock/request_handlers/helpers/charge_helpers.rb'
|
39
40
|
require 'stripe_mock/request_handlers/helpers/coupon_helpers.rb'
|
@@ -35,6 +35,23 @@ shared_examples 'Customer Subscriptions' do
|
|
35
35
|
expect(customer.subscriptions.data.first.metadata.example).to eq( "yes" )
|
36
36
|
end
|
37
37
|
|
38
|
+
it "adds a new subscription to customer (string/symbol agnostic)" do
|
39
|
+
customer = Stripe::Customer.create(source: gen_card_tk)
|
40
|
+
expect(customer.subscriptions.count).to eq(0)
|
41
|
+
|
42
|
+
plan = stripe_helper.create_plan(id: :silver, name: 'Silver Plan', amount: 4999, currency: 'usd')
|
43
|
+
sub = customer.subscriptions.create({ :plan => 'silver' })
|
44
|
+
customer = Stripe::Customer.retrieve(customer.id)
|
45
|
+
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
46
|
+
expect(customer.subscriptions.count).to eq(1)
|
47
|
+
|
48
|
+
plan = stripe_helper.create_plan(id: 'gold', name: 'Gold Plan', amount: 14999, currency: 'usd')
|
49
|
+
sub = customer.subscriptions.create({ :plan => :gold })
|
50
|
+
customer = Stripe::Customer.retrieve(customer.id)
|
51
|
+
expect(sub.plan.to_hash).to eq(plan.to_hash)
|
52
|
+
expect(customer.subscriptions.count).to eq(2)
|
53
|
+
end
|
54
|
+
|
38
55
|
it 'creates a charge for the customer', live: true do
|
39
56
|
stripe_helper.create_plan(id: 'silver', name: 'Silver Plan', amount: 4999)
|
40
57
|
|
@@ -267,6 +284,7 @@ shared_examples 'Customer Subscriptions' do
|
|
267
284
|
expect(e.message).to eq("Invalid timestamp: can be no more than five years in the future")
|
268
285
|
}
|
269
286
|
end
|
287
|
+
|
270
288
|
end
|
271
289
|
|
272
290
|
context "updating a subscription" do
|
data/stripe-ruby-mock.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ['lib']
|
19
19
|
|
20
|
-
gem.add_dependency 'stripe', '>= 1.31.0'
|
20
|
+
gem.add_dependency 'stripe', ['>= 1.31.0', '< 1.42']
|
21
21
|
gem.add_dependency 'jimson-temp'
|
22
22
|
gem.add_dependency 'dante', '>= 0.2.0'
|
23
23
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe-ruby-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stripe
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.31.0
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.42'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 1.31.0
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.42'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: jimson-temp
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +146,7 @@ files:
|
|
140
146
|
- lib/stripe_mock/request_handlers/customers.rb
|
141
147
|
- lib/stripe_mock/request_handlers/disputes.rb
|
142
148
|
- lib/stripe_mock/request_handlers/events.rb
|
149
|
+
- lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb
|
143
150
|
- lib/stripe_mock/request_handlers/helpers/card_helpers.rb
|
144
151
|
- lib/stripe_mock/request_handlers/helpers/charge_helpers.rb
|
145
152
|
- lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb
|