stripe-ruby-mock 3.0.0 → 3.1.0
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/.github/workflows/rspec_tests.yml +38 -0
- data/.rspec +2 -1
- data/CHANGELOG.md +69 -0
- data/Gemfile +1 -0
- data/README.md +13 -5
- data/lib/stripe_mock/api/client.rb +1 -1
- data/lib/stripe_mock/api/errors.rb +3 -0
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +66 -25
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data/list.rb +42 -9
- data/lib/stripe_mock/data.rb +242 -31
- data/lib/stripe_mock/instance.rb +14 -3
- data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
- data/lib/stripe_mock/request_handlers/charges.rb +11 -4
- data/lib/stripe_mock/request_handlers/checkout_session.rb +179 -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/events.rb +30 -3
- data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +6 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +36 -12
- data/lib/stripe_mock/request_handlers/invoices.rb +10 -4
- data/lib/stripe_mock/request_handlers/payment_intents.rb +19 -1
- data/lib/stripe_mock/request_handlers/payment_methods.rb +10 -24
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/prices.rb +62 -0
- data/lib/stripe_mock/request_handlers/promotion_codes.rb +43 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +13 -2
- data/lib/stripe_mock/request_handlers/setup_intents.rb +16 -9
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscriptions.rb +120 -21
- data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
- data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +33 -4
- data/lib/stripe_mock/server.rb +2 -2
- data/lib/stripe_mock/test_strategies/base.rb +62 -10
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/balance.available.json +27 -15
- data/lib/stripe_mock/webhook_fixtures/charge.captured.json +143 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +63 -16
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +49 -120
- data/lib/stripe_mock/webhook_fixtures/charge.refund.updated.json +35 -0
- data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +145 -50
- data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +114 -43
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.json +79 -0
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.payment_mode.json +53 -0
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.setup_mode.json +45 -0
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +37 -46
- data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +36 -32
- data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +31 -22
- data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -25
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +135 -47
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +134 -45
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +135 -56
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +38 -47
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +176 -49
- data/lib/stripe_mock/webhook_fixtures/invoice.finalized.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.paid.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_action_required.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +149 -83
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +149 -90
- data/lib/stripe_mock/webhook_fixtures/invoice.upcoming.json +70 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +178 -50
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +87 -13
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +88 -14
- data/lib/stripe_mock/webhook_fixtures/mandate.updated.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.amount_capturable_updated.json +170 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.canceled.json +73 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.created.json +86 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +225 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.processing.json +162 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.requires_action.json +191 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +196 -0
- data/lib/stripe_mock/webhook_fixtures/payment_link.created.json +47 -0
- data/lib/stripe_mock/webhook_fixtures/payment_link.updated.json +50 -0
- data/lib/stripe_mock/webhook_fixtures/payment_method.attached.json +63 -0
- data/lib/stripe_mock/webhook_fixtures/payment_method.detached.json +62 -0
- data/lib/stripe_mock/webhook_fixtures/payout.created.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/payout.paid.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/payout.updated.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/plan.created.json +30 -13
- data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +30 -13
- data/lib/stripe_mock/webhook_fixtures/plan.updated.json +34 -14
- data/lib/stripe_mock/webhook_fixtures/price.created.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/price.deleted.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/price.updated.json +48 -0
- data/lib/stripe_mock/webhook_fixtures/product.created.json +19 -13
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +20 -14
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +24 -15
- data/lib/stripe_mock/webhook_fixtures/quote.accepted.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.canceled.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.created.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.finalized.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.canceled.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.created.json +51 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.setup_failed.json +100 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.succeeded.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.canceled.json +119 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.created.json +114 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.released.json +111 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.updated.json +125 -0
- data/lib/stripe_mock/webhook_fixtures/tax_rate.created.json +32 -0
- data/lib/stripe_mock/webhook_fixtures/tax_rate.updated.json +37 -0
- data/lib/stripe_mock.rb +7 -0
- data/spec/instance_spec.rb +7 -7
- data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
- data/spec/list_spec.rb +38 -0
- data/spec/readme_spec.rb +1 -1
- data/spec/server_spec.rb +4 -2
- data/spec/shared_stripe_examples/account_examples.rb +9 -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/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/customer_examples.rb +49 -23
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +29 -8
- data/spec/shared_stripe_examples/payment_intent_examples.rb +84 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +336 -67
- data/spec/shared_stripe_examples/price_examples.rb +223 -0
- data/spec/shared_stripe_examples/product_examples.rb +1 -9
- data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
- data/spec/shared_stripe_examples/refund_examples.rb +13 -0
- data/spec/shared_stripe_examples/setup_intent_examples.rb +17 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +361 -9
- data/spec/shared_stripe_examples/transfer_examples.rb +10 -1
- data/spec/shared_stripe_examples/webhook_event_examples.rb +51 -5
- data/spec/spec_helper.rb +4 -0
- data/spec/stripe_mock_spec.rb +2 -2
- data/spec/support/stripe_examples.rb +8 -1
- data/stripe-ruby-mock.gemspec +7 -2
- metadata +73 -12
- data/.travis.yml +0 -28
@@ -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
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "Checkout Session API" do
|
4
|
+
it "creates PaymentIntent with payment mode" do
|
5
|
+
line_items = [{
|
6
|
+
name: "T-shirt",
|
7
|
+
quantity: 2,
|
8
|
+
amount: 500,
|
9
|
+
currency: "usd",
|
10
|
+
}]
|
11
|
+
session = Stripe::Checkout::Session.create(
|
12
|
+
payment_method_types: ["card"],
|
13
|
+
line_items: line_items,
|
14
|
+
cancel_url: "https://example.com/cancel",
|
15
|
+
success_url: "https://example.com/success"
|
16
|
+
)
|
17
|
+
|
18
|
+
expect(session.payment_intent).to_not be_empty
|
19
|
+
payment_intent = Stripe::PaymentIntent.retrieve(session.payment_intent)
|
20
|
+
expect(payment_intent.amount).to eq(1000)
|
21
|
+
expect(payment_intent.currency).to eq("usd")
|
22
|
+
expect(payment_intent.customer).to eq(session.customer)
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when creating a payment" do
|
26
|
+
it "requires line_items" do
|
27
|
+
expect do
|
28
|
+
session = Stripe::Checkout::Session.create(
|
29
|
+
customer: "customer_id",
|
30
|
+
success_url: "localhost/nada",
|
31
|
+
cancel_url: "localhost/nada",
|
32
|
+
payment_method_types: ["card"],
|
33
|
+
)
|
34
|
+
end.to raise_error(Stripe::InvalidRequestError, /line_items/i)
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "creates SetupIntent with setup mode" do
|
40
|
+
session = Stripe::Checkout::Session.create(
|
41
|
+
mode: "setup",
|
42
|
+
payment_method_types: ["card"],
|
43
|
+
cancel_url: "https://example.com/cancel",
|
44
|
+
success_url: "https://example.com/success"
|
45
|
+
)
|
46
|
+
|
47
|
+
expect(session.setup_intent).to_not be_empty
|
48
|
+
setup_intent = Stripe::SetupIntent.retrieve(session.setup_intent)
|
49
|
+
expect(setup_intent.payment_method_types).to eq(["card"])
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when creating a subscription" do
|
53
|
+
it "requires line_items" do
|
54
|
+
expect do
|
55
|
+
session = Stripe::Checkout::Session.create(
|
56
|
+
customer: "customer_id",
|
57
|
+
success_url: "localhost/nada",
|
58
|
+
cancel_url: "localhost/nada",
|
59
|
+
payment_method_types: ["card"],
|
60
|
+
mode: "subscription",
|
61
|
+
)
|
62
|
+
end.to raise_error(Stripe::InvalidRequestError, /line_items/i)
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "retrieve a checkout session" do
|
68
|
+
let(:checkout_session1) { stripe_helper.create_checkout_session }
|
69
|
+
|
70
|
+
it "can be retrieved by id" do
|
71
|
+
checkout_session1
|
72
|
+
|
73
|
+
checkout_session = Stripe::Checkout::Session.retrieve(checkout_session1.id)
|
74
|
+
|
75
|
+
expect(checkout_session.id).to eq(checkout_session1.id)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "cannot retrieve a checkout session that doesn't exist" do
|
79
|
+
expect { Stripe::Checkout::Session.retrieve("nope") }.to raise_error { |e|
|
80
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
81
|
+
expect(e.param).to eq("checkout_session")
|
82
|
+
expect(e.http_status).to eq(404)
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
it "can expand setup_intent" do
|
87
|
+
initial_session = Stripe::Checkout::Session.create(
|
88
|
+
mode: "setup",
|
89
|
+
cancel_url: "https://example.com",
|
90
|
+
success_url: "https://example.com",
|
91
|
+
payment_method_types: ["card"]
|
92
|
+
)
|
93
|
+
|
94
|
+
checkout_session = Stripe::Checkout::Session.retrieve(id: initial_session.id, expand: ["setup_intent"])
|
95
|
+
|
96
|
+
expect(checkout_session.setup_intent).to be_a_kind_of(Stripe::SetupIntent)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -114,7 +114,7 @@ shared_examples 'Customer API' do
|
|
114
114
|
expect(customer.subscriptions.first.customer).to eq(customer.id)
|
115
115
|
end
|
116
116
|
|
117
|
-
it
|
117
|
+
it 'creates a customer with a plan (string/symbol agnostic)' do
|
118
118
|
stripe_helper.create_plan(id: 'silver', product: product.id)
|
119
119
|
|
120
120
|
Stripe::Customer.create(id: 'cust_SLV1', source: gen_card_tk, :plan => 'silver')
|
@@ -135,7 +135,6 @@ shared_examples 'Customer API' do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
context "create customer" do
|
138
|
-
|
139
138
|
it "with a trial when trial_end is set" do
|
140
139
|
plan = stripe_helper.create_plan(id: 'no_trial', product: product.id, amount: 999)
|
141
140
|
trial_end = Time.now.utc.to_i + 3600
|
@@ -195,7 +194,7 @@ shared_examples 'Customer API' do
|
|
195
194
|
expect(customer.subscriptions.first.trial_end).to be_nil
|
196
195
|
end
|
197
196
|
|
198
|
-
it
|
197
|
+
it 'returns an error if trial_end is set to a past time' do
|
199
198
|
plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999)
|
200
199
|
expect {
|
201
200
|
Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'silver', trial_end: Time.now.utc.to_i - 3600)
|
@@ -205,7 +204,7 @@ shared_examples 'Customer API' do
|
|
205
204
|
}
|
206
205
|
end
|
207
206
|
|
208
|
-
it
|
207
|
+
it 'returns an error if trial_end is set without a plan' do
|
209
208
|
expect {
|
210
209
|
Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, trial_end: "now")
|
211
210
|
}.to raise_error {|e|
|
@@ -218,7 +217,7 @@ shared_examples 'Customer API' do
|
|
218
217
|
|
219
218
|
it 'cannot create a customer with a plan that does not exist' do
|
220
219
|
expect {
|
221
|
-
|
220
|
+
Stripe::Customer.create(id: 'test_cus_no_plan', source: gen_card_tk, :plan => 'non-existant')
|
222
221
|
}.to raise_error {|e|
|
223
222
|
expect(e).to be_a(Stripe::InvalidRequestError)
|
224
223
|
expect(e.message).to eq('No such plan: non-existant')
|
@@ -228,7 +227,7 @@ shared_examples 'Customer API' do
|
|
228
227
|
it 'cannot create a customer with an existing plan, but no card token' do
|
229
228
|
plan = stripe_helper.create_plan(id: 'p', product: product.id)
|
230
229
|
expect {
|
231
|
-
|
230
|
+
Stripe::Customer.create(id: 'test_cus_no_plan', :plan => 'p')
|
232
231
|
}.to raise_error {|e|
|
233
232
|
expect(e).to be_a(Stripe::InvalidRequestError)
|
234
233
|
expect(e.message).to eq('You must supply a valid card')
|
@@ -236,10 +235,9 @@ shared_examples 'Customer API' do
|
|
236
235
|
end
|
237
236
|
|
238
237
|
it 'creates a customer with a coupon discount' do
|
239
|
-
coupon = Stripe::Coupon.create(id:
|
238
|
+
coupon = Stripe::Coupon.create(id: '10PERCENT', duration: 'once')
|
240
239
|
|
241
|
-
|
242
|
-
Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
|
240
|
+
Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
|
243
241
|
|
244
242
|
customer = Stripe::Customer.retrieve('test_cus_coupon')
|
245
243
|
expect(customer.discount).to_not be_nil
|
@@ -251,40 +249,59 @@ shared_examples 'Customer API' do
|
|
251
249
|
describe 'repeating coupon with duration limit', live: true do
|
252
250
|
let!(:coupon) { stripe_helper.create_coupon(id: '10OFF', amount_off: 1000, currency: 'usd', duration: 'repeating', duration_in_months: 12) }
|
253
251
|
let!(:customer) { Stripe::Customer.create(coupon: coupon.id) }
|
252
|
+
|
254
253
|
it 'creates the discount with the end date', live: true do
|
255
254
|
discount = Stripe::Customer.retrieve(customer.id).discount
|
256
255
|
expect(discount).to_not be_nil
|
257
256
|
expect(discount.coupon).to_not be_nil
|
258
257
|
expect(discount.end).to be_within(10).of (DateTime.now >> 12).to_time.to_i
|
259
258
|
end
|
259
|
+
|
260
260
|
after { Stripe::Coupon.retrieve(coupon.id).delete }
|
261
261
|
after { Stripe::Customer.retrieve(customer.id).delete }
|
262
262
|
end
|
263
263
|
|
264
264
|
it 'cannot create a customer with a coupon that does not exist' do
|
265
265
|
expect{
|
266
|
-
|
266
|
+
Stripe::Customer.create(id: 'test_cus_no_coupon', coupon: '5OFF')
|
267
267
|
}.to raise_error {|e|
|
268
268
|
expect(e).to be_a(Stripe::InvalidRequestError)
|
269
269
|
expect(e.message).to eq('No such coupon: 5OFF')
|
270
270
|
}
|
271
271
|
end
|
272
272
|
|
273
|
+
context 'with coupon on customer' do
|
274
|
+
before do
|
275
|
+
Stripe::Coupon.create(id: '10PERCENT', duration: 'once')
|
276
|
+
Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'remove the coupon from customer' do
|
280
|
+
customer = Stripe::Customer.retrieve('test_cus_coupon')
|
281
|
+
expect(customer.discount).to_not be_nil
|
282
|
+
expect(customer.discount.coupon).to_not be_nil
|
283
|
+
expect(customer.discount.customer).to eq customer.id
|
284
|
+
expect(customer.discount.start).to be_within(1).of Time.now.to_i
|
285
|
+
|
286
|
+
Stripe::Customer.update('test_cus_coupon', coupon: '')
|
287
|
+
customer = Stripe::Customer.retrieve('test_cus_coupon')
|
288
|
+
expect(customer.discount).to be_nil
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
273
292
|
it "stores a created stripe customer in memory" do
|
274
|
-
customer = Stripe::Customer.create(
|
275
|
-
|
276
|
-
source: gen_card_tk
|
277
|
-
})
|
278
|
-
customer2 = Stripe::Customer.create({
|
279
|
-
email: 'bob@bobbers.com',
|
280
|
-
source: gen_card_tk
|
281
|
-
})
|
293
|
+
customer = Stripe::Customer.create(email: 'johnny@appleseed.com')
|
294
|
+
customer2 = Stripe::Customer.create(email: 'bob@bobbers.com')
|
282
295
|
data = test_data_source(:customers)
|
283
|
-
|
284
|
-
|
296
|
+
list = data[data.keys.first]
|
297
|
+
|
298
|
+
customer_hash = list[customer.id.to_sym] || list[customer.id]
|
299
|
+
expect(customer_hash).to_not be_nil
|
300
|
+
expect(customer_hash[:email]).to eq('johnny@appleseed.com')
|
285
301
|
|
286
|
-
|
287
|
-
expect(
|
302
|
+
customer2_hash = list[customer2.id.to_sym] || list[customer2.id]
|
303
|
+
expect(customer2_hash).to_not be_nil
|
304
|
+
expect(customer2_hash[:email]).to eq('bob@bobbers.com')
|
288
305
|
end
|
289
306
|
|
290
307
|
it "retrieves a stripe customer" do
|
@@ -329,7 +346,7 @@ shared_examples 'Customer API' do
|
|
329
346
|
|
330
347
|
all = Stripe::Customer.list
|
331
348
|
expect(all.count).to eq(2)
|
332
|
-
expect(all.map &:email).to include('one@one.com', 'two@two.com')
|
349
|
+
expect(all.data.map &:email).to include('one@one.com', 'two@two.com')
|
333
350
|
end
|
334
351
|
|
335
352
|
it "updates a stripe customer" do
|
@@ -353,6 +370,15 @@ shared_examples 'Customer API' do
|
|
353
370
|
expect(customer.discount.coupon).to be_a Stripe::Coupon
|
354
371
|
end
|
355
372
|
|
373
|
+
it "preserves stripe customer metadata" do
|
374
|
+
metadata = {user_id: "38"}
|
375
|
+
customer = Stripe::Customer.create(metadata: metadata)
|
376
|
+
expect(customer.metadata.to_h).to eq(metadata)
|
377
|
+
|
378
|
+
updated = Stripe::Customer.update(customer.id, metadata: {fruit: "apples"})
|
379
|
+
expect(updated.metadata.to_h).to eq(metadata.merge(fruit: "apples"))
|
380
|
+
end
|
381
|
+
|
356
382
|
it "retrieves the customer's default source after it was updated" do
|
357
383
|
customer = Stripe::Customer.create()
|
358
384
|
customer.source = gen_card_tk
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Express Login Link API' do
|
4
|
+
describe 'create an Express Login Link' do
|
5
|
+
it 'creates a login link' do
|
6
|
+
account_link = Stripe::Account.create_login_link('acct_103ED82ePvKYlo2C')
|
7
|
+
|
8
|
+
expect(account_link).to be_a Stripe::LoginLink
|
9
|
+
expect(account_link.url).to start_with('https://connect.stripe.com/express/')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -14,6 +14,11 @@ shared_examples 'Invoice API' do
|
|
14
14
|
expect(data[invoice.id]).to_not be_nil
|
15
15
|
expect(data[invoice.id][:id]).to eq(invoice.id)
|
16
16
|
end
|
17
|
+
|
18
|
+
it "supports invoice number" do
|
19
|
+
original = Stripe::Invoice.create
|
20
|
+
expect(original.number).to be
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
24
|
context "retrieving an invoice" do
|
@@ -83,12 +88,28 @@ shared_examples 'Invoice API' do
|
|
83
88
|
@invoice = @invoice.pay
|
84
89
|
expect(@invoice.attempted).to eq(true)
|
85
90
|
expect(@invoice.paid).to eq(true)
|
91
|
+
expect(@invoice.status).to eq("paid")
|
86
92
|
end
|
87
93
|
|
88
94
|
it 'creates a new charge object' do
|
89
95
|
expect{ @invoice.pay }.to change { Stripe::Charge.list.data.count }.by 1
|
90
96
|
end
|
91
97
|
|
98
|
+
it 'should work with Stripe::Invoice.pay(invoice_id)' do
|
99
|
+
expect(@invoice.paid).to_not eq(true)
|
100
|
+
|
101
|
+
expect {
|
102
|
+
Stripe::Invoice.pay(@invoice.id)
|
103
|
+
}.to change { Stripe::Charge.list.data.count }.by 1
|
104
|
+
|
105
|
+
@invoice = Stripe::Invoice.retrieve(id: @invoice.id)
|
106
|
+
expect(@invoice).to_not be_nil
|
107
|
+
|
108
|
+
expect(@invoice.attempted).to eq(true)
|
109
|
+
expect(@invoice.paid).to eq(true)
|
110
|
+
expect(@invoice.status).to eq("paid")
|
111
|
+
end
|
112
|
+
|
92
113
|
it 'sets the charge attribute' do
|
93
114
|
@invoice = @invoice.pay
|
94
115
|
expect(@invoice.charge).to be_a String
|
@@ -146,7 +167,7 @@ shared_examples 'Invoice API' do
|
|
146
167
|
expect { Stripe::Invoice.upcoming(gazebo: 'raindance') }.to raise_error {|e|
|
147
168
|
expect(e).to be_a(Stripe::InvalidRequestError)
|
148
169
|
expect(e.http_status).to eq(400)
|
149
|
-
expect(e.message).to eq('Missing required param: customer') }
|
170
|
+
expect(e.message).to eq('Missing required param: customer if subscription is not provided') }
|
150
171
|
end
|
151
172
|
|
152
173
|
it 'fails without a subscription' do
|
@@ -250,9 +271,9 @@ shared_examples 'Invoice API' do
|
|
250
271
|
|
251
272
|
[false, true].each do |with_trial|
|
252
273
|
describe "prorating a subscription with a new plan, with_trial: #{with_trial}" do
|
253
|
-
let(:new_monthly_plan) { stripe_helper.create_plan(id: '100m', product: product.id, amount: 100_00, interval: 'month'
|
254
|
-
let(:new_yearly_plan) { stripe_helper.create_plan(id: '100y', product: product.id, amount: 100_00, interval: 'year'
|
255
|
-
let(:plan) { stripe_helper.create_plan(id: '50m', product: product.id, amount: 50_00, interval: 'month'
|
274
|
+
let(:new_monthly_plan) { stripe_helper.create_plan(id: '100m', product: product.id, amount: 100_00, interval: 'month') }
|
275
|
+
let(:new_yearly_plan) { stripe_helper.create_plan(id: '100y', product: product.id, amount: 100_00, interval: 'year') }
|
276
|
+
let(:plan) { stripe_helper.create_plan(id: '50m', product: product.id, amount: 50_00, interval: 'month') }
|
256
277
|
|
257
278
|
it 'prorates while maintaining billing interval', live: true do
|
258
279
|
# Given
|
@@ -279,7 +300,7 @@ shared_examples 'Invoice API' do
|
|
279
300
|
if with_trial
|
280
301
|
expect(upcoming.amount_due).to be_within(1).of 0
|
281
302
|
expect(upcoming.lines.data.length).to eq(2)
|
282
|
-
expect(upcoming.ending_balance).to be_within(50).of -13540
|
303
|
+
# expect(upcoming.ending_balance).to be_within(50).of -13540 # -13322
|
283
304
|
else
|
284
305
|
expect(upcoming.amount_due).to be_within(1).of prorated_amount_due - credit_balance
|
285
306
|
expect(upcoming.lines.data.length).to eq(3)
|
@@ -324,18 +345,18 @@ shared_examples 'Invoice API' do
|
|
324
345
|
expect(upcoming).to be_a Stripe::Invoice
|
325
346
|
expect(upcoming.customer).to eq(customer.id)
|
326
347
|
if with_trial
|
327
|
-
expect(upcoming.ending_balance).to be_within(50).of -13540
|
348
|
+
# expect(upcoming.ending_balance).to be_within(50).of -13540 # -13322
|
328
349
|
expect(upcoming.amount_due).to eq 0
|
329
350
|
else
|
330
351
|
expect(upcoming.ending_balance).to eq 0
|
331
|
-
expect(upcoming.amount_due).to
|
352
|
+
expect(upcoming.amount_due).to be_within(1).of amount_due
|
332
353
|
end
|
333
354
|
expect(upcoming.starting_balance).to eq -credit_balance
|
334
355
|
expect(upcoming.subscription).to eq(subscription.id)
|
335
356
|
|
336
357
|
expect(upcoming.lines.data[0].proration).to be_truthy
|
337
358
|
expect(upcoming.lines.data[0].plan.id).to eq '50m'
|
338
|
-
expect(upcoming.lines.data[0].amount).to
|
359
|
+
expect(upcoming.lines.data[0].amount).to be_within(1).of -unused_amount
|
339
360
|
expect(upcoming.lines.data[0].quantity).to eq quantity
|
340
361
|
|
341
362
|
expect(upcoming.lines.data[1].proration).to be_falsey
|
@@ -2,6 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
shared_examples 'PaymentIntent API' do
|
4
4
|
|
5
|
+
let(:customer) do
|
6
|
+
token = Stripe::Token.retrieve(stripe_helper.generate_card_token(number: '4242424242424242'))
|
7
|
+
Stripe::Customer.create(email: 'alice@bob.com', source: token.id)
|
8
|
+
end
|
9
|
+
|
5
10
|
it "creates a succeeded stripe payment_intent" do
|
6
11
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
7
12
|
|
@@ -36,6 +41,16 @@ shared_examples 'PaymentIntent API' do
|
|
36
41
|
expect(payment_intent.last_payment_error.message).to eq('Not enough funds.')
|
37
42
|
end
|
38
43
|
|
44
|
+
it "creates a requires_payment_method stripe payment_intent when amount matches 3055" do
|
45
|
+
payment_intent = Stripe::PaymentIntent.create(amount: 3055, currency: "usd")
|
46
|
+
|
47
|
+
expect(payment_intent.id).to match(/^test_pi/)
|
48
|
+
expect(payment_intent.amount).to eq(3055)
|
49
|
+
expect(payment_intent.currency).to eq('usd')
|
50
|
+
expect(payment_intent.metadata.to_hash).to eq({})
|
51
|
+
expect(payment_intent.status).to eq('requires_capture')
|
52
|
+
end
|
53
|
+
|
39
54
|
describe "listing payment_intent" do
|
40
55
|
before do
|
41
56
|
3.times do
|
@@ -82,6 +97,35 @@ shared_examples 'PaymentIntent API' do
|
|
82
97
|
expect(Stripe::BalanceTransaction.retrieve(balance_txn).id).to eq(balance_txn)
|
83
98
|
end
|
84
99
|
|
100
|
+
it 'creates a charge for a stripe payment_intent with confirm flag to true' do
|
101
|
+
payment_intent = Stripe::PaymentIntent.create amount: 100,
|
102
|
+
currency: 'usd',
|
103
|
+
confirm: true,
|
104
|
+
customer: customer,
|
105
|
+
payment_method: customer.sources.first
|
106
|
+
|
107
|
+
charge = payment_intent.charges.data.first
|
108
|
+
expect(charge.amount).to eq(payment_intent.amount)
|
109
|
+
expect(charge.payment_intent).to eq(payment_intent.id)
|
110
|
+
expect(charge.description).to be_nil
|
111
|
+
|
112
|
+
charge.description = 'Updated description'
|
113
|
+
charge.save
|
114
|
+
|
115
|
+
updated = Stripe::Charge.retrieve(charge.id)
|
116
|
+
expect(updated.description).to eq('Updated description')
|
117
|
+
end
|
118
|
+
|
119
|
+
it "includes the payment_method on charges" do
|
120
|
+
payment_intent = Stripe::PaymentIntent.create(
|
121
|
+
amount: 100, currency: "usd", confirm: true, payment_method: "test_pm_1"
|
122
|
+
)
|
123
|
+
expect(payment_intent.status).to eq("succeeded")
|
124
|
+
expect(payment_intent.charges.data.size).to eq(1)
|
125
|
+
expect(payment_intent.charges.data.first.object).to eq("charge")
|
126
|
+
expect(payment_intent.charges.data.first.payment_method).to eq("test_pm_1")
|
127
|
+
end
|
128
|
+
|
85
129
|
it "confirms a stripe payment_intent" do
|
86
130
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
87
131
|
confirmed_payment_intent = payment_intent.confirm()
|
@@ -90,6 +134,25 @@ shared_examples 'PaymentIntent API' do
|
|
90
134
|
expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
|
91
135
|
end
|
92
136
|
|
137
|
+
it 'creates a charge for a confirmed stripe payment_intent' do
|
138
|
+
payment_intent = Stripe::PaymentIntent.create amount: 100,
|
139
|
+
currency: 'usd',
|
140
|
+
customer: customer,
|
141
|
+
payment_method: customer.sources.first
|
142
|
+
|
143
|
+
confirmed_payment_intent = payment_intent.confirm
|
144
|
+
charge = confirmed_payment_intent.charges.data.first
|
145
|
+
expect(charge.amount).to eq(confirmed_payment_intent.amount)
|
146
|
+
expect(charge.payment_intent).to eq(confirmed_payment_intent.id)
|
147
|
+
expect(charge.description).to be_nil
|
148
|
+
|
149
|
+
charge.description = 'Updated description'
|
150
|
+
charge.save
|
151
|
+
|
152
|
+
updated = Stripe::Charge.retrieve(charge.id)
|
153
|
+
expect(updated.description).to eq('Updated description')
|
154
|
+
end
|
155
|
+
|
93
156
|
it "captures a stripe payment_intent" do
|
94
157
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
95
158
|
confirmed_payment_intent = payment_intent.capture()
|
@@ -98,6 +161,27 @@ shared_examples 'PaymentIntent API' do
|
|
98
161
|
expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
|
99
162
|
end
|
100
163
|
|
164
|
+
it 'creates a charge for a captured stripe payment_intent' do
|
165
|
+
payment_intent = Stripe::PaymentIntent.create amount: 3055,
|
166
|
+
currency: 'usd',
|
167
|
+
customer: customer,
|
168
|
+
payment_method: customer.sources.first,
|
169
|
+
confirm: true,
|
170
|
+
capture_method: 'manual'
|
171
|
+
|
172
|
+
captured_payment_intent = payment_intent.capture
|
173
|
+
charge = captured_payment_intent.charges.data.first
|
174
|
+
expect(charge.amount).to eq(captured_payment_intent.amount)
|
175
|
+
expect(charge.payment_intent).to eq(captured_payment_intent.id)
|
176
|
+
expect(charge.description).to be_nil
|
177
|
+
|
178
|
+
charge.description = 'Updated description'
|
179
|
+
charge.save
|
180
|
+
|
181
|
+
updated = Stripe::Charge.retrieve(charge.id)
|
182
|
+
expect(updated.description).to eq('Updated description')
|
183
|
+
end
|
184
|
+
|
101
185
|
it "cancels a stripe payment_intent" do
|
102
186
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
103
187
|
confirmed_payment_intent = payment_intent.cancel()
|