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
@@ -0,0 +1,22 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module CountrySpec
|
4
|
+
|
5
|
+
def CountrySpec.included(klass)
|
6
|
+
klass.add_handler 'get /v1/country_specs/(.*)', :retrieve_country_spec
|
7
|
+
end
|
8
|
+
|
9
|
+
def retrieve_country_spec(route, method_url, params, headers)
|
10
|
+
route =~ method_url
|
11
|
+
|
12
|
+
unless ["AT", "AU", "BE", "CA", "DE", "DK", "ES", "FI", "FR", "GB", "IE", "IT", "JP", "LU", "NL", "NO", "SE", "SG", "US"].include?($1)
|
13
|
+
raise Stripe::InvalidRequestError.new("#{$1} is not currently supported by Stripe.", $1.to_s)
|
14
|
+
end
|
15
|
+
|
16
|
+
country_spec[$1] ||= Data.mock_country_spec($1)
|
17
|
+
|
18
|
+
assert_existence :country_spec, $1, country_spec[$1]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -4,9 +4,9 @@ module StripeMock
|
|
4
4
|
|
5
5
|
def Customers.included(klass)
|
6
6
|
klass.add_handler 'post /v1/customers', :new_customer
|
7
|
-
klass.add_handler 'post /v1/customers/(
|
8
|
-
klass.add_handler 'get /v1/customers/(
|
9
|
-
klass.add_handler 'delete /v1/customers/(
|
7
|
+
klass.add_handler 'post /v1/customers/([^/]*)', :update_customer
|
8
|
+
klass.add_handler 'get /v1/customers/([^/]*)', :get_customer
|
9
|
+
klass.add_handler 'delete /v1/customers/([^/]*)', :delete_customer
|
10
10
|
klass.add_handler 'get /v1/customers', :list_customers
|
11
11
|
end
|
12
12
|
|
@@ -26,8 +26,11 @@ module StripeMock
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def add_subscription_to_customer(cus, sub)
|
29
|
-
|
30
|
-
|
29
|
+
if sub[:trial_end].nil? || sub[:trial_end] == "now"
|
30
|
+
id = new_id('ch')
|
31
|
+
charges[id] = Data.mock_charge(:id => id, :customer => cus[:id], :amount => sub[:plan][:amount])
|
32
|
+
end
|
33
|
+
|
31
34
|
if cus[:currency].nil?
|
32
35
|
cus[:currency] = sub[:plan][:currency]
|
33
36
|
elsif cus[:currency] != sub[:plan][:currency]
|
@@ -35,7 +35,8 @@ module StripeMock
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def get_card_or_bank_by_token(token)
|
38
|
-
|
38
|
+
token_id = token['id'] || token
|
39
|
+
@card_tokens[token_id] || @bank_tokens[token_id] || raise(Stripe::InvalidRequestError.new("Invalid token id: #{token_id}", 'tok', 404))
|
39
40
|
end
|
40
41
|
|
41
42
|
end
|
@@ -12,6 +12,18 @@ module StripeMock
|
|
12
12
|
params[:id] ||= new_id('rp')
|
13
13
|
cards = []
|
14
14
|
|
15
|
+
if params[:name].nil?
|
16
|
+
raise StripeMock::StripeMockError.new("Missing required parameter name for recipients.")
|
17
|
+
end
|
18
|
+
|
19
|
+
if params[:type].nil?
|
20
|
+
raise StripeMock::StripeMockError.new("Missing required parameter type for recipients.")
|
21
|
+
end
|
22
|
+
|
23
|
+
unless %w(individual corporation).include?(params[:type])
|
24
|
+
raise StripeMock::StripeMockError.new("Type must be either individual or corporation..")
|
25
|
+
end
|
26
|
+
|
15
27
|
if params[:bank_account]
|
16
28
|
params[:active_account] = get_bank_by_token(params.delete(:bank_account))
|
17
29
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module Refunds
|
4
|
+
|
5
|
+
def Refunds.included(klass)
|
6
|
+
klass.add_handler 'post /v1/refunds', :new_refund
|
7
|
+
klass.add_handler 'get /v1/refunds', :get_refunds
|
8
|
+
klass.add_handler 'get /v1/refunds/(.*)', :get_refund
|
9
|
+
klass.add_handler 'post /v1/refunds/(.*)', :update_refund
|
10
|
+
end
|
11
|
+
|
12
|
+
def new_refund(route, method_url, params, headers)
|
13
|
+
if params[:idempotency_key] && refunds.any?
|
14
|
+
original_refund = refunds.values.find { |c| c[:idempotency_key] == params[:idempotency_key]}
|
15
|
+
return refunds[original_refund[:id]] if original_refund
|
16
|
+
end
|
17
|
+
|
18
|
+
charge = get_charge(route, method_url, params, headers)
|
19
|
+
params[:amount] ||= charge[:amount]
|
20
|
+
id = new_id('re')
|
21
|
+
bal_trans_params = {
|
22
|
+
amount: params[:amount] * -1,
|
23
|
+
source: id,
|
24
|
+
type: 'refund'
|
25
|
+
}
|
26
|
+
balance_transaction_id = new_balance_transaction('txn', bal_trans_params)
|
27
|
+
refund = Data.mock_refund params.merge(
|
28
|
+
:balance_transaction => balance_transaction_id,
|
29
|
+
:id => id,
|
30
|
+
:charge => charge[:id],
|
31
|
+
)
|
32
|
+
add_refund_to_charge(refund, charge)
|
33
|
+
refunds[id] = refund
|
34
|
+
|
35
|
+
if params[:expand] == ['balance_transaction']
|
36
|
+
refunds[id][:balance_transaction] =
|
37
|
+
balance_transactions[balance_transaction_id]
|
38
|
+
end
|
39
|
+
refund
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_refund(route, method_url, params, headers)
|
43
|
+
route =~ method_url
|
44
|
+
id = $1
|
45
|
+
|
46
|
+
refund = assert_existence :refund, id, refunds[id]
|
47
|
+
allowed = allowed_refund_params(params)
|
48
|
+
disallowed = params.keys - allowed
|
49
|
+
if disallowed.count > 0
|
50
|
+
raise Stripe::InvalidRequestError.new("Received unknown parameters: #{disallowed.join(', ')}" , '', 400)
|
51
|
+
end
|
52
|
+
|
53
|
+
refunds[id] = Util.rmerge(refund, params)
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_refunds(route, method_url, params, headers)
|
57
|
+
params[:offset] ||= 0
|
58
|
+
params[:limit] ||= 10
|
59
|
+
|
60
|
+
clone = refunds.clone
|
61
|
+
|
62
|
+
Data.mock_list_object(clone.values, params)
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_refund(route, method_url, params, headers)
|
66
|
+
route =~ method_url
|
67
|
+
refund_id = $1 || params[:refund]
|
68
|
+
assert_existence :refund, refund_id, refunds[refund_id]
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def ensure_refund_required_params(params)
|
74
|
+
if non_integer_charge_amount?(params)
|
75
|
+
raise Stripe::InvalidRequestError.new("Invalid integer: #{params[:amount]}", 'amount', 400)
|
76
|
+
elsif non_positive_charge_amount?(params)
|
77
|
+
raise Stripe::InvalidRequestError.new('Invalid positive integer', 'amount', 400)
|
78
|
+
elsif params[:charge].nil?
|
79
|
+
raise Stripe::InvalidRequestError.new('Must provide the identifier of the charge to refund.', nil)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def allowed_refund_params(params)
|
84
|
+
[:metadata]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -9,15 +9,17 @@ module StripeMock
|
|
9
9
|
klass.add_handler 'post /v1/subscriptions/(.*)', :update_subscription
|
10
10
|
klass.add_handler 'delete /v1/subscriptions/(.*)', :cancel_subscription
|
11
11
|
|
12
|
-
klass.add_handler 'post /v1/customers/(.*)/
|
13
|
-
klass.add_handler 'get /v1/customers/(.*)/
|
14
|
-
klass.add_handler 'get /v1/customers/(.*)/
|
12
|
+
klass.add_handler 'post /v1/customers/(.*)/subscription(?:s)?', :create_customer_subscription
|
13
|
+
klass.add_handler 'get /v1/customers/(.*)/subscription(?:s)?/(.*)', :retrieve_customer_subscription
|
14
|
+
klass.add_handler 'get /v1/customers/(.*)/subscription(?:s)?', :retrieve_customer_subscriptions
|
15
|
+
klass.add_handler 'post /v1/customers/(.*)subscription(?:s)?/(.*)', :update_subscription
|
16
|
+
klass.add_handler 'delete /v1/customers/(.*)/subscription(?:s)?/(.*)', :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,25 @@ 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
|
+
if coupon
|
162
|
+
subscription[:discount] = Stripe::Util.convert_to_stripe_object({ coupon: coupon }, {})
|
163
|
+
elsif coupon_id == ""
|
164
|
+
subscription[:discount] = Stripe::Util.convert_to_stripe_object(nil, {})
|
165
|
+
else
|
166
|
+
raise Stripe::InvalidRequestError.new("No such coupon: #{coupon_id}", 'coupon', 400)
|
167
|
+
end
|
153
168
|
end
|
154
169
|
|
155
170
|
assert_existence :plan, plan_name, plan
|
@@ -161,6 +176,7 @@ module StripeMock
|
|
161
176
|
subscription[:canceled_at] = nil
|
162
177
|
end
|
163
178
|
|
179
|
+
params[:current_period_start] = subscription[:current_period_start]
|
164
180
|
subscription.merge!(custom_subscription_params(plan, customer, params))
|
165
181
|
|
166
182
|
# delete the old subscription, replace with the new subscription
|
@@ -173,7 +189,8 @@ module StripeMock
|
|
173
189
|
def cancel_subscription(route, method_url, params, headers)
|
174
190
|
route =~ method_url
|
175
191
|
|
176
|
-
|
192
|
+
subscription_id = $2 ? $2 : $1
|
193
|
+
subscription = assert_existence :subscription, subscription_id, subscriptions[subscription_id]
|
177
194
|
|
178
195
|
customer_id = subscription[:customer]
|
179
196
|
customer = assert_existence :customer, customer_id, customers[customer_id]
|
@@ -183,7 +200,7 @@ module StripeMock
|
|
183
200
|
if cancelled_at_period_end
|
184
201
|
cancel_params[:cancel_at_period_end] = true
|
185
202
|
else
|
186
|
-
cancel_params[:status] =
|
203
|
+
cancel_params[:status] = 'canceled'
|
187
204
|
cancel_params[:cancel_at_period_end] = false
|
188
205
|
cancel_params[:ended_at] = Time.now.utc.to_i
|
189
206
|
end
|
@@ -206,6 +223,14 @@ module StripeMock
|
|
206
223
|
end
|
207
224
|
end
|
208
225
|
|
226
|
+
def verify_active_status(subscription)
|
227
|
+
id, status = subscription.values_at(:id, :status)
|
228
|
+
|
229
|
+
if status == 'canceled'
|
230
|
+
message = "No such subscription: #{id}"
|
231
|
+
raise Stripe::InvalidRequestError.new(message, 'subscription', 404)
|
232
|
+
end
|
233
|
+
end
|
209
234
|
end
|
210
235
|
end
|
211
236
|
end
|
@@ -8,9 +8,14 @@ module StripeMock
|
|
8
8
|
@base_strategy.create_plan_params.keys.each do |name|
|
9
9
|
raise Stripe::InvalidRequestError.new("Missing required param: #{name}.", name) if params[name].nil?
|
10
10
|
end
|
11
|
+
|
11
12
|
if plans[ params[:id] ]
|
12
13
|
raise Stripe::InvalidRequestError.new("Plan already exists.", :id)
|
13
14
|
end
|
15
|
+
|
16
|
+
unless params[:amount].integer?
|
17
|
+
raise Stripe::InvalidRequestError.new("Invalid integer: #{params[:amount]}", :amount)
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
end
|
@@ -3,17 +3,18 @@ module StripeMock
|
|
3
3
|
class Base
|
4
4
|
|
5
5
|
def create_plan_params(params={})
|
6
|
+
currency = params[:currency] || 'usd'
|
6
7
|
{
|
7
8
|
:id => 'stripe_mock_default_plan_id',
|
8
9
|
:name => 'StripeMock Default Plan ID',
|
9
10
|
:amount => 1337,
|
10
|
-
:currency =>
|
11
|
+
:currency => currency,
|
11
12
|
:interval => 'month'
|
12
13
|
}.merge(params)
|
13
14
|
end
|
14
15
|
|
15
16
|
def generate_card_token(card_params={})
|
16
|
-
card_data = { :number => "4242424242424242", :exp_month => 9, :exp_year => 2018, :cvc => "999" }
|
17
|
+
card_data = { :number => "4242424242424242", :exp_month => 9, :exp_year => 2018, :cvc => "999", :tokenization_method => nil }
|
17
18
|
card = StripeMock::Util.card_merge(card_data, card_params)
|
18
19
|
card[:fingerprint] = StripeMock::Util.fingerprint(card[:number]) if StripeMock.state == 'local'
|
19
20
|
|
@@ -22,9 +23,10 @@ module StripeMock
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def generate_bank_token(bank_account_params={})
|
26
|
+
currency = bank_account_params[:currency] || 'usd'
|
25
27
|
bank_account = {
|
26
28
|
:country => "US",
|
27
|
-
:currency =>
|
29
|
+
:currency => currency,
|
28
30
|
:account_holder_name => "Jane Austen",
|
29
31
|
:account_holder_type => "individual",
|
30
32
|
:routing_number => "110000000",
|
@@ -37,10 +39,11 @@ module StripeMock
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def create_coupon_params(params = {})
|
42
|
+
currency = params[:currency] || 'usd'
|
40
43
|
{
|
41
44
|
id: '10BUCKS',
|
42
45
|
amount_off: 1000,
|
43
|
-
currency:
|
46
|
+
currency: currency,
|
44
47
|
max_redemptions: 100,
|
45
48
|
metadata: {
|
46
49
|
created_by: 'admin_acct_1'
|
data/lib/stripe_mock/version.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"created":1326853478,
|
3
|
+
"livemode":false,
|
4
|
+
"id":"evt_00000000000000",
|
5
|
+
"type":"account.external_account.created",
|
6
|
+
"object":"event",
|
7
|
+
"data":{
|
8
|
+
"object":{
|
9
|
+
"id":"ba_00000000000000",
|
10
|
+
"object":"bank_account",
|
11
|
+
"account":"acct_00000000000000",
|
12
|
+
"account_holder_name":"Jane Austen",
|
13
|
+
"account_holder_type":"individual",
|
14
|
+
"bank_name":"STRIPE TEST BANK",
|
15
|
+
"country":"US",
|
16
|
+
"currency":"eur",
|
17
|
+
"default_for_currency":false,
|
18
|
+
"fingerprint":"efGCBmiwp56O1lsN",
|
19
|
+
"last4":"6789",
|
20
|
+
"metadata":{
|
21
|
+
|
22
|
+
},
|
23
|
+
"routing_number":"110000000",
|
24
|
+
"status":"new"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"created":1326853478,
|
3
|
+
"livemode":false,
|
4
|
+
"id":"evt_00000000000000",
|
5
|
+
"type":"account.external_account.deleted",
|
6
|
+
"object":"event",
|
7
|
+
"data":{
|
8
|
+
"object":{
|
9
|
+
"id":"ba_00000000000000",
|
10
|
+
"object":"bank_account",
|
11
|
+
"account":"acct_00000000000000",
|
12
|
+
"account_holder_name":"Jane Austen",
|
13
|
+
"account_holder_type":"individual",
|
14
|
+
"bank_name":"STRIPE TEST BANK",
|
15
|
+
"country":"US",
|
16
|
+
"currency":"eur",
|
17
|
+
"default_for_currency":false,
|
18
|
+
"fingerprint":"efGCBmiwp56O1lsN",
|
19
|
+
"last4":"6789",
|
20
|
+
"metadata":{
|
21
|
+
|
22
|
+
},
|
23
|
+
"routing_number":"110000000",
|
24
|
+
"status":"new"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"created":1326853478,
|
3
|
+
"livemode":false,
|
4
|
+
"id":"evt_00000000000000",
|
5
|
+
"type":"account.external_account.updated",
|
6
|
+
"object":"event",
|
7
|
+
"data":{
|
8
|
+
"object":{
|
9
|
+
"id":"ba_00000000000000",
|
10
|
+
"object":"bank_account",
|
11
|
+
"account":"acct_00000000000000",
|
12
|
+
"account_holder_name":"Jane Austen",
|
13
|
+
"account_holder_type":"individual",
|
14
|
+
"bank_name":"STRIPE TEST BANK",
|
15
|
+
"country":"US",
|
16
|
+
"currency":"eur",
|
17
|
+
"default_for_currency":false,
|
18
|
+
"fingerprint":"efGCBmiwp56O1lsN",
|
19
|
+
"last4":"6789",
|
20
|
+
"metadata":{
|
21
|
+
|
22
|
+
},
|
23
|
+
"routing_number":"110000000",
|
24
|
+
"status":"new"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
data/lib/stripe_mock.rb
CHANGED
@@ -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'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StripeMock do
|
4
|
+
describe ".mock" do
|
5
|
+
it "yields the given block between starting and stopping StripeMock" do
|
6
|
+
expect(StripeMock.instance).to be_nil
|
7
|
+
expect(StripeMock.state).to eq "ready"
|
8
|
+
|
9
|
+
StripeMock.mock do
|
10
|
+
expect(StripeMock.instance).to be_instance_of StripeMock::Instance
|
11
|
+
expect(StripeMock.state).to eq "local"
|
12
|
+
end
|
13
|
+
|
14
|
+
expect(StripeMock.instance).to be_nil
|
15
|
+
expect(StripeMock.state).to eq "ready"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "stops StripeMock if the given block raises an exception" do
|
19
|
+
expect(StripeMock.instance).to be_nil
|
20
|
+
begin
|
21
|
+
StripeMock.mock do
|
22
|
+
raise "Uh-oh..."
|
23
|
+
end
|
24
|
+
rescue
|
25
|
+
expect(StripeMock.instance).to be_nil
|
26
|
+
expect(StripeMock.state).to eq "ready"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/list_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe StripeMock::Data::List do
|
4
|
+
let(:stripe_helper) { StripeMock.create_test_helper }
|
5
|
+
|
4
6
|
before :all do
|
5
7
|
StripeMock.start
|
6
8
|
end
|
@@ -33,9 +35,9 @@ describe StripeMock::Data::List do
|
|
33
35
|
end
|
34
36
|
|
35
37
|
it "eventually gets turned into a hash" do
|
36
|
-
charge1 = Stripe::Charge.create(amount: 1, currency: 'usd')
|
37
|
-
charge2 = Stripe::Charge.create(amount: 1, currency: 'usd')
|
38
|
-
charge3 = Stripe::Charge.create(amount: 1, currency: 'usd')
|
38
|
+
charge1 = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
|
39
|
+
charge2 = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
|
40
|
+
charge3 = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
|
39
41
|
list = StripeMock::Data::List.new([charge1, charge2, charge3])
|
40
42
|
hash = list.to_h
|
41
43
|
|
@@ -95,15 +97,17 @@ describe StripeMock::Data::List do
|
|
95
97
|
|
96
98
|
context "pagination" do
|
97
99
|
it "has a has_more field when it has more" do
|
98
|
-
list = StripeMock::Data::List.new(
|
100
|
+
list = StripeMock::Data::List.new(
|
101
|
+
[Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)] * 256
|
102
|
+
)
|
99
103
|
|
100
104
|
expect(list).to have_more
|
101
105
|
end
|
102
106
|
|
103
107
|
it "accepts a starting_after parameter" do
|
104
108
|
data = []
|
105
|
-
255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd') }
|
106
|
-
new_charge = Stripe::Charge.create(amount: 1, currency: 'usd')
|
109
|
+
255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token) }
|
110
|
+
new_charge = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
|
107
111
|
data[89] = new_charge
|
108
112
|
list = StripeMock::Data::List.new(data, starting_after: new_charge.id)
|
109
113
|
hash = list.to_h
|
@@ -114,7 +118,7 @@ describe StripeMock::Data::List do
|
|
114
118
|
|
115
119
|
it "raises an error if starting_after cursor is not found" do
|
116
120
|
data = []
|
117
|
-
255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd') }
|
121
|
+
255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token) }
|
118
122
|
list = StripeMock::Data::List.new(data, starting_after: "test_ch_unknown")
|
119
123
|
|
120
124
|
expect { list.to_h }.to raise_error
|
data/spec/server_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe 'StripeMock Server', :mock_server => true do
|
|
24
24
|
charge = Stripe::Charge.create(
|
25
25
|
amount: 987,
|
26
26
|
currency: 'USD',
|
27
|
-
|
27
|
+
source: stripe_helper.generate_card_token,
|
28
28
|
description: 'card charge'
|
29
29
|
)
|
30
30
|
expect(charge.amount).to eq(987)
|
@@ -34,6 +34,9 @@ shared_examples 'Account API' do
|
|
34
34
|
expect(account.keys).not_to be_nil
|
35
35
|
expect(account.keys.secret).to match /sk_(live|test)_[\d\w]+/
|
36
36
|
expect(account.keys.publishable).to match /pk_(live|test)_[\d\w]+/
|
37
|
+
expect(account.external_accounts).not_to be_nil
|
38
|
+
expect(account.external_accounts.data).to be_an Array
|
39
|
+
expect(account.external_accounts.url).to match /\/v1\/accounts\/.*\/external_accounts/
|
37
40
|
end
|
38
41
|
end
|
39
42
|
describe 'updates account' do
|
@@ -47,4 +50,12 @@ shared_examples 'Account API' do
|
|
47
50
|
expect(account.support_phone).to eq '1234567'
|
48
51
|
end
|
49
52
|
end
|
53
|
+
|
54
|
+
it 'deauthorizes the stripe account', live: false do
|
55
|
+
account = Stripe::Account.retrieve
|
56
|
+
result = account.deauthorize('CLIENT_ID')
|
57
|
+
|
58
|
+
expect(result).to be_a Stripe::StripeObject
|
59
|
+
expect(result[:stripe_user_id]).to eq account[:id]
|
60
|
+
end
|
50
61
|
end
|
@@ -22,7 +22,13 @@ shared_examples 'Card API' do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'creates/returns a card when using recipient.cards.create given a card token' do
|
25
|
-
|
25
|
+
params = {
|
26
|
+
id: 'test_recipient_sub',
|
27
|
+
name: 'MyRec',
|
28
|
+
type: 'individual'
|
29
|
+
}
|
30
|
+
|
31
|
+
recipient = Stripe::Recipient.create(params)
|
26
32
|
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
27
33
|
card = recipient.cards.create(card: card_token)
|
28
34
|
|
@@ -64,7 +70,12 @@ shared_examples 'Card API' do
|
|
64
70
|
end
|
65
71
|
|
66
72
|
it 'creates/returns a card when using recipient.cards.create given card params' do
|
67
|
-
|
73
|
+
params = {
|
74
|
+
id: 'test_recipient_sub',
|
75
|
+
name: 'MyRec',
|
76
|
+
type: 'individual'
|
77
|
+
}
|
78
|
+
recipient = Stripe::Recipient.create(params)
|
68
79
|
card = recipient.cards.create(card: {
|
69
80
|
number: '4000056655665556',
|
70
81
|
exp_month: '11',
|
@@ -12,6 +12,7 @@ shared_examples 'Card Token Mocking' do
|
|
12
12
|
expect(card.last4).to eq("4242")
|
13
13
|
expect(card.exp_month).to eq(4)
|
14
14
|
expect(card.exp_year).to eq(2016)
|
15
|
+
expect(card.tokenization_method).to eq(nil)
|
15
16
|
end
|
16
17
|
|
17
18
|
it "generates and reads a card token for create charge" do
|