@economist/web-apple-pay 0.1.1-beta.0 → 0.1.1-beta.2
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/dist/index.js
CHANGED
|
@@ -307,7 +307,9 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
307
307
|
this.#country = value;
|
|
308
308
|
}
|
|
309
309
|
connectedCallback() {
|
|
310
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback");
|
|
310
311
|
if (this.querySelector(".apm-overlay")) {
|
|
312
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback: already rendered, skipping");
|
|
311
313
|
return;
|
|
312
314
|
}
|
|
313
315
|
ensureApplePayLogoSymbol();
|
|
@@ -321,6 +323,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
321
323
|
this.remove();
|
|
322
324
|
return;
|
|
323
325
|
}
|
|
326
|
+
console.log("[web-apple-pay] ApplePayModal: rendering for offer", { skuId: offer.sku_id, country });
|
|
324
327
|
const offerNameElement = this.querySelector(
|
|
325
328
|
"#apple-pay-modal-offer-name"
|
|
326
329
|
);
|
|
@@ -393,11 +396,14 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
393
396
|
});
|
|
394
397
|
}
|
|
395
398
|
cta?.addEventListener("click", () => {
|
|
399
|
+
console.log("[web-apple-pay] ApplePayModal: CTA clicked", { skuId: offer.sku_id, country, isUS });
|
|
396
400
|
if (isUS && checkbox && !checkbox.checked) {
|
|
401
|
+
console.log("[web-apple-pay] ApplePayModal: T&C checkbox not accepted, showing error");
|
|
397
402
|
errorElement?.classList.add("apm__error--visible");
|
|
398
403
|
checkboxLabel?.classList.add("apm__checkbox-label--error");
|
|
399
404
|
return;
|
|
400
405
|
}
|
|
406
|
+
console.log("[web-apple-pay] ApplePayModal: dispatching apple-pay-confirmed", { skuId: offer.sku_id, country });
|
|
401
407
|
this.dispatchEvent(
|
|
402
408
|
new CustomEvent("apple-pay-confirmed", {
|
|
403
409
|
bubbles: true,
|
|
@@ -405,7 +411,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
405
411
|
detail: { skuId: offer.sku_id, country }
|
|
406
412
|
})
|
|
407
413
|
);
|
|
408
|
-
this.close();
|
|
409
414
|
});
|
|
410
415
|
this.querySelector("#apple-pay-modal-close")?.addEventListener(
|
|
411
416
|
"click",
|
|
@@ -413,6 +418,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
413
418
|
);
|
|
414
419
|
}
|
|
415
420
|
open() {
|
|
421
|
+
console.log("[web-apple-pay] ApplePayModal: open()");
|
|
416
422
|
this.#triggerElement = document.activeElement;
|
|
417
423
|
document.body.appendChild(this);
|
|
418
424
|
this.#keyHandler = (event) => {
|
|
@@ -427,6 +433,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
427
433
|
this.querySelector("#apple-pay-modal")?.focus();
|
|
428
434
|
}
|
|
429
435
|
close() {
|
|
436
|
+
console.log("[web-apple-pay] ApplePayModal: close()");
|
|
430
437
|
if (this.#keyHandler) {
|
|
431
438
|
document.removeEventListener("keydown", this.#keyHandler, {
|
|
432
439
|
capture: true
|
|
@@ -1351,11 +1358,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1351
1358
|
* Creates and configures an ApplePayButton if the feature flag is present.
|
|
1352
1359
|
*/
|
|
1353
1360
|
static createIfEnabled(offer, country, entryPoint) {
|
|
1354
|
-
if (!offer)
|
|
1355
|
-
|
|
1361
|
+
if (!offer) {
|
|
1362
|
+
console.log("[web-apple-pay] createIfEnabled: no offer provided \u2192 null");
|
|
1356
1363
|
return null;
|
|
1357
|
-
|
|
1364
|
+
}
|
|
1365
|
+
if (APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant)) {
|
|
1366
|
+
console.log("[web-apple-pay] createIfEnabled: excluded variant \u2192 null", { variant: offer.product?.variant });
|
|
1358
1367
|
return null;
|
|
1368
|
+
}
|
|
1369
|
+
if (!new URLSearchParams(window.location.search).has(FEATURE_APPLE_PAY_EXPRESS_CHECKOUT)) {
|
|
1370
|
+
console.log("[web-apple-pay] createIfEnabled: feature flag absent \u2192 null");
|
|
1371
|
+
return null;
|
|
1372
|
+
}
|
|
1373
|
+
console.log("[web-apple-pay] createIfEnabled: creating button", { skuId: offer.sku_id, country, entryPoint });
|
|
1359
1374
|
_ApplePayButton.define();
|
|
1360
1375
|
const button = document.createElement(_ApplePayButton.tag);
|
|
1361
1376
|
button.offer = offer;
|
|
@@ -1423,7 +1438,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1423
1438
|
}
|
|
1424
1439
|
// ─── Lifecycle ──────────────────────────────────────────────────────────────
|
|
1425
1440
|
async connectedCallback() {
|
|
1441
|
+
console.log("[web-apple-pay] connectedCallback: element connected");
|
|
1426
1442
|
if (this.#rendering || this.querySelector(SEL_CONTAINER)) {
|
|
1443
|
+
console.log("[web-apple-pay] connectedCallback: already rendering or rendered, skipping");
|
|
1427
1444
|
return;
|
|
1428
1445
|
}
|
|
1429
1446
|
this.#rendering = true;
|
|
@@ -1450,6 +1467,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1450
1467
|
}
|
|
1451
1468
|
// ─── Render pipeline ────────────────────────────────────────────────────────
|
|
1452
1469
|
async #run() {
|
|
1470
|
+
console.log("[web-apple-pay] #run: starting render pipeline");
|
|
1453
1471
|
try {
|
|
1454
1472
|
if (await this.#checkAvailability()) return;
|
|
1455
1473
|
if (await this.#checkSession()) return;
|
|
@@ -1468,9 +1486,11 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1468
1486
|
async #checkAvailability() {
|
|
1469
1487
|
const available = await isApplePayAvailable();
|
|
1470
1488
|
if (!available) {
|
|
1489
|
+
console.log("[web-apple-pay] #checkAvailability: Apple Pay unavailable \u2192 hiding");
|
|
1471
1490
|
this.style.display = "none";
|
|
1472
1491
|
return true;
|
|
1473
1492
|
}
|
|
1493
|
+
console.log("[web-apple-pay] #checkAvailability: Apple Pay available");
|
|
1474
1494
|
return false;
|
|
1475
1495
|
}
|
|
1476
1496
|
/**
|
|
@@ -1479,7 +1499,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1479
1499
|
*/
|
|
1480
1500
|
async #checkSession() {
|
|
1481
1501
|
this.#sessionData = await this.#fetchSession();
|
|
1502
|
+
console.log("[web-apple-pay] #checkSession: session fetched", { loggedIn: this.#sessionData?.loggedIn, userType: this.#sessionData?.userType });
|
|
1482
1503
|
if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
|
|
1504
|
+
console.log("[web-apple-pay] #checkSession: ineligible user \u2192 hiding", { userType: this.#sessionData.userType });
|
|
1483
1505
|
this.style.display = "none";
|
|
1484
1506
|
return true;
|
|
1485
1507
|
}
|
|
@@ -1488,14 +1510,17 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1488
1510
|
/** Returns `true` (hide) when no offer has been set before mount. */
|
|
1489
1511
|
#checkOffer() {
|
|
1490
1512
|
if (!this.#offer) {
|
|
1513
|
+
console.log("[web-apple-pay] #checkOffer: no offer set \u2192 hiding");
|
|
1491
1514
|
this.style.display = "none";
|
|
1492
1515
|
return true;
|
|
1493
1516
|
}
|
|
1517
|
+
console.log("[web-apple-pay] #checkOffer: offer present", { skuId: this.#offer.sku_id });
|
|
1494
1518
|
return false;
|
|
1495
1519
|
}
|
|
1496
1520
|
/** Captures the current page URL once at mount for reuse across the session lifetime. */
|
|
1497
1521
|
#captureReturnUrl() {
|
|
1498
1522
|
this.#returnUrl = captureOriginUrl();
|
|
1523
|
+
console.log("[web-apple-pay] #captureReturnUrl:", this.#returnUrl);
|
|
1499
1524
|
}
|
|
1500
1525
|
/**
|
|
1501
1526
|
* Computes supported billing countries once at mount.
|
|
@@ -1507,6 +1532,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1507
1532
|
this.#country,
|
|
1508
1533
|
this.#offer.product?.variant ?? ""
|
|
1509
1534
|
);
|
|
1535
|
+
console.log("[web-apple-pay] #computeBillingCountries:", this.#supportedBillingCountries);
|
|
1510
1536
|
}
|
|
1511
1537
|
/**
|
|
1512
1538
|
* Returns `true` (hide) when the wallet BFF reports Apple Pay is unavailable
|
|
@@ -1516,6 +1542,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1516
1542
|
this.#paymentOptions = await this.#fetchPaymentOptions();
|
|
1517
1543
|
console.log("[web-apple-pay] #fetchAndCacheOptions: fetched payment options", { paymentOptions: this.#paymentOptions });
|
|
1518
1544
|
if (!this.#paymentOptions?.options?.apple_pay) {
|
|
1545
|
+
console.log("[web-apple-pay] #fetchAndCacheOptions: apple_pay not in options \u2192 hiding");
|
|
1519
1546
|
this.style.display = "none";
|
|
1520
1547
|
return true;
|
|
1521
1548
|
}
|
|
@@ -1523,6 +1550,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1523
1550
|
}
|
|
1524
1551
|
/** Injects the button template and wires click and confirm event listeners. */
|
|
1525
1552
|
#renderTemplate() {
|
|
1553
|
+
console.log("[web-apple-pay] #renderTemplate: rendering Apple Pay button", { skuId: this.#offer?.sku_id, country: this.#country });
|
|
1526
1554
|
this.style.removeProperty("display");
|
|
1527
1555
|
ensureApplePayLogoSymbol();
|
|
1528
1556
|
const template = document.createElement("template");
|
|
@@ -1555,6 +1583,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1555
1583
|
button.setAttribute("aria-disabled", "true");
|
|
1556
1584
|
}
|
|
1557
1585
|
#openModal() {
|
|
1586
|
+
console.log("[web-apple-pay] #openModal: button clicked", { skuId: this.#offer?.sku_id });
|
|
1558
1587
|
if (!this.#offer || document.querySelector(ApplePayModal.tag)) return;
|
|
1559
1588
|
trackExpressWalletClick(this.#offer.sku_id);
|
|
1560
1589
|
ApplePayModal.define();
|
|
@@ -1568,24 +1597,31 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1568
1597
|
}
|
|
1569
1598
|
async #fetchSession() {
|
|
1570
1599
|
try {
|
|
1571
|
-
|
|
1572
|
-
|
|
1600
|
+
const session = await getExpressCheckoutSession();
|
|
1601
|
+
console.log("[web-apple-pay] #fetchSession: success", { loggedIn: session.loggedIn, userType: session.userType });
|
|
1602
|
+
return session;
|
|
1603
|
+
} catch (err) {
|
|
1604
|
+
console.warn("[web-apple-pay] #fetchSession: failed, falling back to anonymous session", err);
|
|
1573
1605
|
return null;
|
|
1574
1606
|
}
|
|
1575
1607
|
}
|
|
1576
1608
|
async #fetchPaymentOptions() {
|
|
1577
1609
|
try {
|
|
1578
|
-
|
|
1610
|
+
const options = await getPaymentOptions({
|
|
1579
1611
|
sku: this.#offer.sku_id,
|
|
1580
1612
|
countryCode: this.#country,
|
|
1581
1613
|
currencyCode: this.#offer.price?.currency_code ?? DEFAULT_CURRENCY,
|
|
1582
1614
|
checkoutUrl: this.#returnUrl
|
|
1583
1615
|
});
|
|
1584
|
-
|
|
1616
|
+
console.log("[web-apple-pay] #fetchPaymentOptions: success", { hasApplePay: !!options?.options?.apple_pay });
|
|
1617
|
+
return options;
|
|
1618
|
+
} catch (err) {
|
|
1619
|
+
console.warn("[web-apple-pay] #fetchPaymentOptions: failed", err);
|
|
1585
1620
|
return null;
|
|
1586
1621
|
}
|
|
1587
1622
|
}
|
|
1588
1623
|
#buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokens) {
|
|
1624
|
+
console.log("[web-apple-pay] #buildSessionParams", { skuId, country, userLoggedIn: sessionData.loggedIn });
|
|
1589
1625
|
const offer = this.#offer;
|
|
1590
1626
|
const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
|
|
1591
1627
|
return {
|
|
@@ -1608,6 +1644,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1608
1644
|
};
|
|
1609
1645
|
}
|
|
1610
1646
|
async #initiateApplePay(skuId, country) {
|
|
1647
|
+
console.log("[web-apple-pay] #initiateApplePay: starting", { skuId, country });
|
|
1611
1648
|
try {
|
|
1612
1649
|
const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
|
|
1613
1650
|
const paymentOptions = this.#paymentOptions;
|
|
@@ -307,7 +307,9 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
307
307
|
this.#country = value;
|
|
308
308
|
}
|
|
309
309
|
connectedCallback() {
|
|
310
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback");
|
|
310
311
|
if (this.querySelector(".apm-overlay")) {
|
|
312
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback: already rendered, skipping");
|
|
311
313
|
return;
|
|
312
314
|
}
|
|
313
315
|
ensureApplePayLogoSymbol();
|
|
@@ -321,6 +323,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
321
323
|
this.remove();
|
|
322
324
|
return;
|
|
323
325
|
}
|
|
326
|
+
console.log("[web-apple-pay] ApplePayModal: rendering for offer", { skuId: offer.sku_id, country });
|
|
324
327
|
const offerNameElement = this.querySelector(
|
|
325
328
|
"#apple-pay-modal-offer-name"
|
|
326
329
|
);
|
|
@@ -393,11 +396,14 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
393
396
|
});
|
|
394
397
|
}
|
|
395
398
|
cta?.addEventListener("click", () => {
|
|
399
|
+
console.log("[web-apple-pay] ApplePayModal: CTA clicked", { skuId: offer.sku_id, country, isUS });
|
|
396
400
|
if (isUS && checkbox && !checkbox.checked) {
|
|
401
|
+
console.log("[web-apple-pay] ApplePayModal: T&C checkbox not accepted, showing error");
|
|
397
402
|
errorElement?.classList.add("apm__error--visible");
|
|
398
403
|
checkboxLabel?.classList.add("apm__checkbox-label--error");
|
|
399
404
|
return;
|
|
400
405
|
}
|
|
406
|
+
console.log("[web-apple-pay] ApplePayModal: dispatching apple-pay-confirmed", { skuId: offer.sku_id, country });
|
|
401
407
|
this.dispatchEvent(
|
|
402
408
|
new CustomEvent("apple-pay-confirmed", {
|
|
403
409
|
bubbles: true,
|
|
@@ -405,7 +411,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
405
411
|
detail: { skuId: offer.sku_id, country }
|
|
406
412
|
})
|
|
407
413
|
);
|
|
408
|
-
this.close();
|
|
409
414
|
});
|
|
410
415
|
this.querySelector("#apple-pay-modal-close")?.addEventListener(
|
|
411
416
|
"click",
|
|
@@ -413,6 +418,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
413
418
|
);
|
|
414
419
|
}
|
|
415
420
|
open() {
|
|
421
|
+
console.log("[web-apple-pay] ApplePayModal: open()");
|
|
416
422
|
this.#triggerElement = document.activeElement;
|
|
417
423
|
document.body.appendChild(this);
|
|
418
424
|
this.#keyHandler = (event) => {
|
|
@@ -427,6 +433,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
427
433
|
this.querySelector("#apple-pay-modal")?.focus();
|
|
428
434
|
}
|
|
429
435
|
close() {
|
|
436
|
+
console.log("[web-apple-pay] ApplePayModal: close()");
|
|
430
437
|
if (this.#keyHandler) {
|
|
431
438
|
document.removeEventListener("keydown", this.#keyHandler, {
|
|
432
439
|
capture: true
|
|
@@ -1340,11 +1347,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1340
1347
|
* Creates and configures an ApplePayButton if the feature flag is present.
|
|
1341
1348
|
*/
|
|
1342
1349
|
static createIfEnabled(offer, country, entryPoint) {
|
|
1343
|
-
if (!offer)
|
|
1344
|
-
|
|
1350
|
+
if (!offer) {
|
|
1351
|
+
console.log("[web-apple-pay] createIfEnabled: no offer provided \u2192 null");
|
|
1345
1352
|
return null;
|
|
1346
|
-
|
|
1353
|
+
}
|
|
1354
|
+
if (APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant)) {
|
|
1355
|
+
console.log("[web-apple-pay] createIfEnabled: excluded variant \u2192 null", { variant: offer.product?.variant });
|
|
1347
1356
|
return null;
|
|
1357
|
+
}
|
|
1358
|
+
if (!new URLSearchParams(window.location.search).has(FEATURE_APPLE_PAY_EXPRESS_CHECKOUT)) {
|
|
1359
|
+
console.log("[web-apple-pay] createIfEnabled: feature flag absent \u2192 null");
|
|
1360
|
+
return null;
|
|
1361
|
+
}
|
|
1362
|
+
console.log("[web-apple-pay] createIfEnabled: creating button", { skuId: offer.sku_id, country, entryPoint });
|
|
1348
1363
|
_ApplePayButton.define();
|
|
1349
1364
|
const button = document.createElement(_ApplePayButton.tag);
|
|
1350
1365
|
button.offer = offer;
|
|
@@ -1412,7 +1427,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1412
1427
|
}
|
|
1413
1428
|
// ─── Lifecycle ──────────────────────────────────────────────────────────────
|
|
1414
1429
|
async connectedCallback() {
|
|
1430
|
+
console.log("[web-apple-pay] connectedCallback: element connected");
|
|
1415
1431
|
if (this.#rendering || this.querySelector(SEL_CONTAINER)) {
|
|
1432
|
+
console.log("[web-apple-pay] connectedCallback: already rendering or rendered, skipping");
|
|
1416
1433
|
return;
|
|
1417
1434
|
}
|
|
1418
1435
|
this.#rendering = true;
|
|
@@ -1439,6 +1456,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1439
1456
|
}
|
|
1440
1457
|
// ─── Render pipeline ────────────────────────────────────────────────────────
|
|
1441
1458
|
async #run() {
|
|
1459
|
+
console.log("[web-apple-pay] #run: starting render pipeline");
|
|
1442
1460
|
try {
|
|
1443
1461
|
if (await this.#checkAvailability()) return;
|
|
1444
1462
|
if (await this.#checkSession()) return;
|
|
@@ -1457,9 +1475,11 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1457
1475
|
async #checkAvailability() {
|
|
1458
1476
|
const available = await isApplePayAvailable();
|
|
1459
1477
|
if (!available) {
|
|
1478
|
+
console.log("[web-apple-pay] #checkAvailability: Apple Pay unavailable \u2192 hiding");
|
|
1460
1479
|
this.style.display = "none";
|
|
1461
1480
|
return true;
|
|
1462
1481
|
}
|
|
1482
|
+
console.log("[web-apple-pay] #checkAvailability: Apple Pay available");
|
|
1463
1483
|
return false;
|
|
1464
1484
|
}
|
|
1465
1485
|
/**
|
|
@@ -1468,7 +1488,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1468
1488
|
*/
|
|
1469
1489
|
async #checkSession() {
|
|
1470
1490
|
this.#sessionData = await this.#fetchSession();
|
|
1491
|
+
console.log("[web-apple-pay] #checkSession: session fetched", { loggedIn: this.#sessionData?.loggedIn, userType: this.#sessionData?.userType });
|
|
1471
1492
|
if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
|
|
1493
|
+
console.log("[web-apple-pay] #checkSession: ineligible user \u2192 hiding", { userType: this.#sessionData.userType });
|
|
1472
1494
|
this.style.display = "none";
|
|
1473
1495
|
return true;
|
|
1474
1496
|
}
|
|
@@ -1477,14 +1499,17 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1477
1499
|
/** Returns `true` (hide) when no offer has been set before mount. */
|
|
1478
1500
|
#checkOffer() {
|
|
1479
1501
|
if (!this.#offer) {
|
|
1502
|
+
console.log("[web-apple-pay] #checkOffer: no offer set \u2192 hiding");
|
|
1480
1503
|
this.style.display = "none";
|
|
1481
1504
|
return true;
|
|
1482
1505
|
}
|
|
1506
|
+
console.log("[web-apple-pay] #checkOffer: offer present", { skuId: this.#offer.sku_id });
|
|
1483
1507
|
return false;
|
|
1484
1508
|
}
|
|
1485
1509
|
/** Captures the current page URL once at mount for reuse across the session lifetime. */
|
|
1486
1510
|
#captureReturnUrl() {
|
|
1487
1511
|
this.#returnUrl = captureOriginUrl();
|
|
1512
|
+
console.log("[web-apple-pay] #captureReturnUrl:", this.#returnUrl);
|
|
1488
1513
|
}
|
|
1489
1514
|
/**
|
|
1490
1515
|
* Computes supported billing countries once at mount.
|
|
@@ -1496,6 +1521,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1496
1521
|
this.#country,
|
|
1497
1522
|
this.#offer.product?.variant ?? ""
|
|
1498
1523
|
);
|
|
1524
|
+
console.log("[web-apple-pay] #computeBillingCountries:", this.#supportedBillingCountries);
|
|
1499
1525
|
}
|
|
1500
1526
|
/**
|
|
1501
1527
|
* Returns `true` (hide) when the wallet BFF reports Apple Pay is unavailable
|
|
@@ -1505,6 +1531,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1505
1531
|
this.#paymentOptions = await this.#fetchPaymentOptions();
|
|
1506
1532
|
console.log("[web-apple-pay] #fetchAndCacheOptions: fetched payment options", { paymentOptions: this.#paymentOptions });
|
|
1507
1533
|
if (!this.#paymentOptions?.options?.apple_pay) {
|
|
1534
|
+
console.log("[web-apple-pay] #fetchAndCacheOptions: apple_pay not in options \u2192 hiding");
|
|
1508
1535
|
this.style.display = "none";
|
|
1509
1536
|
return true;
|
|
1510
1537
|
}
|
|
@@ -1512,6 +1539,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1512
1539
|
}
|
|
1513
1540
|
/** Injects the button template and wires click and confirm event listeners. */
|
|
1514
1541
|
#renderTemplate() {
|
|
1542
|
+
console.log("[web-apple-pay] #renderTemplate: rendering Apple Pay button", { skuId: this.#offer?.sku_id, country: this.#country });
|
|
1515
1543
|
this.style.removeProperty("display");
|
|
1516
1544
|
ensureApplePayLogoSymbol();
|
|
1517
1545
|
const template = document.createElement("template");
|
|
@@ -1544,6 +1572,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1544
1572
|
button.setAttribute("aria-disabled", "true");
|
|
1545
1573
|
}
|
|
1546
1574
|
#openModal() {
|
|
1575
|
+
console.log("[web-apple-pay] #openModal: button clicked", { skuId: this.#offer?.sku_id });
|
|
1547
1576
|
if (!this.#offer || document.querySelector(ApplePayModal.tag)) return;
|
|
1548
1577
|
trackExpressWalletClick(this.#offer.sku_id);
|
|
1549
1578
|
ApplePayModal.define();
|
|
@@ -1557,24 +1586,31 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1557
1586
|
}
|
|
1558
1587
|
async #fetchSession() {
|
|
1559
1588
|
try {
|
|
1560
|
-
|
|
1561
|
-
|
|
1589
|
+
const session = await getExpressCheckoutSession();
|
|
1590
|
+
console.log("[web-apple-pay] #fetchSession: success", { loggedIn: session.loggedIn, userType: session.userType });
|
|
1591
|
+
return session;
|
|
1592
|
+
} catch (err) {
|
|
1593
|
+
console.warn("[web-apple-pay] #fetchSession: failed, falling back to anonymous session", err);
|
|
1562
1594
|
return null;
|
|
1563
1595
|
}
|
|
1564
1596
|
}
|
|
1565
1597
|
async #fetchPaymentOptions() {
|
|
1566
1598
|
try {
|
|
1567
|
-
|
|
1599
|
+
const options = await getPaymentOptions({
|
|
1568
1600
|
sku: this.#offer.sku_id,
|
|
1569
1601
|
countryCode: this.#country,
|
|
1570
1602
|
currencyCode: this.#offer.price?.currency_code ?? DEFAULT_CURRENCY,
|
|
1571
1603
|
checkoutUrl: this.#returnUrl
|
|
1572
1604
|
});
|
|
1573
|
-
|
|
1605
|
+
console.log("[web-apple-pay] #fetchPaymentOptions: success", { hasApplePay: !!options?.options?.apple_pay });
|
|
1606
|
+
return options;
|
|
1607
|
+
} catch (err) {
|
|
1608
|
+
console.warn("[web-apple-pay] #fetchPaymentOptions: failed", err);
|
|
1574
1609
|
return null;
|
|
1575
1610
|
}
|
|
1576
1611
|
}
|
|
1577
1612
|
#buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokens) {
|
|
1613
|
+
console.log("[web-apple-pay] #buildSessionParams", { skuId, country, userLoggedIn: sessionData.loggedIn });
|
|
1578
1614
|
const offer = this.#offer;
|
|
1579
1615
|
const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
|
|
1580
1616
|
return {
|
|
@@ -1597,6 +1633,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1597
1633
|
};
|
|
1598
1634
|
}
|
|
1599
1635
|
async #initiateApplePay(skuId, country) {
|
|
1636
|
+
console.log("[web-apple-pay] #initiateApplePay: starting", { skuId, country });
|
|
1600
1637
|
try {
|
|
1601
1638
|
const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
|
|
1602
1639
|
const paymentOptions = this.#paymentOptions;
|
|
@@ -307,7 +307,9 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
307
307
|
this.#country = value;
|
|
308
308
|
}
|
|
309
309
|
connectedCallback() {
|
|
310
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback");
|
|
310
311
|
if (this.querySelector(".apm-overlay")) {
|
|
312
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback: already rendered, skipping");
|
|
311
313
|
return;
|
|
312
314
|
}
|
|
313
315
|
ensureApplePayLogoSymbol();
|
|
@@ -321,6 +323,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
321
323
|
this.remove();
|
|
322
324
|
return;
|
|
323
325
|
}
|
|
326
|
+
console.log("[web-apple-pay] ApplePayModal: rendering for offer", { skuId: offer.sku_id, country });
|
|
324
327
|
const offerNameElement = this.querySelector(
|
|
325
328
|
"#apple-pay-modal-offer-name"
|
|
326
329
|
);
|
|
@@ -393,11 +396,14 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
393
396
|
});
|
|
394
397
|
}
|
|
395
398
|
cta?.addEventListener("click", () => {
|
|
399
|
+
console.log("[web-apple-pay] ApplePayModal: CTA clicked", { skuId: offer.sku_id, country, isUS });
|
|
396
400
|
if (isUS && checkbox && !checkbox.checked) {
|
|
401
|
+
console.log("[web-apple-pay] ApplePayModal: T&C checkbox not accepted, showing error");
|
|
397
402
|
errorElement?.classList.add("apm__error--visible");
|
|
398
403
|
checkboxLabel?.classList.add("apm__checkbox-label--error");
|
|
399
404
|
return;
|
|
400
405
|
}
|
|
406
|
+
console.log("[web-apple-pay] ApplePayModal: dispatching apple-pay-confirmed", { skuId: offer.sku_id, country });
|
|
401
407
|
this.dispatchEvent(
|
|
402
408
|
new CustomEvent("apple-pay-confirmed", {
|
|
403
409
|
bubbles: true,
|
|
@@ -405,7 +411,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
405
411
|
detail: { skuId: offer.sku_id, country }
|
|
406
412
|
})
|
|
407
413
|
);
|
|
408
|
-
this.close();
|
|
409
414
|
});
|
|
410
415
|
this.querySelector("#apple-pay-modal-close")?.addEventListener(
|
|
411
416
|
"click",
|
|
@@ -413,6 +418,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
413
418
|
);
|
|
414
419
|
}
|
|
415
420
|
open() {
|
|
421
|
+
console.log("[web-apple-pay] ApplePayModal: open()");
|
|
416
422
|
this.#triggerElement = document.activeElement;
|
|
417
423
|
document.body.appendChild(this);
|
|
418
424
|
this.#keyHandler = (event) => {
|
|
@@ -427,6 +433,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
427
433
|
this.querySelector("#apple-pay-modal")?.focus();
|
|
428
434
|
}
|
|
429
435
|
close() {
|
|
436
|
+
console.log("[web-apple-pay] ApplePayModal: close()");
|
|
430
437
|
if (this.#keyHandler) {
|
|
431
438
|
document.removeEventListener("keydown", this.#keyHandler, {
|
|
432
439
|
capture: true
|
|
@@ -1355,11 +1362,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1355
1362
|
* Creates and configures an ApplePayButton if the feature flag is present.
|
|
1356
1363
|
*/
|
|
1357
1364
|
static createIfEnabled(offer, country, entryPoint) {
|
|
1358
|
-
if (!offer)
|
|
1359
|
-
|
|
1365
|
+
if (!offer) {
|
|
1366
|
+
console.log("[web-apple-pay] createIfEnabled: no offer provided \u2192 null");
|
|
1360
1367
|
return null;
|
|
1361
|
-
|
|
1368
|
+
}
|
|
1369
|
+
if (APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant)) {
|
|
1370
|
+
console.log("[web-apple-pay] createIfEnabled: excluded variant \u2192 null", { variant: offer.product?.variant });
|
|
1362
1371
|
return null;
|
|
1372
|
+
}
|
|
1373
|
+
if (!new URLSearchParams(window.location.search).has(FEATURE_APPLE_PAY_EXPRESS_CHECKOUT)) {
|
|
1374
|
+
console.log("[web-apple-pay] createIfEnabled: feature flag absent \u2192 null");
|
|
1375
|
+
return null;
|
|
1376
|
+
}
|
|
1377
|
+
console.log("[web-apple-pay] createIfEnabled: creating button", { skuId: offer.sku_id, country, entryPoint });
|
|
1363
1378
|
_ApplePayButton.define();
|
|
1364
1379
|
const button = document.createElement(_ApplePayButton.tag);
|
|
1365
1380
|
button.offer = offer;
|
|
@@ -1427,7 +1442,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1427
1442
|
}
|
|
1428
1443
|
// ─── Lifecycle ──────────────────────────────────────────────────────────────
|
|
1429
1444
|
async connectedCallback() {
|
|
1445
|
+
console.log("[web-apple-pay] connectedCallback: element connected");
|
|
1430
1446
|
if (this.#rendering || this.querySelector(SEL_CONTAINER)) {
|
|
1447
|
+
console.log("[web-apple-pay] connectedCallback: already rendering or rendered, skipping");
|
|
1431
1448
|
return;
|
|
1432
1449
|
}
|
|
1433
1450
|
this.#rendering = true;
|
|
@@ -1454,6 +1471,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1454
1471
|
}
|
|
1455
1472
|
// ─── Render pipeline ────────────────────────────────────────────────────────
|
|
1456
1473
|
async #run() {
|
|
1474
|
+
console.log("[web-apple-pay] #run: starting render pipeline");
|
|
1457
1475
|
try {
|
|
1458
1476
|
if (await this.#checkAvailability()) return;
|
|
1459
1477
|
if (await this.#checkSession()) return;
|
|
@@ -1472,9 +1490,11 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1472
1490
|
async #checkAvailability() {
|
|
1473
1491
|
const available = await isApplePayAvailable();
|
|
1474
1492
|
if (!available) {
|
|
1493
|
+
console.log("[web-apple-pay] #checkAvailability: Apple Pay unavailable \u2192 hiding");
|
|
1475
1494
|
this.style.display = "none";
|
|
1476
1495
|
return true;
|
|
1477
1496
|
}
|
|
1497
|
+
console.log("[web-apple-pay] #checkAvailability: Apple Pay available");
|
|
1478
1498
|
return false;
|
|
1479
1499
|
}
|
|
1480
1500
|
/**
|
|
@@ -1483,7 +1503,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1483
1503
|
*/
|
|
1484
1504
|
async #checkSession() {
|
|
1485
1505
|
this.#sessionData = await this.#fetchSession();
|
|
1506
|
+
console.log("[web-apple-pay] #checkSession: session fetched", { loggedIn: this.#sessionData?.loggedIn, userType: this.#sessionData?.userType });
|
|
1486
1507
|
if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
|
|
1508
|
+
console.log("[web-apple-pay] #checkSession: ineligible user \u2192 hiding", { userType: this.#sessionData.userType });
|
|
1487
1509
|
this.style.display = "none";
|
|
1488
1510
|
return true;
|
|
1489
1511
|
}
|
|
@@ -1492,14 +1514,17 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1492
1514
|
/** Returns `true` (hide) when no offer has been set before mount. */
|
|
1493
1515
|
#checkOffer() {
|
|
1494
1516
|
if (!this.#offer) {
|
|
1517
|
+
console.log("[web-apple-pay] #checkOffer: no offer set \u2192 hiding");
|
|
1495
1518
|
this.style.display = "none";
|
|
1496
1519
|
return true;
|
|
1497
1520
|
}
|
|
1521
|
+
console.log("[web-apple-pay] #checkOffer: offer present", { skuId: this.#offer.sku_id });
|
|
1498
1522
|
return false;
|
|
1499
1523
|
}
|
|
1500
1524
|
/** Captures the current page URL once at mount for reuse across the session lifetime. */
|
|
1501
1525
|
#captureReturnUrl() {
|
|
1502
1526
|
this.#returnUrl = captureOriginUrl();
|
|
1527
|
+
console.log("[web-apple-pay] #captureReturnUrl:", this.#returnUrl);
|
|
1503
1528
|
}
|
|
1504
1529
|
/**
|
|
1505
1530
|
* Computes supported billing countries once at mount.
|
|
@@ -1511,6 +1536,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1511
1536
|
this.#country,
|
|
1512
1537
|
this.#offer.product?.variant ?? ""
|
|
1513
1538
|
);
|
|
1539
|
+
console.log("[web-apple-pay] #computeBillingCountries:", this.#supportedBillingCountries);
|
|
1514
1540
|
}
|
|
1515
1541
|
/**
|
|
1516
1542
|
* Returns `true` (hide) when the wallet BFF reports Apple Pay is unavailable
|
|
@@ -1520,6 +1546,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1520
1546
|
this.#paymentOptions = await this.#fetchPaymentOptions();
|
|
1521
1547
|
console.log("[web-apple-pay] #fetchAndCacheOptions: fetched payment options", { paymentOptions: this.#paymentOptions });
|
|
1522
1548
|
if (!this.#paymentOptions?.options?.apple_pay) {
|
|
1549
|
+
console.log("[web-apple-pay] #fetchAndCacheOptions: apple_pay not in options \u2192 hiding");
|
|
1523
1550
|
this.style.display = "none";
|
|
1524
1551
|
return true;
|
|
1525
1552
|
}
|
|
@@ -1527,6 +1554,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1527
1554
|
}
|
|
1528
1555
|
/** Injects the button template and wires click and confirm event listeners. */
|
|
1529
1556
|
#renderTemplate() {
|
|
1557
|
+
console.log("[web-apple-pay] #renderTemplate: rendering Apple Pay button", { skuId: this.#offer?.sku_id, country: this.#country });
|
|
1530
1558
|
this.style.removeProperty("display");
|
|
1531
1559
|
ensureApplePayLogoSymbol();
|
|
1532
1560
|
const template = document.createElement("template");
|
|
@@ -1559,6 +1587,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1559
1587
|
button.setAttribute("aria-disabled", "true");
|
|
1560
1588
|
}
|
|
1561
1589
|
#openModal() {
|
|
1590
|
+
console.log("[web-apple-pay] #openModal: button clicked", { skuId: this.#offer?.sku_id });
|
|
1562
1591
|
if (!this.#offer || document.querySelector(ApplePayModal.tag)) return;
|
|
1563
1592
|
trackExpressWalletClick(this.#offer.sku_id);
|
|
1564
1593
|
ApplePayModal.define();
|
|
@@ -1572,24 +1601,31 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1572
1601
|
}
|
|
1573
1602
|
async #fetchSession() {
|
|
1574
1603
|
try {
|
|
1575
|
-
|
|
1576
|
-
|
|
1604
|
+
const session = await getExpressCheckoutSession();
|
|
1605
|
+
console.log("[web-apple-pay] #fetchSession: success", { loggedIn: session.loggedIn, userType: session.userType });
|
|
1606
|
+
return session;
|
|
1607
|
+
} catch (err) {
|
|
1608
|
+
console.warn("[web-apple-pay] #fetchSession: failed, falling back to anonymous session", err);
|
|
1577
1609
|
return null;
|
|
1578
1610
|
}
|
|
1579
1611
|
}
|
|
1580
1612
|
async #fetchPaymentOptions() {
|
|
1581
1613
|
try {
|
|
1582
|
-
|
|
1614
|
+
const options = await getPaymentOptions({
|
|
1583
1615
|
sku: this.#offer.sku_id,
|
|
1584
1616
|
countryCode: this.#country,
|
|
1585
1617
|
currencyCode: this.#offer.price?.currency_code ?? DEFAULT_CURRENCY,
|
|
1586
1618
|
checkoutUrl: this.#returnUrl
|
|
1587
1619
|
});
|
|
1588
|
-
|
|
1620
|
+
console.log("[web-apple-pay] #fetchPaymentOptions: success", { hasApplePay: !!options?.options?.apple_pay });
|
|
1621
|
+
return options;
|
|
1622
|
+
} catch (err) {
|
|
1623
|
+
console.warn("[web-apple-pay] #fetchPaymentOptions: failed", err);
|
|
1589
1624
|
return null;
|
|
1590
1625
|
}
|
|
1591
1626
|
}
|
|
1592
1627
|
#buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokens) {
|
|
1628
|
+
console.log("[web-apple-pay] #buildSessionParams", { skuId, country, userLoggedIn: sessionData.loggedIn });
|
|
1593
1629
|
const offer = this.#offer;
|
|
1594
1630
|
const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
|
|
1595
1631
|
return {
|
|
@@ -1612,6 +1648,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1612
1648
|
};
|
|
1613
1649
|
}
|
|
1614
1650
|
async #initiateApplePay(skuId, country) {
|
|
1651
|
+
console.log("[web-apple-pay] #initiateApplePay: starting", { skuId, country });
|
|
1615
1652
|
try {
|
|
1616
1653
|
const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
|
|
1617
1654
|
const paymentOptions = this.#paymentOptions;
|
|
@@ -307,7 +307,9 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
307
307
|
this.#country = value;
|
|
308
308
|
}
|
|
309
309
|
connectedCallback() {
|
|
310
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback");
|
|
310
311
|
if (this.querySelector(".apm-overlay")) {
|
|
312
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback: already rendered, skipping");
|
|
311
313
|
return;
|
|
312
314
|
}
|
|
313
315
|
ensureApplePayLogoSymbol();
|
|
@@ -321,6 +323,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
321
323
|
this.remove();
|
|
322
324
|
return;
|
|
323
325
|
}
|
|
326
|
+
console.log("[web-apple-pay] ApplePayModal: rendering for offer", { skuId: offer.sku_id, country });
|
|
324
327
|
const offerNameElement = this.querySelector(
|
|
325
328
|
"#apple-pay-modal-offer-name"
|
|
326
329
|
);
|
|
@@ -393,11 +396,14 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
393
396
|
});
|
|
394
397
|
}
|
|
395
398
|
cta?.addEventListener("click", () => {
|
|
399
|
+
console.log("[web-apple-pay] ApplePayModal: CTA clicked", { skuId: offer.sku_id, country, isUS });
|
|
396
400
|
if (isUS && checkbox && !checkbox.checked) {
|
|
401
|
+
console.log("[web-apple-pay] ApplePayModal: T&C checkbox not accepted, showing error");
|
|
397
402
|
errorElement?.classList.add("apm__error--visible");
|
|
398
403
|
checkboxLabel?.classList.add("apm__checkbox-label--error");
|
|
399
404
|
return;
|
|
400
405
|
}
|
|
406
|
+
console.log("[web-apple-pay] ApplePayModal: dispatching apple-pay-confirmed", { skuId: offer.sku_id, country });
|
|
401
407
|
this.dispatchEvent(
|
|
402
408
|
new CustomEvent("apple-pay-confirmed", {
|
|
403
409
|
bubbles: true,
|
|
@@ -405,7 +411,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
405
411
|
detail: { skuId: offer.sku_id, country }
|
|
406
412
|
})
|
|
407
413
|
);
|
|
408
|
-
this.close();
|
|
409
414
|
});
|
|
410
415
|
this.querySelector("#apple-pay-modal-close")?.addEventListener(
|
|
411
416
|
"click",
|
|
@@ -413,6 +418,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
413
418
|
);
|
|
414
419
|
}
|
|
415
420
|
open() {
|
|
421
|
+
console.log("[web-apple-pay] ApplePayModal: open()");
|
|
416
422
|
this.#triggerElement = document.activeElement;
|
|
417
423
|
document.body.appendChild(this);
|
|
418
424
|
this.#keyHandler = (event) => {
|
|
@@ -427,6 +433,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
427
433
|
this.querySelector("#apple-pay-modal")?.focus();
|
|
428
434
|
}
|
|
429
435
|
close() {
|
|
436
|
+
console.log("[web-apple-pay] ApplePayModal: close()");
|
|
430
437
|
if (this.#keyHandler) {
|
|
431
438
|
document.removeEventListener("keydown", this.#keyHandler, {
|
|
432
439
|
capture: true
|
|
@@ -307,7 +307,9 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
307
307
|
this.#country = value;
|
|
308
308
|
}
|
|
309
309
|
connectedCallback() {
|
|
310
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback");
|
|
310
311
|
if (this.querySelector(".apm-overlay")) {
|
|
312
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback: already rendered, skipping");
|
|
311
313
|
return;
|
|
312
314
|
}
|
|
313
315
|
ensureApplePayLogoSymbol();
|
|
@@ -321,6 +323,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
321
323
|
this.remove();
|
|
322
324
|
return;
|
|
323
325
|
}
|
|
326
|
+
console.log("[web-apple-pay] ApplePayModal: rendering for offer", { skuId: offer.sku_id, country });
|
|
324
327
|
const offerNameElement = this.querySelector(
|
|
325
328
|
"#apple-pay-modal-offer-name"
|
|
326
329
|
);
|
|
@@ -393,11 +396,14 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
393
396
|
});
|
|
394
397
|
}
|
|
395
398
|
cta?.addEventListener("click", () => {
|
|
399
|
+
console.log("[web-apple-pay] ApplePayModal: CTA clicked", { skuId: offer.sku_id, country, isUS });
|
|
396
400
|
if (isUS && checkbox && !checkbox.checked) {
|
|
401
|
+
console.log("[web-apple-pay] ApplePayModal: T&C checkbox not accepted, showing error");
|
|
397
402
|
errorElement?.classList.add("apm__error--visible");
|
|
398
403
|
checkboxLabel?.classList.add("apm__checkbox-label--error");
|
|
399
404
|
return;
|
|
400
405
|
}
|
|
406
|
+
console.log("[web-apple-pay] ApplePayModal: dispatching apple-pay-confirmed", { skuId: offer.sku_id, country });
|
|
401
407
|
this.dispatchEvent(
|
|
402
408
|
new CustomEvent("apple-pay-confirmed", {
|
|
403
409
|
bubbles: true,
|
|
@@ -405,7 +411,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
405
411
|
detail: { skuId: offer.sku_id, country }
|
|
406
412
|
})
|
|
407
413
|
);
|
|
408
|
-
this.close();
|
|
409
414
|
});
|
|
410
415
|
this.querySelector("#apple-pay-modal-close")?.addEventListener(
|
|
411
416
|
"click",
|
|
@@ -413,6 +418,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
413
418
|
);
|
|
414
419
|
}
|
|
415
420
|
open() {
|
|
421
|
+
console.log("[web-apple-pay] ApplePayModal: open()");
|
|
416
422
|
this.#triggerElement = document.activeElement;
|
|
417
423
|
document.body.appendChild(this);
|
|
418
424
|
this.#keyHandler = (event) => {
|
|
@@ -427,6 +433,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
427
433
|
this.querySelector("#apple-pay-modal")?.focus();
|
|
428
434
|
}
|
|
429
435
|
close() {
|
|
436
|
+
console.log("[web-apple-pay] ApplePayModal: close()");
|
|
430
437
|
if (this.#keyHandler) {
|
|
431
438
|
document.removeEventListener("keydown", this.#keyHandler, {
|
|
432
439
|
capture: true
|
|
@@ -1340,11 +1347,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1340
1347
|
* Creates and configures an ApplePayButton if the feature flag is present.
|
|
1341
1348
|
*/
|
|
1342
1349
|
static createIfEnabled(offer, country, entryPoint) {
|
|
1343
|
-
if (!offer)
|
|
1344
|
-
|
|
1350
|
+
if (!offer) {
|
|
1351
|
+
console.log("[web-apple-pay] createIfEnabled: no offer provided \u2192 null");
|
|
1345
1352
|
return null;
|
|
1346
|
-
|
|
1353
|
+
}
|
|
1354
|
+
if (APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant)) {
|
|
1355
|
+
console.log("[web-apple-pay] createIfEnabled: excluded variant \u2192 null", { variant: offer.product?.variant });
|
|
1347
1356
|
return null;
|
|
1357
|
+
}
|
|
1358
|
+
if (!new URLSearchParams(window.location.search).has(FEATURE_APPLE_PAY_EXPRESS_CHECKOUT)) {
|
|
1359
|
+
console.log("[web-apple-pay] createIfEnabled: feature flag absent \u2192 null");
|
|
1360
|
+
return null;
|
|
1361
|
+
}
|
|
1362
|
+
console.log("[web-apple-pay] createIfEnabled: creating button", { skuId: offer.sku_id, country, entryPoint });
|
|
1348
1363
|
_ApplePayButton.define();
|
|
1349
1364
|
const button = document.createElement(_ApplePayButton.tag);
|
|
1350
1365
|
button.offer = offer;
|
|
@@ -1412,7 +1427,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1412
1427
|
}
|
|
1413
1428
|
// ─── Lifecycle ──────────────────────────────────────────────────────────────
|
|
1414
1429
|
async connectedCallback() {
|
|
1430
|
+
console.log("[web-apple-pay] connectedCallback: element connected");
|
|
1415
1431
|
if (this.#rendering || this.querySelector(SEL_CONTAINER)) {
|
|
1432
|
+
console.log("[web-apple-pay] connectedCallback: already rendering or rendered, skipping");
|
|
1416
1433
|
return;
|
|
1417
1434
|
}
|
|
1418
1435
|
this.#rendering = true;
|
|
@@ -1439,6 +1456,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1439
1456
|
}
|
|
1440
1457
|
// ─── Render pipeline ────────────────────────────────────────────────────────
|
|
1441
1458
|
async #run() {
|
|
1459
|
+
console.log("[web-apple-pay] #run: starting render pipeline");
|
|
1442
1460
|
try {
|
|
1443
1461
|
if (await this.#checkAvailability()) return;
|
|
1444
1462
|
if (await this.#checkSession()) return;
|
|
@@ -1457,9 +1475,11 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1457
1475
|
async #checkAvailability() {
|
|
1458
1476
|
const available = await isApplePayAvailable();
|
|
1459
1477
|
if (!available) {
|
|
1478
|
+
console.log("[web-apple-pay] #checkAvailability: Apple Pay unavailable \u2192 hiding");
|
|
1460
1479
|
this.style.display = "none";
|
|
1461
1480
|
return true;
|
|
1462
1481
|
}
|
|
1482
|
+
console.log("[web-apple-pay] #checkAvailability: Apple Pay available");
|
|
1463
1483
|
return false;
|
|
1464
1484
|
}
|
|
1465
1485
|
/**
|
|
@@ -1468,7 +1488,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1468
1488
|
*/
|
|
1469
1489
|
async #checkSession() {
|
|
1470
1490
|
this.#sessionData = await this.#fetchSession();
|
|
1491
|
+
console.log("[web-apple-pay] #checkSession: session fetched", { loggedIn: this.#sessionData?.loggedIn, userType: this.#sessionData?.userType });
|
|
1471
1492
|
if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
|
|
1493
|
+
console.log("[web-apple-pay] #checkSession: ineligible user \u2192 hiding", { userType: this.#sessionData.userType });
|
|
1472
1494
|
this.style.display = "none";
|
|
1473
1495
|
return true;
|
|
1474
1496
|
}
|
|
@@ -1477,14 +1499,17 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1477
1499
|
/** Returns `true` (hide) when no offer has been set before mount. */
|
|
1478
1500
|
#checkOffer() {
|
|
1479
1501
|
if (!this.#offer) {
|
|
1502
|
+
console.log("[web-apple-pay] #checkOffer: no offer set \u2192 hiding");
|
|
1480
1503
|
this.style.display = "none";
|
|
1481
1504
|
return true;
|
|
1482
1505
|
}
|
|
1506
|
+
console.log("[web-apple-pay] #checkOffer: offer present", { skuId: this.#offer.sku_id });
|
|
1483
1507
|
return false;
|
|
1484
1508
|
}
|
|
1485
1509
|
/** Captures the current page URL once at mount for reuse across the session lifetime. */
|
|
1486
1510
|
#captureReturnUrl() {
|
|
1487
1511
|
this.#returnUrl = captureOriginUrl();
|
|
1512
|
+
console.log("[web-apple-pay] #captureReturnUrl:", this.#returnUrl);
|
|
1488
1513
|
}
|
|
1489
1514
|
/**
|
|
1490
1515
|
* Computes supported billing countries once at mount.
|
|
@@ -1496,6 +1521,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1496
1521
|
this.#country,
|
|
1497
1522
|
this.#offer.product?.variant ?? ""
|
|
1498
1523
|
);
|
|
1524
|
+
console.log("[web-apple-pay] #computeBillingCountries:", this.#supportedBillingCountries);
|
|
1499
1525
|
}
|
|
1500
1526
|
/**
|
|
1501
1527
|
* Returns `true` (hide) when the wallet BFF reports Apple Pay is unavailable
|
|
@@ -1505,6 +1531,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1505
1531
|
this.#paymentOptions = await this.#fetchPaymentOptions();
|
|
1506
1532
|
console.log("[web-apple-pay] #fetchAndCacheOptions: fetched payment options", { paymentOptions: this.#paymentOptions });
|
|
1507
1533
|
if (!this.#paymentOptions?.options?.apple_pay) {
|
|
1534
|
+
console.log("[web-apple-pay] #fetchAndCacheOptions: apple_pay not in options \u2192 hiding");
|
|
1508
1535
|
this.style.display = "none";
|
|
1509
1536
|
return true;
|
|
1510
1537
|
}
|
|
@@ -1512,6 +1539,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1512
1539
|
}
|
|
1513
1540
|
/** Injects the button template and wires click and confirm event listeners. */
|
|
1514
1541
|
#renderTemplate() {
|
|
1542
|
+
console.log("[web-apple-pay] #renderTemplate: rendering Apple Pay button", { skuId: this.#offer?.sku_id, country: this.#country });
|
|
1515
1543
|
this.style.removeProperty("display");
|
|
1516
1544
|
ensureApplePayLogoSymbol();
|
|
1517
1545
|
const template = document.createElement("template");
|
|
@@ -1544,6 +1572,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1544
1572
|
button.setAttribute("aria-disabled", "true");
|
|
1545
1573
|
}
|
|
1546
1574
|
#openModal() {
|
|
1575
|
+
console.log("[web-apple-pay] #openModal: button clicked", { skuId: this.#offer?.sku_id });
|
|
1547
1576
|
if (!this.#offer || document.querySelector(ApplePayModal.tag)) return;
|
|
1548
1577
|
trackExpressWalletClick(this.#offer.sku_id);
|
|
1549
1578
|
ApplePayModal.define();
|
|
@@ -1557,24 +1586,31 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1557
1586
|
}
|
|
1558
1587
|
async #fetchSession() {
|
|
1559
1588
|
try {
|
|
1560
|
-
|
|
1561
|
-
|
|
1589
|
+
const session = await getExpressCheckoutSession();
|
|
1590
|
+
console.log("[web-apple-pay] #fetchSession: success", { loggedIn: session.loggedIn, userType: session.userType });
|
|
1591
|
+
return session;
|
|
1592
|
+
} catch (err) {
|
|
1593
|
+
console.warn("[web-apple-pay] #fetchSession: failed, falling back to anonymous session", err);
|
|
1562
1594
|
return null;
|
|
1563
1595
|
}
|
|
1564
1596
|
}
|
|
1565
1597
|
async #fetchPaymentOptions() {
|
|
1566
1598
|
try {
|
|
1567
|
-
|
|
1599
|
+
const options = await getPaymentOptions({
|
|
1568
1600
|
sku: this.#offer.sku_id,
|
|
1569
1601
|
countryCode: this.#country,
|
|
1570
1602
|
currencyCode: this.#offer.price?.currency_code ?? DEFAULT_CURRENCY,
|
|
1571
1603
|
checkoutUrl: this.#returnUrl
|
|
1572
1604
|
});
|
|
1573
|
-
|
|
1605
|
+
console.log("[web-apple-pay] #fetchPaymentOptions: success", { hasApplePay: !!options?.options?.apple_pay });
|
|
1606
|
+
return options;
|
|
1607
|
+
} catch (err) {
|
|
1608
|
+
console.warn("[web-apple-pay] #fetchPaymentOptions: failed", err);
|
|
1574
1609
|
return null;
|
|
1575
1610
|
}
|
|
1576
1611
|
}
|
|
1577
1612
|
#buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokens) {
|
|
1613
|
+
console.log("[web-apple-pay] #buildSessionParams", { skuId, country, userLoggedIn: sessionData.loggedIn });
|
|
1578
1614
|
const offer = this.#offer;
|
|
1579
1615
|
const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
|
|
1580
1616
|
return {
|
|
@@ -1597,6 +1633,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1597
1633
|
};
|
|
1598
1634
|
}
|
|
1599
1635
|
async #initiateApplePay(skuId, country) {
|
|
1636
|
+
console.log("[web-apple-pay] #initiateApplePay: starting", { skuId, country });
|
|
1600
1637
|
try {
|
|
1601
1638
|
const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
|
|
1602
1639
|
const paymentOptions = this.#paymentOptions;
|
package/dist/src/index.js
CHANGED
|
@@ -307,7 +307,9 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
307
307
|
this.#country = value;
|
|
308
308
|
}
|
|
309
309
|
connectedCallback() {
|
|
310
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback");
|
|
310
311
|
if (this.querySelector(".apm-overlay")) {
|
|
312
|
+
console.log("[web-apple-pay] ApplePayModal connectedCallback: already rendered, skipping");
|
|
311
313
|
return;
|
|
312
314
|
}
|
|
313
315
|
ensureApplePayLogoSymbol();
|
|
@@ -321,6 +323,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
321
323
|
this.remove();
|
|
322
324
|
return;
|
|
323
325
|
}
|
|
326
|
+
console.log("[web-apple-pay] ApplePayModal: rendering for offer", { skuId: offer.sku_id, country });
|
|
324
327
|
const offerNameElement = this.querySelector(
|
|
325
328
|
"#apple-pay-modal-offer-name"
|
|
326
329
|
);
|
|
@@ -393,11 +396,14 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
393
396
|
});
|
|
394
397
|
}
|
|
395
398
|
cta?.addEventListener("click", () => {
|
|
399
|
+
console.log("[web-apple-pay] ApplePayModal: CTA clicked", { skuId: offer.sku_id, country, isUS });
|
|
396
400
|
if (isUS && checkbox && !checkbox.checked) {
|
|
401
|
+
console.log("[web-apple-pay] ApplePayModal: T&C checkbox not accepted, showing error");
|
|
397
402
|
errorElement?.classList.add("apm__error--visible");
|
|
398
403
|
checkboxLabel?.classList.add("apm__checkbox-label--error");
|
|
399
404
|
return;
|
|
400
405
|
}
|
|
406
|
+
console.log("[web-apple-pay] ApplePayModal: dispatching apple-pay-confirmed", { skuId: offer.sku_id, country });
|
|
401
407
|
this.dispatchEvent(
|
|
402
408
|
new CustomEvent("apple-pay-confirmed", {
|
|
403
409
|
bubbles: true,
|
|
@@ -405,7 +411,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
405
411
|
detail: { skuId: offer.sku_id, country }
|
|
406
412
|
})
|
|
407
413
|
);
|
|
408
|
-
this.close();
|
|
409
414
|
});
|
|
410
415
|
this.querySelector("#apple-pay-modal-close")?.addEventListener(
|
|
411
416
|
"click",
|
|
@@ -413,6 +418,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
413
418
|
);
|
|
414
419
|
}
|
|
415
420
|
open() {
|
|
421
|
+
console.log("[web-apple-pay] ApplePayModal: open()");
|
|
416
422
|
this.#triggerElement = document.activeElement;
|
|
417
423
|
document.body.appendChild(this);
|
|
418
424
|
this.#keyHandler = (event) => {
|
|
@@ -427,6 +433,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
|
|
|
427
433
|
this.querySelector("#apple-pay-modal")?.focus();
|
|
428
434
|
}
|
|
429
435
|
close() {
|
|
436
|
+
console.log("[web-apple-pay] ApplePayModal: close()");
|
|
430
437
|
if (this.#keyHandler) {
|
|
431
438
|
document.removeEventListener("keydown", this.#keyHandler, {
|
|
432
439
|
capture: true
|
|
@@ -1351,11 +1358,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1351
1358
|
* Creates and configures an ApplePayButton if the feature flag is present.
|
|
1352
1359
|
*/
|
|
1353
1360
|
static createIfEnabled(offer, country, entryPoint) {
|
|
1354
|
-
if (!offer)
|
|
1355
|
-
|
|
1361
|
+
if (!offer) {
|
|
1362
|
+
console.log("[web-apple-pay] createIfEnabled: no offer provided \u2192 null");
|
|
1356
1363
|
return null;
|
|
1357
|
-
|
|
1364
|
+
}
|
|
1365
|
+
if (APPLE_PAY_EXCLUDED_VARIANTS.includes(offer.product?.variant)) {
|
|
1366
|
+
console.log("[web-apple-pay] createIfEnabled: excluded variant \u2192 null", { variant: offer.product?.variant });
|
|
1358
1367
|
return null;
|
|
1368
|
+
}
|
|
1369
|
+
if (!new URLSearchParams(window.location.search).has(FEATURE_APPLE_PAY_EXPRESS_CHECKOUT)) {
|
|
1370
|
+
console.log("[web-apple-pay] createIfEnabled: feature flag absent \u2192 null");
|
|
1371
|
+
return null;
|
|
1372
|
+
}
|
|
1373
|
+
console.log("[web-apple-pay] createIfEnabled: creating button", { skuId: offer.sku_id, country, entryPoint });
|
|
1359
1374
|
_ApplePayButton.define();
|
|
1360
1375
|
const button = document.createElement(_ApplePayButton.tag);
|
|
1361
1376
|
button.offer = offer;
|
|
@@ -1423,7 +1438,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1423
1438
|
}
|
|
1424
1439
|
// ─── Lifecycle ──────────────────────────────────────────────────────────────
|
|
1425
1440
|
async connectedCallback() {
|
|
1441
|
+
console.log("[web-apple-pay] connectedCallback: element connected");
|
|
1426
1442
|
if (this.#rendering || this.querySelector(SEL_CONTAINER)) {
|
|
1443
|
+
console.log("[web-apple-pay] connectedCallback: already rendering or rendered, skipping");
|
|
1427
1444
|
return;
|
|
1428
1445
|
}
|
|
1429
1446
|
this.#rendering = true;
|
|
@@ -1450,6 +1467,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1450
1467
|
}
|
|
1451
1468
|
// ─── Render pipeline ────────────────────────────────────────────────────────
|
|
1452
1469
|
async #run() {
|
|
1470
|
+
console.log("[web-apple-pay] #run: starting render pipeline");
|
|
1453
1471
|
try {
|
|
1454
1472
|
if (await this.#checkAvailability()) return;
|
|
1455
1473
|
if (await this.#checkSession()) return;
|
|
@@ -1468,9 +1486,11 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1468
1486
|
async #checkAvailability() {
|
|
1469
1487
|
const available = await isApplePayAvailable();
|
|
1470
1488
|
if (!available) {
|
|
1489
|
+
console.log("[web-apple-pay] #checkAvailability: Apple Pay unavailable \u2192 hiding");
|
|
1471
1490
|
this.style.display = "none";
|
|
1472
1491
|
return true;
|
|
1473
1492
|
}
|
|
1493
|
+
console.log("[web-apple-pay] #checkAvailability: Apple Pay available");
|
|
1474
1494
|
return false;
|
|
1475
1495
|
}
|
|
1476
1496
|
/**
|
|
@@ -1479,7 +1499,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1479
1499
|
*/
|
|
1480
1500
|
async #checkSession() {
|
|
1481
1501
|
this.#sessionData = await this.#fetchSession();
|
|
1502
|
+
console.log("[web-apple-pay] #checkSession: session fetched", { loggedIn: this.#sessionData?.loggedIn, userType: this.#sessionData?.userType });
|
|
1482
1503
|
if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
|
|
1504
|
+
console.log("[web-apple-pay] #checkSession: ineligible user \u2192 hiding", { userType: this.#sessionData.userType });
|
|
1483
1505
|
this.style.display = "none";
|
|
1484
1506
|
return true;
|
|
1485
1507
|
}
|
|
@@ -1488,14 +1510,17 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1488
1510
|
/** Returns `true` (hide) when no offer has been set before mount. */
|
|
1489
1511
|
#checkOffer() {
|
|
1490
1512
|
if (!this.#offer) {
|
|
1513
|
+
console.log("[web-apple-pay] #checkOffer: no offer set \u2192 hiding");
|
|
1491
1514
|
this.style.display = "none";
|
|
1492
1515
|
return true;
|
|
1493
1516
|
}
|
|
1517
|
+
console.log("[web-apple-pay] #checkOffer: offer present", { skuId: this.#offer.sku_id });
|
|
1494
1518
|
return false;
|
|
1495
1519
|
}
|
|
1496
1520
|
/** Captures the current page URL once at mount for reuse across the session lifetime. */
|
|
1497
1521
|
#captureReturnUrl() {
|
|
1498
1522
|
this.#returnUrl = captureOriginUrl();
|
|
1523
|
+
console.log("[web-apple-pay] #captureReturnUrl:", this.#returnUrl);
|
|
1499
1524
|
}
|
|
1500
1525
|
/**
|
|
1501
1526
|
* Computes supported billing countries once at mount.
|
|
@@ -1507,6 +1532,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1507
1532
|
this.#country,
|
|
1508
1533
|
this.#offer.product?.variant ?? ""
|
|
1509
1534
|
);
|
|
1535
|
+
console.log("[web-apple-pay] #computeBillingCountries:", this.#supportedBillingCountries);
|
|
1510
1536
|
}
|
|
1511
1537
|
/**
|
|
1512
1538
|
* Returns `true` (hide) when the wallet BFF reports Apple Pay is unavailable
|
|
@@ -1516,6 +1542,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1516
1542
|
this.#paymentOptions = await this.#fetchPaymentOptions();
|
|
1517
1543
|
console.log("[web-apple-pay] #fetchAndCacheOptions: fetched payment options", { paymentOptions: this.#paymentOptions });
|
|
1518
1544
|
if (!this.#paymentOptions?.options?.apple_pay) {
|
|
1545
|
+
console.log("[web-apple-pay] #fetchAndCacheOptions: apple_pay not in options \u2192 hiding");
|
|
1519
1546
|
this.style.display = "none";
|
|
1520
1547
|
return true;
|
|
1521
1548
|
}
|
|
@@ -1523,6 +1550,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1523
1550
|
}
|
|
1524
1551
|
/** Injects the button template and wires click and confirm event listeners. */
|
|
1525
1552
|
#renderTemplate() {
|
|
1553
|
+
console.log("[web-apple-pay] #renderTemplate: rendering Apple Pay button", { skuId: this.#offer?.sku_id, country: this.#country });
|
|
1526
1554
|
this.style.removeProperty("display");
|
|
1527
1555
|
ensureApplePayLogoSymbol();
|
|
1528
1556
|
const template = document.createElement("template");
|
|
@@ -1555,6 +1583,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1555
1583
|
button.setAttribute("aria-disabled", "true");
|
|
1556
1584
|
}
|
|
1557
1585
|
#openModal() {
|
|
1586
|
+
console.log("[web-apple-pay] #openModal: button clicked", { skuId: this.#offer?.sku_id });
|
|
1558
1587
|
if (!this.#offer || document.querySelector(ApplePayModal.tag)) return;
|
|
1559
1588
|
trackExpressWalletClick(this.#offer.sku_id);
|
|
1560
1589
|
ApplePayModal.define();
|
|
@@ -1568,24 +1597,31 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1568
1597
|
}
|
|
1569
1598
|
async #fetchSession() {
|
|
1570
1599
|
try {
|
|
1571
|
-
|
|
1572
|
-
|
|
1600
|
+
const session = await getExpressCheckoutSession();
|
|
1601
|
+
console.log("[web-apple-pay] #fetchSession: success", { loggedIn: session.loggedIn, userType: session.userType });
|
|
1602
|
+
return session;
|
|
1603
|
+
} catch (err) {
|
|
1604
|
+
console.warn("[web-apple-pay] #fetchSession: failed, falling back to anonymous session", err);
|
|
1573
1605
|
return null;
|
|
1574
1606
|
}
|
|
1575
1607
|
}
|
|
1576
1608
|
async #fetchPaymentOptions() {
|
|
1577
1609
|
try {
|
|
1578
|
-
|
|
1610
|
+
const options = await getPaymentOptions({
|
|
1579
1611
|
sku: this.#offer.sku_id,
|
|
1580
1612
|
countryCode: this.#country,
|
|
1581
1613
|
currencyCode: this.#offer.price?.currency_code ?? DEFAULT_CURRENCY,
|
|
1582
1614
|
checkoutUrl: this.#returnUrl
|
|
1583
1615
|
});
|
|
1584
|
-
|
|
1616
|
+
console.log("[web-apple-pay] #fetchPaymentOptions: success", { hasApplePay: !!options?.options?.apple_pay });
|
|
1617
|
+
return options;
|
|
1618
|
+
} catch (err) {
|
|
1619
|
+
console.warn("[web-apple-pay] #fetchPaymentOptions: failed", err);
|
|
1585
1620
|
return null;
|
|
1586
1621
|
}
|
|
1587
1622
|
}
|
|
1588
1623
|
#buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokens) {
|
|
1624
|
+
console.log("[web-apple-pay] #buildSessionParams", { skuId, country, userLoggedIn: sessionData.loggedIn });
|
|
1589
1625
|
const offer = this.#offer;
|
|
1590
1626
|
const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
|
|
1591
1627
|
return {
|
|
@@ -1608,6 +1644,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
|
|
|
1608
1644
|
};
|
|
1609
1645
|
}
|
|
1610
1646
|
async #initiateApplePay(skuId, country) {
|
|
1647
|
+
console.log("[web-apple-pay] #initiateApplePay: starting", { skuId, country });
|
|
1611
1648
|
try {
|
|
1612
1649
|
const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
|
|
1613
1650
|
const paymentOptions = this.#paymentOptions;
|
package/package.json
CHANGED