@salla.sa/applepay 2.13.37 → 2.13.38
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 +2 -2
- package/src/index.js +31 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salla.sa/applepay",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.38",
|
|
4
4
|
"description": "Salla Apple Pay light",
|
|
5
5
|
"main": "dist/app.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"axios": "^0.23.0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "c1a307509629e442ade1cae566690f3773bdf012"
|
|
30
30
|
}
|
package/src/index.js
CHANGED
|
@@ -231,35 +231,45 @@ window.SallaApplePay = {
|
|
|
231
231
|
*
|
|
232
232
|
* @param event
|
|
233
233
|
*/
|
|
234
|
-
onValidateMerchant: (event) => {
|
|
235
|
-
|
|
234
|
+
onValidateMerchant: async (event) => {
|
|
235
|
+
try {
|
|
236
|
+
// Dispatch event to initialize Apple Pay merchant validation
|
|
237
|
+
Salla.event.dispatch('payments::apple-pay.validate-merchant.init', event);
|
|
236
238
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
// Post request to validate merchant
|
|
240
|
+
const { data } = await Http.post(SallaApplePay.detail.validateMerchant.url.replace('{id}', SallaApplePay.id), {
|
|
241
|
+
validation_url: event.validationURL
|
|
242
|
+
});
|
|
240
243
|
|
|
244
|
+
// Dispatch event on successful merchant validation
|
|
241
245
|
Salla.event.dispatch('payments::apple-pay.validate-merchant.success', data);
|
|
242
246
|
|
|
247
|
+
// Define a function to handle the completion of merchant validation
|
|
248
|
+
const completeMerchantValidation = async (responseData) => {
|
|
249
|
+
try {
|
|
250
|
+
await SallaApplePay.recalculateTotal();
|
|
251
|
+
} catch (error) {
|
|
252
|
+
salla.logger.warn('🍏 Pay: Failed recalculate total', error);
|
|
253
|
+
}
|
|
254
|
+
SallaApplePay.session.completeMerchantValidation(responseData);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// Check if onSuccess function is defined in SallaApplePay.detail.validateMerchant
|
|
243
258
|
if (typeof SallaApplePay.detail.validateMerchant.onSuccess === 'function') {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
SallaApplePay.session.completeMerchantValidation(data.data);
|
|
252
|
-
}).catch((response) => {
|
|
253
|
-
SallaApplePay.abortValidateMerchant(response);
|
|
254
|
-
});
|
|
255
|
-
} else {
|
|
256
|
-
SallaApplePay.session.completeMerchantValidation(data.data);
|
|
259
|
+
// Call onSuccess function and handle response
|
|
260
|
+
const response = await SallaApplePay.detail.validateMerchant.onSuccess(data);
|
|
261
|
+
if (response?.redirect) {
|
|
262
|
+
// Handle redirect if present
|
|
263
|
+
window.location = response.redirect;
|
|
264
|
+
return SallaApplePay.abortValidateMerchant(response);
|
|
265
|
+
}
|
|
257
266
|
}
|
|
258
|
-
|
|
259
|
-
}
|
|
267
|
+
completeMerchantValidation(data.data);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
// Handle errors
|
|
260
270
|
console.error(error);
|
|
261
271
|
SallaApplePay.abortValidateMerchant(error?.response);
|
|
262
|
-
}
|
|
272
|
+
}
|
|
263
273
|
},
|
|
264
274
|
|
|
265
275
|
abortValidateMerchant: (response = null) => {
|