@salla.sa/twilight-components 2.14.346 → 2.14.349

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 (170) hide show
  1. package/dist/cjs/{filepond-D3JT19b9.js → filepond-DFhbfTkt.js} +1 -1
  2. package/dist/cjs/{filepond-plugin-file-poster-vIqpi5Jb.js → filepond-plugin-file-poster-Dj4Zm459.js} +1 -1
  3. package/dist/cjs/{filepond-plugin-file-validate-size-CGka-OOR.js → filepond-plugin-file-validate-size-DsH6GzKJ.js} +1 -1
  4. package/dist/cjs/{filepond-plugin-file-validate-type-D5Xexu4N.js → filepond-plugin-file-validate-type-DfaEudMs.js} +1 -1
  5. package/dist/cjs/{filepond-plugin-image-edit-CIxcoEFX.js → filepond-plugin-image-edit-gz-CV83v.js} +1 -1
  6. package/dist/cjs/{filepond-plugin-image-exif-orientation-yRezDeUb.js → filepond-plugin-image-exif-orientation-DfkLjcpx.js} +1 -1
  7. package/dist/cjs/{filepond-plugin-image-preview-CPE8T2_S.js → filepond-plugin-image-preview-BxaEwNCI.js} +1 -1
  8. package/dist/cjs/{index-B_jylE1-.js → index-C9ymZIiv.js} +1 -1
  9. package/dist/cjs/{index-CBbHmJY_.js → index-DcTksD2K.js} +2 -2
  10. package/dist/cjs/loader.cjs.js +2 -2
  11. package/dist/cjs/salla-accordion_62.cjs.entry.js +10395 -1320
  12. package/dist/cjs/salla-advertisement.cjs.entry.js +1 -1
  13. package/dist/cjs/salla-app-install-alert.cjs.entry.js +1 -1
  14. package/dist/cjs/salla-apps-icons.cjs.entry.js +1 -1
  15. package/dist/cjs/salla-cart-item-offers.cjs.entry.js +1 -1
  16. package/dist/cjs/salla-conditional-offer.cjs.entry.js +1 -1
  17. package/dist/cjs/salla-contacts.cjs.entry.js +1 -1
  18. package/dist/cjs/salla-custom-fields.cjs.entry.js +1 -1
  19. package/dist/cjs/salla-filters-widget.cjs.entry.js +1 -1
  20. package/dist/cjs/salla-filters.cjs.entry.js +1 -1
  21. package/dist/cjs/salla-hook.cjs.entry.js +1 -1
  22. package/dist/cjs/salla-installment.cjs.entry.js +1 -1
  23. package/dist/cjs/salla-loyalty-prize-item.cjs.entry.js +1 -1
  24. package/dist/cjs/salla-loyalty-program.cjs.entry.js +1 -1
  25. package/dist/cjs/salla-metadata.cjs.entry.js +1 -1
  26. package/dist/cjs/salla-notification-item.cjs.entry.js +1 -1
  27. package/dist/cjs/salla-notifications.cjs.entry.js +1 -1
  28. package/dist/cjs/salla-offer.cjs.entry.js +1 -1
  29. package/dist/cjs/salla-order-details-multiple-bundle-product.cjs.entry.js +1 -11
  30. package/dist/cjs/salla-order-details-options.cjs.entry.js +1 -1
  31. package/dist/cjs/salla-order-details.cjs.entry.js +1 -1
  32. package/dist/cjs/salla-order-summary.cjs.entry.js +1 -1
  33. package/dist/cjs/salla-order-totals-card.cjs.entry.js +1 -1
  34. package/dist/cjs/salla-orders.cjs.entry.js +1 -1
  35. package/dist/cjs/salla-payments.cjs.entry.js +1 -1
  36. package/dist/cjs/salla-price-range.cjs.entry.js +1 -1
  37. package/dist/cjs/salla-review-card.cjs.entry.js +1 -1
  38. package/dist/cjs/salla-reviews-page.cjs.entry.js +1 -1
  39. package/dist/cjs/salla-reviews.cjs.entry.js +1 -1
  40. package/dist/cjs/salla-social.cjs.entry.js +1 -1
  41. package/dist/cjs/salla-tiered-offer.cjs.entry.js +1 -1
  42. package/dist/cjs/salla-tooltip.cjs.entry.js +1 -1
  43. package/dist/cjs/salla-trust-badges.cjs.entry.js +1 -1
  44. package/dist/cjs/salla-verify.cjs.entry.js +1 -1
  45. package/dist/cjs/salla-wallet.cjs.entry.js +1 -1
  46. package/dist/cjs/twilight.cjs.js +2 -2
  47. package/dist/cjs/vanilla-picker-BYDLZw1n.js +1045 -0
  48. package/dist/collection/components/salla-color-picker/salla-color-picker.js +67 -37
  49. package/dist/collection/components/salla-count-down/salla-count-down.js +125 -1
  50. package/dist/collection/components/salla-multiple-bundle-product/components/salla-multiple-bundle-product-options-modal.js +4 -5
  51. package/dist/collection/components/salla-multiple-bundle-product/components/salla-multiple-bundle-product-slider.js +1 -1
  52. package/dist/collection/components/salla-order-details/salla-order-details-multiple-bundle-product.js +0 -10
  53. package/dist/collection/components/salla-products-slider/salla-products-slider.js +3 -0
  54. package/dist/collection/components/salla-quick-buy/salla-quick-buy.js +68 -55
  55. package/dist/collection/components/salla-slider/salla-slider.css +691 -238
  56. package/dist/collection/components/salla-slider/salla-slider.js +96 -58
  57. package/dist/components/index.js +2 -2
  58. package/dist/components/salla-color-picker2.js +69 -1056
  59. package/dist/components/salla-count-down2.js +24 -2
  60. package/dist/components/salla-multiple-bundle-product-options-modal2.js +4 -5
  61. package/dist/components/salla-multiple-bundle-product-slider2.js +1 -1
  62. package/dist/components/salla-order-details-multiple-bundle-product2.js +0 -10
  63. package/dist/components/salla-products-slider2.js +3 -0
  64. package/dist/components/salla-quick-buy2.js +367 -139
  65. package/dist/components/salla-slider2.js +9881 -61
  66. package/dist/components/vanilla-picker.js +1043 -0
  67. package/dist/esm/{filepond-ESI025KA.js → filepond-DQR2YBu7.js} +1 -1
  68. package/dist/esm/{filepond-plugin-file-poster-CWHjkl55.js → filepond-plugin-file-poster-XvYa1rlk.js} +1 -1
  69. package/dist/esm/{filepond-plugin-file-validate-size-B7W5i7Mk.js → filepond-plugin-file-validate-size-BRBnctOE.js} +1 -1
  70. package/dist/esm/{filepond-plugin-file-validate-type-B1Ny76Ep.js → filepond-plugin-file-validate-type-BuD6F1gi.js} +1 -1
  71. package/dist/esm/{filepond-plugin-image-edit-DfqS6NSZ.js → filepond-plugin-image-edit-BJ8YnBRL.js} +1 -1
  72. package/dist/esm/{filepond-plugin-image-exif-orientation-3kpdQNdB.js → filepond-plugin-image-exif-orientation-BGad_AoX.js} +1 -1
  73. package/dist/esm/{filepond-plugin-image-preview-Ck91BQiY.js → filepond-plugin-image-preview-Cb6UzPfa.js} +1 -1
  74. package/dist/esm/{index-gdKTeC4S.js → index-Bhszo8cU.js} +2 -2
  75. package/dist/esm/{index-5xSCOnsp.js → index-DIfeuyTs.js} +1 -1
  76. package/dist/esm/loader.js +3 -3
  77. package/dist/esm/salla-accordion_62.entry.js +10395 -1320
  78. package/dist/esm/salla-advertisement.entry.js +1 -1
  79. package/dist/esm/salla-app-install-alert.entry.js +1 -1
  80. package/dist/esm/salla-apps-icons.entry.js +1 -1
  81. package/dist/esm/salla-cart-item-offers.entry.js +1 -1
  82. package/dist/esm/salla-conditional-offer.entry.js +1 -1
  83. package/dist/esm/salla-contacts.entry.js +1 -1
  84. package/dist/esm/salla-custom-fields.entry.js +1 -1
  85. package/dist/esm/salla-filters-widget.entry.js +1 -1
  86. package/dist/esm/salla-filters.entry.js +1 -1
  87. package/dist/esm/salla-hook.entry.js +1 -1
  88. package/dist/esm/salla-installment.entry.js +1 -1
  89. package/dist/esm/salla-loyalty-prize-item.entry.js +1 -1
  90. package/dist/esm/salla-loyalty-program.entry.js +1 -1
  91. package/dist/esm/salla-metadata.entry.js +1 -1
  92. package/dist/esm/salla-notification-item.entry.js +1 -1
  93. package/dist/esm/salla-notifications.entry.js +1 -1
  94. package/dist/esm/salla-offer.entry.js +1 -1
  95. package/dist/esm/salla-order-details-multiple-bundle-product.entry.js +1 -11
  96. package/dist/esm/salla-order-details-options.entry.js +1 -1
  97. package/dist/esm/salla-order-details.entry.js +1 -1
  98. package/dist/esm/salla-order-summary.entry.js +1 -1
  99. package/dist/esm/salla-order-totals-card.entry.js +1 -1
  100. package/dist/esm/salla-orders.entry.js +1 -1
  101. package/dist/esm/salla-payments.entry.js +1 -1
  102. package/dist/esm/salla-price-range.entry.js +1 -1
  103. package/dist/esm/salla-review-card.entry.js +1 -1
  104. package/dist/esm/salla-reviews-page.entry.js +1 -1
  105. package/dist/esm/salla-reviews.entry.js +1 -1
  106. package/dist/esm/salla-social.entry.js +1 -1
  107. package/dist/esm/salla-tiered-offer.entry.js +1 -1
  108. package/dist/esm/salla-tooltip.entry.js +1 -1
  109. package/dist/esm/salla-trust-badges.entry.js +1 -1
  110. package/dist/esm/salla-verify.entry.js +1 -1
  111. package/dist/esm/salla-wallet.entry.js +1 -1
  112. package/dist/esm/twilight.js +3 -3
  113. package/dist/esm/vanilla-picker-C4Kwbr5L.js +1043 -0
  114. package/dist/twilight/{p-936a76d1.entry.js → p-004be2ff.entry.js} +1 -1
  115. package/dist/twilight/{p-0a4b04a4.entry.js → p-0daa34c4.entry.js} +1 -1
  116. package/dist/twilight/{p-6bd166a7.entry.js → p-112e9574.entry.js} +1 -1
  117. package/dist/twilight/{p-369ada5a.entry.js → p-129e02c2.entry.js} +1 -1
  118. package/dist/twilight/{p-d5da6f45.entry.js → p-1bfef164.entry.js} +1 -1
  119. package/dist/twilight/{p-36a95a0f.entry.js → p-25f64b3e.entry.js} +1 -1
  120. package/dist/twilight/{p-8563e747.entry.js → p-307b5fa0.entry.js} +1 -1
  121. package/dist/twilight/{p-a7a488d5.entry.js → p-46fb77ce.entry.js} +1 -1
  122. package/dist/twilight/{p-b0e7c134.entry.js → p-48617181.entry.js} +1 -1
  123. package/dist/twilight/{p-4e98e961.entry.js → p-48df4495.entry.js} +1 -1
  124. package/dist/twilight/p-4fc33cee.entry.js +4 -0
  125. package/dist/twilight/{p-aefe5639.entry.js → p-55c9e7fe.entry.js} +1 -1
  126. package/dist/twilight/{p-5570cae4.entry.js → p-574bd55f.entry.js} +1 -1
  127. package/dist/twilight/{p-ef0fa205.entry.js → p-5bb9ace5.entry.js} +1 -1
  128. package/dist/twilight/{p-eab13555.entry.js → p-60747f3b.entry.js} +1 -1
  129. package/dist/twilight/{p-3e410acd.entry.js → p-6222b0fa.entry.js} +1 -1
  130. package/dist/twilight/{p-b8f7b4eb.entry.js → p-64c18854.entry.js} +1 -1
  131. package/dist/twilight/{p-e465a952.entry.js → p-66c5dcd3.entry.js} +1 -1
  132. package/dist/twilight/{p-343c8271.entry.js → p-7a706d50.entry.js} +1 -1
  133. package/dist/twilight/{p-ad2b2919.entry.js → p-911bbc7d.entry.js} +1 -1
  134. package/dist/twilight/{p-7b5906b8.entry.js → p-9f541d63.entry.js} +1 -1
  135. package/dist/twilight/{p-DId3Z42j.js → p-B-MyfVCv.js} +1 -1
  136. package/dist/twilight/{p-D3JRC8L6.js → p-BVmy-j16.js} +1 -1
  137. package/dist/twilight/{p-gdKTeC4S.js → p-Bhszo8cU.js} +1 -1
  138. package/dist/twilight/{p-CUtvZOiz.js → p-BvldZUSR.js} +1 -1
  139. package/dist/twilight/{p-CMYBgZIX.js → p-ByJhdNbq.js} +1 -1
  140. package/dist/twilight/{p-DH5ljldi.js → p-CmuTtBET.js} +1 -1
  141. package/dist/twilight/{p-EnsROQgl.js → p-CuNS5C_o.js} +2 -2
  142. package/dist/twilight/{p-DpJnHcvE.js → p-Cy9bcLMa.js} +1 -1
  143. package/dist/twilight/{p-rYLDeLaL.js → p-DAM1DKLB.js} +1 -1
  144. package/dist/twilight/p-NTgp-Syt.js +11 -0
  145. package/dist/twilight/{p-5099bc51.entry.js → p-a25fe3c1.entry.js} +1 -1
  146. package/dist/twilight/{p-49638a91.entry.js → p-a5df8334.entry.js} +1 -1
  147. package/dist/twilight/{p-46b242d9.entry.js → p-a6f250b8.entry.js} +1 -1
  148. package/dist/twilight/{p-ebd8dbf8.entry.js → p-ae93ed50.entry.js} +1 -1
  149. package/dist/twilight/{p-f64cd638.entry.js → p-af8daa75.entry.js} +1 -1
  150. package/dist/twilight/{p-8100a941.entry.js → p-b0abcc89.entry.js} +1 -1
  151. package/dist/twilight/{p-360a28b9.entry.js → p-b8a203c1.entry.js} +1 -1
  152. package/dist/twilight/p-cadbe7b6.entry.js +4 -0
  153. package/dist/twilight/{p-1037bca4.entry.js → p-cc43a1bd.entry.js} +1 -1
  154. package/dist/twilight/{p-db68f32e.entry.js → p-cc6238be.entry.js} +1 -1
  155. package/dist/twilight/{p-158398ff.entry.js → p-de290cc2.entry.js} +1 -1
  156. package/dist/twilight/{p-8a1aa61c.entry.js → p-ed0f40e2.entry.js} +1 -1
  157. package/dist/twilight/{p-003a77fe.entry.js → p-f3d3e11e.entry.js} +1 -1
  158. package/dist/twilight/{p-8418b725.entry.js → p-f4bf39fb.entry.js} +1 -1
  159. package/dist/twilight/twilight.esm.js +1 -1
  160. package/dist/types/components/salla-color-picker/interfaces.d.ts +9 -0
  161. package/dist/types/components/salla-color-picker/salla-color-picker.d.ts +4 -1
  162. package/dist/types/components/salla-count-down/salla-count-down.d.ts +22 -0
  163. package/dist/types/components/salla-order-details/salla-order-details-multiple-bundle-product.d.ts +0 -1
  164. package/dist/types/components/salla-products-slider/salla-products-slider.d.ts +1 -0
  165. package/dist/types/components/salla-quick-buy/salla-quick-buy.d.ts +2 -0
  166. package/dist/types/components/salla-slider/salla-slider.d.ts +12 -3
  167. package/dist/types/components.d.ts +48 -0
  168. package/package.json +6 -6
  169. package/dist/twilight/p-04e81b46.entry.js +0 -11
  170. package/dist/twilight/p-1445c077.entry.js +0 -4
@@ -4,7 +4,7 @@
4
4
  import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
5
5
  import { a as axios } from './axios.js';
6
6
 
7
- var Http = {
7
+ var http = {
8
8
  request(method, url, data, successCb = null, errorCb = null) {
9
9
  return axios
10
10
  .request({url, data, method: method.toLowerCase(), responseType: 'json'})
@@ -162,27 +162,70 @@ var DetectOS = {
162
162
  * @param {ApplePayPaymentContact} shippingContact
163
163
  *
164
164
  */
165
- function mutateShipmentAddress(SallaApplePay, shippingContact, isAuthorized = false) {
166
- console.log('mutateShipmentAddress called', shippingContact, isAuthorized);
165
+ async function mutateShippingContact(SallaApplePay, shippingContact, isAuthorized = false) {
166
+ salla.logger.log('🍏 Pay: mutateShippingContact called', shippingContact, isAuthorized);
167
167
 
168
- if (!SallaApplePay.detail.requiredShippingContactFields) {
168
+ if (!SallaApplePay.detail.requiredShippingContactFields || SallaApplePay.detail.requiredShippingContactFields.length == 0) {
169
169
  return;
170
170
  }
171
171
 
172
- return Http.post(
172
+ if (isAuthorized) {
173
+ if (isGuestCheckout()) {
174
+
175
+ if (
176
+ !shippingContact.emailAddress ||
177
+ !shippingContact.givenName ||
178
+ !shippingContact.familyName ||
179
+ !shippingContact.phoneNumber
180
+ ) {
181
+
182
+ salla.logger.warn('🍏 Pay: Guest contact fields are required', shippingContact);
183
+
184
+ const errors = [];
185
+ if (!shippingContact.emailAddress) {
186
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'emailAddress', 'Email address is required'));
187
+ }
188
+
189
+ if (!shippingContact.phoneNumber) {
190
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'phoneNumber', 'Phone number is required'));
191
+ }
192
+
193
+ if (!shippingContact.givenName || !shippingContact.familyName) {
194
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'name', 'Name is required'));
195
+ }
196
+
197
+ SallaApplePay.session.completePayment({
198
+ status: SallaApplePay.session.STATUS_INVALID_SHIPPING_CONTACT,
199
+ errors: errors
200
+ });
201
+
202
+ return;
203
+ }
204
+
205
+ await updateGuestContact(SallaApplePay, shippingContact);
206
+
207
+ }
208
+
209
+ // if authorized and not guest checkout, do nothing address already added
210
+ return;
211
+ }
212
+
213
+ if (!SallaApplePay.detail.requiredShippingContactFields.includes('postalAddress')) {
214
+ return;
215
+ }
216
+
217
+ return http.post(
173
218
  SallaApplePay.detail.shippingContactSelected.url.replace('{id}', SallaApplePay.id),
174
219
  {
175
220
  'country': shippingContact.country,
176
221
  'city': shippingContact.locality,
177
- 'local': shippingContact.subLocality,
222
+ 'local': shippingContact.subLocality || shippingContact.administrativeArea || shippingContact.locality,
178
223
  'description': shippingContact.subAdministrativeArea,
179
224
  'street': shippingContact.addressLines?.join(", ") || shippingContact.administrativeArea,
180
225
  'country_code': shippingContact.countryCode,
181
226
  'postal_code': shippingContact.postalCode,
182
- 'is_authorized': isAuthorized
183
227
  },
184
228
  async ({ data }) => {
185
- if (isAuthorized) { return }
186
229
  if (typeof SallaApplePay.detail.shippingContactSelected.onSuccess === 'function') {
187
230
  SallaApplePay.detail.shippingContactSelected.onSuccess(data);
188
231
  }
@@ -193,25 +236,29 @@ function mutateShipmentAddress(SallaApplePay, shippingContact, isAuthorized = fa
193
236
  if (!SallaApplePay.shipping_methods || (SallaApplePay.shipping_methods && !SallaApplePay.shipping_methods.length)) {
194
237
  salla.logger.warn('🍏 Pay: We dont found any supported methods', data);
195
238
 
196
- return SallaApplePay.session.completeShippingContactSelection({
239
+ SallaApplePay.session.completeShippingContactSelection({
197
240
  status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
198
241
  errors: [
199
242
  new window.ApplePayError('addressUnserviceable')
200
243
  ]
201
244
  });
245
+
246
+ return
202
247
  }
203
248
 
204
249
  try {
205
- await SallaApplePay.selectApplePayShippingMethod(SallaApplePay.shipping_methods[0]['ship_id'], SallaApplePay.shipping_methods[0]['private_ship_id']);
250
+ await SallaApplePay.selectApplePayShippingMethod(SallaApplePay.shipping_methods[0]);
206
251
  } catch (error) {
207
252
  salla.logger.warn('Failed set the shipping details to api', error);
208
253
 
209
- return SallaApplePay.session.completeShippingContactSelection({
254
+ SallaApplePay.session.completeShippingContactSelection({
210
255
  status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
211
256
  errors: [
212
257
  new window.ApplePayError('addressUnserviceable')
213
258
  ]
214
259
  });
260
+
261
+ return;
215
262
  }
216
263
 
217
264
  try {
@@ -219,20 +266,25 @@ function mutateShipmentAddress(SallaApplePay, shippingContact, isAuthorized = fa
219
266
  } catch (error) {
220
267
  salla.logger.warn('🍏 Pay: Failed recalculate total', error);
221
268
 
222
- return SallaApplePay.session.completeShippingContactSelection({
269
+ SallaApplePay.session.completeShippingContactSelection({
223
270
  status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
224
271
  errors: [
225
272
  new window.ApplePayError('addressUnserviceable')
226
273
  ]
227
274
  });
275
+
276
+ return;
228
277
  }
229
278
 
230
- SallaApplePay.session.completeShippingContactSelection({
279
+ const updatedShippingContactSelection = {
231
280
  newTotal: SallaApplePay.prepareTotal(),
232
281
  newLineItems: SallaApplePay.prepareLineItems(),
233
282
  newShippingMethods: SallaApplePay.mappingShippingMethods(SallaApplePay.shipping_methods)
234
- });
283
+ };
284
+
285
+ salla.logger.log('🍏 Pay: completeShippingContactSelection', updatedShippingContactSelection);
235
286
 
287
+ SallaApplePay.session.completeShippingContactSelection(updatedShippingContactSelection);
236
288
  },
237
289
  ({ response }) => {
238
290
  salla.logger.warn('🍏 Pay: Failed add address via api', response);
@@ -244,19 +296,11 @@ function mutateShipmentAddress(SallaApplePay, shippingContact, isAuthorized = fa
244
296
  // parse 422 errors
245
297
  let fields = response?.data?.error?.fields;
246
298
 
247
- let errors = [];
248
-
249
- if (fields?.country_code) {
250
- errors.push(new window.ApplePayError('shippingContactInvalid', 'countryCode', fields?.country_code[0]));
251
- }
252
-
253
- if (fields?.city) {
254
- errors.push(new window.ApplePayError('shippingContactInvalid', 'locality', fields?.city[0]));
255
- }
256
-
257
- if (fields?.country) {
258
- errors.push(new window.ApplePayError('shippingContactInvalid', 'country', fields?.country[0]));
259
- }
299
+ let errors = getApplePayErrors({
300
+ countryCode: fields?.country_code && fields.country_code.length > 0 ? fields.country_code[0] : null,
301
+ locality: fields?.city && fields.city.length > 0 ? fields.city[0] : null,
302
+ country: fields?.country && fields.country.length > 0 ? fields.country[0] : null,
303
+ });
260
304
 
261
305
  if (errors.length === 0 && response?.data?.error?.message) {
262
306
  errors.push(new window.ApplePayError('shippingContactInvalid', 'locality', response?.data?.error?.message));
@@ -272,6 +316,56 @@ function mutateShipmentAddress(SallaApplePay, shippingContact, isAuthorized = fa
272
316
  );
273
317
  }
274
318
 
319
+ function isGuestCheckout() {
320
+ return salla.config.isGuest() && salla.config.get('store.features').includes('guest-checkout');
321
+ }
322
+
323
+ /**
324
+ * Update guest contact
325
+ *
326
+ * @param {SallaApplePay} SallaApplePay
327
+ * @param {ApplePayPaymentContact} shippingContact
328
+ *
329
+ */
330
+ async function updateGuestContact(SallaApplePay, shippingContact) {
331
+ salla.logger.log('🍏 Pay: Updating guest contact', shippingContact);
332
+
333
+ return new Promise((resolve, reject) => {
334
+ http.post(
335
+ SallaApplePay.detail.guestContactSelected.url.replace('{id}', SallaApplePay.id),
336
+ {
337
+ 'email': shippingContact.emailAddress || null,
338
+ 'first_name': shippingContact.givenName || null,
339
+ 'last_name': shippingContact.familyName || null,
340
+ 'phone_number': shippingContact.phoneNumber || null,
341
+ 'country_code': shippingContact.countryCode || null,
342
+ },
343
+ async ({ data }) => {
344
+ if (typeof SallaApplePay.detail.guestContactSelected?.onSuccess === 'function') {
345
+ SallaApplePay.detail.guestContactSelected.onSuccess(data);
346
+ }
347
+ resolve(data);
348
+ },
349
+ ({ response }) => {
350
+ salla.logger.warn('🍏 Pay: Failed to update guest contact via api', response);
351
+
352
+ if (typeof SallaApplePay.detail.guestContactSelected?.onFailed === 'function') {
353
+ SallaApplePay.detail.guestContactSelected.onFailed(response);
354
+ }
355
+
356
+ // Reject the promise so it can be caught in onPaymentAuthorized
357
+ reject({ response });
358
+ }
359
+ );
360
+ });
361
+ }
362
+
363
+ function getApplePayErrors(fields) {
364
+ return Object.entries(fields)
365
+ .filter(([field, messages]) => messages && messages.length > 0)
366
+ .map(([field, messages]) => new window.ApplePayError('shippingContactInvalid', field, messages[0]));
367
+ }
368
+
275
369
  window.Salla = window.Salla || {};
276
370
  window.Salla.Payments = window.Salla.Payments || {};
277
371
 
@@ -314,6 +408,8 @@ window.SallaApplePay = {
314
408
  request: undefined,
315
409
  id: undefined,
316
410
  countryCode: null,
411
+ totals: [],
412
+ shippingCompany: null,
317
413
  init: function () {
318
414
  document.removeEventListener('payments::apple-pay.start-transaction', SallaApplePay.startSession);
319
415
  Salla.event.addEventListener('payments::apple-pay.start-transaction', SallaApplePay.startSession);
@@ -355,7 +451,7 @@ window.SallaApplePay = {
355
451
  SallaApplePay.detail.items = [
356
452
  {
357
453
  label: salla.lang.get('pages.cart.items_total'),
358
- amount: SallaApplePay.detail.amount
454
+ amount: parseFloat(SallaApplePay.detail.amount).toString()
359
455
  }
360
456
  ];
361
457
  }
@@ -368,10 +464,14 @@ window.SallaApplePay = {
368
464
  // apple ask to use business name
369
465
  label: window.location.hostname || 'Salla',
370
466
  //label: salla.lang.get('pages.cart.final_total'),
371
- amount: SallaApplePay.detail.amount
467
+ amount: parseFloat(SallaApplePay.detail.amount).toString()
372
468
  }
373
469
  },
374
470
 
471
+ isPhysical() {
472
+ return SallaApplePay.detail?.requiredShippingContactFields?.includes('postalAddress');
473
+ },
474
+
375
475
  startSession: async function (event) {
376
476
 
377
477
  SallaApplePay.detail = event.detail || event;
@@ -412,30 +512,62 @@ window.SallaApplePay = {
412
512
  SallaApplePay.session.onvalidatemerchant = SallaApplePay.onValidateMerchant;
413
513
  SallaApplePay.session.onpaymentauthorized = SallaApplePay.onPaymentAuthorized;
414
514
  SallaApplePay.session.oncancel = SallaApplePay.onCancel;
415
- SallaApplePay.session.oncouponcodechanged = SallaApplePay.oncouponcodechanged;
416
- SallaApplePay.session.onpaymentmethodselected = SallaApplePay.onpaymentmethodselected;
515
+ SallaApplePay.session.oncouponcodechanged = SallaApplePay.onCouponCodeChanged;
516
+ SallaApplePay.session.onpaymentmethodselected = SallaApplePay.onPaymentMethodSelected;
417
517
 
418
518
  SallaApplePay.session.begin();
419
519
  },
420
- async onpaymentmethodselected(event) {
421
- await SallaApplePay.recalculateTotal();
422
- const updatedPaymentDetails = {
520
+ onPaymentMethodSelected: async (event) => {
521
+ salla.logger.log('🍏 Pay: onPaymentMethodSelected', event);
522
+
523
+ // perform recalculate here only if digital product
524
+ // if physical recalculate performed with shipping company
525
+ if (!SallaApplePay.isPhysical()) {
526
+ try {
527
+ await SallaApplePay.recalculateTotal();
528
+
529
+ const updatedPaymentDetails = {
530
+ newTotal: SallaApplePay.prepareTotal(),
531
+ newLineItems: SallaApplePay.prepareLineItems()
532
+ };
533
+
534
+ salla.logger.log('🍏 Pay: completePaymentMethodSelection', updatedPaymentDetails);
535
+
536
+ SallaApplePay.session.completePaymentMethodSelection(updatedPaymentDetails);
537
+
538
+ } catch (error) {
539
+ salla.logger.warn('🍏 Pay: Failed recalculate total', error);
540
+
541
+ SallaApplePay.session.completePaymentMethodSelection({
542
+ newTotal: SallaApplePay.prepareTotal(),
543
+ newLineItems: SallaApplePay.prepareLineItems(),
544
+ status: SallaApplePay.session.STATUS_FAILURE,
545
+ errors: [new window.ApplePayError("unknown", undefined, error?.response?.data?.error?.message || error?.response?.data?.error?.code || 'Failed to recalculate total')]
546
+ });
547
+ }
548
+ return;
549
+ }
550
+
551
+ salla.logger.log('🍏 Pay: completePaymentMethodSelection', {
423
552
  newTotal: SallaApplePay.prepareTotal(),
424
553
  newLineItems: SallaApplePay.prepareLineItems(),
425
- };
554
+ });
426
555
 
427
- SallaApplePay.session.completePaymentMethodSelection(updatedPaymentDetails);
556
+ SallaApplePay.session.completePaymentMethodSelection({
557
+ newTotal: SallaApplePay.prepareTotal(),
558
+ newLineItems: SallaApplePay.prepareLineItems(),
559
+ });
428
560
  },
429
561
 
430
- oncouponcodechanged(event) {
562
+ onCouponCodeChanged(event) {
431
563
  Salla.event.dispatch('payments::apple-pay.coupon.change', event);
432
564
 
433
- return Http.post(SallaApplePay.detail.oncouponcodechanged.url.replace('{id}', SallaApplePay.id), {
565
+ return http.post(SallaApplePay.detail.onCouponCodeChanged.url.replace('{id}', SallaApplePay.id), {
434
566
  'coupon': event.couponCode,
435
567
  'payment_method': 'apple_pay',
436
568
  }, async ({ data }) => {
437
- if (typeof SallaApplePay.detail.oncouponcodechanged.onSuccess === 'function') {
438
- SallaApplePay.detail.oncouponcodechanged.onSuccess(data);
569
+ if (typeof SallaApplePay.detail.onCouponCodeChanged.onSuccess === 'function') {
570
+ SallaApplePay.detail.onCouponCodeChanged.onSuccess(data);
439
571
  }
440
572
 
441
573
  salla.log('🍏 Pay: Coupon applied success');
@@ -452,8 +584,8 @@ window.SallaApplePay = {
452
584
  Salla.event.dispatch('payments::apple-pay.coupon.failed', response);
453
585
 
454
586
  // SallaApplePay.abortSession();
455
- if (typeof SallaApplePay.detail.oncouponcodechanged.onFailed === 'function') {
456
- SallaApplePay.detail.oncouponcodechanged.onFailed(response);
587
+ if (typeof SallaApplePay.detail.onCouponCodeChanged.onFailed === 'function') {
588
+ SallaApplePay.detail.onCouponCodeChanged.onFailed(response);
457
589
  }
458
590
 
459
591
  await SallaApplePay.recalculateTotal();
@@ -479,35 +611,80 @@ window.SallaApplePay = {
479
611
  onPaymentAuthorized: async (event) => {
480
612
  salla.logger.log('🍏 Pay: onPaymentAuthorized', event.payment);
481
613
 
482
- // Update the payment address
483
- await mutateShipmentAddress(SallaApplePay, event.payment.shippingContact, true);
614
+ // update guest details
615
+ try {
616
+ await mutateShippingContact(SallaApplePay, event.payment.shippingContact, true);
617
+ } catch (error) {
618
+ salla.logger.error('🍏 Pay: Failed to update guest contact details', error);
619
+
620
+ const response = error?.response || error;
621
+
622
+ // Parse backend errors for shipping contact fields
623
+ const fields = response?.data?.error?.fields || {};
624
+ const errors = [];
625
+
626
+ // Map backend field errors to Apple Pay contact field errors
627
+ if (fields?.email && fields.email.length > 0) {
628
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'emailAddress', fields.email[0]));
629
+ }
630
+
631
+ if (fields?.phone && fields.phone.length > 0) {
632
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'phoneNumber', fields.phone[0]));
633
+ }
634
+
635
+ if (fields?.first_name && fields.first_name.length > 0) {
636
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'name', fields.first_name[0]));
637
+ } else if (fields?.last_name && fields.last_name.length > 0) {
638
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'name', fields.last_name[0]));
639
+ }
640
+
641
+ // If no specific field errors, use general error message
642
+ if (errors.length === 0) {
643
+ const errorMessage = response?.data?.error?.message || response?.data?.error?.code || 'Invalid shipping contact details';
644
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'name', errorMessage));
645
+ }
646
+
647
+ Salla.event.dispatch('payments::apple-pay.authorized.failed', response);
648
+
649
+ if (typeof SallaApplePay.detail.authorized.onFailed === 'function') {
650
+ SallaApplePay.detail.authorized.onFailed(response);
651
+ }
652
+
653
+ // Complete shipping contact selection with invalid contact status
654
+ SallaApplePay.session.completePayment({
655
+ status: ApplePaySession.STATUS_INVALID_SHIPPING_CONTACT,
656
+ errors: errors
657
+ });
658
+
659
+ return;
660
+ }
484
661
 
485
662
  Salla.event.dispatch('payments::apple-pay.authorized.init', event);
486
- Http.post(SallaApplePay.detail.authorized.url.replace('{id}', SallaApplePay.id), {
663
+ http.post(SallaApplePay.detail.authorized.url.replace('{id}', SallaApplePay.id), {
487
664
  payment_method: 'apple_pay',
488
665
  applepay_token: JSON.stringify(event.payment)
489
666
  }, ({ data }) => {
490
667
  Salla.event.dispatch('payments::apple-pay.authorized.success', data);
491
668
 
492
- SallaApplePay.session.completePayment(ApplePaySession.STATUS_SUCCESS);
493
-
494
669
  if (typeof SallaApplePay.detail.authorized.onSuccess === 'function') {
495
670
  SallaApplePay.detail.authorized.onSuccess(data);
496
671
  }
672
+
673
+ SallaApplePay.session.completePayment(ApplePaySession.STATUS_SUCCESS);
497
674
  }, (error) => {
498
675
 
499
676
  let response = error?.response;
500
677
 
501
678
  Salla.event.dispatch('payments::apple-pay.authorized.failed', response);
502
679
 
503
- SallaApplePay.session.completePayment({
504
- status: ApplePaySession.STATUS_FAILURE,
505
- errors: [new ApplePayError("unknown", undefined, response?.data?.error?.message || response?.data?.error?.code || 'Failed to parse authorized response')]
506
- });
507
-
508
680
  if (typeof SallaApplePay.detail.authorized.onFailed === 'function') {
509
681
  SallaApplePay.detail.authorized.onFailed(response);
510
682
  }
683
+
684
+ SallaApplePay.session.completePayment({
685
+ status: ApplePaySession.STATUS_FAILURE,
686
+ errors: [new window.ApplePayError("unknown", undefined, response?.data?.error?.message || response?.data?.error?.code || 'Failed to parse authorized response')]
687
+ });
511
688
  });
512
689
  },
513
690
 
@@ -522,7 +699,7 @@ window.SallaApplePay = {
522
699
  Salla.event.dispatch('payments::apple-pay.validate-merchant.init', event);
523
700
 
524
701
  // Post request to validate merchant
525
- const { data } = await Http.post(SallaApplePay.detail.validateMerchant.url.replace('{id}', SallaApplePay.id), {
702
+ const { data } = await http.post(SallaApplePay.detail.validateMerchant.url.replace('{id}', SallaApplePay.id), {
526
703
  validation_url: event.validationURL
527
704
  });
528
705
 
@@ -571,7 +748,7 @@ window.SallaApplePay = {
571
748
  salla.logger.log('🍏 Pay: onShippingContactSelected', event.shippingContact);
572
749
 
573
750
  // create address for shipping calculation
574
- mutateShipmentAddress(SallaApplePay, event.shippingContact);
751
+ await mutateShippingContact(SallaApplePay, event.shippingContact);
575
752
  },
576
753
 
577
754
  /**
@@ -581,25 +758,54 @@ window.SallaApplePay = {
581
758
  *
582
759
  */
583
760
  onShippingMethodSelected: async (event) => {
584
- salla.logger.log(event);
585
761
 
586
762
  let shipping_ids = event.shippingMethod.identifier.split(',');
763
+ let shippingMethod = {
764
+ ship_id: shipping_ids[0],
765
+ private_ship_id: typeof shipping_ids[1] === 'undefined' ? null : shipping_ids[1],
766
+ type: typeof shipping_ids[2] === 'undefined' ? null : shipping_ids[2],
767
+ route_id: typeof shipping_ids[3] === 'undefined' ? null : shipping_ids[3],
768
+ };
587
769
 
588
- try {
589
- await SallaApplePay.selectApplePayShippingMethod(shipping_ids[0], typeof shipping_ids[1] === 'undefined' ? null : shipping_ids[1]);
770
+ salla.logger.log('🍏 Pay: onShippingMethodSelected', {
771
+ event,
772
+ previous: SallaApplePay.shippingCompany,
773
+ current: shippingMethod,
774
+ });
590
775
 
591
- await SallaApplePay.recalculateTotal();
776
+ if (SallaApplePay.shouldUpdateShippingCompany(shippingMethod)) {
777
+ try {
778
+
779
+ await SallaApplePay.selectApplePayShippingMethod(shippingMethod);
780
+
781
+ await SallaApplePay.recalculateTotal();
782
+
783
+ } catch (error) {
784
+ salla.logger.warn('🍏 Pay: Failed set the shipping details to api', error);
785
+
786
+ // todo :: find a better handling for error without abort session
787
+ SallaApplePay.session.completeShippingMethodSelection({
788
+ newTotal: SallaApplePay.prepareTotal(),
789
+ newLineItems: SallaApplePay.prepareLineItems(),
790
+ status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
791
+ errors: [
792
+ new window.ApplePayError('addressUnserviceable')
793
+ ]
794
+ });
795
+
796
+ return;
797
+ }
798
+ }
592
799
 
593
- SallaApplePay.session.completeShippingMethodSelection({
594
- newTotal: SallaApplePay.prepareTotal(),
595
- newLineItems: SallaApplePay.prepareLineItems(),
596
- });
597
- } catch (error) {
598
- salla.logger.warn('🍏 Pay: Failed set the shipping details to api', error);
800
+ salla.logger.log('🍏 Pay: completeShippingMethodSelection', {
801
+ newTotal: SallaApplePay.prepareTotal(),
802
+ newLineItems: SallaApplePay.prepareLineItems(),
803
+ });
599
804
 
600
- // todo :: find a better handling for error without abort session
601
- SallaApplePay.abortSession();
602
- }
805
+ SallaApplePay.session.completeShippingMethodSelection({
806
+ newTotal: SallaApplePay.prepareTotal(),
807
+ newLineItems: SallaApplePay.prepareLineItems(),
808
+ });
603
809
  },
604
810
 
605
811
 
@@ -609,6 +815,10 @@ window.SallaApplePay = {
609
815
  }
610
816
  },
611
817
 
818
+ shouldUpdateShippingCompany(shippingCompany) {
819
+ return SallaApplePay.shippingCompany?.ship_id != shippingCompany?.ship_id || SallaApplePay.shippingCompany?.private_ship_id != shippingCompany?.private_ship_id
820
+ },
821
+
612
822
  getApplePaySessionVersion: () => {
613
823
  const userAgent = navigator.userAgent || navigator.vendor || window.opera;
614
824
 
@@ -634,11 +844,17 @@ window.SallaApplePay = {
634
844
  },
635
845
 
636
846
  recalculateTotal: () => {
637
- salla.logger.log('Recalculate Total');
847
+ salla.logger.log('🍏 Pay: recalculate total');
638
848
 
639
- return Http.requestWithSupportAjax(SallaApplePay.detail.recalculateTotal.url.replace('{id}', SallaApplePay.id), {}, 'get').then((data) => {
849
+ return http.get(SallaApplePay.detail.recalculateTotal.url.replace('{id}', SallaApplePay.id), ({ data }) => {
850
+ salla.logger.log('🍏 Pay: recalculate total success', data);
640
851
  let cart = data.data.initial_data?.cart || data.data.cart;
641
- let payments = data.data.initial_data?.payments;
852
+ let payments = data.data.initial_data?.payments || data.data.payments;
853
+
854
+ salla.logger.log('🍏 Pay: recalculate total success', {
855
+ cart,
856
+ payments
857
+ });
642
858
 
643
859
  // todo :: enhance response from backend
644
860
  SallaApplePay.detail.amount = payments?.gateways?.applePay?.supportedMultiCurrency ? cart.total_in_customer_currency : cart.total;
@@ -651,9 +867,9 @@ window.SallaApplePay = {
651
867
 
652
868
  // lets remove last element (final total)
653
869
  SallaApplePay.detail.items.pop();
870
+ SallaApplePay.totals = SallaApplePay.detail.items;
654
871
 
655
- return data;
656
- }).catch((error) => {
872
+ }, (error) => {
657
873
  salla.logger.warn('🍏 Pay: recalculate total failed', error);
658
874
 
659
875
  // general error
@@ -662,27 +878,26 @@ window.SallaApplePay = {
662
878
  },
663
879
 
664
880
 
665
- selectApplePayShippingMethod: (company_id, private_company_id) => {
666
- salla.logger.log('🍏 Pay: select shipping method ', 'company_id : ' + company_id, 'private_company_id: ' + private_company_id);
881
+ selectApplePayShippingMethod: (shippingMethod) => {
882
+ salla.logger.log('🍏 Pay: select shipping method ', shippingMethod);
883
+ SallaApplePay.shippingCompany = shippingMethod;
884
+
667
885
  const payload = {
668
886
  address_id: SallaApplePay.address_id,
669
- company_id: company_id,
670
- private_company_id: private_company_id,
887
+ company_id: shippingMethod.ship_id,
888
+ private_company_id: shippingMethod.private_ship_id,
889
+ type: shippingMethod.type || undefined,
890
+ route_id: shippingMethod.route_id || undefined,
671
891
  payment_method: 'apple_pay'
672
892
  };
673
- const selectedShippingMethod = SallaApplePay.shipping_methods?.find((item)=> item.company == company_id || item.ship_id == company_id);
674
- if (selectedShippingMethod?.route_id){
675
- payload.shipping_route_id = selectedShippingMethod.route_id;
676
- payload.type = selectedShippingMethod.type;
677
- }
678
- return Http.requestWithSupportAjax(SallaApplePay.detail.shippingMethodSelected.url.replace('{id}', SallaApplePay.id), payload, 'post').then(() => {
893
+ return http.post(SallaApplePay.detail.shippingMethodSelected.url.replace('{id}', SallaApplePay.id), payload, ({ data }) => {
679
894
  if (typeof SallaApplePay.detail.shippingMethodSelected.onSuccess === 'function') {
680
895
  SallaApplePay.detail.shippingMethodSelected.onSuccess(data);
681
896
  }
682
897
 
683
898
  // we don't have any data in this request, lets resolve the promise
684
899
  return true;
685
- }).catch((error) => {
900
+ }, (error) => {
686
901
  salla.logger.warn('🍏 Pay: Set shipping method failed', error);
687
902
 
688
903
  if (typeof SallaApplePay.detail.shippingMethodSelected.onFailed === 'function') {
@@ -705,7 +920,7 @@ window.SallaApplePay = {
705
920
  'label': method.shipping_title,
706
921
  'amount': method.enable_free_shipping ? 0 : method.ship_cost,
707
922
  'detail': '',
708
- 'identifier': method.ship_id.toString() + (method.private_ship_id ? ',' + method.private_ship_id.toString() : '')
923
+ 'identifier': method.ship_id.toString() + (method.private_ship_id ? ',' + method.private_ship_id.toString() : '') + (method.type ? ',' + method.type : '') + (method.route_id ? ',' + method.route_id : '')
709
924
  }))
710
925
  };
711
926
 
@@ -746,7 +961,8 @@ const SallaQuickBuy = /*@__PURE__*/ proxyCustomElement(class SallaQuickBuy exten
746
961
  });
747
962
  }
748
963
  async quickBuyHandler() {
749
- if (salla.config.isGuest()) {
964
+ // user guest and guest-checkout not enabled
965
+ if (salla.config.isGuest() && !this.isGuestCheckout()) {
750
966
  this.requireLogin.emit({ productId: this.productId });
751
967
  // todo (low) :: find a way to re-fire the method after success
752
968
  let afterLoginEvent = "salla-quick-buy::user.logged-in";
@@ -784,7 +1000,7 @@ const SallaQuickBuy = /*@__PURE__*/ proxyCustomElement(class SallaQuickBuy exten
784
1000
  salla.event.dispatch('payments::apple-pay.start-transaction', {
785
1001
  amount: this.amount, // 1000
786
1002
  currency: this.currency || 'SAR', // SAR
787
- requiredShippingContactFields: this.isRequireShipping ? ['postalAddress'] : undefined,
1003
+ requiredShippingContactFields: this.getRequiredShippingContactFields(),
788
1004
  shippingMethods: this.isRequireShipping ? [] : undefined,
789
1005
  supportedNetworks: salla.config.get('store.settings.buy_now.networks'),
790
1006
  supportedCountries: salla.config.get('store.settings.buy_now.countries'),
@@ -835,7 +1051,10 @@ const SallaQuickBuy = /*@__PURE__*/ proxyCustomElement(class SallaQuickBuy exten
835
1051
  shippingContactSelected: this.isRequireShipping ? {
836
1052
  url: salla.url.get('checkout/{id}/address/add'),
837
1053
  } : undefined,
838
- oncouponcodechanged: {
1054
+ guestContactSelected: this.isGuestCheckout() ? {
1055
+ url: salla.url.get('checkout/{id}/customer'),
1056
+ } : undefined,
1057
+ onCouponCodeChanged: {
839
1058
  url: salla.url.get('checkout/{id}/coupons')
840
1059
  },
841
1060
  recalculateTotal: {
@@ -847,70 +1066,79 @@ const SallaQuickBuy = /*@__PURE__*/ proxyCustomElement(class SallaQuickBuy exten
847
1066
  }
848
1067
  });
849
1068
  }
1069
+ isGuestCheckout() {
1070
+ return salla.config.isGuest() && salla.config.get('store.features').includes('guest-checkout');
1071
+ }
1072
+ getRequiredShippingContactFields() {
1073
+ let fields = [];
1074
+ if (this.isRequireShipping) {
1075
+ fields.push('postalAddress');
1076
+ }
1077
+ if (this.isGuestCheckout()) {
1078
+ fields.push('email', 'phone', 'name');
1079
+ }
1080
+ return fields;
1081
+ }
850
1082
  componentWillLoad() {
851
1083
  console.log('🍏 Pay: Quick Buy Component Loaded');
852
- return new Promise((resolve, reject) => {
853
- salla.onReady(async () => {
854
- if (!this.currency) {
855
- this.currency = salla.config.get('store.settings.buy_now.multi_currency') ? salla.config.get('user.currency_code') : 'SAR';
856
- }
857
- if (!this.productId && salla.config.get('page.id')) {
858
- this.productId = salla.config.get('page.id');
859
- }
860
- if (!this.applePayOnly && !this.productId) {
861
- salla.logger.warn('🍏 Pay: Failed load the quick buy, the product id is missing');
862
- return reject();
863
- }
864
- /**
865
- * We should check the product if it's required shipping
866
- * in order for apple pay sdk to show the required Shipping Contact Fields
867
- * components..
868
- */
869
- if ((!this.amount || !this.isRequireShipping) && this.productId) {
870
- await salla.product.getDetails(this.productId, []).then((response) => {
871
- this.amount = response.data.price;
872
- this.isRequireShipping = response?.data?.is_require_shipping || false;
873
- }).catch((error) => {
874
- salla.logger.warn('🍏 Pay: Failed load the quick buy, get the product details failed: ', error);
875
- return reject();
876
- });
877
- }
878
- if (this.type == 'donate') {
879
- salla.event.on('product-options::donation-changed', (data) => {
880
- if (String(data.id) !== String(this.productId)) {
881
- return;
882
- }
883
- this.amount = data.price;
884
- });
885
- }
886
- else if (salla.url.is_page('product.single')) {
887
- salla.product.event?.onPriceUpdated(response => {
888
- this.amount = response.data.price;
889
- });
890
- }
891
- this.isApplePayActive = salla.helpers.hasApplePay()
892
- && salla.config.get('store.settings.payments')?.includes('apple_pay')
893
- && salla.config.get('store.settings.is_salla_gateway', false);
894
- let applePaySdk = document.getElementById('apple-pay-sdk');
895
- if (applePaySdk || !this.isApplePayActive) {
896
- salla.logger.warn('🍏 Pay: Skipped load apple pay because ' + (applePaySdk ? 'already loaded' : 'is not available in the browser'));
897
- resolve(true);
898
- return;
899
- }
1084
+ const canMakePayments = typeof window !== 'undefined' && !!window.ApplePaySession?.canMakePayments?.();
1085
+ const storeHasApplePay = salla?.config?.get?.('store.settings.payments')?.includes?.('apple_pay') ?? true;
1086
+ const isSallaGateway = salla?.config?.get?.('store.settings.is_salla_gateway', false) ?? true;
1087
+ this.isApplePayActive = canMakePayments && storeHasApplePay && isSallaGateway;
1088
+ const runInit = async () => {
1089
+ if (!this.currency && salla?.config?.get) {
1090
+ this.currency = salla.config.get('store.settings.buy_now.multi_currency') ? salla.config.get('user.currency_code') : 'SAR';
1091
+ }
1092
+ if (!this.productId && salla?.config?.get && salla.url?.is_page) {
1093
+ this.productId = salla.config.get('page.id');
1094
+ }
1095
+ if (!this.applePayOnly && !this.productId) {
1096
+ salla?.logger?.warn?.('🍏 Pay: Failed load the quick buy, the product id is missing');
1097
+ return;
1098
+ }
1099
+ if ((!this.amount || !this.isRequireShipping) && this.productId && salla?.product?.getDetails) {
1100
+ await salla.product.getDetails(this.productId, []).then((response) => {
1101
+ this.amount = response.data.price;
1102
+ this.isRequireShipping = response?.data?.is_require_shipping || false;
1103
+ }).catch((error) => {
1104
+ salla?.logger?.warn?.('🍏 Pay: Failed load the quick buy, get the product details failed: ', error);
1105
+ });
1106
+ }
1107
+ if (this.type === 'donate' && salla?.event?.on) {
1108
+ salla.event.on('product-options::donation-changed', (data) => {
1109
+ if (String(data.id) !== String(this.productId))
1110
+ return;
1111
+ this.amount = data.price;
1112
+ });
1113
+ }
1114
+ else if (salla?.url?.is_page?.('product.single') && salla?.product?.event?.onPriceUpdated) {
1115
+ salla.product.event.onPriceUpdated(response => { this.amount = response.data.price; });
1116
+ }
1117
+ this.isApplePayActive = (salla?.helpers?.hasApplePay?.() ?? canMakePayments)
1118
+ && (salla?.config?.get?.('store.settings.payments')?.includes?.('apple_pay') ?? storeHasApplePay)
1119
+ && (salla?.config?.get?.('store.settings.is_salla_gateway', false) ?? isSallaGateway);
1120
+ if (!document.getElementById('apple-pay-sdk') && this.isApplePayActive) {
900
1121
  const script = document.createElement('script');
901
1122
  script.src = 'https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js';
902
1123
  script.setAttribute('id', 'apple-pay-sdk');
903
1124
  script.async = true;
904
1125
  document.body.appendChild(script);
905
- resolve(true);
906
- });
1126
+ }
1127
+ };
1128
+ return new Promise((resolve) => {
1129
+ if (typeof salla?.onReady === 'function') {
1130
+ salla.onReady(() => runInit().then(() => resolve(true)));
1131
+ }
1132
+ else {
1133
+ runInit().then(() => resolve(true));
1134
+ }
907
1135
  });
908
1136
  }
909
1137
  render() {
910
- return h(Host, { key: '326f9d1a5336de18e77a71cef8d4e0118acb8055' }, this.quickBuyButton());
1138
+ return h(Host, { key: '9a36fa6b7163dae6feed474712e3d0c3003d012c' }, this.quickBuyButton());
911
1139
  }
912
1140
  quickBuyButton() {
913
- return h("apple-pay-button", { locale: salla.config.get('user.language_code'), onClick: () => this.quickBuyHandler(), "data-quick-purchase": "applepay", class: "s-quick-buy-apple-pay", "data-is-applepay": "1", buttonstyle: "black", type: this.type });
1141
+ return h("apple-pay-button", { locale: salla?.config?.get?.('user.language_code') || 'ar', onClick: () => this.quickBuyHandler(), "data-quick-purchase": "applepay", class: "s-quick-buy-apple-pay", "data-is-applepay": "1", buttonstyle: "black", type: this.type });
914
1142
  }
915
1143
  get host() { return this; }
916
1144
  static get style() { return sallaQuickBuyCss; }