@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/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.5";
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);
@@ -4766,6 +4769,7 @@ class CardElementImpl {
4766
4769
  this.handleInitializationTimeout();
4767
4770
  return;
4768
4771
  }
4772
+ this.group.retryStalledControllerInitialization();
4769
4773
  const replacement = this.createFrame();
4770
4774
  const previousGeneration = this.componentGeneration;
4771
4775
  this.componentGeneration += 1;
@@ -5152,6 +5156,38 @@ function patchApplePayModalFocus(modal, attempts = 0) {
5152
5156
  root.appendChild(style);
5153
5157
  }
5154
5158
 
5159
+ /** Merchant-document layout shared by the hosted frame and its iOS Google Pay button. */
5160
+ function createExpressCheckoutMount(frame) {
5161
+ const mount = document.createElement('div');
5162
+ mount.dataset.paypercutElementsExpressMount = '';
5163
+ Object.assign(mount.style, {
5164
+ position: 'relative',
5165
+ display: 'block',
5166
+ width: '100%',
5167
+ minWidth: '0',
5168
+ margin: '0',
5169
+ padding: '0',
5170
+ border: '0',
5171
+ });
5172
+ mount.appendChild(frame);
5173
+ return mount;
5174
+ }
5175
+ function createGooglePayButtonSurface(componentId) {
5176
+ const container = document.createElement('div');
5177
+ container.dataset.paypercutElementsGooglePayButton = componentId;
5178
+ Object.assign(container.style, {
5179
+ position: 'absolute',
5180
+ margin: '0',
5181
+ padding: '0',
5182
+ border: '0',
5183
+ overflow: 'hidden',
5184
+ zIndex: '2147483000',
5185
+ pointerEvents: 'auto',
5186
+ visibility: 'hidden',
5187
+ });
5188
+ return container;
5189
+ }
5190
+
5155
5191
  const GOOGLE_PAY_POPUP_RECOVERY_POLICY = {
5156
5192
  closedPollIntervalMs: 250,
5157
5193
  providerSettlementGraceMs: 3500,
@@ -5330,6 +5366,7 @@ class ExpressCheckoutElementImpl {
5330
5366
  this.googlePayAuthorization = null;
5331
5367
  this.googlePayButtonTarget = null;
5332
5368
  this.googlePayButtonContainer = null;
5369
+ this.mountSurface = null;
5333
5370
  this.googlePayButtonGeneration = 0;
5334
5371
  this.googlePayButtonPositionFrame = null;
5335
5372
  this.googlePayButtonResizeObserver = null;
@@ -5378,7 +5415,8 @@ class ExpressCheckoutElementImpl {
5378
5415
  this.group.markComponentMounted();
5379
5416
  window.addEventListener('message', this.messageHandler);
5380
5417
  this.group.ensureController();
5381
- container.appendChild(iframe);
5418
+ this.mountSurface = createExpressCheckoutMount(iframe);
5419
+ container.appendChild(this.mountSurface);
5382
5420
  this.registerDeveloperAssistant();
5383
5421
  }
5384
5422
  on(event, handler) {
@@ -5392,6 +5430,9 @@ class ExpressCheckoutElementImpl {
5392
5430
  throw new Error('[Paypercut Elements] Cannot update Express Checkout while a wallet attempt is active.');
5393
5431
  }
5394
5432
  const validated = validateElementUpdateOptions(options);
5433
+ if ('paymentMethodOrder' in validated && this.previewTransitionActive) {
5434
+ throw new Error('[Paypercut Elements] Cannot update wallet order while an Appearance preview is active.');
5435
+ }
5395
5436
  this.options = validateOptions({ ...this.options, ...validated });
5396
5437
  if (this.componentRevision === Number.MAX_SAFE_INTEGER) {
5397
5438
  throw new Error('[Paypercut Elements] The component update revision limit has been reached.');
@@ -5681,6 +5722,8 @@ class ExpressCheckoutElementImpl {
5681
5722
  }
5682
5723
  this.iframe?.remove();
5683
5724
  this.iframe = null;
5725
+ this.mountSurface?.remove();
5726
+ this.mountSurface = null;
5684
5727
  this.connectedFrame = null;
5685
5728
  this.mounted = false;
5686
5729
  this.emitter.clear();
@@ -5688,6 +5731,7 @@ class ExpressCheckoutElementImpl {
5688
5731
  }
5689
5732
  createFrame(options = this.options) {
5690
5733
  const iframe = document.createElement('iframe');
5734
+ const disableAnimations = this.group.getRenderableElementsOptions().appearance?.disableAnimations === true;
5691
5735
  iframe.id = `paypercut-express-checkout-element-${this.componentId}`;
5692
5736
  iframe.title = 'Express checkout';
5693
5737
  iframe.referrerPolicy = 'origin';
@@ -5716,8 +5760,8 @@ class ExpressCheckoutElementImpl {
5716
5760
  display: 'block',
5717
5761
  overflow: 'hidden',
5718
5762
  colorScheme: 'light dark',
5719
- transition: 'height 250ms ease-in-out, opacity 250ms ease-in-out',
5720
- willChange: 'height, opacity',
5763
+ transition: disableAnimations ? 'none' : 'height 250ms ease-in-out, opacity 250ms ease-in-out',
5764
+ willChange: disableAnimations ? 'auto' : 'height, opacity',
5721
5765
  });
5722
5766
  return iframe;
5723
5767
  }
@@ -6024,8 +6068,7 @@ class ExpressCheckoutElementImpl {
6024
6068
  // merchant click decision returns. Keep the request identity until the
6025
6069
  // controller's wallet_cancel arrives so integrations receive their
6026
6070
  // normal cancel lifecycle and can release their own attempt lock.
6027
- if (wallet !== 'google_pay' ||
6028
- this.googlePayRequestId !== requestId) {
6071
+ if (wallet !== 'google_pay' || this.googlePayRequestId !== requestId) {
6029
6072
  this.activeAttempt = null;
6030
6073
  this.activeOptions = null;
6031
6074
  }
@@ -6259,18 +6302,9 @@ class ExpressCheckoutElementImpl {
6259
6302
  }
6260
6303
  mountGooglePayButton(client, target, request, allowedPaymentMethods) {
6261
6304
  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
- });
6305
+ if (!this.mountSurface)
6306
+ return;
6307
+ const container = createGooglePayButtonSurface(this.componentId);
6274
6308
  const button = client.createButton({
6275
6309
  buttonColor: target.buttonColor,
6276
6310
  buttonType: target.buttonType,
@@ -6296,10 +6330,9 @@ class ExpressCheckoutElementImpl {
6296
6330
  });
6297
6331
  Object.assign(button.style, { width: '100%', height: '100%', margin: '0' });
6298
6332
  container.appendChild(button);
6299
- document.body.appendChild(container);
6333
+ this.mountSurface.appendChild(container);
6300
6334
  this.googlePayButtonContainer = container;
6301
6335
  window.addEventListener('resize', this.googlePayButtonPositionHandler);
6302
- window.addEventListener('scroll', this.googlePayButtonPositionHandler, true);
6303
6336
  if (typeof ResizeObserver !== 'undefined' && this.iframe) {
6304
6337
  this.googlePayButtonResizeObserver = new ResizeObserver(this.googlePayButtonPositionHandler);
6305
6338
  this.googlePayButtonResizeObserver.observe(this.iframe);
@@ -6318,8 +6351,10 @@ class ExpressCheckoutElementImpl {
6318
6351
  return;
6319
6352
  }
6320
6353
  const frameRect = iframe.getBoundingClientRect();
6321
- const left = frameRect.left + target.target.x;
6322
- const top = frameRect.top + target.target.y;
6354
+ // The surface shares the frame's layout origin. Scrolling and merchant
6355
+ // layout shifts move both together without waiting for JS scroll/rAF work.
6356
+ const left = target.target.x;
6357
+ const top = target.target.y;
6323
6358
  Object.assign(container.style, {
6324
6359
  left: `${left}px`,
6325
6360
  top: `${top}px`,
@@ -6341,7 +6376,6 @@ class ExpressCheckoutElementImpl {
6341
6376
  this.googlePayButtonPositionFrame = null;
6342
6377
  }
6343
6378
  window.removeEventListener('resize', this.googlePayButtonPositionHandler);
6344
- window.removeEventListener('scroll', this.googlePayButtonPositionHandler, true);
6345
6379
  this.googlePayButtonResizeObserver?.disconnect();
6346
6380
  this.googlePayButtonResizeObserver = null;
6347
6381
  this.googlePayButtonContainer?.remove();
@@ -6718,6 +6752,7 @@ class ExpressCheckoutElementImpl {
6718
6752
  }
6719
6753
  }
6720
6754
  const OPTION_KEYS = new Set([
6755
+ 'paymentMethodOrder',
6721
6756
  'paymentMethods',
6722
6757
  'layout',
6723
6758
  'buttonType',
@@ -6775,6 +6810,7 @@ function validateOptions(options) {
6775
6810
  if (!isRecord(rawOptions) || Object.keys(rawOptions).some((key) => !OPTION_KEYS.has(key))) {
6776
6811
  throw new Error('[Paypercut Elements] Express Checkout options are invalid.');
6777
6812
  }
6813
+ validatePaymentMethodOrder(options.paymentMethodOrder);
6778
6814
  if (options.buttonHeight !== undefined) {
6779
6815
  if (typeof options.buttonHeight !== 'number' ||
6780
6816
  !Number.isSafeInteger(options.buttonHeight) ||
@@ -6927,11 +6963,25 @@ function validateClickResolveOptions(options) {
6927
6963
  : {}),
6928
6964
  });
6929
6965
  }
6966
+ function validatePaymentMethodOrder(order) {
6967
+ if (order !== undefined &&
6968
+ (!Array.isArray(order) ||
6969
+ [...order].some((wallet) => wallet !== 'apple_pay' && wallet !== 'google_pay') ||
6970
+ new Set(order).size !== order.length)) {
6971
+ throw invalidOptions();
6972
+ }
6973
+ }
6930
6974
  function validateElementUpdateOptions(options) {
6931
6975
  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.');
6976
+ throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details or wallet order.');
6933
6977
  }
6934
- return validateClickResolveOptions(options);
6978
+ const { paymentMethodOrder, ...checkoutDetails } = options;
6979
+ validatePaymentMethodOrder(paymentMethodOrder);
6980
+ const validated = validateClickResolveOptions(checkoutDetails);
6981
+ return {
6982
+ ...validated,
6983
+ ...('paymentMethodOrder' in options ? { paymentMethodOrder: paymentMethodOrder?.slice() } : {}),
6984
+ };
6935
6985
  }
6936
6986
  function validateShippingUpdate(update) {
6937
6987
  if (update === undefined)
@@ -11702,6 +11752,29 @@ class ElementsGroupImpl {
11702
11752
  window.addEventListener('message', this.windowMessageHandler);
11703
11753
  (document.body ?? document.documentElement).appendChild(iframe);
11704
11754
  }
11755
+ retryStalledControllerInitialization() {
11756
+ const current = this.controllerIframe;
11757
+ const parent = current?.parentNode;
11758
+ if (this.destroyed || this.controllerInitialized || !current || !parent)
11759
+ return false;
11760
+ // A component-only reload cannot recover a controller whose session request
11761
+ // or bootstrap never completed. Keep the group and its pending components,
11762
+ // but give the controller a fresh browsing context and navigation identity.
11763
+ let replacement;
11764
+ try {
11765
+ replacement = current.cloneNode(false);
11766
+ replacement.src = withElementsFrameNavigationIdentity(current.src, generateId());
11767
+ parent.replaceChild(replacement, current);
11768
+ }
11769
+ catch {
11770
+ return false;
11771
+ }
11772
+ this.controlPort?.close();
11773
+ this.controlPort = null;
11774
+ this.controllerBootstrapped = false;
11775
+ this.controllerIframe = replacement;
11776
+ return true;
11777
+ }
11705
11778
  attachComponent(element, port) {
11706
11779
  if (this.destroyed || !this.elements.has(element.componentId)) {
11707
11780
  port.close();