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,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Subscription Items API' do
|
4
|
+
let(:stripe_helper) { StripeMock.create_test_helper }
|
5
|
+
let(:plan) { stripe_helper.create_plan }
|
6
|
+
let(:plan2) { stripe_helper.create_plan(amount: 100, id: 'one_more_1_plan') }
|
7
|
+
let(:customer) { Stripe::Customer.create(source: stripe_helper.generate_card_token) }
|
8
|
+
let(:subscription) { Stripe::Subscription.create(customer: customer.id, items: [{ plan: plan.id }]) }
|
9
|
+
|
10
|
+
context 'creates an item' do
|
11
|
+
it 'when required params only' do
|
12
|
+
item = Stripe::SubscriptionItem.create(plan: plan.id, subscription: subscription.id)
|
13
|
+
|
14
|
+
expect(item.id).to match(/^test_si/)
|
15
|
+
expect(item.plan.id).to eq(plan.id)
|
16
|
+
expect(item.subscription).to eq(subscription.id)
|
17
|
+
end
|
18
|
+
it 'when no subscription params' do
|
19
|
+
expect { Stripe::SubscriptionItem.create(plan: plan.id) }.to raise_error { |e|
|
20
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
21
|
+
expect(e.param).to eq('subscription')
|
22
|
+
expect(e.message).to eq('Missing required param: subscription.')
|
23
|
+
}
|
24
|
+
end
|
25
|
+
it 'when no plan params' do
|
26
|
+
expect { Stripe::SubscriptionItem.create(subscription: subscription.id) }.to raise_error { |e|
|
27
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
28
|
+
expect(e.param).to eq('plan')
|
29
|
+
expect(e.message).to eq('Missing required param: plan.')
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'updates an item' do
|
35
|
+
let(:item) { Stripe::SubscriptionItem.create(plan: plan.id, subscription: subscription.id, quantity: 2 ) }
|
36
|
+
|
37
|
+
it 'updates plan' do
|
38
|
+
updated_item = Stripe::SubscriptionItem.update(item.id, plan: plan2.id)
|
39
|
+
|
40
|
+
expect(updated_item.plan.id).to eq(plan2.id)
|
41
|
+
end
|
42
|
+
it 'updates quantity' do
|
43
|
+
updated_item = Stripe::SubscriptionItem.update(item.id, quantity: 23)
|
44
|
+
|
45
|
+
expect(updated_item.quantity).to eq(23)
|
46
|
+
end
|
47
|
+
it 'when no existing item' do
|
48
|
+
expect { Stripe::SubscriptionItem.update('some_id') }.to raise_error { |e|
|
49
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
50
|
+
expect(e.param).to eq('subscription_item')
|
51
|
+
expect(e.message).to eq('No such subscription_item: some_id')
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'retrieves a list of items' do
|
57
|
+
before do
|
58
|
+
Stripe::SubscriptionItem.create(plan: plan.id, subscription: subscription.id, quantity: 2 )
|
59
|
+
Stripe::SubscriptionItem.create(plan: plan2.id, subscription: subscription.id, quantity: 20)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'retrieves all subscription items' do
|
63
|
+
all = Stripe::SubscriptionItem.list(subscription: subscription.id)
|
64
|
+
|
65
|
+
expect(all.count).to eq(2)
|
66
|
+
end
|
67
|
+
it 'when no subscription param' do
|
68
|
+
expect { Stripe::SubscriptionItem.list }.to raise_error { |e|
|
69
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
70
|
+
expect(e.param).to eq('subscription')
|
71
|
+
expect(e.message).to eq('Missing required param: subscription.')
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'TaxRate API' do
|
4
|
+
context 'with created tax rate' do
|
5
|
+
let!(:rate) { Stripe::TaxRate.create }
|
6
|
+
|
7
|
+
it 'returns list of tax rates' do
|
8
|
+
rates = Stripe::TaxRate.list
|
9
|
+
expect(rates.count).to eq(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'retrieves tax rate' do
|
13
|
+
ret_rate = Stripe::TaxRate.retrieve(rate.id)
|
14
|
+
expect(ret_rate.id).not_to be_nil
|
15
|
+
expect(ret_rate.object).to eq('tax_rate')
|
16
|
+
expect(ret_rate.display_name).to eq('VAT')
|
17
|
+
expect(ret_rate.percentage).to eq(21.0)
|
18
|
+
expect(ret_rate.jurisdiction).to eq('EU')
|
19
|
+
expect(ret_rate.inclusive).to eq(false)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'updates tax rate' do
|
23
|
+
ret_rate = Stripe::TaxRate.update(rate.id, percentage: 30.5)
|
24
|
+
expect(ret_rate.id).not_to be_nil
|
25
|
+
expect(ret_rate.object).to eq('tax_rate')
|
26
|
+
expect(ret_rate.display_name).to eq('VAT')
|
27
|
+
expect(ret_rate.percentage).to eq(30.5)
|
28
|
+
expect(ret_rate.jurisdiction).to eq('EU')
|
29
|
+
expect(ret_rate.inclusive).to eq(false)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'creates tax rate' do
|
34
|
+
rate = Stripe::TaxRate.create
|
35
|
+
expect(rate.id).not_to be_nil
|
36
|
+
expect(rate.object).to eq('tax_rate')
|
37
|
+
expect(rate.display_name).to eq('VAT')
|
38
|
+
expect(rate.percentage).to eq(21.0)
|
39
|
+
expect(rate.jurisdiction).to eq('EU')
|
40
|
+
expect(rate.inclusive).to eq(false)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Transfer API' do
|
4
|
+
|
5
|
+
it "creates a stripe transfer" do
|
6
|
+
destination = Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com", id: "acct_12345")
|
7
|
+
transfer = Stripe::Transfer.create(amount: 100, currency: "usd", destination: destination.id)
|
8
|
+
|
9
|
+
expect(transfer.id).to match /^test_tr/
|
10
|
+
expect(transfer.amount).to eq(100)
|
11
|
+
expect(transfer.amount_reversed).to eq(0)
|
12
|
+
expect(transfer.balance_transaction).to eq('txn_2dyYXXP90MN26R')
|
13
|
+
expect(transfer.created).to eq(1304114826)
|
14
|
+
expect(transfer.currency).to eq('usd')
|
15
|
+
expect(transfer.description).to eq('Transfer description')
|
16
|
+
expect(transfer.destination).to eq('acct_12345')
|
17
|
+
expect(transfer.destination_payment).to eq("py_164xRvKbnvuxQXGuVFV2pZo1")
|
18
|
+
expect(transfer.livemode).to eq(false)
|
19
|
+
expect(transfer.metadata).to eq(Stripe::StripeObject.new)
|
20
|
+
expect(transfer.reversals).to eq(Stripe::ListObject.construct_from({
|
21
|
+
object: "list",
|
22
|
+
data: [],
|
23
|
+
total_count: 0,
|
24
|
+
has_more: false,
|
25
|
+
url: "/v1/transfers/#{transfer.id}/reversals"
|
26
|
+
}))
|
27
|
+
expect(transfer.reversed).to eq(false)
|
28
|
+
expect(transfer.source_transaction).to eq("ch_164xRv2eZvKYlo2Clu1sIJWB")
|
29
|
+
expect(transfer.source_type).to eq("card")
|
30
|
+
expect(transfer.transfer_group).to eq("group_ch_164xRv2eZvKYlo2Clu1sIJWB")
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "listing transfers" do
|
34
|
+
let(:destination) { Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com", business_name: "MyCo") }
|
35
|
+
|
36
|
+
before do
|
37
|
+
3.times do
|
38
|
+
Stripe::Transfer.create(amount: "100", currency: "usd", destination: destination.id)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "without params retrieves all tripe transfers" do
|
43
|
+
expect(Stripe::Transfer.all.count).to eq(3)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "accepts a limit param" do
|
47
|
+
expect(Stripe::Transfer.all(limit: 2).count).to eq(2)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "filters the search to a specific destination" do
|
51
|
+
d2 = Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com", business_name: "MyCo")
|
52
|
+
Stripe::Transfer.create(amount: "100", currency: "usd", destination: d2.id)
|
53
|
+
|
54
|
+
expect(Stripe::Transfer.all(destination: d2.id).count).to eq(1)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "disallows unknown parameters" do
|
58
|
+
expect { Stripe::Transfer.all(recipient: "foo") }.to raise_error {|e|
|
59
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
60
|
+
expect(e.param).to eq("recipient")
|
61
|
+
expect(e.message).to eq("Received unknown parameter: recipient")
|
62
|
+
expect(e.http_status).to eq(400)
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
it "retrieves a stripe transfer" do
|
69
|
+
original = Stripe::Transfer.create(amount: "100", currency: "usd")
|
70
|
+
transfer = Stripe::Transfer.retrieve(original.id)
|
71
|
+
|
72
|
+
expect(transfer.id).to eq(original.id)
|
73
|
+
expect(transfer.object).to eq(original.object)
|
74
|
+
expect(transfer.amount).to eq(original.amount)
|
75
|
+
expect(transfer.amount_reversed).to eq(original.amount_reversed)
|
76
|
+
expect(transfer.balance_transaction).to eq(original.balance_transaction)
|
77
|
+
expect(transfer.created).to eq(original.created)
|
78
|
+
expect(transfer.currency).to eq(original.currency)
|
79
|
+
expect(transfer.description).to eq(original.description)
|
80
|
+
expect(transfer.destination).to eq(original.destination)
|
81
|
+
expect(transfer.destination_payment).to eq(original.destination_payment)
|
82
|
+
expect(transfer.livemode).to eq(original.livemode)
|
83
|
+
expect(transfer.metadata).to eq(original.metadata)
|
84
|
+
expect(transfer.reversals).to eq(original.reversals)
|
85
|
+
expect(transfer.reversed).to eq(original.reversed)
|
86
|
+
expect(transfer.source_transaction).to eq(original.source_transaction)
|
87
|
+
expect(transfer.source_type).to eq(original.source_type)
|
88
|
+
expect(transfer.transfer_group).to eq(original.transfer_group)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "cancels a stripe transfer" do
|
92
|
+
original = Stripe::Transfer.create(amount: "100", currency: "usd")
|
93
|
+
res, api_key = Stripe::StripeClient.active_client.execute_request(:post, "/v1/transfers/#{original.id}/cancel", api_key: 'api_key')
|
94
|
+
|
95
|
+
expect(res.data[:status]).to eq("canceled")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "cannot retrieve a transfer that doesn't exist" do
|
99
|
+
expect { Stripe::Transfer.retrieve('nope') }.to raise_error {|e|
|
100
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
101
|
+
expect(e.param).to eq('transfer')
|
102
|
+
expect(e.http_status).to eq(404)
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "when amount is not integer", live: true do
|
107
|
+
dest = Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com", business_name: "Alex Smith")
|
108
|
+
expect { Stripe::Transfer.create(amount: '400.2',
|
109
|
+
currency: 'usd',
|
110
|
+
destination: dest.id,
|
111
|
+
description: 'Transfer for test@example.com') }.to raise_error { |e|
|
112
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
113
|
+
expect(e.param).to eq('amount')
|
114
|
+
expect(e.http_status).to eq(400)
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
it "when amount is negative", live: true do
|
119
|
+
dest = Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com", business_name: "Alex Smith")
|
120
|
+
expect { Stripe::Transfer.create(amount: '-400',
|
121
|
+
currency: 'usd',
|
122
|
+
destination: dest.id,
|
123
|
+
description: 'Transfer for test@example.com') }.to raise_error { |e|
|
124
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
125
|
+
expect(e.param).to eq('amount')
|
126
|
+
expect(e.message).to match(/^Invalid.*integer/)
|
127
|
+
expect(e.http_status).to eq(400)
|
128
|
+
}
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Server Validation', :live => true do
|
4
|
+
|
5
|
+
def credit_card_valid?(account_number)
|
6
|
+
digits = account_number.scan(/./).map(&:to_i)
|
7
|
+
check = digits.pop
|
8
|
+
|
9
|
+
sum = digits.reverse.each_slice(2).map do |x, y|
|
10
|
+
[(x * 2).divmod(10), y || 0]
|
11
|
+
end.flatten.inject(:+)
|
12
|
+
|
13
|
+
(10 - sum % 10) == check
|
14
|
+
end
|
15
|
+
|
16
|
+
it "runs a luhn check for charges" do
|
17
|
+
Stripe::Charge.new :with => "4242424242424241"
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Webhook Events API' do
|
4
|
+
|
5
|
+
it "matches the list of webhooks with the folder of fixtures" do
|
6
|
+
events = StripeMock::Webhooks.event_list.to_set
|
7
|
+
file_names = Dir['./lib/stripe_mock/webhook_fixtures/*'].map {|f| File.basename(f, '.json')}.to_set
|
8
|
+
# The reason we take the difference instead of compare equal is so
|
9
|
+
# that a missing event name will show up in the test failure report.
|
10
|
+
expect(events - file_names).to eq(Set.new)
|
11
|
+
expect(file_names - events).to eq(Set.new)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
it "first looks in spec/fixtures/stripe_webhooks/ for fixtures by default" do
|
16
|
+
event = StripeMock.mock_webhook_event('account.updated')
|
17
|
+
payload = StripeMock.mock_webhook_payload('account.updated')
|
18
|
+
expect(event).to be_a(Stripe::Event)
|
19
|
+
expect(event.id).to match /^test_evt_[0-9]+/
|
20
|
+
expect(event.type).to eq('account.updated')
|
21
|
+
|
22
|
+
expect(payload).to be_a(Hash)
|
23
|
+
expect(payload[:id]).to match /^test_evt_[0-9]+/
|
24
|
+
expect(payload[:type]).to eq('account.updated')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "allows non-standard event names in the project fixture folder" do
|
28
|
+
expect {
|
29
|
+
event = StripeMock.mock_webhook_event('custom.account.updated')
|
30
|
+
StripeMock.mock_webhook_payload('custom.account.updated')
|
31
|
+
}.to_not raise_error
|
32
|
+
end
|
33
|
+
|
34
|
+
it "allows configuring the project fixture folder" do
|
35
|
+
original_path = StripeMock.webhook_fixture_path
|
36
|
+
|
37
|
+
StripeMock.webhook_fixture_path = './spec/_dummy/webhooks/'
|
38
|
+
expect(StripeMock.webhook_fixture_path).to eq('./spec/_dummy/webhooks/')
|
39
|
+
|
40
|
+
event = StripeMock.mock_webhook_event('dummy.event')
|
41
|
+
payload = StripeMock.mock_webhook_payload('dummy.event')
|
42
|
+
expect(event.val).to eq('success')
|
43
|
+
expect(payload[:val]).to eq('success')
|
44
|
+
|
45
|
+
StripeMock.webhook_fixture_path = original_path
|
46
|
+
end
|
47
|
+
|
48
|
+
it "generates an event and stores it in memory" do
|
49
|
+
event = StripeMock.mock_webhook_event('customer.created')
|
50
|
+
expect(event).to be_a(Stripe::Event)
|
51
|
+
expect(event.id).to_not be_nil
|
52
|
+
|
53
|
+
data = test_data_source(:events)
|
54
|
+
expect(data[event.id]).to_not be_nil
|
55
|
+
expect(data[event.id][:id]).to eq(event.id)
|
56
|
+
expect(data[event.id][:type]).to eq('customer.created')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "generates an id for a new event" do
|
60
|
+
event_a = StripeMock.mock_webhook_event('customer.created')
|
61
|
+
event_b = StripeMock.mock_webhook_event('customer.created')
|
62
|
+
expect(event_a.id).to_not be_nil
|
63
|
+
expect(event_a.id).to_not eq(event_b.id)
|
64
|
+
|
65
|
+
data = test_data_source(:events)
|
66
|
+
expect(data[event_a.id]).to_not be_nil
|
67
|
+
expect(data[event_a.id][:id]).to eq(event_a.id)
|
68
|
+
|
69
|
+
expect(data[event_b.id]).to_not be_nil
|
70
|
+
expect(data[event_b.id][:id]).to eq(event_b.id)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "handles stripe connect event when account is present" do
|
74
|
+
acc_12314 = 'acc_12314'
|
75
|
+
event = StripeMock.mock_webhook_event('customer.created', account: acc_12314)
|
76
|
+
expect(event[:account]).to eq(acc_12314)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "retrieves an eveng using the event resource" do
|
80
|
+
webhook_event = StripeMock.mock_webhook_event('plan.created')
|
81
|
+
expect(webhook_event.id).to_not be_nil
|
82
|
+
|
83
|
+
event = Stripe::Event.retrieve(webhook_event.id)
|
84
|
+
expect(event).to_not be_nil
|
85
|
+
expect(event.type).to eq 'plan.created'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "takes a hash and deep merges into the data object" do
|
89
|
+
event = StripeMock.mock_webhook_event('customer.created', {
|
90
|
+
:account_balance => 12345
|
91
|
+
})
|
92
|
+
payload = StripeMock.mock_webhook_event('customer.created', {
|
93
|
+
:account_balance => 12345
|
94
|
+
})
|
95
|
+
expect(event.data.object.account_balance).to eq(12345)
|
96
|
+
expect(payload[:data][:object][:account_balance]).to eq(12345)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "takes a hash and deep merges arrays in the data object" do
|
100
|
+
event = StripeMock.mock_webhook_event('invoice.created', {
|
101
|
+
:lines => {
|
102
|
+
:data => [
|
103
|
+
{ :amount => 555,
|
104
|
+
:plan => { :id => 'wh_test' }
|
105
|
+
}
|
106
|
+
]
|
107
|
+
}
|
108
|
+
})
|
109
|
+
expect(event.data.object.lines.data.first.amount).to eq(555)
|
110
|
+
expect(event.data.object.lines.data.first.plan.id).to eq('wh_test')
|
111
|
+
# Ensure data from invoice.created.json is still present
|
112
|
+
expect(event.data.object.lines.data.first.type).to eq('subscription')
|
113
|
+
expect(event.data.object.lines.data.first.plan.currency).to eq('usd')
|
114
|
+
end
|
115
|
+
|
116
|
+
it "can generate all events" do
|
117
|
+
StripeMock::Webhooks.event_list.each do |event_name|
|
118
|
+
expect { StripeMock.mock_webhook_event(event_name) }.to_not raise_error
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it "raises an error for non-existant event types" do
|
123
|
+
expect {
|
124
|
+
event = StripeMock.mock_webhook_event('cow.bell')
|
125
|
+
}.to raise_error StripeMock::UnsupportedRequestError
|
126
|
+
|
127
|
+
expect {
|
128
|
+
StripeMock.mock_webhook_payload('cow.bell')
|
129
|
+
}.to raise_error StripeMock::UnsupportedRequestError
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'has actual created attribute' do
|
133
|
+
time = Time.now.to_i
|
134
|
+
|
135
|
+
evnt = StripeMock.mock_webhook_event('customer.subscription.updated')
|
136
|
+
|
137
|
+
expect(evnt.created).to eq time
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'when created param can be overrided' do
|
141
|
+
time = Time.now.to_i - 1000
|
142
|
+
|
143
|
+
evnt = StripeMock.mock_webhook_event('customer.subscription.updated', created: time)
|
144
|
+
|
145
|
+
expect(evnt.created).to eq time
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "listing events" do
|
149
|
+
|
150
|
+
it "retrieves all events" do
|
151
|
+
customer_created_event = StripeMock.mock_webhook_event('customer.created')
|
152
|
+
expect(customer_created_event).to be_a(Stripe::Event)
|
153
|
+
expect(customer_created_event.id).to_not be_nil
|
154
|
+
|
155
|
+
plan_created_event = StripeMock.mock_webhook_event('plan.created')
|
156
|
+
expect(plan_created_event).to be_a(Stripe::Event)
|
157
|
+
expect(plan_created_event.id).to_not be_nil
|
158
|
+
|
159
|
+
coupon_created_event = StripeMock.mock_webhook_event('coupon.created')
|
160
|
+
expect(coupon_created_event).to be_a(Stripe::Event)
|
161
|
+
expect(coupon_created_event).to_not be_nil
|
162
|
+
|
163
|
+
invoice_created_event = StripeMock.mock_webhook_event('invoice.created')
|
164
|
+
expect(invoice_created_event).to be_a(Stripe::Event)
|
165
|
+
expect(invoice_created_event).to_not be_nil
|
166
|
+
|
167
|
+
invoice_item_created_event = StripeMock.mock_webhook_event('invoiceitem.created')
|
168
|
+
expect(invoice_item_created_event).to be_a(Stripe::Event)
|
169
|
+
expect(invoice_item_created_event).to_not be_nil
|
170
|
+
|
171
|
+
events = Stripe::Event.all
|
172
|
+
|
173
|
+
expect(events.count).to eq(5)
|
174
|
+
expect(events.map &:id).to include(customer_created_event.id, plan_created_event.id, coupon_created_event.id, invoice_created_event.id, invoice_item_created_event.id)
|
175
|
+
expect(events.map &:type).to include('customer.created', 'plan.created', 'coupon.created', 'invoice.created', 'invoiceitem.created')
|
176
|
+
end
|
177
|
+
|
178
|
+
it "retrieves events with a limit(3)" do
|
179
|
+
customer_created_event = StripeMock.mock_webhook_event('customer.created')
|
180
|
+
expect(customer_created_event).to be_a(Stripe::Event)
|
181
|
+
expect(customer_created_event.id).to_not be_nil
|
182
|
+
|
183
|
+
plan_created_event = StripeMock.mock_webhook_event('plan.created')
|
184
|
+
expect(plan_created_event).to be_a(Stripe::Event)
|
185
|
+
expect(plan_created_event.id).to_not be_nil
|
186
|
+
|
187
|
+
coupon_created_event = StripeMock.mock_webhook_event('coupon.created')
|
188
|
+
expect(coupon_created_event).to be_a(Stripe::Event)
|
189
|
+
expect(coupon_created_event).to_not be_nil
|
190
|
+
|
191
|
+
invoice_created_event = StripeMock.mock_webhook_event('invoice.created')
|
192
|
+
expect(invoice_created_event).to be_a(Stripe::Event)
|
193
|
+
expect(invoice_created_event).to_not be_nil
|
194
|
+
|
195
|
+
invoice_item_created_event = StripeMock.mock_webhook_event('invoiceitem.created')
|
196
|
+
expect(invoice_item_created_event).to be_a(Stripe::Event)
|
197
|
+
expect(invoice_item_created_event).to_not be_nil
|
198
|
+
|
199
|
+
events = Stripe::Event.all(limit: 3)
|
200
|
+
|
201
|
+
expect(events.count).to eq(3)
|
202
|
+
expect(events.map &:id).to include(invoice_item_created_event.id, invoice_created_event.id, coupon_created_event.id)
|
203
|
+
expect(events.map &:type).to include('invoiceitem.created', 'invoice.created', 'coupon.created')
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
describe 'Subscription events' do
|
209
|
+
it "Checks for billing items in customer.subscription.created" do
|
210
|
+
subscription_created_event = StripeMock.mock_webhook_event('customer.subscription.created')
|
211
|
+
expect(subscription_created_event).to be_a(Stripe::Event)
|
212
|
+
expect(subscription_created_event.id).to_not be_nil
|
213
|
+
expect(subscription_created_event.data.object.items.data.class).to be Array
|
214
|
+
expect(subscription_created_event.data.object.items.data.length).to be 2
|
215
|
+
expect(subscription_created_event.data.object.items.data.first).to respond_to(:plan)
|
216
|
+
expect(subscription_created_event.data.object.items.data.first.id).to eq('si_00000000000000')
|
217
|
+
end
|
218
|
+
|
219
|
+
it "Checks for billing items in customer.subscription.deleted" do
|
220
|
+
subscription_deleted_event = StripeMock.mock_webhook_event('customer.subscription.deleted')
|
221
|
+
expect(subscription_deleted_event).to be_a(Stripe::Event)
|
222
|
+
expect(subscription_deleted_event.id).to_not be_nil
|
223
|
+
expect(subscription_deleted_event.data.object.items.data.class).to be Array
|
224
|
+
expect(subscription_deleted_event.data.object.items.data.length).to be 2
|
225
|
+
expect(subscription_deleted_event.data.object.items.data.first).to respond_to(:plan)
|
226
|
+
expect(subscription_deleted_event.data.object.items.data.first.id).to eq('si_00000000000000')
|
227
|
+
end
|
228
|
+
|
229
|
+
it "Checks for billing items in customer.subscription.updated" do
|
230
|
+
subscription_updated_event = StripeMock.mock_webhook_event('customer.subscription.updated')
|
231
|
+
expect(subscription_updated_event).to be_a(Stripe::Event)
|
232
|
+
expect(subscription_updated_event.id).to_not be_nil
|
233
|
+
expect(subscription_updated_event.data.object.items.data.class).to be Array
|
234
|
+
expect(subscription_updated_event.data.object.items.data.length).to be 2
|
235
|
+
expect(subscription_updated_event.data.object.items.data.first).to respond_to(:plan)
|
236
|
+
expect(subscription_updated_event.data.object.items.data.first.id).to eq('si_00000000000000')
|
237
|
+
end
|
238
|
+
|
239
|
+
it "Checks for billing items in customer.subscription.trial_will_end" do
|
240
|
+
subscription_trial_will_end_event = StripeMock.mock_webhook_event('customer.subscription.trial_will_end')
|
241
|
+
expect(subscription_trial_will_end_event).to be_a(Stripe::Event)
|
242
|
+
expect(subscription_trial_will_end_event.id).to_not be_nil
|
243
|
+
expect(subscription_trial_will_end_event.data.object.items.data.class).to be Array
|
244
|
+
expect(subscription_trial_will_end_event.data.object.items.data.length).to be 2
|
245
|
+
expect(subscription_trial_will_end_event.data.object.items.data.first).to respond_to(:plan)
|
246
|
+
expect(subscription_trial_will_end_event.data.object.items.data.first.id).to eq('si_00000000000000')
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe 'Invoices events' do
|
251
|
+
it "Checks for billing items in invoice.payment_succeeded" do
|
252
|
+
invoice_payment_succeeded = StripeMock.mock_webhook_event('invoice.payment_succeeded')
|
253
|
+
expect(invoice_payment_succeeded).to be_a(Stripe::Event)
|
254
|
+
expect(invoice_payment_succeeded.id).to_not be_nil
|
255
|
+
expect(invoice_payment_succeeded.data.object.lines.data.class).to be Array
|
256
|
+
expect(invoice_payment_succeeded.data.object.lines.data.length).to be 2
|
257
|
+
expect(invoice_payment_succeeded.data.object.lines.data.first).to respond_to(:plan)
|
258
|
+
expect(invoice_payment_succeeded.data.object.lines.data.first.id).to eq('sub_00000000000000')
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|