@paypercut/checkout-js 1.4.3 → 1.4.4
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 +71 -23
- 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 +71 -23
- 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.4/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.4";
|
|
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);
|
|
@@ -5157,6 +5160,38 @@ function patchApplePayModalFocus(modal, attempts = 0) {
|
|
|
5157
5160
|
root.appendChild(style);
|
|
5158
5161
|
}
|
|
5159
5162
|
|
|
5163
|
+
/** Merchant-document layout shared by the hosted frame and its iOS Google Pay button. */
|
|
5164
|
+
function createExpressCheckoutMount(frame) {
|
|
5165
|
+
const mount = document.createElement('div');
|
|
5166
|
+
mount.dataset.paypercutElementsExpressMount = '';
|
|
5167
|
+
Object.assign(mount.style, {
|
|
5168
|
+
position: 'relative',
|
|
5169
|
+
display: 'block',
|
|
5170
|
+
width: '100%',
|
|
5171
|
+
minWidth: '0',
|
|
5172
|
+
margin: '0',
|
|
5173
|
+
padding: '0',
|
|
5174
|
+
border: '0',
|
|
5175
|
+
});
|
|
5176
|
+
mount.appendChild(frame);
|
|
5177
|
+
return mount;
|
|
5178
|
+
}
|
|
5179
|
+
function createGooglePayButtonSurface(componentId) {
|
|
5180
|
+
const container = document.createElement('div');
|
|
5181
|
+
container.dataset.paypercutElementsGooglePayButton = componentId;
|
|
5182
|
+
Object.assign(container.style, {
|
|
5183
|
+
position: 'absolute',
|
|
5184
|
+
margin: '0',
|
|
5185
|
+
padding: '0',
|
|
5186
|
+
border: '0',
|
|
5187
|
+
overflow: 'hidden',
|
|
5188
|
+
zIndex: '2147483000',
|
|
5189
|
+
pointerEvents: 'auto',
|
|
5190
|
+
visibility: 'hidden',
|
|
5191
|
+
});
|
|
5192
|
+
return container;
|
|
5193
|
+
}
|
|
5194
|
+
|
|
5160
5195
|
const GOOGLE_PAY_POPUP_RECOVERY_POLICY = {
|
|
5161
5196
|
closedPollIntervalMs: 250,
|
|
5162
5197
|
providerSettlementGraceMs: 3500,
|
|
@@ -5335,6 +5370,7 @@ class ExpressCheckoutElementImpl {
|
|
|
5335
5370
|
this.googlePayAuthorization = null;
|
|
5336
5371
|
this.googlePayButtonTarget = null;
|
|
5337
5372
|
this.googlePayButtonContainer = null;
|
|
5373
|
+
this.mountSurface = null;
|
|
5338
5374
|
this.googlePayButtonGeneration = 0;
|
|
5339
5375
|
this.googlePayButtonPositionFrame = null;
|
|
5340
5376
|
this.googlePayButtonResizeObserver = null;
|
|
@@ -5383,7 +5419,8 @@ class ExpressCheckoutElementImpl {
|
|
|
5383
5419
|
this.group.markComponentMounted();
|
|
5384
5420
|
window.addEventListener('message', this.messageHandler);
|
|
5385
5421
|
this.group.ensureController();
|
|
5386
|
-
|
|
5422
|
+
this.mountSurface = createExpressCheckoutMount(iframe);
|
|
5423
|
+
container.appendChild(this.mountSurface);
|
|
5387
5424
|
this.registerDeveloperAssistant();
|
|
5388
5425
|
}
|
|
5389
5426
|
on(event, handler) {
|
|
@@ -5397,6 +5434,9 @@ class ExpressCheckoutElementImpl {
|
|
|
5397
5434
|
throw new Error('[Paypercut Elements] Cannot update Express Checkout while a wallet attempt is active.');
|
|
5398
5435
|
}
|
|
5399
5436
|
const validated = validateElementUpdateOptions(options);
|
|
5437
|
+
if ('paymentMethodOrder' in validated && this.previewTransitionActive) {
|
|
5438
|
+
throw new Error('[Paypercut Elements] Cannot update wallet order while an Appearance preview is active.');
|
|
5439
|
+
}
|
|
5400
5440
|
this.options = validateOptions({ ...this.options, ...validated });
|
|
5401
5441
|
if (this.componentRevision === Number.MAX_SAFE_INTEGER) {
|
|
5402
5442
|
throw new Error('[Paypercut Elements] The component update revision limit has been reached.');
|
|
@@ -5686,6 +5726,8 @@ class ExpressCheckoutElementImpl {
|
|
|
5686
5726
|
}
|
|
5687
5727
|
this.iframe?.remove();
|
|
5688
5728
|
this.iframe = null;
|
|
5729
|
+
this.mountSurface?.remove();
|
|
5730
|
+
this.mountSurface = null;
|
|
5689
5731
|
this.connectedFrame = null;
|
|
5690
5732
|
this.mounted = false;
|
|
5691
5733
|
this.emitter.clear();
|
|
@@ -6029,8 +6071,7 @@ class ExpressCheckoutElementImpl {
|
|
|
6029
6071
|
// merchant click decision returns. Keep the request identity until the
|
|
6030
6072
|
// controller's wallet_cancel arrives so integrations receive their
|
|
6031
6073
|
// normal cancel lifecycle and can release their own attempt lock.
|
|
6032
|
-
if (wallet !== 'google_pay' ||
|
|
6033
|
-
this.googlePayRequestId !== requestId) {
|
|
6074
|
+
if (wallet !== 'google_pay' || this.googlePayRequestId !== requestId) {
|
|
6034
6075
|
this.activeAttempt = null;
|
|
6035
6076
|
this.activeOptions = null;
|
|
6036
6077
|
}
|
|
@@ -6264,18 +6305,9 @@ class ExpressCheckoutElementImpl {
|
|
|
6264
6305
|
}
|
|
6265
6306
|
mountGooglePayButton(client, target, request, allowedPaymentMethods) {
|
|
6266
6307
|
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
|
-
});
|
|
6308
|
+
if (!this.mountSurface)
|
|
6309
|
+
return;
|
|
6310
|
+
const container = createGooglePayButtonSurface(this.componentId);
|
|
6279
6311
|
const button = client.createButton({
|
|
6280
6312
|
buttonColor: target.buttonColor,
|
|
6281
6313
|
buttonType: target.buttonType,
|
|
@@ -6301,10 +6333,9 @@ class ExpressCheckoutElementImpl {
|
|
|
6301
6333
|
});
|
|
6302
6334
|
Object.assign(button.style, { width: '100%', height: '100%', margin: '0' });
|
|
6303
6335
|
container.appendChild(button);
|
|
6304
|
-
|
|
6336
|
+
this.mountSurface.appendChild(container);
|
|
6305
6337
|
this.googlePayButtonContainer = container;
|
|
6306
6338
|
window.addEventListener('resize', this.googlePayButtonPositionHandler);
|
|
6307
|
-
window.addEventListener('scroll', this.googlePayButtonPositionHandler, true);
|
|
6308
6339
|
if (typeof ResizeObserver !== 'undefined' && this.iframe) {
|
|
6309
6340
|
this.googlePayButtonResizeObserver = new ResizeObserver(this.googlePayButtonPositionHandler);
|
|
6310
6341
|
this.googlePayButtonResizeObserver.observe(this.iframe);
|
|
@@ -6323,8 +6354,10 @@ class ExpressCheckoutElementImpl {
|
|
|
6323
6354
|
return;
|
|
6324
6355
|
}
|
|
6325
6356
|
const frameRect = iframe.getBoundingClientRect();
|
|
6326
|
-
|
|
6327
|
-
|
|
6357
|
+
// The surface shares the frame's layout origin. Scrolling and merchant
|
|
6358
|
+
// layout shifts move both together without waiting for JS scroll/rAF work.
|
|
6359
|
+
const left = target.target.x;
|
|
6360
|
+
const top = target.target.y;
|
|
6328
6361
|
Object.assign(container.style, {
|
|
6329
6362
|
left: `${left}px`,
|
|
6330
6363
|
top: `${top}px`,
|
|
@@ -6346,7 +6379,6 @@ class ExpressCheckoutElementImpl {
|
|
|
6346
6379
|
this.googlePayButtonPositionFrame = null;
|
|
6347
6380
|
}
|
|
6348
6381
|
window.removeEventListener('resize', this.googlePayButtonPositionHandler);
|
|
6349
|
-
window.removeEventListener('scroll', this.googlePayButtonPositionHandler, true);
|
|
6350
6382
|
this.googlePayButtonResizeObserver?.disconnect();
|
|
6351
6383
|
this.googlePayButtonResizeObserver = null;
|
|
6352
6384
|
this.googlePayButtonContainer?.remove();
|
|
@@ -6723,6 +6755,7 @@ class ExpressCheckoutElementImpl {
|
|
|
6723
6755
|
}
|
|
6724
6756
|
}
|
|
6725
6757
|
const OPTION_KEYS = new Set([
|
|
6758
|
+
'paymentMethodOrder',
|
|
6726
6759
|
'paymentMethods',
|
|
6727
6760
|
'layout',
|
|
6728
6761
|
'buttonType',
|
|
@@ -6780,6 +6813,7 @@ function validateOptions(options) {
|
|
|
6780
6813
|
if (!isRecord(rawOptions) || Object.keys(rawOptions).some((key) => !OPTION_KEYS.has(key))) {
|
|
6781
6814
|
throw new Error('[Paypercut Elements] Express Checkout options are invalid.');
|
|
6782
6815
|
}
|
|
6816
|
+
validatePaymentMethodOrder(options.paymentMethodOrder);
|
|
6783
6817
|
if (options.buttonHeight !== undefined) {
|
|
6784
6818
|
if (typeof options.buttonHeight !== 'number' ||
|
|
6785
6819
|
!Number.isSafeInteger(options.buttonHeight) ||
|
|
@@ -6932,11 +6966,25 @@ function validateClickResolveOptions(options) {
|
|
|
6932
6966
|
: {}),
|
|
6933
6967
|
});
|
|
6934
6968
|
}
|
|
6969
|
+
function validatePaymentMethodOrder(order) {
|
|
6970
|
+
if (order !== undefined &&
|
|
6971
|
+
(!Array.isArray(order) ||
|
|
6972
|
+
[...order].some((wallet) => wallet !== 'apple_pay' && wallet !== 'google_pay') ||
|
|
6973
|
+
new Set(order).size !== order.length)) {
|
|
6974
|
+
throw invalidOptions();
|
|
6975
|
+
}
|
|
6976
|
+
}
|
|
6935
6977
|
function validateElementUpdateOptions(options) {
|
|
6936
6978
|
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.');
|
|
6979
|
+
throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details or wallet order.');
|
|
6938
6980
|
}
|
|
6939
|
-
|
|
6981
|
+
const { paymentMethodOrder, ...checkoutDetails } = options;
|
|
6982
|
+
validatePaymentMethodOrder(paymentMethodOrder);
|
|
6983
|
+
const validated = validateClickResolveOptions(checkoutDetails);
|
|
6984
|
+
return {
|
|
6985
|
+
...validated,
|
|
6986
|
+
...('paymentMethodOrder' in options ? { paymentMethodOrder: paymentMethodOrder?.slice() } : {}),
|
|
6987
|
+
};
|
|
6940
6988
|
}
|
|
6941
6989
|
function validateShippingUpdate(update) {
|
|
6942
6990
|
if (update === undefined)
|