spree_stripe 1.2.3 → 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: 4d1395fdcc4bb553b8cf0391c06098131b0c5529c397e60c0c1f17cc476f80bb
4
- data.tar.gz: 7d97dde52f20fbc99547b66484ee54800a682835d5a10c7a222c5828cbf73a0c
3
+ metadata.gz: 1fc16c4c66625cd297cb6b34950212f80282a391bcfd8504f5bdca3fb965e3b6
4
+ data.tar.gz: c375e87b7aa96d0ff378b181b0db2585cfb16a8c207e859c1d7d266cf8de3116
5
5
  SHA512:
6
- metadata.gz: fa7713aa1cd16ff77a28bdc7dc53e127d95370c58e6fbd14efef8dc6d44c2520c5e4dce52457151c8ffa97b3e8337a52761e78b78423a9183dd7b8b51feeb813
7
- data.tar.gz: 993d3bf730afeeb71e8f50606df34ff6363eb43ebe6428b097f467e611e1a81b4a94b67a620ed536bfc57fcecf9e2ba89bab720dea84329c5993c80bbaf83f54
6
+ metadata.gz: f75ae1f8dafbf9be2c134b8689fdeddc9dd1a05e66b77b1cb315fb40627493c91ee035aa30555e6f8d1f8c48b24bf05a3338b0c9eba5e31ceeeead9b803518d1
7
+ data.tar.gz: 5577ee9f5e556bca74158eefe15091778a67099d7a9b44936fd778a11fcfaf62a3b268dfd30394790ffe825fa38361feab4b9c761e09156e228fc7d3512c9fcf
@@ -23,6 +23,7 @@ export default class extends Controller {
23
23
  checkoutSelectShippingMethodPath: String,
24
24
  checkoutValidateGiftCardDataPath: String,
25
25
  checkoutValidateOrderForPaymentPath: String,
26
+ shippingRequired: { type: Boolean, default: true },
26
27
  returnUrl: String,
27
28
  }
28
29
 
@@ -103,10 +104,10 @@ export default class extends Controller {
103
104
 
104
105
  event.resolve({
105
106
  emailRequired: true,
106
- shippingAddressRequired: true,
107
+ shippingAddressRequired: this.shippingRequiredValue,
107
108
  allowedShippingCountries: this.availableCountriesValue,
108
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
109
- shippingRates: [{ id: 'loading', displayName: 'Loading...', amount: 0 }],
110
+ shippingRates: this.shippingRequiredValue ? [{ id: 'loading', displayName: 'Loading...', amount: 0 }] : [],
110
111
  lineItems: [
111
112
  { name: 'Subtotal', amount: 0 },
112
113
  { name: 'Shipping', amount: 0 },
@@ -116,8 +117,10 @@ export default class extends Controller {
116
117
  ]
117
118
  })
118
119
  })
119
- prButton.on('shippingaddresschange', this.handleAddressChange.bind(this))
120
- 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
+ }
121
124
  prButton.on('confirm', this.handleFinalizePayment.bind(this))
122
125
  prButton.on('cancel', this.handleCancelPayment.bind(this))
123
126
  }
@@ -229,7 +232,7 @@ export default class extends Controller {
229
232
  shippingRateId = String(shippingRateId).replace(/_google_pay_\d+/, '')
230
233
  }
231
234
 
232
- if (!shippingRateId || shippingRateId === 'loading') {
235
+ if (this.shippingRequiredValue && (!shippingRateId || shippingRateId === 'loading')) {
233
236
  ev.paymentFailed({ reason: 'invalid_shipping_address' })
234
237
  return
235
238
  }
@@ -285,18 +288,7 @@ export default class extends Controller {
285
288
  const orderUpdatePayload = {
286
289
  order: {
287
290
  email: ev.billingDetails.email,
288
- ship_address_attributes: {
289
- quick_checkout: true,
290
- firstname: ev.shippingAddress.name.split(' ')[0],
291
- lastname: ev.shippingAddress.name.split(' ')[1],
292
- address1: ev.shippingAddress.address.line1,
293
- address2: ev.shippingAddress.address.line2,
294
- city: ev.shippingAddress.address.city,
295
- zipcode: ev.shippingAddress.address.postal_code,
296
- country_iso: ev.shippingAddress.address.country,
297
- state_name: ev.shippingAddress.address.state,
298
- phone: ev.billingDetails.phone
299
- }
291
+ ship_address_attributes: this.ShipAddressAttributes(ev)
300
292
  },
301
293
  do_not_change_state: true
302
294
  }
@@ -310,49 +302,48 @@ export default class extends Controller {
310
302
  body: JSON.stringify(orderUpdatePayload)
311
303
  })
312
304
 
313
- if (updateResponse.status === 200) {
314
- const advanceResponse = await fetch(`${this.checkoutAdvancePathValue}?state=payment`, {
315
- method: 'PATCH',
316
- headers: {
317
- 'X-Spree-Order-Token': this.orderTokenValue,
318
- 'Content-Type': 'application/json'
319
- },
320
- body: JSON.stringify({ shipping_method_id: shippingRateId })
321
- })
305
+ if (updateResponse.status !== 200) {
306
+ ev.paymentFailed()
307
+ return
308
+ }
322
309
 
323
- if (advanceResponse.status === 200) {
324
- try {
325
- const { error: paymentMethodError, paymentMethod } = await this.stripe.createPaymentMethod({
326
- elements: this.elements
327
- })
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
+ })
328
318
 
329
- if (paymentMethodError) {
330
- showFlashMessage(error, 'error')
331
- return
332
- }
319
+ if (advanceResponse.status !== 200) {
320
+ ev.paymentFailed()
321
+ return
322
+ }
333
323
 
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
340
- }
341
- })
342
- if (error) {
343
- if (error.length > 0) {
344
- showFlashMessage(error, 'error')
345
- }
346
- return
347
- }
348
- } catch (e) {
349
- 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
350
340
  }
351
- } else {
352
- ev.paymentFailed()
341
+ })
342
+ if (error?.length > 0) {
343
+ showFlashMessage(error, 'error')
353
344
  }
354
- } else {
355
- ev.paymentFailed()
345
+ } catch (e) {
346
+ console.log(e)
356
347
  }
357
348
  }
358
349
 
@@ -453,4 +444,26 @@ export default class extends Controller {
453
444
 
454
445
  return { name: 'Tax', amount: amount }
455
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
+ }
456
469
  }
@@ -205,7 +205,7 @@ export default class extends Controller {
205
205
 
206
206
  async updateBillingAddress() {
207
207
  // billing address same as shipping address
208
- if (this.billingAddressCheckbox.checked) {
208
+ if (this.billingAddressCheckbox?.checked) {
209
209
  const response = await fetch(`${this.checkoutPathValue}?include=billing_address`, {
210
210
  method: 'PATCH',
211
211
  headers: this.spreeApiHeaders,
@@ -22,7 +22,8 @@
22
22
  checkout_stripe_button_checkout_select_shipping_method_path_value: spree.select_shipping_method_api_v2_storefront_checkout_path,
23
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
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)
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
26
27
  } do %>
27
28
  <div id="payment-request-button"></div>
28
29
 
@@ -1,5 +1,5 @@
1
1
  module SpreeStripe
2
- VERSION = '1.2.3'.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.3
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-06-05 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