@paypercut/checkout-js 1.2.5 → 1.2.9
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.cjs +148 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +148 -1
- package/dist/index.mjs.map +1 -1
- package/dist/paypercut-checkout.iife.min.js +1 -1
- package/dist/paypercut-checkout.iife.min.js.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -87,7 +87,7 @@ class Emitter {
|
|
|
87
87
|
* Production configuration (for merchants)
|
|
88
88
|
*/
|
|
89
89
|
const productionConfig = {
|
|
90
|
-
version: "1.2.
|
|
90
|
+
version: "1.2.9",
|
|
91
91
|
defaultCheckoutOrigin: 'https://buy.paypercut.io',
|
|
92
92
|
defaultApiOrigin: 'https://api.paypercut.io',
|
|
93
93
|
defaultVaultApiUrl: 'https://api.basistheory.com',
|
|
@@ -528,6 +528,19 @@ var SdkEvent;
|
|
|
528
528
|
SdkEvent["Cancel"] = "cancel";
|
|
529
529
|
SdkEvent["FormValidation"] = "form_validation";
|
|
530
530
|
})(SdkEvent || (SdkEvent = {}));
|
|
531
|
+
// Apple Pay bridge message names — wire format shared with hosted-checkout's CheckoutMessageType enum.
|
|
532
|
+
// Defined here as a const so the switch in index.ts is compile-checked within this repo.
|
|
533
|
+
// If a message name changes in hosted-checkout, update this map and the switch together.
|
|
534
|
+
const ApplePayBridgeMsg = {
|
|
535
|
+
START: 'APPLE_PAY_START',
|
|
536
|
+
VALIDATE_MERCHANT: 'APPLE_PAY_VALIDATE_MERCHANT',
|
|
537
|
+
MERCHANT_SESSION: 'APPLE_PAY_MERCHANT_SESSION',
|
|
538
|
+
MERCHANT_ERROR: 'APPLE_PAY_MERCHANT_ERROR',
|
|
539
|
+
PAYMENT_DATA: 'APPLE_PAY_PAYMENT_DATA',
|
|
540
|
+
PAYMENT_RESULT: 'APPLE_PAY_PAYMENT_RESULT',
|
|
541
|
+
CANCELLED: 'APPLE_PAY_CANCELLED',
|
|
542
|
+
SESSION_ERROR: 'APPLE_PAY_SESSION_ERROR',
|
|
543
|
+
};
|
|
531
544
|
|
|
532
545
|
// ─── Locale ───────────────────────────────────────────────────────────────────
|
|
533
546
|
/**
|
|
@@ -2009,6 +2022,30 @@ const PaypercutExpressCheckout = function (options) {
|
|
|
2009
2022
|
return new ExpressCheckoutImpl(options);
|
|
2010
2023
|
};
|
|
2011
2024
|
|
|
2025
|
+
// ── Apple Pay SDK loader ──────────────────────────────────────────────────────
|
|
2026
|
+
// Tracks whether the Apple Pay CDN script has already been injected so multiple
|
|
2027
|
+
// CheckoutImpl instances don't race to add it more than once.
|
|
2028
|
+
let _applePaySdkInjected = false;
|
|
2029
|
+
/**
|
|
2030
|
+
* Injects Apple's cross-browser Apple Pay JS SDK into the parent page so that
|
|
2031
|
+
* window.ApplePaySession is available when the embedded bridge delegates session
|
|
2032
|
+
* creation here. On Safari, ApplePaySession is a browser built-in and the script
|
|
2033
|
+
* is a no-op; on Chrome it provides the iCloud Keychain integration.
|
|
2034
|
+
*/
|
|
2035
|
+
function ensureApplePaySdk() {
|
|
2036
|
+
if (typeof window === 'undefined')
|
|
2037
|
+
return;
|
|
2038
|
+
if (window.ApplePaySession)
|
|
2039
|
+
return;
|
|
2040
|
+
if (_applePaySdkInjected)
|
|
2041
|
+
return;
|
|
2042
|
+
_applePaySdkInjected = true;
|
|
2043
|
+
const s = document.createElement('script');
|
|
2044
|
+
s.src = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';
|
|
2045
|
+
s.crossOrigin = 'anonymous';
|
|
2046
|
+
s.async = true;
|
|
2047
|
+
document.head.appendChild(s);
|
|
2048
|
+
}
|
|
2012
2049
|
// ── Appearance validation ─────────────────────────────────────────────────────
|
|
2013
2050
|
const _HEX_RE = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
2014
2051
|
const _CSS_LEN_RE = /^(0|(\d+(\.\d+)?(px|rem|em)))$/;
|
|
@@ -2043,6 +2080,9 @@ class CheckoutImpl {
|
|
|
2043
2080
|
this.mounted = false;
|
|
2044
2081
|
this.destroyed = false;
|
|
2045
2082
|
this.iframe = null;
|
|
2083
|
+
// Apple Pay bridge state (embedded mode only)
|
|
2084
|
+
this.applePaySession = null;
|
|
2085
|
+
this.applePayBridgeTimeout = null;
|
|
2046
2086
|
// Bind message handler
|
|
2047
2087
|
this.messageHandler = this.onMessage.bind(this);
|
|
2048
2088
|
this.threeDSModal = new ThreeDSModalController({
|
|
@@ -2052,6 +2092,10 @@ class CheckoutImpl {
|
|
|
2052
2092
|
onReady: (iframe) => this.postThreeDSInit(iframe),
|
|
2053
2093
|
});
|
|
2054
2094
|
window.addEventListener('message', this.messageHandler);
|
|
2095
|
+
// In embedded mode the Apple Pay bridge delegates ApplePaySession creation to this parent window.
|
|
2096
|
+
if (validateUIMode(options.ui_mode ?? UIMode.EMBEDDED) === UIMode.EMBEDDED) {
|
|
2097
|
+
ensureApplePaySdk();
|
|
2098
|
+
}
|
|
2055
2099
|
}
|
|
2056
2100
|
/**
|
|
2057
2101
|
* Build the iframe source URL with query parameters
|
|
@@ -2210,6 +2254,18 @@ class CheckoutImpl {
|
|
|
2210
2254
|
wallet: data.wallet,
|
|
2211
2255
|
});
|
|
2212
2256
|
break;
|
|
2257
|
+
case ApplePayBridgeMsg.START:
|
|
2258
|
+
this.handleApplePayStart(data);
|
|
2259
|
+
break;
|
|
2260
|
+
case ApplePayBridgeMsg.MERCHANT_SESSION:
|
|
2261
|
+
this.handleApplePayMerchantSession(data.merchantSession);
|
|
2262
|
+
break;
|
|
2263
|
+
case ApplePayBridgeMsg.MERCHANT_ERROR:
|
|
2264
|
+
this.abortApplePaySession();
|
|
2265
|
+
break;
|
|
2266
|
+
case ApplePayBridgeMsg.PAYMENT_RESULT:
|
|
2267
|
+
this.handleApplePayPaymentResult(data.success === true);
|
|
2268
|
+
break;
|
|
2213
2269
|
}
|
|
2214
2270
|
}
|
|
2215
2271
|
/**
|
|
@@ -2333,6 +2389,95 @@ class CheckoutImpl {
|
|
|
2333
2389
|
checkoutId: this.options.id,
|
|
2334
2390
|
}, checkoutOrigin);
|
|
2335
2391
|
}
|
|
2392
|
+
// ---------------------------------------------------------------------------
|
|
2393
|
+
// Apple Pay bridge
|
|
2394
|
+
// ---------------------------------------------------------------------------
|
|
2395
|
+
/**
|
|
2396
|
+
* Called when the embedded iframe requests that we create an ApplePaySession at the
|
|
2397
|
+
* top-level window so the payment sheet / QR popup is not clipped by the container.
|
|
2398
|
+
*/
|
|
2399
|
+
handleApplePayStart(data) {
|
|
2400
|
+
this.abortApplePaySession();
|
|
2401
|
+
const ApplePayAPI = window.ApplePaySession;
|
|
2402
|
+
if (!ApplePayAPI) {
|
|
2403
|
+
this.postToIframe({ type: ApplePayBridgeMsg.SESSION_ERROR, checkoutId: this.options.id });
|
|
2404
|
+
return;
|
|
2405
|
+
}
|
|
2406
|
+
const version = ApplePayAPI.supportsVersion?.(14) ? 14 : 3;
|
|
2407
|
+
let session;
|
|
2408
|
+
try {
|
|
2409
|
+
session = new ApplePayAPI(version, data.request);
|
|
2410
|
+
}
|
|
2411
|
+
catch (e) {
|
|
2412
|
+
console.error(e?.name === 'SecurityError'
|
|
2413
|
+
? '[PaypercutCheckout] Apple Pay blocked — parent page missing allow="payment" on iframe'
|
|
2414
|
+
: '[PaypercutCheckout] Failed to create ApplePaySession', e);
|
|
2415
|
+
this.postToIframe({ type: ApplePayBridgeMsg.SESSION_ERROR, checkoutId: this.options.id });
|
|
2416
|
+
return;
|
|
2417
|
+
}
|
|
2418
|
+
this.applePaySession = session;
|
|
2419
|
+
session.onvalidatemerchant = (event) => {
|
|
2420
|
+
// If the iframe doesn't respond within 15 s, abort — Apple's own timeout is ~30 s
|
|
2421
|
+
// and we need to clean up the ref before that fires.
|
|
2422
|
+
this.applePayBridgeTimeout = setTimeout(() => this.abortApplePaySession(), 15000);
|
|
2423
|
+
this.postToIframe({
|
|
2424
|
+
type: ApplePayBridgeMsg.VALIDATE_MERCHANT,
|
|
2425
|
+
checkoutId: this.options.id,
|
|
2426
|
+
validationURL: event.validationURL,
|
|
2427
|
+
});
|
|
2428
|
+
};
|
|
2429
|
+
session.onpaymentauthorized = (event) => {
|
|
2430
|
+
this.postToIframe({
|
|
2431
|
+
type: ApplePayBridgeMsg.PAYMENT_DATA,
|
|
2432
|
+
checkoutId: this.options.id,
|
|
2433
|
+
payment: event.payment,
|
|
2434
|
+
});
|
|
2435
|
+
};
|
|
2436
|
+
session.oncancel = () => {
|
|
2437
|
+
this.applePaySession = null;
|
|
2438
|
+
this.postToIframe({ type: ApplePayBridgeMsg.CANCELLED, checkoutId: this.options.id });
|
|
2439
|
+
};
|
|
2440
|
+
session.begin();
|
|
2441
|
+
}
|
|
2442
|
+
handleApplePayMerchantSession(merchantSession) {
|
|
2443
|
+
if (this.applePayBridgeTimeout) {
|
|
2444
|
+
clearTimeout(this.applePayBridgeTimeout);
|
|
2445
|
+
this.applePayBridgeTimeout = null;
|
|
2446
|
+
}
|
|
2447
|
+
if (!this.applePaySession)
|
|
2448
|
+
return;
|
|
2449
|
+
try {
|
|
2450
|
+
this.applePaySession.completeMerchantValidation(merchantSession);
|
|
2451
|
+
}
|
|
2452
|
+
catch (e) {
|
|
2453
|
+
console.error('[PaypercutCheckout] completeMerchantValidation failed', e);
|
|
2454
|
+
this.abortApplePaySession();
|
|
2455
|
+
this.postToIframe({ type: ApplePayBridgeMsg.SESSION_ERROR, checkoutId: this.options.id });
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
handleApplePayPaymentResult(success) {
|
|
2459
|
+
if (!this.applePaySession)
|
|
2460
|
+
return;
|
|
2461
|
+
const ApplePayAPI = window.ApplePaySession;
|
|
2462
|
+
try {
|
|
2463
|
+
this.applePaySession.completePayment(success ? ApplePayAPI.STATUS_SUCCESS : ApplePayAPI.STATUS_FAILURE);
|
|
2464
|
+
}
|
|
2465
|
+
catch (e) {
|
|
2466
|
+
console.error('[PaypercutCheckout] completePayment failed', e);
|
|
2467
|
+
}
|
|
2468
|
+
this.applePaySession = null;
|
|
2469
|
+
}
|
|
2470
|
+
abortApplePaySession() {
|
|
2471
|
+
if (this.applePayBridgeTimeout) {
|
|
2472
|
+
clearTimeout(this.applePayBridgeTimeout);
|
|
2473
|
+
this.applePayBridgeTimeout = null;
|
|
2474
|
+
}
|
|
2475
|
+
try {
|
|
2476
|
+
this.applePaySession?.abort();
|
|
2477
|
+
}
|
|
2478
|
+
catch { }
|
|
2479
|
+
this.applePaySession = null;
|
|
2480
|
+
}
|
|
2336
2481
|
/**
|
|
2337
2482
|
* Destroy the checkout instance and cleanup (idempotent)
|
|
2338
2483
|
*/
|
|
@@ -2353,6 +2498,8 @@ class CheckoutImpl {
|
|
|
2353
2498
|
}
|
|
2354
2499
|
// Cleanup 3DS modal if open
|
|
2355
2500
|
this.threeDSModal.close();
|
|
2501
|
+
// Abort Apple Pay session if active
|
|
2502
|
+
this.abortApplePaySession();
|
|
2356
2503
|
// Only set mounted = false after successful DOM removal
|
|
2357
2504
|
this.mounted = false;
|
|
2358
2505
|
this.destroyed = true;
|