stripe-ruby-mock 2.5.6 → 3.1.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -1
- data/.travis.yml +6 -9
- data/CHANGELOG.md +35 -0
- data/Gemfile +1 -0
- data/README.md +17 -11
- data/lib/stripe_mock.rb +11 -0
- data/lib/stripe_mock/api/client.rb +1 -1
- data/lib/stripe_mock/api/errors.rb +34 -28
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +7 -0
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data.rb +323 -13
- data/lib/stripe_mock/data/list.rb +42 -9
- data/lib/stripe_mock/instance.rb +52 -5
- data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/balance_transactions.rb +2 -2
- data/lib/stripe_mock/request_handlers/charges.rb +13 -12
- data/lib/stripe_mock/request_handlers/checkout.rb +15 -0
- data/lib/stripe_mock/request_handlers/checkout_session.rb +16 -0
- data/lib/stripe_mock/request_handlers/customers.rb +35 -18
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
- data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +14 -10
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +22 -7
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/invoices.rb +11 -5
- data/lib/stripe_mock/request_handlers/payment_intents.rb +182 -0
- data/lib/stripe_mock/request_handlers/payment_methods.rb +120 -0
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/prices.rb +44 -0
- data/lib/stripe_mock/request_handlers/products.rb +44 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +6 -3
- data/lib/stripe_mock/request_handlers/setup_intents.rb +93 -0
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +82 -41
- data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
- data/lib/stripe_mock/request_handlers/tokens.rb +8 -6
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +130 -9
- data/lib/stripe_mock/test_strategies/base.rb +68 -8
- data/lib/stripe_mock/test_strategies/live.rb +23 -12
- data/lib/stripe_mock/test_strategies/mock.rb +6 -2
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/balance.available.json +6 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +166 -38
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +2 -1
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +2 -1
- data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +186 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +164 -0
- data/lib/stripe_mock/webhook_fixtures/product.created.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +38 -0
- data/spec/instance_spec.rb +10 -12
- data/spec/list_spec.rb +38 -0
- data/spec/server_spec.rb +6 -3
- data/spec/shared_stripe_examples/account_examples.rb +1 -1
- data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
- data/spec/shared_stripe_examples/balance_examples.rb +6 -0
- data/spec/shared_stripe_examples/balance_transaction_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_examples.rb +3 -3
- data/spec/shared_stripe_examples/card_examples.rb +4 -4
- data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/charge_examples.rb +32 -36
- data/spec/shared_stripe_examples/checkout_examples.rb +38 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +103 -53
- data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
- data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
- data/spec/shared_stripe_examples/invoice_examples.rb +43 -41
- data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
- data/spec/shared_stripe_examples/payment_intent_examples.rb +147 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +449 -0
- data/spec/shared_stripe_examples/payout_examples.rb +2 -2
- data/spec/shared_stripe_examples/plan_examples.rb +135 -77
- data/spec/shared_stripe_examples/price_examples.rb +183 -0
- data/spec/shared_stripe_examples/product_examples.rb +155 -0
- data/spec/shared_stripe_examples/refund_examples.rb +41 -31
- data/spec/shared_stripe_examples/setup_intent_examples.rb +68 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +546 -295
- data/spec/shared_stripe_examples/subscription_items_examples.rb +76 -0
- data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
- data/spec/shared_stripe_examples/transfer_examples.rb +9 -9
- data/spec/shared_stripe_examples/webhook_event_examples.rb +11 -11
- data/spec/spec_helper.rb +7 -4
- data/spec/stripe_mock_spec.rb +4 -4
- data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
- data/spec/support/stripe_examples.rb +12 -2
- data/stripe-ruby-mock.gemspec +8 -3
- metadata +81 -32
@@ -0,0 +1,449 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'PaymentMethod API' do
|
4
|
+
|
5
|
+
let(:billing_details) do
|
6
|
+
{
|
7
|
+
address: {
|
8
|
+
city: 'North New Portland',
|
9
|
+
country: 'US',
|
10
|
+
line1: '2631 Bloomfield Way',
|
11
|
+
line2: 'Apartment 5B',
|
12
|
+
postal_code: '05555',
|
13
|
+
state: 'ME'
|
14
|
+
},
|
15
|
+
email: 'john@example.com',
|
16
|
+
name: 'John Doe',
|
17
|
+
phone: '555-555-5555'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
let(:card_details) do
|
21
|
+
{
|
22
|
+
number: 4242_4242_4242_4242,
|
23
|
+
exp_month: 9,
|
24
|
+
exp_year: (Time.now.year + 5),
|
25
|
+
cvc: 999
|
26
|
+
}
|
27
|
+
end
|
28
|
+
let(:sepa_debit_details) do
|
29
|
+
{
|
30
|
+
iban: 'DE89370400440532013000'
|
31
|
+
}
|
32
|
+
end
|
33
|
+
let(:ideal_details) do
|
34
|
+
{
|
35
|
+
bank: 'bunq'
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# post /v1/payment_methods
|
40
|
+
describe 'Create a PaymentMethod', live: true do
|
41
|
+
let(:payment_method) do
|
42
|
+
Stripe::PaymentMethod.create(
|
43
|
+
type: type,
|
44
|
+
billing_details: billing_details,
|
45
|
+
card: card_details,
|
46
|
+
metadata: {
|
47
|
+
order_id: '123456789'
|
48
|
+
}
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with credit card' do
|
53
|
+
let(:type) { 'card' }
|
54
|
+
|
55
|
+
it 'creates a payment method with a valid id', live: false do
|
56
|
+
expect(payment_method.id).to match(/^test_pm/)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'creates a payment method with a billing address' do
|
60
|
+
expect(payment_method.billing_details.address.city).to eq('North New Portland')
|
61
|
+
expect(payment_method.billing_details.address.country).to eq('US')
|
62
|
+
expect(payment_method.billing_details.address.line1).to eq('2631 Bloomfield Way')
|
63
|
+
expect(payment_method.billing_details.address.line2).to eq('Apartment 5B')
|
64
|
+
expect(payment_method.billing_details.address.postal_code).to eq('05555')
|
65
|
+
expect(payment_method.billing_details.address.state).to eq('ME')
|
66
|
+
expect(payment_method.billing_details.email).to eq('john@example.com')
|
67
|
+
expect(payment_method.billing_details.name).to eq('John Doe')
|
68
|
+
expect(payment_method.billing_details.phone).to eq('555-555-5555')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'creates a payment method with metadata' do
|
72
|
+
expect(payment_method.metadata.order_id).to eq('123456789')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'with ideal' do
|
77
|
+
let(:type) { 'ideal' }
|
78
|
+
|
79
|
+
it 'creates a payment method with a valid id', live: false do
|
80
|
+
expect(payment_method.id).to match(/^test_pm/)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'creates a payment method with a billing address' do
|
84
|
+
expect(payment_method.billing_details.address.city).to eq('North New Portland')
|
85
|
+
expect(payment_method.billing_details.address.country).to eq('US')
|
86
|
+
expect(payment_method.billing_details.address.line1).to eq('2631 Bloomfield Way')
|
87
|
+
expect(payment_method.billing_details.address.line2).to eq('Apartment 5B')
|
88
|
+
expect(payment_method.billing_details.address.postal_code).to eq('05555')
|
89
|
+
expect(payment_method.billing_details.address.state).to eq('ME')
|
90
|
+
expect(payment_method.billing_details.email).to eq('john@example.com')
|
91
|
+
expect(payment_method.billing_details.name).to eq('John Doe')
|
92
|
+
expect(payment_method.billing_details.phone).to eq('555-555-5555')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'creates a payment method with metadata' do
|
96
|
+
expect(payment_method.metadata.order_id).to eq('123456789')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'with sepa debit' do
|
101
|
+
let(:type) { 'sepa_debit' }
|
102
|
+
|
103
|
+
it 'creates a payment method with a valid id', live: false do
|
104
|
+
expect(payment_method.id).to match(/^test_pm/)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'creates a payment method with a billing address' do
|
108
|
+
expect(payment_method.billing_details.address.city).to eq('North New Portland')
|
109
|
+
expect(payment_method.billing_details.address.country).to eq('US')
|
110
|
+
expect(payment_method.billing_details.address.line1).to eq('2631 Bloomfield Way')
|
111
|
+
expect(payment_method.billing_details.address.line2).to eq('Apartment 5B')
|
112
|
+
expect(payment_method.billing_details.address.postal_code).to eq('05555')
|
113
|
+
expect(payment_method.billing_details.address.state).to eq('ME')
|
114
|
+
expect(payment_method.billing_details.email).to eq('john@example.com')
|
115
|
+
expect(payment_method.billing_details.name).to eq('John Doe')
|
116
|
+
expect(payment_method.billing_details.phone).to eq('555-555-5555')
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'creates a payment method with metadata' do
|
120
|
+
expect(payment_method.metadata.order_id).to eq('123456789')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'when type is invalid' do
|
125
|
+
let(:type) { 'bank_account' }
|
126
|
+
|
127
|
+
it 'raises invalid requestion exception' do
|
128
|
+
expect { payment_method }.to raise_error(Stripe::InvalidRequestError)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# get /v1/payment_methods/:id
|
134
|
+
describe 'Retrieve a PaymentMethod', live: true do
|
135
|
+
context 'with credit card' do
|
136
|
+
it 'retrieves a given payment method' do
|
137
|
+
customer = Stripe::Customer.create
|
138
|
+
original = Stripe::PaymentMethod.create(type: 'card', card: card_details)
|
139
|
+
Stripe::PaymentMethod.attach(original.id, customer: customer.id)
|
140
|
+
|
141
|
+
payment_method = Stripe::PaymentMethod.retrieve(original.id)
|
142
|
+
|
143
|
+
expect(payment_method.id).to eq(original.id)
|
144
|
+
expect(payment_method.type).to eq(original.type)
|
145
|
+
expect(payment_method.customer).to eq(customer.id)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'with ideal' do
|
150
|
+
it 'retrieves a given payment method' do
|
151
|
+
customer = Stripe::Customer.create
|
152
|
+
original = Stripe::PaymentMethod.create(type: 'ideal', ideal: ideal_details)
|
153
|
+
Stripe::PaymentMethod.attach(original.id, customer: customer.id)
|
154
|
+
|
155
|
+
payment_method = Stripe::PaymentMethod.retrieve(original.id)
|
156
|
+
|
157
|
+
expect(payment_method.id).to eq(original.id)
|
158
|
+
expect(payment_method.type).to eq(original.type)
|
159
|
+
expect(payment_method.customer).to eq(customer.id)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'with sepa debit' do
|
164
|
+
it 'retrieves a given payment method' do
|
165
|
+
customer = Stripe::Customer.create
|
166
|
+
original = Stripe::PaymentMethod.create(type: 'sepa_debit', sepa_debit: sepa_debit_details)
|
167
|
+
Stripe::PaymentMethod.attach(original.id, customer: customer.id)
|
168
|
+
|
169
|
+
payment_method = Stripe::PaymentMethod.retrieve(original.id)
|
170
|
+
|
171
|
+
expect(payment_method.id).to eq(original.id)
|
172
|
+
expect(payment_method.type).to eq(original.type)
|
173
|
+
expect(payment_method.customer).to eq(customer.id)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
it "cannot retrieve a payment_method that doesn't exist" do
|
178
|
+
expect { Stripe::PaymentMethod.retrieve('nope') }.to raise_error { |e|
|
179
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
180
|
+
expect(e.param).to eq('payment_method')
|
181
|
+
expect(e.http_status).to eq(404)
|
182
|
+
}
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# get /v1/payment_methods
|
187
|
+
describe "List a Customer's PaymentMethods", live: true do
|
188
|
+
let(:customer1) { Stripe::Customer.create }
|
189
|
+
let(:customer2) { Stripe::Customer.create }
|
190
|
+
|
191
|
+
context 'with credit card' do
|
192
|
+
before do
|
193
|
+
3.times do
|
194
|
+
payment_method = Stripe::PaymentMethod.create(type: 'card', card: card_details)
|
195
|
+
Stripe::PaymentMethod.attach(payment_method.id, customer: customer1.id)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'lists all payment methods' do
|
200
|
+
expect(Stripe::PaymentMethod.list(customer: customer1.id, type: 'card').count).to eq(3)
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'when passing a limit' do
|
204
|
+
it 'only lists the limited number of payment methods' do
|
205
|
+
expect(Stripe::PaymentMethod.list(customer: customer1.id, type: 'card', limit: 2).count).to eq(2)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'when listing the payment methods of another customer' do
|
210
|
+
it 'does not list any payment methods' do
|
211
|
+
expect(Stripe::PaymentMethod.list(customer: customer2.id, type: 'card').count).to eq(0)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'with ideal' do
|
217
|
+
before do
|
218
|
+
3.times do
|
219
|
+
payment_method = Stripe::PaymentMethod.create(type: 'ideal', ideal: ideal_details)
|
220
|
+
Stripe::PaymentMethod.attach(payment_method.id, customer: customer1.id)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'lists all payment methods' do
|
225
|
+
expect(Stripe::PaymentMethod.list(customer: customer1.id, type: 'ideal').count).to eq(3)
|
226
|
+
end
|
227
|
+
|
228
|
+
context 'when passing a limit' do
|
229
|
+
it 'only lists the limited number of payment methods' do
|
230
|
+
expect(Stripe::PaymentMethod.list(customer: customer1.id, type: 'ideal', limit: 2).count).to eq(2)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'when listing the payment methods of another customer' do
|
235
|
+
it 'does not list any payment methods' do
|
236
|
+
expect(Stripe::PaymentMethod.list(customer: customer2.id, type: 'ideal').count).to eq(0)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context 'with sepa debit' do
|
242
|
+
before do
|
243
|
+
3.times do
|
244
|
+
payment_method = Stripe::PaymentMethod.create(type: 'sepa_debit', sepa_debit: sepa_debit_details)
|
245
|
+
Stripe::PaymentMethod.attach(payment_method.id, customer: customer1.id)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'lists all payment methods' do
|
250
|
+
expect(Stripe::PaymentMethod.list(customer: customer1.id, type: 'sepa_debit').count).to eq(3)
|
251
|
+
end
|
252
|
+
|
253
|
+
context 'when passing a limit' do
|
254
|
+
it 'only lists the limited number of payment methods' do
|
255
|
+
expect(Stripe::PaymentMethod.list(customer: customer1.id, type: 'sepa_debit', limit: 2).count).to eq(2)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'when listing the payment methods of another customer' do
|
260
|
+
it 'does not list any payment methods' do
|
261
|
+
expect(Stripe::PaymentMethod.list(customer: customer2.id, type: 'sepa_debit').count).to eq(0)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
# post /v1/payment_methods/:id/attach
|
268
|
+
describe 'Attach a PaymentMethod to a Customer', live: true do
|
269
|
+
let(:customer) { Stripe::Customer.create }
|
270
|
+
|
271
|
+
context 'with credit card' do
|
272
|
+
let(:payment_method) { Stripe::PaymentMethod.create(type: 'card', card: card_details) }
|
273
|
+
|
274
|
+
it 'attaches a payment method to a customer' do
|
275
|
+
expect { Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id) }
|
276
|
+
.to change { Stripe::PaymentMethod.retrieve(payment_method.id).customer }
|
277
|
+
.from(nil).to(customer.id)
|
278
|
+
end
|
279
|
+
|
280
|
+
context "when the customer doesn't exist" do
|
281
|
+
it 'raises invalid requestion exception' do
|
282
|
+
expect { Stripe::PaymentMethod.attach(payment_method.id, customer: 'cus_invalid') }
|
283
|
+
.to raise_error(Stripe::InvalidRequestError)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
context 'with ideal' do
|
289
|
+
let(:payment_method) { Stripe::PaymentMethod.create(type: 'ideal', ideal: ideal_details) }
|
290
|
+
|
291
|
+
it 'attaches a payment method to a customer' do
|
292
|
+
expect { Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id) }
|
293
|
+
.to change { Stripe::PaymentMethod.retrieve(payment_method.id).customer }
|
294
|
+
.from(nil).to(customer.id)
|
295
|
+
end
|
296
|
+
|
297
|
+
context "when the customer doesn't exist" do
|
298
|
+
it 'raises invalid requestion exception' do
|
299
|
+
expect { Stripe::PaymentMethod.attach(payment_method.id, customer: 'cus_invalid') }
|
300
|
+
.to raise_error(Stripe::InvalidRequestError)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
context 'with sepa_debit' do
|
306
|
+
let(:payment_method) { Stripe::PaymentMethod.create(type: 'sepa_debit', sepa_debit: sepa_debit_details) }
|
307
|
+
|
308
|
+
it 'attaches a payment method to a customer' do
|
309
|
+
expect { Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id) }
|
310
|
+
.to change { Stripe::PaymentMethod.retrieve(payment_method.id).customer }
|
311
|
+
.from(nil).to(customer.id)
|
312
|
+
end
|
313
|
+
|
314
|
+
context "when the customer doesn't exist" do
|
315
|
+
it 'raises invalid requestion exception' do
|
316
|
+
expect { Stripe::PaymentMethod.attach(payment_method.id, customer: 'cus_invalid') }
|
317
|
+
.to raise_error(Stripe::InvalidRequestError)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
# post /v1/payment_methods/:id/detach
|
324
|
+
describe 'Detach a PaymentMethod from a Customer', live: true do
|
325
|
+
let(:customer) { Stripe::Customer.create }
|
326
|
+
|
327
|
+
context 'with credit card' do
|
328
|
+
let(:payment_method) do
|
329
|
+
payment_method = Stripe::PaymentMethod.create(type: 'card', card: card_details)
|
330
|
+
Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'detaches a PaymentMethod from a customer' do
|
334
|
+
expect { Stripe::PaymentMethod.detach(payment_method.id) }
|
335
|
+
.to change { Stripe::PaymentMethod.retrieve(payment_method.id).customer }
|
336
|
+
.from(customer.id).to(nil)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
context 'with ideal' do
|
341
|
+
let(:payment_method) do
|
342
|
+
payment_method = Stripe::PaymentMethod.create(type: 'ideal', ideal: ideal_details)
|
343
|
+
Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'detaches a PaymentMethod from a customer' do
|
347
|
+
expect { Stripe::PaymentMethod.detach(payment_method.id) }
|
348
|
+
.to change { Stripe::PaymentMethod.retrieve(payment_method.id).customer }
|
349
|
+
.from(customer.id).to(nil)
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
context 'with sepa debit' do
|
354
|
+
let(:payment_method) do
|
355
|
+
payment_method = Stripe::PaymentMethod.create(type: 'sepa_debit', sepa_debit: sepa_debit_details)
|
356
|
+
Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'detaches a PaymentMethod from a customer' do
|
360
|
+
expect { Stripe::PaymentMethod.detach(payment_method.id) }
|
361
|
+
.to change { Stripe::PaymentMethod.retrieve(payment_method.id).customer }
|
362
|
+
.from(customer.id).to(nil)
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
# post /v1/payment_methods/:id
|
368
|
+
describe 'Update a PaymentMethod', live: true do
|
369
|
+
let(:customer) { Stripe::Customer.create }
|
370
|
+
|
371
|
+
context 'with credit card' do
|
372
|
+
let(:payment_method) do
|
373
|
+
Stripe::PaymentMethod.create(type: 'card', card: card_details)
|
374
|
+
end
|
375
|
+
|
376
|
+
it 'updates the card for the payment method' do
|
377
|
+
Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
|
378
|
+
|
379
|
+
original_card_exp_month = payment_method.card.exp_month
|
380
|
+
new_card_exp_month = 12
|
381
|
+
|
382
|
+
expect do
|
383
|
+
Stripe::PaymentMethod.update(payment_method.id, card: { exp_month: new_card_exp_month })
|
384
|
+
end.to change { Stripe::PaymentMethod.retrieve(payment_method.id).card.exp_month }
|
385
|
+
.from(original_card_exp_month).to(new_card_exp_month)
|
386
|
+
end
|
387
|
+
|
388
|
+
context 'without a customer' do
|
389
|
+
it 'raises invalid requestion exception' do
|
390
|
+
expect do
|
391
|
+
Stripe::PaymentMethod.update(payment_method.id, card: { exp_month: 12 })
|
392
|
+
end.to raise_error(Stripe::InvalidRequestError)
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context 'with ideal' do
|
398
|
+
let(:payment_method) do
|
399
|
+
Stripe::PaymentMethod.create(type: 'ideal', ideal: ideal_details)
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'updates the ideal for the payment method' do
|
403
|
+
Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
|
404
|
+
|
405
|
+
original_ideal_bank = payment_method.ideal.bank
|
406
|
+
new_ideal_bank = 12
|
407
|
+
|
408
|
+
expect do
|
409
|
+
Stripe::PaymentMethod.update(payment_method.id, ideal: { bank: new_ideal_bank })
|
410
|
+
end.to change { Stripe::PaymentMethod.retrieve(payment_method.id).ideal.bank }
|
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
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
context 'with sepa debit' do
|
424
|
+
let(:payment_method) do
|
425
|
+
Stripe::PaymentMethod.create(type: 'sepa_debit', sepa_debit: sepa_debit_details)
|
426
|
+
end
|
427
|
+
|
428
|
+
it 'updates the sepa_debit for the payment method' do
|
429
|
+
Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
|
430
|
+
|
431
|
+
original_iban = payment_method.sepa_debit.iban
|
432
|
+
new_iban = 'DE62370400440532013001'
|
433
|
+
|
434
|
+
expect do
|
435
|
+
Stripe::PaymentMethod.update(payment_method.id, sepa_debit: { iban: new_iban })
|
436
|
+
end.to change { Stripe::PaymentMethod.retrieve(payment_method.id).sepa_debit.iban }
|
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
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
449
|
+
end
|
@@ -19,11 +19,11 @@ shared_examples 'Payout API' do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "without params retrieves all tripe payouts" do
|
22
|
-
expect(Stripe::Payout.
|
22
|
+
expect(Stripe::Payout.list.count).to eq(3)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "accepts a limit param" do
|
26
|
-
expect(Stripe::Payout.
|
26
|
+
expect(Stripe::Payout.list(limit: 2).count).to eq(2)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|