@paypercut/checkout-js 1.1.0 → 1.1.7
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 +135 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +135 -30
- 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.7",
|
|
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,11 @@ 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.applePayContainer.remove();
|
|
800
|
+
this.applePayContainer = null;
|
|
801
|
+
}
|
|
728
802
|
if (showGooglePay && config) {
|
|
729
803
|
this.mountGooglePayFromConfig();
|
|
730
804
|
}
|
|
@@ -1141,6 +1215,10 @@ class ExpressCheckoutImpl {
|
|
|
1141
1215
|
* Called after config is fetched. Waits for the GPay script to finish loading,
|
|
1142
1216
|
* then mounts the button.
|
|
1143
1217
|
*/
|
|
1218
|
+
removeGpayContainer() {
|
|
1219
|
+
this.gpayContainer?.remove();
|
|
1220
|
+
this.gpayContainer = null;
|
|
1221
|
+
}
|
|
1144
1222
|
mountGooglePayFromConfig() {
|
|
1145
1223
|
const config = this.expressConfig;
|
|
1146
1224
|
if (!config)
|
|
@@ -1151,10 +1229,18 @@ class ExpressCheckoutImpl {
|
|
|
1151
1229
|
const merchantName = config.displayName || 'Checkout';
|
|
1152
1230
|
if (!tenantId) {
|
|
1153
1231
|
console.error('[PaypercutExpressCheckout] tenantId is empty — Google Pay cannot be mounted without a valid gatewayMerchantId.');
|
|
1232
|
+
this.removeGpayContainer();
|
|
1154
1233
|
return;
|
|
1155
1234
|
}
|
|
1156
1235
|
if (!googlePayMerchantId) {
|
|
1157
1236
|
console.warn('[PaypercutExpressCheckout] googlePayMerchantId is empty — Google Pay will not be mounted (merchant may not have Google Pay active).');
|
|
1237
|
+
this.removeGpayContainer();
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
console.log({ liveMode });
|
|
1241
|
+
if (liveMode && (!config.merchantMcc || !config.merchantUrl)) {
|
|
1242
|
+
console.warn('[PaypercutExpressCheckout] Google Pay disabled!');
|
|
1243
|
+
this.removeGpayContainer();
|
|
1158
1244
|
return;
|
|
1159
1245
|
}
|
|
1160
1246
|
loadGooglePayScript().then(() => {
|
|
@@ -1317,6 +1403,12 @@ class ExpressCheckoutImpl {
|
|
|
1317
1403
|
}
|
|
1318
1404
|
try {
|
|
1319
1405
|
await this.gpayClient.loadPaymentData(paymentRequest);
|
|
1406
|
+
// If 3DS was triggered, the GPay sheet is now fully dismissed — show the challenge modal.
|
|
1407
|
+
if (this.pending3DSAfterGpay) {
|
|
1408
|
+
const threeDSData = this.pending3DSAfterGpay;
|
|
1409
|
+
this.pending3DSAfterGpay = null;
|
|
1410
|
+
this.show3DSModal(threeDSData);
|
|
1411
|
+
}
|
|
1320
1412
|
}
|
|
1321
1413
|
catch (e) {
|
|
1322
1414
|
if (e?.statusCode === 'CANCELED' || e?.message?.toLowerCase?.().includes('cancel')) {
|
|
@@ -1333,6 +1425,7 @@ class ExpressCheckoutImpl {
|
|
|
1333
1425
|
async handleGooglePayAuthorized(paymentData) {
|
|
1334
1426
|
try {
|
|
1335
1427
|
const encryptedToken = paymentData.paymentMethodData.tokenizationData.token;
|
|
1428
|
+
const cardNetwork = paymentData.paymentMethodData?.info?.cardNetwork ?? '';
|
|
1336
1429
|
const billingAddr = paymentData.paymentMethodData?.info?.billingAddress;
|
|
1337
1430
|
const shippingAddr = paymentData.shippingAddress;
|
|
1338
1431
|
const shippingOptionData = paymentData.shippingOptionData;
|
|
@@ -1346,6 +1439,27 @@ class ExpressCheckoutImpl {
|
|
|
1346
1439
|
country: billingAddr.countryCode,
|
|
1347
1440
|
},
|
|
1348
1441
|
} : null;
|
|
1442
|
+
const shippingDetails = shippingAddr ? {
|
|
1443
|
+
name: shippingAddr.name || undefined,
|
|
1444
|
+
address: {
|
|
1445
|
+
line1: shippingAddr.address1,
|
|
1446
|
+
city: shippingAddr.locality,
|
|
1447
|
+
state: shippingAddr.administrativeArea,
|
|
1448
|
+
postalCode: shippingAddr.postalCode,
|
|
1449
|
+
country: shippingAddr.countryCode,
|
|
1450
|
+
},
|
|
1451
|
+
} : undefined;
|
|
1452
|
+
const selectedShippingOption = shippingOptionData
|
|
1453
|
+
? (this.currentShippingOptions.find((so) => so.id === shippingOptionData.id) ?? {
|
|
1454
|
+
id: shippingOptionData.id,
|
|
1455
|
+
label: shippingOptionData.label ?? shippingOptionData.id,
|
|
1456
|
+
amount: 0,
|
|
1457
|
+
})
|
|
1458
|
+
: undefined;
|
|
1459
|
+
// Store metadata upfront — needed if 3DS triggers and the sheet closes before TOKENIZE_RESPONSE
|
|
1460
|
+
this.pendingGpayBillingDetails = billingDetails;
|
|
1461
|
+
this.pendingGpayShippingDetails = shippingDetails;
|
|
1462
|
+
this.pendingGpayShippingOption = selectedShippingOption;
|
|
1349
1463
|
// Send to hidden tokenize iframe — it will BT-tokenize + create the payment method
|
|
1350
1464
|
const tokenResult = await new Promise((resolve, reject) => {
|
|
1351
1465
|
const timeoutId = setTimeout(() => {
|
|
@@ -1360,6 +1474,7 @@ class ExpressCheckoutImpl {
|
|
|
1360
1474
|
instanceId: this.instanceId,
|
|
1361
1475
|
wallet: 'google_pay',
|
|
1362
1476
|
encryptedToken,
|
|
1477
|
+
cardNetwork,
|
|
1363
1478
|
idemKey: this.idempotencyKey,
|
|
1364
1479
|
publishableKey: this.options.publishableKey,
|
|
1365
1480
|
billingDetails,
|
|
@@ -1374,6 +1489,10 @@ class ExpressCheckoutImpl {
|
|
|
1374
1489
|
},
|
|
1375
1490
|
});
|
|
1376
1491
|
});
|
|
1492
|
+
// 3DS was triggered — sheet already closed, payment method creation handled in message handler
|
|
1493
|
+
if (tokenResult.__closeSheet) {
|
|
1494
|
+
return { transactionState: 'SUCCESS' };
|
|
1495
|
+
}
|
|
1377
1496
|
if (!tokenResult.success) {
|
|
1378
1497
|
const errMsg = tokenResult.error ?? 'Tokenization failed';
|
|
1379
1498
|
this.emitter.emit(exports.ExpressSdkEvent.Error, new Error(errMsg));
|
|
@@ -1387,23 +1506,6 @@ class ExpressCheckoutImpl {
|
|
|
1387
1506
|
csessId: tokenResult.csessId,
|
|
1388
1507
|
walletType: 'google_pay',
|
|
1389
1508
|
});
|
|
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
1509
|
this.emitter.emit(exports.ExpressSdkEvent.PaymentMethodCreated, {
|
|
1408
1510
|
paymentMethodId,
|
|
1409
1511
|
wallet: 'google_pay',
|
|
@@ -1411,6 +1513,9 @@ class ExpressCheckoutImpl {
|
|
|
1411
1513
|
shippingDetails,
|
|
1412
1514
|
selectedShippingOption,
|
|
1413
1515
|
});
|
|
1516
|
+
this.pendingGpayBillingDetails = null;
|
|
1517
|
+
this.pendingGpayShippingDetails = null;
|
|
1518
|
+
this.pendingGpayShippingOption = undefined;
|
|
1414
1519
|
return { transactionState: 'SUCCESS' };
|
|
1415
1520
|
}
|
|
1416
1521
|
catch (err) {
|