@paypercut/checkout-js 1.4.2 → 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 +74 -24
- 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 +74 -24
- 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/dist/index.d.cts
CHANGED
|
@@ -692,6 +692,8 @@ interface ExpressCheckoutPaymentMethodPreview {
|
|
|
692
692
|
/** Controls whether a wallet is considered when the hosted component checks availability. */
|
|
693
693
|
type ExpressCheckoutPaymentMethodVisibility = 'auto' | 'always' | 'never';
|
|
694
694
|
interface ExpressCheckoutElementOptions {
|
|
695
|
+
/** Preferred wallet order. Other available wallets follow in their default order. */
|
|
696
|
+
paymentMethodOrder?: ExpressCheckoutWallet[];
|
|
695
697
|
paymentMethods?: {
|
|
696
698
|
applePay?: ExpressCheckoutPaymentMethodVisibility;
|
|
697
699
|
googlePay?: ExpressCheckoutPaymentMethodVisibility;
|
|
@@ -802,8 +804,10 @@ interface ExpressCheckoutClickEvent {
|
|
|
802
804
|
resolve(options?: ExpressCheckoutClickResolveOptions): void;
|
|
803
805
|
reject(): void;
|
|
804
806
|
}
|
|
805
|
-
/** Mutable checkout details for an
|
|
807
|
+
/** Mutable checkout details and wallet order for an idle Express Checkout Element. */
|
|
806
808
|
interface ExpressCheckoutElementUpdateOptions {
|
|
809
|
+
/** Replaces the wallet preference list. An empty list restores the default order. */
|
|
810
|
+
paymentMethodOrder?: ExpressCheckoutWallet[];
|
|
807
811
|
lineItems?: ExpressCheckoutLineItem[];
|
|
808
812
|
emailRequired?: boolean;
|
|
809
813
|
phoneNumberRequired?: boolean;
|
|
@@ -816,7 +820,7 @@ interface ExpressCheckoutElementUpdateOptions {
|
|
|
816
820
|
* Current checkout details supplied immediately before a wallet is opened.
|
|
817
821
|
* The amount and wallet details are applied to the same attempt atomically.
|
|
818
822
|
*/
|
|
819
|
-
interface ExpressCheckoutClickResolveOptions extends ExpressCheckoutElementUpdateOptions {
|
|
823
|
+
interface ExpressCheckoutClickResolveOptions extends Omit<ExpressCheckoutElementUpdateOptions, 'paymentMethodOrder'> {
|
|
820
824
|
/** Authoritative order total in the group's currency, in minor units. */
|
|
821
825
|
amount?: number;
|
|
822
826
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -692,6 +692,8 @@ interface ExpressCheckoutPaymentMethodPreview {
|
|
|
692
692
|
/** Controls whether a wallet is considered when the hosted component checks availability. */
|
|
693
693
|
type ExpressCheckoutPaymentMethodVisibility = 'auto' | 'always' | 'never';
|
|
694
694
|
interface ExpressCheckoutElementOptions {
|
|
695
|
+
/** Preferred wallet order. Other available wallets follow in their default order. */
|
|
696
|
+
paymentMethodOrder?: ExpressCheckoutWallet[];
|
|
695
697
|
paymentMethods?: {
|
|
696
698
|
applePay?: ExpressCheckoutPaymentMethodVisibility;
|
|
697
699
|
googlePay?: ExpressCheckoutPaymentMethodVisibility;
|
|
@@ -802,8 +804,10 @@ interface ExpressCheckoutClickEvent {
|
|
|
802
804
|
resolve(options?: ExpressCheckoutClickResolveOptions): void;
|
|
803
805
|
reject(): void;
|
|
804
806
|
}
|
|
805
|
-
/** Mutable checkout details for an
|
|
807
|
+
/** Mutable checkout details and wallet order for an idle Express Checkout Element. */
|
|
806
808
|
interface ExpressCheckoutElementUpdateOptions {
|
|
809
|
+
/** Replaces the wallet preference list. An empty list restores the default order. */
|
|
810
|
+
paymentMethodOrder?: ExpressCheckoutWallet[];
|
|
807
811
|
lineItems?: ExpressCheckoutLineItem[];
|
|
808
812
|
emailRequired?: boolean;
|
|
809
813
|
phoneNumberRequired?: boolean;
|
|
@@ -816,7 +820,7 @@ interface ExpressCheckoutElementUpdateOptions {
|
|
|
816
820
|
* Current checkout details supplied immediately before a wallet is opened.
|
|
817
821
|
* The amount and wallet details are applied to the same attempt atomically.
|
|
818
822
|
*/
|
|
819
|
-
interface ExpressCheckoutClickResolveOptions extends ExpressCheckoutElementUpdateOptions {
|
|
823
|
+
interface ExpressCheckoutClickResolveOptions extends Omit<ExpressCheckoutElementUpdateOptions, 'paymentMethodOrder'> {
|
|
820
824
|
/** Authoritative order total in the group's currency, in minor units. */
|
|
821
825
|
amount?: number;
|
|
822
826
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -692,6 +692,8 @@ interface ExpressCheckoutPaymentMethodPreview {
|
|
|
692
692
|
/** Controls whether a wallet is considered when the hosted component checks availability. */
|
|
693
693
|
type ExpressCheckoutPaymentMethodVisibility = 'auto' | 'always' | 'never';
|
|
694
694
|
interface ExpressCheckoutElementOptions {
|
|
695
|
+
/** Preferred wallet order. Other available wallets follow in their default order. */
|
|
696
|
+
paymentMethodOrder?: ExpressCheckoutWallet[];
|
|
695
697
|
paymentMethods?: {
|
|
696
698
|
applePay?: ExpressCheckoutPaymentMethodVisibility;
|
|
697
699
|
googlePay?: ExpressCheckoutPaymentMethodVisibility;
|
|
@@ -802,8 +804,10 @@ interface ExpressCheckoutClickEvent {
|
|
|
802
804
|
resolve(options?: ExpressCheckoutClickResolveOptions): void;
|
|
803
805
|
reject(): void;
|
|
804
806
|
}
|
|
805
|
-
/** Mutable checkout details for an
|
|
807
|
+
/** Mutable checkout details and wallet order for an idle Express Checkout Element. */
|
|
806
808
|
interface ExpressCheckoutElementUpdateOptions {
|
|
809
|
+
/** Replaces the wallet preference list. An empty list restores the default order. */
|
|
810
|
+
paymentMethodOrder?: ExpressCheckoutWallet[];
|
|
807
811
|
lineItems?: ExpressCheckoutLineItem[];
|
|
808
812
|
emailRequired?: boolean;
|
|
809
813
|
phoneNumberRequired?: boolean;
|
|
@@ -816,7 +820,7 @@ interface ExpressCheckoutElementUpdateOptions {
|
|
|
816
820
|
* Current checkout details supplied immediately before a wallet is opened.
|
|
817
821
|
* The amount and wallet details are applied to the same attempt atomically.
|
|
818
822
|
*/
|
|
819
|
-
interface ExpressCheckoutClickResolveOptions extends ExpressCheckoutElementUpdateOptions {
|
|
823
|
+
interface ExpressCheckoutClickResolveOptions extends Omit<ExpressCheckoutElementUpdateOptions, 'paymentMethodOrder'> {
|
|
820
824
|
/** Authoritative order total in the group's currency, in minor units. */
|
|
821
825
|
amount?: number;
|
|
822
826
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -100,7 +100,7 @@ class Emitter {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
const SDK_VERSION = "1.4.
|
|
103
|
+
const SDK_VERSION = "1.4.4";
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* Build-time configuration
|
|
@@ -3234,6 +3234,9 @@ function buildExpressCheckoutFrameUrl(input) {
|
|
|
3234
3234
|
params.set('mode', input.elementsOptions.mode);
|
|
3235
3235
|
params.set('amount', String(input.elementsOptions.amount));
|
|
3236
3236
|
params.set('currency', input.elementsOptions.currency);
|
|
3237
|
+
if (input.options.paymentMethodOrder !== undefined) {
|
|
3238
|
+
params.set('publicOptions[paymentMethodOrder]', input.options.paymentMethodOrder.join(','));
|
|
3239
|
+
}
|
|
3237
3240
|
set(params, 'publicOptions[paymentMethods][applePay]', input.options.paymentMethods?.applePay);
|
|
3238
3241
|
set(params, 'publicOptions[paymentMethods][googlePay]', input.options.paymentMethods?.googlePay);
|
|
3239
3242
|
set(params, 'publicOptions[layout][maxColumns]', input.options.layout?.maxColumns);
|
|
@@ -4815,7 +4818,9 @@ class CardElementImpl {
|
|
|
4815
4818
|
border: '0',
|
|
4816
4819
|
display: 'block',
|
|
4817
4820
|
overflow: 'hidden',
|
|
4818
|
-
|
|
4821
|
+
// Hosted Elements uses a normal document color scheme. A mismatch makes
|
|
4822
|
+
// browsers paint an opaque canvas even with transparent html/body styles.
|
|
4823
|
+
colorScheme: 'normal',
|
|
4819
4824
|
transition: 'height 350ms ease-in-out, opacity 400ms ease-in-out 100ms',
|
|
4820
4825
|
willChange: 'height, opacity',
|
|
4821
4826
|
});
|
|
@@ -5150,6 +5155,38 @@ function patchApplePayModalFocus(modal, attempts = 0) {
|
|
|
5150
5155
|
root.appendChild(style);
|
|
5151
5156
|
}
|
|
5152
5157
|
|
|
5158
|
+
/** Merchant-document layout shared by the hosted frame and its iOS Google Pay button. */
|
|
5159
|
+
function createExpressCheckoutMount(frame) {
|
|
5160
|
+
const mount = document.createElement('div');
|
|
5161
|
+
mount.dataset.paypercutElementsExpressMount = '';
|
|
5162
|
+
Object.assign(mount.style, {
|
|
5163
|
+
position: 'relative',
|
|
5164
|
+
display: 'block',
|
|
5165
|
+
width: '100%',
|
|
5166
|
+
minWidth: '0',
|
|
5167
|
+
margin: '0',
|
|
5168
|
+
padding: '0',
|
|
5169
|
+
border: '0',
|
|
5170
|
+
});
|
|
5171
|
+
mount.appendChild(frame);
|
|
5172
|
+
return mount;
|
|
5173
|
+
}
|
|
5174
|
+
function createGooglePayButtonSurface(componentId) {
|
|
5175
|
+
const container = document.createElement('div');
|
|
5176
|
+
container.dataset.paypercutElementsGooglePayButton = componentId;
|
|
5177
|
+
Object.assign(container.style, {
|
|
5178
|
+
position: 'absolute',
|
|
5179
|
+
margin: '0',
|
|
5180
|
+
padding: '0',
|
|
5181
|
+
border: '0',
|
|
5182
|
+
overflow: 'hidden',
|
|
5183
|
+
zIndex: '2147483000',
|
|
5184
|
+
pointerEvents: 'auto',
|
|
5185
|
+
visibility: 'hidden',
|
|
5186
|
+
});
|
|
5187
|
+
return container;
|
|
5188
|
+
}
|
|
5189
|
+
|
|
5153
5190
|
const GOOGLE_PAY_POPUP_RECOVERY_POLICY = {
|
|
5154
5191
|
closedPollIntervalMs: 250,
|
|
5155
5192
|
providerSettlementGraceMs: 3500,
|
|
@@ -5328,6 +5365,7 @@ class ExpressCheckoutElementImpl {
|
|
|
5328
5365
|
this.googlePayAuthorization = null;
|
|
5329
5366
|
this.googlePayButtonTarget = null;
|
|
5330
5367
|
this.googlePayButtonContainer = null;
|
|
5368
|
+
this.mountSurface = null;
|
|
5331
5369
|
this.googlePayButtonGeneration = 0;
|
|
5332
5370
|
this.googlePayButtonPositionFrame = null;
|
|
5333
5371
|
this.googlePayButtonResizeObserver = null;
|
|
@@ -5376,7 +5414,8 @@ class ExpressCheckoutElementImpl {
|
|
|
5376
5414
|
this.group.markComponentMounted();
|
|
5377
5415
|
window.addEventListener('message', this.messageHandler);
|
|
5378
5416
|
this.group.ensureController();
|
|
5379
|
-
|
|
5417
|
+
this.mountSurface = createExpressCheckoutMount(iframe);
|
|
5418
|
+
container.appendChild(this.mountSurface);
|
|
5380
5419
|
this.registerDeveloperAssistant();
|
|
5381
5420
|
}
|
|
5382
5421
|
on(event, handler) {
|
|
@@ -5390,6 +5429,9 @@ class ExpressCheckoutElementImpl {
|
|
|
5390
5429
|
throw new Error('[Paypercut Elements] Cannot update Express Checkout while a wallet attempt is active.');
|
|
5391
5430
|
}
|
|
5392
5431
|
const validated = validateElementUpdateOptions(options);
|
|
5432
|
+
if ('paymentMethodOrder' in validated && this.previewTransitionActive) {
|
|
5433
|
+
throw new Error('[Paypercut Elements] Cannot update wallet order while an Appearance preview is active.');
|
|
5434
|
+
}
|
|
5393
5435
|
this.options = validateOptions({ ...this.options, ...validated });
|
|
5394
5436
|
if (this.componentRevision === Number.MAX_SAFE_INTEGER) {
|
|
5395
5437
|
throw new Error('[Paypercut Elements] The component update revision limit has been reached.');
|
|
@@ -5679,6 +5721,8 @@ class ExpressCheckoutElementImpl {
|
|
|
5679
5721
|
}
|
|
5680
5722
|
this.iframe?.remove();
|
|
5681
5723
|
this.iframe = null;
|
|
5724
|
+
this.mountSurface?.remove();
|
|
5725
|
+
this.mountSurface = null;
|
|
5682
5726
|
this.connectedFrame = null;
|
|
5683
5727
|
this.mounted = false;
|
|
5684
5728
|
this.emitter.clear();
|
|
@@ -6022,8 +6066,7 @@ class ExpressCheckoutElementImpl {
|
|
|
6022
6066
|
// merchant click decision returns. Keep the request identity until the
|
|
6023
6067
|
// controller's wallet_cancel arrives so integrations receive their
|
|
6024
6068
|
// normal cancel lifecycle and can release their own attempt lock.
|
|
6025
|
-
if (wallet !== 'google_pay' ||
|
|
6026
|
-
this.googlePayRequestId !== requestId) {
|
|
6069
|
+
if (wallet !== 'google_pay' || this.googlePayRequestId !== requestId) {
|
|
6027
6070
|
this.activeAttempt = null;
|
|
6028
6071
|
this.activeOptions = null;
|
|
6029
6072
|
}
|
|
@@ -6257,18 +6300,9 @@ class ExpressCheckoutElementImpl {
|
|
|
6257
6300
|
}
|
|
6258
6301
|
mountGooglePayButton(client, target, request, allowedPaymentMethods) {
|
|
6259
6302
|
this.removeGooglePayButton();
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
position: 'fixed',
|
|
6264
|
-
margin: '0',
|
|
6265
|
-
padding: '0',
|
|
6266
|
-
border: '0',
|
|
6267
|
-
overflow: 'hidden',
|
|
6268
|
-
zIndex: '2147483000',
|
|
6269
|
-
pointerEvents: 'auto',
|
|
6270
|
-
visibility: 'hidden',
|
|
6271
|
-
});
|
|
6303
|
+
if (!this.mountSurface)
|
|
6304
|
+
return;
|
|
6305
|
+
const container = createGooglePayButtonSurface(this.componentId);
|
|
6272
6306
|
const button = client.createButton({
|
|
6273
6307
|
buttonColor: target.buttonColor,
|
|
6274
6308
|
buttonType: target.buttonType,
|
|
@@ -6294,10 +6328,9 @@ class ExpressCheckoutElementImpl {
|
|
|
6294
6328
|
});
|
|
6295
6329
|
Object.assign(button.style, { width: '100%', height: '100%', margin: '0' });
|
|
6296
6330
|
container.appendChild(button);
|
|
6297
|
-
|
|
6331
|
+
this.mountSurface.appendChild(container);
|
|
6298
6332
|
this.googlePayButtonContainer = container;
|
|
6299
6333
|
window.addEventListener('resize', this.googlePayButtonPositionHandler);
|
|
6300
|
-
window.addEventListener('scroll', this.googlePayButtonPositionHandler, true);
|
|
6301
6334
|
if (typeof ResizeObserver !== 'undefined' && this.iframe) {
|
|
6302
6335
|
this.googlePayButtonResizeObserver = new ResizeObserver(this.googlePayButtonPositionHandler);
|
|
6303
6336
|
this.googlePayButtonResizeObserver.observe(this.iframe);
|
|
@@ -6316,8 +6349,10 @@ class ExpressCheckoutElementImpl {
|
|
|
6316
6349
|
return;
|
|
6317
6350
|
}
|
|
6318
6351
|
const frameRect = iframe.getBoundingClientRect();
|
|
6319
|
-
|
|
6320
|
-
|
|
6352
|
+
// The surface shares the frame's layout origin. Scrolling and merchant
|
|
6353
|
+
// layout shifts move both together without waiting for JS scroll/rAF work.
|
|
6354
|
+
const left = target.target.x;
|
|
6355
|
+
const top = target.target.y;
|
|
6321
6356
|
Object.assign(container.style, {
|
|
6322
6357
|
left: `${left}px`,
|
|
6323
6358
|
top: `${top}px`,
|
|
@@ -6339,7 +6374,6 @@ class ExpressCheckoutElementImpl {
|
|
|
6339
6374
|
this.googlePayButtonPositionFrame = null;
|
|
6340
6375
|
}
|
|
6341
6376
|
window.removeEventListener('resize', this.googlePayButtonPositionHandler);
|
|
6342
|
-
window.removeEventListener('scroll', this.googlePayButtonPositionHandler, true);
|
|
6343
6377
|
this.googlePayButtonResizeObserver?.disconnect();
|
|
6344
6378
|
this.googlePayButtonResizeObserver = null;
|
|
6345
6379
|
this.googlePayButtonContainer?.remove();
|
|
@@ -6716,6 +6750,7 @@ class ExpressCheckoutElementImpl {
|
|
|
6716
6750
|
}
|
|
6717
6751
|
}
|
|
6718
6752
|
const OPTION_KEYS = new Set([
|
|
6753
|
+
'paymentMethodOrder',
|
|
6719
6754
|
'paymentMethods',
|
|
6720
6755
|
'layout',
|
|
6721
6756
|
'buttonType',
|
|
@@ -6773,6 +6808,7 @@ function validateOptions(options) {
|
|
|
6773
6808
|
if (!isRecord(rawOptions) || Object.keys(rawOptions).some((key) => !OPTION_KEYS.has(key))) {
|
|
6774
6809
|
throw new Error('[Paypercut Elements] Express Checkout options are invalid.');
|
|
6775
6810
|
}
|
|
6811
|
+
validatePaymentMethodOrder(options.paymentMethodOrder);
|
|
6776
6812
|
if (options.buttonHeight !== undefined) {
|
|
6777
6813
|
if (typeof options.buttonHeight !== 'number' ||
|
|
6778
6814
|
!Number.isSafeInteger(options.buttonHeight) ||
|
|
@@ -6925,11 +6961,25 @@ function validateClickResolveOptions(options) {
|
|
|
6925
6961
|
: {}),
|
|
6926
6962
|
});
|
|
6927
6963
|
}
|
|
6964
|
+
function validatePaymentMethodOrder(order) {
|
|
6965
|
+
if (order !== undefined &&
|
|
6966
|
+
(!Array.isArray(order) ||
|
|
6967
|
+
[...order].some((wallet) => wallet !== 'apple_pay' && wallet !== 'google_pay') ||
|
|
6968
|
+
new Set(order).size !== order.length)) {
|
|
6969
|
+
throw invalidOptions();
|
|
6970
|
+
}
|
|
6971
|
+
}
|
|
6928
6972
|
function validateElementUpdateOptions(options) {
|
|
6929
6973
|
if (!isRecord(options) || Object.keys(options).length === 0 || 'amount' in options) {
|
|
6930
|
-
throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details.');
|
|
6974
|
+
throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details or wallet order.');
|
|
6931
6975
|
}
|
|
6932
|
-
|
|
6976
|
+
const { paymentMethodOrder, ...checkoutDetails } = options;
|
|
6977
|
+
validatePaymentMethodOrder(paymentMethodOrder);
|
|
6978
|
+
const validated = validateClickResolveOptions(checkoutDetails);
|
|
6979
|
+
return {
|
|
6980
|
+
...validated,
|
|
6981
|
+
...('paymentMethodOrder' in options ? { paymentMethodOrder: paymentMethodOrder?.slice() } : {}),
|
|
6982
|
+
};
|
|
6933
6983
|
}
|
|
6934
6984
|
function validateShippingUpdate(update) {
|
|
6935
6985
|
if (update === undefined)
|