@delopay/sdk 0.334.0 → 0.338.0

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.cjs CHANGED
@@ -1021,7 +1021,7 @@ var Connectors = class {
1021
1021
  );
1022
1022
  }
1023
1023
  /**
1024
- * Share a connector with more shops of the same merchant (todos#320).
1024
+ * Share a connector with more shops of the same merchant.
1025
1025
  * `POST /account/{accountId}/connectors/{connectorId}/shops`
1026
1026
  *
1027
1027
  * Nothing is copied: every shop sends payments to the same account, on the
@@ -1035,7 +1035,7 @@ var Connectors = class {
1035
1035
  );
1036
1036
  }
1037
1037
  /**
1038
- * Fold copies of the same provider account into this connector (todos#395).
1038
+ * Fold copies of the same provider account into this connector.
1039
1039
  * `POST /account/{accountId}/connectors/{connectorId}/consolidate`
1040
1040
  *
1041
1041
  * The copies' shops move to the connector with their on/off state, routing,
@@ -1063,7 +1063,7 @@ var Connectors = class {
1063
1063
  );
1064
1064
  }
1065
1065
  /**
1066
- * Stop a connector serving one shop (todos#407). Any shop may leave, the
1066
+ * Stop a connector serving one shop. Any shop may leave, the
1067
1067
  * one the connector was created in included, while another one stays: the
1068
1068
  * last shop is refused, and the connector is deleted instead. The account,
1069
1069
  * its limits and every other shop on it are unaffected.
@@ -1078,7 +1078,7 @@ var Connectors = class {
1078
1078
  /**
1079
1079
  * Read the transaction currencies a connector may process: its own list,
1080
1080
  * what the provider is known to accept with its methods, and the effective
1081
- * currencies in each shop it serves (todos#333).
1081
+ * currencies in each shop it serves.
1082
1082
  * `GET /account/{accountId}/connectors/{connectorId}/currencies`
1083
1083
  */
1084
1084
  async getCurrencies(accountId, connectorId) {
@@ -2967,6 +2967,21 @@ var Payments = class {
2967
2967
  if (Object.keys(query).length === 0) return this.request("GET", path);
2968
2968
  return this.request("GET", path, { query });
2969
2969
  }
2970
+ /**
2971
+ * The payment's buyer risk evaluations, newest first (at most 50): each
2972
+ * one's score from 0 to 100, its band, the action the merchant's model asks
2973
+ * for that band and the action that was taken, the signals that fired with
2974
+ * the points each added, and the model version it was scored with.
2975
+ *
2976
+ * A payment is scored at every confirm that is about to reach a processor;
2977
+ * a payment never scored answers an empty list. A caller scoped to one shop
2978
+ * reads only that shop's payments.
2979
+ *
2980
+ * `GET /payments/{paymentId}/buyer-risk`
2981
+ */
2982
+ async buyerRisk(paymentId, options) {
2983
+ return this.request("GET", `/payments/${encodeURIComponent(paymentId)}/buyer-risk`, options);
2984
+ }
2970
2985
  /** Product names and prices as frozen when the payment was created. */
2971
2986
  async productLines(paymentId) {
2972
2987
  return this.request("GET", `/payments/${encodeURIComponent(paymentId)}/lines`);
@@ -3130,6 +3145,12 @@ var Payments = class {
3130
3145
  * @param paymentId - The payment intent ID to confirm.
3131
3146
  * @param params - Confirmation parameters (payment method data, return URL, etc.).
3132
3147
  * @returns The updated payment intent.
3148
+ *
3149
+ * A buyer the merchant's buyer risk model refuses fails before any processor
3150
+ * is called, with a `DelopayError` of code `DE_23` (`buyer_risk_refused`,
3151
+ * HTTP 422). The error does not say which signal fired; read the evaluation
3152
+ * with {@link Payments.buyerRisk}. A shop whose payments are switched off is
3153
+ * refused with `DE_21`.
3133
3154
  */
3134
3155
  async confirm(paymentId, params) {
3135
3156
  return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/confirm`, {
@@ -3661,6 +3682,31 @@ var Profiles = class {
3661
3682
  { body: { is_archived: false } }
3662
3683
  );
3663
3684
  }
3685
+ /**
3686
+ * Switch a shop's payments off. While they are off the shop takes no new
3687
+ * payment: creating one, and confirming one no provider holds yet, is
3688
+ * refused with `DE_21`, and its hosted checkout does not render. A payment a
3689
+ * provider already holds is finished; refunds and disputes are unaffected.
3690
+ * Needs the `ShopPaymentsSwitch` area's `Write` and a signed-in user.
3691
+ * Repeating the same state is safe.
3692
+ *
3693
+ * `PUT /account/{accountId}/business-profile/{profileId}/payments-switch`
3694
+ */
3695
+ async disablePayments(accountId, profileId) {
3696
+ return this.request(
3697
+ "PUT",
3698
+ `/account/${encodeURIComponent(accountId)}/business-profile/${encodeURIComponent(profileId)}/payments-switch`,
3699
+ { body: { payments_disabled: true } }
3700
+ );
3701
+ }
3702
+ /** Switch a shop's payments on again after {@link Profiles.disablePayments}. */
3703
+ async enablePayments(accountId, profileId) {
3704
+ return this.request(
3705
+ "PUT",
3706
+ `/account/${encodeURIComponent(accountId)}/business-profile/${encodeURIComponent(profileId)}/payments-switch`,
3707
+ { body: { payments_disabled: false } }
3708
+ );
3709
+ }
3664
3710
  /** Archived shop identities in the caller's merchant and shop-read scope. */
3665
3711
  async listArchived(accountId) {
3666
3712
  return this.request(
@@ -6758,7 +6804,7 @@ var SellToRestrictions = class {
6758
6804
  );
6759
6805
  }
6760
6806
  /**
6761
- * One payment connector account's own policy (todos#504), and which buyer
6807
+ * One payment connector account's own policy, and which buyer
6762
6808
  * signals its payments can be judged on. Needs the merchant-level `Read`
6763
6809
  * rung; a shop-scoped role is refused.
6764
6810
  * `GET /sell-to-restrictions/connectors/{merchant_connector_id}`
@@ -10866,6 +10912,9 @@ var Delopay = class {
10866
10912
  this.maxRetries = options?.maxRetries ?? 2;
10867
10913
  this.debug = options?.debug ?? false;
10868
10914
  if (options?.logger !== void 0) this.logger = options.logger;
10915
+ if (options?.profileId !== void 0 && options.profileId !== "") {
10916
+ this.profileId = options.profileId;
10917
+ }
10869
10918
  if (options?.baseUrl !== void 0) {
10870
10919
  this.baseUrl = options.baseUrl;
10871
10920
  } else if (options?.sandbox) {
@@ -11014,6 +11063,17 @@ var Delopay = class {
11014
11063
  return url;
11015
11064
  }
11016
11065
  /** The credential header: the JWT when one is set, else the API key. */
11066
+ /**
11067
+ * The client's `X-Profile-Id`, unless the call names one itself (in any
11068
+ * letter case: two spellings would be sent as one joined value).
11069
+ */
11070
+ profileHeaders(callHeaders) {
11071
+ if (this.profileId === void 0) return {};
11072
+ const named = Object.keys(callHeaders ?? {}).some(
11073
+ (name) => name.toLowerCase() === "x-profile-id"
11074
+ );
11075
+ return named ? {} : { "X-Profile-Id": this.profileId };
11076
+ }
11017
11077
  authHeaders() {
11018
11078
  if (this.jwtToken) return { Authorization: `Bearer ${this.jwtToken}` };
11019
11079
  if (this.apiKey) return { "api-key": this.apiKey };
@@ -11057,6 +11117,7 @@ var Delopay = class {
11057
11117
  const lastEventId = options.lastEventId ?? "";
11058
11118
  const headers = {
11059
11119
  ...this.authHeaders(),
11120
+ ...this.profileHeaders(options.headers),
11060
11121
  Accept: "text/event-stream",
11061
11122
  ...lastEventId ? { "Last-Event-ID": lastEventId } : {},
11062
11123
  ...options.headers
@@ -11194,6 +11255,7 @@ var Delopay = class {
11194
11255
  const url = this.buildUrl(path, options?.query);
11195
11256
  let headers = {
11196
11257
  ...this.authHeaders(),
11258
+ ...this.profileHeaders(options?.headers),
11197
11259
  ...options?.headers
11198
11260
  };
11199
11261
  const isRawBody = options?.body !== void 0 && options?.body !== null && (options.body instanceof FormData || options.body instanceof Blob || options.body instanceof ArrayBuffer || options.body instanceof URLSearchParams);
@@ -13783,7 +13845,7 @@ function decodeBranding(source) {
13783
13845
  DEFAULT_BRANDING.whopSelection
13784
13846
  ),
13785
13847
  paypalValidTint: parseBool(extras["paypalValidTint"], DEFAULT_BRANDING.paypalValidTint),
13786
- // A look stored before todos#412 has no e-Payouts keys: the form keeps
13848
+ // A look stored before e-Payouts had its own keys has none: the form keeps
13787
13849
  // the PayPal values it was drawn with until then.
13788
13850
  epayoutsCardLayout: pickEnum(
13789
13851
  extras["epayoutsCardLayout"],
@@ -14472,7 +14534,7 @@ function parseImportedBranding(raw) {
14472
14534
  dflt.whopSelection
14473
14535
  ),
14474
14536
  paypalValidTint: parseBool(root["paypalValidTint"], dflt.paypalValidTint),
14475
- // A look stored before todos#412 has no e-Payouts keys: the form keeps
14537
+ // A look stored before e-Payouts had its own keys has none: the form keeps
14476
14538
  // the PayPal values it was drawn with until then.
14477
14539
  epayoutsCardLayout: pickEnum(
14478
14540
  root["epayoutsCardLayout"],
@@ -14932,6 +14994,52 @@ var CheckoutSession = class {
14932
14994
  }
14933
14995
  );
14934
14996
  }
14997
+ /**
14998
+ * The methods the buyer may pick for a subscription that waits for the
14999
+ * choice (`method_choice_pending`), judged for the buyer. Call it from the
15000
+ * buyer's browser: the sell-to country is read from this request's own
15001
+ * connection. A cancelled subscription answers 400, and one that already
15002
+ * bills on an account answers 409 (`DE_20`). Authenticated with the
15003
+ * subscription's client secret.
15004
+ *
15005
+ * `GET /subscriptions/method-options/{merchantId}/{subscriptionId}`
15006
+ */
15007
+ async subscriptionMethodOptions(options) {
15008
+ return this.client.request(
15009
+ "GET",
15010
+ `/subscriptions/method-options/${encodeURIComponent(this.merchantId)}/${encodeURIComponent(this.paymentId)}`,
15011
+ {
15012
+ ...options,
15013
+ headers: this.bearerHeaders(options?.headers)
15014
+ }
15015
+ );
15016
+ }
15017
+ /**
15018
+ * Bind a waiting subscription to the method the buyer picked and open its
15019
+ * first cycle on that method's billing account. The methods are judged
15020
+ * again from this request; afterwards
15021
+ * {@link CheckoutSession.fetchSubscriptionData} describes the bound
15022
+ * subscription (Stripe's Payment Element for `card`, `confirmSubscription`
15023
+ * for the others). Picking the same method again answers the bound
15024
+ * subscription. A subscription bound to another method already, or whose
15025
+ * billing account changed meanwhile, answers 409 (`DE_20`); a method not
15026
+ * offered to this buyer, or a cancelled subscription, answers 400.
15027
+ * Authenticated with the subscription's client secret.
15028
+ *
15029
+ * `POST /subscriptions/select-method/{merchantId}/{subscriptionId}`
15030
+ */
15031
+ async selectSubscriptionMethod(method, options) {
15032
+ const body = { method };
15033
+ return this.client.request(
15034
+ "POST",
15035
+ `/subscriptions/select-method/${encodeURIComponent(this.merchantId)}/${encodeURIComponent(this.paymentId)}`,
15036
+ {
15037
+ body,
15038
+ ...options,
15039
+ headers: this.bearerHeaders(options?.headers)
15040
+ }
15041
+ );
15042
+ }
14935
15043
  /**
14936
15044
  * Confirm a subscription (PayPal approval rail). The client secret is
14937
15045
  * attached automatically; the shop's profile id travels as the
@@ -15205,7 +15313,9 @@ var CheckoutSession = class {
15205
15313
  * Only `authorized: true` permits the form to contact its processor. A
15206
15314
  * competing flow receives `false` and must reload; an unresolved provider
15207
15315
  * outcome stays reserved, regardless of elapsed time. A buyer-blocklist
15208
- * refusal throws a `DelopayError` with code `DE_14`.
15316
+ * refusal throws a `DelopayError` with code `DE_14`; a shop whose payments
15317
+ * DeloPay stopped is refused with `DE_22`, and a shop whose payments the
15318
+ * merchant switched off with `DE_21`.
15209
15319
  *
15210
15320
  * `POST /payment-link/{merchantId}/{paymentId}/browser-card-claim`
15211
15321
  */
@@ -15231,7 +15341,11 @@ var CheckoutSession = class {
15231
15341
  * against the shop's sell-to restrictions before Stripe authorises, and a
15232
15342
  * refusal throws a `DelopayError` with code `DE_10`. A buyer on the
15233
15343
  * merchant's buyer blocklist is refused before any Stripe call with code
15234
- * `DE_14` (`buyer_blocked`, 422), which names no entry. When the answer's
15344
+ * `DE_14` (`buyer_blocked`, 422), which names no entry, a shop whose
15345
+ * payments DeloPay stopped with `DE_22`, and a shop whose payments the
15346
+ * merchant switched off with `DE_21`. A buyer the merchant's buyer risk
15347
+ * model refuses fails with `DE_23` (`buyer_risk_refused`, 422), which says
15348
+ * nothing about the signals. When the answer's
15235
15349
  * `status` is `requires_action`, run `stripe.handleNextAction` with its
15236
15350
  * `client_secret` — safe, because the intent is `confirmation_method=manual`
15237
15351
  * and that secret confirms nothing without the secret key — then call this
@@ -15462,7 +15576,7 @@ var CheckoutSession = class {
15462
15576
  /**
15463
15577
  * Reopen a provider session the buyer switched away from, when they pick the
15464
15578
  * same method again, instead of opening a second session at the provider
15465
- * (delopay-todos#401). Pass an `attempt_id` from the checkout's
15579
+ *. Pass an `attempt_id` from the checkout's
15466
15580
  * `reopenable_attempts`; the attempt becomes the payment's active one again
15467
15581
  * and `redirect_url` sends the buyer back to it. Refused (`IR_16`) when the
15468
15582
  * payment no longer awaits a method, a payment is under way on the checkout,