@paypercut/checkout-js 1.4.3 → 1.4.5
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/README.md +19 -1
- package/dist/developer-assistance.cjs +1 -1
- package/dist/developer-assistance.mjs +1 -1
- package/dist/index.cjs +98 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.mjs +98 -25
- 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/dist/paypercut-developer-assistance.iife.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -818,6 +818,7 @@ const elements = paypercut.elements({
|
|
|
818
818
|
});
|
|
819
819
|
|
|
820
820
|
const expressCheckout = elements.create('expressCheckout', {
|
|
821
|
+
paymentMethodOrder: ['apple_pay', 'google_pay'],
|
|
821
822
|
paymentMethods: {
|
|
822
823
|
applePay: 'auto',
|
|
823
824
|
googlePay: 'auto',
|
|
@@ -901,6 +902,23 @@ events and requires each event to be resolved or rejected promptly. The final
|
|
|
901
902
|
`shippingRate`. Integrations without shipping (for example, an EV charging
|
|
902
903
|
payment) should leave those options unset and receive no shipping callbacks.
|
|
903
904
|
|
|
905
|
+
Set `paymentMethodOrder` to choose which wallet button appears first. Listed
|
|
906
|
+
wallets appear in your preferred order; other available wallets follow. A wallet
|
|
907
|
+
that is unavailable or set to `never` is skipped without leaving a gap. Omitting
|
|
908
|
+
the option, or passing `[]`, uses Google Pay followed by Apple Pay. The order
|
|
909
|
+
applies within this Element; your page controls the placement of separate
|
|
910
|
+
Elements.
|
|
911
|
+
|
|
912
|
+
You can change the order while no wallet payment or Appearance preview is active:
|
|
913
|
+
|
|
914
|
+
```ts
|
|
915
|
+
expressCheckout.update({ paymentMethodOrder: ['google_pay', 'apple_pay'] });
|
|
916
|
+
expressCheckout.update({ paymentMethodOrder: [] }); // Restore the default order.
|
|
917
|
+
```
|
|
918
|
+
|
|
919
|
+
An update that omits `paymentMethodOrder` keeps the current preference. Use only
|
|
920
|
+
`apple_pay` and `google_pay`, without duplicates. Invalid lists are rejected.
|
|
921
|
+
|
|
904
922
|
---
|
|
905
923
|
|
|
906
924
|
## Quick Start
|
|
@@ -1743,7 +1761,7 @@ Tip: Prefer subscribing with the SdkEvent enum for stronger typing.
|
|
|
1743
1761
|
<body>
|
|
1744
1762
|
<div id="checkout"></div>
|
|
1745
1763
|
|
|
1746
|
-
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.4.
|
|
1764
|
+
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.4.5/dist/paypercut-checkout.iife.min.js"></script>
|
|
1747
1765
|
<script>
|
|
1748
1766
|
const checkout = PaypercutCheckout({
|
|
1749
1767
|
id: '01KB23M9EC960C50G3AH14FTTT',
|
package/dist/index.cjs
CHANGED
|
@@ -105,7 +105,7 @@ class Emitter {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
const SDK_VERSION = "1.4.
|
|
108
|
+
const SDK_VERSION = "1.4.5";
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
111
|
* Build-time configuration
|
|
@@ -3239,6 +3239,9 @@ function buildExpressCheckoutFrameUrl(input) {
|
|
|
3239
3239
|
params.set('mode', input.elementsOptions.mode);
|
|
3240
3240
|
params.set('amount', String(input.elementsOptions.amount));
|
|
3241
3241
|
params.set('currency', input.elementsOptions.currency);
|
|
3242
|
+
if (input.options.paymentMethodOrder !== undefined) {
|
|
3243
|
+
params.set('publicOptions[paymentMethodOrder]', input.options.paymentMethodOrder.join(','));
|
|
3244
|
+
}
|
|
3242
3245
|
set(params, 'publicOptions[paymentMethods][applePay]', input.options.paymentMethods?.applePay);
|
|
3243
3246
|
set(params, 'publicOptions[paymentMethods][googlePay]', input.options.paymentMethods?.googlePay);
|
|
3244
3247
|
set(params, 'publicOptions[layout][maxColumns]', input.options.layout?.maxColumns);
|
|
@@ -4771,6 +4774,7 @@ class CardElementImpl {
|
|
|
4771
4774
|
this.handleInitializationTimeout();
|
|
4772
4775
|
return;
|
|
4773
4776
|
}
|
|
4777
|
+
this.group.retryStalledControllerInitialization();
|
|
4774
4778
|
const replacement = this.createFrame();
|
|
4775
4779
|
const previousGeneration = this.componentGeneration;
|
|
4776
4780
|
this.componentGeneration += 1;
|
|
@@ -5157,6 +5161,38 @@ function patchApplePayModalFocus(modal, attempts = 0) {
|
|
|
5157
5161
|
root.appendChild(style);
|
|
5158
5162
|
}
|
|
5159
5163
|
|
|
5164
|
+
/** Merchant-document layout shared by the hosted frame and its iOS Google Pay button. */
|
|
5165
|
+
function createExpressCheckoutMount(frame) {
|
|
5166
|
+
const mount = document.createElement('div');
|
|
5167
|
+
mount.dataset.paypercutElementsExpressMount = '';
|
|
5168
|
+
Object.assign(mount.style, {
|
|
5169
|
+
position: 'relative',
|
|
5170
|
+
display: 'block',
|
|
5171
|
+
width: '100%',
|
|
5172
|
+
minWidth: '0',
|
|
5173
|
+
margin: '0',
|
|
5174
|
+
padding: '0',
|
|
5175
|
+
border: '0',
|
|
5176
|
+
});
|
|
5177
|
+
mount.appendChild(frame);
|
|
5178
|
+
return mount;
|
|
5179
|
+
}
|
|
5180
|
+
function createGooglePayButtonSurface(componentId) {
|
|
5181
|
+
const container = document.createElement('div');
|
|
5182
|
+
container.dataset.paypercutElementsGooglePayButton = componentId;
|
|
5183
|
+
Object.assign(container.style, {
|
|
5184
|
+
position: 'absolute',
|
|
5185
|
+
margin: '0',
|
|
5186
|
+
padding: '0',
|
|
5187
|
+
border: '0',
|
|
5188
|
+
overflow: 'hidden',
|
|
5189
|
+
zIndex: '2147483000',
|
|
5190
|
+
pointerEvents: 'auto',
|
|
5191
|
+
visibility: 'hidden',
|
|
5192
|
+
});
|
|
5193
|
+
return container;
|
|
5194
|
+
}
|
|
5195
|
+
|
|
5160
5196
|
const GOOGLE_PAY_POPUP_RECOVERY_POLICY = {
|
|
5161
5197
|
closedPollIntervalMs: 250,
|
|
5162
5198
|
providerSettlementGraceMs: 3500,
|
|
@@ -5335,6 +5371,7 @@ class ExpressCheckoutElementImpl {
|
|
|
5335
5371
|
this.googlePayAuthorization = null;
|
|
5336
5372
|
this.googlePayButtonTarget = null;
|
|
5337
5373
|
this.googlePayButtonContainer = null;
|
|
5374
|
+
this.mountSurface = null;
|
|
5338
5375
|
this.googlePayButtonGeneration = 0;
|
|
5339
5376
|
this.googlePayButtonPositionFrame = null;
|
|
5340
5377
|
this.googlePayButtonResizeObserver = null;
|
|
@@ -5383,7 +5420,8 @@ class ExpressCheckoutElementImpl {
|
|
|
5383
5420
|
this.group.markComponentMounted();
|
|
5384
5421
|
window.addEventListener('message', this.messageHandler);
|
|
5385
5422
|
this.group.ensureController();
|
|
5386
|
-
|
|
5423
|
+
this.mountSurface = createExpressCheckoutMount(iframe);
|
|
5424
|
+
container.appendChild(this.mountSurface);
|
|
5387
5425
|
this.registerDeveloperAssistant();
|
|
5388
5426
|
}
|
|
5389
5427
|
on(event, handler) {
|
|
@@ -5397,6 +5435,9 @@ class ExpressCheckoutElementImpl {
|
|
|
5397
5435
|
throw new Error('[Paypercut Elements] Cannot update Express Checkout while a wallet attempt is active.');
|
|
5398
5436
|
}
|
|
5399
5437
|
const validated = validateElementUpdateOptions(options);
|
|
5438
|
+
if ('paymentMethodOrder' in validated && this.previewTransitionActive) {
|
|
5439
|
+
throw new Error('[Paypercut Elements] Cannot update wallet order while an Appearance preview is active.');
|
|
5440
|
+
}
|
|
5400
5441
|
this.options = validateOptions({ ...this.options, ...validated });
|
|
5401
5442
|
if (this.componentRevision === Number.MAX_SAFE_INTEGER) {
|
|
5402
5443
|
throw new Error('[Paypercut Elements] The component update revision limit has been reached.');
|
|
@@ -5686,6 +5727,8 @@ class ExpressCheckoutElementImpl {
|
|
|
5686
5727
|
}
|
|
5687
5728
|
this.iframe?.remove();
|
|
5688
5729
|
this.iframe = null;
|
|
5730
|
+
this.mountSurface?.remove();
|
|
5731
|
+
this.mountSurface = null;
|
|
5689
5732
|
this.connectedFrame = null;
|
|
5690
5733
|
this.mounted = false;
|
|
5691
5734
|
this.emitter.clear();
|
|
@@ -5693,6 +5736,7 @@ class ExpressCheckoutElementImpl {
|
|
|
5693
5736
|
}
|
|
5694
5737
|
createFrame(options = this.options) {
|
|
5695
5738
|
const iframe = document.createElement('iframe');
|
|
5739
|
+
const disableAnimations = this.group.getRenderableElementsOptions().appearance?.disableAnimations === true;
|
|
5696
5740
|
iframe.id = `paypercut-express-checkout-element-${this.componentId}`;
|
|
5697
5741
|
iframe.title = 'Express checkout';
|
|
5698
5742
|
iframe.referrerPolicy = 'origin';
|
|
@@ -5721,8 +5765,8 @@ class ExpressCheckoutElementImpl {
|
|
|
5721
5765
|
display: 'block',
|
|
5722
5766
|
overflow: 'hidden',
|
|
5723
5767
|
colorScheme: 'light dark',
|
|
5724
|
-
transition: 'height 250ms ease-in-out, opacity 250ms ease-in-out',
|
|
5725
|
-
willChange: 'height, opacity',
|
|
5768
|
+
transition: disableAnimations ? 'none' : 'height 250ms ease-in-out, opacity 250ms ease-in-out',
|
|
5769
|
+
willChange: disableAnimations ? 'auto' : 'height, opacity',
|
|
5726
5770
|
});
|
|
5727
5771
|
return iframe;
|
|
5728
5772
|
}
|
|
@@ -6029,8 +6073,7 @@ class ExpressCheckoutElementImpl {
|
|
|
6029
6073
|
// merchant click decision returns. Keep the request identity until the
|
|
6030
6074
|
// controller's wallet_cancel arrives so integrations receive their
|
|
6031
6075
|
// normal cancel lifecycle and can release their own attempt lock.
|
|
6032
|
-
if (wallet !== 'google_pay' ||
|
|
6033
|
-
this.googlePayRequestId !== requestId) {
|
|
6076
|
+
if (wallet !== 'google_pay' || this.googlePayRequestId !== requestId) {
|
|
6034
6077
|
this.activeAttempt = null;
|
|
6035
6078
|
this.activeOptions = null;
|
|
6036
6079
|
}
|
|
@@ -6264,18 +6307,9 @@ class ExpressCheckoutElementImpl {
|
|
|
6264
6307
|
}
|
|
6265
6308
|
mountGooglePayButton(client, target, request, allowedPaymentMethods) {
|
|
6266
6309
|
this.removeGooglePayButton();
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
position: 'fixed',
|
|
6271
|
-
margin: '0',
|
|
6272
|
-
padding: '0',
|
|
6273
|
-
border: '0',
|
|
6274
|
-
overflow: 'hidden',
|
|
6275
|
-
zIndex: '2147483000',
|
|
6276
|
-
pointerEvents: 'auto',
|
|
6277
|
-
visibility: 'hidden',
|
|
6278
|
-
});
|
|
6310
|
+
if (!this.mountSurface)
|
|
6311
|
+
return;
|
|
6312
|
+
const container = createGooglePayButtonSurface(this.componentId);
|
|
6279
6313
|
const button = client.createButton({
|
|
6280
6314
|
buttonColor: target.buttonColor,
|
|
6281
6315
|
buttonType: target.buttonType,
|
|
@@ -6301,10 +6335,9 @@ class ExpressCheckoutElementImpl {
|
|
|
6301
6335
|
});
|
|
6302
6336
|
Object.assign(button.style, { width: '100%', height: '100%', margin: '0' });
|
|
6303
6337
|
container.appendChild(button);
|
|
6304
|
-
|
|
6338
|
+
this.mountSurface.appendChild(container);
|
|
6305
6339
|
this.googlePayButtonContainer = container;
|
|
6306
6340
|
window.addEventListener('resize', this.googlePayButtonPositionHandler);
|
|
6307
|
-
window.addEventListener('scroll', this.googlePayButtonPositionHandler, true);
|
|
6308
6341
|
if (typeof ResizeObserver !== 'undefined' && this.iframe) {
|
|
6309
6342
|
this.googlePayButtonResizeObserver = new ResizeObserver(this.googlePayButtonPositionHandler);
|
|
6310
6343
|
this.googlePayButtonResizeObserver.observe(this.iframe);
|
|
@@ -6323,8 +6356,10 @@ class ExpressCheckoutElementImpl {
|
|
|
6323
6356
|
return;
|
|
6324
6357
|
}
|
|
6325
6358
|
const frameRect = iframe.getBoundingClientRect();
|
|
6326
|
-
|
|
6327
|
-
|
|
6359
|
+
// The surface shares the frame's layout origin. Scrolling and merchant
|
|
6360
|
+
// layout shifts move both together without waiting for JS scroll/rAF work.
|
|
6361
|
+
const left = target.target.x;
|
|
6362
|
+
const top = target.target.y;
|
|
6328
6363
|
Object.assign(container.style, {
|
|
6329
6364
|
left: `${left}px`,
|
|
6330
6365
|
top: `${top}px`,
|
|
@@ -6346,7 +6381,6 @@ class ExpressCheckoutElementImpl {
|
|
|
6346
6381
|
this.googlePayButtonPositionFrame = null;
|
|
6347
6382
|
}
|
|
6348
6383
|
window.removeEventListener('resize', this.googlePayButtonPositionHandler);
|
|
6349
|
-
window.removeEventListener('scroll', this.googlePayButtonPositionHandler, true);
|
|
6350
6384
|
this.googlePayButtonResizeObserver?.disconnect();
|
|
6351
6385
|
this.googlePayButtonResizeObserver = null;
|
|
6352
6386
|
this.googlePayButtonContainer?.remove();
|
|
@@ -6723,6 +6757,7 @@ class ExpressCheckoutElementImpl {
|
|
|
6723
6757
|
}
|
|
6724
6758
|
}
|
|
6725
6759
|
const OPTION_KEYS = new Set([
|
|
6760
|
+
'paymentMethodOrder',
|
|
6726
6761
|
'paymentMethods',
|
|
6727
6762
|
'layout',
|
|
6728
6763
|
'buttonType',
|
|
@@ -6780,6 +6815,7 @@ function validateOptions(options) {
|
|
|
6780
6815
|
if (!isRecord(rawOptions) || Object.keys(rawOptions).some((key) => !OPTION_KEYS.has(key))) {
|
|
6781
6816
|
throw new Error('[Paypercut Elements] Express Checkout options are invalid.');
|
|
6782
6817
|
}
|
|
6818
|
+
validatePaymentMethodOrder(options.paymentMethodOrder);
|
|
6783
6819
|
if (options.buttonHeight !== undefined) {
|
|
6784
6820
|
if (typeof options.buttonHeight !== 'number' ||
|
|
6785
6821
|
!Number.isSafeInteger(options.buttonHeight) ||
|
|
@@ -6932,11 +6968,25 @@ function validateClickResolveOptions(options) {
|
|
|
6932
6968
|
: {}),
|
|
6933
6969
|
});
|
|
6934
6970
|
}
|
|
6971
|
+
function validatePaymentMethodOrder(order) {
|
|
6972
|
+
if (order !== undefined &&
|
|
6973
|
+
(!Array.isArray(order) ||
|
|
6974
|
+
[...order].some((wallet) => wallet !== 'apple_pay' && wallet !== 'google_pay') ||
|
|
6975
|
+
new Set(order).size !== order.length)) {
|
|
6976
|
+
throw invalidOptions();
|
|
6977
|
+
}
|
|
6978
|
+
}
|
|
6935
6979
|
function validateElementUpdateOptions(options) {
|
|
6936
6980
|
if (!isRecord(options) || Object.keys(options).length === 0 || 'amount' in options) {
|
|
6937
|
-
throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details.');
|
|
6981
|
+
throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details or wallet order.');
|
|
6938
6982
|
}
|
|
6939
|
-
|
|
6983
|
+
const { paymentMethodOrder, ...checkoutDetails } = options;
|
|
6984
|
+
validatePaymentMethodOrder(paymentMethodOrder);
|
|
6985
|
+
const validated = validateClickResolveOptions(checkoutDetails);
|
|
6986
|
+
return {
|
|
6987
|
+
...validated,
|
|
6988
|
+
...('paymentMethodOrder' in options ? { paymentMethodOrder: paymentMethodOrder?.slice() } : {}),
|
|
6989
|
+
};
|
|
6940
6990
|
}
|
|
6941
6991
|
function validateShippingUpdate(update) {
|
|
6942
6992
|
if (update === undefined)
|
|
@@ -11707,6 +11757,29 @@ class ElementsGroupImpl {
|
|
|
11707
11757
|
window.addEventListener('message', this.windowMessageHandler);
|
|
11708
11758
|
(document.body ?? document.documentElement).appendChild(iframe);
|
|
11709
11759
|
}
|
|
11760
|
+
retryStalledControllerInitialization() {
|
|
11761
|
+
const current = this.controllerIframe;
|
|
11762
|
+
const parent = current?.parentNode;
|
|
11763
|
+
if (this.destroyed || this.controllerInitialized || !current || !parent)
|
|
11764
|
+
return false;
|
|
11765
|
+
// A component-only reload cannot recover a controller whose session request
|
|
11766
|
+
// or bootstrap never completed. Keep the group and its pending components,
|
|
11767
|
+
// but give the controller a fresh browsing context and navigation identity.
|
|
11768
|
+
let replacement;
|
|
11769
|
+
try {
|
|
11770
|
+
replacement = current.cloneNode(false);
|
|
11771
|
+
replacement.src = withElementsFrameNavigationIdentity(current.src, generateId());
|
|
11772
|
+
parent.replaceChild(replacement, current);
|
|
11773
|
+
}
|
|
11774
|
+
catch {
|
|
11775
|
+
return false;
|
|
11776
|
+
}
|
|
11777
|
+
this.controlPort?.close();
|
|
11778
|
+
this.controlPort = null;
|
|
11779
|
+
this.controllerBootstrapped = false;
|
|
11780
|
+
this.controllerIframe = replacement;
|
|
11781
|
+
return true;
|
|
11782
|
+
}
|
|
11710
11783
|
attachComponent(element, port) {
|
|
11711
11784
|
if (this.destroyed || !this.elements.has(element.componentId)) {
|
|
11712
11785
|
port.close();
|