@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.mjs
CHANGED
|
@@ -87,7 +87,7 @@ class Emitter {
|
|
|
87
87
|
* Production configuration (for merchants)
|
|
88
88
|
*/
|
|
89
89
|
const productionConfig = {
|
|
90
|
-
version: "1.1.
|
|
90
|
+
version: "1.1.7",
|
|
91
91
|
defaultCheckoutOrigin: 'https://buy.paypercut.io',
|
|
92
92
|
defaultApiOrigin: 'https://api.paypercut.io',
|
|
93
93
|
defaultVaultApiUrl: 'https://api.basistheory.com',
|
|
@@ -484,6 +484,9 @@ class ExpressCheckoutImpl {
|
|
|
484
484
|
// 3DS modal — same pattern as CheckoutImpl
|
|
485
485
|
this.threeDSModal = null;
|
|
486
486
|
this.threeDSIframe = null;
|
|
487
|
+
// Pending 3DS data captured during THREEDS_START_FLOW while GPay sheet is still closing.
|
|
488
|
+
// Shown after loadPaymentData() resolves
|
|
489
|
+
this.pending3DSAfterGpay = null;
|
|
487
490
|
// Apple Pay native session state — session created directly in the SDK window
|
|
488
491
|
// on the merchant's registered domain.
|
|
489
492
|
this.applePaySession = null;
|
|
@@ -503,6 +506,10 @@ class ExpressCheckoutImpl {
|
|
|
503
506
|
// Pending Google Pay payment data waiting for tokenization response
|
|
504
507
|
this.pendingGpayResolve = null;
|
|
505
508
|
this.pendingGpayReject = null;
|
|
509
|
+
// Stored GPay metadata for use when TOKENIZE_RESPONSE arrives after 3DS (sheet already closed)
|
|
510
|
+
this.pendingGpayBillingDetails = null;
|
|
511
|
+
this.pendingGpayShippingDetails = null;
|
|
512
|
+
this.pendingGpayShippingOption = undefined;
|
|
506
513
|
this.currentShippingOptions = options.shippingOptions ?? [];
|
|
507
514
|
this.messageHandler = this.onMessage.bind(this);
|
|
508
515
|
window.addEventListener('message', this.messageHandler);
|
|
@@ -544,10 +551,10 @@ class ExpressCheckoutImpl {
|
|
|
544
551
|
googlePayStatus,
|
|
545
552
|
applePayStatus: data.payment_domain?.wallets?.apple_pay?.status ?? 'inactive',
|
|
546
553
|
displayName: data.merchant?.name ?? '',
|
|
547
|
-
merchantMid: data.
|
|
548
|
-
merchantMcc: data.
|
|
549
|
-
merchantCountry: data.
|
|
550
|
-
merchantUrl: data.
|
|
554
|
+
merchantMid: data.merchant?.mid ?? '',
|
|
555
|
+
merchantMcc: data.merchant?.mcc ?? '',
|
|
556
|
+
merchantCountry: data.merchant?.country ?? '',
|
|
557
|
+
merchantUrl: data.merchant?.business_url ?? '',
|
|
551
558
|
};
|
|
552
559
|
}
|
|
553
560
|
catch (err) {
|
|
@@ -558,7 +565,7 @@ class ExpressCheckoutImpl {
|
|
|
558
565
|
// postMessage handler
|
|
559
566
|
onMessage(evt) {
|
|
560
567
|
if (!isOriginAllowed(evt.origin)) {
|
|
561
|
-
if (evt.origin.includes('localhost')
|
|
568
|
+
if (evt.origin.includes('localhost')) {
|
|
562
569
|
console.warn('[PaypercutExpressCheckout] Message blocked — origin not allowed:', evt.origin);
|
|
563
570
|
}
|
|
564
571
|
return;
|
|
@@ -613,20 +620,82 @@ class ExpressCheckoutImpl {
|
|
|
613
620
|
}
|
|
614
621
|
}
|
|
615
622
|
else {
|
|
616
|
-
// Google Pay
|
|
623
|
+
// Google Pay
|
|
617
624
|
if (data.success) {
|
|
618
|
-
this.pendingGpayResolve
|
|
625
|
+
if (this.pendingGpayResolve) {
|
|
626
|
+
// Normal path (no 3DS): resolve and let handleGooglePayAuthorized create PM
|
|
627
|
+
this.pendingGpayResolve(data);
|
|
628
|
+
this.pendingGpayResolve = null;
|
|
629
|
+
this.pendingGpayReject = null;
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
// Post-3DS path: sheet was already closed — create PM directly, same as Apple Pay
|
|
633
|
+
this.createPaymentMethod({
|
|
634
|
+
btTokenId: data.btTokenId,
|
|
635
|
+
cardPayload: data.cardPayload,
|
|
636
|
+
billingDetails: data.billingDetails,
|
|
637
|
+
csessId: data.csessId,
|
|
638
|
+
walletType: 'google_pay',
|
|
639
|
+
}).then((paymentMethodId) => {
|
|
640
|
+
this.emitter.emit(ExpressSdkEvent.PaymentMethodCreated, {
|
|
641
|
+
paymentMethodId,
|
|
642
|
+
wallet: 'google_pay',
|
|
643
|
+
billingDetails: this.pendingGpayBillingDetails ?? undefined,
|
|
644
|
+
shippingDetails: this.pendingGpayShippingDetails ?? undefined,
|
|
645
|
+
selectedShippingOption: this.pendingGpayShippingOption,
|
|
646
|
+
});
|
|
647
|
+
}).catch((err) => {
|
|
648
|
+
this.emitter.emit(ExpressSdkEvent.Error, new Error(err?.message ?? 'Payment method creation failed'));
|
|
649
|
+
this.emitter.emit(ExpressSdkEvent.PaymentMethodFailed, { error: err?.message ?? 'Payment method creation failed' });
|
|
650
|
+
}).finally(() => {
|
|
651
|
+
this.pendingGpayBillingDetails = null;
|
|
652
|
+
this.pendingGpayShippingDetails = null;
|
|
653
|
+
this.pendingGpayShippingOption = undefined;
|
|
654
|
+
});
|
|
655
|
+
}
|
|
619
656
|
}
|
|
620
657
|
else {
|
|
621
|
-
this.pendingGpayReject
|
|
658
|
+
if (this.pendingGpayReject) {
|
|
659
|
+
// Normal path (no 3DS): reject the pending promise in handleGooglePayAuthorized
|
|
660
|
+
this.pendingGpayReject(new Error(data.error ?? 'Tokenization failed'));
|
|
661
|
+
this.pendingGpayResolve = null;
|
|
662
|
+
this.pendingGpayReject = null;
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
// Post-3DS path: sheet already closed — emit events directly.
|
|
666
|
+
// Distinguish user cancellation from an actual error so integrators
|
|
667
|
+
// can handle them differently (e.g. "cancel" = re-show checkout,
|
|
668
|
+
// "error" = show an error message).
|
|
669
|
+
const errMsg = data.error ?? 'Google Pay payment failed';
|
|
670
|
+
const isCanceled = errMsg.toLowerCase().includes('cancel');
|
|
671
|
+
if (isCanceled) {
|
|
672
|
+
this.emitter.emit(ExpressSdkEvent.Cancel);
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
this.emitter.emit(ExpressSdkEvent.Error, new Error(errMsg));
|
|
676
|
+
this.emitter.emit(ExpressSdkEvent.PaymentMethodFailed, { error: errMsg });
|
|
677
|
+
}
|
|
678
|
+
this.pendingGpayBillingDetails = null;
|
|
679
|
+
this.pendingGpayShippingDetails = null;
|
|
680
|
+
this.pendingGpayShippingOption = undefined;
|
|
681
|
+
}
|
|
622
682
|
}
|
|
623
|
-
this.pendingGpayResolve = null;
|
|
624
|
-
this.pendingGpayReject = null;
|
|
625
683
|
}
|
|
626
684
|
break;
|
|
627
|
-
// 3DS flow
|
|
685
|
+
// 3DS flow
|
|
628
686
|
case 'THREEDS_START_FLOW':
|
|
629
|
-
|
|
687
|
+
// Google Pay sheet is a native browser UI that cannot be overlaid by DOM elements.
|
|
688
|
+
// Resolve the pending GPay promise so GPay starts closing its sheet.
|
|
689
|
+
if (this.pendingGpayResolve) {
|
|
690
|
+
this.pending3DSAfterGpay = data;
|
|
691
|
+
this.pendingGpayResolve({ __closeSheet: true });
|
|
692
|
+
this.pendingGpayResolve = null;
|
|
693
|
+
this.pendingGpayReject = null;
|
|
694
|
+
}
|
|
695
|
+
else {
|
|
696
|
+
// Apple Pay or any path without a pending GPay sheet — show immediately
|
|
697
|
+
this.show3DSModal(data);
|
|
698
|
+
}
|
|
630
699
|
break;
|
|
631
700
|
case 'THREEDS_READY':
|
|
632
701
|
this.handle3DSReady();
|
|
@@ -721,6 +790,11 @@ class ExpressCheckoutImpl {
|
|
|
721
790
|
if (showApplePay && this.applePayContainer && config?.applePayStatus === 'active') {
|
|
722
791
|
await this.mountApplePayButton(this.applePayContainer);
|
|
723
792
|
}
|
|
793
|
+
else if (this.applePayContainer) {
|
|
794
|
+
// Apple Pay can't mount — remove its container so the remaining button fills full width
|
|
795
|
+
this.applePayContainer.remove();
|
|
796
|
+
this.applePayContainer = null;
|
|
797
|
+
}
|
|
724
798
|
if (showGooglePay && config) {
|
|
725
799
|
this.mountGooglePayFromConfig();
|
|
726
800
|
}
|
|
@@ -1137,6 +1211,10 @@ class ExpressCheckoutImpl {
|
|
|
1137
1211
|
* Called after config is fetched. Waits for the GPay script to finish loading,
|
|
1138
1212
|
* then mounts the button.
|
|
1139
1213
|
*/
|
|
1214
|
+
removeGpayContainer() {
|
|
1215
|
+
this.gpayContainer?.remove();
|
|
1216
|
+
this.gpayContainer = null;
|
|
1217
|
+
}
|
|
1140
1218
|
mountGooglePayFromConfig() {
|
|
1141
1219
|
const config = this.expressConfig;
|
|
1142
1220
|
if (!config)
|
|
@@ -1147,10 +1225,18 @@ class ExpressCheckoutImpl {
|
|
|
1147
1225
|
const merchantName = config.displayName || 'Checkout';
|
|
1148
1226
|
if (!tenantId) {
|
|
1149
1227
|
console.error('[PaypercutExpressCheckout] tenantId is empty — Google Pay cannot be mounted without a valid gatewayMerchantId.');
|
|
1228
|
+
this.removeGpayContainer();
|
|
1150
1229
|
return;
|
|
1151
1230
|
}
|
|
1152
1231
|
if (!googlePayMerchantId) {
|
|
1153
1232
|
console.warn('[PaypercutExpressCheckout] googlePayMerchantId is empty — Google Pay will not be mounted (merchant may not have Google Pay active).');
|
|
1233
|
+
this.removeGpayContainer();
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1236
|
+
console.log({ liveMode });
|
|
1237
|
+
if (liveMode && (!config.merchantMcc || !config.merchantUrl)) {
|
|
1238
|
+
console.warn('[PaypercutExpressCheckout] Google Pay disabled!');
|
|
1239
|
+
this.removeGpayContainer();
|
|
1154
1240
|
return;
|
|
1155
1241
|
}
|
|
1156
1242
|
loadGooglePayScript().then(() => {
|
|
@@ -1313,6 +1399,12 @@ class ExpressCheckoutImpl {
|
|
|
1313
1399
|
}
|
|
1314
1400
|
try {
|
|
1315
1401
|
await this.gpayClient.loadPaymentData(paymentRequest);
|
|
1402
|
+
// If 3DS was triggered, the GPay sheet is now fully dismissed — show the challenge modal.
|
|
1403
|
+
if (this.pending3DSAfterGpay) {
|
|
1404
|
+
const threeDSData = this.pending3DSAfterGpay;
|
|
1405
|
+
this.pending3DSAfterGpay = null;
|
|
1406
|
+
this.show3DSModal(threeDSData);
|
|
1407
|
+
}
|
|
1316
1408
|
}
|
|
1317
1409
|
catch (e) {
|
|
1318
1410
|
if (e?.statusCode === 'CANCELED' || e?.message?.toLowerCase?.().includes('cancel')) {
|
|
@@ -1329,6 +1421,7 @@ class ExpressCheckoutImpl {
|
|
|
1329
1421
|
async handleGooglePayAuthorized(paymentData) {
|
|
1330
1422
|
try {
|
|
1331
1423
|
const encryptedToken = paymentData.paymentMethodData.tokenizationData.token;
|
|
1424
|
+
const cardNetwork = paymentData.paymentMethodData?.info?.cardNetwork ?? '';
|
|
1332
1425
|
const billingAddr = paymentData.paymentMethodData?.info?.billingAddress;
|
|
1333
1426
|
const shippingAddr = paymentData.shippingAddress;
|
|
1334
1427
|
const shippingOptionData = paymentData.shippingOptionData;
|
|
@@ -1342,6 +1435,27 @@ class ExpressCheckoutImpl {
|
|
|
1342
1435
|
country: billingAddr.countryCode,
|
|
1343
1436
|
},
|
|
1344
1437
|
} : null;
|
|
1438
|
+
const shippingDetails = shippingAddr ? {
|
|
1439
|
+
name: shippingAddr.name || undefined,
|
|
1440
|
+
address: {
|
|
1441
|
+
line1: shippingAddr.address1,
|
|
1442
|
+
city: shippingAddr.locality,
|
|
1443
|
+
state: shippingAddr.administrativeArea,
|
|
1444
|
+
postalCode: shippingAddr.postalCode,
|
|
1445
|
+
country: shippingAddr.countryCode,
|
|
1446
|
+
},
|
|
1447
|
+
} : undefined;
|
|
1448
|
+
const selectedShippingOption = shippingOptionData
|
|
1449
|
+
? (this.currentShippingOptions.find((so) => so.id === shippingOptionData.id) ?? {
|
|
1450
|
+
id: shippingOptionData.id,
|
|
1451
|
+
label: shippingOptionData.label ?? shippingOptionData.id,
|
|
1452
|
+
amount: 0,
|
|
1453
|
+
})
|
|
1454
|
+
: undefined;
|
|
1455
|
+
// Store metadata upfront — needed if 3DS triggers and the sheet closes before TOKENIZE_RESPONSE
|
|
1456
|
+
this.pendingGpayBillingDetails = billingDetails;
|
|
1457
|
+
this.pendingGpayShippingDetails = shippingDetails;
|
|
1458
|
+
this.pendingGpayShippingOption = selectedShippingOption;
|
|
1345
1459
|
// Send to hidden tokenize iframe — it will BT-tokenize + create the payment method
|
|
1346
1460
|
const tokenResult = await new Promise((resolve, reject) => {
|
|
1347
1461
|
const timeoutId = setTimeout(() => {
|
|
@@ -1356,6 +1470,7 @@ class ExpressCheckoutImpl {
|
|
|
1356
1470
|
instanceId: this.instanceId,
|
|
1357
1471
|
wallet: 'google_pay',
|
|
1358
1472
|
encryptedToken,
|
|
1473
|
+
cardNetwork,
|
|
1359
1474
|
idemKey: this.idempotencyKey,
|
|
1360
1475
|
publishableKey: this.options.publishableKey,
|
|
1361
1476
|
billingDetails,
|
|
@@ -1370,6 +1485,10 @@ class ExpressCheckoutImpl {
|
|
|
1370
1485
|
},
|
|
1371
1486
|
});
|
|
1372
1487
|
});
|
|
1488
|
+
// 3DS was triggered — sheet already closed, payment method creation handled in message handler
|
|
1489
|
+
if (tokenResult.__closeSheet) {
|
|
1490
|
+
return { transactionState: 'SUCCESS' };
|
|
1491
|
+
}
|
|
1373
1492
|
if (!tokenResult.success) {
|
|
1374
1493
|
const errMsg = tokenResult.error ?? 'Tokenization failed';
|
|
1375
1494
|
this.emitter.emit(ExpressSdkEvent.Error, new Error(errMsg));
|
|
@@ -1383,23 +1502,6 @@ class ExpressCheckoutImpl {
|
|
|
1383
1502
|
csessId: tokenResult.csessId,
|
|
1384
1503
|
walletType: 'google_pay',
|
|
1385
1504
|
});
|
|
1386
|
-
const selectedShippingOption = shippingOptionData
|
|
1387
|
-
? (this.currentShippingOptions.find((so) => so.id === shippingOptionData.id) ?? {
|
|
1388
|
-
id: shippingOptionData.id,
|
|
1389
|
-
label: shippingOptionData.label ?? shippingOptionData.id,
|
|
1390
|
-
amount: 0,
|
|
1391
|
-
})
|
|
1392
|
-
: undefined;
|
|
1393
|
-
const shippingDetails = shippingAddr ? {
|
|
1394
|
-
name: shippingAddr.name || undefined,
|
|
1395
|
-
address: {
|
|
1396
|
-
line1: shippingAddr.address1,
|
|
1397
|
-
city: shippingAddr.locality,
|
|
1398
|
-
state: shippingAddr.administrativeArea,
|
|
1399
|
-
postalCode: shippingAddr.postalCode,
|
|
1400
|
-
country: shippingAddr.countryCode,
|
|
1401
|
-
},
|
|
1402
|
-
} : undefined;
|
|
1403
1505
|
this.emitter.emit(ExpressSdkEvent.PaymentMethodCreated, {
|
|
1404
1506
|
paymentMethodId,
|
|
1405
1507
|
wallet: 'google_pay',
|
|
@@ -1407,6 +1509,9 @@ class ExpressCheckoutImpl {
|
|
|
1407
1509
|
shippingDetails,
|
|
1408
1510
|
selectedShippingOption,
|
|
1409
1511
|
});
|
|
1512
|
+
this.pendingGpayBillingDetails = null;
|
|
1513
|
+
this.pendingGpayShippingDetails = null;
|
|
1514
|
+
this.pendingGpayShippingOption = undefined;
|
|
1410
1515
|
return { transactionState: 'SUCCESS' };
|
|
1411
1516
|
}
|
|
1412
1517
|
catch (err) {
|