@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 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.2/dist/paypercut-checkout.iife.min.js"></script>
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',
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
4
- const SDK_VERSION = "1.4.2";
4
+ const SDK_VERSION = "1.4.4";
5
5
 
6
6
  const ELEMENTS_APPEARANCE_VARIABLE_NAMES = [
7
7
  'colorPrimary',
@@ -1,4 +1,4 @@
1
- const SDK_VERSION = "1.4.2";
1
+ const SDK_VERSION = "1.4.4";
2
2
 
3
3
  const ELEMENTS_APPEARANCE_VARIABLE_NAMES = [
4
4
  'colorPrimary',
package/dist/index.cjs CHANGED
@@ -105,7 +105,7 @@ class Emitter {
105
105
  }
106
106
  }
107
107
 
108
- const SDK_VERSION = "1.4.2";
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);
@@ -4820,7 +4823,9 @@ class CardElementImpl {
4820
4823
  border: '0',
4821
4824
  display: 'block',
4822
4825
  overflow: 'hidden',
4823
- colorScheme: 'light dark',
4826
+ // Hosted Elements uses a normal document color scheme. A mismatch makes
4827
+ // browsers paint an opaque canvas even with transparent html/body styles.
4828
+ colorScheme: 'normal',
4824
4829
  transition: 'height 350ms ease-in-out, opacity 400ms ease-in-out 100ms',
4825
4830
  willChange: 'height, opacity',
4826
4831
  });
@@ -5155,6 +5160,38 @@ function patchApplePayModalFocus(modal, attempts = 0) {
5155
5160
  root.appendChild(style);
5156
5161
  }
5157
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
+
5158
5195
  const GOOGLE_PAY_POPUP_RECOVERY_POLICY = {
5159
5196
  closedPollIntervalMs: 250,
5160
5197
  providerSettlementGraceMs: 3500,
@@ -5333,6 +5370,7 @@ class ExpressCheckoutElementImpl {
5333
5370
  this.googlePayAuthorization = null;
5334
5371
  this.googlePayButtonTarget = null;
5335
5372
  this.googlePayButtonContainer = null;
5373
+ this.mountSurface = null;
5336
5374
  this.googlePayButtonGeneration = 0;
5337
5375
  this.googlePayButtonPositionFrame = null;
5338
5376
  this.googlePayButtonResizeObserver = null;
@@ -5381,7 +5419,8 @@ class ExpressCheckoutElementImpl {
5381
5419
  this.group.markComponentMounted();
5382
5420
  window.addEventListener('message', this.messageHandler);
5383
5421
  this.group.ensureController();
5384
- container.appendChild(iframe);
5422
+ this.mountSurface = createExpressCheckoutMount(iframe);
5423
+ container.appendChild(this.mountSurface);
5385
5424
  this.registerDeveloperAssistant();
5386
5425
  }
5387
5426
  on(event, handler) {
@@ -5395,6 +5434,9 @@ class ExpressCheckoutElementImpl {
5395
5434
  throw new Error('[Paypercut Elements] Cannot update Express Checkout while a wallet attempt is active.');
5396
5435
  }
5397
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
+ }
5398
5440
  this.options = validateOptions({ ...this.options, ...validated });
5399
5441
  if (this.componentRevision === Number.MAX_SAFE_INTEGER) {
5400
5442
  throw new Error('[Paypercut Elements] The component update revision limit has been reached.');
@@ -5684,6 +5726,8 @@ class ExpressCheckoutElementImpl {
5684
5726
  }
5685
5727
  this.iframe?.remove();
5686
5728
  this.iframe = null;
5729
+ this.mountSurface?.remove();
5730
+ this.mountSurface = null;
5687
5731
  this.connectedFrame = null;
5688
5732
  this.mounted = false;
5689
5733
  this.emitter.clear();
@@ -6027,8 +6071,7 @@ class ExpressCheckoutElementImpl {
6027
6071
  // merchant click decision returns. Keep the request identity until the
6028
6072
  // controller's wallet_cancel arrives so integrations receive their
6029
6073
  // normal cancel lifecycle and can release their own attempt lock.
6030
- if (wallet !== 'google_pay' ||
6031
- this.googlePayRequestId !== requestId) {
6074
+ if (wallet !== 'google_pay' || this.googlePayRequestId !== requestId) {
6032
6075
  this.activeAttempt = null;
6033
6076
  this.activeOptions = null;
6034
6077
  }
@@ -6262,18 +6305,9 @@ class ExpressCheckoutElementImpl {
6262
6305
  }
6263
6306
  mountGooglePayButton(client, target, request, allowedPaymentMethods) {
6264
6307
  this.removeGooglePayButton();
6265
- const container = document.createElement('div');
6266
- container.dataset.paypercutElementsGooglePayButton = this.componentId;
6267
- Object.assign(container.style, {
6268
- position: 'fixed',
6269
- margin: '0',
6270
- padding: '0',
6271
- border: '0',
6272
- overflow: 'hidden',
6273
- zIndex: '2147483000',
6274
- pointerEvents: 'auto',
6275
- visibility: 'hidden',
6276
- });
6308
+ if (!this.mountSurface)
6309
+ return;
6310
+ const container = createGooglePayButtonSurface(this.componentId);
6277
6311
  const button = client.createButton({
6278
6312
  buttonColor: target.buttonColor,
6279
6313
  buttonType: target.buttonType,
@@ -6299,10 +6333,9 @@ class ExpressCheckoutElementImpl {
6299
6333
  });
6300
6334
  Object.assign(button.style, { width: '100%', height: '100%', margin: '0' });
6301
6335
  container.appendChild(button);
6302
- document.body.appendChild(container);
6336
+ this.mountSurface.appendChild(container);
6303
6337
  this.googlePayButtonContainer = container;
6304
6338
  window.addEventListener('resize', this.googlePayButtonPositionHandler);
6305
- window.addEventListener('scroll', this.googlePayButtonPositionHandler, true);
6306
6339
  if (typeof ResizeObserver !== 'undefined' && this.iframe) {
6307
6340
  this.googlePayButtonResizeObserver = new ResizeObserver(this.googlePayButtonPositionHandler);
6308
6341
  this.googlePayButtonResizeObserver.observe(this.iframe);
@@ -6321,8 +6354,10 @@ class ExpressCheckoutElementImpl {
6321
6354
  return;
6322
6355
  }
6323
6356
  const frameRect = iframe.getBoundingClientRect();
6324
- const left = frameRect.left + target.target.x;
6325
- const top = frameRect.top + target.target.y;
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;
6326
6361
  Object.assign(container.style, {
6327
6362
  left: `${left}px`,
6328
6363
  top: `${top}px`,
@@ -6344,7 +6379,6 @@ class ExpressCheckoutElementImpl {
6344
6379
  this.googlePayButtonPositionFrame = null;
6345
6380
  }
6346
6381
  window.removeEventListener('resize', this.googlePayButtonPositionHandler);
6347
- window.removeEventListener('scroll', this.googlePayButtonPositionHandler, true);
6348
6382
  this.googlePayButtonResizeObserver?.disconnect();
6349
6383
  this.googlePayButtonResizeObserver = null;
6350
6384
  this.googlePayButtonContainer?.remove();
@@ -6721,6 +6755,7 @@ class ExpressCheckoutElementImpl {
6721
6755
  }
6722
6756
  }
6723
6757
  const OPTION_KEYS = new Set([
6758
+ 'paymentMethodOrder',
6724
6759
  'paymentMethods',
6725
6760
  'layout',
6726
6761
  'buttonType',
@@ -6778,6 +6813,7 @@ function validateOptions(options) {
6778
6813
  if (!isRecord(rawOptions) || Object.keys(rawOptions).some((key) => !OPTION_KEYS.has(key))) {
6779
6814
  throw new Error('[Paypercut Elements] Express Checkout options are invalid.');
6780
6815
  }
6816
+ validatePaymentMethodOrder(options.paymentMethodOrder);
6781
6817
  if (options.buttonHeight !== undefined) {
6782
6818
  if (typeof options.buttonHeight !== 'number' ||
6783
6819
  !Number.isSafeInteger(options.buttonHeight) ||
@@ -6930,11 +6966,25 @@ function validateClickResolveOptions(options) {
6930
6966
  : {}),
6931
6967
  });
6932
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
+ }
6933
6977
  function validateElementUpdateOptions(options) {
6934
6978
  if (!isRecord(options) || Object.keys(options).length === 0 || 'amount' in options) {
6935
- 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.');
6936
6980
  }
6937
- return validateClickResolveOptions(options);
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
+ };
6938
6988
  }
6939
6989
  function validateShippingUpdate(update) {
6940
6990
  if (update === undefined)