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