@salla.sa/applepay 1.0.30 → 2.11.70

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.
package/package.json CHANGED
@@ -1,37 +1,30 @@
1
1
  {
2
2
  "name": "@salla.sa/applepay",
3
- "version": "1.0.30",
4
- "description": "Salla Apple Pay",
3
+ "version": "2.11.70",
4
+ "description": "Salla Apple Pay light",
5
5
  "main": "dist/app.js",
6
6
  "scripts": {
7
- "dev": "npm run development",
8
- "development": "",
9
- "watch": "",
10
- "watch-poll": "npm run watch -- --watch-poll",
11
- "hot": "",
12
- "prod": "npm run production",
13
- "production": "",
14
- "lint": "eslint ./src --fix",
7
+ "watch": "echo \"There is no watch!\"",
8
+ "build": "echo \"There is no build!\"",
15
9
  "test": "echo \"Error: no test specified\" && exit 1"
16
10
  },
17
11
  "repository": {
18
12
  "type": "git",
19
- "url": "git+https://github.com/SallaApp/applePay-js.git"
13
+ "url": "git+https://github.com/SallaApp/twilight.git"
20
14
  },
21
15
  "keywords": [
22
16
  "salla",
23
- "ui"
17
+ "ui",
18
+ "apple-pay"
24
19
  ],
25
- "publishConfig": {
26
- "registry": "https://npm.pkg.github.com/"
27
- },
28
20
  "author": "rasha@salla.sa",
29
21
  "bugs": {
30
- "url": "https://github.com/SallaApp/applePay-js/issues"
22
+ "url": "https://github.com/SallaApp/twilight/issues"
31
23
  },
32
24
  "license": "UNLICENSED",
33
- "homepage": "https://github.com/SallaApp/applePay-js#readme",
25
+ "homepage": "https://github.com/SallaApp/twilight#readme",
34
26
  "dependencies": {
35
27
  "axios": "^0.23.0"
36
- }
28
+ },
29
+ "gitHead": "e7c9c08172f3075e72b5b3de384b95821d0a6093"
37
30
  }
package/src/http.js CHANGED
@@ -3,7 +3,7 @@ import axios from 'axios'
3
3
  export default {
4
4
  request(method, url, data, successCb = null, errorCb = null) {
5
5
  return axios
6
- .request({ url, data, method: method.toLowerCase(), responseType: 'json'})
6
+ .request({url, data, method: method.toLowerCase(), responseType: 'json'})
7
7
  .then(successCb)
8
8
  .catch(errorCb);
9
9
  },
@@ -11,12 +11,12 @@ export default {
11
11
  get(url, successCb = null, errorCb = null, data) {
12
12
  // return this.request('get', url, data, successCb, errorCb);
13
13
  return axios
14
- .get(url, { params: data })
14
+ .get(url, {params: data})
15
15
  .then(successCb)
16
16
  .catch(errorCb);
17
17
  },
18
18
 
19
- post(url, data, successCb = null, errorCb = null ) {
19
+ post(url, data, successCb = null, errorCb = null) {
20
20
  return this.request('post', url, data, successCb, errorCb);
21
21
  },
22
22
 
@@ -26,5 +26,33 @@ export default {
26
26
 
27
27
  delete(url, data, successCb = null, errorCb = null) {
28
28
  return this.request('delete', url, data, successCb, errorCb);
29
+ },
30
+
31
+ requestWithSupportAjax(url, payload, method = 'post') {
32
+ return new Promise((resolve, reject) => {
33
+ if (!window?.isLegacyTheme) {
34
+ return this.request(method, url, payload, ({data}) => {
35
+ return resolve(data);
36
+ }, ({response}) => {
37
+ return reject(response);
38
+ })
39
+ }
40
+
41
+ /**
42
+ * @deprecated to support legacy themes
43
+ */
44
+ $.ajax({
45
+ url: url,
46
+ method: method.toUpperCase(),
47
+ data: payload,
48
+ async: false,
49
+ success: function ({data}) {
50
+ return resolve(data);
51
+ },
52
+ error: function ({response}) {
53
+ return reject(response);
54
+ }
55
+ });
56
+ })
29
57
  }
30
58
  };
package/src/index.js CHANGED
@@ -1 +1,518 @@
1
- require('./ApplePay');
1
+ import Http from './http';
2
+ import DetectOS from './DetectOS';
3
+
4
+ window.Salla = window.Salla || {};
5
+ window.Salla.Payments = window.Salla.Payments || {};
6
+
7
+ /**
8
+ * Full Example
9
+ *
10
+ * Salla.event.createAndDispatch('payments::apple-pay.start-transaction', {
11
+ * amount: 1000,
12
+ * validateMerchant: {
13
+ * url: '{{ route('cp.marketplace.cart.pay', ['cart' => $cart]) }}',
14
+ * // onFailed: (response) => {
15
+ * // laravel.ajax.errorHandler(response);
16
+ * // this.onCancel({}, response.data.error.message);
17
+ * // },
18
+ * // onSuccess: (response) => {
19
+ * // laravel.ajax.successHandler(response);
20
+ * // }
21
+ * },
22
+ * authorized: {
23
+ * url: '{{ route('cp.marketplace.cart.confirm', ['cart' => $cart]) }}',
24
+ * // onFailed: (response) => {
25
+ * // laravel.ajax.errorHandler(response);
26
+ * // this.onCancel({}, response.data.error.message);
27
+ * // },
28
+ * // onSuccess: (response) => {
29
+ * // // nothing
30
+ * // }
31
+ * },
32
+ * // onError: function (message) {
33
+ * // laravel.alert(message);
34
+ * // }
35
+ * });
36
+ */
37
+ window.SallaApplePay = {
38
+ session: null,
39
+ detail: null,
40
+ address_id: null,
41
+ shipping_methods: [],
42
+ total: undefined,
43
+ request: undefined,
44
+ id: undefined,
45
+ init: function () {
46
+ document.removeEventListener('payments::apple-pay.start-transaction', SallaApplePay.startSession);
47
+ Salla.event.addEventListener('payments::apple-pay.start-transaction', SallaApplePay.startSession);
48
+ },
49
+
50
+ initDefault: function () {
51
+ if (!SallaApplePay.detail.onError) {
52
+ SallaApplePay.detail.onError = function (message) {
53
+ salla.notify.error(message);
54
+ };
55
+ }
56
+
57
+ if (!SallaApplePay.detail.authorized.onFailed) {
58
+ SallaApplePay.detail.authorized.onFailed = (response) => {
59
+ salla.logger.log(JSON.stringify(response))
60
+ salla.api.handleErrorResponse(response);
61
+ SallaApplePay.onCancel({}, response.data.error.message);
62
+ };
63
+ }
64
+
65
+ if (!SallaApplePay.detail.validateMerchant.onFailed) {
66
+ SallaApplePay.detail.validateMerchant.onFailed = (response) => {
67
+ salla.logger.log(JSON.stringify(response))
68
+ salla.api.handleErrorResponse(response);
69
+ SallaApplePay.onCancel({}, response.data.error.message);
70
+ };
71
+ }
72
+
73
+ if (!SallaApplePay.detail.authorized.onSuccess) {
74
+ SallaApplePay.detail.authorized.onSuccess = (response) => {
75
+ salla.logger.log(JSON.stringify(response))
76
+ salla.api.handleAfterResponseActions(response);
77
+ };
78
+ }
79
+ },
80
+
81
+ prepareLineItems: function () {
82
+ if(!SallaApplePay.detail?.items?.length){
83
+ SallaApplePay.detail.items = [
84
+ {
85
+ label: salla.lang.get('pages.cart.items_total'),
86
+ amount: SallaApplePay.detail.amount
87
+ }
88
+ ]
89
+ }
90
+
91
+ return SallaApplePay.detail.items;
92
+ },
93
+
94
+ prepareTotal: function () {
95
+ return {
96
+ // apple ask to use business name
97
+ label: window.location.hostname || 'Salla',
98
+ //label: salla.lang.get('pages.cart.final_total'),
99
+ amount: SallaApplePay.detail.amount
100
+ }
101
+ },
102
+
103
+ startSession: async function (event) {
104
+
105
+ SallaApplePay.detail = event.detail || event;
106
+
107
+ salla.log('🍏 Pay: payments::apple-pay.start-transaction', SallaApplePay.detail);
108
+
109
+ SallaApplePay.initDefault();
110
+
111
+ let version = SallaApplePay.getApplePaySessionVersion();
112
+ let supportedNetworks = SallaApplePay.detail.supportedNetworks || ['masterCard', 'visa'];
113
+
114
+ if (version === 5) {
115
+ supportedNetworks.push('mada');
116
+ }
117
+
118
+ SallaApplePay.request = {
119
+ countryCode: 'SA',
120
+ supportsCouponCode: true,
121
+ couponCode: '',
122
+ currencyCode: SallaApplePay.detail.currency || 'SAR',
123
+ requiredShippingContactFields: SallaApplePay.detail.requiredShippingContactFields ? SallaApplePay.detail.requiredShippingContactFields : [],
124
+ merchantCapabilities: ['supports3DS'],
125
+ supportedNetworks: supportedNetworks,
126
+ supportedCountries: SallaApplePay.detail.supportedCountries || ['SA'],
127
+ total: SallaApplePay.prepareTotal(),
128
+ shippingContact: SallaApplePay.detail.shippingContact ? SallaApplePay.detail.shippingContact : {},
129
+ shippingMethods: SallaApplePay.detail.shippingMethods && SallaApplePay.detail.shippingMethods.length ? SallaApplePay.mappingShippingMethods(event.detail.shippingMethods) : [],
130
+ lineItems: SallaApplePay.prepareLineItems()
131
+ };
132
+
133
+ salla.log('🍏 Pay: init ', SallaApplePay.request);
134
+
135
+ // https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentrequest
136
+ SallaApplePay.session = new ApplePaySession(version, SallaApplePay.request);
137
+
138
+ SallaApplePay.session.onshippingcontactselected = SallaApplePay.onShippingContactSelected;
139
+ SallaApplePay.session.onshippingmethodselected = SallaApplePay.onShippingMethodSelected;
140
+ SallaApplePay.session.onvalidatemerchant = SallaApplePay.onValidateMerchant;
141
+ SallaApplePay.session.onpaymentauthorized = SallaApplePay.onPaymentAuthorized;
142
+ SallaApplePay.session.oncancel = SallaApplePay.onCancel;
143
+ SallaApplePay.session.oncouponcodechanged = SallaApplePay.oncouponcodechanged;
144
+
145
+ SallaApplePay.session.begin();
146
+ },
147
+
148
+ oncouponcodechanged(event) {
149
+ Salla.event.dispatch('payments::apple-pay.coupon.change', event);
150
+
151
+ return Http.post(SallaApplePay.detail.oncouponcodechanged.url.replace('{id}', SallaApplePay.id), {
152
+ 'coupon': event.couponCode,
153
+ 'payment_method': 'apple_pay',
154
+ }, async ({data}) => {
155
+ if (typeof SallaApplePay.detail.oncouponcodechanged.onSuccess === 'function') {
156
+ SallaApplePay.detail.oncouponcodechanged.onSuccess(data);
157
+ }
158
+
159
+ salla.log('🍏 Pay: Coupon applied success');
160
+
161
+ await SallaApplePay.recalculateTotal();
162
+
163
+ SallaApplePay.session.completeCouponCodeChange({
164
+ newTotal: SallaApplePay.prepareTotal(),
165
+ newLineItems: SallaApplePay.prepareLineItems()
166
+ });
167
+ }, async (error) => {
168
+ let response = error?.response;
169
+
170
+ Salla.event.dispatch('payments::apple-pay.coupon.failed', response);
171
+
172
+ // SallaApplePay.abortSession();
173
+ if (typeof SallaApplePay.detail.oncouponcodechanged.onFailed === 'function') {
174
+ SallaApplePay.detail.oncouponcodechanged.onFailed(response);
175
+ }
176
+
177
+ await SallaApplePay.recalculateTotal();
178
+
179
+ SallaApplePay.session.completeCouponCodeChange({
180
+ newTotal: SallaApplePay.prepareTotal(),
181
+ newLineItems: SallaApplePay.prepareLineItems(),
182
+ errors: [new window.ApplePayError('couponCodeInvalid')]
183
+ });
184
+ });
185
+ },
186
+
187
+ onCancel: (event = {}, message = null) => {
188
+ SallaApplePay.detail.onError(message || salla.lang.get('pages.checkout.payment_failed'));
189
+ Salla.event.createAndDispatch('payments::apple-pay.canceled', event);
190
+ },
191
+
192
+ /**
193
+ * Confirm payment after authorization.
194
+ *
195
+ * @param event
196
+ */
197
+ onPaymentAuthorized: (event) => {
198
+ salla.logger.log('🍏 Pay: onPaymentAuthorized', event.payment);
199
+
200
+ Salla.event.dispatch('payments::apple-pay.authorized.init', event);
201
+ Http.post(SallaApplePay.detail.authorized.url.replace('{id}', SallaApplePay.id), {
202
+ payment_method: 'apple_pay',
203
+ applepay_token: JSON.stringify(event.payment)
204
+ }, ({data}) => {
205
+ Salla.event.dispatch('payments::apple-pay.authorized.success', data);
206
+
207
+ SallaApplePay.session.completePayment(ApplePaySession.STATUS_SUCCESS);
208
+
209
+ if (typeof SallaApplePay.detail.authorized.onSuccess === 'function') {
210
+ SallaApplePay.detail.authorized.onSuccess(data);
211
+ }
212
+ }, (error) => {
213
+
214
+ let response = error?.response;
215
+
216
+ Salla.event.dispatch('payments::apple-pay.authorized.failed', response);
217
+
218
+ SallaApplePay.session.completePayment({
219
+ status: ApplePaySession.STATUS_FAILURE,
220
+ errors: [new ApplePayError("unknown", undefined, response?.data?.error?.message || response?.data?.error?.code || 'Failed to parse authorized response')]
221
+ })
222
+
223
+ if (typeof SallaApplePay.detail.authorized.onFailed === 'function') {
224
+ SallaApplePay.detail.authorized.onFailed(response);
225
+ }
226
+ });
227
+ },
228
+
229
+ /**
230
+ * Validate Submit.
231
+ *
232
+ * @param event
233
+ */
234
+ onValidateMerchant: (event) => {
235
+ Salla.event.dispatch('payments::apple-pay.validate-merchant.init', event);
236
+
237
+ Http.post(SallaApplePay.detail.validateMerchant.url.replace('{id}', SallaApplePay.id), {
238
+ validation_url: event.validationURL
239
+ }, ({data}) => {
240
+
241
+ Salla.event.dispatch('payments::apple-pay.validate-merchant.success', data);
242
+
243
+ if (typeof SallaApplePay.detail.validateMerchant.onSuccess === 'function') {
244
+ SallaApplePay.detail.validateMerchant.onSuccess(data).then((response) => {
245
+ // check if there are redirect
246
+ if (response?.redirect) {
247
+ window.location = response.redirect;
248
+ return SallaApplePay.abortValidateMerchant(response);
249
+ }
250
+
251
+ SallaApplePay.session.completeMerchantValidation(data.data);
252
+ }).catch((response) => {
253
+ SallaApplePay.abortValidateMerchant(response);
254
+ });
255
+ } else {
256
+ SallaApplePay.session.completeMerchantValidation(data.data);
257
+ }
258
+
259
+ }, ({response}) => {
260
+ SallaApplePay.abortValidateMerchant(response);
261
+ });
262
+ },
263
+
264
+ abortValidateMerchant: (response = null) => {
265
+
266
+ SallaApplePay.abortSession();
267
+ Salla.event.dispatch('payments::apple-pay.validate-merchant.failed', response);
268
+
269
+ if (typeof SallaApplePay.detail.validateMerchant.onFailed === 'function') {
270
+ SallaApplePay.detail.validateMerchant.onFailed(response);
271
+ }
272
+ },
273
+
274
+ /**
275
+ * Select Shipping Contact
276
+ *
277
+ * @param event
278
+ */
279
+ onShippingContactSelected: async (event) => {
280
+ salla.logger.log('🍏 Pay: onShippingContactSelected', event.shippingContact);
281
+
282
+ if (!SallaApplePay.detail.requiredShippingContactFields) {
283
+ return;
284
+ }
285
+
286
+ // Create New Address
287
+ return Http.post(SallaApplePay.detail.shippingContactSelected.url.replace('{id}', SallaApplePay.id),
288
+ {
289
+ 'country': event.shippingContact.country,
290
+ 'city': event.shippingContact.locality,
291
+ 'local': event.shippingContact.subLocality,
292
+ 'description': event.shippingContact.subAdministrativeArea,
293
+ 'street': event.shippingContact.administrativeArea,
294
+ 'country_code': event.shippingContact.countryCode,
295
+ 'postal_code': event.shippingContact.postalCode
296
+ },
297
+ async ({data}) => {
298
+ if (typeof SallaApplePay.detail.shippingContactSelected.onSuccess === 'function') {
299
+ SallaApplePay.detail.shippingContactSelected.onSuccess(data);
300
+ }
301
+
302
+ SallaApplePay.address_id = data.data.address_id;
303
+ SallaApplePay.shipping_methods = data.data.shipping_methods;
304
+
305
+ if (!SallaApplePay.shipping_methods || (SallaApplePay.shipping_methods && !SallaApplePay.shipping_methods.length)) {
306
+ salla.logger.warn('🍏 Pay: We dont found any supported methods', data);
307
+
308
+ return SallaApplePay.session.completeShippingContactSelection({
309
+ status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
310
+ errors: [
311
+ new window.ApplePayError('addressUnserviceable')
312
+ ]
313
+ });
314
+ }
315
+
316
+ try {
317
+ await SallaApplePay.selectApplePayShippingMethod(SallaApplePay.shipping_methods[0]['ship_id'], SallaApplePay.shipping_methods[0]['private_ship_id']);
318
+ } catch (error) {
319
+ salla.logger.warn('Failed set the shipping details to api', error);
320
+
321
+ return SallaApplePay.session.completeShippingContactSelection({
322
+ status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
323
+ errors: [
324
+ new window.ApplePayError('addressUnserviceable')
325
+ ]
326
+ });
327
+ }
328
+
329
+ try {
330
+ await SallaApplePay.recalculateTotal();
331
+ } catch (error) {
332
+ salla.logger.warn('🍏 Pay: Failed recalculate total', error);
333
+
334
+ return SallaApplePay.session.completeShippingContactSelection({
335
+ status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
336
+ errors: [
337
+ new window.ApplePayError('addressUnserviceable')
338
+ ]
339
+ });
340
+ }
341
+
342
+ SallaApplePay.session.completeShippingContactSelection({
343
+ newTotal: SallaApplePay.prepareTotal(),
344
+ newLineItems: SallaApplePay.prepareLineItems(),
345
+ newShippingMethods: SallaApplePay.mappingShippingMethods(SallaApplePay.shipping_methods)
346
+ });
347
+
348
+ }, ({response}) => {
349
+ salla.logger.warn('🍏 Pay: Failed add address via api', response);
350
+
351
+ if (typeof SallaApplePay.detail.shippingContactSelected.onFailed === 'function') {
352
+ SallaApplePay.detail.shippingContactSelected.onFailed(response);
353
+ }
354
+
355
+ // parse 422 errors
356
+ let fields = response?.data?.error?.fields;
357
+
358
+ let errors = [];
359
+
360
+ if (fields?.country_code) {
361
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'countryCode', fields?.country_code[0]))
362
+ }
363
+
364
+ if (fields?.city) {
365
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'locality', fields?.city[0]))
366
+ }
367
+
368
+ if (fields?.country) {
369
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'country', fields?.country[0]))
370
+ }
371
+
372
+ if (errors.length === 0 && response?.data?.error?.message) {
373
+ errors.push(new window.ApplePayError('shippingContactInvalid', 'locality', response?.data?.error?.message))
374
+ }
375
+
376
+ SallaApplePay.session.completeShippingContactSelection({
377
+ newTotal: SallaApplePay.prepareTotal(),
378
+ newLineItems: SallaApplePay.prepareLineItems(),
379
+ status: SallaApplePay.session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,
380
+ errors: errors
381
+ });
382
+ });
383
+ },
384
+
385
+ /**
386
+ * Select Shipping Method
387
+ *
388
+ * @param event
389
+ *
390
+ */
391
+ onShippingMethodSelected: async (event) => {
392
+ salla.logger.log(event);
393
+
394
+ let shipping_ids = event.shippingMethod.identifier.split(',');
395
+
396
+ try {
397
+ await SallaApplePay.selectApplePayShippingMethod(shipping_ids[0], typeof shipping_ids[1] === 'undefined' ? null : shipping_ids[1]);
398
+
399
+ await SallaApplePay.recalculateTotal();
400
+
401
+ SallaApplePay.session.completeShippingMethodSelection({
402
+ newTotal: SallaApplePay.prepareTotal(),
403
+ newLineItems: SallaApplePay.prepareLineItems(),
404
+ });
405
+ } catch (error) {
406
+ salla.logger.warn('🍏 Pay: Failed set the shipping details to api', error);
407
+
408
+ // todo :: find a better handling for error without abort session
409
+ SallaApplePay.abortSession();
410
+ }
411
+ },
412
+
413
+
414
+ abortSession: () => {
415
+ if (SallaApplePay.session) {
416
+ SallaApplePay.session.abort();
417
+ }
418
+ },
419
+
420
+ getApplePaySessionVersion: () => {
421
+ const userAgent = navigator.userAgent || navigator.vendor || window.opera;
422
+
423
+ if (userAgent === 'sallapp') {
424
+ return 5;
425
+ }
426
+
427
+ // can't handle custom user agent like sallapp
428
+ let detection = DetectOS.init();
429
+ let v = parseFloat(detection.os.version);
430
+
431
+ if (detection.os.name === 'Macintosh') {
432
+ if (v < 10.142) {
433
+ return 1;
434
+ }
435
+ } else {
436
+ if (v < 12.11) {
437
+ return 1;
438
+ }
439
+ }
440
+
441
+ return 5;
442
+ },
443
+
444
+ recalculateTotal: () => {
445
+ salla.logger.log('Recalculate Total');
446
+
447
+ return Http.requestWithSupportAjax(SallaApplePay.detail.recalculateTotal.url.replace('{id}', SallaApplePay.id),{}, 'get').then((data) => {
448
+ console.log(data);
449
+ // todo :: enhance response from backend
450
+ SallaApplePay.detail.amount = data.data.initial_data.cart.total;
451
+ SallaApplePay.detail.items = data.data.initial_data.cart.items.map((item) => {
452
+ return {
453
+ label: item.title,
454
+ amount: item.amount === 'مجاني' ? 0 : item.amount.toString().replace('+', ''),
455
+ };
456
+ })
457
+
458
+ // lets remove last element (final total)
459
+ SallaApplePay.detail.items.pop();
460
+
461
+ return data;
462
+ }).catch((error) => {
463
+ salla.logger.warn('🍏 Pay: recalculate total failed', error);
464
+
465
+ // general error
466
+ return error?.response?.data?.message;
467
+ });
468
+ },
469
+
470
+
471
+ selectApplePayShippingMethod: (company_id, private_company_id) => {
472
+ salla.logger.log('🍏 Pay: select shipping method ', 'company_id : ' + company_id, 'private_company_id: ' + private_company_id);
473
+
474
+ return Http.requestWithSupportAjax(SallaApplePay.detail.shippingMethodSelected.url.replace('{id}', SallaApplePay.id), {
475
+ address_id: SallaApplePay.address_id,
476
+ company_id: company_id,
477
+ private_company_id: private_company_id,
478
+ payment_method: 'apple_pay'
479
+ }, 'post').then(() => {
480
+ if (typeof SallaApplePay.detail. shippingMethodSelected.onSuccess === 'function') {
481
+ SallaApplePay.detail.shippingMethodSelected.onSuccess(data);
482
+ }
483
+
484
+ // we don't have any data in this request, lets resolve the promise
485
+ return true;
486
+ }).catch((error) => {
487
+ salla.logger.warn('🍏 Pay: Set shipping method failed', error);
488
+
489
+ if (typeof SallaApplePay.detail.shippingMethodSelected.onFailed === 'function') {
490
+ SallaApplePay.detail.shippingMethodSelected.onFailed(error);
491
+ }
492
+
493
+ // parse 422 errors
494
+ let response = error?.response?.data?.error;
495
+
496
+ // address id is not valid
497
+ if (response?.data?.fields?.address_id) {
498
+ return response?.data?.fields?.address_id[0];
499
+ }
500
+
501
+ // general error
502
+ return response?.data?.message;
503
+ });
504
+ },
505
+ mappingShippingMethods: methods => methods.map(method => ({
506
+ 'label': method.shipping_title,
507
+ 'amount': method.enable_free_shipping ? 0 : method.ship_cost,
508
+ 'detail': '',
509
+ 'identifier': method.ship_id.toString() + (method.private_ship_id ? ',' + method.private_ship_id.toString() : '')
510
+ }))
511
+ }
512
+
513
+ if (window.ApplePaySession && ApplePaySession.canMakePayments()) {
514
+ SallaApplePay.init();
515
+ } else {
516
+ // You can hide the Apple Pay button easy with add data-show-if-apple-pay-supported to element like <div data-show-if-apple-pay-supported>
517
+ document.querySelectorAll('data-show-if-apple-pay-supported').forEach(element => element.style.display = 'none');
518
+ }
@@ -1,15 +0,0 @@
1
- # To get started with Dependabot version updates, you'll need to specify which
2
- # package ecosystems to update and where the package manifests are located.
3
- # Please see the documentation for all configuration options:
4
- # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
-
6
- version: 2
7
- updates:
8
- - package-ecosystem: "composer" # See documentation for possible values
9
- directory: "/" # Location of package manifests
10
- schedule:
11
- interval: "daily"
12
- - package-ecosystem: "npm" # See documentation for possible values
13
- directory: "/" # Location of package manifests
14
- schedule:
15
- interval: "daily"
@@ -1,28 +0,0 @@
1
- name: Publish NPM Package
2
- on:
3
- push:
4
- branches:
5
- - master
6
- jobs:
7
- build:
8
- runs-on: ubuntu-latest
9
- steps:
10
- - uses: actions/checkout@v2
11
- - name: Access package.json
12
- run: cat ./package.json
13
- - name: Automated Version Bump
14
- uses: phips28/gh-action-bump-version@master
15
- with:
16
- tag-prefix: ''
17
- env:
18
- GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
19
- - name: Publish New Version
20
- uses: actions/setup-node@master
21
- with:
22
- node-version: 12
23
- registry-url: https://registry.npmjs.org/
24
- scope: 'salla.sa'
25
- - name: Publish to NPM Package Registry
26
- run: npm publish --access private
27
- env:
28
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}