spree_stripe 1.2.3 → 1.2.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e37d17d73e754ef2f8526777041be558487592f42818dbe3a554dc663fb0eb97
|
4
|
+
data.tar.gz: c139162cc9fece31518aad3c5ac849de9c392648ee005693f3aa131ea4a98963
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 857e2aecfe5e8860da213246d1098819eca5ab56060c4d91bebe1ac49af3b6207a279d1f86239f263488d8c878ef94a76dafa1a3b4cab0a8279e30b8bb2b49c8
|
7
|
+
data.tar.gz: d2770b0f50b05d0e8f91b52fbc79c321108464c791ca356248d5361913f54c160fb6cf4ea08170c3055a56d2843c2abcabf3ddcac22916e5426a3b10761c5867
|
@@ -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:
|
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
|
-
|
120
|
-
|
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
|
}
|
@@ -157,14 +160,19 @@ export default class extends Controller {
|
|
157
160
|
// In case of any error here we have to allow user try again
|
158
161
|
try {
|
159
162
|
const response = await fetch(
|
160
|
-
|
163
|
+
this.checkoutAdvancePathValue,
|
161
164
|
{
|
162
165
|
method: 'PATCH',
|
163
166
|
headers: {
|
164
167
|
'X-Spree-Order-Token': this.orderTokenValue,
|
165
168
|
'Content-Type': 'application/json'
|
166
169
|
},
|
167
|
-
body: JSON.stringify({
|
170
|
+
body: JSON.stringify({
|
171
|
+
state: 'delivery',
|
172
|
+
include: 'shipments.shipping_rates',
|
173
|
+
quick_checkout: true,
|
174
|
+
shipping_method_id: this.currentShippingOptionId
|
175
|
+
})
|
168
176
|
}
|
169
177
|
)
|
170
178
|
const newOrderResponse = await response.json()
|
@@ -229,7 +237,7 @@ export default class extends Controller {
|
|
229
237
|
shippingRateId = String(shippingRateId).replace(/_google_pay_\d+/, '')
|
230
238
|
}
|
231
239
|
|
232
|
-
if (!shippingRateId || shippingRateId === 'loading') {
|
240
|
+
if (this.shippingRequiredValue && (!shippingRateId || shippingRateId === 'loading')) {
|
233
241
|
ev.paymentFailed({ reason: 'invalid_shipping_address' })
|
234
242
|
return
|
235
243
|
}
|
@@ -256,13 +264,14 @@ export default class extends Controller {
|
|
256
264
|
}
|
257
265
|
|
258
266
|
const validationResponse = await fetch(
|
259
|
-
|
267
|
+
this.checkoutValidateOrderForPaymentPathValue,
|
260
268
|
{
|
261
269
|
method: 'POST',
|
262
270
|
headers: {
|
263
271
|
'X-Spree-Order-Token': this.orderTokenValue,
|
264
272
|
'Content-Type': 'application/json'
|
265
|
-
}
|
273
|
+
},
|
274
|
+
body: JSON.stringify({ skip_state: true })
|
266
275
|
}
|
267
276
|
)
|
268
277
|
|
@@ -285,18 +294,7 @@ export default class extends Controller {
|
|
285
294
|
const orderUpdatePayload = {
|
286
295
|
order: {
|
287
296
|
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
|
-
}
|
297
|
+
ship_address_attributes: this.ShipAddressAttributes(ev)
|
300
298
|
},
|
301
299
|
do_not_change_state: true
|
302
300
|
}
|
@@ -310,49 +308,51 @@ export default class extends Controller {
|
|
310
308
|
body: JSON.stringify(orderUpdatePayload)
|
311
309
|
})
|
312
310
|
|
313
|
-
if (updateResponse.status
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
311
|
+
if (updateResponse.status !== 200) {
|
312
|
+
ev.paymentFailed()
|
313
|
+
return
|
314
|
+
}
|
315
|
+
|
316
|
+
const advanceResponse = await fetch(this.checkoutAdvancePathValue, {
|
317
|
+
method: 'PATCH',
|
318
|
+
headers: {
|
319
|
+
'X-Spree-Order-Token': this.orderTokenValue,
|
320
|
+
'Content-Type': 'application/json'
|
321
|
+
},
|
322
|
+
body: JSON.stringify({
|
323
|
+
state: 'payment',
|
324
|
+
shipping_method_id: shippingRateId
|
321
325
|
})
|
326
|
+
})
|
322
327
|
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
})
|
328
|
+
if (advanceResponse.status !== 200) {
|
329
|
+
ev.paymentFailed()
|
330
|
+
return
|
331
|
+
}
|
328
332
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
+
try {
|
334
|
+
const { error: paymentMethodError, paymentMethod } = await this.stripe.createPaymentMethod({
|
335
|
+
elements: this.elements
|
336
|
+
})
|
333
337
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
}
|
346
|
-
return
|
347
|
-
}
|
348
|
-
} catch (e) {
|
349
|
-
console.log(e)
|
338
|
+
if (paymentMethodError) {
|
339
|
+
showFlashMessage(paymentMethodError, 'error')
|
340
|
+
return
|
341
|
+
}
|
342
|
+
|
343
|
+
const { error } = await this.stripe.confirmPayment({
|
344
|
+
clientSecret: this.clientSecretValue,
|
345
|
+
confirmParams: {
|
346
|
+
payment_method: paymentMethod.id,
|
347
|
+
// Stripe will automatically add `payment_intent` and `payment_intent_client_secret` params
|
348
|
+
return_url: this.returnUrlValue
|
350
349
|
}
|
351
|
-
}
|
352
|
-
|
350
|
+
})
|
351
|
+
if (error?.length > 0) {
|
352
|
+
showFlashMessage(error, 'error')
|
353
353
|
}
|
354
|
-
}
|
355
|
-
|
354
|
+
} catch (e) {
|
355
|
+
console.log(e)
|
356
356
|
}
|
357
357
|
}
|
358
358
|
|
@@ -453,4 +453,26 @@ export default class extends Controller {
|
|
453
453
|
|
454
454
|
return { name: 'Tax', amount: amount }
|
455
455
|
}
|
456
|
+
|
457
|
+
ShipAddressAttributes(ev) {
|
458
|
+
if (ev.shippingAddress) {
|
459
|
+
return {
|
460
|
+
quick_checkout: true,
|
461
|
+
firstname: ev.shippingAddress.name.split(' ')[0],
|
462
|
+
lastname: ev.shippingAddress.name.split(' ')[1],
|
463
|
+
address1: ev.shippingAddress.address.line1,
|
464
|
+
address2: ev.shippingAddress.address.line2,
|
465
|
+
city: ev.shippingAddress.address.city,
|
466
|
+
zipcode: ev.shippingAddress.address.postal_code,
|
467
|
+
country_iso: ev.shippingAddress.address.country,
|
468
|
+
state_name: ev.shippingAddress.address.state,
|
469
|
+
phone: ev.billingDetails.phone
|
470
|
+
}
|
471
|
+
}
|
472
|
+
else {
|
473
|
+
return {
|
474
|
+
quick_checkout: true,
|
475
|
+
}
|
476
|
+
}
|
477
|
+
}
|
456
478
|
}
|
@@ -205,11 +205,12 @@ export default class extends Controller {
|
|
205
205
|
|
206
206
|
async updateBillingAddress() {
|
207
207
|
// billing address same as shipping address
|
208
|
-
if (this.billingAddressCheckbox
|
209
|
-
const response = await fetch(
|
208
|
+
if (this.billingAddressCheckbox?.checked) {
|
209
|
+
const response = await fetch(this.checkoutPathValue, {
|
210
210
|
method: 'PATCH',
|
211
211
|
headers: this.spreeApiHeaders,
|
212
212
|
body: JSON.stringify({
|
213
|
+
include: 'billing_address',
|
213
214
|
order: {
|
214
215
|
use_shipping: true
|
215
216
|
}
|
@@ -230,10 +231,11 @@ export default class extends Controller {
|
|
230
231
|
if (this.billingAddressForm.checkValidity()) {
|
231
232
|
const formData = new FormData(this.billingAddressForm);
|
232
233
|
|
233
|
-
const response = await fetch(
|
234
|
+
const response = await fetch(this.checkoutPathValue, {
|
234
235
|
method: 'PATCH',
|
235
236
|
headers: this.spreeApiHeaders,
|
236
237
|
body: JSON.stringify({
|
238
|
+
include: 'billing_address',
|
237
239
|
order: {
|
238
240
|
bill_address_attributes: {
|
239
241
|
firstname: formData.get("order[bill_address_attributes][firstname]"),
|
@@ -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
|
|
data/lib/spree_stripe/version.rb
CHANGED
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.
|
4
|
+
version: 1.2.5
|
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-
|
11
|
+
date: 2025-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree
|