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,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
shared_examples 'Dispute API' do
|
5
|
+
|
6
|
+
let(:stripe_helper) { StripeMock.create_test_helper }
|
7
|
+
|
8
|
+
it "returns an error if dispute does not exist" do
|
9
|
+
dispute_id = 'dp_xxxxxxxxxxxxxxxxxxxxxxxx'
|
10
|
+
|
11
|
+
expect {
|
12
|
+
Stripe::Dispute.retrieve(dispute_id)
|
13
|
+
}.to raise_error { |e|
|
14
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
15
|
+
expect(e.message).to eq('No such dispute: ' + dispute_id)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
it "retrieves a single dispute" do
|
20
|
+
dispute_id = 'dp_05RsQX2eZvKYlo2C0FRTGSSA'
|
21
|
+
dispute = Stripe::Dispute.retrieve(dispute_id)
|
22
|
+
|
23
|
+
expect(dispute).to be_a(Stripe::Dispute)
|
24
|
+
expect(dispute.id).to eq(dispute_id)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "updates a dispute" do
|
28
|
+
dispute_id = 'dp_65RsQX2eZvKYlo2C0ASDFGHJ'
|
29
|
+
dispute = Stripe::Dispute.retrieve(dispute_id)
|
30
|
+
|
31
|
+
expect(dispute).to be_a(Stripe::Dispute)
|
32
|
+
expect(dispute.id).to eq(dispute_id)
|
33
|
+
expect(dispute.evidence.customer_name).to eq(nil)
|
34
|
+
expect(dispute.evidence.product_description).to eq(nil)
|
35
|
+
expect(dispute.evidence.shipping_documentation).to eq(nil)
|
36
|
+
|
37
|
+
dispute.evidence = {
|
38
|
+
:customer_name => 'Rebel Idealist',
|
39
|
+
:product_description => 'Lorem ipsum dolor sit amet.',
|
40
|
+
:shipping_documentation => 'fil_15BZxW2eZvKYlo2CvQbrn9dc',
|
41
|
+
}
|
42
|
+
dispute.save
|
43
|
+
|
44
|
+
dispute = Stripe::Dispute.retrieve(dispute_id)
|
45
|
+
|
46
|
+
expect(dispute).to be_a(Stripe::Dispute)
|
47
|
+
expect(dispute.id).to eq(dispute_id)
|
48
|
+
expect(dispute.evidence.customer_name).to eq('Rebel Idealist')
|
49
|
+
expect(dispute.evidence.product_description).to eq('Lorem ipsum dolor sit amet.')
|
50
|
+
expect(dispute.evidence.shipping_documentation).to eq('fil_15BZxW2eZvKYlo2CvQbrn9dc')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "closes a dispute" do
|
54
|
+
dispute_id = 'dp_75RsQX2eZvKYlo2C0EDCXSWQ'
|
55
|
+
|
56
|
+
dispute = Stripe::Dispute.retrieve(dispute_id)
|
57
|
+
|
58
|
+
expect(dispute).to be_a(Stripe::Dispute)
|
59
|
+
expect(dispute.id).to eq(dispute_id)
|
60
|
+
expect(dispute.status).to eq('under_review')
|
61
|
+
|
62
|
+
dispute.close
|
63
|
+
|
64
|
+
dispute = Stripe::Dispute.retrieve(dispute_id)
|
65
|
+
|
66
|
+
expect(dispute).to be_a(Stripe::Dispute)
|
67
|
+
expect(dispute.id).to eq(dispute_id)
|
68
|
+
expect(dispute.status).to eq('lost')
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "listing disputes" do
|
72
|
+
|
73
|
+
it "retrieves all disputes" do
|
74
|
+
disputes = Stripe::Dispute.all
|
75
|
+
|
76
|
+
expect(disputes.count).to eq(10)
|
77
|
+
expect(disputes.map &:id).to include('dp_05RsQX2eZvKYlo2C0FRTGSSA','dp_15RsQX2eZvKYlo2C0ERTYUIA', 'dp_25RsQX2eZvKYlo2C0ZXCVBNM', 'dp_35RsQX2eZvKYlo2C0QAZXSWE', 'dp_45RsQX2eZvKYlo2C0EDCVFRT', 'dp_55RsQX2eZvKYlo2C0OIKLJUY', 'dp_65RsQX2eZvKYlo2C0ASDFGHJ', 'dp_75RsQX2eZvKYlo2C0EDCXSWQ', 'dp_85RsQX2eZvKYlo2C0UJMCDET', 'dp_95RsQX2eZvKYlo2C0EDFRYUI')
|
78
|
+
end
|
79
|
+
|
80
|
+
it "retrieves disputes with a limit(3)" do
|
81
|
+
disputes = Stripe::Dispute.all(limit: 3)
|
82
|
+
|
83
|
+
expect(disputes.count).to eq(3)
|
84
|
+
expected = ['dp_95RsQX2eZvKYlo2C0EDFRYUI','dp_85RsQX2eZvKYlo2C0UJMCDET', 'dp_75RsQX2eZvKYlo2C0EDCXSWQ']
|
85
|
+
expect(disputes.map &:id).to include(*expected)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
it "creates a dispute" do
|
91
|
+
card_token = stripe_helper.generate_card_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
92
|
+
charge = Stripe::Charge.create(amount: 1000, currency: "usd", source: card_token)
|
93
|
+
stripe_dispute_id = stripe_helper.upsert_stripe_object(:dispute, {amount: charge.amount, charge: charge.id})
|
94
|
+
stripe_dispute = Stripe::Dispute.retrieve(stripe_dispute_id)
|
95
|
+
expect(stripe_dispute.charge).to eq(charge.id)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'EphemeralKey API' do
|
4
|
+
describe 'Create a new key' do
|
5
|
+
let(:customer) { Stripe::Customer.create email: 'test@example.com' }
|
6
|
+
let(:version) { '2016-07-06' }
|
7
|
+
|
8
|
+
it 'creates a new key' do
|
9
|
+
key = Stripe::EphemeralKey.create(
|
10
|
+
{ customer: customer.id },
|
11
|
+
{ stripe_version: version }
|
12
|
+
)
|
13
|
+
|
14
|
+
expect(key[:associated_objects][0][:id]).to eq customer.id
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def expect_card_error(code, param)
|
4
|
+
expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error {|e|
|
5
|
+
expect(e).to be_a(Stripe::CardError)
|
6
|
+
expect(e.http_status).to eq(402)
|
7
|
+
expect(e.code).to eq(code)
|
8
|
+
expect(e.param).to eq(param)
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
shared_examples 'Stripe Error Mocking' do
|
13
|
+
|
14
|
+
it "mocks a manually given stripe card error" do
|
15
|
+
error = Stripe::CardError.new('Test Msg', 'param_name', 'bad_code', http_status: 444, http_body: 'body', json_body: 'json body')
|
16
|
+
StripeMock.prepare_error(error)
|
17
|
+
|
18
|
+
expect { Stripe::Customer.create() }.to raise_error {|e|
|
19
|
+
expect(e).to be_a(Stripe::CardError)
|
20
|
+
expect(e.code).to eq('bad_code')
|
21
|
+
expect(e.param).to eq('param_name')
|
22
|
+
expect(e.message).to eq('Test Msg')
|
23
|
+
|
24
|
+
expect(e.http_status).to eq(444)
|
25
|
+
expect(e.http_body).to eq('body')
|
26
|
+
expect(e.json_body).to eq('json body')
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
it "mocks a manually gives stripe invalid request error" do
|
32
|
+
|
33
|
+
error = Stripe::InvalidRequestError.new('Test Invalid', 'param', http_status: 987, http_body: 'ibody', json_body: 'json ibody')
|
34
|
+
StripeMock.prepare_error(error)
|
35
|
+
|
36
|
+
expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error {|e|
|
37
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
38
|
+
expect(e.param).to eq('param')
|
39
|
+
expect(e.message).to eq('Test Invalid')
|
40
|
+
|
41
|
+
expect(e.http_status).to eq(987)
|
42
|
+
expect(e.http_body).to eq('ibody')
|
43
|
+
expect(e.json_body).to eq('json ibody')
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
it "mocks a manually gives stripe invalid auth error" do
|
49
|
+
error = Stripe::AuthenticationError.new('Bad Auth', http_status: 499, http_body: 'abody', json_body: 'json abody')
|
50
|
+
StripeMock.prepare_error(error)
|
51
|
+
|
52
|
+
expect { stripe_helper.create_plan() }.to raise_error {|e|
|
53
|
+
expect(e).to be_a(Stripe::AuthenticationError)
|
54
|
+
expect(e.message).to eq('Bad Auth')
|
55
|
+
|
56
|
+
expect(e.http_status).to eq(499)
|
57
|
+
expect(e.http_body).to eq('abody')
|
58
|
+
expect(e.json_body).to eq('json abody')
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
it "raises a custom error for specific actions" do
|
64
|
+
custom_error = StandardError.new("Please knock first.")
|
65
|
+
StripeMock.prepare_error(custom_error, :new_customer)
|
66
|
+
|
67
|
+
expect {
|
68
|
+
Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
|
69
|
+
}.to_not raise_error
|
70
|
+
|
71
|
+
expect { Stripe::Customer.create }.to raise_error {|e|
|
72
|
+
expect(e).to be_a StandardError
|
73
|
+
expect(e.message).to eq("Please knock first.")
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
# # # # # # # # # # # # # #
|
78
|
+
# Card Error Helper Methods
|
79
|
+
# # # # # # # # # # # # # #
|
80
|
+
|
81
|
+
it "raises an error for an unrecognized card error code" do
|
82
|
+
expect { StripeMock.prepare_card_error(:non_existant_error_code) }.to raise_error {|e|
|
83
|
+
expect(e).to be_a(StripeMock::StripeMockError)
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
it "only raises a card error when a card charge is attempted" do
|
88
|
+
StripeMock.prepare_card_error(:card_declined)
|
89
|
+
expect { Stripe::Customer.create(id: 'x') }.to_not raise_error
|
90
|
+
expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error Stripe::CardError
|
91
|
+
end
|
92
|
+
|
93
|
+
it "mocks a card error with a given handler" do
|
94
|
+
StripeMock.prepare_card_error(:incorrect_cvc, :new_customer)
|
95
|
+
expect {
|
96
|
+
Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
|
97
|
+
}.to_not raise_error
|
98
|
+
|
99
|
+
expect { Stripe::Customer.create() }.to raise_error {|e|
|
100
|
+
expect(e).to be_a(Stripe::CardError)
|
101
|
+
expect(e.http_status).to eq(402)
|
102
|
+
expect(e.code).to eq('incorrect_cvc')
|
103
|
+
expect(e.param).to eq('cvc')
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
it "mocks an incorrect number card error" do
|
108
|
+
StripeMock.prepare_card_error(:incorrect_number)
|
109
|
+
expect_card_error 'incorrect_number', 'number'
|
110
|
+
end
|
111
|
+
|
112
|
+
it "mocks an invalid number card error" do
|
113
|
+
StripeMock.prepare_card_error(:invalid_number)
|
114
|
+
expect_card_error 'invalid_number', 'number'
|
115
|
+
end
|
116
|
+
|
117
|
+
it "mocks an invalid expiration month card error" do
|
118
|
+
StripeMock.prepare_card_error(:invalid_expiry_month)
|
119
|
+
expect_card_error 'invalid_expiry_month', 'exp_month'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "mocks an invalid expiration year card error" do
|
123
|
+
StripeMock.prepare_card_error(:invalid_expiry_year)
|
124
|
+
expect_card_error 'invalid_expiry_year', 'exp_year'
|
125
|
+
end
|
126
|
+
|
127
|
+
it "mocks an invalid cvc card error" do
|
128
|
+
StripeMock.prepare_card_error(:invalid_cvc)
|
129
|
+
expect_card_error 'invalid_cvc', 'cvc'
|
130
|
+
end
|
131
|
+
|
132
|
+
it "mocks an expired card error" do
|
133
|
+
StripeMock.prepare_card_error(:expired_card)
|
134
|
+
expect_card_error 'expired_card', 'exp_month'
|
135
|
+
end
|
136
|
+
|
137
|
+
it "mocks an incorrect cvc card error" do
|
138
|
+
StripeMock.prepare_card_error(:incorrect_cvc)
|
139
|
+
expect_card_error 'incorrect_cvc', 'cvc'
|
140
|
+
end
|
141
|
+
|
142
|
+
it "mocks a declined card error" do
|
143
|
+
StripeMock.prepare_card_error(:card_declined)
|
144
|
+
expect_card_error 'card_declined', nil
|
145
|
+
end
|
146
|
+
|
147
|
+
it "mocks a missing card error" do
|
148
|
+
StripeMock.prepare_card_error(:missing)
|
149
|
+
expect_card_error 'missing', nil
|
150
|
+
end
|
151
|
+
|
152
|
+
it "mocks a processing error card error" do
|
153
|
+
StripeMock.prepare_card_error(:processing_error)
|
154
|
+
expect_card_error 'processing_error', nil
|
155
|
+
end
|
156
|
+
|
157
|
+
it "mocks an incorrect zip code card error" do
|
158
|
+
StripeMock.prepare_card_error(:incorrect_zip)
|
159
|
+
expect_card_error 'incorrect_zip', 'address_zip'
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'External Account API' do
|
4
|
+
|
5
|
+
it 'creates/returns a bank when using account.external_accounts.create given a bank token' do
|
6
|
+
account = Stripe::Account.create(id: 'test_account', type: 'custom', country: "US")
|
7
|
+
bank_token = stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
8
|
+
bank = account.external_accounts.create(external_account: bank_token)
|
9
|
+
|
10
|
+
expect(bank.account).to eq('test_account')
|
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
|
+
account = Stripe::Account.retrieve('test_account')
|
16
|
+
expect(account.external_accounts.count).to eq(1)
|
17
|
+
bank = account.external_accounts.first
|
18
|
+
expect(bank.account).to eq('test_account')
|
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 account.external_accounts.create given bank params' do
|
25
|
+
account = Stripe::Account.create(id: 'test_account', type: 'custom', country: "US")
|
26
|
+
bank = account.external_accounts.create(external_account: {
|
27
|
+
object: 'bank_account',
|
28
|
+
account_number: '000123456789',
|
29
|
+
routing_number: '110000000',
|
30
|
+
country: 'US',
|
31
|
+
currency: 'usd'
|
32
|
+
})
|
33
|
+
|
34
|
+
expect(bank.account).to eq('test_account')
|
35
|
+
expect(bank.routing_number).to eq('110000000')
|
36
|
+
expect(bank.country).to eq('US')
|
37
|
+
expect(bank.currency).to eq('usd')
|
38
|
+
|
39
|
+
account = Stripe::Account.retrieve('test_account')
|
40
|
+
expect(account.external_accounts.count).to eq(1)
|
41
|
+
bank = account.external_accounts.first
|
42
|
+
expect(bank.account).to eq('test_account')
|
43
|
+
expect(bank.routing_number).to eq('110000000')
|
44
|
+
expect(bank.country).to eq('US')
|
45
|
+
expect(bank.currency).to eq('usd')
|
46
|
+
end
|
47
|
+
|
48
|
+
it "creates a single bank with a generated bank token" do
|
49
|
+
account = Stripe::Account.create(type: 'custom', country: "US")
|
50
|
+
expect(account.external_accounts.count).to eq 0
|
51
|
+
|
52
|
+
account.external_accounts.create external_account: stripe_helper.generate_bank_token
|
53
|
+
# Yes, stripe-ruby does not actually add the new bank to the account instance
|
54
|
+
expect(account.external_accounts.count).to eq 0
|
55
|
+
|
56
|
+
account2 = Stripe::Account.retrieve(account.id)
|
57
|
+
expect(account2.external_accounts.count).to eq 1
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "retrieval and deletion with accounts" do
|
61
|
+
let!(:account) { Stripe::Account.create(id: 'test_account', type: 'custom', country: "US") }
|
62
|
+
let!(:bank_token) { stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
63
|
+
let!(:bank) { account.external_accounts.create(external_account: bank_token) }
|
64
|
+
|
65
|
+
it "can retrieve all account's banks" do
|
66
|
+
retrieved = account.external_accounts.all
|
67
|
+
expect(retrieved.count).to eq(1)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "retrieves an account bank" do
|
71
|
+
retrieved = account.external_accounts.retrieve(bank.id)
|
72
|
+
expect(retrieved.to_s).to eq(bank.to_s)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "retrieves an account's bank after re-fetching the account" do
|
76
|
+
retrieved = Stripe::Account.retrieve(account.id).external_accounts.retrieve(bank.id)
|
77
|
+
expect(retrieved.id).to eq bank.id
|
78
|
+
end
|
79
|
+
|
80
|
+
it "deletes an accounts bank" do
|
81
|
+
bank.delete
|
82
|
+
retrieved_acct = Stripe::Account.retrieve(account.id)
|
83
|
+
expect(retrieved_acct.external_accounts.data).to be_empty
|
84
|
+
end
|
85
|
+
|
86
|
+
context "deletion when the user has two external accounts" do
|
87
|
+
let!(:bank_token_2) { stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
88
|
+
let!(:bank_2) { account.external_accounts.create(external_account: bank_token_2) }
|
89
|
+
|
90
|
+
it "has just one bank anymore" do
|
91
|
+
bank.delete
|
92
|
+
retrieved_acct = Stripe::Account.retrieve(account.id)
|
93
|
+
expect(retrieved_acct.external_accounts.data.count).to eq 1
|
94
|
+
expect(retrieved_acct.external_accounts.data.first.id).to eq bank_2.id
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "Errors" do
|
100
|
+
it "throws an error when the account does not have the retrieving bank id" do
|
101
|
+
account = Stripe::Account.create(type: 'custom', country: "US")
|
102
|
+
bank_id = "bank_123"
|
103
|
+
expect { account.external_accounts.retrieve(bank_id) }.to raise_error {|e|
|
104
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
105
|
+
expect(e.message).to match /no.*source/i
|
106
|
+
expect(e.message).to include bank_id
|
107
|
+
expect(e.param).to eq 'id'
|
108
|
+
expect(e.http_status).to eq 404
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "update bank" do
|
114
|
+
let!(:account) { Stripe::Account.create(id: 'test_account', type: 'custom', country: "US") }
|
115
|
+
let!(:bank_token) { stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099) }
|
116
|
+
let!(:bank) { account.external_accounts.create(external_account: bank_token) }
|
117
|
+
|
118
|
+
it "updates the bank" do
|
119
|
+
exp_month = 10
|
120
|
+
exp_year = 2098
|
121
|
+
|
122
|
+
bank.exp_month = exp_month
|
123
|
+
bank.exp_year = exp_year
|
124
|
+
bank.save
|
125
|
+
|
126
|
+
retrieved = account.external_accounts.retrieve(bank.id)
|
127
|
+
|
128
|
+
expect(retrieved.exp_month).to eq(exp_month)
|
129
|
+
expect(retrieved.exp_year).to eq(exp_year)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "retrieve multiple banks" do
|
134
|
+
|
135
|
+
it "retrieves a list of multiple banks" do
|
136
|
+
account = Stripe::Account.create(id: 'test_account', type: 'custom', country: "US")
|
137
|
+
|
138
|
+
bank_token = stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099)
|
139
|
+
bank1 = account.external_accounts.create(external_accout: bank_token)
|
140
|
+
bank_token = stripe_helper.generate_bank_token(last4: "1124", exp_month: 12, exp_year: 2098)
|
141
|
+
bank2 = account.external_accounts.create(external_account: bank_token)
|
142
|
+
|
143
|
+
account = Stripe::Account.retrieve('test_account')
|
144
|
+
|
145
|
+
list = account.external_accounts.all
|
146
|
+
|
147
|
+
expect(list.object).to eq("list")
|
148
|
+
expect(list.count).to eq(2)
|
149
|
+
expect(list.data.length).to eq(2)
|
150
|
+
|
151
|
+
expect(list.data.first.object).to eq("bank_account")
|
152
|
+
expect(list.data.first.to_hash).to eq(bank1.to_hash)
|
153
|
+
|
154
|
+
expect(list.data.last.object).to eq("bank_account")
|
155
|
+
expect(list.data.last.to_hash).to eq(bank2.to_hash)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "retrieves an empty list if there's no subscriptions" do
|
159
|
+
Stripe::Account.create(id: 'no_banks', type: 'custom', country: "US")
|
160
|
+
account = Stripe::Account.retrieve('no_banks')
|
161
|
+
|
162
|
+
list = account.external_accounts.all
|
163
|
+
|
164
|
+
expect(list.object).to eq("list")
|
165
|
+
expect(list.count).to eq(0)
|
166
|
+
expect(list.data.length).to eq(0)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|