@salla.sa/applepay 3.0.5 → 3.0.6

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@salla.sa/applepay",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
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": "^1.10.0"
28
28
  },
29
- "gitHead": "6edf6a7a8f7da54e89f29fa340360cab603b0892"
29
+ "gitHead": "51f8a1a586198fe89f64056ee346b99df1ee1c02"
30
30
  }
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import http from './http';
2
2
  import DetectOS from './DetectOS';
3
- import { mutateShippingContact } from './utils';
3
+ import { mutateShippingContact, resolveErrorMessage } from './utils';
4
4
  import { resolveApplePayNetworks } from './apple-pay-support';
5
5
 
6
6
  // SSR-safe: only access window in browser environment
@@ -94,7 +94,7 @@ const SallaApplePay = typeof window !== 'undefined' ? {
94
94
  SallaApplePay.detail.validateMerchant.onFailed = (response) => {
95
95
  salla.logger.log(JSON.stringify(response))
96
96
  salla.api.handleErrorResponse({response});
97
- SallaApplePay.onCancel({}, response.data.error.message);
97
+ SallaApplePay.onCancel({}, resolveErrorMessage(response));
98
98
  };
99
99
  }
100
100
 
package/src/utils.js CHANGED
@@ -229,3 +229,10 @@ function getApplePayErrors(fields) {
229
229
  .filter(([field, messages]) => messages && messages.length > 0)
230
230
  .map(([field, messages]) => new window.ApplePayError('shippingContactInvalid', field, messages[0]));
231
231
  }
232
+
233
+ /** First validation message from a 422, falling back to the generic error message. */
234
+ export function resolveErrorMessage(response) {
235
+ const fields = response?.data?.error?.fields;
236
+ const fieldMessage = fields && Object.values(fields).flat().find(Boolean);
237
+ return fieldMessage || response?.data?.error?.message;
238
+ }