stripe-ruby-mock 2.5.6 → 3.1.0.rc2
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 +5 -5
- data/.gitignore +1 -1
- data/.travis.yml +6 -9
- data/CHANGELOG.md +35 -0
- data/Gemfile +1 -0
- data/README.md +17 -11
- data/lib/stripe_mock.rb +11 -0
- data/lib/stripe_mock/api/client.rb +1 -1
- data/lib/stripe_mock/api/errors.rb +34 -28
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +7 -0
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data.rb +323 -13
- data/lib/stripe_mock/data/list.rb +42 -9
- data/lib/stripe_mock/instance.rb +52 -5
- data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/balance_transactions.rb +2 -2
- data/lib/stripe_mock/request_handlers/charges.rb +13 -12
- data/lib/stripe_mock/request_handlers/checkout.rb +15 -0
- data/lib/stripe_mock/request_handlers/checkout_session.rb +16 -0
- data/lib/stripe_mock/request_handlers/customers.rb +35 -18
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
- data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +14 -10
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +22 -7
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/invoices.rb +11 -5
- data/lib/stripe_mock/request_handlers/payment_intents.rb +182 -0
- data/lib/stripe_mock/request_handlers/payment_methods.rb +120 -0
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/prices.rb +44 -0
- data/lib/stripe_mock/request_handlers/products.rb +44 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +6 -3
- data/lib/stripe_mock/request_handlers/setup_intents.rb +93 -0
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +82 -41
- data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
- data/lib/stripe_mock/request_handlers/tokens.rb +8 -6
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +130 -9
- data/lib/stripe_mock/test_strategies/base.rb +68 -8
- data/lib/stripe_mock/test_strategies/live.rb +23 -12
- data/lib/stripe_mock/test_strategies/mock.rb +6 -2
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/balance.available.json +6 -0
- data/lib/stripe_mock/webhook_fixtures/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.failed.json +166 -38
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +2 -1
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +2 -1
- data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +186 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +164 -0
- data/lib/stripe_mock/webhook_fixtures/product.created.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +38 -0
- data/spec/instance_spec.rb +10 -12
- data/spec/list_spec.rb +38 -0
- data/spec/server_spec.rb +6 -3
- data/spec/shared_stripe_examples/account_examples.rb +1 -1
- data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
- data/spec/shared_stripe_examples/balance_examples.rb +6 -0
- data/spec/shared_stripe_examples/balance_transaction_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_examples.rb +3 -3
- data/spec/shared_stripe_examples/card_examples.rb +4 -4
- data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/charge_examples.rb +32 -36
- data/spec/shared_stripe_examples/checkout_examples.rb +38 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +103 -53
- data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
- data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
- data/spec/shared_stripe_examples/invoice_examples.rb +43 -41
- data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
- data/spec/shared_stripe_examples/payment_intent_examples.rb +147 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +449 -0
- data/spec/shared_stripe_examples/payout_examples.rb +2 -2
- data/spec/shared_stripe_examples/plan_examples.rb +135 -77
- data/spec/shared_stripe_examples/price_examples.rb +183 -0
- data/spec/shared_stripe_examples/product_examples.rb +155 -0
- data/spec/shared_stripe_examples/refund_examples.rb +41 -31
- data/spec/shared_stripe_examples/setup_intent_examples.rb +68 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +546 -295
- data/spec/shared_stripe_examples/subscription_items_examples.rb +76 -0
- data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
- data/spec/shared_stripe_examples/transfer_examples.rb +9 -9
- data/spec/shared_stripe_examples/webhook_event_examples.rb +11 -11
- data/spec/spec_helper.rb +7 -4
- data/spec/stripe_mock_spec.rb +4 -4
- data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
- data/spec/support/stripe_examples.rb +12 -2
- data/stripe-ruby-mock.gemspec +8 -3
- metadata +81 -32
data/spec/instance_spec.rb
CHANGED
@@ -13,13 +13,13 @@ describe StripeMock::Instance do
|
|
13
13
|
after { StripeMock.stop }
|
14
14
|
|
15
15
|
it "handles both string and symbol hash keys" do
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
symbol_params = stripe_helper.create_product_params(
|
17
|
+
:name => "Symbol Product",
|
18
|
+
"type" => "service"
|
19
19
|
)
|
20
|
-
res, api_key = StripeMock.instance.mock_request('post', '/v1/
|
21
|
-
expect(res.data[:
|
22
|
-
expect(res.data[:
|
20
|
+
res, api_key = StripeMock.instance.mock_request('post', '/v1/products', api_key: 'api_key', params: symbol_params)
|
21
|
+
expect(res.data[:name]).to eq('Symbol Product')
|
22
|
+
expect(res.data[:type]).to eq('service')
|
23
23
|
end
|
24
24
|
|
25
25
|
it "exits gracefully on an unrecognized handler url" do
|
@@ -54,17 +54,15 @@ describe StripeMock::Instance do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "allows non-usd default currency" do
|
57
|
+
pending("Stripe::Plan requires currency param - how can we test this?")
|
57
58
|
old_default_currency = StripeMock.default_currency
|
58
|
-
|
59
|
+
plan = begin
|
59
60
|
StripeMock.default_currency = "jpy"
|
60
|
-
Stripe::
|
61
|
-
email: 'johnny@appleseed.com',
|
62
|
-
source: stripe_helper.generate_card_token
|
63
|
-
})
|
61
|
+
Stripe::Plan.create(interval: 'month')
|
64
62
|
ensure
|
65
63
|
StripeMock.default_currency = old_default_currency
|
66
64
|
end
|
67
|
-
expect(
|
65
|
+
expect(plan.currency).to eq("jpy")
|
68
66
|
end
|
69
67
|
|
70
68
|
context 'when creating sources with metadata' do
|
data/spec/list_spec.rb
CHANGED
@@ -109,6 +109,21 @@ describe StripeMock::Data::List do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
context "active filter" do
|
113
|
+
it "accepts an active param which filters out data accordingly" do
|
114
|
+
product = Stripe::Product.create(id: "prod_123", name: "My Beautiful Product", type: "service")
|
115
|
+
|
116
|
+
plan_attributes = { product: product.id, interval: "month", currency: "usd", amount: 500 }
|
117
|
+
plan_a = Stripe::Plan.create(plan_attributes)
|
118
|
+
plan_b = Stripe::Plan.create(**plan_attributes, active: false)
|
119
|
+
|
120
|
+
list = StripeMock::Data::List.new([plan_a, plan_b], active: true)
|
121
|
+
|
122
|
+
expect(list.active).to eq(true)
|
123
|
+
expect(list.to_h[:data].count).to eq(1)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
112
127
|
context "pagination" do
|
113
128
|
it "has a has_more field when it has more" do
|
114
129
|
list = StripeMock::Data::List.new(
|
@@ -137,4 +152,27 @@ describe StripeMock::Data::List do
|
|
137
152
|
expect { list.to_h }.to raise_error
|
138
153
|
end
|
139
154
|
end
|
155
|
+
|
156
|
+
context "with data containing records marked 'deleted'" do
|
157
|
+
let(:customer_data) { StripeMock.instance.customers.values }
|
158
|
+
let(:customers) do
|
159
|
+
customer_data.map { |datum| Stripe::Util.convert_to_stripe_object(datum) }
|
160
|
+
end
|
161
|
+
|
162
|
+
before do
|
163
|
+
StripeMock.instance.customers.clear
|
164
|
+
Stripe::Customer.create
|
165
|
+
Stripe::Customer.delete(Stripe::Customer.create.id)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "does not raise error on initialization" do
|
169
|
+
expect { StripeMock::Data::List.new(customer_data) }.to_not raise_error
|
170
|
+
expect { StripeMock::Data::List.new(customers) }.to_not raise_error
|
171
|
+
end
|
172
|
+
|
173
|
+
it "omits records marked 'deleted'" do
|
174
|
+
expect(StripeMock::Data::List.new(customer_data).data.size).to eq(1)
|
175
|
+
expect(StripeMock::Data::List.new(customers).data.size).to eq(1)
|
176
|
+
end
|
177
|
+
end
|
140
178
|
end
|
data/spec/server_spec.rb
CHANGED
@@ -19,6 +19,7 @@ describe 'StripeMock Server', :mock_server => true do
|
|
19
19
|
|
20
20
|
after { StripeMock.stop_client(:clear_server_data => true) }
|
21
21
|
|
22
|
+
let(:product) { stripe_helper.create_product }
|
22
23
|
|
23
24
|
it "uses an RPC client for mock requests" do
|
24
25
|
charge = Stripe::Charge.create(
|
@@ -37,21 +38,23 @@ describe 'StripeMock Server', :mock_server => true do
|
|
37
38
|
customer = Stripe::Customer.create(email: 'johnny@appleseed.com')
|
38
39
|
expect(customer.email).to eq('johnny@appleseed.com')
|
39
40
|
|
40
|
-
server_customer_data = StripeMock.client.get_server_data(:customers)
|
41
|
+
server_customer_data = StripeMock.client.get_server_data(:customers)
|
42
|
+
server_customer_data = server_customer_data[server_customer_data.keys.first][customer.id.to_sym]
|
41
43
|
expect(server_customer_data).to_not be_nil
|
42
44
|
expect(server_customer_data[:email]).to eq('johnny@appleseed.com')
|
43
45
|
|
44
46
|
StripeMock.stop_client
|
45
47
|
StripeMock.start_client
|
46
48
|
|
47
|
-
server_customer_data = StripeMock.client.get_server_data(:customers)
|
49
|
+
server_customer_data = StripeMock.client.get_server_data(:customers)
|
50
|
+
server_customer_data = server_customer_data[server_customer_data.keys.first][customer.id.to_sym]
|
48
51
|
expect(server_customer_data).to_not be_nil
|
49
52
|
expect(server_customer_data[:email]).to eq('johnny@appleseed.com')
|
50
53
|
end
|
51
54
|
|
52
55
|
|
53
56
|
it "returns a response with symbolized hash keys" do
|
54
|
-
stripe_helper.create_plan(id: 'x')
|
57
|
+
stripe_helper.create_plan(id: 'x', product: product.id)
|
55
58
|
response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', api_key: 'xxx')
|
56
59
|
response.data.keys.each {|k| expect(k).to be_a(Symbol) }
|
57
60
|
end
|
@@ -15,7 +15,7 @@ shared_examples 'Account API' do
|
|
15
15
|
expect(account.id).to match /acct\_/
|
16
16
|
end
|
17
17
|
it 'retrieves all' do
|
18
|
-
accounts = Stripe::Account.
|
18
|
+
accounts = Stripe::Account.list
|
19
19
|
|
20
20
|
expect(accounts).to be_a Stripe::ListObject
|
21
21
|
expect(accounts.data.count).to satisfy { |n| n >= 1 }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Account Link API' do
|
4
|
+
describe 'create account link' do
|
5
|
+
it 'creates an account link' do
|
6
|
+
account_link = Stripe::AccountLink.create(
|
7
|
+
type: 'onboarding',
|
8
|
+
account: 'acct_103ED82ePvKYlo2C',
|
9
|
+
failure_url: 'https://stripe.com',
|
10
|
+
success_url: 'https://stripe.com'
|
11
|
+
)
|
12
|
+
|
13
|
+
expect(account_link).to be_a Stripe::AccountLink
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -8,4 +8,10 @@ shared_examples 'Balance API' do
|
|
8
8
|
expect(balance.available[0].amount).to eq(2000)
|
9
9
|
end
|
10
10
|
|
11
|
+
it "retrieves a stripe instant balance" do
|
12
|
+
StripeMock.set_account_balance(2000)
|
13
|
+
balance = Stripe::Balance.retrieve()
|
14
|
+
expect(balance.instant_available[0].amount).to eq(2000)
|
15
|
+
end
|
16
|
+
|
11
17
|
end
|
@@ -26,7 +26,7 @@ shared_examples 'Balance Transaction API' do
|
|
26
26
|
describe "listing balance transactions" do
|
27
27
|
|
28
28
|
it "retrieves all balance transactions" do
|
29
|
-
disputes = Stripe::BalanceTransaction.
|
29
|
+
disputes = Stripe::BalanceTransaction.list
|
30
30
|
|
31
31
|
expect(disputes.count).to eq(10)
|
32
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')
|
@@ -38,7 +38,7 @@ shared_examples 'Balance Transaction API' do
|
|
38
38
|
transfer_id = Stripe::Transfer.create({ amount: 2730, currency: "usd" })
|
39
39
|
|
40
40
|
# verify transfer currently has no balance transactions
|
41
|
-
transfer_transactions = Stripe::BalanceTransaction.
|
41
|
+
transfer_transactions = Stripe::BalanceTransaction.list({transfer: transfer_id})
|
42
42
|
expect(transfer_transactions.count).to eq(0)
|
43
43
|
|
44
44
|
# verify we can create a new balance transaction associated with the transfer
|
@@ -55,7 +55,7 @@ shared_examples 'Balance Transaction API' do
|
|
55
55
|
stripe_helper.upsert_stripe_object(:balance_transaction, {id: existing_txn_id, transfer: transfer_id})
|
56
56
|
|
57
57
|
# now verify that only these balance transactions are retrieved with the transfer
|
58
|
-
transfer_transactions = Stripe::BalanceTransaction.
|
58
|
+
transfer_transactions = Stripe::BalanceTransaction.list({transfer: transfer_id})
|
59
59
|
expect(transfer_transactions.count).to eq(2)
|
60
60
|
expect(transfer_transactions.map &:id).to include(new_txn_id, existing_txn_id)
|
61
61
|
end
|
@@ -77,7 +77,7 @@ shared_examples 'Bank API' do
|
|
77
77
|
let!(:bank) { customer.sources.create(source: bank_token) }
|
78
78
|
|
79
79
|
it "can retrieve all customer's banks" do
|
80
|
-
retrieved = customer.sources.
|
80
|
+
retrieved = customer.sources.list
|
81
81
|
expect(retrieved.count).to eq(1)
|
82
82
|
end
|
83
83
|
|
@@ -174,7 +174,7 @@ shared_examples 'Bank API' do
|
|
174
174
|
|
175
175
|
customer = Stripe::Customer.retrieve('test_customer_bank')
|
176
176
|
|
177
|
-
list = customer.sources.
|
177
|
+
list = customer.sources.list
|
178
178
|
|
179
179
|
expect(list.object).to eq("list")
|
180
180
|
expect(list.count).to eq(2)
|
@@ -191,7 +191,7 @@ shared_examples 'Bank API' do
|
|
191
191
|
Stripe::Customer.create(id: 'no_banks')
|
192
192
|
customer = Stripe::Customer.retrieve('no_banks')
|
193
193
|
|
194
|
-
list = customer.sources.
|
194
|
+
list = customer.sources.list
|
195
195
|
|
196
196
|
expect(list.object).to eq("list")
|
197
197
|
expect(list.count).to eq(0)
|
@@ -134,7 +134,7 @@ shared_examples 'Card API' do
|
|
134
134
|
let!(:card) { customer.sources.create(source: card_token) }
|
135
135
|
|
136
136
|
it "can retrieve all customer's cards" do
|
137
|
-
retrieved = customer.sources.
|
137
|
+
retrieved = customer.sources.list
|
138
138
|
expect(retrieved.count).to eq(1)
|
139
139
|
end
|
140
140
|
|
@@ -198,7 +198,7 @@ shared_examples 'Card API' do
|
|
198
198
|
let!(:card) { recipient.cards.create(card: card_token) }
|
199
199
|
|
200
200
|
it "can retrieve all recipient's cards" do
|
201
|
-
retrieved = recipient.cards.
|
201
|
+
retrieved = recipient.cards.list
|
202
202
|
expect(retrieved.count).to eq(1)
|
203
203
|
end
|
204
204
|
|
@@ -279,7 +279,7 @@ shared_examples 'Card API' do
|
|
279
279
|
|
280
280
|
customer = Stripe::Customer.retrieve('test_customer_card')
|
281
281
|
|
282
|
-
list = customer.sources.
|
282
|
+
list = customer.sources.list
|
283
283
|
|
284
284
|
expect(list.object).to eq("list")
|
285
285
|
expect(list.count).to eq(2)
|
@@ -296,7 +296,7 @@ shared_examples 'Card API' do
|
|
296
296
|
Stripe::Customer.create(id: 'no_cards')
|
297
297
|
customer = Stripe::Customer.retrieve('no_cards')
|
298
298
|
|
299
|
-
list = customer.sources.
|
299
|
+
list = customer.sources.list
|
300
300
|
|
301
301
|
expect(list.object).to eq("list")
|
302
302
|
expect(list.count).to eq(0)
|
@@ -145,34 +145,30 @@ shared_examples 'Card Token Mocking' do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'generates a card token from another card', oauth: true do
|
148
|
-
token =
|
149
|
-
card: {
|
150
|
-
exp_month: 10,
|
151
|
-
exp_year: 2016,
|
152
|
-
number: '4242424242424242'
|
153
|
-
}
|
154
|
-
)
|
148
|
+
token = StripeMock.generate_card_token(last4: "2244", exp_month: 33, exp_year: 2255)
|
155
149
|
|
156
|
-
cus1 = Stripe::Customer.create(
|
150
|
+
cus1 = Stripe::Customer.create()
|
151
|
+
cus1.source = token
|
152
|
+
cus1.save
|
157
153
|
|
158
154
|
card1 = cus1.sources.data.first
|
159
|
-
expect(card1.last4).to eq(
|
160
|
-
expect(card1.exp_month).to eq(
|
161
|
-
expect(card1.exp_year).to eq(
|
155
|
+
expect(card1.last4).to eq("2244")
|
156
|
+
expect(card1.exp_month).to eq(33)
|
157
|
+
expect(card1.exp_year).to eq(2255)
|
162
158
|
|
163
|
-
card_token = Stripe::Token.create(
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
},
|
168
|
-
ENV['STRIPE_TEST_OAUTH_ACCESS_TOKEN'])
|
159
|
+
card_token = Stripe::Token.create({
|
160
|
+
customer: cus1.id,
|
161
|
+
card: card1.id
|
162
|
+
})
|
169
163
|
|
170
|
-
cus2 = Stripe::Customer.create({
|
164
|
+
cus2 = Stripe::Customer.create({}, ENV['STRIPE_TEST_OAUTH_ACCESS_TOKEN'])
|
165
|
+
cus2.source = card_token.id
|
166
|
+
cus2.save
|
171
167
|
|
172
168
|
card2 = cus2.sources.data.first
|
173
|
-
expect(card2.last4).to eq(
|
174
|
-
expect(card2.exp_month).to eq(
|
175
|
-
expect(card2.exp_year).to eq(
|
169
|
+
expect(card2.last4).to eq("2244")
|
170
|
+
expect(card2.exp_month).to eq(33)
|
171
|
+
expect(card2.exp_year).to eq(2255)
|
176
172
|
end
|
177
173
|
|
178
174
|
it "throws an error if neither card nor customer are provided", :live => true do
|
@@ -163,15 +163,19 @@ shared_examples 'Charge API' do
|
|
163
163
|
end
|
164
164
|
|
165
165
|
it "creates a balance transaction" do
|
166
|
+
amount = 300
|
167
|
+
fee = 10
|
166
168
|
charge = Stripe::Charge.create({
|
167
|
-
amount:
|
169
|
+
amount: amount,
|
168
170
|
currency: 'USD',
|
169
|
-
source: stripe_helper.generate_card_token
|
171
|
+
source: stripe_helper.generate_card_token,
|
172
|
+
application_fee: fee,
|
170
173
|
})
|
171
174
|
bal_trans = Stripe::BalanceTransaction.retrieve(charge.balance_transaction)
|
172
|
-
expect(bal_trans.amount).to eq(
|
173
|
-
expect(bal_trans.fee).to eq(39)
|
175
|
+
expect(bal_trans.amount).to eq(amount)
|
176
|
+
expect(bal_trans.fee).to eq(39 + fee)
|
174
177
|
expect(bal_trans.source).to eq(charge.id)
|
178
|
+
expect(bal_trans.net).to eq(amount - bal_trans.fee)
|
175
179
|
end
|
176
180
|
|
177
181
|
context 'when conversion rate is set' do
|
@@ -274,20 +278,6 @@ shared_examples 'Charge API' do
|
|
274
278
|
}.not_to raise_error
|
275
279
|
end
|
276
280
|
|
277
|
-
it "marks a charge as safe" do
|
278
|
-
original = Stripe::Charge.create({
|
279
|
-
amount: 777,
|
280
|
-
currency: 'USD',
|
281
|
-
source: stripe_helper.generate_card_token
|
282
|
-
})
|
283
|
-
charge = Stripe::Charge.retrieve(original.id)
|
284
|
-
|
285
|
-
charge.mark_as_safe
|
286
|
-
|
287
|
-
updated = Stripe::Charge.retrieve(original.id)
|
288
|
-
expect(updated.fraud_details[:user_report]).to eq "safe"
|
289
|
-
end
|
290
|
-
|
291
281
|
it "does not lose data when updating a charge" do
|
292
282
|
original = Stripe::Charge.create({
|
293
283
|
amount: 777,
|
@@ -353,28 +343,29 @@ shared_examples 'Charge API' do
|
|
353
343
|
end
|
354
344
|
|
355
345
|
it "stores charges for a customer in memory" do
|
356
|
-
|
346
|
+
charges = Stripe::Charge.list(customer: @customer.id)
|
347
|
+
expect(charges.map(&:id)).to eq([@charge.id])
|
357
348
|
end
|
358
349
|
|
359
350
|
it "stores all charges in memory" do
|
360
|
-
expect(Stripe::Charge.
|
351
|
+
expect(Stripe::Charge.list.data.map(&:id).reverse).to eq([@charge.id, @charge2.id])
|
361
352
|
end
|
362
353
|
|
363
354
|
it "defaults count to 10 charges" do
|
364
355
|
11.times { Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token) }
|
365
356
|
|
366
|
-
expect(Stripe::Charge.
|
357
|
+
expect(Stripe::Charge.list.data.count).to eq(10)
|
367
358
|
end
|
368
359
|
|
369
360
|
it "is marked as having more when more objects exist" do
|
370
361
|
11.times { Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token) }
|
371
362
|
|
372
|
-
expect(Stripe::Charge.
|
363
|
+
expect(Stripe::Charge.list.has_more).to eq(true)
|
373
364
|
end
|
374
365
|
|
375
366
|
context "when passing limit" do
|
376
367
|
it "gets that many charges" do
|
377
|
-
expect(Stripe::Charge.
|
368
|
+
expect(Stripe::Charge.list(limit: 1).count).to eq(1)
|
378
369
|
end
|
379
370
|
end
|
380
371
|
end
|
@@ -394,13 +385,13 @@ shared_examples 'Charge API' do
|
|
394
385
|
Stripe::Charge.create(customer: cus.id, amount: 100, currency: "usd")
|
395
386
|
end
|
396
387
|
|
397
|
-
|
388
|
+
all_charges = Stripe::Charge.list
|
398
389
|
default_limit = 10
|
399
|
-
half = Stripe::Charge.
|
390
|
+
half = Stripe::Charge.list(starting_after: all_charges.data.at(1).id)
|
400
391
|
|
401
392
|
expect(half).to be_a(Stripe::ListObject)
|
402
393
|
expect(half.data.count).to eq(default_limit)
|
403
|
-
expect(half.data.first.id).to eq(
|
394
|
+
expect(half.data.first.id).to eq(all_charges.data.at(2).id)
|
404
395
|
end
|
405
396
|
|
406
397
|
|
@@ -472,29 +463,34 @@ shared_examples 'Charge API' do
|
|
472
463
|
|
473
464
|
describe "idempotency" do
|
474
465
|
let(:customer) { Stripe::Customer.create(email: 'johnny@appleseed.com') }
|
475
|
-
let(:
|
466
|
+
let(:charge_params) {{
|
476
467
|
amount: 777,
|
477
468
|
currency: 'USD',
|
478
469
|
customer: customer.id,
|
479
|
-
capture: true
|
470
|
+
capture: true
|
471
|
+
}}
|
472
|
+
let(:charge_headers) {{
|
480
473
|
idempotency_key: 'onceisenough'
|
481
474
|
}}
|
482
475
|
|
483
476
|
it "returns the original charge if the same idempotency_key is passed in" do
|
484
|
-
charge1 = Stripe::Charge.create(
|
485
|
-
charge2 = Stripe::Charge.create(
|
477
|
+
charge1 = Stripe::Charge.create(charge_params, charge_headers)
|
478
|
+
charge2 = Stripe::Charge.create(charge_params, charge_headers)
|
486
479
|
|
487
480
|
expect(charge1).to eq(charge2)
|
488
481
|
end
|
489
482
|
|
490
|
-
|
491
|
-
|
492
|
-
|
483
|
+
context 'different key' do
|
484
|
+
let(:different_charge_headers) {{
|
485
|
+
idempotency_key: 'thisoneisdifferent'
|
486
|
+
}}
|
493
487
|
|
494
|
-
|
495
|
-
|
488
|
+
it "returns different charges if different idempotency_keys are used for each charge" do
|
489
|
+
charge1 = Stripe::Charge.create(charge_params, charge_headers)
|
490
|
+
charge2 = Stripe::Charge.create(charge_params, different_charge_headers)
|
496
491
|
|
497
|
-
|
492
|
+
expect(charge1).not_to eq(charge2)
|
493
|
+
end
|
498
494
|
end
|
499
495
|
end
|
500
496
|
|