@salla.sa/applepay 2.14.501 → 2.14.502

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +19 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salla.sa/applepay",
3
- "version": "2.14.501",
3
+ "version": "2.14.502",
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": "ef456773d218616e9f3ced43cc9da43977d74db7"
29
+ "gitHead": "0bb786cfea5db6f3b2b1445f7995e901795a14d5"
30
30
  }
package/src/index.js CHANGED
@@ -117,9 +117,15 @@ window.SallaApplePay = {
117
117
  SallaApplePay.initDefault();
118
118
 
119
119
  let version = SallaApplePay.getApplePaySessionVersion();
120
- let supportedNetworks = SallaApplePay.detail.supportedNetworks || ['masterCard', 'visa'];
121
-
122
- if (version === 5) {
120
+ // Normalize to an array: the backend can serialize the networks list as a JSON object
121
+ // (non-sequential PHP array keys). Copy it so we never mutate the shared `detail` reference.
122
+ // Works for both legacy (plain array) and unified (object-shaped) payloads.
123
+ let rawNetworks = SallaApplePay.detail.supportedNetworks;
124
+ let supportedNetworks = Array.isArray(rawNetworks) ? [...rawNetworks] : Object.values(rawNetworks || {});
125
+ if (!supportedNetworks.length) {
126
+ supportedNetworks = ['masterCard', 'visa'];
127
+ }
128
+ if (version === 5 && !supportedNetworks.includes('mada')) {
123
129
  supportedNetworks.push('mada');
124
130
  }
125
131
 
@@ -500,8 +506,16 @@ window.SallaApplePay = {
500
506
  payments
501
507
  });
502
508
 
503
- // todo :: enhance response from backend
504
- SallaApplePay.detail.amount = payments?.gateways?.applePay?.supportedMultiCurrency ? cart.total_in_customer_currency : cart.total;
509
+ // BE-canary gate keyed on the live payload (not cached config): the unified BE adds
510
+ // applePay.amount, legacy BE doesn't so gate and data can never desync.
511
+ if (payments?.gateways?.applePay?.amount != null) {
512
+ // Unified BE: Apple Pay is always charged in the store base currency.
513
+ SallaApplePay.detail.amount = payments.gateways.applePay.amount;
514
+ SallaApplePay.detail.currency = payments.gateways.applePay.currency ?? SallaApplePay.detail.currency;
515
+ } else {
516
+ // Legacy BE .
517
+ SallaApplePay.detail.amount = payments?.gateways?.applePay?.supportedMultiCurrency ? cart.total_in_customer_currency : cart.total;
518
+ }
505
519
  SallaApplePay.detail.items = (cart.totals || cart.items).map((item) => {
506
520
  return {
507
521
  label: item.title,