stripe-ruby-mock 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +5 -0
- data/README.md +1 -1
- data/lib/stripe_mock/data.rb +8 -5
- data/lib/stripe_mock/request_handlers/charges.rb +5 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +44 -20
- data/lib/stripe_mock/version.rb +1 -1
- data/spec/shared_stripe_examples/charge_examples.rb +27 -0
- data/spec/shared_stripe_examples/plan_examples.rb +8 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +13 -0
- data/stripe-ruby-mock.gemspec +3 -3
- metadata +14 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7c2b8715ff3b25f019be501ef40f6d246448d39
|
4
|
+
data.tar.gz: bbb68394eeb61334c49ce3f86d37ea44b513e516
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14dc5c186dc169b310d38e5639ee801863d3f856d36c7f9522c62608cd8d8667c8a69b7ddc6c80023537cb6b65866904fa2f5660c5f59e6c8290f5f3d918d4d3
|
7
|
+
data.tar.gz: 1c8f4d5fcb31c4e8f1716e379b2aed29538a59d43ec2bc96e52751bae4c21a14e5265a6003fca7b12768c61061ad200d122a930461b04b1863d6c8c61cab2d30
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/lib/stripe_mock/data.rb
CHANGED
@@ -444,14 +444,17 @@ module StripeMock
|
|
444
444
|
|
445
445
|
def self.mock_plan(params={})
|
446
446
|
{
|
447
|
-
interval: "month",
|
448
|
-
name: "The Basic Plan",
|
449
|
-
amount: 2300,
|
450
|
-
currency: "usd",
|
451
447
|
id: "2",
|
452
448
|
object: "plan",
|
453
|
-
|
449
|
+
amount: 2300,
|
450
|
+
created: 1466698898,
|
451
|
+
currency: "usd",
|
452
|
+
interval: "month",
|
454
453
|
interval_count: 1,
|
454
|
+
livemode: false,
|
455
|
+
metadata: {},
|
456
|
+
name: "The Basic Plan",
|
457
|
+
statement_descriptor: nil,
|
455
458
|
trial_period_days: nil
|
456
459
|
}.merge(params)
|
457
460
|
end
|
@@ -13,6 +13,11 @@ module StripeMock
|
|
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]
|
@@ -12,12 +12,14 @@ module StripeMock
|
|
12
12
|
klass.add_handler 'post /v1/customers/(.*)/subscriptions', :create_customer_subscription
|
13
13
|
klass.add_handler 'get /v1/customers/(.*)/subscriptions/(.*)', :retrieve_customer_subscription
|
14
14
|
klass.add_handler 'get /v1/customers/(.*)/subscriptions', :retrieve_customer_subscriptions
|
15
|
+
klass.add_handler 'post /v1/customers/(.*)subscriptions/(.*)', :update_subscription
|
16
|
+
klass.add_handler 'delete /v1/customers/(.*)/subscriptions/(.*)', :cancel_subscription
|
15
17
|
end
|
16
18
|
|
17
19
|
def retrieve_customer_subscription(route, method_url, params, headers)
|
18
20
|
route =~ method_url
|
19
21
|
|
20
|
-
customer = :customer, $1, customers[$1]
|
22
|
+
customer = assert_existence :customer, $1, customers[$1]
|
21
23
|
subscription = get_customer_subscription(customer, $2)
|
22
24
|
|
23
25
|
assert_existence :subscription, $2, subscription
|
@@ -53,14 +55,16 @@ module StripeMock
|
|
53
55
|
if params[:coupon]
|
54
56
|
coupon_id = params[:coupon]
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
# FIXME assert_existence returns 404 error code but Stripe returns 400
|
58
|
+
# assert_existence returns 404 error code but Stripe returns 400
|
59
59
|
# coupon = assert_existence :coupon, coupon_id, coupons[coupon_id]
|
60
60
|
|
61
|
-
coupon =
|
61
|
+
coupon = coupons[coupon_id]
|
62
62
|
|
63
|
-
|
63
|
+
if coupon
|
64
|
+
subscription[:discount] = Stripe::Util.convert_to_stripe_object({ coupon: coupon }, {})
|
65
|
+
else
|
66
|
+
raise Stripe::InvalidRequestError.new("No such coupon: #{coupon_id}", 'coupon', 400)
|
67
|
+
end
|
64
68
|
end
|
65
69
|
|
66
70
|
subscriptions[subscription[:id]] = subscription
|
@@ -93,14 +97,16 @@ module StripeMock
|
|
93
97
|
if params[:coupon]
|
94
98
|
coupon_id = params[:coupon]
|
95
99
|
|
96
|
-
|
97
|
-
|
98
|
-
# FIXME assert_existence returns 404 error code but Stripe returns 400
|
100
|
+
# assert_existence returns 404 error code but Stripe returns 400
|
99
101
|
# coupon = assert_existence :coupon, coupon_id, coupons[coupon_id]
|
100
102
|
|
101
|
-
coupon =
|
103
|
+
coupon = coupons[coupon_id]
|
102
104
|
|
103
|
-
|
105
|
+
if coupon
|
106
|
+
subscription[:discount] = Stripe::Util.convert_to_stripe_object({ coupon: coupon }, {})
|
107
|
+
else
|
108
|
+
raise Stripe::InvalidRequestError.new("No such coupon: #{coupon_id}", 'coupon', 400)
|
109
|
+
end
|
104
110
|
end
|
105
111
|
|
106
112
|
subscriptions[subscription[:id]] = subscription
|
@@ -125,7 +131,10 @@ module StripeMock
|
|
125
131
|
|
126
132
|
def update_subscription(route, method_url, params, headers)
|
127
133
|
route =~ method_url
|
128
|
-
|
134
|
+
|
135
|
+
subscription_id = $2 ? $2 : $1
|
136
|
+
subscription = assert_existence :subscription, subscription_id, subscriptions[subscription_id]
|
137
|
+
verify_active_status(subscription)
|
129
138
|
|
130
139
|
customer_id = subscription[:customer]
|
131
140
|
customer = assert_existence :customer, customer_id, customers[customer_id]
|
@@ -137,19 +146,24 @@ module StripeMock
|
|
137
146
|
end
|
138
147
|
|
139
148
|
# expand the plan for addition to the customer object
|
140
|
-
plan_name =
|
141
|
-
|
149
|
+
plan_name =
|
150
|
+
params[:plan].is_a?(String) ? params[:plan] : subscription[:plan][:id]
|
151
|
+
|
142
152
|
plan = plans[plan_name]
|
143
153
|
|
144
154
|
if params[:coupon]
|
145
155
|
coupon_id = params[:coupon]
|
146
|
-
raise Stripe::InvalidRequestError.new("No such coupon: #{coupon_id}", 'coupon', 400) unless coupons[coupon_id]
|
147
156
|
|
148
|
-
#
|
157
|
+
# assert_existence returns 404 error code but Stripe returns 400
|
149
158
|
# coupon = assert_existence :coupon, coupon_id, coupons[coupon_id]
|
150
159
|
|
151
|
-
coupon =
|
152
|
-
|
160
|
+
coupon = coupons[coupon_id]
|
161
|
+
|
162
|
+
if coupon
|
163
|
+
subscription[:discount] = Stripe::Util.convert_to_stripe_object({ coupon: coupon }, {})
|
164
|
+
else
|
165
|
+
raise Stripe::InvalidRequestError.new("No such coupon: #{coupon_id}", 'coupon', 400)
|
166
|
+
end
|
153
167
|
end
|
154
168
|
|
155
169
|
assert_existence :plan, plan_name, plan
|
@@ -161,6 +175,7 @@ module StripeMock
|
|
161
175
|
subscription[:canceled_at] = nil
|
162
176
|
end
|
163
177
|
|
178
|
+
params[:current_period_start] = subscription[:current_period_start]
|
164
179
|
subscription.merge!(custom_subscription_params(plan, customer, params))
|
165
180
|
|
166
181
|
# delete the old subscription, replace with the new subscription
|
@@ -173,7 +188,8 @@ module StripeMock
|
|
173
188
|
def cancel_subscription(route, method_url, params, headers)
|
174
189
|
route =~ method_url
|
175
190
|
|
176
|
-
|
191
|
+
subscription_id = $2 ? $2 : $1
|
192
|
+
subscription = assert_existence :subscription, subscription_id, subscriptions[subscription_id]
|
177
193
|
|
178
194
|
customer_id = subscription[:customer]
|
179
195
|
customer = assert_existence :customer, customer_id, customers[customer_id]
|
@@ -183,7 +199,7 @@ module StripeMock
|
|
183
199
|
if cancelled_at_period_end
|
184
200
|
cancel_params[:cancel_at_period_end] = true
|
185
201
|
else
|
186
|
-
cancel_params[:status] =
|
202
|
+
cancel_params[:status] = 'canceled'
|
187
203
|
cancel_params[:cancel_at_period_end] = false
|
188
204
|
cancel_params[:ended_at] = Time.now.utc.to_i
|
189
205
|
end
|
@@ -206,6 +222,14 @@ module StripeMock
|
|
206
222
|
end
|
207
223
|
end
|
208
224
|
|
225
|
+
def verify_active_status(subscription)
|
226
|
+
id, status = subscription.values_at(:id, :status)
|
227
|
+
|
228
|
+
if status == 'canceled'
|
229
|
+
message = "No such subscription: #{id}"
|
230
|
+
raise Stripe::InvalidRequestError.new(message, 'subscription', 404)
|
231
|
+
end
|
232
|
+
end
|
209
233
|
end
|
210
234
|
end
|
211
235
|
end
|
data/lib/stripe_mock/version.rb
CHANGED
@@ -375,4 +375,31 @@ shared_examples 'Charge API' do
|
|
375
375
|
end
|
376
376
|
end
|
377
377
|
|
378
|
+
describe "idempotency" do
|
379
|
+
let(:idempotent_charge_params) {{
|
380
|
+
amount: 777,
|
381
|
+
currency: 'USD',
|
382
|
+
card: stripe_helper.generate_card_token,
|
383
|
+
capture: true,
|
384
|
+
idempotency_key: 'onceisenough'
|
385
|
+
}}
|
386
|
+
|
387
|
+
it "returns the original charge if the same idempotency_key is passed in" do
|
388
|
+
charge1 = Stripe::Charge.create(idempotent_charge_params)
|
389
|
+
charge2 = Stripe::Charge.create(idempotent_charge_params)
|
390
|
+
|
391
|
+
expect(charge1).to eq(charge2)
|
392
|
+
end
|
393
|
+
|
394
|
+
it "returns different charges if different idempotency_keys are used for each charge" do
|
395
|
+
idempotent_charge_params2 = idempotent_charge_params.clone
|
396
|
+
idempotent_charge_params2[:idempotency_key] = 'thisoneisdifferent'
|
397
|
+
|
398
|
+
charge1 = Stripe::Charge.create(idempotent_charge_params)
|
399
|
+
charge2 = Stripe::Charge.create(idempotent_charge_params2)
|
400
|
+
|
401
|
+
expect(charge1).not_to eq(charge2)
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
378
405
|
end
|
@@ -9,6 +9,10 @@ shared_examples 'Plan API' do
|
|
9
9
|
:amount => 9900,
|
10
10
|
:currency => 'USD',
|
11
11
|
:interval => 1,
|
12
|
+
:metadata => {
|
13
|
+
:description => "desc text",
|
14
|
+
:info => "info text"
|
15
|
+
},
|
12
16
|
:trial_period_days => 30
|
13
17
|
)
|
14
18
|
|
@@ -18,6 +22,10 @@ shared_examples 'Plan API' do
|
|
18
22
|
|
19
23
|
expect(plan.currency).to eq('USD')
|
20
24
|
expect(plan.interval).to eq(1)
|
25
|
+
|
26
|
+
expect(plan.metadata.description).to eq('desc text')
|
27
|
+
expect(plan.metadata.info).to eq('info text')
|
28
|
+
|
21
29
|
expect(plan.trial_period_days).to eq(30)
|
22
30
|
end
|
23
31
|
|
@@ -288,6 +288,19 @@ shared_examples 'Customer Subscriptions' do
|
|
288
288
|
end
|
289
289
|
|
290
290
|
context "updating a subscription" do
|
291
|
+
it 'raises invalid request exception when subscription is cancelled' do
|
292
|
+
stripe_helper.create_plan(id: 'the truth')
|
293
|
+
customer = Stripe::Customer.create(source: gen_card_tk, plan: 'the truth')
|
294
|
+
|
295
|
+
subscription = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
|
296
|
+
subscription.delete
|
297
|
+
|
298
|
+
expect { subscription.save }.to raise_error { |e|
|
299
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
300
|
+
expect(e.http_status).to eq(404)
|
301
|
+
expect(e.message).to eq("No such subscription: #{subscription.id}")
|
302
|
+
}
|
303
|
+
end
|
291
304
|
|
292
305
|
it "updates a stripe customer's existing subscription" do
|
293
306
|
silver = stripe_helper.create_plan(id: 'silver')
|
data/stripe-ruby-mock.gemspec
CHANGED
@@ -17,11 +17,11 @@ 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',
|
21
|
-
gem.add_dependency 'multi_json', '
|
20
|
+
gem.add_dependency 'stripe', '~> 1.31'
|
21
|
+
gem.add_dependency 'multi_json', '~> 1.0'
|
22
22
|
gem.add_dependency 'dante', '>= 0.2.0'
|
23
23
|
|
24
24
|
gem.add_development_dependency 'rspec', '~> 3.1.0'
|
25
25
|
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
26
|
-
gem.add_development_dependency 'thin'
|
26
|
+
gem.add_development_dependency 'thin', '~> 1.6.4'
|
27
27
|
end
|
metadata
CHANGED
@@ -1,49 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe-ruby-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stripe
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.31.0
|
20
|
-
- - <=
|
17
|
+
- - ~>
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: '1.
|
19
|
+
version: '1.31'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 1.31.0
|
30
|
-
- - <=
|
24
|
+
- - ~>
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: '1.
|
26
|
+
version: '1.31'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: multi_json
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- -
|
31
|
+
- - ~>
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: 1.0
|
33
|
+
version: '1.0'
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
|
-
- -
|
38
|
+
- - ~>
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: 1.0
|
40
|
+
version: '1.0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: dante
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,16 +84,16 @@ dependencies:
|
|
90
84
|
name: thin
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
92
86
|
requirements:
|
93
|
-
- -
|
87
|
+
- - ~>
|
94
88
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
89
|
+
version: 1.6.4
|
96
90
|
type: :development
|
97
91
|
prerelease: false
|
98
92
|
version_requirements: !ruby/object:Gem::Requirement
|
99
93
|
requirements:
|
100
|
-
- -
|
94
|
+
- - ~>
|
101
95
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
96
|
+
version: 1.6.4
|
103
97
|
description: A drop-in library to test stripe without hitting their servers
|
104
98
|
email: gilbertbgarza@gmail.com
|
105
99
|
executables:
|