stripe-ruby-mock 3.0.1 → 3.1.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -5
- data/CHANGELOG.md +28 -15
- data/Gemfile +1 -0
- data/lib/stripe_mock.rb +4 -0
- data/lib/stripe_mock/api/client.rb +1 -1
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +2 -0
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data.rb +127 -25
- data/lib/stripe_mock/data/list.rb +31 -6
- data/lib/stripe_mock/instance.rb +7 -2
- data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/charges.rb +6 -4
- data/lib/stripe_mock/request_handlers/checkout_session.rb +16 -0
- data/lib/stripe_mock/request_handlers/customers.rb +22 -13
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
- data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +12 -7
- data/lib/stripe_mock/request_handlers/invoices.rb +4 -3
- data/lib/stripe_mock/request_handlers/payment_methods.rb +8 -5
- data/lib/stripe_mock/request_handlers/prices.rb +44 -0
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscriptions.rb +29 -19
- data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +32 -0
- data/lib/stripe_mock/test_strategies/base.rb +26 -0
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/balance.available.json +6 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +186 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +164 -0
- data/spec/instance_spec.rb +4 -6
- data/spec/list_spec.rb +23 -0
- data/spec/server_spec.rb +4 -2
- data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
- data/spec/shared_stripe_examples/balance_examples.rb +6 -0
- data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/checkout_examples.rb +20 -1
- data/spec/shared_stripe_examples/customer_examples.rb +11 -13
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +8 -8
- data/spec/shared_stripe_examples/payment_method_examples.rb +332 -68
- data/spec/shared_stripe_examples/price_examples.rb +183 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +115 -8
- data/spec/spec_helper.rb +4 -0
- data/spec/stripe_mock_spec.rb +2 -2
- data/spec/support/stripe_examples.rb +5 -1
- data/stripe-ruby-mock.gemspec +6 -1
- metadata +25 -11
data/lib/stripe_mock/instance.rb
CHANGED
@@ -24,6 +24,8 @@ module StripeMock
|
|
24
24
|
include StripeMock::RequestHandlers::PaymentMethods
|
25
25
|
include StripeMock::RequestHandlers::SetupIntents
|
26
26
|
include StripeMock::RequestHandlers::ExternalAccounts
|
27
|
+
include StripeMock::RequestHandlers::AccountLinks
|
28
|
+
include StripeMock::RequestHandlers::ExpressLoginLinks
|
27
29
|
include StripeMock::RequestHandlers::Accounts
|
28
30
|
include StripeMock::RequestHandlers::Balance
|
29
31
|
include StripeMock::RequestHandlers::BalanceTransactions
|
@@ -40,6 +42,7 @@ module StripeMock
|
|
40
42
|
include StripeMock::RequestHandlers::InvoiceItems
|
41
43
|
include StripeMock::RequestHandlers::Orders
|
42
44
|
include StripeMock::RequestHandlers::Plans
|
45
|
+
include StripeMock::RequestHandlers::Prices
|
43
46
|
include StripeMock::RequestHandlers::Products
|
44
47
|
include StripeMock::RequestHandlers::Refunds
|
45
48
|
include StripeMock::RequestHandlers::Recipients
|
@@ -50,10 +53,11 @@ module StripeMock
|
|
50
53
|
include StripeMock::RequestHandlers::EphemeralKey
|
51
54
|
include StripeMock::RequestHandlers::TaxRates
|
52
55
|
include StripeMock::RequestHandlers::Checkout
|
56
|
+
include StripeMock::RequestHandlers::Checkout::Session
|
53
57
|
|
54
58
|
attr_reader :accounts, :balance, :balance_transactions, :bank_tokens, :charges, :coupons, :customers,
|
55
59
|
:disputes, :events, :invoices, :invoice_items, :orders, :payment_intents, :payment_methods,
|
56
|
-
:setup_intents, :plans, :recipients, :refunds, :transfers, :payouts, :subscriptions, :country_spec,
|
60
|
+
:setup_intents, :plans, :prices, :recipients, :refunds, :transfers, :payouts, :subscriptions, :country_spec,
|
57
61
|
:subscriptions_items, :products, :tax_rates, :checkout_sessions
|
58
62
|
|
59
63
|
attr_accessor :error_queue, :debug, :conversion_rate, :account_balance
|
@@ -64,7 +68,7 @@ module StripeMock
|
|
64
68
|
@balance_transactions = Data.mock_balance_transactions(['txn_05RsQX2eZvKYlo2C0FRTGSSA','txn_15RsQX2eZvKYlo2C0ERTYUIA', 'txn_25RsQX2eZvKYlo2C0ZXCVBNM', 'txn_35RsQX2eZvKYlo2C0QAZXSWE', 'txn_45RsQX2eZvKYlo2C0EDCVFRT', 'txn_55RsQX2eZvKYlo2C0OIKLJUY', 'txn_65RsQX2eZvKYlo2C0ASDFGHJ', 'txn_75RsQX2eZvKYlo2C0EDCXSWQ', 'txn_85RsQX2eZvKYlo2C0UJMCDET', 'txn_95RsQX2eZvKYlo2C0EDFRYUI'])
|
65
69
|
@bank_tokens = {}
|
66
70
|
@card_tokens = {}
|
67
|
-
@customers = {}
|
71
|
+
@customers = { Stripe.api_key => {} }
|
68
72
|
@charges = {}
|
69
73
|
@payment_intents = {}
|
70
74
|
@payment_methods = {}
|
@@ -77,6 +81,7 @@ module StripeMock
|
|
77
81
|
@orders = {}
|
78
82
|
@payment_methods = {}
|
79
83
|
@plans = {}
|
84
|
+
@prices = {}
|
80
85
|
@products = {}
|
81
86
|
@recipients = {}
|
82
87
|
@refunds = {}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module AccountLinks
|
4
|
+
|
5
|
+
def AccountLinks.included(klass)
|
6
|
+
klass.add_handler 'post /v1/account_links', :new_account_link
|
7
|
+
end
|
8
|
+
|
9
|
+
def new_account_link(route, method_url, params, headers)
|
10
|
+
route =~ method_url
|
11
|
+
Data.mock_account_link(params)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -12,7 +12,9 @@ module StripeMock
|
|
12
12
|
klass.add_handler 'post /v1/charges/(.*)', :update_charge
|
13
13
|
end
|
14
14
|
|
15
|
-
def new_charge(route, method_url, params, headers)
|
15
|
+
def new_charge(route, method_url, params, headers = {})
|
16
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
17
|
+
|
16
18
|
if headers && headers[:idempotency_key]
|
17
19
|
params[:idempotency_key] = headers[:idempotency_key]
|
18
20
|
if charges.any?
|
@@ -29,7 +31,7 @@ module StripeMock
|
|
29
31
|
# card id, not a token. in this case we'll find the card in the customer
|
30
32
|
# object and return that.
|
31
33
|
if params[:customer]
|
32
|
-
params[:source] = get_card(customers[params[:customer]], params[:source])
|
34
|
+
params[:source] = get_card(customers[stripe_account][params[:customer]], params[:source])
|
33
35
|
else
|
34
36
|
params[:source] = get_card_or_bank_by_token(params[:source])
|
35
37
|
end
|
@@ -37,7 +39,7 @@ module StripeMock
|
|
37
39
|
raise Stripe::InvalidRequestError.new("Invalid token id: #{params[:source]}", 'card', http_status: 400)
|
38
40
|
end
|
39
41
|
elsif params[:customer]
|
40
|
-
customer = customers[params[:customer]]
|
42
|
+
customer = customers[stripe_account][params[:customer]]
|
41
43
|
if customer && customer[:default_source]
|
42
44
|
params[:source] = get_card(customer, customer[:default_source])
|
43
45
|
end
|
@@ -146,7 +148,7 @@ module StripeMock
|
|
146
148
|
elsif non_positive_charge_amount?(params)
|
147
149
|
raise Stripe::InvalidRequestError.new('Invalid positive integer', 'amount', http_status: 400)
|
148
150
|
elsif params[:source].nil? && params[:customer].nil?
|
149
|
-
raise Stripe::InvalidRequestError.new('Must provide source or customer.', http_status: nil)
|
151
|
+
raise Stripe::InvalidRequestError.new('Must provide source or customer.', nil, http_status: nil)
|
150
152
|
end
|
151
153
|
end
|
152
154
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module Checkout
|
4
|
+
module Session
|
5
|
+
def Session.included(klass)
|
6
|
+
klass.add_handler 'get /v1/checkout/sessions/(.*)', :get_checkout_session
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_checkout_session(route, method_url, params, headers)
|
10
|
+
route =~ method_url
|
11
|
+
assert_existence :checkout_session, $1, checkout_sessions[$1]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -12,6 +12,7 @@ module StripeMock
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def new_customer(route, method_url, params, headers)
|
15
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
15
16
|
params[:id] ||= new_id('cus')
|
16
17
|
sources = []
|
17
18
|
|
@@ -29,7 +30,8 @@ module StripeMock
|
|
29
30
|
params[:default_source] = sources.first[:id]
|
30
31
|
end
|
31
32
|
|
32
|
-
customers[
|
33
|
+
customers[stripe_account] ||= {}
|
34
|
+
customers[stripe_account][params[:id]] = Data.mock_customer(sources, params)
|
33
35
|
|
34
36
|
if params[:plan]
|
35
37
|
plan_id = params[:plan].to_s
|
@@ -40,8 +42,8 @@ module StripeMock
|
|
40
42
|
end
|
41
43
|
|
42
44
|
subscription = Data.mock_subscription({ id: new_id('su') })
|
43
|
-
subscription = resolve_subscription_changes(subscription, [plan], customers[
|
44
|
-
add_subscription_to_customer(customers[
|
45
|
+
subscription = resolve_subscription_changes(subscription, [plan], customers[stripe_account][params[:id]], params)
|
46
|
+
add_subscription_to_customer(customers[stripe_account][params[:id]], subscription)
|
45
47
|
subscriptions[subscription[:id]] = subscription
|
46
48
|
elsif params[:trial_end]
|
47
49
|
raise Stripe::InvalidRequestError.new('Received unknown parameter: trial_end', nil, http_status: 400)
|
@@ -50,15 +52,16 @@ module StripeMock
|
|
50
52
|
if params[:coupon]
|
51
53
|
coupon = coupons[params[:coupon]]
|
52
54
|
assert_existence :coupon, params[:coupon], coupon
|
53
|
-
add_coupon_to_object(customers[params[:id]], coupon)
|
55
|
+
add_coupon_to_object(customers[stripe_account][params[:id]], coupon)
|
54
56
|
end
|
55
57
|
|
56
|
-
customers[params[:id]]
|
58
|
+
customers[stripe_account][params[:id]]
|
57
59
|
end
|
58
60
|
|
59
61
|
def update_customer(route, method_url, params, headers)
|
62
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
60
63
|
route =~ method_url
|
61
|
-
cus = assert_existence :customer, $1, customers[$1]
|
64
|
+
cus = assert_existence :customer, $1, customers[stripe_account][$1]
|
62
65
|
|
63
66
|
# get existing and pending metadata
|
64
67
|
metadata = cus.delete(:metadata) || {}
|
@@ -80,6 +83,8 @@ module StripeMock
|
|
80
83
|
if params[:source]
|
81
84
|
if params[:source].is_a?(String)
|
82
85
|
new_card = get_card_or_bank_by_token(params.delete(:source))
|
86
|
+
elsif params[:source].is_a?(Stripe::Token)
|
87
|
+
new_card = get_card_or_bank_by_token(params[:source][:id])
|
83
88
|
elsif params[:source].is_a?(Hash)
|
84
89
|
unless params[:source][:object] && params[:source][:number] && params[:source][:exp_month] && params[:source][:exp_year]
|
85
90
|
raise Stripe::InvalidRequestError.new('You must supply a valid card', nil, http_status: 400)
|
@@ -105,21 +110,23 @@ module StripeMock
|
|
105
110
|
end
|
106
111
|
|
107
112
|
def delete_customer(route, method_url, params, headers)
|
113
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
108
114
|
route =~ method_url
|
109
|
-
assert_existence :customer, $1, customers[$1]
|
115
|
+
assert_existence :customer, $1, customers[stripe_account][$1]
|
110
116
|
|
111
|
-
customers[$1] = {
|
112
|
-
id: customers[$1][:id],
|
117
|
+
customers[stripe_account][$1] = {
|
118
|
+
id: customers[stripe_account][$1][:id],
|
113
119
|
deleted: true
|
114
120
|
}
|
115
121
|
end
|
116
122
|
|
117
123
|
def get_customer(route, method_url, params, headers)
|
124
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
118
125
|
route =~ method_url
|
119
|
-
customer = assert_existence :customer, $1, customers[$1]
|
126
|
+
customer = assert_existence :customer, $1, customers[stripe_account][$1]
|
120
127
|
|
121
128
|
customer = customer.clone
|
122
|
-
if params[:expand] == ['default_source']
|
129
|
+
if params[:expand] == ['default_source'] && customer[:sources][:data]
|
123
130
|
customer[:default_source] = customer[:sources][:data].detect do |source|
|
124
131
|
source[:id] == customer[:default_source]
|
125
132
|
end
|
@@ -129,12 +136,14 @@ module StripeMock
|
|
129
136
|
end
|
130
137
|
|
131
138
|
def list_customers(route, method_url, params, headers)
|
132
|
-
|
139
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
140
|
+
Data.mock_list_object(customers[stripe_account]&.values, params)
|
133
141
|
end
|
134
142
|
|
135
143
|
def delete_customer_discount(route, method_url, params, headers)
|
144
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
136
145
|
route =~ method_url
|
137
|
-
cus = assert_existence :customer, $1, customers[$1]
|
146
|
+
cus = assert_existence :customer, $1, customers[stripe_account][$1]
|
138
147
|
|
139
148
|
cus[:discount] = nil
|
140
149
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module ExpressLoginLinks
|
4
|
+
|
5
|
+
def ExpressLoginLinks.included(klass)
|
6
|
+
klass.add_handler 'post /v1/accounts/(.*)/login_links', :new_account_login_link
|
7
|
+
end
|
8
|
+
|
9
|
+
def new_account_login_link(route, method_url, params, headers)
|
10
|
+
route =~ method_url
|
11
|
+
Data.mock_express_login_link(params)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -11,12 +11,13 @@ module StripeMock
|
|
11
11
|
items = options[:items]
|
12
12
|
items = items.values if items.respond_to?(:values)
|
13
13
|
subscription[:items][:data] = plans.map do |plan|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
matching_item = items && items.detect { |item| [item[:price], item[:plan]].include? plan[:id] }
|
15
|
+
if matching_item
|
16
|
+
quantity = matching_item[:quantity] || 1
|
17
|
+
id = matching_item[:id] || new_id('si')
|
18
|
+
Data.mock_subscription_item({ plan: plan, quantity: quantity, id: id })
|
18
19
|
else
|
19
|
-
Data.mock_subscription_item({ plan: plan })
|
20
|
+
Data.mock_subscription_item({ plan: plan, id: new_id('si') })
|
20
21
|
end
|
21
22
|
end
|
22
23
|
subscription
|
@@ -32,7 +33,7 @@ module StripeMock
|
|
32
33
|
start_time = options[:current_period_start] || now
|
33
34
|
params = { customer: cus[:id], current_period_start: start_time, created: created_time }
|
34
35
|
params.merge!({ :plan => (plans.size == 1 ? plans.first : nil) })
|
35
|
-
keys_to_merge = /application_fee_percent|quantity|metadata|tax_percent|billing|days_until_due|default_tax_rates|pending_invoice_item_interval/
|
36
|
+
keys_to_merge = /application_fee_percent|quantity|metadata|tax_percent|billing|days_until_due|default_tax_rates|pending_invoice_item_interval|default_payment_method|collection_method/
|
36
37
|
params.merge! options.select {|k,v| k =~ keys_to_merge}
|
37
38
|
|
38
39
|
if options[:cancel_at_period_end] == true
|
@@ -111,7 +112,11 @@ module StripeMock
|
|
111
112
|
|
112
113
|
def total_items_amount(items)
|
113
114
|
total = 0
|
114
|
-
items.each
|
115
|
+
items.each do |item|
|
116
|
+
quantity = item[:quantity] || 1
|
117
|
+
amount = item[:plan][:unit_amount] || item[:plan][:amount]
|
118
|
+
total += quantity * amount
|
119
|
+
end
|
115
120
|
total
|
116
121
|
end
|
117
122
|
end
|
@@ -56,13 +56,14 @@ module StripeMock
|
|
56
56
|
invoices[$1].merge!(:paid => true, :attempted => true, :charge => charge[:id])
|
57
57
|
end
|
58
58
|
|
59
|
-
def upcoming_invoice(route, method_url, params, headers)
|
59
|
+
def upcoming_invoice(route, method_url, params, headers = {})
|
60
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
60
61
|
route =~ method_url
|
61
|
-
raise Stripe::InvalidRequestError.new('Missing required param: customer', nil, http_status: 400) if params[:customer].nil?
|
62
|
+
raise Stripe::InvalidRequestError.new('Missing required param: customer if subscription is not provided', nil, http_status: 400) if params[:customer].nil? && params[:subscription].nil?
|
62
63
|
raise Stripe::InvalidRequestError.new('When previewing changes to a subscription, you must specify either `subscription` or `subscription_items`', nil, http_status: 400) if !params[:subscription_proration_date].nil? && params[:subscription].nil? && params[:subscription_plan].nil?
|
63
64
|
raise Stripe::InvalidRequestError.new('Cannot specify proration date without specifying a subscription', nil, http_status: 400) if !params[:subscription_proration_date].nil? && params[:subscription].nil?
|
64
65
|
|
65
|
-
customer = customers[params[:customer]]
|
66
|
+
customer = customers[stripe_account][params[:customer]]
|
66
67
|
assert_existence :customer, params[:customer], customer
|
67
68
|
|
68
69
|
raise Stripe::InvalidRequestError.new("No upcoming invoices for customer: #{customer[:id]}", nil, http_status: 404) if customer[:subscriptions][:data].length == 0
|
@@ -51,14 +51,15 @@ module StripeMock
|
|
51
51
|
|
52
52
|
Data.mock_list_object(clone.values, params)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
# post /v1/payment_methods/:id/attach
|
56
56
|
def attach_payment_method(route, method_url, params, headers)
|
57
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
57
58
|
allowed_params = [:customer]
|
58
59
|
|
59
60
|
id = method_url.match(route)[1]
|
60
61
|
|
61
|
-
assert_existence :customer, params[:customer], customers[params[:customer]]
|
62
|
+
assert_existence :customer, params[:customer], customers[stripe_account][params[:customer]]
|
62
63
|
|
63
64
|
payment_method = assert_existence :payment_method, id, payment_methods[id]
|
64
65
|
payment_methods[id] = Util.rmerge(payment_method, params.select { |k, _v| allowed_params.include?(k) })
|
@@ -77,7 +78,7 @@ module StripeMock
|
|
77
78
|
|
78
79
|
# post /v1/payment_methods/:id
|
79
80
|
def update_payment_method(route, method_url, params, headers)
|
80
|
-
allowed_params = [:billing_details, :card, :metadata]
|
81
|
+
allowed_params = [:billing_details, :card, :ideal, :sepa_debit, :metadata]
|
81
82
|
|
82
83
|
id = method_url.match(route)[1]
|
83
84
|
|
@@ -86,6 +87,7 @@ module StripeMock
|
|
86
87
|
if payment_method[:customer].nil?
|
87
88
|
raise Stripe::InvalidRequestError.new(
|
88
89
|
'You must save this PaymentMethod to a customer before you can update it.',
|
90
|
+
nil,
|
89
91
|
http_status: 400
|
90
92
|
)
|
91
93
|
end
|
@@ -103,14 +105,15 @@ module StripeMock
|
|
103
105
|
|
104
106
|
if invalid_type?(params[:type])
|
105
107
|
raise Stripe::InvalidRequestError.new(
|
106
|
-
'Invalid type: must be one of card or
|
108
|
+
'Invalid type: must be one of card, ideal or sepa_debit',
|
109
|
+
nil,
|
107
110
|
http_status: 400
|
108
111
|
)
|
109
112
|
end
|
110
113
|
end
|
111
114
|
|
112
115
|
def invalid_type?(type)
|
113
|
-
|
116
|
+
!%w(card ideal sepa_debit).include?(type)
|
114
117
|
end
|
115
118
|
end
|
116
119
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module Prices
|
4
|
+
|
5
|
+
def Prices.included(klass)
|
6
|
+
klass.add_handler 'post /v1/prices', :new_price
|
7
|
+
klass.add_handler 'post /v1/prices/(.*)', :update_price
|
8
|
+
klass.add_handler 'get /v1/prices/(.*)', :get_price
|
9
|
+
klass.add_handler 'get /v1/prices', :list_prices
|
10
|
+
end
|
11
|
+
|
12
|
+
def new_price(route, method_url, params, headers)
|
13
|
+
params[:id] ||= new_id('price')
|
14
|
+
validate_create_price_params(params)
|
15
|
+
prices[ params[:id] ] = Data.mock_price(params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_price(route, method_url, params, headers)
|
19
|
+
route =~ method_url
|
20
|
+
assert_existence :price, $1, prices[$1]
|
21
|
+
prices[$1].merge!(params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_price(route, method_url, params, headers)
|
25
|
+
route =~ method_url
|
26
|
+
assert_existence :price, $1, prices[$1]
|
27
|
+
end
|
28
|
+
|
29
|
+
def list_prices(route, method_url, params, headers)
|
30
|
+
limit = params[:limit] ? params[:limit] : 10
|
31
|
+
price_data = prices.values
|
32
|
+
validate_list_prices_params(params)
|
33
|
+
|
34
|
+
if params.key?(:lookup_keys)
|
35
|
+
price_data.select! do |price|
|
36
|
+
params[:lookup_keys].include?(price[:lookup_key])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Data.mock_list_object(price_data.first(limit), params.merge!(limit: limit))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -12,30 +12,35 @@ module StripeMock
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def create_source(route, method_url, params, headers)
|
15
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
15
16
|
route =~ method_url
|
16
|
-
add_source_to(:customer, $1, params, customers)
|
17
|
+
add_source_to(:customer, $1, params, customers[stripe_account])
|
17
18
|
end
|
18
19
|
|
19
20
|
def retrieve_sources(route, method_url, params, headers)
|
21
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
20
22
|
route =~ method_url
|
21
|
-
retrieve_object_cards(:customer, $1, customers)
|
23
|
+
retrieve_object_cards(:customer, $1, customers[stripe_account])
|
22
24
|
end
|
23
25
|
|
24
26
|
def retrieve_source(route, method_url, params, headers)
|
27
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
25
28
|
route =~ method_url
|
26
|
-
customer = assert_existence :customer, $1, customers[$1]
|
29
|
+
customer = assert_existence :customer, $1, customers[stripe_account][$1]
|
27
30
|
|
28
31
|
assert_existence :card, $2, get_card(customer, $2)
|
29
32
|
end
|
30
33
|
|
31
34
|
def delete_source(route, method_url, params, headers)
|
35
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
32
36
|
route =~ method_url
|
33
|
-
delete_card_from(:customer, $1, $2, customers)
|
37
|
+
delete_card_from(:customer, $1, $2, customers[stripe_account])
|
34
38
|
end
|
35
39
|
|
36
40
|
def update_source(route, method_url, params, headers)
|
41
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
37
42
|
route =~ method_url
|
38
|
-
customer = assert_existence :customer, $1, customers[$1]
|
43
|
+
customer = assert_existence :customer, $1, customers[stripe_account][$1]
|
39
44
|
|
40
45
|
card = assert_existence :card, $2, get_card(customer, $2)
|
41
46
|
card.merge!(params)
|
@@ -43,8 +48,9 @@ module StripeMock
|
|
43
48
|
end
|
44
49
|
|
45
50
|
def verify_source(route, method_url, params, headers)
|
51
|
+
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
|
46
52
|
route =~ method_url
|
47
|
-
customer = assert_existence :customer, $1, customers[$1]
|
53
|
+
customer = assert_existence :customer, $1, customers[stripe_account][$1]
|
48
54
|
|
49
55
|
bank_account = assert_existence :bank_account, $2, verify_bank_account(customer, $2)
|
50
56
|
bank_account
|