@paypercut/checkout-js 1.1.0 → 1.1.8
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 +145 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +145 -31
- 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 +1 -1
package/dist/index.cjs
CHANGED
|
@@ -91,7 +91,7 @@ class Emitter {
|
|
|
91
91
|
* Production configuration (for merchants)
|
|
92
92
|
*/
|
|
93
93
|
const productionConfig = {
|
|
94
|
-
version: "1.1.
|
|
94
|
+
version: "1.1.8",
|
|
95
95
|
defaultCheckoutOrigin: 'https://buy.paypercut.io',
|
|
96
96
|
defaultApiOrigin: 'https://api.paypercut.io',
|
|
97
97
|
defaultVaultApiUrl: 'https://api.basistheory.com',
|
|
@@ -488,6 +488,9 @@ class ExpressCheckoutImpl {
|
|
|
488
488
|
// 3DS modal — same pattern as CheckoutImpl
|
|
489
489
|
this.threeDSModal = null;
|
|
490
490
|
this.threeDSIframe = null;
|
|
491
|
+
// Pending 3DS data captured during THREEDS_START_FLOW while GPay sheet is still closing.
|
|
492
|
+
// Shown after loadPaymentData() resolves
|
|
493
|
+
this.pending3DSAfterGpay = null;
|
|
491
494
|
// Apple Pay native session state — session created directly in the SDK window
|
|
492
495
|
// on the merchant's registered domain.
|
|
493
496
|
this.applePaySession = null;
|
|
@@ -507,6 +510,10 @@ class ExpressCheckoutImpl {
|
|
|
507
510
|
// Pending Google Pay payment data waiting for tokenization response
|
|
508
511
|
this.pendingGpayResolve = null;
|
|
509
512
|
this.pendingGpayReject = null;
|
|
513
|
+
// Stored GPay metadata for use when TOKENIZE_RESPONSE arrives after 3DS (sheet already closed)
|
|
514
|
+
this.pendingGpayBillingDetails = null;
|
|
515
|
+
this.pendingGpayShippingDetails = null;
|
|
516
|
+
this.pendingGpayShippingOption = undefined;
|
|
510
517
|
this.currentShippingOptions = options.shippingOptions ?? [];
|
|
511
518
|
this.messageHandler = this.onMessage.bind(this);
|
|
512
519
|
window.addEventListener('message', this.messageHandler);
|
|
@@ -548,10 +555,10 @@ class ExpressCheckoutImpl {
|
|
|
548
555
|
googlePayStatus,
|
|
549
556
|
applePayStatus: data.payment_domain?.wallets?.apple_pay?.status ?? 'inactive',
|
|
550
557
|
displayName: data.merchant?.name ?? '',
|
|
551
|
-
merchantMid: data.
|
|
552
|
-
merchantMcc: data.
|
|
553
|
-
merchantCountry: data.
|
|
554
|
-
merchantUrl: data.
|
|
558
|
+
merchantMid: data.merchant?.mid ?? '',
|
|
559
|
+
merchantMcc: data.merchant?.mcc ?? '',
|
|
560
|
+
merchantCountry: data.merchant?.country ?? '',
|
|
561
|
+
merchantUrl: data.merchant?.business_url ?? '',
|
|
555
562
|
};
|
|
556
563
|
}
|
|
557
564
|
catch (err) {
|
|
@@ -562,7 +569,7 @@ class ExpressCheckoutImpl {
|
|
|
562
569
|
// postMessage handler
|
|
563
570
|
onMessage(evt) {
|
|
564
571
|
if (!isOriginAllowed(evt.origin)) {
|
|
565
|
-
if (evt.origin.includes('localhost')
|
|
572
|
+
if (evt.origin.includes('localhost')) {
|
|
566
573
|
console.warn('[PaypercutExpressCheckout] Message blocked — origin not allowed:', evt.origin);
|
|
567
574
|
}
|
|
568
575
|
return;
|
|
@@ -617,20 +624,82 @@ class ExpressCheckoutImpl {
|
|
|
617
624
|
}
|
|
618
625
|
}
|
|
619
626
|
else {
|
|
620
|
-
// Google Pay
|
|
627
|
+
// Google Pay
|
|
621
628
|
if (data.success) {
|
|
622
|
-
this.pendingGpayResolve
|
|
629
|
+
if (this.pendingGpayResolve) {
|
|
630
|
+
// Normal path (no 3DS): resolve and let handleGooglePayAuthorized create PM
|
|
631
|
+
this.pendingGpayResolve(data);
|
|
632
|
+
this.pendingGpayResolve = null;
|
|
633
|
+
this.pendingGpayReject = null;
|
|
634
|
+
}
|
|
635
|
+
else {
|
|
636
|
+
// Post-3DS path: sheet was already closed — create PM directly, same as Apple Pay
|
|
637
|
+
this.createPaymentMethod({
|
|
638
|
+
btTokenId: data.btTokenId,
|
|
639
|
+
cardPayload: data.cardPayload,
|
|
640
|
+
billingDetails: data.billingDetails,
|
|
641
|
+
csessId: data.csessId,
|
|
642
|
+
walletType: 'google_pay',
|
|
643
|
+
}).then((paymentMethodId) => {
|
|
644
|
+
this.emitter.emit(exports.ExpressSdkEvent.PaymentMethodCreated, {
|
|
645
|
+
paymentMethodId,
|
|
646
|
+
wallet: 'google_pay',
|
|
647
|
+
billingDetails: this.pendingGpayBillingDetails ?? undefined,
|
|
648
|
+
shippingDetails: this.pendingGpayShippingDetails ?? undefined,
|
|
649
|
+
selectedShippingOption: this.pendingGpayShippingOption,
|
|
650
|
+
});
|
|
651
|
+
}).catch((err) => {
|
|
652
|
+
this.emitter.emit(exports.ExpressSdkEvent.Error, new Error(err?.message ?? 'Payment method creation failed'));
|
|
653
|
+
this.emitter.emit(exports.ExpressSdkEvent.PaymentMethodFailed, { error: err?.message ?? 'Payment method creation failed' });
|
|
654
|
+
}).finally(() => {
|
|
655
|
+
this.pendingGpayBillingDetails = null;
|
|
656
|
+
this.pendingGpayShippingDetails = null;
|
|
657
|
+
this.pendingGpayShippingOption = undefined;
|
|
658
|
+
});
|
|
659
|
+
}
|
|
623
660
|
}
|
|
624
661
|
else {
|
|
625
|
-
this.pendingGpayReject
|
|
662
|
+
if (this.pendingGpayReject) {
|
|
663
|
+
// Normal path (no 3DS): reject the pending promise in handleGooglePayAuthorized
|
|
664
|
+
this.pendingGpayReject(new Error(data.error ?? 'Tokenization failed'));
|
|
665
|
+
this.pendingGpayResolve = null;
|
|
666
|
+
this.pendingGpayReject = null;
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
// Post-3DS path: sheet already closed — emit events directly.
|
|
670
|
+
// Distinguish user cancellation from an actual error so integrators
|
|
671
|
+
// can handle them differently (e.g. "cancel" = re-show checkout,
|
|
672
|
+
// "error" = show an error message).
|
|
673
|
+
const errMsg = data.error ?? 'Google Pay payment failed';
|
|
674
|
+
const isCanceled = errMsg.toLowerCase().includes('cancel');
|
|
675
|
+
if (isCanceled) {
|
|
676
|
+
this.emitter.emit(exports.ExpressSdkEvent.Cancel);
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
this.emitter.emit(exports.ExpressSdkEvent.Error, new Error(errMsg));
|
|
680
|
+
this.emitter.emit(exports.ExpressSdkEvent.PaymentMethodFailed, { error: errMsg });
|
|
681
|
+
}
|
|
682
|
+
this.pendingGpayBillingDetails = null;
|
|
683
|
+
this.pendingGpayShippingDetails = null;
|
|
684
|
+
this.pendingGpayShippingOption = undefined;
|
|
685
|
+
}
|
|
626
686
|
}
|
|
627
|
-
this.pendingGpayResolve = null;
|
|
628
|
-
this.pendingGpayReject = null;
|
|
629
687
|
}
|
|
630
688
|
break;
|
|
631
|
-
// 3DS flow
|
|
689
|
+
// 3DS flow
|
|
632
690
|
case 'THREEDS_START_FLOW':
|
|
633
|
-
|
|
691
|
+
// Google Pay sheet is a native browser UI that cannot be overlaid by DOM elements.
|
|
692
|
+
// Resolve the pending GPay promise so GPay starts closing its sheet.
|
|
693
|
+
if (this.pendingGpayResolve) {
|
|
694
|
+
this.pending3DSAfterGpay = data;
|
|
695
|
+
this.pendingGpayResolve({ __closeSheet: true });
|
|
696
|
+
this.pendingGpayResolve = null;
|
|
697
|
+
this.pendingGpayReject = null;
|
|
698
|
+
}
|
|
699
|
+
else {
|
|
700
|
+
// Apple Pay or any path without a pending GPay sheet — show immediately
|
|
701
|
+
this.show3DSModal(data);
|
|
702
|
+
}
|
|
634
703
|
break;
|
|
635
704
|
case 'THREEDS_READY':
|
|
636
705
|
this.handle3DSReady();
|
|
@@ -725,6 +794,10 @@ class ExpressCheckoutImpl {
|
|
|
725
794
|
if (showApplePay && this.applePayContainer && config?.applePayStatus === 'active') {
|
|
726
795
|
await this.mountApplePayButton(this.applePayContainer);
|
|
727
796
|
}
|
|
797
|
+
else if (this.applePayContainer) {
|
|
798
|
+
// Apple Pay can't mount — remove its container so the remaining button fills full width
|
|
799
|
+
this.removeApplePayContainer();
|
|
800
|
+
}
|
|
728
801
|
if (showGooglePay && config) {
|
|
729
802
|
this.mountGooglePayFromConfig();
|
|
730
803
|
}
|
|
@@ -1141,6 +1214,15 @@ class ExpressCheckoutImpl {
|
|
|
1141
1214
|
* Called after config is fetched. Waits for the GPay script to finish loading,
|
|
1142
1215
|
* then mounts the button.
|
|
1143
1216
|
*/
|
|
1217
|
+
removeGpayContainer() {
|
|
1218
|
+
this.gpayContainer?.remove();
|
|
1219
|
+
this.gpayContainer = null;
|
|
1220
|
+
}
|
|
1221
|
+
removeApplePayContainer() {
|
|
1222
|
+
this.applePayContainer?.remove();
|
|
1223
|
+
this.applePayContainer = null;
|
|
1224
|
+
this.applePayButtonEl = null;
|
|
1225
|
+
}
|
|
1144
1226
|
mountGooglePayFromConfig() {
|
|
1145
1227
|
const config = this.expressConfig;
|
|
1146
1228
|
if (!config)
|
|
@@ -1151,10 +1233,18 @@ class ExpressCheckoutImpl {
|
|
|
1151
1233
|
const merchantName = config.displayName || 'Checkout';
|
|
1152
1234
|
if (!tenantId) {
|
|
1153
1235
|
console.error('[PaypercutExpressCheckout] tenantId is empty — Google Pay cannot be mounted without a valid gatewayMerchantId.');
|
|
1236
|
+
this.removeGpayContainer();
|
|
1154
1237
|
return;
|
|
1155
1238
|
}
|
|
1156
1239
|
if (!googlePayMerchantId) {
|
|
1157
1240
|
console.warn('[PaypercutExpressCheckout] googlePayMerchantId is empty — Google Pay will not be mounted (merchant may not have Google Pay active).');
|
|
1241
|
+
this.removeGpayContainer();
|
|
1242
|
+
return;
|
|
1243
|
+
}
|
|
1244
|
+
console.log({ liveMode });
|
|
1245
|
+
if (liveMode && (!config.merchantMcc || !config.merchantUrl)) {
|
|
1246
|
+
console.warn('[PaypercutExpressCheckout] Google Pay disabled!');
|
|
1247
|
+
this.removeGpayContainer();
|
|
1158
1248
|
return;
|
|
1159
1249
|
}
|
|
1160
1250
|
loadGooglePayScript().then(() => {
|
|
@@ -1317,6 +1407,12 @@ class ExpressCheckoutImpl {
|
|
|
1317
1407
|
}
|
|
1318
1408
|
try {
|
|
1319
1409
|
await this.gpayClient.loadPaymentData(paymentRequest);
|
|
1410
|
+
// If 3DS was triggered, the GPay sheet is now fully dismissed — show the challenge modal.
|
|
1411
|
+
if (this.pending3DSAfterGpay) {
|
|
1412
|
+
const threeDSData = this.pending3DSAfterGpay;
|
|
1413
|
+
this.pending3DSAfterGpay = null;
|
|
1414
|
+
this.show3DSModal(threeDSData);
|
|
1415
|
+
}
|
|
1320
1416
|
}
|
|
1321
1417
|
catch (e) {
|
|
1322
1418
|
if (e?.statusCode === 'CANCELED' || e?.message?.toLowerCase?.().includes('cancel')) {
|
|
@@ -1333,6 +1429,7 @@ class ExpressCheckoutImpl {
|
|
|
1333
1429
|
async handleGooglePayAuthorized(paymentData) {
|
|
1334
1430
|
try {
|
|
1335
1431
|
const encryptedToken = paymentData.paymentMethodData.tokenizationData.token;
|
|
1432
|
+
const cardNetwork = paymentData.paymentMethodData?.info?.cardNetwork ?? '';
|
|
1336
1433
|
const billingAddr = paymentData.paymentMethodData?.info?.billingAddress;
|
|
1337
1434
|
const shippingAddr = paymentData.shippingAddress;
|
|
1338
1435
|
const shippingOptionData = paymentData.shippingOptionData;
|
|
@@ -1346,6 +1443,27 @@ class ExpressCheckoutImpl {
|
|
|
1346
1443
|
country: billingAddr.countryCode,
|
|
1347
1444
|
},
|
|
1348
1445
|
} : null;
|
|
1446
|
+
const shippingDetails = shippingAddr ? {
|
|
1447
|
+
name: shippingAddr.name || undefined,
|
|
1448
|
+
address: {
|
|
1449
|
+
line1: shippingAddr.address1,
|
|
1450
|
+
city: shippingAddr.locality,
|
|
1451
|
+
state: shippingAddr.administrativeArea,
|
|
1452
|
+
postalCode: shippingAddr.postalCode,
|
|
1453
|
+
country: shippingAddr.countryCode,
|
|
1454
|
+
},
|
|
1455
|
+
} : undefined;
|
|
1456
|
+
const selectedShippingOption = shippingOptionData
|
|
1457
|
+
? (this.currentShippingOptions.find((so) => so.id === shippingOptionData.id) ?? {
|
|
1458
|
+
id: shippingOptionData.id,
|
|
1459
|
+
label: shippingOptionData.label ?? shippingOptionData.id,
|
|
1460
|
+
amount: 0,
|
|
1461
|
+
})
|
|
1462
|
+
: undefined;
|
|
1463
|
+
// Store metadata upfront — needed if 3DS triggers and the sheet closes before TOKENIZE_RESPONSE
|
|
1464
|
+
this.pendingGpayBillingDetails = billingDetails;
|
|
1465
|
+
this.pendingGpayShippingDetails = shippingDetails;
|
|
1466
|
+
this.pendingGpayShippingOption = selectedShippingOption;
|
|
1349
1467
|
// Send to hidden tokenize iframe — it will BT-tokenize + create the payment method
|
|
1350
1468
|
const tokenResult = await new Promise((resolve, reject) => {
|
|
1351
1469
|
const timeoutId = setTimeout(() => {
|
|
@@ -1360,6 +1478,7 @@ class ExpressCheckoutImpl {
|
|
|
1360
1478
|
instanceId: this.instanceId,
|
|
1361
1479
|
wallet: 'google_pay',
|
|
1362
1480
|
encryptedToken,
|
|
1481
|
+
cardNetwork,
|
|
1363
1482
|
idemKey: this.idempotencyKey,
|
|
1364
1483
|
publishableKey: this.options.publishableKey,
|
|
1365
1484
|
billingDetails,
|
|
@@ -1374,6 +1493,10 @@ class ExpressCheckoutImpl {
|
|
|
1374
1493
|
},
|
|
1375
1494
|
});
|
|
1376
1495
|
});
|
|
1496
|
+
// 3DS was triggered — sheet already closed, payment method creation handled in message handler
|
|
1497
|
+
if (tokenResult.__closeSheet) {
|
|
1498
|
+
return { transactionState: 'SUCCESS' };
|
|
1499
|
+
}
|
|
1377
1500
|
if (!tokenResult.success) {
|
|
1378
1501
|
const errMsg = tokenResult.error ?? 'Tokenization failed';
|
|
1379
1502
|
this.emitter.emit(exports.ExpressSdkEvent.Error, new Error(errMsg));
|
|
@@ -1387,23 +1510,6 @@ class ExpressCheckoutImpl {
|
|
|
1387
1510
|
csessId: tokenResult.csessId,
|
|
1388
1511
|
walletType: 'google_pay',
|
|
1389
1512
|
});
|
|
1390
|
-
const selectedShippingOption = shippingOptionData
|
|
1391
|
-
? (this.currentShippingOptions.find((so) => so.id === shippingOptionData.id) ?? {
|
|
1392
|
-
id: shippingOptionData.id,
|
|
1393
|
-
label: shippingOptionData.label ?? shippingOptionData.id,
|
|
1394
|
-
amount: 0,
|
|
1395
|
-
})
|
|
1396
|
-
: undefined;
|
|
1397
|
-
const shippingDetails = shippingAddr ? {
|
|
1398
|
-
name: shippingAddr.name || undefined,
|
|
1399
|
-
address: {
|
|
1400
|
-
line1: shippingAddr.address1,
|
|
1401
|
-
city: shippingAddr.locality,
|
|
1402
|
-
state: shippingAddr.administrativeArea,
|
|
1403
|
-
postalCode: shippingAddr.postalCode,
|
|
1404
|
-
country: shippingAddr.countryCode,
|
|
1405
|
-
},
|
|
1406
|
-
} : undefined;
|
|
1407
1513
|
this.emitter.emit(exports.ExpressSdkEvent.PaymentMethodCreated, {
|
|
1408
1514
|
paymentMethodId,
|
|
1409
1515
|
wallet: 'google_pay',
|
|
@@ -1411,6 +1517,9 @@ class ExpressCheckoutImpl {
|
|
|
1411
1517
|
shippingDetails,
|
|
1412
1518
|
selectedShippingOption,
|
|
1413
1519
|
});
|
|
1520
|
+
this.pendingGpayBillingDetails = null;
|
|
1521
|
+
this.pendingGpayShippingDetails = null;
|
|
1522
|
+
this.pendingGpayShippingOption = undefined;
|
|
1414
1523
|
return { transactionState: 'SUCCESS' };
|
|
1415
1524
|
}
|
|
1416
1525
|
catch (err) {
|
|
@@ -1505,7 +1614,12 @@ class ExpressCheckoutImpl {
|
|
|
1505
1614
|
catch { }
|
|
1506
1615
|
this.gpayContainer = null;
|
|
1507
1616
|
}
|
|
1508
|
-
this.
|
|
1617
|
+
if (this.applePayContainer) {
|
|
1618
|
+
try {
|
|
1619
|
+
this.removeApplePayContainer();
|
|
1620
|
+
}
|
|
1621
|
+
catch { }
|
|
1622
|
+
}
|
|
1509
1623
|
this.gpayPaymentRequest = null;
|
|
1510
1624
|
if (this.layoutResizeObserver) {
|
|
1511
1625
|
this.layoutResizeObserver.disconnect();
|