spree_stripe 1.2.2 → 1.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cde218d7699681e3ca1686627494c10f7ba74c68c05cd7ed712e26454592c043
4
- data.tar.gz: 7e956a2740e2ad931ce6243b6a2dba8d4345f8e7a67fa214e394c3f401a64c54
3
+ metadata.gz: 1fc16c4c66625cd297cb6b34950212f80282a391bcfd8504f5bdca3fb965e3b6
4
+ data.tar.gz: c375e87b7aa96d0ff378b181b0db2585cfb16a8c207e859c1d7d266cf8de3116
5
5
  SHA512:
6
- metadata.gz: 7e780d1ab73b6947a1922f0d5b070f907e3629bb87284879b6a716597107faa4c923b90af18c6d5796c1f89f879c8e561ce0578f1f5350ca0d63f117ff654154
7
- data.tar.gz: 884a713f6ed9782940e1ab45aab1ed2a68a406a02ca8db8b81659c3fedc420c637912def17fff3c593143bf0a24a602e206f6b0cae1207ff430825164894cf81
6
+ metadata.gz: f75ae1f8dafbf9be2c134b8689fdeddc9dd1a05e66b77b1cb315fb40627493c91ee035aa30555e6f8d1f8c48b24bf05a3338b0c9eba5e31ceeeead9b803518d1
7
+ data.tar.gz: 5577ee9f5e556bca74158eefe15091778a67099d7a9b44936fd778a11fcfaf62a3b268dfd30394790ffe825fa38361feab4b9c761e09156e228fc7d3512c9fcf
data/README.md CHANGED
@@ -9,7 +9,7 @@ This is the official Stripe payment gateway extension for [Spree Commerce](https
9
9
 
10
10
  This Stripe integration is bundled in the [Spree Starter](https://github.com/spree/spree_starter/) for your development convenience.
11
11
 
12
- Or you could follow the [installation instructions](https://github.com/spree/spree_stripe/edit/main/README.md#installation) below.
12
+ Or you could follow the [installation instructions](https://spreecommerce.org/docs/integrations/payments/stripe).
13
13
 
14
14
  If you like what you see, consider giving this repo a GitHub star :star:
15
15
 
@@ -18,7 +18,12 @@ export default class extends Controller {
18
18
  maxRows: Number,
19
19
  maxColumns: Number,
20
20
  buttonWidth: Number,
21
- storeUrl: String,
21
+ checkoutPath: String,
22
+ checkoutAdvancePath: String,
23
+ checkoutSelectShippingMethodPath: String,
24
+ checkoutValidateGiftCardDataPath: String,
25
+ checkoutValidateOrderForPaymentPath: String,
26
+ shippingRequired: { type: Boolean, default: true },
22
27
  returnUrl: String,
23
28
  }
24
29
 
@@ -99,10 +104,10 @@ export default class extends Controller {
99
104
 
100
105
  event.resolve({
101
106
  emailRequired: true,
102
- shippingAddressRequired: true,
107
+ shippingAddressRequired: this.shippingRequiredValue,
103
108
  allowedShippingCountries: this.availableCountriesValue,
104
109
  // If we want to collect shipping address then we need to provide at least one shipping option, it will be updated to the real ones in the `shippingaddresschange` event
105
- shippingRates: [{ id: 'loading', displayName: 'Loading...', amount: 0 }],
110
+ shippingRates: this.shippingRequiredValue ? [{ id: 'loading', displayName: 'Loading...', amount: 0 }] : [],
106
111
  lineItems: [
107
112
  { name: 'Subtotal', amount: 0 },
108
113
  { name: 'Shipping', amount: 0 },
@@ -112,8 +117,10 @@ export default class extends Controller {
112
117
  ]
113
118
  })
114
119
  })
115
- prButton.on('shippingaddresschange', this.handleAddressChange.bind(this))
116
- prButton.on('shippingratechange', this.handleShippingOptionChange.bind(this))
120
+ if (this.shippingRequiredValue) {
121
+ prButton.on('shippingaddresschange', this.handleAddressChange.bind(this))
122
+ prButton.on('shippingratechange', this.handleShippingOptionChange.bind(this))
123
+ }
117
124
  prButton.on('confirm', this.handleFinalizePayment.bind(this))
118
125
  prButton.on('cancel', this.handleCancelPayment.bind(this))
119
126
  }
@@ -139,7 +146,7 @@ export default class extends Controller {
139
146
  }
140
147
 
141
148
  // 1st we need to persist the address to the order
142
- const saveAddressResponse = await fetch(`${this.storeUrlValue}/api/v2/storefront/checkout`, {
149
+ const saveAddressResponse = await fetch(this.checkoutPathValue, {
143
150
  method: 'PATCH',
144
151
  headers: {
145
152
  'X-Spree-Order-Token': this.orderTokenValue,
@@ -153,7 +160,7 @@ export default class extends Controller {
153
160
  // In case of any error here we have to allow user try again
154
161
  try {
155
162
  const response = await fetch(
156
- `${this.storeUrlValue}/api/v2/storefront/checkout/advance?state=delivery&include=shipments.shipping_rates,line_items.vendor`,
163
+ `${this.checkoutAdvancePathValue}?state=delivery&include=shipments.shipping_rates,line_items.vendor`,
157
164
  {
158
165
  method: 'PATCH',
159
166
  headers: {
@@ -197,7 +204,7 @@ export default class extends Controller {
197
204
 
198
205
  this.currentShippingOptionId = shippingRateId
199
206
 
200
- const response = await fetch(`${this.storeUrlValue}/api/v2/storefront/checkout/select_shipping_method`, {
207
+ const response = await fetch(this.checkoutSelectShippingMethodPathValue, {
201
208
  method: 'PATCH',
202
209
  headers: {
203
210
  'X-Spree-Order-Token': this.orderTokenValue,
@@ -225,14 +232,14 @@ export default class extends Controller {
225
232
  shippingRateId = String(shippingRateId).replace(/_google_pay_\d+/, '')
226
233
  }
227
234
 
228
- if (!shippingRateId || shippingRateId === 'loading') {
235
+ if (this.shippingRequiredValue && (!shippingRateId || shippingRateId === 'loading')) {
229
236
  ev.paymentFailed({ reason: 'invalid_shipping_address' })
230
237
  return
231
238
  }
232
239
 
233
- if (this.giftCardCodeValue && this.giftCardAmountValue) {
240
+ if (this.giftCardCodeValue && this.giftCardAmountValue && this.checkoutValidateGiftCardDataPathValue) {
234
241
  const giftCardValidationResponse = await fetch(
235
- `${this.storeUrlValue}/api/v2/storefront/checkout/validate_gift_card_data`,
242
+ this.checkoutValidateGiftCardDataPathValue,
236
243
  {
237
244
  method: 'POST',
238
245
  headers: {
@@ -252,7 +259,7 @@ export default class extends Controller {
252
259
  }
253
260
 
254
261
  const validationResponse = await fetch(
255
- `${this.storeUrlValue}/api/v2/storefront/checkout/validate_order_for_payment?skip_state=true`,
262
+ `${this.checkoutValidateOrderForPaymentPathValue}?skip_state=true`,
256
263
  {
257
264
  method: 'POST',
258
265
  headers: {
@@ -281,23 +288,12 @@ export default class extends Controller {
281
288
  const orderUpdatePayload = {
282
289
  order: {
283
290
  email: ev.billingDetails.email,
284
- ship_address_attributes: {
285
- quick_checkout: true,
286
- firstname: ev.shippingAddress.name.split(' ')[0],
287
- lastname: ev.shippingAddress.name.split(' ')[1],
288
- address1: ev.shippingAddress.address.line1,
289
- address2: ev.shippingAddress.address.line2,
290
- city: ev.shippingAddress.address.city,
291
- zipcode: ev.shippingAddress.address.postal_code,
292
- country_iso: ev.shippingAddress.address.country,
293
- state_name: ev.shippingAddress.address.state,
294
- phone: ev.billingDetails.phone
295
- }
291
+ ship_address_attributes: this.ShipAddressAttributes(ev)
296
292
  },
297
293
  do_not_change_state: true
298
294
  }
299
295
 
300
- const updateResponse = await fetch(`${this.storeUrlValue}/api/v2/storefront/checkout`, {
296
+ const updateResponse = await fetch(this.checkoutPathValue, {
301
297
  method: 'PATCH',
302
298
  headers: {
303
299
  'X-Spree-Order-Token': this.orderTokenValue,
@@ -306,49 +302,48 @@ export default class extends Controller {
306
302
  body: JSON.stringify(orderUpdatePayload)
307
303
  })
308
304
 
309
- if (updateResponse.status === 200) {
310
- const advanceResponse = await fetch(`${this.storeUrlValue}/api/v2/storefront/checkout/advance?state=payment`, {
311
- method: 'PATCH',
312
- headers: {
313
- 'X-Spree-Order-Token': this.orderTokenValue,
314
- 'Content-Type': 'application/json'
315
- },
316
- body: JSON.stringify({ shipping_method_id: shippingRateId })
317
- })
305
+ if (updateResponse.status !== 200) {
306
+ ev.paymentFailed()
307
+ return
308
+ }
318
309
 
319
- if (advanceResponse.status === 200) {
320
- try {
321
- const { error: paymentMethodError, paymentMethod } = await this.stripe.createPaymentMethod({
322
- elements: this.elements
323
- })
310
+ const advanceResponse = await fetch(`${this.checkoutAdvancePathValue}?state=payment`, {
311
+ method: 'PATCH',
312
+ headers: {
313
+ 'X-Spree-Order-Token': this.orderTokenValue,
314
+ 'Content-Type': 'application/json'
315
+ },
316
+ body: JSON.stringify({ shipping_method_id: shippingRateId })
317
+ })
324
318
 
325
- if (paymentMethodError) {
326
- showFlashMessage(error, 'error')
327
- return
328
- }
319
+ if (advanceResponse.status !== 200) {
320
+ ev.paymentFailed()
321
+ return
322
+ }
329
323
 
330
- const { error } = await this.stripe.confirmPayment({
331
- clientSecret: this.clientSecretValue,
332
- confirmParams: {
333
- payment_method: paymentMethod.id,
334
- // Stripe will automatically add `payment_intent` and `payment_intent_client_secret` params
335
- return_url: this.returnUrlValue
336
- }
337
- })
338
- if (error) {
339
- if (error.length > 0) {
340
- showFlashMessage(error, 'error')
341
- }
342
- return
343
- }
344
- } catch (e) {
345
- console.log(e)
324
+ try {
325
+ const { error: paymentMethodError, paymentMethod } = await this.stripe.createPaymentMethod({
326
+ elements: this.elements
327
+ })
328
+
329
+ if (paymentMethodError) {
330
+ showFlashMessage(paymentMethodError, 'error')
331
+ return
332
+ }
333
+
334
+ const { error } = await this.stripe.confirmPayment({
335
+ clientSecret: this.clientSecretValue,
336
+ confirmParams: {
337
+ payment_method: paymentMethod.id,
338
+ // Stripe will automatically add `payment_intent` and `payment_intent_client_secret` params
339
+ return_url: this.returnUrlValue
346
340
  }
347
- } else {
348
- ev.paymentFailed()
341
+ })
342
+ if (error?.length > 0) {
343
+ showFlashMessage(error, 'error')
349
344
  }
350
- } else {
351
- ev.paymentFailed()
345
+ } catch (e) {
346
+ console.log(e)
352
347
  }
353
348
  }
354
349
 
@@ -369,7 +364,7 @@ export default class extends Controller {
369
364
 
370
365
  if (this.shippingRates?.length > 1 && this.currentShippingOptionId !== defaultShippingMethodId) {
371
366
  // reset shipping choice
372
- await fetch(`${this.storeUrlValue}/api/v2/storefront/checkout/select_shipping_method`, {
367
+ await fetch(this.checkoutSelectShippingMethodPathValue, {
373
368
  method: 'PATCH',
374
369
  headers: {
375
370
  'X-Spree-Order-Token': this.orderTokenValue,
@@ -380,7 +375,7 @@ export default class extends Controller {
380
375
  }
381
376
 
382
377
  // reset addresses
383
- await fetch(`${this.storeUrlValue}/api/v2/storefront/checkout`, {
378
+ await fetch(this.checkoutPathValue, {
384
379
  method: 'PATCH',
385
380
  headers: {
386
381
  'X-Spree-Order-Token': this.orderTokenValue,
@@ -449,4 +444,26 @@ export default class extends Controller {
449
444
 
450
445
  return { name: 'Tax', amount: amount }
451
446
  }
447
+
448
+ ShipAddressAttributes(ev) {
449
+ if (ev.shippingAddress) {
450
+ return {
451
+ quick_checkout: true,
452
+ firstname: ev.shippingAddress.name.split(' ')[0],
453
+ lastname: ev.shippingAddress.name.split(' ')[1],
454
+ address1: ev.shippingAddress.address.line1,
455
+ address2: ev.shippingAddress.address.line2,
456
+ city: ev.shippingAddress.address.city,
457
+ zipcode: ev.shippingAddress.address.postal_code,
458
+ country_iso: ev.shippingAddress.address.country,
459
+ state_name: ev.shippingAddress.address.state,
460
+ phone: ev.billingDetails.phone
461
+ }
462
+ }
463
+ else {
464
+ return {
465
+ quick_checkout: true,
466
+ }
467
+ }
468
+ }
452
469
  }
@@ -11,7 +11,9 @@ export default class extends Controller {
11
11
  colorPrimary: String,
12
12
  colorBackground: String,
13
13
  colorText: String,
14
- storeUrl: String
14
+ paymentIntentPath: String,
15
+ checkoutPath: String,
16
+ checkoutValidateOrderForPaymentPath: String
15
17
  }
16
18
 
17
19
  static targets = [
@@ -53,7 +55,7 @@ export default class extends Controller {
53
55
  }
54
56
 
55
57
  const response = await fetch(
56
- `${this.storeUrlValue}/api/v2/storefront/stripe/payment_intents/${this.paymentIntentValue.id}`,
58
+ this.paymentIntentPathValue,
57
59
  {
58
60
  method: 'PATCH',
59
61
  headers: this.spreeApiHeaders,
@@ -179,7 +181,7 @@ export default class extends Controller {
179
181
 
180
182
  async validateOrderForPayment() {
181
183
  const response = await fetch(
182
- `${this.storeUrlValue}/api/v2/storefront/checkout/validate_order_for_payment`,
184
+ this.checkoutValidateOrderForPaymentPathValue,
183
185
  {
184
186
  method: 'POST',
185
187
  headers: this.spreeApiHeaders
@@ -203,8 +205,8 @@ export default class extends Controller {
203
205
 
204
206
  async updateBillingAddress() {
205
207
  // billing address same as shipping address
206
- if (this.billingAddressCheckbox.checked) {
207
- const response = await fetch(`${this.storeUrlValue}/api/v2/storefront/checkout?include=billing_address`, {
208
+ if (this.billingAddressCheckbox?.checked) {
209
+ const response = await fetch(`${this.checkoutPathValue}?include=billing_address`, {
208
210
  method: 'PATCH',
209
211
  headers: this.spreeApiHeaders,
210
212
  body: JSON.stringify({
@@ -228,7 +230,7 @@ export default class extends Controller {
228
230
  if (this.billingAddressForm.checkValidity()) {
229
231
  const formData = new FormData(this.billingAddressForm);
230
232
 
231
- const response = await fetch(`${this.storeUrlValue}/api/v2/storefront/checkout?include=billing_address`, {
233
+ const response = await fetch(`${this.checkoutPathValue}?include=billing_address`, {
232
234
  method: 'PATCH',
233
235
  headers: this.spreeApiHeaders,
234
236
  body: JSON.stringify({
@@ -7,7 +7,9 @@
7
7
  data-checkout-stripe-order-email-value="<%= @order.email %>"
8
8
  data-checkout-stripe-color-primary-value="<%= hex_color_to_rgb(theme_setting(:primary_color)) %>"
9
9
  data-checkout-stripe-color-text-value="<%= hex_color_to_rgb(theme_setting(:text_color)) %>"
10
- data-checkout-stripe-store-url-value="<%= current_store.formatted_url_or_custom_domain %>"
10
+ data-checkout-stripe-payment-intent-path-value="<%= spree.api_v2_storefront_stripe_payment_intent_path(current_stripe_payment_intent.id) %>"
11
+ data-checkout-stripe-checkout-path-value="<%= spree.api_v2_storefront_checkout_path %>"
12
+ data-checkout-stripe-checkout-validate-order-for-payment-path-value="<%= spree.validate_order_for_payment_api_v2_storefront_checkout_path %>"
11
13
  >
12
14
  <% payment_sources = checkout_payment_sources(payment_method) %>
13
15
 
@@ -17,8 +17,13 @@
17
17
  checkout_stripe_button_max_rows_value: defined?(max_rows) ? max_rows : nil,
18
18
  checkout_stripe_button_max_columns_value: defined?(max_columns) ? max_columns : nil,
19
19
  checkout_stripe_button_button_width_value: defined?(button_width) ? button_width : nil,
20
- checkout_stripe_button_store_url_value: current_store.formatted_url_or_custom_domain,
21
- checkout_stripe_button_return_url_value: spree.stripe_payment_intent_url(current_stripe_payment_intent)
20
+ checkout_stripe_button_checkout_path_value: spree.api_v2_storefront_checkout_path,
21
+ checkout_stripe_button_checkout_advance_path_value: spree.advance_api_v2_storefront_checkout_path,
22
+ checkout_stripe_button_checkout_select_shipping_method_path_value: spree.select_shipping_method_api_v2_storefront_checkout_path,
23
+ checkout_stripe_button_checkout_validate_gift_card_data_path_value: respond_to?(:validate_gift_card_data_api_v2_storefront_checkout_path) ? spree.validate_gift_card_data_api_v2_storefront_checkout_path : nil,
24
+ checkout_stripe_button_checkout_validate_order_for_payment_path_value: spree.validate_order_for_payment_api_v2_storefront_checkout_path,
25
+ checkout_stripe_button_return_url_value: spree.stripe_payment_intent_url(current_stripe_payment_intent),
26
+ checkout_stripe_button_shipping_required_value: @order.respond_to?(:quick_checkout_require_address?) ? @order.quick_checkout_require_address? : true
22
27
  } do %>
23
28
  <div id="payment-request-button"></div>
24
29
 
@@ -1,5 +1,5 @@
1
1
  module SpreeStripe
2
- VERSION = '1.2.2'.freeze
2
+ VERSION = '1.2.4'.freeze
3
3
 
4
4
  def gem_version
5
5
  Gem::Version.new(VERSION)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vendo Connect Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-24 00:00:00.000000000 Z
11
+ date: 2025-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree
@@ -279,7 +279,6 @@ files:
279
279
  - lib/spree_stripe/testing_support/factories/klarna_payment_source_factory.rb
280
280
  - lib/spree_stripe/testing_support/factories/link_payment_source_factory.rb
281
281
  - lib/spree_stripe/testing_support/factories/payment_intent_factory.rb
282
- - lib/spree_stripe/testing_support/factories/payment_source_factory.rb
283
282
  - lib/spree_stripe/testing_support/factories/przelewy24_payment_source_factory.rb
284
283
  - lib/spree_stripe/testing_support/factories/sepa_debit_payment_source_factory.rb
285
284
  - lib/spree_stripe/testing_support/factories/webhook_key_factory.rb
@@ -305,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
305
304
  version: '0'
306
305
  requirements:
307
306
  - none
308
- rubygems_version: 3.3.26
307
+ rubygems_version: 3.5.3
309
308
  signing_key:
310
309
  specification_version: 4
311
310
  summary: Official Spree Commerce Stripe payment gateway extension
@@ -1,8 +0,0 @@
1
- FactoryBot.define do
2
- factory :payment_source, class: Spree::PaymentSource do
3
- association :payment_method, factory: :payment_method
4
- gateway_payment_profile_id { 'pm_1adfg34fgfdf5245' }
5
- type { 'SpreeStripe::PaymentSources::Alipay' }
6
- user
7
- end
8
- end