epopia-stripe-ruby-mock 2.5.8
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 +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
data/spec/readme_spec.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'stripe_mock'
|
2
|
+
|
3
|
+
describe 'README examples' do
|
4
|
+
let(:stripe_helper) { StripeMock.create_test_helper }
|
5
|
+
|
6
|
+
before { StripeMock.start }
|
7
|
+
after { StripeMock.stop }
|
8
|
+
|
9
|
+
it "creates a stripe customer" do
|
10
|
+
|
11
|
+
# This doesn't touch stripe's servers nor the internet!
|
12
|
+
customer = Stripe::Customer.create({
|
13
|
+
email: 'johnny@appleseed.com',
|
14
|
+
card: stripe_helper.generate_card_token
|
15
|
+
})
|
16
|
+
expect(customer.email).to eq('johnny@appleseed.com')
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
it "mocks a declined card error" do
|
21
|
+
# Prepares an error for the next create charge request
|
22
|
+
StripeMock.prepare_card_error(:card_declined)
|
23
|
+
|
24
|
+
expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error {|e|
|
25
|
+
expect(e).to be_a Stripe::CardError
|
26
|
+
expect(e.http_status).to eq(402)
|
27
|
+
expect(e.code).to eq('card_declined')
|
28
|
+
expect(e.json_body[:error][:decline_code]).to eq('do_not_honor')
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has built-in card errors" do
|
33
|
+
StripeMock.prepare_card_error(:incorrect_number)
|
34
|
+
StripeMock.prepare_card_error(:invalid_number)
|
35
|
+
StripeMock.prepare_card_error(:invalid_expiry_month)
|
36
|
+
StripeMock.prepare_card_error(:invalid_expiry_year)
|
37
|
+
StripeMock.prepare_card_error(:invalid_cvc)
|
38
|
+
StripeMock.prepare_card_error(:expired_card)
|
39
|
+
StripeMock.prepare_card_error(:incorrect_cvc)
|
40
|
+
StripeMock.prepare_card_error(:card_declined)
|
41
|
+
StripeMock.prepare_card_error(:missing)
|
42
|
+
StripeMock.prepare_card_error(:processing_error)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "mocks a stripe webhook" do
|
46
|
+
event = StripeMock.mock_webhook_event('customer.created')
|
47
|
+
|
48
|
+
customer_object = event.data.object
|
49
|
+
expect(customer_object.id).to_not be_nil
|
50
|
+
expect(customer_object.default_card).to_not be_nil
|
51
|
+
# etc.
|
52
|
+
end
|
53
|
+
|
54
|
+
it "can override default webhook values" do
|
55
|
+
event = StripeMock.mock_webhook_event('customer.created', {
|
56
|
+
:id => 'cus_my_custom_value',
|
57
|
+
:email => 'joe@example.com'
|
58
|
+
})
|
59
|
+
# Alternatively:
|
60
|
+
# event.data.object.id = 'cus_my_custom_value'
|
61
|
+
# event.data.object.email = 'joe@example.com'
|
62
|
+
expect(event.data.object.id).to eq('cus_my_custom_value')
|
63
|
+
expect(event.data.object.email).to eq('joe@example.com')
|
64
|
+
end
|
65
|
+
|
66
|
+
it "generates a stripe card token" do
|
67
|
+
card_token = StripeMock.generate_card_token(last4: "9191", exp_year: 1984)
|
68
|
+
|
69
|
+
cus = Stripe::Customer.create(source: card_token)
|
70
|
+
card = cus.sources.data.first
|
71
|
+
expect(card.last4).to eq("9191")
|
72
|
+
expect(card.exp_year).to eq(1984)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/spec/server_spec.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_stripe_examples
|
3
|
+
|
4
|
+
describe 'StripeMock Server', :mock_server => true do
|
5
|
+
|
6
|
+
let(:stripe_helper) { StripeMock.create_test_helper }
|
7
|
+
|
8
|
+
it_behaves_like_stripe do
|
9
|
+
def test_data_source(type); StripeMock.client.get_server_data(type); end
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:all) do
|
13
|
+
StripeMock.spawn_server
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
@client = StripeMock.start_client
|
18
|
+
end
|
19
|
+
|
20
|
+
after { StripeMock.stop_client(:clear_server_data => true) }
|
21
|
+
|
22
|
+
|
23
|
+
it "uses an RPC client for mock requests" do
|
24
|
+
charge = Stripe::Charge.create(
|
25
|
+
amount: 987,
|
26
|
+
currency: 'USD',
|
27
|
+
source: stripe_helper.generate_card_token,
|
28
|
+
description: 'card charge'
|
29
|
+
)
|
30
|
+
expect(charge.amount).to eq(987)
|
31
|
+
expect(charge.currency).to eq('USD')
|
32
|
+
expect(charge.description).to eq('card charge')
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
it "should not clear server data in between client sessions by default" do
|
37
|
+
customer = Stripe::Customer.create(email: 'johnny@appleseed.com')
|
38
|
+
expect(customer.email).to eq('johnny@appleseed.com')
|
39
|
+
|
40
|
+
server_customer_data = StripeMock.client.get_server_data(:customers)[customer.id]
|
41
|
+
expect(server_customer_data).to_not be_nil
|
42
|
+
expect(server_customer_data[:email]).to eq('johnny@appleseed.com')
|
43
|
+
|
44
|
+
StripeMock.stop_client
|
45
|
+
StripeMock.start_client
|
46
|
+
|
47
|
+
server_customer_data = StripeMock.client.get_server_data(:customers)[customer.id]
|
48
|
+
expect(server_customer_data).to_not be_nil
|
49
|
+
expect(server_customer_data[:email]).to eq('johnny@appleseed.com')
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
it "returns a response with symbolized hash keys" do
|
54
|
+
stripe_helper.create_plan(id: 'x')
|
55
|
+
response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', api_key: 'xxx')
|
56
|
+
response.data.keys.each {|k| expect(k).to be_a(Symbol) }
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
it "can toggle debug" do
|
61
|
+
StripeMock.toggle_debug(true)
|
62
|
+
expect(@client.server_debug?).to eq(true)
|
63
|
+
StripeMock.toggle_debug(false)
|
64
|
+
expect(@client.server_debug?).to eq(false)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
it "should toggle off debug when mock session ends" do
|
69
|
+
StripeMock.toggle_debug(true)
|
70
|
+
|
71
|
+
StripeMock.stop_client
|
72
|
+
expect(StripeMock.client).to be_nil
|
73
|
+
|
74
|
+
StripeMock.start_client
|
75
|
+
expect(StripeMock.client.server_debug?).to eq(false)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
it "can set the default server pid path" do
|
80
|
+
expect(StripeMock.default_server_pid_path).to eq('./stripe-mock-server.pid')
|
81
|
+
|
82
|
+
orig = StripeMock.default_server_pid_path
|
83
|
+
StripeMock.default_server_pid_path = 'abc'
|
84
|
+
expect(StripeMock.default_server_pid_path).to eq('abc')
|
85
|
+
|
86
|
+
# Set back to original for #kill_server to work properly
|
87
|
+
StripeMock.default_server_pid_path = orig
|
88
|
+
end
|
89
|
+
|
90
|
+
it "can set the default server log path" do
|
91
|
+
expect(StripeMock.default_server_log_path).to eq('./stripe-mock-server.log')
|
92
|
+
|
93
|
+
StripeMock.default_server_log_path = 'yule.log'
|
94
|
+
expect(StripeMock.default_server_log_path).to eq('yule.log')
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
it "doesn't create multiple clients" do
|
99
|
+
result = StripeMock.start_client
|
100
|
+
expect(result.__id__).to eq(@client.__id__)
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
it "raises an error when client is stopped" do
|
105
|
+
expect(@client).to be_a StripeMock::Client
|
106
|
+
expect(@client.state).to eq('ready')
|
107
|
+
|
108
|
+
StripeMock.stop_client
|
109
|
+
expect(@client.state).to eq('closed')
|
110
|
+
expect { @client.clear_server_data }.to raise_error StripeMock::ClosedClientConnectionError
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
it "raises an error when client connection is closed" do
|
115
|
+
expect(@client).to be_a StripeMock::Client
|
116
|
+
expect(@client.state).to eq('ready')
|
117
|
+
|
118
|
+
@client.close!
|
119
|
+
expect(@client.state).to eq('closed')
|
120
|
+
expect(StripeMock.stop_client).to eq(false)
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
it "throws an error when server is not running" do
|
125
|
+
StripeMock.stop_client
|
126
|
+
begin
|
127
|
+
StripeMock.start_client(1515)
|
128
|
+
# We should never get here
|
129
|
+
expect(false).to eq(true)
|
130
|
+
rescue StripeMock::ServerTimeoutError => e
|
131
|
+
expect(e).to be_a StripeMock::ServerTimeoutError
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it "can set a conversion rate" do
|
136
|
+
StripeMock.set_conversion_rate(1.2)
|
137
|
+
expect(StripeMock.client.get_conversion_rate).to eq(1.2)
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Account API' do
|
4
|
+
describe 'retrive accounts' do
|
5
|
+
it 'retrieves a stripe account', live: true do
|
6
|
+
account = Stripe::Account.retrieve
|
7
|
+
|
8
|
+
expect(account).to be_a Stripe::Account
|
9
|
+
expect(account.id).to match /acct\_/
|
10
|
+
end
|
11
|
+
it 'retrieves a specific stripe account' do
|
12
|
+
account = Stripe::Account.retrieve('acct_103ED82ePvKYlo2C')
|
13
|
+
|
14
|
+
expect(account).to be_a Stripe::Account
|
15
|
+
expect(account.id).to match /acct\_/
|
16
|
+
end
|
17
|
+
it 'retrieves all' do
|
18
|
+
accounts = Stripe::Account.all
|
19
|
+
|
20
|
+
expect(accounts).to be_a Stripe::ListObject
|
21
|
+
expect(accounts.data.count).to satisfy { |n| n >= 1 }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
describe 'create account' do
|
25
|
+
it 'creates one more account' do
|
26
|
+
account = Stripe::Account.create(email: 'lol@what.com')
|
27
|
+
|
28
|
+
expect(account).to be_a Stripe::Account
|
29
|
+
end
|
30
|
+
it 'create managed account' do
|
31
|
+
account = Stripe::Account.create(managed: true, country: 'CA')
|
32
|
+
|
33
|
+
# expect(account).to include(:keys)
|
34
|
+
expect(account.keys).not_to be_nil
|
35
|
+
expect(account.keys.secret).to match /sk_(live|test)_[\d\w]+/
|
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/
|
40
|
+
end
|
41
|
+
end
|
42
|
+
describe 'updates account' do
|
43
|
+
it 'updates account' do
|
44
|
+
account = Stripe::Account.retrieve
|
45
|
+
account.support_phone = '1234567'
|
46
|
+
account.save
|
47
|
+
|
48
|
+
account = Stripe::Account.retrieve
|
49
|
+
|
50
|
+
expect(account.support_phone).to eq '1234567'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'raises when sending an empty tos date' do
|
54
|
+
account = Stripe::Account.retrieve
|
55
|
+
account.tos_acceptance.date = nil
|
56
|
+
expect {
|
57
|
+
account.save
|
58
|
+
}.to raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with tos acceptance date' do
|
62
|
+
let(:error_message) { "ToS acceptance date is not valid. Dates are expected to be integers, measured in seconds, not in the future, and after 2009" }
|
63
|
+
|
64
|
+
it 'raises error when tos date is before 2009' do
|
65
|
+
date = Date.new(2008,1,1).strftime("%s").to_i
|
66
|
+
|
67
|
+
account = Stripe::Account.retrieve
|
68
|
+
account.tos_acceptance.date = date
|
69
|
+
|
70
|
+
expect {
|
71
|
+
account.save
|
72
|
+
}.to raise_error Stripe::InvalidRequestError, error_message
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'raises error when tos date is in the future' do
|
76
|
+
year = Time.now.year + 5
|
77
|
+
date = Date.new(year,1,1).strftime("%s").to_i
|
78
|
+
|
79
|
+
account = Stripe::Account.retrieve
|
80
|
+
account.tos_acceptance.date = date
|
81
|
+
|
82
|
+
expect {
|
83
|
+
account.save
|
84
|
+
}.to raise_error Stripe::InvalidRequestError, error_message
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'deauthorizes the stripe account', live: false do
|
90
|
+
account = Stripe::Account.retrieve
|
91
|
+
result = account.deauthorize('CLIENT_ID')
|
92
|
+
|
93
|
+
expect(result).to be_a Stripe::StripeObject
|
94
|
+
expect(result[:stripe_user_id]).to eq account[:id]
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Balance Transaction API' do
|
4
|
+
|
5
|
+
let(:stripe_helper) { StripeMock.create_test_helper }
|
6
|
+
|
7
|
+
it "returns an error if balance transaction does not exist" do
|
8
|
+
txn_id = 'txn_xxxxxxxxxxxxxxxxxxxxxxxx'
|
9
|
+
|
10
|
+
expect {
|
11
|
+
Stripe::BalanceTransaction.retrieve(txn_id)
|
12
|
+
}.to raise_error { |e|
|
13
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
14
|
+
expect(e.message).to eq('No such balance_transaction: ' + txn_id)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "retrieves a single balance transaction" do
|
19
|
+
txn_id = 'txn_05RsQX2eZvKYlo2C0FRTGSSA'
|
20
|
+
txn = Stripe::BalanceTransaction.retrieve(txn_id)
|
21
|
+
|
22
|
+
expect(txn).to be_a(Stripe::BalanceTransaction)
|
23
|
+
expect(txn.id).to eq(txn_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "listing balance transactions" do
|
27
|
+
|
28
|
+
it "retrieves all balance transactions" do
|
29
|
+
disputes = Stripe::BalanceTransaction.all
|
30
|
+
|
31
|
+
expect(disputes.count).to eq(10)
|
32
|
+
expect(disputes.map &:id).to include('txn_05RsQX2eZvKYlo2C0FRTGSSA','txn_15RsQX2eZvKYlo2C0ERTYUIA', 'txn_25RsQX2eZvKYlo2C0ZXCVBNM', 'txn_35RsQX2eZvKYlo2C0QAZXSWE', 'txn_45RsQX2eZvKYlo2C0EDCVFRT', 'txn_55RsQX2eZvKYlo2C0OIKLJUY', 'txn_65RsQX2eZvKYlo2C0ASDFGHJ', 'txn_75RsQX2eZvKYlo2C0EDCXSWQ', 'txn_85RsQX2eZvKYlo2C0UJMCDET', 'txn_95RsQX2eZvKYlo2C0EDFRYUI')
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'retrieves balance transactions for an automated transfer' do
|
38
|
+
transfer_id = Stripe::Transfer.create({ amount: 2730, currency: "usd" })
|
39
|
+
|
40
|
+
# verify transfer currently has no balance transactions
|
41
|
+
transfer_transactions = Stripe::BalanceTransaction.all({transfer: transfer_id})
|
42
|
+
expect(transfer_transactions.count).to eq(0)
|
43
|
+
|
44
|
+
# verify we can create a new balance transaction associated with the transfer
|
45
|
+
new_txn_id = stripe_helper.upsert_stripe_object(:balance_transaction, {amount: 12300, transfer: transfer_id})
|
46
|
+
new_txn = Stripe::BalanceTransaction.retrieve(new_txn_id)
|
47
|
+
expect(new_txn).to be_a(Stripe::BalanceTransaction)
|
48
|
+
expect(new_txn.amount).to eq(12300)
|
49
|
+
# although transfer was specified as an attribute on the balance_transaction, it should not be returned in the object
|
50
|
+
expect{new_txn.transfer}.to raise_error(NoMethodError)
|
51
|
+
|
52
|
+
# verify we can update an existing balance transaction to associate with the transfer
|
53
|
+
existing_txn_id = 'txn_05RsQX2eZvKYlo2C0FRTGSSA'
|
54
|
+
existing_txn = Stripe::BalanceTransaction.retrieve(existing_txn_id)
|
55
|
+
stripe_helper.upsert_stripe_object(:balance_transaction, {id: existing_txn_id, transfer: transfer_id})
|
56
|
+
|
57
|
+
# now verify that only these balance transactions are retrieved with the transfer
|
58
|
+
transfer_transactions = Stripe::BalanceTransaction.all({transfer: transfer_id})
|
59
|
+
expect(transfer_transactions.count).to eq(2)
|
60
|
+
expect(transfer_transactions.map &:id).to include(new_txn_id, existing_txn_id)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Bank API' do
|
4
|
+
|
5
|
+
it 'creates/returns a bank when using customer.sources.create given a bank token' do
|
6
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
7
|
+
bank_token = stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
8
|
+
bank = customer.sources.create(source: bank_token)
|
9
|
+
|
10
|
+
expect(bank.customer).to eq('test_customer_sub')
|
11
|
+
expect(bank.last4).to eq("1123")
|
12
|
+
expect(bank.exp_month).to eq(11)
|
13
|
+
expect(bank.exp_year).to eq(2099)
|
14
|
+
|
15
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
16
|
+
expect(customer.sources.count).to eq(1)
|
17
|
+
bank = customer.sources.data.first
|
18
|
+
expect(bank.customer).to eq('test_customer_sub')
|
19
|
+
expect(bank.last4).to eq("1123")
|
20
|
+
expect(bank.exp_month).to eq(11)
|
21
|
+
expect(bank.exp_year).to eq(2099)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'creates/returns a bank when using customer.sources.create given bank params' do
|
25
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
26
|
+
bank = customer.sources.create(bank: {
|
27
|
+
number: '4242424242424242',
|
28
|
+
exp_month: '11',
|
29
|
+
exp_year: '3031',
|
30
|
+
cvc: '123'
|
31
|
+
})
|
32
|
+
|
33
|
+
expect(bank.customer).to eq('test_customer_sub')
|
34
|
+
expect(bank.last4).to eq("6789")
|
35
|
+
|
36
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
37
|
+
expect(customer.sources.count).to eq(1)
|
38
|
+
bank = customer.sources.data.first
|
39
|
+
expect(bank.customer).to eq('test_customer_sub')
|
40
|
+
expect(bank.last4).to eq("6789")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "creates a single bank with a generated bank token" do
|
44
|
+
customer = Stripe::Customer.create
|
45
|
+
expect(customer.sources.count).to eq 0
|
46
|
+
|
47
|
+
customer.sources.create :source => stripe_helper.generate_bank_token
|
48
|
+
# Yes, stripe-ruby does not actually add the new bank to the customer instance
|
49
|
+
expect(customer.sources.count).to eq 0
|
50
|
+
|
51
|
+
customer2 = Stripe::Customer.retrieve(customer.id)
|
52
|
+
expect(customer2.sources.count).to eq 1
|
53
|
+
expect(customer2.default_source).to eq customer2.sources.first.id
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'create does not change the customers default bank if already set' do
|
57
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub', default_source: "test_cc_original")
|
58
|
+
bank_token = stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
59
|
+
bank = customer.sources.create(source: bank_token)
|
60
|
+
|
61
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
62
|
+
expect(customer.default_source).to eq("test_cc_original")
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'create updates the customers default bank if not set' do
|
66
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub')
|
67
|
+
bank_token = stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
68
|
+
bank = customer.sources.create(source: bank_token)
|
69
|
+
|
70
|
+
customer = Stripe::Customer.retrieve('test_customer_sub')
|
71
|
+
expect(customer.default_source).to_not be_nil
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "retrieval and deletion with customers" do
|
75
|
+
let!(:customer) { Stripe::Customer.create(id: 'test_customer_sub') }
|
76
|
+
let!(:bank_token) { stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
77
|
+
let!(:bank) { customer.sources.create(source: bank_token) }
|
78
|
+
|
79
|
+
it "can retrieve all customer's banks" do
|
80
|
+
retrieved = customer.sources.all
|
81
|
+
expect(retrieved.count).to eq(1)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "retrieves a customers bank" do
|
85
|
+
retrieved = customer.sources.retrieve(bank.id)
|
86
|
+
expect(retrieved.to_s).to eq(bank.to_s)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "retrieves a customer's bank after re-fetching the customer" do
|
90
|
+
retrieved = Stripe::Customer.retrieve(customer.id).sources.retrieve(bank.id)
|
91
|
+
expect(retrieved.id).to eq bank.id
|
92
|
+
end
|
93
|
+
|
94
|
+
it "deletes a customers bank" do
|
95
|
+
bank.delete
|
96
|
+
retrieved_cus = Stripe::Customer.retrieve(customer.id)
|
97
|
+
expect(retrieved_cus.sources.data).to be_empty
|
98
|
+
end
|
99
|
+
|
100
|
+
it "deletes a customers bank then set the default_bank to nil" do
|
101
|
+
bank.delete
|
102
|
+
retrieved_cus = Stripe::Customer.retrieve(customer.id)
|
103
|
+
expect(retrieved_cus.default_source).to be_nil
|
104
|
+
end
|
105
|
+
|
106
|
+
it "updates the default bank if deleted" do
|
107
|
+
bank.delete
|
108
|
+
retrieved_cus = Stripe::Customer.retrieve(customer.id)
|
109
|
+
expect(retrieved_cus.default_source).to be_nil
|
110
|
+
end
|
111
|
+
|
112
|
+
context "deletion when the user has two banks" do
|
113
|
+
let!(:bank_token_2) { stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
114
|
+
let!(:bank_2) { customer.sources.create(source: bank_token_2) }
|
115
|
+
|
116
|
+
it "has just one bank anymore" do
|
117
|
+
bank.delete
|
118
|
+
retrieved_cus = Stripe::Customer.retrieve(customer.id)
|
119
|
+
expect(retrieved_cus.sources.data.count).to eq 1
|
120
|
+
expect(retrieved_cus.sources.data.first.id).to eq bank_2.id
|
121
|
+
end
|
122
|
+
|
123
|
+
it "sets the default_bank id to the last bank remaining id" do
|
124
|
+
bank.delete
|
125
|
+
retrieved_cus = Stripe::Customer.retrieve(customer.id)
|
126
|
+
expect(retrieved_cus.default_source).to eq bank_2.id
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "Errors", :live => true do
|
132
|
+
it "throws an error when the customer does not have the retrieving bank id" do
|
133
|
+
customer = Stripe::Customer.create
|
134
|
+
bank_id = "bank_123"
|
135
|
+
expect { customer.sources.retrieve(bank_id) }.to raise_error {|e|
|
136
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
137
|
+
expect(e.message).to match /no.*source/i
|
138
|
+
expect(e.message).to include bank_id
|
139
|
+
expect(e.param).to eq 'id'
|
140
|
+
expect(e.http_status).to eq 404
|
141
|
+
}
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "update bank" do
|
146
|
+
let!(:customer) { Stripe::Customer.create(id: 'test_customer_sub') }
|
147
|
+
let!(:bank_token) { stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
148
|
+
let!(:bank) { customer.sources.create(source: bank_token) }
|
149
|
+
|
150
|
+
it "updates the bank" do
|
151
|
+
exp_month = 10
|
152
|
+
exp_year = 2098
|
153
|
+
|
154
|
+
bank.exp_month = exp_month
|
155
|
+
bank.exp_year = exp_year
|
156
|
+
bank.save
|
157
|
+
|
158
|
+
retrieved = customer.sources.retrieve(bank.id)
|
159
|
+
|
160
|
+
expect(retrieved.exp_month).to eq(exp_month)
|
161
|
+
expect(retrieved.exp_year).to eq(exp_year)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "retrieve multiple banks" do
|
166
|
+
|
167
|
+
it "retrieves a list of multiple banks" do
|
168
|
+
customer = Stripe::Customer.create(id: 'test_customer_bank')
|
169
|
+
|
170
|
+
bank_token = stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
171
|
+
bank1 = customer.sources.create(source: bank_token)
|
172
|
+
bank_token = stripe_helper.generate_bank_token(last4: "1124", exp_month: 12, exp_year: 2098)
|
173
|
+
bank2 = customer.sources.create(source: bank_token)
|
174
|
+
|
175
|
+
customer = Stripe::Customer.retrieve('test_customer_bank')
|
176
|
+
|
177
|
+
list = customer.sources.all
|
178
|
+
|
179
|
+
expect(list.object).to eq("list")
|
180
|
+
expect(list.count).to eq(2)
|
181
|
+
expect(list.data.length).to eq(2)
|
182
|
+
|
183
|
+
expect(list.data.first.object).to eq("bank_account")
|
184
|
+
expect(list.data.first.to_hash).to eq(bank1.to_hash)
|
185
|
+
|
186
|
+
expect(list.data.last.object).to eq("bank_account")
|
187
|
+
expect(list.data.last.to_hash).to eq(bank2.to_hash)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "retrieves an empty list if there's no subscriptions" do
|
191
|
+
Stripe::Customer.create(id: 'no_banks')
|
192
|
+
customer = Stripe::Customer.retrieve('no_banks')
|
193
|
+
|
194
|
+
list = customer.sources.all
|
195
|
+
|
196
|
+
expect(list.object).to eq("list")
|
197
|
+
expect(list.count).to eq(0)
|
198
|
+
expect(list.data.length).to eq(0)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe 'Stripe::Token creation from bank account' do
|
203
|
+
it 'generates token from bank account informations' do
|
204
|
+
token = Stripe::Token.create({
|
205
|
+
bank_account: {
|
206
|
+
account_number: "4222222222222222",
|
207
|
+
routing_number: "123456",
|
208
|
+
bank_name: "Fake bank"
|
209
|
+
}
|
210
|
+
})
|
211
|
+
|
212
|
+
cus = Stripe::Customer.create(source: token.id)
|
213
|
+
bank_account = cus.sources.data.first
|
214
|
+
expect(bank_account.bank_name).to eq('Fake bank')
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'generates token from existing bank account token' do
|
218
|
+
bank_token = StripeMock.generate_bank_token(bank_name: 'Fake bank')
|
219
|
+
cus = Stripe::Customer.create(source: bank_token)
|
220
|
+
token = Stripe::Token.create({ customer: cus.id, bank_account: cus.sources.first.id })
|
221
|
+
cus.sources.create(source: token.id)
|
222
|
+
cus = Stripe::Customer.retrieve(cus.id)
|
223
|
+
expect(cus.sources.data.count).to eq 2
|
224
|
+
cus.sources.data.each do |source|
|
225
|
+
expect(source.bank_name).to eq('Fake bank')
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|