stripe-ruby-mock 3.1.0.rc3 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec_tests.yml +38 -0
- data/.rspec +2 -1
- data/CHANGELOG.md +36 -0
- data/Gemfile +0 -5
- data/README.md +6 -4
- data/lib/stripe_mock/api/client.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +65 -26
- data/lib/stripe_mock/data.rb +80 -11
- data/lib/stripe_mock/instance.rb +7 -3
- data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
- data/lib/stripe_mock/request_handlers/charges.rb +25 -1
- data/lib/stripe_mock/request_handlers/checkout_session.rb +158 -1
- data/lib/stripe_mock/request_handlers/customers.rb +12 -1
- data/lib/stripe_mock/request_handlers/events.rb +30 -3
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +1 -0
- data/lib/stripe_mock/request_handlers/helpers/search_helpers.rb +67 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +28 -9
- data/lib/stripe_mock/request_handlers/invoices.rb +16 -2
- data/lib/stripe_mock/request_handlers/payment_intents.rb +23 -3
- data/lib/stripe_mock/request_handlers/payment_methods.rb +5 -1
- data/lib/stripe_mock/request_handlers/prices.rb +31 -4
- data/lib/stripe_mock/request_handlers/products.rb +14 -5
- 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/subscriptions.rb +103 -5
- data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +5 -4
- data/lib/stripe_mock/test_strategies/base.rb +51 -24
- 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 +26 -20
- 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 +118 -79
- 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 +85 -53
- 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 +4 -1
- data/spec/instance_spec.rb +3 -1
- data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
- data/spec/readme_spec.rb +1 -1
- data/spec/shared_stripe_examples/account_examples.rb +9 -1
- data/spec/shared_stripe_examples/bank_token_examples.rb +5 -7
- data/spec/shared_stripe_examples/charge_examples.rb +97 -0
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/customer_examples.rb +56 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +107 -1
- data/spec/shared_stripe_examples/payment_intent_examples.rb +136 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +32 -27
- data/spec/shared_stripe_examples/price_examples.rb +111 -2
- data/spec/shared_stripe_examples/product_examples.rb +68 -0
- 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 +276 -6
- 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 +1 -1
- data/spec/support/stripe_examples.rb +3 -1
- data/stripe-ruby-mock.gemspec +3 -4
- metadata +59 -29
- data/.travis.yml +0 -25
- data/lib/stripe_mock/request_handlers/checkout.rb +0 -15
- data/spec/shared_stripe_examples/checkout_examples.rb +0 -47
@@ -349,6 +349,62 @@ shared_examples 'Customer API' do
|
|
349
349
|
expect(all.data.map &:email).to include('one@one.com', 'two@two.com')
|
350
350
|
end
|
351
351
|
|
352
|
+
context "search" do
|
353
|
+
# the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
|
354
|
+
it "searches customers for exact matches", :aggregate_failures do
|
355
|
+
response = Stripe::Customer.search({query: 'email:"one@one.com"'}, stripe_version: '2020-08-27')
|
356
|
+
expect(response.data.size).to eq(0)
|
357
|
+
|
358
|
+
one = Stripe::Customer.create(email: 'one@one.com', name: 'one', phone: '1111111111', metadata: {key: 'uno'})
|
359
|
+
two = Stripe::Customer.create(email: 'two@two.com', name: 'two', phone: '2222222222', metadata: {key: 'dos'})
|
360
|
+
|
361
|
+
response = Stripe::Customer.search({query: 'email:"one@one.com"'}, stripe_version: '2020-08-27')
|
362
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
363
|
+
|
364
|
+
response = Stripe::Customer.search({query: 'name:"two"'}, stripe_version: '2020-08-27')
|
365
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
366
|
+
|
367
|
+
response = Stripe::Customer.search({query: 'phone:"2222222222"'}, stripe_version: '2020-08-27')
|
368
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
369
|
+
|
370
|
+
response = Stripe::Customer.search({query: 'metadata["key"]:"uno"'}, stripe_version: '2020-08-27')
|
371
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
372
|
+
end
|
373
|
+
|
374
|
+
it "respects limit", :aggregate_failures do
|
375
|
+
one = Stripe::Customer.create(email: 'one@one.com', name: 'one')
|
376
|
+
two = Stripe::Customer.create(email: 'two@two.com', name: 'one')
|
377
|
+
three = Stripe::Customer.create(email: 'three@three.com', name: 'one')
|
378
|
+
four = Stripe::Customer.create(email: 'four@four.com', name: 'one')
|
379
|
+
five = Stripe::Customer.create(email: 'five@five.com', name: 'one')
|
380
|
+
six = Stripe::Customer.create(email: 'six@six.com', name: 'one')
|
381
|
+
seven = Stripe::Customer.create(email: 'seven@seven.com', name: 'one')
|
382
|
+
eight = Stripe::Customer.create(email: 'eight@eight.com', name: 'one')
|
383
|
+
nine = Stripe::Customer.create(email: 'nine@nine.com', name: 'one')
|
384
|
+
ten = Stripe::Customer.create(email: 'ten@ten.com', name: 'one')
|
385
|
+
eleven = Stripe::Customer.create(email: 'eleven@eleven.com', name: 'one')
|
386
|
+
|
387
|
+
response = Stripe::Customer.search({query: 'name:"one"'}, stripe_version: '2020-08-27')
|
388
|
+
expect(response.data.size).to eq(10)
|
389
|
+
response = Stripe::Customer.search({query: 'name:"one"', limit: 1}, stripe_version: '2020-08-27')
|
390
|
+
expect(response.data.size).to eq(1)
|
391
|
+
end
|
392
|
+
|
393
|
+
it "reports search errors", :aggregate_failures do
|
394
|
+
expect {
|
395
|
+
Stripe::Customer.search({limit: 1}, stripe_version: '2020-08-27')
|
396
|
+
}.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
|
397
|
+
|
398
|
+
expect {
|
399
|
+
Stripe::Customer.search({query: 'asdf'}, stripe_version: '2020-08-27')
|
400
|
+
}.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
|
401
|
+
|
402
|
+
expect {
|
403
|
+
Stripe::Customer.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
|
404
|
+
}.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `customers`./)
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
352
408
|
it "updates a stripe customer" do
|
353
409
|
original = Stripe::Customer.create(id: 'test_customer_update')
|
354
410
|
email = original.email
|
@@ -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
|
@@ -74,6 +79,88 @@ shared_examples 'Invoice API' do
|
|
74
79
|
end
|
75
80
|
end
|
76
81
|
|
82
|
+
context "searching invoices" do
|
83
|
+
# the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
|
84
|
+
it "searches invoices for exact matches", :aggregate_failures do
|
85
|
+
response = Stripe::Invoice.search({query: 'currency:"usd"'}, stripe_version: '2020-08-27')
|
86
|
+
expect(response.data.size).to eq(0)
|
87
|
+
|
88
|
+
product = stripe_helper.create_product
|
89
|
+
stripe_helper.create_plan(
|
90
|
+
amount: 500,
|
91
|
+
interval: 'month',
|
92
|
+
product: product.id,
|
93
|
+
currency: 'usd',
|
94
|
+
id: 'Sample5',
|
95
|
+
)
|
96
|
+
customer = Stripe::Customer.create(email: 'johnny@appleseed.com', source: stripe_helper.generate_card_token)
|
97
|
+
subscription = Stripe::Subscription.create(customer: customer.id, items: [{plan: 'Sample5'}])
|
98
|
+
one = Stripe::Invoice.create(
|
99
|
+
customer: customer.id,
|
100
|
+
currency: 'usd',
|
101
|
+
subscription: subscription.id,
|
102
|
+
metadata: {key: 'uno'},
|
103
|
+
number: 'one-1',
|
104
|
+
receipt_number: '111',
|
105
|
+
)
|
106
|
+
two = Stripe::Invoice.create(
|
107
|
+
customer: customer.id,
|
108
|
+
currency: 'gbp',
|
109
|
+
subscription: subscription.id,
|
110
|
+
metadata: {key: 'dos'},
|
111
|
+
number: 'two-2',
|
112
|
+
receipt_number: '222',
|
113
|
+
)
|
114
|
+
|
115
|
+
response = Stripe::Invoice.search({query: 'currency:"gbp"'}, stripe_version: '2020-08-27')
|
116
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
117
|
+
|
118
|
+
response = Stripe::Invoice.search({query: %(customer:"#{customer.id}")}, stripe_version: '2020-08-27')
|
119
|
+
expect(response.data.map(&:id)).to match_array([one.id, two.id])
|
120
|
+
|
121
|
+
response = Stripe::Invoice.search({query: 'number:"one-1"'}, stripe_version: '2020-08-27')
|
122
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
123
|
+
|
124
|
+
response = Stripe::Invoice.search({query: 'receipt_number:"222"'}, stripe_version: '2020-08-27')
|
125
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
126
|
+
|
127
|
+
response = Stripe::Invoice.search({query: %(subscription:"#{subscription.id}")}, stripe_version: '2020-08-27')
|
128
|
+
expect(response.data.map(&:id)).to match_array([one.id, two.id])
|
129
|
+
|
130
|
+
response = Stripe::Invoice.search({query: 'total:1000'}, stripe_version: '2020-08-27')
|
131
|
+
expect(response.data.map(&:id)).to match_array([one.id, two.id])
|
132
|
+
|
133
|
+
response = Stripe::Invoice.search({query: 'metadata["key"]:"uno"'}, stripe_version: '2020-08-27')
|
134
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
135
|
+
end
|
136
|
+
|
137
|
+
it "respects limit", :aggregate_failures do
|
138
|
+
customer = Stripe::Customer.create(email: 'one@one.com', name: 'one', phone: '1111111111', metadata: {key: 'uno'})
|
139
|
+
11.times do
|
140
|
+
Stripe::Invoice.create(customer: customer.id, currency: 'usd')
|
141
|
+
end
|
142
|
+
|
143
|
+
response = Stripe::Invoice.search({query: %(customer:"#{customer.id}")}, stripe_version: '2020-08-27')
|
144
|
+
expect(response.data.size).to eq(10)
|
145
|
+
response = Stripe::Invoice.search({query: %(customer:"#{customer.id}"), limit: 1}, stripe_version: '2020-08-27')
|
146
|
+
expect(response.data.size).to eq(1)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "reports search errors", :aggregate_failures do
|
150
|
+
expect {
|
151
|
+
Stripe::Invoice.search({limit: 1}, stripe_version: '2020-08-27')
|
152
|
+
}.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
|
153
|
+
|
154
|
+
expect {
|
155
|
+
Stripe::Invoice.search({query: 'asdf'}, stripe_version: '2020-08-27')
|
156
|
+
}.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
|
157
|
+
|
158
|
+
expect {
|
159
|
+
Stripe::Invoice.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
|
160
|
+
}.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `invoices`./)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
77
164
|
context "paying an invoice" do
|
78
165
|
before do
|
79
166
|
@invoice = Stripe::Invoice.create
|
@@ -83,12 +170,28 @@ shared_examples 'Invoice API' do
|
|
83
170
|
@invoice = @invoice.pay
|
84
171
|
expect(@invoice.attempted).to eq(true)
|
85
172
|
expect(@invoice.paid).to eq(true)
|
173
|
+
expect(@invoice.status).to eq("paid")
|
86
174
|
end
|
87
175
|
|
88
176
|
it 'creates a new charge object' do
|
89
177
|
expect{ @invoice.pay }.to change { Stripe::Charge.list.data.count }.by 1
|
90
178
|
end
|
91
179
|
|
180
|
+
it 'should work with Stripe::Invoice.pay(invoice_id)' do
|
181
|
+
expect(@invoice.paid).to_not eq(true)
|
182
|
+
|
183
|
+
expect {
|
184
|
+
Stripe::Invoice.pay(@invoice.id)
|
185
|
+
}.to change { Stripe::Charge.list.data.count }.by 1
|
186
|
+
|
187
|
+
@invoice = Stripe::Invoice.retrieve(id: @invoice.id)
|
188
|
+
expect(@invoice).to_not be_nil
|
189
|
+
|
190
|
+
expect(@invoice.attempted).to eq(true)
|
191
|
+
expect(@invoice.paid).to eq(true)
|
192
|
+
expect(@invoice.status).to eq("paid")
|
193
|
+
end
|
194
|
+
|
92
195
|
it 'sets the charge attribute' do
|
93
196
|
@invoice = @invoice.pay
|
94
197
|
expect(@invoice.charge).to be_a String
|
@@ -133,7 +236,10 @@ shared_examples 'Invoice API' do
|
|
133
236
|
describe 'parameter validation' do
|
134
237
|
it 'fails without parameters' do
|
135
238
|
expect { Stripe::Invoice.upcoming() }.to raise_error {|e|
|
136
|
-
|
239
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
240
|
+
expect(e.http_status).to eq(400)
|
241
|
+
expect(e.message).to eq('Missing required param: customer if subscription is not provided')
|
242
|
+
}
|
137
243
|
end
|
138
244
|
|
139
245
|
it 'fails without a valid customer' do
|
@@ -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
|
|
@@ -92,6 +97,35 @@ shared_examples 'PaymentIntent API' do
|
|
92
97
|
expect(Stripe::BalanceTransaction.retrieve(balance_txn).id).to eq(balance_txn)
|
93
98
|
end
|
94
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
|
+
|
95
129
|
it "confirms a stripe payment_intent" do
|
96
130
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
97
131
|
confirmed_payment_intent = payment_intent.confirm()
|
@@ -100,6 +134,25 @@ shared_examples 'PaymentIntent API' do
|
|
100
134
|
expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
|
101
135
|
end
|
102
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
|
+
|
103
156
|
it "captures a stripe payment_intent" do
|
104
157
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
105
158
|
confirmed_payment_intent = payment_intent.capture()
|
@@ -108,6 +161,27 @@ shared_examples 'PaymentIntent API' do
|
|
108
161
|
expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
|
109
162
|
end
|
110
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
|
+
|
111
185
|
it "cancels a stripe payment_intent" do
|
112
186
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
113
187
|
confirmed_payment_intent = payment_intent.cancel()
|
@@ -144,4 +218,66 @@ shared_examples 'PaymentIntent API' do
|
|
144
218
|
expect(e.http_status).to eq(400)
|
145
219
|
}
|
146
220
|
end
|
221
|
+
|
222
|
+
context "search" do
|
223
|
+
# the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
|
224
|
+
it "searches payment intents for exact matches", :aggregate_failures do
|
225
|
+
response = Stripe::PaymentIntent.search({query: 'currency:"usd"'}, stripe_version: '2020-08-27')
|
226
|
+
expect(response.data.size).to eq(0)
|
227
|
+
|
228
|
+
customer = Stripe::Customer.create(email: 'johnny@appleseed.com', source: stripe_helper.generate_card_token)
|
229
|
+
one = Stripe::PaymentIntent.create(
|
230
|
+
amount: 100,
|
231
|
+
customer: customer.id,
|
232
|
+
currency: 'usd',
|
233
|
+
metadata: {key: 'uno'},
|
234
|
+
)
|
235
|
+
two = Stripe::PaymentIntent.create(
|
236
|
+
amount: 3184, # status: requires_action
|
237
|
+
customer: customer.id,
|
238
|
+
currency: 'gbp',
|
239
|
+
metadata: {key: 'dos'},
|
240
|
+
)
|
241
|
+
|
242
|
+
response = Stripe::PaymentIntent.search({query: 'amount:100'}, stripe_version: '2020-08-27')
|
243
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
244
|
+
|
245
|
+
response = Stripe::PaymentIntent.search({query: 'currency:"gbp"'}, stripe_version: '2020-08-27')
|
246
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
247
|
+
|
248
|
+
response = Stripe::PaymentIntent.search({query: %(customer:"#{customer.id}")}, stripe_version: '2020-08-27')
|
249
|
+
expect(response.data.map(&:id)).to match_array([one.id, two.id])
|
250
|
+
|
251
|
+
response = Stripe::PaymentIntent.search({query: 'status:"requires_action"'}, stripe_version: '2020-08-27')
|
252
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
253
|
+
|
254
|
+
response = Stripe::PaymentIntent.search({query: 'metadata["key"]:"uno"'}, stripe_version: '2020-08-27')
|
255
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
256
|
+
end
|
257
|
+
|
258
|
+
it "respects limit", :aggregate_failures do
|
259
|
+
11.times do
|
260
|
+
Stripe::PaymentIntent.create(amount: 100, currency: 'usd')
|
261
|
+
end
|
262
|
+
|
263
|
+
response = Stripe::PaymentIntent.search({query: 'amount:100'}, stripe_version: '2020-08-27')
|
264
|
+
expect(response.data.size).to eq(10)
|
265
|
+
response = Stripe::PaymentIntent.search({query: 'amount:100', limit: 1}, stripe_version: '2020-08-27')
|
266
|
+
expect(response.data.size).to eq(1)
|
267
|
+
end
|
268
|
+
|
269
|
+
it "reports search errors", :aggregate_failures do
|
270
|
+
expect {
|
271
|
+
Stripe::PaymentIntent.search({limit: 1}, stripe_version: '2020-08-27')
|
272
|
+
}.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
|
273
|
+
|
274
|
+
expect {
|
275
|
+
Stripe::PaymentIntent.search({query: 'asdf'}, stripe_version: '2020-08-27')
|
276
|
+
}.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
|
277
|
+
|
278
|
+
expect {
|
279
|
+
Stripe::PaymentIntent.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
|
280
|
+
}.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `payment_intents`./)
|
281
|
+
end
|
282
|
+
end
|
147
283
|
end
|
@@ -25,6 +25,12 @@ shared_examples 'PaymentMethod API' do
|
|
25
25
|
cvc: 999
|
26
26
|
}
|
27
27
|
end
|
28
|
+
let(:visa_card_details) do
|
29
|
+
card_details
|
30
|
+
end
|
31
|
+
let(:mastercard_card_details) do
|
32
|
+
card_details.merge(:number => 5555_5555_5555_4444)
|
33
|
+
end
|
28
34
|
let(:sepa_debit_details) do
|
29
35
|
{
|
30
36
|
iban: 'DE89370400440532013000'
|
@@ -385,6 +391,7 @@ shared_examples 'PaymentMethod API' do
|
|
385
391
|
.from(original_card_exp_month).to(new_card_exp_month)
|
386
392
|
end
|
387
393
|
|
394
|
+
|
388
395
|
context 'without a customer' do
|
389
396
|
it 'raises invalid requestion exception' do
|
390
397
|
expect do
|
@@ -394,29 +401,39 @@ shared_examples 'PaymentMethod API' do
|
|
394
401
|
end
|
395
402
|
end
|
396
403
|
|
404
|
+
context 'with visa card' do
|
405
|
+
let(:payment_method) do
|
406
|
+
Stripe::PaymentMethod.create(type: 'card', card: visa_card_details)
|
407
|
+
end
|
408
|
+
|
409
|
+
it 'uses correct brand' do
|
410
|
+
expect(payment_method.card.brand).to eq('visa')
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
context 'with mastercard card' do
|
415
|
+
let(:payment_method) do
|
416
|
+
Stripe::PaymentMethod.create(type: 'card', card: mastercard_card_details)
|
417
|
+
end
|
418
|
+
|
419
|
+
it 'uses correct brand' do
|
420
|
+
expect(payment_method.card.brand).to eq('mastercard')
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
397
424
|
context 'with ideal' do
|
398
425
|
let(:payment_method) do
|
399
426
|
Stripe::PaymentMethod.create(type: 'ideal', ideal: ideal_details)
|
400
427
|
end
|
401
428
|
|
402
|
-
it '
|
429
|
+
it 'cannot update' do
|
403
430
|
Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
|
404
431
|
|
405
|
-
original_ideal_bank = payment_method.ideal.bank
|
406
432
|
new_ideal_bank = 12
|
407
433
|
|
408
434
|
expect do
|
409
435
|
Stripe::PaymentMethod.update(payment_method.id, ideal: { bank: new_ideal_bank })
|
410
|
-
end.to
|
411
|
-
.from(original_ideal_bank).to(new_ideal_bank)
|
412
|
-
end
|
413
|
-
|
414
|
-
context 'without a customer' do
|
415
|
-
it 'raises invalid requestion exception' do
|
416
|
-
expect do
|
417
|
-
Stripe::PaymentMethod.update(payment_method.id, ideal: { bank: 12 })
|
418
|
-
end.to raise_error(Stripe::InvalidRequestError)
|
419
|
-
end
|
436
|
+
end.to raise_error(Stripe::InvalidRequestError)
|
420
437
|
end
|
421
438
|
end
|
422
439
|
|
@@ -425,24 +442,12 @@ shared_examples 'PaymentMethod API' do
|
|
425
442
|
Stripe::PaymentMethod.create(type: 'sepa_debit', sepa_debit: sepa_debit_details)
|
426
443
|
end
|
427
444
|
|
428
|
-
it '
|
445
|
+
it 'cannot update' do
|
429
446
|
Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
|
430
447
|
|
431
|
-
original_iban = payment_method.sepa_debit.iban
|
432
|
-
new_iban = 'DE62370400440532013001'
|
433
|
-
|
434
448
|
expect do
|
435
|
-
Stripe::PaymentMethod.update(payment_method.id, sepa_debit: { iban:
|
436
|
-
end.to
|
437
|
-
.from(original_iban).to(new_iban)
|
438
|
-
end
|
439
|
-
|
440
|
-
context 'without a customer' do
|
441
|
-
it 'raises invalid requestion exception' do
|
442
|
-
expect do
|
443
|
-
Stripe::PaymentMethod.update(payment_method.id, sepa_debit: { iban: 'DE62370400440532013001' })
|
444
|
-
end.to raise_error(Stripe::InvalidRequestError)
|
445
|
-
end
|
449
|
+
Stripe::PaymentMethod.update(payment_method.id, sepa_debit: { iban: 'DE62370400440532013001'})
|
450
|
+
end.to raise_error(Stripe::InvalidRequestError)
|
446
451
|
end
|
447
452
|
end
|
448
453
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
shared_examples 'Price API' do
|
4
|
-
let(:
|
5
|
-
let(:
|
4
|
+
let(:product_id) { "product_id_1" }
|
5
|
+
let(:product) { stripe_helper.create_product(id: product_id) }
|
6
|
+
|
7
|
+
let(:other_product_id) { "product_id_2" }
|
8
|
+
let(:other_product) { stripe_helper.create_product(id: other_product_id) }
|
6
9
|
|
7
10
|
let(:price_attributes) { {
|
8
11
|
:id => "price_abc123",
|
@@ -26,6 +29,7 @@ shared_examples 'Price API' do
|
|
26
29
|
|
27
30
|
before(:each) do
|
28
31
|
product
|
32
|
+
other_product
|
29
33
|
end
|
30
34
|
|
31
35
|
it "creates a stripe price" do
|
@@ -124,6 +128,111 @@ shared_examples 'Price API' do
|
|
124
128
|
expect(two.map &:id).to include('price Two')
|
125
129
|
expect(two.map &:amount).to include(98765)
|
126
130
|
end
|
131
|
+
|
132
|
+
it "retrieves prices filtering by currency" do
|
133
|
+
5.times do | i|
|
134
|
+
stripe_helper.create_price(id: "usd price #{i}", product: product_id, amount: 11, currency: 'usd')
|
135
|
+
stripe_helper.create_price(id: "brl price #{i}", product: product_id, amount: 11, currency: 'brl')
|
136
|
+
end
|
137
|
+
|
138
|
+
all = Stripe::Price.list()
|
139
|
+
expect(all.count).to eq(10)
|
140
|
+
|
141
|
+
usd = Stripe::Price.list({currency: 'usd'})
|
142
|
+
expect(usd.count).to eq(5)
|
143
|
+
expect(usd.all? {|p| p.currency == 'usd' }).to be_truthy
|
144
|
+
|
145
|
+
brl = Stripe::Price.list({currency: 'brl'})
|
146
|
+
expect(brl.count).to eq(5)
|
147
|
+
expect(brl.all? {|p| p.currency == 'brl' }).to be_truthy
|
148
|
+
end
|
149
|
+
|
150
|
+
it "retrieves prices filtering by product" do
|
151
|
+
5.times do | i|
|
152
|
+
stripe_helper.create_price(id: "product 1 price #{i}", product: product_id)
|
153
|
+
stripe_helper.create_price(id: "product 2 price #{i}", product: other_product_id)
|
154
|
+
end
|
155
|
+
|
156
|
+
all = Stripe::Price.list()
|
157
|
+
expect(all.count).to eq(10)
|
158
|
+
|
159
|
+
product_prices = Stripe::Price.list({product: product.id})
|
160
|
+
expect(product_prices.count).to eq(5)
|
161
|
+
expect(product_prices.all? {|p| p.product == product.id }).to be_truthy
|
162
|
+
|
163
|
+
other_product_prices = Stripe::Price.list({product: other_product.id})
|
164
|
+
expect(other_product_prices.count).to eq(5)
|
165
|
+
expect(other_product_prices.all? {|p| p.product == other_product.id }).to be_truthy
|
166
|
+
end
|
167
|
+
|
168
|
+
context "searching prices" do
|
169
|
+
# the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
|
170
|
+
it "searches prices for exact matches", :aggregate_failures do
|
171
|
+
response = Stripe::Price.search({query: 'currency:"usd"'}, stripe_version: '2020-08-27')
|
172
|
+
expect(response.data.size).to eq(0)
|
173
|
+
|
174
|
+
one = stripe_helper.create_price(
|
175
|
+
amount: 100,
|
176
|
+
currency: 'usd',
|
177
|
+
lookup_key: 'one',
|
178
|
+
product: product_id,
|
179
|
+
metadata: {key: 'uno'},
|
180
|
+
type: "one_time",
|
181
|
+
)
|
182
|
+
two = stripe_helper.create_price(
|
183
|
+
active: false,
|
184
|
+
amount: 200,
|
185
|
+
currency: 'gbp',
|
186
|
+
lookup_key: 'two',
|
187
|
+
product: product_id,
|
188
|
+
recurring: {interval: 'month'},
|
189
|
+
metadata: {key: 'dos'},
|
190
|
+
)
|
191
|
+
|
192
|
+
response = Stripe::Price.search({query: 'active:"true"'}, stripe_version: '2020-08-27')
|
193
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
194
|
+
|
195
|
+
response = Stripe::Price.search({query: 'currency:"gbp"'}, stripe_version: '2020-08-27')
|
196
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
197
|
+
|
198
|
+
response = Stripe::Price.search({query: 'lookup_key:"one"'}, stripe_version: '2020-08-27')
|
199
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
200
|
+
|
201
|
+
response = Stripe::Price.search({query: %(product:"#{product.id}")}, stripe_version: '2020-08-27')
|
202
|
+
expect(response.data.map(&:id)).to match_array([one.id, two.id])
|
203
|
+
|
204
|
+
response = Stripe::Price.search({query: 'type:"recurring"'}, stripe_version: '2020-08-27')
|
205
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
206
|
+
|
207
|
+
response = Stripe::Price.search({query: 'metadata["key"]:"uno"'}, stripe_version: '2020-08-27')
|
208
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
209
|
+
end
|
210
|
+
|
211
|
+
it "respects limit", :aggregate_failures do
|
212
|
+
11.times do
|
213
|
+
stripe_helper.create_price(product: product_id)
|
214
|
+
end
|
215
|
+
|
216
|
+
response = Stripe::Price.search({query: %(product:"#{product.id}")}, stripe_version: '2020-08-27')
|
217
|
+
expect(response.data.size).to eq(10)
|
218
|
+
response = Stripe::Price.search({query: %(product:"#{product.id}"), limit: 1}, stripe_version: '2020-08-27')
|
219
|
+
expect(response.data.size).to eq(1)
|
220
|
+
end
|
221
|
+
|
222
|
+
it "reports search errors", :aggregate_failures do
|
223
|
+
expect {
|
224
|
+
Stripe::Price.search({limit: 1}, stripe_version: '2020-08-27')
|
225
|
+
}.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
|
226
|
+
|
227
|
+
expect {
|
228
|
+
Stripe::Price.search({query: 'asdf'}, stripe_version: '2020-08-27')
|
229
|
+
}.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
|
230
|
+
|
231
|
+
expect {
|
232
|
+
Stripe::Price.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
|
233
|
+
}.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `prices`./)
|
234
|
+
end
|
235
|
+
end
|
127
236
|
|
128
237
|
describe "Validations", :live => true do
|
129
238
|
include_context "stripe validator"
|
@@ -85,6 +85,74 @@ shared_examples "Product API" do
|
|
85
85
|
expect(all.count).to eq(100)
|
86
86
|
end
|
87
87
|
|
88
|
+
context "searching products" do
|
89
|
+
# the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
|
90
|
+
it "searches products for exact matches", :aggregate_failures do
|
91
|
+
response = Stripe::Product.search({query: 'name:"one"'}, stripe_version: '2020-08-27')
|
92
|
+
expect(response.data.size).to eq(0)
|
93
|
+
|
94
|
+
one = stripe_helper.create_product(
|
95
|
+
id: "product_1",
|
96
|
+
name: "one",
|
97
|
+
description: "un",
|
98
|
+
shippable: true,
|
99
|
+
url: "http://example.com/one",
|
100
|
+
metadata: {key: "uno"},
|
101
|
+
)
|
102
|
+
two = stripe_helper.create_product(
|
103
|
+
id: "product_2",
|
104
|
+
name: "two",
|
105
|
+
active: false,
|
106
|
+
description: "deux",
|
107
|
+
url: "http://example.com/two",
|
108
|
+
metadata: {key: "dos"},
|
109
|
+
)
|
110
|
+
|
111
|
+
response = Stripe::Product.search({query: 'active:"true"'}, stripe_version: '2020-08-27')
|
112
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
113
|
+
|
114
|
+
response = Stripe::Product.search({query: 'description:"deux"'}, stripe_version: '2020-08-27')
|
115
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
116
|
+
|
117
|
+
response = Stripe::Product.search({query: 'name:"one"'}, stripe_version: '2020-08-27')
|
118
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
119
|
+
|
120
|
+
response = Stripe::Product.search({query: 'shippable:"true"'}, stripe_version: '2020-08-27')
|
121
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
122
|
+
|
123
|
+
response = Stripe::Product.search({query: 'url:"http://example.com/two"'}, stripe_version: '2020-08-27')
|
124
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
125
|
+
|
126
|
+
response = Stripe::Product.search({query: 'metadata["key"]:"uno"'}, stripe_version: '2020-08-27')
|
127
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
128
|
+
end
|
129
|
+
|
130
|
+
it "respects limit", :aggregate_failures do
|
131
|
+
11.times do |i|
|
132
|
+
stripe_helper.create_product(id: "product_#{i}", name: "Product #{i}")
|
133
|
+
end
|
134
|
+
|
135
|
+
response = Stripe::Product.search({query: 'active:"true"'}, stripe_version: '2020-08-27')
|
136
|
+
expect(response.data.size).to eq(10)
|
137
|
+
response = Stripe::Product.search({query: 'active:"true"', limit: 1}, stripe_version: '2020-08-27')
|
138
|
+
expect(response.data.size).to eq(1)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "reports search errors", :aggregate_failures do
|
142
|
+
expect {
|
143
|
+
Stripe::Product.search({limit: 1}, stripe_version: '2020-08-27')
|
144
|
+
}.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
|
145
|
+
|
146
|
+
expect {
|
147
|
+
Stripe::Product.search({query: 'asdf'}, stripe_version: '2020-08-27')
|
148
|
+
}.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
|
149
|
+
|
150
|
+
expect {
|
151
|
+
Stripe::Product.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
|
152
|
+
}.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `products`./)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
88
156
|
describe "Validation", :live => true do
|
89
157
|
include_context "stripe validator"
|
90
158
|
let(:params) { stripe_helper.create_product_params }
|