epopia-stripe-ruby-mock 2.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env +2 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.travis.yml +28 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +413 -0
- data/Rakefile +14 -0
- data/bin/stripe-mock-server +19 -0
- data/lib/stripe_mock.rb +95 -0
- data/lib/stripe_mock/api/account_balance.rb +14 -0
- data/lib/stripe_mock/api/bank_tokens.rb +13 -0
- data/lib/stripe_mock/api/card_tokens.rb +13 -0
- data/lib/stripe_mock/api/client.rb +41 -0
- data/lib/stripe_mock/api/conversion_rate.rb +14 -0
- data/lib/stripe_mock/api/debug.rb +11 -0
- data/lib/stripe_mock/api/errors.rb +65 -0
- data/lib/stripe_mock/api/global_id_prefix.rb +22 -0
- data/lib/stripe_mock/api/instance.rb +38 -0
- data/lib/stripe_mock/api/live.rb +15 -0
- data/lib/stripe_mock/api/server.rb +39 -0
- data/lib/stripe_mock/api/test_helpers.rb +24 -0
- data/lib/stripe_mock/api/webhooks.rb +88 -0
- data/lib/stripe_mock/client.rb +127 -0
- data/lib/stripe_mock/data.rb +1193 -0
- data/lib/stripe_mock/data/list.rb +73 -0
- data/lib/stripe_mock/error_queue.rb +27 -0
- data/lib/stripe_mock/errors/closed_client_connection_error.rb +9 -0
- data/lib/stripe_mock/errors/server_timeout_error.rb +12 -0
- data/lib/stripe_mock/errors/stripe_mock_error.rb +15 -0
- data/lib/stripe_mock/errors/uninitialized_instance_error.rb +9 -0
- data/lib/stripe_mock/errors/unstarted_state_error.rb +9 -0
- data/lib/stripe_mock/errors/unsupported_request_error.rb +4 -0
- data/lib/stripe_mock/instance.rb +237 -0
- data/lib/stripe_mock/request_handlers/accounts.rb +86 -0
- data/lib/stripe_mock/request_handlers/balance.rb +17 -0
- data/lib/stripe_mock/request_handlers/balance_transactions.rb +37 -0
- data/lib/stripe_mock/request_handlers/cards.rb +35 -0
- data/lib/stripe_mock/request_handlers/charges.rb +177 -0
- data/lib/stripe_mock/request_handlers/country_spec.rb +22 -0
- data/lib/stripe_mock/request_handlers/coupons.rb +35 -0
- data/lib/stripe_mock/request_handlers/customers.rb +137 -0
- data/lib/stripe_mock/request_handlers/disputes.rb +35 -0
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +13 -0
- data/lib/stripe_mock/request_handlers/events.rb +21 -0
- data/lib/stripe_mock/request_handlers/external_accounts.rb +55 -0
- data/lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb +14 -0
- data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +127 -0
- data/lib/stripe_mock/request_handlers/helpers/charge_helpers.rb +16 -0
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +17 -0
- data/lib/stripe_mock/request_handlers/helpers/external_account_helpers.rb +49 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +119 -0
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +44 -0
- data/lib/stripe_mock/request_handlers/invoice_items.rb +45 -0
- data/lib/stripe_mock/request_handlers/invoices.rb +177 -0
- data/lib/stripe_mock/request_handlers/orders.rb +80 -0
- data/lib/stripe_mock/request_handlers/payment_intents.rb +203 -0
- data/lib/stripe_mock/request_handlers/payment_methods.rb +112 -0
- data/lib/stripe_mock/request_handlers/payouts.rb +32 -0
- data/lib/stripe_mock/request_handlers/plans.rb +42 -0
- data/lib/stripe_mock/request_handlers/products.rb +43 -0
- data/lib/stripe_mock/request_handlers/recipients.rb +60 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +91 -0
- data/lib/stripe_mock/request_handlers/sources.rb +55 -0
- data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +296 -0
- data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
- data/lib/stripe_mock/request_handlers/tokens.rb +75 -0
- data/lib/stripe_mock/request_handlers/transfers.rb +65 -0
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +32 -0
- data/lib/stripe_mock/server.rb +93 -0
- data/lib/stripe_mock/test_strategies/base.rb +81 -0
- data/lib/stripe_mock/test_strategies/live.rb +40 -0
- data/lib/stripe_mock/test_strategies/mock.rb +27 -0
- data/lib/stripe_mock/util.rb +44 -0
- data/lib/stripe_mock/version.rb +4 -0
- data/lib/stripe_mock/webhook_fixtures/account.application.deauthorized.json +12 -0
- 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/webhook_fixtures/account.updated.json +26 -0
- data/lib/stripe_mock/webhook_fixtures/balance.available.json +25 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.closed.json +22 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +22 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.updated.json +25 -0
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +56 -0
- data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +69 -0
- data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +55 -0
- data/lib/stripe_mock/webhook_fixtures/charge.updated.json +58 -0
- data/lib/stripe_mock/webhook_fixtures/coupon.created.json +23 -0
- data/lib/stripe_mock/webhook_fixtures/coupon.deleted.json +23 -0
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +54 -0
- data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/customer.discount.created.json +28 -0
- data/lib/stripe_mock/webhook_fixtures/customer.discount.deleted.json +28 -0
- data/lib/stripe_mock/webhook_fixtures/customer.discount.updated.json +43 -0
- data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +32 -0
- data/lib/stripe_mock/webhook_fixtures/customer.source.deleted.json +32 -0
- data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -0
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +66 -0
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +65 -0
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json +65 -0
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +78 -0
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +57 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +71 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +105 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +112 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +74 -0
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +21 -0
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.deleted.json +21 -0
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +24 -0
- data/lib/stripe_mock/webhook_fixtures/plan.created.json +20 -0
- data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +20 -0
- data/lib/stripe_mock/webhook_fixtures/plan.updated.json +23 -0
- data/lib/stripe_mock/webhook_fixtures/transfer.created.json +89 -0
- data/lib/stripe_mock/webhook_fixtures/transfer.failed.json +89 -0
- data/lib/stripe_mock/webhook_fixtures/transfer.paid.json +89 -0
- data/lib/stripe_mock/webhook_fixtures/transfer.updated.json +92 -0
- data/lib/trollop.rb +782 -0
- data/spec/_dummy/webhooks/dummy.event.json +6 -0
- data/spec/api/instance_spec.rb +30 -0
- data/spec/fixtures/create_refund.yml +126 -0
- data/spec/fixtures/stripe_webhooks/account.updated.json +7 -0
- data/spec/fixtures/stripe_webhooks/custom.account.updated.json +5 -0
- data/spec/instance_spec.rb +100 -0
- data/spec/integration_examples/charge_token_examples.rb +51 -0
- data/spec/integration_examples/customer_card_examples.rb +42 -0
- data/spec/integration_examples/prepare_error_examples.rb +38 -0
- data/spec/list_spec.rb +140 -0
- data/spec/readme_spec.rb +75 -0
- data/spec/server_spec.rb +139 -0
- data/spec/shared_stripe_examples/account_examples.rb +96 -0
- data/spec/shared_stripe_examples/balance_examples.rb +11 -0
- data/spec/shared_stripe_examples/balance_transaction_examples.rb +63 -0
- data/spec/shared_stripe_examples/bank_examples.rb +229 -0
- data/spec/shared_stripe_examples/bank_token_examples.rb +59 -0
- data/spec/shared_stripe_examples/card_examples.rb +307 -0
- data/spec/shared_stripe_examples/card_token_examples.rb +185 -0
- data/spec/shared_stripe_examples/charge_examples.rb +510 -0
- data/spec/shared_stripe_examples/country_specs_examples.rb +18 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +85 -0
- data/spec/shared_stripe_examples/customer_examples.rb +453 -0
- data/spec/shared_stripe_examples/dispute_examples.rb +98 -0
- data/spec/shared_stripe_examples/ephemeral_key_examples.rb +17 -0
- data/spec/shared_stripe_examples/error_mock_examples.rb +162 -0
- data/spec/shared_stripe_examples/external_account_examples.rb +170 -0
- data/spec/shared_stripe_examples/extra_features_examples.rb +36 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +524 -0
- data/spec/shared_stripe_examples/invoice_item_examples.rb +69 -0
- data/spec/shared_stripe_examples/payment_intent_examples.rb +131 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +175 -0
- data/spec/shared_stripe_examples/payout_examples.rb +68 -0
- data/spec/shared_stripe_examples/plan_examples.rb +194 -0
- data/spec/shared_stripe_examples/product_example.rb +65 -0
- data/spec/shared_stripe_examples/recipient_examples.rb +118 -0
- data/spec/shared_stripe_examples/refund_examples.rb +472 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +1148 -0
- data/spec/shared_stripe_examples/subscription_items_examples.rb +75 -0
- data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
- data/spec/shared_stripe_examples/transfer_examples.rb +130 -0
- data/spec/shared_stripe_examples/validation_examples.rb +19 -0
- data/spec/shared_stripe_examples/webhook_event_examples.rb +261 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/stripe_mock_spec.rb +123 -0
- data/spec/support/stripe_examples.rb +42 -0
- data/spec/util_spec.rb +121 -0
- data/stripe-ruby-mock.gemspec +27 -0
- metadata +344 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
module StripeMock
|
2
|
+
|
3
|
+
def self.mock_webhook_payload(type, params = {})
|
4
|
+
|
5
|
+
fixture_file = File.join(@webhook_fixture_path, "#{type}.json")
|
6
|
+
|
7
|
+
unless File.exists?(fixture_file)
|
8
|
+
unless Webhooks.event_list.include?(type)
|
9
|
+
raise UnsupportedRequestError.new "Unsupported webhook event `#{type}` (Searched in #{@webhook_fixture_path})"
|
10
|
+
end
|
11
|
+
fixture_file = File.join(@webhook_fixture_fallback_path, "#{type}.json")
|
12
|
+
end
|
13
|
+
|
14
|
+
json = MultiJson.load File.read(fixture_file)
|
15
|
+
|
16
|
+
json = Stripe::Util.symbolize_names(json)
|
17
|
+
params = Stripe::Util.symbolize_names(params)
|
18
|
+
json[:account] = params.delete(:account) if params.key?(:account)
|
19
|
+
json[:data][:object] = Util.rmerge(json[:data][:object], params)
|
20
|
+
json.delete(:id)
|
21
|
+
json[:created] = params[:created] || Time.now.to_i
|
22
|
+
|
23
|
+
if @state == 'local'
|
24
|
+
event_data = instance.generate_webhook_event(json)
|
25
|
+
elsif @state == 'remote'
|
26
|
+
event_data = client.generate_webhook_event(json)
|
27
|
+
else
|
28
|
+
raise UnstartedStateError
|
29
|
+
end
|
30
|
+
event_data
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.mock_webhook_event(type, params={})
|
34
|
+
Stripe::Event.construct_from(mock_webhook_payload(type, params))
|
35
|
+
end
|
36
|
+
|
37
|
+
module Webhooks
|
38
|
+
def self.event_list
|
39
|
+
@__list = [
|
40
|
+
'account.updated',
|
41
|
+
'account.application.deauthorized',
|
42
|
+
'account.external_account.created',
|
43
|
+
'account.external_account.updated',
|
44
|
+
'account.external_account.deleted',
|
45
|
+
'balance.available',
|
46
|
+
'charge.succeeded',
|
47
|
+
'charge.updated',
|
48
|
+
'charge.failed',
|
49
|
+
'charge.refunded',
|
50
|
+
'charge.dispute.created',
|
51
|
+
'charge.dispute.updated',
|
52
|
+
'charge.dispute.closed',
|
53
|
+
'charge.dispute.funds_reinstated',
|
54
|
+
'charge.dispute.funds_withdrawn',
|
55
|
+
'customer.source.created',
|
56
|
+
'customer.source.deleted',
|
57
|
+
'customer.source.updated',
|
58
|
+
'customer.created',
|
59
|
+
'customer.updated',
|
60
|
+
'customer.deleted',
|
61
|
+
'customer.subscription.created',
|
62
|
+
'customer.subscription.updated',
|
63
|
+
'customer.subscription.deleted',
|
64
|
+
'customer.subscription.trial_will_end',
|
65
|
+
'customer.discount.created',
|
66
|
+
'customer.discount.updated',
|
67
|
+
'customer.discount.deleted',
|
68
|
+
'invoice.created',
|
69
|
+
'invoice.updated',
|
70
|
+
'invoice.payment_succeeded',
|
71
|
+
'invoice.payment_failed',
|
72
|
+
'invoiceitem.created',
|
73
|
+
'invoiceitem.updated',
|
74
|
+
'invoiceitem.deleted',
|
75
|
+
'plan.created',
|
76
|
+
'plan.updated',
|
77
|
+
'plan.deleted',
|
78
|
+
'coupon.created',
|
79
|
+
'coupon.deleted',
|
80
|
+
'transfer.created',
|
81
|
+
'transfer.paid',
|
82
|
+
'transfer.updated',
|
83
|
+
'transfer.failed'
|
84
|
+
]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module StripeMock
|
2
|
+
class Client
|
3
|
+
attr_reader :port, :state
|
4
|
+
|
5
|
+
def initialize(port)
|
6
|
+
@port = port
|
7
|
+
|
8
|
+
DRb.start_service
|
9
|
+
@pipe = DRbObject.new_with_uri "druby://localhost:#{port}"
|
10
|
+
|
11
|
+
# Ensure client can connect to server
|
12
|
+
timeout_wrap(5) { @pipe.ping }
|
13
|
+
@state = 'ready'
|
14
|
+
end
|
15
|
+
|
16
|
+
def mock_request(method, url, api_key: nil, params: {}, headers: {})
|
17
|
+
timeout_wrap do
|
18
|
+
@pipe.mock_request(method, url, api_key: api_key, params: params, headers: headers).tap {|result|
|
19
|
+
response, api_key = result
|
20
|
+
if response.is_a?(Hash) && response[:error_raised] == 'invalid_request'
|
21
|
+
raise Stripe::InvalidRequestError.new(*response[:error_params])
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_server_data(key)
|
28
|
+
timeout_wrap {
|
29
|
+
# Massage the data make this behave the same as the local StripeMock.start
|
30
|
+
result = {}
|
31
|
+
@pipe.get_data(key).each {|k,v| result[k] = Stripe::Util.symbolize_names(v) }
|
32
|
+
result
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def error_queue
|
37
|
+
timeout_wrap { @pipe.error_queue }
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_server_debug(toggle)
|
41
|
+
timeout_wrap { @pipe.set_debug(toggle) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def server_debug?
|
45
|
+
timeout_wrap { @pipe.debug? }
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_server_global_id_prefix(value)
|
49
|
+
timeout_wrap { @pipe.set_global_id_prefix(value) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def server_global_id_prefix
|
53
|
+
timeout_wrap { @pipe.global_id_prefix }
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_bank_token(recipient_params)
|
57
|
+
timeout_wrap { @pipe.generate_bank_token(recipient_params) }
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_card_token(card_params)
|
61
|
+
timeout_wrap { @pipe.generate_card_token(card_params) }
|
62
|
+
end
|
63
|
+
|
64
|
+
def generate_webhook_event(event_data)
|
65
|
+
timeout_wrap { Stripe::Util.symbolize_names @pipe.generate_webhook_event(event_data) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_conversion_rate
|
69
|
+
timeout_wrap { @pipe.get_data(:conversion_rate) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_conversion_rate(value)
|
73
|
+
timeout_wrap { @pipe.set_conversion_rate(value) }
|
74
|
+
end
|
75
|
+
|
76
|
+
def set_account_balance(value)
|
77
|
+
timeout_wrap { @pipe.set_account_balance(value) }
|
78
|
+
end
|
79
|
+
|
80
|
+
def destroy_resource(type, id)
|
81
|
+
timeout_wrap { @pipe.destroy_resource(type, id) }
|
82
|
+
end
|
83
|
+
|
84
|
+
def clear_server_data
|
85
|
+
timeout_wrap { @pipe.clear_data }
|
86
|
+
end
|
87
|
+
|
88
|
+
def upsert_stripe_object(object, attributes)
|
89
|
+
timeout_wrap { @pipe.upsert_stripe_object(object, attributes) }
|
90
|
+
end
|
91
|
+
|
92
|
+
def close!
|
93
|
+
self.cleanup
|
94
|
+
StripeMock.stop_client(:clear_server_data => false)
|
95
|
+
end
|
96
|
+
|
97
|
+
def cleanup
|
98
|
+
return if @state == 'closed'
|
99
|
+
set_server_debug(false)
|
100
|
+
@state = 'closed'
|
101
|
+
end
|
102
|
+
|
103
|
+
def timeout_wrap(tries=1)
|
104
|
+
original_tries = tries
|
105
|
+
begin
|
106
|
+
raise ClosedClientConnectionError if @state == 'closed'
|
107
|
+
yield
|
108
|
+
rescue ClosedClientConnectionError
|
109
|
+
raise
|
110
|
+
rescue Errno::ECONNREFUSED, DRb::DRbConnError => e
|
111
|
+
tries -= 1
|
112
|
+
if tries > 0
|
113
|
+
if tries == original_tries - 1
|
114
|
+
print "Waiting for StripeMock Server.."
|
115
|
+
else
|
116
|
+
print '.'
|
117
|
+
end
|
118
|
+
sleep 1
|
119
|
+
retry
|
120
|
+
else
|
121
|
+
raise StripeMock::ServerTimeoutError.new(e)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
@@ -0,0 +1,1193 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module Data
|
3
|
+
|
4
|
+
def self.mock_account(params = {})
|
5
|
+
id = params[:id] || 'acct_103ED82ePvKYlo2C'
|
6
|
+
currency = params[:currency] || StripeMock.default_currency
|
7
|
+
{
|
8
|
+
id: id,
|
9
|
+
email: "bob@example.com",
|
10
|
+
statement_descriptor: nil,
|
11
|
+
display_name: "Stripe.com",
|
12
|
+
timezone: "US/Pacific",
|
13
|
+
details_submitted: false,
|
14
|
+
charges_enabled: false,
|
15
|
+
payouts_enabled: false,
|
16
|
+
currencies_supported: [
|
17
|
+
"usd"
|
18
|
+
],
|
19
|
+
default_currency: currency,
|
20
|
+
country: "US",
|
21
|
+
object: "account",
|
22
|
+
business_name: "Stripe.com",
|
23
|
+
business_url: nil,
|
24
|
+
support_phone: nil,
|
25
|
+
managed: false,
|
26
|
+
product_description: nil,
|
27
|
+
debit_negative_balances: true,
|
28
|
+
bank_accounts: {
|
29
|
+
object: "list",
|
30
|
+
total_count: 0,
|
31
|
+
has_more: false,
|
32
|
+
url: "/v1/accounts/#{id}/bank_accounts",
|
33
|
+
data: [
|
34
|
+
|
35
|
+
]
|
36
|
+
},
|
37
|
+
verification: {
|
38
|
+
fields_needed: [],
|
39
|
+
due_by: nil,
|
40
|
+
contacted: false
|
41
|
+
},
|
42
|
+
transfer_schedule: {
|
43
|
+
delay_days: 7,
|
44
|
+
interval: "daily"
|
45
|
+
},
|
46
|
+
tos_acceptance: {
|
47
|
+
ip: nil,
|
48
|
+
date: nil,
|
49
|
+
user_agent: nil
|
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
|
+
},
|
60
|
+
legal_entity: {
|
61
|
+
type: nil,
|
62
|
+
business_name: nil,
|
63
|
+
address: {
|
64
|
+
line1: nil,
|
65
|
+
line2: nil,
|
66
|
+
city: nil,
|
67
|
+
state: nil,
|
68
|
+
postal_code: nil,
|
69
|
+
country: "US"
|
70
|
+
},
|
71
|
+
first_name: nil,
|
72
|
+
last_name: nil,
|
73
|
+
personal_address: {
|
74
|
+
line1: nil,
|
75
|
+
line2: nil,
|
76
|
+
city: nil,
|
77
|
+
state: nil,
|
78
|
+
postal_code: nil,
|
79
|
+
country: nil
|
80
|
+
},
|
81
|
+
dob: {
|
82
|
+
day: nil,
|
83
|
+
month: nil,
|
84
|
+
year: nil
|
85
|
+
},
|
86
|
+
additional_owners: nil,
|
87
|
+
verification: {
|
88
|
+
status: "unverified",
|
89
|
+
document: nil,
|
90
|
+
details: nil
|
91
|
+
}
|
92
|
+
},
|
93
|
+
decline_charge_on: {
|
94
|
+
cvc_failure: false,
|
95
|
+
avs_failure: false
|
96
|
+
},
|
97
|
+
keys: {
|
98
|
+
secret: "sk_test_AmJhMTLPtY9JL4c6EG0",
|
99
|
+
publishable: "pk_test_2rSaMTLPtY9JL449dsf"
|
100
|
+
}
|
101
|
+
}.merge(params)
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.mock_tax_rate(params)
|
105
|
+
{
|
106
|
+
id: 'test_cus_default',
|
107
|
+
object: 'tax_rate',
|
108
|
+
active: true,
|
109
|
+
created: 1559079603,
|
110
|
+
description: nil,
|
111
|
+
display_name: 'VAT',
|
112
|
+
inclusive: false,
|
113
|
+
jurisdiction: 'EU',
|
114
|
+
livemode: false,
|
115
|
+
metadata: {},
|
116
|
+
percentage: 21.0
|
117
|
+
}.merge(params)
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.mock_customer(sources, params)
|
121
|
+
cus_id = params[:id] || "test_cus_default"
|
122
|
+
currency = params[:currency] || StripeMock.default_currency
|
123
|
+
invoice_prefix = SecureRandom.hex(4).upcase
|
124
|
+
sources.each {|source| source[:customer] = cus_id}
|
125
|
+
{
|
126
|
+
email: 'stripe_mock@example.com',
|
127
|
+
description: 'an auto-generated stripe customer data mock',
|
128
|
+
object: "customer",
|
129
|
+
created: 1372126710,
|
130
|
+
id: cus_id,
|
131
|
+
invoice_prefix: invoice_prefix,
|
132
|
+
invoice_settings: {
|
133
|
+
custom_fields: nil,
|
134
|
+
default_payment_method: nil,
|
135
|
+
footer: nil
|
136
|
+
},
|
137
|
+
name: nil,
|
138
|
+
livemode: false,
|
139
|
+
delinquent: false,
|
140
|
+
discount: nil,
|
141
|
+
account_balance: 0,
|
142
|
+
currency: currency,
|
143
|
+
sources: {
|
144
|
+
object: "list",
|
145
|
+
total_count: sources.size,
|
146
|
+
url: "/v1/customers/#{cus_id}/sources",
|
147
|
+
data: sources
|
148
|
+
},
|
149
|
+
subscriptions: {
|
150
|
+
object: "list",
|
151
|
+
total_count: 0,
|
152
|
+
url: "/v1/customers/#{cus_id}/subscriptions",
|
153
|
+
data: []
|
154
|
+
},
|
155
|
+
default_source: nil
|
156
|
+
}.merge(params)
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.mock_charge(params={})
|
160
|
+
charge_id = params[:id] || "ch_1fD6uiR9FAA2zc"
|
161
|
+
currency = params[:currency] || StripeMock.default_currency
|
162
|
+
{
|
163
|
+
id: charge_id,
|
164
|
+
object: "charge",
|
165
|
+
created: 1366194027,
|
166
|
+
livemode: false,
|
167
|
+
paid: true,
|
168
|
+
amount: 0,
|
169
|
+
application_fee: nil,
|
170
|
+
currency: currency,
|
171
|
+
destination: nil,
|
172
|
+
fraud_details: {},
|
173
|
+
receipt_email: nil,
|
174
|
+
receipt_number: nil,
|
175
|
+
refunded: false,
|
176
|
+
shipping: {},
|
177
|
+
statement_descriptor: "Charge #{charge_id}",
|
178
|
+
status: 'succeeded',
|
179
|
+
source: {
|
180
|
+
object: "card",
|
181
|
+
last4: "4242",
|
182
|
+
type: "Visa",
|
183
|
+
brand: "Visa",
|
184
|
+
funding: "credit",
|
185
|
+
exp_month: 12,
|
186
|
+
exp_year: 2013,
|
187
|
+
fingerprint: "3TQGpK9JoY1GgXPw",
|
188
|
+
country: "US",
|
189
|
+
name: "name",
|
190
|
+
address_line1: nil,
|
191
|
+
address_line2: nil,
|
192
|
+
address_city: nil,
|
193
|
+
address_state: nil,
|
194
|
+
address_zip: nil,
|
195
|
+
address_country: nil,
|
196
|
+
cvc_check: nil,
|
197
|
+
address_line1_check: nil,
|
198
|
+
address_zip_check: nil
|
199
|
+
},
|
200
|
+
captured: params.has_key?(:capture) ? params.delete(:capture) : true,
|
201
|
+
refunds: {
|
202
|
+
object: "list",
|
203
|
+
total_count: 0,
|
204
|
+
has_more: false,
|
205
|
+
url: "/v1/charges/#{charge_id}/refunds",
|
206
|
+
data: []
|
207
|
+
},
|
208
|
+
transfer: nil,
|
209
|
+
balance_transaction: "txn_2dyYXXP90MN26R",
|
210
|
+
failure_message: nil,
|
211
|
+
failure_code: nil,
|
212
|
+
amount_refunded: 0,
|
213
|
+
customer: nil,
|
214
|
+
invoice: nil,
|
215
|
+
description: nil,
|
216
|
+
dispute: nil,
|
217
|
+
metadata: {
|
218
|
+
}
|
219
|
+
}.merge(params)
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.mock_refund(params={})
|
223
|
+
currency = params[:currency] || StripeMock.default_currency
|
224
|
+
{
|
225
|
+
id: "re_4fWhgUh5si7InF",
|
226
|
+
amount: 1,
|
227
|
+
currency: currency,
|
228
|
+
created: 1409165988,
|
229
|
+
object: "refund",
|
230
|
+
balance_transaction: "txn_4fWh2RKvgxcXqV",
|
231
|
+
metadata: {},
|
232
|
+
charge: "ch_4fWhYjzQ23UFWT",
|
233
|
+
receipt_number: nil,
|
234
|
+
status: "succeeded",
|
235
|
+
reason: "requested_by_customer"
|
236
|
+
}.merge(params)
|
237
|
+
end
|
238
|
+
|
239
|
+
def self.mock_charge_array
|
240
|
+
{
|
241
|
+
:data => [test_charge, test_charge, test_charge],
|
242
|
+
:object => 'list',
|
243
|
+
:url => '/v1/charges'
|
244
|
+
}
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.mock_card(params={})
|
248
|
+
StripeMock::Util.card_merge({
|
249
|
+
id: "test_cc_default",
|
250
|
+
object: "card",
|
251
|
+
last4: "4242",
|
252
|
+
type: "Visa",
|
253
|
+
brand: "Visa",
|
254
|
+
funding: "credit",
|
255
|
+
exp_month: 4,
|
256
|
+
exp_year: 2016,
|
257
|
+
fingerprint: "wXWJT135mEK107G8",
|
258
|
+
customer: "test_cus_default",
|
259
|
+
country: "US",
|
260
|
+
name: "Johnny App",
|
261
|
+
address_line1: nil,
|
262
|
+
address_line2: nil,
|
263
|
+
address_city: nil,
|
264
|
+
address_state: nil,
|
265
|
+
address_zip: nil,
|
266
|
+
address_country: nil,
|
267
|
+
cvc_check: nil,
|
268
|
+
address_line1_check: nil,
|
269
|
+
address_zip_check: nil,
|
270
|
+
tokenization_method: nil,
|
271
|
+
metadata: {}
|
272
|
+
}, params)
|
273
|
+
end
|
274
|
+
|
275
|
+
def self.mock_bank_account(params={})
|
276
|
+
currency = params[:currency] || StripeMock.default_currency
|
277
|
+
{
|
278
|
+
id: "test_ba_default",
|
279
|
+
object: "bank_account",
|
280
|
+
bank_name: "STRIPEMOCK TEST BANK",
|
281
|
+
last4: "6789",
|
282
|
+
routing_number: '110000000',
|
283
|
+
country: "US",
|
284
|
+
currency: currency,
|
285
|
+
validated: false,
|
286
|
+
status: 'new',
|
287
|
+
account_holder_name: 'John Doe',
|
288
|
+
account_holder_type: 'individual',
|
289
|
+
fingerprint: "aBcFinGerPrINt123",
|
290
|
+
metadata: {}
|
291
|
+
}.merge(params)
|
292
|
+
end
|
293
|
+
|
294
|
+
def self.mock_coupon(params={})
|
295
|
+
{
|
296
|
+
:duration_in_months => 3,
|
297
|
+
:percent_off => 25,
|
298
|
+
:amount_off => nil,
|
299
|
+
:currency => nil,
|
300
|
+
:id => "co_test_coupon",
|
301
|
+
:object => "coupon",
|
302
|
+
:max_redemptions => nil,
|
303
|
+
:redeem_by => nil,
|
304
|
+
:times_redeemed => 0,
|
305
|
+
:valid => true,
|
306
|
+
:metadata => {},
|
307
|
+
}.merge(params)
|
308
|
+
end
|
309
|
+
|
310
|
+
#FIXME nested overrides would be better than hardcoding plan_id
|
311
|
+
def self.mock_subscription(params={})
|
312
|
+
StripeMock::Util.rmerge({
|
313
|
+
created: 1478204116,
|
314
|
+
billing: 'charge_automatically',
|
315
|
+
current_period_start: 1308595038,
|
316
|
+
current_period_end: 1308681468,
|
317
|
+
status: 'trialing',
|
318
|
+
trial_from_plan: false,
|
319
|
+
plan: {
|
320
|
+
interval: 'month',
|
321
|
+
amount: 7500,
|
322
|
+
trial_period_days: 30,
|
323
|
+
object: 'plan',
|
324
|
+
id: '__test_plan_id__'
|
325
|
+
},
|
326
|
+
items: {
|
327
|
+
object: 'list',
|
328
|
+
data: [{
|
329
|
+
id: 'si_1AwFf62eZvKYlo2C9u6Dhf9',
|
330
|
+
created: 1504035973,
|
331
|
+
metadata: {},
|
332
|
+
object: 'subscription_item',
|
333
|
+
plan: {
|
334
|
+
amount: 999,
|
335
|
+
created: 1504035972,
|
336
|
+
currency: StripeMock.default_currency
|
337
|
+
},
|
338
|
+
quantity: 1
|
339
|
+
}]
|
340
|
+
},
|
341
|
+
cancel_at_period_end: false,
|
342
|
+
canceled_at: nil,
|
343
|
+
ended_at: nil,
|
344
|
+
start: 1308595038,
|
345
|
+
object: 'subscription',
|
346
|
+
trial_start: 1308595038,
|
347
|
+
trial_end: 1308681468,
|
348
|
+
customer: 'c_test_customer',
|
349
|
+
quantity: 1,
|
350
|
+
tax_percent: nil,
|
351
|
+
discount: nil,
|
352
|
+
metadata: {}
|
353
|
+
}, params)
|
354
|
+
end
|
355
|
+
|
356
|
+
def self.mock_invoice(lines, params={})
|
357
|
+
in_id = params[:id] || "test_in_default"
|
358
|
+
currency = params[:currency] || StripeMock.default_currency
|
359
|
+
lines << Data.mock_line_item() if lines.empty?
|
360
|
+
invoice = {
|
361
|
+
id: 'in_test_invoice',
|
362
|
+
status: 'open',
|
363
|
+
invoice_pdf: 'pdf_url',
|
364
|
+
hosted_invoice_url: 'hosted_invoice_url',
|
365
|
+
created: 1349738950,
|
366
|
+
period_end: 1349738950,
|
367
|
+
period_start: 1349738950,
|
368
|
+
lines: {
|
369
|
+
object: "list",
|
370
|
+
total_count: lines.count,
|
371
|
+
url: "/v1/invoices/#{in_id}/lines",
|
372
|
+
data: lines
|
373
|
+
},
|
374
|
+
subtotal: lines.map {|line| line[:amount]}.reduce(0, :+),
|
375
|
+
customer: "test_customer",
|
376
|
+
object: 'invoice',
|
377
|
+
attempted: false,
|
378
|
+
application_fee: nil,
|
379
|
+
closed: false,
|
380
|
+
description: nil,
|
381
|
+
forgiven: false,
|
382
|
+
metadata: {},
|
383
|
+
paid: false,
|
384
|
+
receipt_number: nil,
|
385
|
+
statement_descriptor: nil,
|
386
|
+
tax: 10,
|
387
|
+
tax_percent: nil,
|
388
|
+
webhooks_delivered_at: 1349825350,
|
389
|
+
livemode: false,
|
390
|
+
attempt_count: 0,
|
391
|
+
amount_due: 100,
|
392
|
+
amount_paid: 0,
|
393
|
+
currency: currency,
|
394
|
+
starting_balance: 0,
|
395
|
+
ending_balance: nil,
|
396
|
+
next_payment_attempt: 1349825350,
|
397
|
+
charge: nil,
|
398
|
+
discount: nil,
|
399
|
+
subscription: nil
|
400
|
+
}.merge(params)
|
401
|
+
if invoice[:discount]
|
402
|
+
invoice[:total] = [0, invoice[:subtotal] - invoice[:discount][:coupon][:amount_off]].max if invoice[:discount][:coupon][:amount_off]
|
403
|
+
invoice[:total] = invoice[:subtotal] * invoice[:discount][:coupon][:percent_off] / 100 if invoice[:discount][:coupon][:percent_off]
|
404
|
+
else
|
405
|
+
invoice[:total] = invoice[:subtotal]
|
406
|
+
end
|
407
|
+
due = invoice[:total] + invoice[:starting_balance]
|
408
|
+
invoice[:amount_due] = due < 0 ? 0 : due
|
409
|
+
invoice
|
410
|
+
end
|
411
|
+
|
412
|
+
def self.mock_line_item(params = {})
|
413
|
+
currency = params[:currency] || StripeMock.default_currency
|
414
|
+
{
|
415
|
+
id: "ii_test",
|
416
|
+
object: "line_item",
|
417
|
+
type: "invoiceitem",
|
418
|
+
livemode: false,
|
419
|
+
amount: 1000,
|
420
|
+
currency: currency,
|
421
|
+
discountable: false,
|
422
|
+
proration: false,
|
423
|
+
period: {
|
424
|
+
start: 1349738920,
|
425
|
+
end: 1349738920
|
426
|
+
},
|
427
|
+
tax_amounts: [
|
428
|
+
{
|
429
|
+
amount: 10
|
430
|
+
}
|
431
|
+
],
|
432
|
+
quantity: nil,
|
433
|
+
subscription: nil,
|
434
|
+
plan: nil,
|
435
|
+
description: "Test invoice item",
|
436
|
+
metadata: {}
|
437
|
+
}.merge(params)
|
438
|
+
end
|
439
|
+
|
440
|
+
def self.mock_invoice_item(params = {})
|
441
|
+
currency = params[:currency] || StripeMock.default_currency
|
442
|
+
{
|
443
|
+
id: "test_ii",
|
444
|
+
object: "invoiceitem",
|
445
|
+
created: 1349738920,
|
446
|
+
amount: 1099,
|
447
|
+
livemode: false,
|
448
|
+
proration: false,
|
449
|
+
currency: currency,
|
450
|
+
customer: "cus_test",
|
451
|
+
description: "invoice item desc",
|
452
|
+
metadata: {},
|
453
|
+
invoice: nil,
|
454
|
+
subscription: nil
|
455
|
+
}.merge(params)
|
456
|
+
end
|
457
|
+
|
458
|
+
def self.mock_paid_invoice
|
459
|
+
test_invoice.merge({
|
460
|
+
:attempt_count => 1,
|
461
|
+
:attempted => true,
|
462
|
+
:closed => true,
|
463
|
+
:paid => true,
|
464
|
+
:charge => 'ch_test_charge',
|
465
|
+
:ending_balance => 0,
|
466
|
+
:next_payment_attempt => nil,
|
467
|
+
})
|
468
|
+
end
|
469
|
+
|
470
|
+
def self.mock_invoice_customer_array
|
471
|
+
{
|
472
|
+
:data => [test_invoice],
|
473
|
+
:object => 'list',
|
474
|
+
:url => '/v1/invoices?customer=test_customer'
|
475
|
+
}
|
476
|
+
end
|
477
|
+
|
478
|
+
def self.mock_order(order_items, params)
|
479
|
+
or_id = params[:id] || "test_or_default"
|
480
|
+
currency = params[:currency] || 'eur'
|
481
|
+
order_items << Data.mock_order_item if order_items.empty?
|
482
|
+
{
|
483
|
+
id: or_id,
|
484
|
+
object: "order",
|
485
|
+
amount: 5000,
|
486
|
+
application: nil,
|
487
|
+
application_fee: nil,
|
488
|
+
charge: nil,
|
489
|
+
created: 1448272783,
|
490
|
+
currency: currency,
|
491
|
+
customer: nil,
|
492
|
+
email: nil,
|
493
|
+
items: order_items,
|
494
|
+
livemode: false,
|
495
|
+
metadata: {},
|
496
|
+
selected_shipping_method: nil,
|
497
|
+
shipping: {
|
498
|
+
address: {
|
499
|
+
city: "Anytown",
|
500
|
+
country: "US",
|
501
|
+
line1: "1234 Main street",
|
502
|
+
line2: nil,
|
503
|
+
postal_code: "123456",
|
504
|
+
state: nil
|
505
|
+
},
|
506
|
+
name: "Jenny Rosen",
|
507
|
+
phone: nil
|
508
|
+
},
|
509
|
+
shipping_methods: nil,
|
510
|
+
status: "created",
|
511
|
+
updated: 1448272783
|
512
|
+
}.merge(params)
|
513
|
+
end
|
514
|
+
|
515
|
+
def self.mock_order_item(params={})
|
516
|
+
currency = params[:currency] || 'eur'
|
517
|
+
{
|
518
|
+
object: "order_item",
|
519
|
+
amount: 5000,
|
520
|
+
currency: currency,
|
521
|
+
description: "Anyitem",
|
522
|
+
parent: "sku_parent",
|
523
|
+
quantity: 1,
|
524
|
+
type: "sku"
|
525
|
+
}.merge(params)
|
526
|
+
end
|
527
|
+
|
528
|
+
def self.mock_plan(params={})
|
529
|
+
currency = params[:currency] || StripeMock.default_currency
|
530
|
+
{
|
531
|
+
id: "2",
|
532
|
+
object: "plan",
|
533
|
+
amount: 2300,
|
534
|
+
created: 1466698898,
|
535
|
+
currency: currency,
|
536
|
+
interval: "month",
|
537
|
+
interval_count: 1,
|
538
|
+
livemode: false,
|
539
|
+
metadata: {},
|
540
|
+
name: "The Basic Plan",
|
541
|
+
statement_descriptor: nil,
|
542
|
+
trial_period_days: nil
|
543
|
+
}.merge(params)
|
544
|
+
end
|
545
|
+
|
546
|
+
def self.mock_product(params = {})
|
547
|
+
{
|
548
|
+
id: "default_test_prod",
|
549
|
+
object: "product",
|
550
|
+
active: true,
|
551
|
+
created: 1556896214,
|
552
|
+
livemode: false,
|
553
|
+
metadata: {},
|
554
|
+
name: "Default Test Product",
|
555
|
+
statement_descriptor: "PRODUCT",
|
556
|
+
type: "service",
|
557
|
+
updated: 1556918200,
|
558
|
+
}.merge(params)
|
559
|
+
end
|
560
|
+
|
561
|
+
def self.mock_recipient(cards, params={})
|
562
|
+
rp_id = params[:id] || "test_rp_default"
|
563
|
+
cards.each {|card| card[:recipient] = rp_id}
|
564
|
+
{
|
565
|
+
name: "Stripe User",
|
566
|
+
type: "individual",
|
567
|
+
livemode: false,
|
568
|
+
object: "recipient",
|
569
|
+
id: rp_id,
|
570
|
+
active_account: {
|
571
|
+
last4: "6789",
|
572
|
+
bank_name: "STRIPE TEST BANK",
|
573
|
+
country: "US",
|
574
|
+
object: "bank_account"
|
575
|
+
},
|
576
|
+
created: 1304114758,
|
577
|
+
verified: true,
|
578
|
+
metadata: {
|
579
|
+
},
|
580
|
+
cards: {
|
581
|
+
object: "list",
|
582
|
+
url: "/v1/recipients/#{rp_id}/cards",
|
583
|
+
data: cards,
|
584
|
+
total_count: cards.count
|
585
|
+
},
|
586
|
+
default_card: nil
|
587
|
+
}.merge(params)
|
588
|
+
end
|
589
|
+
|
590
|
+
def self.mock_recipient_array
|
591
|
+
{
|
592
|
+
:data => [test_recipient, test_recipient, test_recipient],
|
593
|
+
:object => 'list',
|
594
|
+
:url => '/v1/recipients'
|
595
|
+
}
|
596
|
+
end
|
597
|
+
|
598
|
+
def self.mock_card_token(params={})
|
599
|
+
{
|
600
|
+
:id => 'tok_default',
|
601
|
+
:livemode => false,
|
602
|
+
:used => false,
|
603
|
+
:object => 'token',
|
604
|
+
:type => 'card',
|
605
|
+
:card => {
|
606
|
+
:id => 'card_default',
|
607
|
+
:object => 'card',
|
608
|
+
:last4 => '2222',
|
609
|
+
:type => 'Visa',
|
610
|
+
:brand => 'Visa',
|
611
|
+
:funding => 'credit',
|
612
|
+
:exp_month => 9,
|
613
|
+
:exp_year => 2017,
|
614
|
+
:fingerprint => 'JRRLXGh38NiYygM7',
|
615
|
+
:customer => nil,
|
616
|
+
:country => 'US',
|
617
|
+
:name => nil,
|
618
|
+
:address_line1 => nil,
|
619
|
+
:address_line2 => nil,
|
620
|
+
:address_city => nil,
|
621
|
+
:address_state => nil,
|
622
|
+
:address_zip => nil,
|
623
|
+
:address_country => nil
|
624
|
+
}
|
625
|
+
}.merge(params)
|
626
|
+
end
|
627
|
+
|
628
|
+
def self.mock_bank_account_token(params={})
|
629
|
+
{
|
630
|
+
:id => 'tok_default',
|
631
|
+
:livemode => false,
|
632
|
+
:used => false,
|
633
|
+
:object => 'token',
|
634
|
+
:type => 'bank_account',
|
635
|
+
:bank_account => {
|
636
|
+
:id => 'bank_account_default',
|
637
|
+
:object => 'bank_account',
|
638
|
+
:last4 => '2222',
|
639
|
+
:fingerprint => 'JRRLXGh38NiYygM7',
|
640
|
+
}
|
641
|
+
}.merge(params)
|
642
|
+
end
|
643
|
+
|
644
|
+
def self.mock_transfer(params={})
|
645
|
+
currency = params[:currency] || StripeMock.default_currency
|
646
|
+
id = params[:id] || 'tr_test_transfer'
|
647
|
+
{
|
648
|
+
:amount => 100,
|
649
|
+
:amount_reversed => 0,
|
650
|
+
:balance_transaction => "txn_2dyYXXP90MN26R",
|
651
|
+
:id => id,
|
652
|
+
:livemode => false,
|
653
|
+
:metadata => {},
|
654
|
+
:currency => currency,
|
655
|
+
:object => "transfer",
|
656
|
+
:created => 1304114826,
|
657
|
+
:description => "Transfer description",
|
658
|
+
:reversed => false,
|
659
|
+
:reversals => {
|
660
|
+
:object => "list",
|
661
|
+
:data => [],
|
662
|
+
:total_count => 0,
|
663
|
+
:has_more => false,
|
664
|
+
:url => "/v1/transfers/#{id}/reversals"
|
665
|
+
},
|
666
|
+
:destination => "acct_164wxjKbnvuxQXGu",
|
667
|
+
:destination_payment => "py_164xRvKbnvuxQXGuVFV2pZo1",
|
668
|
+
:source_transaction => "ch_164xRv2eZvKYlo2Clu1sIJWB",
|
669
|
+
:source_type => "card",
|
670
|
+
:transfer_group => "group_ch_164xRv2eZvKYlo2Clu1sIJWB",
|
671
|
+
}.merge(params)
|
672
|
+
end
|
673
|
+
|
674
|
+
def self.mock_payout(params={})
|
675
|
+
currency = params[:currency] || StripeMock.default_currency
|
676
|
+
id = params[:id] || 'po_test_payout'
|
677
|
+
{
|
678
|
+
:amount => 100,
|
679
|
+
:id => id,
|
680
|
+
:livemode => false,
|
681
|
+
:metadata => {},
|
682
|
+
:currency => currency,
|
683
|
+
:object => "payout",
|
684
|
+
:date => 1304114826,
|
685
|
+
:description => "Payout description",
|
686
|
+
}.merge(params)
|
687
|
+
end
|
688
|
+
|
689
|
+
def self.mock_disputes(ids=[])
|
690
|
+
disputes = {}
|
691
|
+
ids.each do |id|
|
692
|
+
disputes[id] = self.mock_dispute(id: id)
|
693
|
+
end
|
694
|
+
disputes
|
695
|
+
end
|
696
|
+
|
697
|
+
def self.mock_dispute(params={})
|
698
|
+
@timestamp ||= Time.now.to_i
|
699
|
+
currency = params[:currency] || StripeMock.default_currency
|
700
|
+
id = params[:id] || "dp_test_dispute"
|
701
|
+
{
|
702
|
+
:id => id,
|
703
|
+
:object => "dispute",
|
704
|
+
:amount => 195,
|
705
|
+
:balance_transactions => [],
|
706
|
+
:charge => "ch_15RsQR2eZvKYlo2CA8IfzCX0",
|
707
|
+
:created => @timestamp += 1,
|
708
|
+
:currency => currency,
|
709
|
+
:evidence => self.mock_dispute_evidence,
|
710
|
+
:evidence_details => self.mock_dispute_evidence_details,
|
711
|
+
:is_charge_refundable => false,
|
712
|
+
:livemode => false,
|
713
|
+
:metadata => {},
|
714
|
+
:reason => "general",
|
715
|
+
:status => "under_review"
|
716
|
+
}.merge(params)
|
717
|
+
end
|
718
|
+
|
719
|
+
def self.mock_dispute_evidence
|
720
|
+
{
|
721
|
+
:access_activity_log => nil,
|
722
|
+
:billing_address => nil,
|
723
|
+
:cancellation_policy => nil,
|
724
|
+
:cancellation_policy_disclosure => nil,
|
725
|
+
:cancellation_rebuttal => nil,
|
726
|
+
:customer_communication => nil,
|
727
|
+
:customer_email_address => nil,
|
728
|
+
:customer_name => nil,
|
729
|
+
:customer_purchase_ip => nil,
|
730
|
+
:customer_signature => nil,
|
731
|
+
:duplicate_charge_documentation => nil,
|
732
|
+
:duplicate_charge_explanation => nil,
|
733
|
+
:duplicate_charge_id => nil,
|
734
|
+
:product_description => nil,
|
735
|
+
:receipt => nil,
|
736
|
+
:refund_policy => nil,
|
737
|
+
:refund_policy_disclosure => nil,
|
738
|
+
:refund_refusal_explanation => nil,
|
739
|
+
:service_date => nil,
|
740
|
+
:service_documentation => nil,
|
741
|
+
:shipping_address => nil,
|
742
|
+
:shipping_carrier => nil,
|
743
|
+
:shipping_date => nil,
|
744
|
+
:shipping_documentation => nil,
|
745
|
+
:shipping_tracking_number => nil,
|
746
|
+
:uncategorized_file => nil,
|
747
|
+
:uncategorized_text => nil
|
748
|
+
}
|
749
|
+
end
|
750
|
+
|
751
|
+
def self.mock_dispute_evidence_details
|
752
|
+
{
|
753
|
+
:due_by => 1424303999,
|
754
|
+
:has_evidence => false,
|
755
|
+
:past_due => false,
|
756
|
+
:submission_count => 0
|
757
|
+
}
|
758
|
+
end
|
759
|
+
|
760
|
+
def self.mock_transfer_array
|
761
|
+
{
|
762
|
+
:data => [test_transfer, test_transfer, test_transfer],
|
763
|
+
:object => 'list',
|
764
|
+
:url => '/v1/transfers'
|
765
|
+
}
|
766
|
+
end
|
767
|
+
|
768
|
+
def self.mock_invalid_api_key_error
|
769
|
+
{
|
770
|
+
"error" => {
|
771
|
+
"type" => "invalid_request_error",
|
772
|
+
"message" => "Invalid API Key provided: invalid"
|
773
|
+
}
|
774
|
+
}
|
775
|
+
end
|
776
|
+
|
777
|
+
def self.mock_invalid_exp_year_error
|
778
|
+
{
|
779
|
+
"error" => {
|
780
|
+
"code" => "invalid_expiry_year",
|
781
|
+
"param" => "exp_year",
|
782
|
+
"type" => "card_error",
|
783
|
+
"message" => "Your card's expiration year is invalid"
|
784
|
+
}
|
785
|
+
}
|
786
|
+
end
|
787
|
+
|
788
|
+
def self.mock_missing_id_error
|
789
|
+
{
|
790
|
+
:error => {
|
791
|
+
:param => "id",
|
792
|
+
:type => "invalid_request_error",
|
793
|
+
:message => "Missing id"
|
794
|
+
}
|
795
|
+
}
|
796
|
+
end
|
797
|
+
|
798
|
+
def self.mock_delete_subscription(params={})
|
799
|
+
{
|
800
|
+
deleted: true
|
801
|
+
}.merge(params)
|
802
|
+
end
|
803
|
+
|
804
|
+
def self.mock_api_error
|
805
|
+
{
|
806
|
+
:error => {
|
807
|
+
:type => "api_error"
|
808
|
+
}
|
809
|
+
}
|
810
|
+
end
|
811
|
+
|
812
|
+
def self.mock_delete_discount_response
|
813
|
+
{
|
814
|
+
:deleted => true,
|
815
|
+
:id => "di_test_coupon"
|
816
|
+
}
|
817
|
+
end
|
818
|
+
|
819
|
+
def self.mock_list_object(data, params={})
|
820
|
+
list = StripeMock::Data::List.new(data, params)
|
821
|
+
list.to_h
|
822
|
+
end
|
823
|
+
|
824
|
+
def self.mock_country_spec(country_code)
|
825
|
+
id = country_code || "US"
|
826
|
+
{
|
827
|
+
"id"=> "US",
|
828
|
+
"object"=> "country_spec",
|
829
|
+
"default_currency"=> "usd",
|
830
|
+
"supported_bank_account_currencies"=> {"usd"=>["US"]},
|
831
|
+
"supported_payment_currencies"=> [
|
832
|
+
"usd",
|
833
|
+
"aed",
|
834
|
+
"afn",
|
835
|
+
"all",
|
836
|
+
"amd",
|
837
|
+
"ang",
|
838
|
+
"aoa",
|
839
|
+
"ars",
|
840
|
+
"aud",
|
841
|
+
"awg",
|
842
|
+
"azn",
|
843
|
+
"bam",
|
844
|
+
"bbd",
|
845
|
+
"bdt",
|
846
|
+
"bgn",
|
847
|
+
"bif",
|
848
|
+
"bmd",
|
849
|
+
"bnd",
|
850
|
+
"bob",
|
851
|
+
"brl",
|
852
|
+
"bsd",
|
853
|
+
"bwp",
|
854
|
+
"bzd",
|
855
|
+
"cad",
|
856
|
+
"cdf",
|
857
|
+
"chf",
|
858
|
+
"clp",
|
859
|
+
"cny",
|
860
|
+
"cop",
|
861
|
+
"crc",
|
862
|
+
"cve",
|
863
|
+
"czk",
|
864
|
+
"djf",
|
865
|
+
"dkk",
|
866
|
+
"dop",
|
867
|
+
"dzd",
|
868
|
+
"egp",
|
869
|
+
"etb",
|
870
|
+
"eur",
|
871
|
+
"fjd",
|
872
|
+
"fkp",
|
873
|
+
"gbp",
|
874
|
+
"gel",
|
875
|
+
"gip",
|
876
|
+
"gmd",
|
877
|
+
"gnf",
|
878
|
+
"gtq",
|
879
|
+
"gyd",
|
880
|
+
"hkd",
|
881
|
+
"hnl",
|
882
|
+
"hrk",
|
883
|
+
"htg",
|
884
|
+
"huf",
|
885
|
+
"idr",
|
886
|
+
"ils",
|
887
|
+
"inr",
|
888
|
+
"isk",
|
889
|
+
"jmd",
|
890
|
+
"jpy",
|
891
|
+
"kes",
|
892
|
+
"kgs",
|
893
|
+
"khr",
|
894
|
+
"kmf",
|
895
|
+
"krw",
|
896
|
+
"kyd",
|
897
|
+
"kzt",
|
898
|
+
"lak",
|
899
|
+
"lbp",
|
900
|
+
"lkr",
|
901
|
+
"lrd",
|
902
|
+
"lsl",
|
903
|
+
"ltl",
|
904
|
+
"mad",
|
905
|
+
"mdl",
|
906
|
+
"mga",
|
907
|
+
"mkd",
|
908
|
+
"mnt",
|
909
|
+
"mop",
|
910
|
+
"mro",
|
911
|
+
"mur",
|
912
|
+
"mvr",
|
913
|
+
"mwk",
|
914
|
+
"mxn",
|
915
|
+
"myr",
|
916
|
+
"mzn",
|
917
|
+
"nad",
|
918
|
+
"ngn",
|
919
|
+
"nio",
|
920
|
+
"nok",
|
921
|
+
"npr",
|
922
|
+
"nzd",
|
923
|
+
"pab",
|
924
|
+
"pen",
|
925
|
+
"pgk",
|
926
|
+
"php",
|
927
|
+
"pkr",
|
928
|
+
"pln",
|
929
|
+
"pyg",
|
930
|
+
"qar",
|
931
|
+
"ron",
|
932
|
+
"rsd",
|
933
|
+
"rub",
|
934
|
+
"rwf",
|
935
|
+
"sar",
|
936
|
+
"sbd",
|
937
|
+
"scr",
|
938
|
+
"sek",
|
939
|
+
"sgd",
|
940
|
+
"shp",
|
941
|
+
"sll",
|
942
|
+
"sos",
|
943
|
+
"srd",
|
944
|
+
"std",
|
945
|
+
"svc",
|
946
|
+
"szl",
|
947
|
+
"thb",
|
948
|
+
"tjs",
|
949
|
+
"top",
|
950
|
+
"try",
|
951
|
+
"ttd",
|
952
|
+
"twd",
|
953
|
+
"tzs",
|
954
|
+
"uah",
|
955
|
+
"ugx",
|
956
|
+
"uyu",
|
957
|
+
"uzs",
|
958
|
+
"vnd",
|
959
|
+
"vuv",
|
960
|
+
"wst",
|
961
|
+
"xaf",
|
962
|
+
"xcd",
|
963
|
+
"xof",
|
964
|
+
"xpf",
|
965
|
+
"yer",
|
966
|
+
"zar",
|
967
|
+
"zmw"
|
968
|
+
],
|
969
|
+
"supported_payment_methods"=> [
|
970
|
+
"alipay",
|
971
|
+
"card",
|
972
|
+
"stripe"
|
973
|
+
],
|
974
|
+
"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"]}}
|
975
|
+
}
|
976
|
+
end
|
977
|
+
|
978
|
+
def self.mock_balance(usd_balance = 10000)
|
979
|
+
{
|
980
|
+
object: "balance",
|
981
|
+
available: [
|
982
|
+
{
|
983
|
+
currency: "usd",
|
984
|
+
amount: usd_balance,
|
985
|
+
source_types: {
|
986
|
+
card: 25907032203,
|
987
|
+
bank_account: 108476658,
|
988
|
+
bitcoin_receiver: 1545182
|
989
|
+
}
|
990
|
+
}],
|
991
|
+
connect_reserved: [
|
992
|
+
{
|
993
|
+
currency: "usd",
|
994
|
+
amount: 4700
|
995
|
+
}],
|
996
|
+
livemode: false,
|
997
|
+
pending: [
|
998
|
+
{
|
999
|
+
currency: "usd",
|
1000
|
+
amount: 22738833554,
|
1001
|
+
source_types: {
|
1002
|
+
card: 22738826610,
|
1003
|
+
bank_account: 0,
|
1004
|
+
bitcoin_receiver: 6944
|
1005
|
+
}
|
1006
|
+
}]
|
1007
|
+
}
|
1008
|
+
end
|
1009
|
+
|
1010
|
+
def self.mock_balance_transactions(ids=[])
|
1011
|
+
bts = {}
|
1012
|
+
ids.each do |id|
|
1013
|
+
bts[id] = self.mock_balance_transaction(id: id)
|
1014
|
+
end
|
1015
|
+
bts
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
def self.mock_balance_transaction(params = {})
|
1019
|
+
currency = params[:currency] || StripeMock.default_currency
|
1020
|
+
bt_id = params[:id] || 'test_txn_default'
|
1021
|
+
source = params[:source] || 'ch_test_charge'
|
1022
|
+
{
|
1023
|
+
id: bt_id,
|
1024
|
+
object: "balance_transaction",
|
1025
|
+
amount: 10000,
|
1026
|
+
available_on: 1462406400,
|
1027
|
+
created: 1461880226,
|
1028
|
+
currency: currency,
|
1029
|
+
description: nil,
|
1030
|
+
fee: 320,
|
1031
|
+
fee_details: [
|
1032
|
+
{
|
1033
|
+
amount: 320,
|
1034
|
+
application: nil,
|
1035
|
+
currency: currency,
|
1036
|
+
description: "Stripe processing fees",
|
1037
|
+
type: "stripe_fee"
|
1038
|
+
}
|
1039
|
+
],
|
1040
|
+
net: 9680,
|
1041
|
+
source: source,
|
1042
|
+
sourced_transfers: {
|
1043
|
+
object: "list",
|
1044
|
+
data: [],
|
1045
|
+
has_more: false,
|
1046
|
+
total_count: 0,
|
1047
|
+
url: "/v1/transfers?source_transaction=#{source}"
|
1048
|
+
},
|
1049
|
+
status: "pending",
|
1050
|
+
type: "charge"
|
1051
|
+
}.merge(params)
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
def self.mock_subscription_item(params = {})
|
1055
|
+
iid = params[:id] || 'test_txn_default'
|
1056
|
+
{
|
1057
|
+
id: iid,
|
1058
|
+
object: 'subscription_item',
|
1059
|
+
created: 1504716183,
|
1060
|
+
metadata: {
|
1061
|
+
},
|
1062
|
+
plan: {
|
1063
|
+
id: 'PER_USER_PLAN1',
|
1064
|
+
object: 'plan',
|
1065
|
+
amount: 1337,
|
1066
|
+
created: 1504716177,
|
1067
|
+
currency: StripeMock.default_currency,
|
1068
|
+
interval: 'month',
|
1069
|
+
interval_count: 1,
|
1070
|
+
livemode: false,
|
1071
|
+
metadata: {},
|
1072
|
+
name: 'StripeMock Default Plan ID',
|
1073
|
+
statement_descriptor: nil,
|
1074
|
+
trial_period_days: nil
|
1075
|
+
},
|
1076
|
+
quantity: 2
|
1077
|
+
}.merge(params)
|
1078
|
+
end
|
1079
|
+
|
1080
|
+
def self.mock_ephemeral_key(**params)
|
1081
|
+
created = Time.now.to_i
|
1082
|
+
expires = created + 34_000
|
1083
|
+
{
|
1084
|
+
id: "ephkey_default",
|
1085
|
+
object: "ephemeral_key",
|
1086
|
+
associated_objects: [
|
1087
|
+
{
|
1088
|
+
id: params[:customer],
|
1089
|
+
type: "customer"
|
1090
|
+
}
|
1091
|
+
],
|
1092
|
+
created: created,
|
1093
|
+
expires: expires,
|
1094
|
+
livemode: false,
|
1095
|
+
secret: "ek_test_default"
|
1096
|
+
}
|
1097
|
+
end
|
1098
|
+
|
1099
|
+
def self.mock_payment_intent(params = {})
|
1100
|
+
payment_intent_id = params[:id] || "pi_1EwXFB2eZvKYlo2CggNnFBo8"
|
1101
|
+
currency = params[:currency] || StripeMock.default_currency
|
1102
|
+
{
|
1103
|
+
id: payment_intent_id,
|
1104
|
+
object: "payment_intent",
|
1105
|
+
amount: 49900,
|
1106
|
+
amount_capturable: 0,
|
1107
|
+
amount_received: 0,
|
1108
|
+
application: nil,
|
1109
|
+
application_fee_amount: nil,
|
1110
|
+
canceled_at: nil,
|
1111
|
+
cancellation_reason: nil,
|
1112
|
+
capture_method: "automatic",
|
1113
|
+
charges: {
|
1114
|
+
object: "list",
|
1115
|
+
data: [],
|
1116
|
+
has_more: false,
|
1117
|
+
total_count: 0,
|
1118
|
+
url: "/v1/charges?payment_intent=pi_1EwXFB2eZvKYlo2CggNnFBo8"
|
1119
|
+
},
|
1120
|
+
client_secret: "pi_1EwXFB2eZvKYlo2CggNnFBo8_secret_vOMkpqZu8ca7hxhfiO80tpT3v",
|
1121
|
+
confirmation_method: "manual",
|
1122
|
+
created: 1563208901,
|
1123
|
+
currency: "gbp",
|
1124
|
+
customer: nil,
|
1125
|
+
description: nil,
|
1126
|
+
invoice: nil,
|
1127
|
+
last_payment_error: nil,
|
1128
|
+
livemode: false,
|
1129
|
+
metadata: {},
|
1130
|
+
next_action: nil,
|
1131
|
+
on_behalf_of: nil,
|
1132
|
+
payment_method: nil,
|
1133
|
+
payment_method_types: [
|
1134
|
+
"card"
|
1135
|
+
],
|
1136
|
+
receipt_email: nil,
|
1137
|
+
review: nil,
|
1138
|
+
setup_future_usage: nil,
|
1139
|
+
shipping: nil,
|
1140
|
+
source: nil,
|
1141
|
+
statement_descriptor: nil,
|
1142
|
+
status: "requires_action",
|
1143
|
+
transfer_data: nil,
|
1144
|
+
transfer_group: nil
|
1145
|
+
}.merge(params)
|
1146
|
+
end
|
1147
|
+
|
1148
|
+
def self.mock_payment_method(params = {})
|
1149
|
+
payment_intent_id = params[:id] || 'pm_1EUpjA404Ss6rryzkHnUQDxY'
|
1150
|
+
{
|
1151
|
+
id: payment_intent_id,
|
1152
|
+
object: 'payment_method',
|
1153
|
+
billing_details: {
|
1154
|
+
address: {
|
1155
|
+
city: nil,
|
1156
|
+
country: nil,
|
1157
|
+
line1: nil,
|
1158
|
+
line2: nil,
|
1159
|
+
postal_code: nil,
|
1160
|
+
state: nil
|
1161
|
+
},
|
1162
|
+
email: nil,
|
1163
|
+
name: nil,
|
1164
|
+
phone: nil
|
1165
|
+
},
|
1166
|
+
card: {
|
1167
|
+
brand: 'visa',
|
1168
|
+
checks: {
|
1169
|
+
address_line1_check: nil,
|
1170
|
+
address_postal_code_check: nil,
|
1171
|
+
cvc_check: nil
|
1172
|
+
},
|
1173
|
+
country: 'US',
|
1174
|
+
exp_month: 4,
|
1175
|
+
exp_year: (Time.now.year + 5),
|
1176
|
+
fingerprint: 'Gu7YC8IGmLZsZJ4q',
|
1177
|
+
funding: 'credit',
|
1178
|
+
generated_from: nil,
|
1179
|
+
last4: 4242,
|
1180
|
+
three_d_secure_usage: {
|
1181
|
+
supported: true
|
1182
|
+
},
|
1183
|
+
wallet: nil
|
1184
|
+
},
|
1185
|
+
created: 1556606768,
|
1186
|
+
customer: nil,
|
1187
|
+
livemode: false,
|
1188
|
+
metadata: {},
|
1189
|
+
type: 'card'
|
1190
|
+
}.merge(params)
|
1191
|
+
end
|
1192
|
+
end
|
1193
|
+
end
|