@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/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 already mounted Express Checkout Element. */
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 already mounted Express Checkout Element. */
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 already mounted Express Checkout Element. */
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.3";
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);
@@ -5152,6 +5155,38 @@ function patchApplePayModalFocus(modal, attempts = 0) {
5152
5155
  root.appendChild(style);
5153
5156
  }
5154
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
+
5155
5190
  const GOOGLE_PAY_POPUP_RECOVERY_POLICY = {
5156
5191
  closedPollIntervalMs: 250,
5157
5192
  providerSettlementGraceMs: 3500,
@@ -5330,6 +5365,7 @@ class ExpressCheckoutElementImpl {
5330
5365
  this.googlePayAuthorization = null;
5331
5366
  this.googlePayButtonTarget = null;
5332
5367
  this.googlePayButtonContainer = null;
5368
+ this.mountSurface = null;
5333
5369
  this.googlePayButtonGeneration = 0;
5334
5370
  this.googlePayButtonPositionFrame = null;
5335
5371
  this.googlePayButtonResizeObserver = null;
@@ -5378,7 +5414,8 @@ class ExpressCheckoutElementImpl {
5378
5414
  this.group.markComponentMounted();
5379
5415
  window.addEventListener('message', this.messageHandler);
5380
5416
  this.group.ensureController();
5381
- container.appendChild(iframe);
5417
+ this.mountSurface = createExpressCheckoutMount(iframe);
5418
+ container.appendChild(this.mountSurface);
5382
5419
  this.registerDeveloperAssistant();
5383
5420
  }
5384
5421
  on(event, handler) {
@@ -5392,6 +5429,9 @@ class ExpressCheckoutElementImpl {
5392
5429
  throw new Error('[Paypercut Elements] Cannot update Express Checkout while a wallet attempt is active.');
5393
5430
  }
5394
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
+ }
5395
5435
  this.options = validateOptions({ ...this.options, ...validated });
5396
5436
  if (this.componentRevision === Number.MAX_SAFE_INTEGER) {
5397
5437
  throw new Error('[Paypercut Elements] The component update revision limit has been reached.');
@@ -5681,6 +5721,8 @@ class ExpressCheckoutElementImpl {
5681
5721
  }
5682
5722
  this.iframe?.remove();
5683
5723
  this.iframe = null;
5724
+ this.mountSurface?.remove();
5725
+ this.mountSurface = null;
5684
5726
  this.connectedFrame = null;
5685
5727
  this.mounted = false;
5686
5728
  this.emitter.clear();
@@ -6024,8 +6066,7 @@ class ExpressCheckoutElementImpl {
6024
6066
  // merchant click decision returns. Keep the request identity until the
6025
6067
  // controller's wallet_cancel arrives so integrations receive their
6026
6068
  // normal cancel lifecycle and can release their own attempt lock.
6027
- if (wallet !== 'google_pay' ||
6028
- this.googlePayRequestId !== requestId) {
6069
+ if (wallet !== 'google_pay' || this.googlePayRequestId !== requestId) {
6029
6070
  this.activeAttempt = null;
6030
6071
  this.activeOptions = null;
6031
6072
  }
@@ -6259,18 +6300,9 @@ class ExpressCheckoutElementImpl {
6259
6300
  }
6260
6301
  mountGooglePayButton(client, target, request, allowedPaymentMethods) {
6261
6302
  this.removeGooglePayButton();
6262
- const container = document.createElement('div');
6263
- container.dataset.paypercutElementsGooglePayButton = this.componentId;
6264
- Object.assign(container.style, {
6265
- position: 'fixed',
6266
- margin: '0',
6267
- padding: '0',
6268
- border: '0',
6269
- overflow: 'hidden',
6270
- zIndex: '2147483000',
6271
- pointerEvents: 'auto',
6272
- visibility: 'hidden',
6273
- });
6303
+ if (!this.mountSurface)
6304
+ return;
6305
+ const container = createGooglePayButtonSurface(this.componentId);
6274
6306
  const button = client.createButton({
6275
6307
  buttonColor: target.buttonColor,
6276
6308
  buttonType: target.buttonType,
@@ -6296,10 +6328,9 @@ class ExpressCheckoutElementImpl {
6296
6328
  });
6297
6329
  Object.assign(button.style, { width: '100%', height: '100%', margin: '0' });
6298
6330
  container.appendChild(button);
6299
- document.body.appendChild(container);
6331
+ this.mountSurface.appendChild(container);
6300
6332
  this.googlePayButtonContainer = container;
6301
6333
  window.addEventListener('resize', this.googlePayButtonPositionHandler);
6302
- window.addEventListener('scroll', this.googlePayButtonPositionHandler, true);
6303
6334
  if (typeof ResizeObserver !== 'undefined' && this.iframe) {
6304
6335
  this.googlePayButtonResizeObserver = new ResizeObserver(this.googlePayButtonPositionHandler);
6305
6336
  this.googlePayButtonResizeObserver.observe(this.iframe);
@@ -6318,8 +6349,10 @@ class ExpressCheckoutElementImpl {
6318
6349
  return;
6319
6350
  }
6320
6351
  const frameRect = iframe.getBoundingClientRect();
6321
- const left = frameRect.left + target.target.x;
6322
- const top = frameRect.top + target.target.y;
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;
6323
6356
  Object.assign(container.style, {
6324
6357
  left: `${left}px`,
6325
6358
  top: `${top}px`,
@@ -6341,7 +6374,6 @@ class ExpressCheckoutElementImpl {
6341
6374
  this.googlePayButtonPositionFrame = null;
6342
6375
  }
6343
6376
  window.removeEventListener('resize', this.googlePayButtonPositionHandler);
6344
- window.removeEventListener('scroll', this.googlePayButtonPositionHandler, true);
6345
6377
  this.googlePayButtonResizeObserver?.disconnect();
6346
6378
  this.googlePayButtonResizeObserver = null;
6347
6379
  this.googlePayButtonContainer?.remove();
@@ -6718,6 +6750,7 @@ class ExpressCheckoutElementImpl {
6718
6750
  }
6719
6751
  }
6720
6752
  const OPTION_KEYS = new Set([
6753
+ 'paymentMethodOrder',
6721
6754
  'paymentMethods',
6722
6755
  'layout',
6723
6756
  'buttonType',
@@ -6775,6 +6808,7 @@ function validateOptions(options) {
6775
6808
  if (!isRecord(rawOptions) || Object.keys(rawOptions).some((key) => !OPTION_KEYS.has(key))) {
6776
6809
  throw new Error('[Paypercut Elements] Express Checkout options are invalid.');
6777
6810
  }
6811
+ validatePaymentMethodOrder(options.paymentMethodOrder);
6778
6812
  if (options.buttonHeight !== undefined) {
6779
6813
  if (typeof options.buttonHeight !== 'number' ||
6780
6814
  !Number.isSafeInteger(options.buttonHeight) ||
@@ -6927,11 +6961,25 @@ function validateClickResolveOptions(options) {
6927
6961
  : {}),
6928
6962
  });
6929
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
+ }
6930
6972
  function validateElementUpdateOptions(options) {
6931
6973
  if (!isRecord(options) || Object.keys(options).length === 0 || 'amount' in options) {
6932
- 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.');
6933
6975
  }
6934
- return validateClickResolveOptions(options);
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
+ };
6935
6983
  }
6936
6984
  function validateShippingUpdate(update) {
6937
6985
  if (update === undefined)