@paypercut/checkout-js 1.4.1 → 1.4.2

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
@@ -102,6 +102,41 @@ Mounting an Element never creates a Payment Method and never creates or confirms
102
102
  a payment. The merchant server remains authoritative for the final amount,
103
103
  currency, order state, authorization, capture, and fulfillment.
104
104
 
105
+ ### Connected account context
106
+
107
+ Platforms can initialize an Elements client with their platform publishable key
108
+ and the connected account selected for the payment:
109
+
110
+ ```ts
111
+ import { Paypercut } from '@paypercut/checkout-js';
112
+
113
+ const paypercut = Paypercut('pk_live_PLATFORM', {
114
+ account: 'acc_merchant_A',
115
+ });
116
+
117
+ // The existing object initializer supports the same option:
118
+ // Paypercut({ publishableKey: 'pk_live_PLATFORM', account: 'acc_merchant_A' });
119
+
120
+ const elements = paypercut.elements({
121
+ mode: 'payment',
122
+ amount: 2500,
123
+ currency: 'EUR',
124
+ });
125
+ const card = elements.create('card');
126
+ card.mount('#card-element');
127
+ ```
128
+
129
+ `account` is optional and fixed for the client lifetime. Every Elements group
130
+ created by that client inherits it, including Card, split card fields, and
131
+ Express Checkout Elements. `createPaymentMethod()`, `confirmPayment()`, and
132
+ `handleNextAction()` use that same context. Omit `account` to use the
133
+ credential's default account. To select another merchant, destroy the previous
134
+ groups and initialize a new client; `elements.update()` cannot change accounts.
135
+
136
+ Your server must use the same account context when using the Payment Method or
137
+ creating the payment resource whose client secret is returned to this client.
138
+ Do not reuse objects from another account.
139
+
105
140
  ### Developer Assistance
106
141
 
107
142
  The Developer Assistant is an optional configuration preview tool for developers
@@ -1708,7 +1743,7 @@ Tip: Prefer subscribing with the SdkEvent enum for stronger typing.
1708
1743
  <body>
1709
1744
  <div id="checkout"></div>
1710
1745
 
1711
- <script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.4.1/dist/paypercut-checkout.iife.min.js"></script>
1746
+ <script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.4.2/dist/paypercut-checkout.iife.min.js"></script>
1712
1747
  <script>
1713
1748
  const checkout = PaypercutCheckout({
1714
1749
  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.1";
4
+ const SDK_VERSION = "1.4.2";
5
5
 
6
6
  const ELEMENTS_APPEARANCE_VARIABLE_NAMES = [
7
7
  'colorPrimary',
@@ -1,4 +1,4 @@
1
- const SDK_VERSION = "1.4.1";
1
+ const SDK_VERSION = "1.4.2";
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.1";
108
+ const SDK_VERSION = "1.4.2";
109
109
 
110
110
  /**
111
111
  * Build-time configuration
@@ -897,6 +897,7 @@ class ExpressCheckoutImpl {
897
897
  merchantMcc: data.merchant?.mcc ?? '',
898
898
  merchantCountry: data.merchant?.country ?? '',
899
899
  merchantUrl: data.merchant?.business_url ?? '',
900
+ threeDSecure: data.three_d_secure ?? null,
900
901
  };
901
902
  }
902
903
  catch (err) {
@@ -1569,6 +1570,7 @@ class ExpressCheckoutImpl {
1569
1570
  country: this.expressConfig?.merchantCountry ?? '',
1570
1571
  url: this.expressConfig?.merchantUrl ?? '',
1571
1572
  },
1573
+ threeDSecure: this.expressConfig?.threeDSecure ?? null,
1572
1574
  });
1573
1575
  };
1574
1576
  session.oncancel = () => {
@@ -1884,6 +1886,7 @@ class ExpressCheckoutImpl {
1884
1886
  country: this.expressConfig?.merchantCountry ?? '',
1885
1887
  url: this.expressConfig?.merchantUrl ?? '',
1886
1888
  },
1889
+ threeDSecure: this.expressConfig?.threeDSecure ?? null,
1887
1890
  });
1888
1891
  });
1889
1892
  // 3DS was triggered — sheet already closed, payment method creation handled in message handler
@@ -3269,6 +3272,7 @@ function buildCardElementFrameUrl(input) {
3269
3272
  function setSharedParams(params, input, includeKeyMode = true) {
3270
3273
  params.set('controllerId', input.controllerId);
3271
3274
  params.set('apiKey', input.clientOptions.publishableKey);
3275
+ set(params, 'account', input.clientOptions.account);
3272
3276
  if (includeKeyMode)
3273
3277
  params.set('keyMode', inferKeyMode(input.clientOptions.publishableKey));
3274
3278
  params.set('locale', input.elementsOptions.locale || navigatorLocale());
@@ -12793,7 +12797,7 @@ const MAX_CONFIRM_ATTEMPTS = 3;
12793
12797
  const CLIENT_SECRET_MARKER = '_secret_';
12794
12798
  const CLIENT_SECRET_PREFIX_LENGTH = 3;
12795
12799
  const MAX_CLIENT_SECRET_LENGTH = 4096;
12796
- // Shared with Paycore's payment-resource client-secret issuer. Checkout IDs are
12800
+ // Shared with Paypercut's payment-resource client-secret issuer. Checkout IDs are
12797
12801
  // embedded only so the SDK can address the authoritative resource; merchants
12798
12802
  // must continue to treat the complete client secret as opaque.
12799
12803
  const MAX_RESOURCE_ID_LENGTH = 200;
@@ -13011,6 +13015,7 @@ class PaymentConfirmationCoordinator {
13011
13015
  this.billingDetailsFor = billingDetailsFor;
13012
13016
  this.inFlight = new Map();
13013
13017
  this.activeAction = null;
13018
+ this.account = options.account;
13014
13019
  this.apiUrl = getApiOrigin(options.apiUrl);
13015
13020
  this.hostedOrigin = new URL(getCheckoutOrigin(options.hostedCheckoutUrl)).origin;
13016
13021
  this.actionShell = new ElementsActionShell(this.hostedOrigin, (actionId) => this.rejectActiveAction(actionId, 'elements_action_canceled', 'Payment authentication was canceled.', true), (actionId, code, message, recoverable) => this.rejectActiveAction(actionId, code, message, recoverable));
@@ -13088,6 +13093,7 @@ class PaymentConfirmationCoordinator {
13088
13093
  method: 'GET',
13089
13094
  headers: {
13090
13095
  Accept: 'application/json',
13096
+ ...(this.account !== undefined ? { 'Paypercut-Account': this.account } : {}),
13091
13097
  },
13092
13098
  }, 'elements_checkout_status_failed', { deadlineAt });
13093
13099
  return parseCheckoutStatus(value, parsed.checkoutSessionId);
@@ -13101,6 +13107,7 @@ class PaymentConfirmationCoordinator {
13101
13107
  Accept: 'application/json',
13102
13108
  'Content-Type': 'application/json',
13103
13109
  'Idempotency-Key': idempotencyKey,
13110
+ ...(this.account !== undefined ? { 'Paypercut-Account': this.account } : {}),
13104
13111
  },
13105
13112
  body: JSON.stringify({
13106
13113
  key: this.publishableKey,
@@ -13181,6 +13188,7 @@ class PaymentConfirmationCoordinator {
13181
13188
  payload: {
13182
13189
  protocolVersion: ELEMENTS_PAYMENT_CONFIRMATION_PROTOCOL_VERSION,
13183
13190
  publishableKey: this.publishableKey,
13191
+ ...(this.account !== undefined ? { account: this.account } : {}),
13184
13192
  apiUrl: this.apiUrl,
13185
13193
  sdkVersion: config.version,
13186
13194
  deadlineAt,
@@ -13256,6 +13264,7 @@ class PaypercutImpl {
13256
13264
  this.paymentConfirmation = null;
13257
13265
  this.configurationIdentity = JSON.stringify([
13258
13266
  options.publishableKey,
13267
+ options.account ?? null,
13259
13268
  getApiOrigin(options.apiUrl),
13260
13269
  getCheckoutOrigin(options.hostedCheckoutUrl),
13261
13270
  ]);
@@ -13329,6 +13338,7 @@ class PaypercutImpl {
13329
13338
  return Promise.reject(createSubmitError('elements_client_secret_invalid', 'confirmPayment requires only a Checkout Session clientSecret.', false));
13330
13339
  }
13331
13340
  this.paymentConfirmation ?? (this.paymentConfirmation = new PaymentConfirmationCoordinator(this.options.publishableKey, {
13341
+ ...(this.options.account !== undefined ? { account: this.options.account } : {}),
13332
13342
  ...(this.options.apiUrl ? { apiUrl: this.options.apiUrl } : {}),
13333
13343
  ...(this.options.hostedCheckoutUrl
13334
13344
  ? { hostedCheckoutUrl: this.options.hostedCheckoutUrl }
@@ -13340,12 +13350,22 @@ class PaypercutImpl {
13340
13350
  function isSetupFutureUsage(value) {
13341
13351
  return value === undefined || value === 'on_session' || value === 'off_session';
13342
13352
  }
13343
- const Paypercut = function (options) {
13344
- return new PaypercutImpl(validateClientOptions(options));
13353
+ const Paypercut = function (optionsOrKey, options) {
13354
+ if (typeof optionsOrKey === 'string') {
13355
+ if (options !== undefined &&
13356
+ (!options || typeof options !== 'object' || Array.isArray(options))) {
13357
+ throw new Error('[Paypercut Elements] Client options must be an object.');
13358
+ }
13359
+ return new PaypercutImpl(validateClientOptions({ ...options, publishableKey: optionsOrKey }));
13360
+ }
13361
+ if (options !== undefined) {
13362
+ throw new Error('[Paypercut Elements] Pass client options in one initializer object.');
13363
+ }
13364
+ return new PaypercutImpl(validateClientOptions(optionsOrKey));
13345
13365
  };
13346
13366
  Paypercut.version = config.version;
13347
13367
  function validateClientOptions(options) {
13348
- if (!options || typeof options !== 'object') {
13368
+ if (!options || typeof options !== 'object' || Array.isArray(options)) {
13349
13369
  throw new Error('[Paypercut Elements] Client options are required.');
13350
13370
  }
13351
13371
  const publishableKey = options.publishableKey;