stripe-ruby-mock 2.5.8 → 4.0.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/.gitignore +1 -1
- data/.rspec +2 -1
- data/CHANGELOG.md +77 -0
- data/Gemfile +1 -5
- data/README.md +19 -11
- data/lib/stripe_mock/api/client.rb +2 -2
- 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 +68 -24
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data/list.rb +42 -9
- data/lib/stripe_mock/data.rb +359 -21
- data/lib/stripe_mock/instance.rb +23 -5
- 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/balance_transactions.rb +2 -2
- data/lib/stripe_mock/request_handlers/charges.rb +31 -5
- data/lib/stripe_mock/request_handlers/checkout_session.rb +179 -0
- data/lib/stripe_mock/request_handlers/customers.rb +47 -19
- 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/search_helpers.rb +67 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +36 -12
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/invoices.rb +26 -6
- data/lib/stripe_mock/request_handlers/payment_intents.rb +202 -0
- data/lib/stripe_mock/request_handlers/payment_methods.rb +124 -0
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/prices.rb +71 -0
- data/lib/stripe_mock/request_handlers/products.rb +15 -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 +100 -0
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscriptions.rb +146 -25
- 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 +124 -9
- data/lib/stripe_mock/server.rb +2 -2
- data/lib/stripe_mock/test_strategies/base.rb +98 -12
- 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/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 +101 -44
- 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 -45
- 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 -46
- 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 +40 -0
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +47 -0
- 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 +11 -0
- data/spec/instance_spec.rb +13 -13
- 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 +6 -3
- data/spec/shared_stripe_examples/account_examples.rb +10 -2
- 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/bank_token_examples.rb +5 -7
- 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 +106 -22
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +149 -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 +148 -40
- data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
- data/spec/shared_stripe_examples/payment_intent_examples.rb +283 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +454 -0
- data/spec/shared_stripe_examples/payout_examples.rb +2 -2
- data/spec/shared_stripe_examples/plan_examples.rb +135 -92
- data/spec/shared_stripe_examples/price_examples.rb +292 -0
- data/spec/shared_stripe_examples/product_examples.rb +215 -0
- data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
- data/spec/shared_stripe_examples/refund_examples.rb +38 -21
- data/spec/shared_stripe_examples/setup_intent_examples.rb +85 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +706 -324
- data/spec/shared_stripe_examples/subscription_items_examples.rb +3 -2
- data/spec/shared_stripe_examples/transfer_examples.rb +16 -7
- data/spec/shared_stripe_examples/webhook_event_examples.rb +62 -16
- data/spec/spec_helper.rb +8 -5
- 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 +11 -1
- data/stripe-ruby-mock.gemspec +9 -5
- metadata +115 -47
- data/.travis.yml +0 -28
- data/spec/shared_stripe_examples/product_example.rb +0 -65
@@ -0,0 +1,283 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'PaymentIntent API' do
|
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
|
+
|
10
|
+
it "creates a succeeded stripe payment_intent" do
|
11
|
+
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
12
|
+
|
13
|
+
expect(payment_intent.id).to match(/^test_pi/)
|
14
|
+
expect(payment_intent.amount).to eq(100)
|
15
|
+
expect(payment_intent.currency).to eq('usd')
|
16
|
+
expect(payment_intent.metadata.to_hash).to eq({})
|
17
|
+
expect(payment_intent.status).to eq('succeeded')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "creates a requires_action stripe payment_intent when amount matches 3184" do
|
21
|
+
payment_intent = Stripe::PaymentIntent.create(amount: 3184, currency: "usd")
|
22
|
+
|
23
|
+
expect(payment_intent.id).to match(/^test_pi/)
|
24
|
+
expect(payment_intent.amount).to eq(3184)
|
25
|
+
expect(payment_intent.currency).to eq('usd')
|
26
|
+
expect(payment_intent.metadata.to_hash).to eq({})
|
27
|
+
expect(payment_intent.status).to eq('requires_action')
|
28
|
+
expect(payment_intent.next_action.type).to eq('use_stripe_sdk')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "creates a requires_payment_method stripe payment_intent when amount matches 3184" do
|
32
|
+
payment_intent = Stripe::PaymentIntent.create(amount: 3178, currency: "usd")
|
33
|
+
|
34
|
+
expect(payment_intent.id).to match(/^test_pi/)
|
35
|
+
expect(payment_intent.amount).to eq(3178)
|
36
|
+
expect(payment_intent.currency).to eq('usd')
|
37
|
+
expect(payment_intent.metadata.to_hash).to eq({})
|
38
|
+
expect(payment_intent.status).to eq('requires_payment_method')
|
39
|
+
expect(payment_intent.last_payment_error.code).to eq('card_declined')
|
40
|
+
expect(payment_intent.last_payment_error.decline_code).to eq('insufficient_funds')
|
41
|
+
expect(payment_intent.last_payment_error.message).to eq('Not enough funds.')
|
42
|
+
end
|
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
|
+
|
54
|
+
describe "listing payment_intent" do
|
55
|
+
before do
|
56
|
+
3.times do
|
57
|
+
Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "without params retrieves all stripe payment_intent" do
|
62
|
+
expect(Stripe::PaymentIntent.list.count).to eq(3)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "accepts a limit param" do
|
66
|
+
expect(Stripe::PaymentIntent.list(limit: 2).count).to eq(2)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "retrieves a stripe payment_intent" do
|
71
|
+
original = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
72
|
+
payment_intent = Stripe::PaymentIntent.retrieve(original.id)
|
73
|
+
|
74
|
+
expect(payment_intent.id).to eq(original.id)
|
75
|
+
expect(payment_intent.amount).to eq(original.amount)
|
76
|
+
expect(payment_intent.currency).to eq(original.currency)
|
77
|
+
expect(payment_intent.metadata.to_hash).to eq(original.metadata.to_hash)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "cannot retrieve a payment_intent that doesn't exist" do
|
81
|
+
expect { Stripe::PaymentIntent.retrieve('nope') }.to raise_error {|e|
|
82
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
83
|
+
expect(e.param).to eq('payment_intent')
|
84
|
+
expect(e.http_status).to eq(404)
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'creates and confirms a stripe payment_intent with confirm flag to true' do
|
89
|
+
payment_intent = Stripe::PaymentIntent.create(
|
90
|
+
amount: 100, currency: 'usd', confirm: true
|
91
|
+
)
|
92
|
+
expect(payment_intent.status).to eq('succeeded')
|
93
|
+
expect(payment_intent.charges.data.size).to eq(1)
|
94
|
+
expect(payment_intent.charges.data.first.object).to eq('charge')
|
95
|
+
balance_txn = payment_intent.charges.data.first.balance_transaction
|
96
|
+
expect(balance_txn).to match(/^test_txn/)
|
97
|
+
expect(Stripe::BalanceTransaction.retrieve(balance_txn).id).to eq(balance_txn)
|
98
|
+
end
|
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
|
+
|
129
|
+
it "confirms a stripe payment_intent" do
|
130
|
+
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
131
|
+
confirmed_payment_intent = payment_intent.confirm()
|
132
|
+
expect(confirmed_payment_intent.status).to eq("succeeded")
|
133
|
+
expect(confirmed_payment_intent.charges.data.size).to eq(1)
|
134
|
+
expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
|
135
|
+
end
|
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
|
+
|
156
|
+
it "captures a stripe payment_intent" do
|
157
|
+
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
158
|
+
confirmed_payment_intent = payment_intent.capture()
|
159
|
+
expect(confirmed_payment_intent.status).to eq("succeeded")
|
160
|
+
expect(confirmed_payment_intent.charges.data.size).to eq(1)
|
161
|
+
expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
|
162
|
+
end
|
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
|
+
|
185
|
+
it "cancels a stripe payment_intent" do
|
186
|
+
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
187
|
+
confirmed_payment_intent = payment_intent.cancel()
|
188
|
+
expect(confirmed_payment_intent.status).to eq("canceled")
|
189
|
+
end
|
190
|
+
|
191
|
+
it "updates a stripe payment_intent" do
|
192
|
+
original = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
193
|
+
payment_intent = Stripe::PaymentIntent.retrieve(original.id)
|
194
|
+
|
195
|
+
payment_intent.amount = 200
|
196
|
+
payment_intent.save
|
197
|
+
|
198
|
+
updated = Stripe::PaymentIntent.retrieve(original.id)
|
199
|
+
|
200
|
+
expect(updated.amount).to eq(200)
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'when amount is not integer', live: true do
|
204
|
+
expect { Stripe::PaymentIntent.create(amount: 400.2,
|
205
|
+
currency: 'usd') }.to raise_error { |e|
|
206
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
207
|
+
expect(e.param).to eq('amount')
|
208
|
+
expect(e.http_status).to eq(400)
|
209
|
+
}
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'when amount is negative', live: true do
|
213
|
+
expect { Stripe::PaymentIntent.create(amount: -400,
|
214
|
+
currency: 'usd') }.to raise_error { |e|
|
215
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
216
|
+
expect(e.param).to eq('amount')
|
217
|
+
expect(e.message).to match(/^Invalid.*integer/)
|
218
|
+
expect(e.http_status).to eq(400)
|
219
|
+
}
|
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
|
283
|
+
end
|