@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/README.md CHANGED
@@ -26,7 +26,7 @@ const delopay = new Delopay(process.env.DELOPAY_API_KEY!);
26
26
  const payment = await delopay.payments.create({
27
27
  amount: 1000, // in minor units (€10.00)
28
28
  currency: 'EUR',
29
- description: 'Order #1234',
29
+ description: 'Order 1234',
30
30
  customer_id: 'cus_abc123',
31
31
  });
32
32
 
@@ -66,7 +66,7 @@ const payment = await delopay.payments.create({
66
66
  currency: 'EUR',
67
67
  payment_link: true,
68
68
  customer_id: 'cus_abc123',
69
- description: 'Order #1234',
69
+ description: 'Order 1234',
70
70
  return_url: 'https://example.com/checkout/complete',
71
71
  });
72
72
 
@@ -733,7 +733,7 @@ var Connectors = class {
733
733
  );
734
734
  }
735
735
  /**
736
- * Share a connector with more shops of the same merchant (todos#320).
736
+ * Share a connector with more shops of the same merchant.
737
737
  * `POST /account/{accountId}/connectors/{connectorId}/shops`
738
738
  *
739
739
  * Nothing is copied: every shop sends payments to the same account, on the
@@ -747,7 +747,7 @@ var Connectors = class {
747
747
  );
748
748
  }
749
749
  /**
750
- * Fold copies of the same provider account into this connector (todos#395).
750
+ * Fold copies of the same provider account into this connector.
751
751
  * `POST /account/{accountId}/connectors/{connectorId}/consolidate`
752
752
  *
753
753
  * The copies' shops move to the connector with their on/off state, routing,
@@ -775,7 +775,7 @@ var Connectors = class {
775
775
  );
776
776
  }
777
777
  /**
778
- * Stop a connector serving one shop (todos#407). Any shop may leave, the
778
+ * Stop a connector serving one shop. Any shop may leave, the
779
779
  * one the connector was created in included, while another one stays: the
780
780
  * last shop is refused, and the connector is deleted instead. The account,
781
781
  * its limits and every other shop on it are unaffected.
@@ -790,7 +790,7 @@ var Connectors = class {
790
790
  /**
791
791
  * Read the transaction currencies a connector may process: its own list,
792
792
  * what the provider is known to accept with its methods, and the effective
793
- * currencies in each shop it serves (todos#333).
793
+ * currencies in each shop it serves.
794
794
  * `GET /account/{accountId}/connectors/{connectorId}/currencies`
795
795
  */
796
796
  async getCurrencies(accountId, connectorId) {
@@ -2679,6 +2679,21 @@ var Payments = class {
2679
2679
  if (Object.keys(query).length === 0) return this.request("GET", path);
2680
2680
  return this.request("GET", path, { query });
2681
2681
  }
2682
+ /**
2683
+ * The payment's buyer risk evaluations, newest first (at most 50): each
2684
+ * one's score from 0 to 100, its band, the action the merchant's model asks
2685
+ * for that band and the action that was taken, the signals that fired with
2686
+ * the points each added, and the model version it was scored with.
2687
+ *
2688
+ * A payment is scored at every confirm that is about to reach a processor;
2689
+ * a payment never scored answers an empty list. A caller scoped to one shop
2690
+ * reads only that shop's payments.
2691
+ *
2692
+ * `GET /payments/{paymentId}/buyer-risk`
2693
+ */
2694
+ async buyerRisk(paymentId, options) {
2695
+ return this.request("GET", `/payments/${encodeURIComponent(paymentId)}/buyer-risk`, options);
2696
+ }
2682
2697
  /** Product names and prices as frozen when the payment was created. */
2683
2698
  async productLines(paymentId) {
2684
2699
  return this.request("GET", `/payments/${encodeURIComponent(paymentId)}/lines`);
@@ -2842,6 +2857,12 @@ var Payments = class {
2842
2857
  * @param paymentId - The payment intent ID to confirm.
2843
2858
  * @param params - Confirmation parameters (payment method data, return URL, etc.).
2844
2859
  * @returns The updated payment intent.
2860
+ *
2861
+ * A buyer the merchant's buyer risk model refuses fails before any processor
2862
+ * is called, with a `DelopayError` of code `DE_23` (`buyer_risk_refused`,
2863
+ * HTTP 422). The error does not say which signal fired; read the evaluation
2864
+ * with {@link Payments.buyerRisk}. A shop whose payments are switched off is
2865
+ * refused with `DE_21`.
2845
2866
  */
2846
2867
  async confirm(paymentId, params) {
2847
2868
  return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/confirm`, {
@@ -3373,6 +3394,31 @@ var Profiles = class {
3373
3394
  { body: { is_archived: false } }
3374
3395
  );
3375
3396
  }
3397
+ /**
3398
+ * Switch a shop's payments off. While they are off the shop takes no new
3399
+ * payment: creating one, and confirming one no provider holds yet, is
3400
+ * refused with `DE_21`, and its hosted checkout does not render. A payment a
3401
+ * provider already holds is finished; refunds and disputes are unaffected.
3402
+ * Needs the `ShopPaymentsSwitch` area's `Write` and a signed-in user.
3403
+ * Repeating the same state is safe.
3404
+ *
3405
+ * `PUT /account/{accountId}/business-profile/{profileId}/payments-switch`
3406
+ */
3407
+ async disablePayments(accountId, profileId) {
3408
+ return this.request(
3409
+ "PUT",
3410
+ `/account/${encodeURIComponent(accountId)}/business-profile/${encodeURIComponent(profileId)}/payments-switch`,
3411
+ { body: { payments_disabled: true } }
3412
+ );
3413
+ }
3414
+ /** Switch a shop's payments on again after {@link Profiles.disablePayments}. */
3415
+ async enablePayments(accountId, profileId) {
3416
+ return this.request(
3417
+ "PUT",
3418
+ `/account/${encodeURIComponent(accountId)}/business-profile/${encodeURIComponent(profileId)}/payments-switch`,
3419
+ { body: { payments_disabled: false } }
3420
+ );
3421
+ }
3376
3422
  /** Archived shop identities in the caller's merchant and shop-read scope. */
3377
3423
  async listArchived(accountId) {
3378
3424
  return this.request(
@@ -6470,7 +6516,7 @@ var SellToRestrictions = class {
6470
6516
  );
6471
6517
  }
6472
6518
  /**
6473
- * One payment connector account's own policy (todos#504), and which buyer
6519
+ * One payment connector account's own policy, and which buyer
6474
6520
  * signals its payments can be judged on. Needs the merchant-level `Read`
6475
6521
  * rung; a shop-scoped role is refused.
6476
6522
  * `GET /sell-to-restrictions/connectors/{merchant_connector_id}`
@@ -10578,6 +10624,9 @@ var Delopay = class {
10578
10624
  this.maxRetries = options?.maxRetries ?? 2;
10579
10625
  this.debug = options?.debug ?? false;
10580
10626
  if (options?.logger !== void 0) this.logger = options.logger;
10627
+ if (options?.profileId !== void 0 && options.profileId !== "") {
10628
+ this.profileId = options.profileId;
10629
+ }
10581
10630
  if (options?.baseUrl !== void 0) {
10582
10631
  this.baseUrl = options.baseUrl;
10583
10632
  } else if (options?.sandbox) {
@@ -10726,6 +10775,17 @@ var Delopay = class {
10726
10775
  return url;
10727
10776
  }
10728
10777
  /** The credential header: the JWT when one is set, else the API key. */
10778
+ /**
10779
+ * The client's `X-Profile-Id`, unless the call names one itself (in any
10780
+ * letter case: two spellings would be sent as one joined value).
10781
+ */
10782
+ profileHeaders(callHeaders) {
10783
+ if (this.profileId === void 0) return {};
10784
+ const named = Object.keys(callHeaders ?? {}).some(
10785
+ (name) => name.toLowerCase() === "x-profile-id"
10786
+ );
10787
+ return named ? {} : { "X-Profile-Id": this.profileId };
10788
+ }
10729
10789
  authHeaders() {
10730
10790
  if (this.jwtToken) return { Authorization: `Bearer ${this.jwtToken}` };
10731
10791
  if (this.apiKey) return { "api-key": this.apiKey };
@@ -10769,6 +10829,7 @@ var Delopay = class {
10769
10829
  const lastEventId = options.lastEventId ?? "";
10770
10830
  const headers = {
10771
10831
  ...this.authHeaders(),
10832
+ ...this.profileHeaders(options.headers),
10772
10833
  Accept: "text/event-stream",
10773
10834
  ...lastEventId ? { "Last-Event-ID": lastEventId } : {},
10774
10835
  ...options.headers
@@ -10906,6 +10967,7 @@ var Delopay = class {
10906
10967
  const url = this.buildUrl(path, options?.query);
10907
10968
  let headers = {
10908
10969
  ...this.authHeaders(),
10970
+ ...this.profileHeaders(options?.headers),
10909
10971
  ...options?.headers
10910
10972
  };
10911
10973
  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);
@@ -13495,7 +13557,7 @@ function decodeBranding(source) {
13495
13557
  DEFAULT_BRANDING.whopSelection
13496
13558
  ),
13497
13559
  paypalValidTint: parseBool(extras["paypalValidTint"], DEFAULT_BRANDING.paypalValidTint),
13498
- // A look stored before todos#412 has no e-Payouts keys: the form keeps
13560
+ // A look stored before e-Payouts had its own keys has none: the form keeps
13499
13561
  // the PayPal values it was drawn with until then.
13500
13562
  epayoutsCardLayout: pickEnum(
13501
13563
  extras["epayoutsCardLayout"],
@@ -14184,7 +14246,7 @@ function parseImportedBranding(raw) {
14184
14246
  dflt.whopSelection
14185
14247
  ),
14186
14248
  paypalValidTint: parseBool(root["paypalValidTint"], dflt.paypalValidTint),
14187
- // A look stored before todos#412 has no e-Payouts keys: the form keeps
14249
+ // A look stored before e-Payouts had its own keys has none: the form keeps
14188
14250
  // the PayPal values it was drawn with until then.
14189
14251
  epayoutsCardLayout: pickEnum(
14190
14252
  root["epayoutsCardLayout"],
@@ -14644,6 +14706,52 @@ var CheckoutSession = class {
14644
14706
  }
14645
14707
  );
14646
14708
  }
14709
+ /**
14710
+ * The methods the buyer may pick for a subscription that waits for the
14711
+ * choice (`method_choice_pending`), judged for the buyer. Call it from the
14712
+ * buyer's browser: the sell-to country is read from this request's own
14713
+ * connection. A cancelled subscription answers 400, and one that already
14714
+ * bills on an account answers 409 (`DE_20`). Authenticated with the
14715
+ * subscription's client secret.
14716
+ *
14717
+ * `GET /subscriptions/method-options/{merchantId}/{subscriptionId}`
14718
+ */
14719
+ async subscriptionMethodOptions(options) {
14720
+ return this.client.request(
14721
+ "GET",
14722
+ `/subscriptions/method-options/${encodeURIComponent(this.merchantId)}/${encodeURIComponent(this.paymentId)}`,
14723
+ {
14724
+ ...options,
14725
+ headers: this.bearerHeaders(options?.headers)
14726
+ }
14727
+ );
14728
+ }
14729
+ /**
14730
+ * Bind a waiting subscription to the method the buyer picked and open its
14731
+ * first cycle on that method's billing account. The methods are judged
14732
+ * again from this request; afterwards
14733
+ * {@link CheckoutSession.fetchSubscriptionData} describes the bound
14734
+ * subscription (Stripe's Payment Element for `card`, `confirmSubscription`
14735
+ * for the others). Picking the same method again answers the bound
14736
+ * subscription. A subscription bound to another method already, or whose
14737
+ * billing account changed meanwhile, answers 409 (`DE_20`); a method not
14738
+ * offered to this buyer, or a cancelled subscription, answers 400.
14739
+ * Authenticated with the subscription's client secret.
14740
+ *
14741
+ * `POST /subscriptions/select-method/{merchantId}/{subscriptionId}`
14742
+ */
14743
+ async selectSubscriptionMethod(method, options) {
14744
+ const body = { method };
14745
+ return this.client.request(
14746
+ "POST",
14747
+ `/subscriptions/select-method/${encodeURIComponent(this.merchantId)}/${encodeURIComponent(this.paymentId)}`,
14748
+ {
14749
+ body,
14750
+ ...options,
14751
+ headers: this.bearerHeaders(options?.headers)
14752
+ }
14753
+ );
14754
+ }
14647
14755
  /**
14648
14756
  * Confirm a subscription (PayPal approval rail). The client secret is
14649
14757
  * attached automatically; the shop's profile id travels as the
@@ -14917,7 +15025,9 @@ var CheckoutSession = class {
14917
15025
  * Only `authorized: true` permits the form to contact its processor. A
14918
15026
  * competing flow receives `false` and must reload; an unresolved provider
14919
15027
  * outcome stays reserved, regardless of elapsed time. A buyer-blocklist
14920
- * refusal throws a `DelopayError` with code `DE_14`.
15028
+ * refusal throws a `DelopayError` with code `DE_14`; a shop whose payments
15029
+ * DeloPay stopped is refused with `DE_22`, and a shop whose payments the
15030
+ * merchant switched off with `DE_21`.
14921
15031
  *
14922
15032
  * `POST /payment-link/{merchantId}/{paymentId}/browser-card-claim`
14923
15033
  */
@@ -14943,7 +15053,11 @@ var CheckoutSession = class {
14943
15053
  * against the shop's sell-to restrictions before Stripe authorises, and a
14944
15054
  * refusal throws a `DelopayError` with code `DE_10`. A buyer on the
14945
15055
  * merchant's buyer blocklist is refused before any Stripe call with code
14946
- * `DE_14` (`buyer_blocked`, 422), which names no entry. When the answer's
15056
+ * `DE_14` (`buyer_blocked`, 422), which names no entry, a shop whose
15057
+ * payments DeloPay stopped with `DE_22`, and a shop whose payments the
15058
+ * merchant switched off with `DE_21`. A buyer the merchant's buyer risk
15059
+ * model refuses fails with `DE_23` (`buyer_risk_refused`, 422), which says
15060
+ * nothing about the signals. When the answer's
14947
15061
  * `status` is `requires_action`, run `stripe.handleNextAction` with its
14948
15062
  * `client_secret` — safe, because the intent is `confirmation_method=manual`
14949
15063
  * and that secret confirms nothing without the secret key — then call this
@@ -15174,7 +15288,7 @@ var CheckoutSession = class {
15174
15288
  /**
15175
15289
  * Reopen a provider session the buyer switched away from, when they pick the
15176
15290
  * same method again, instead of opening a second session at the provider
15177
- * (delopay-todos#401). Pass an `attempt_id` from the checkout's
15291
+ *. Pass an `attempt_id` from the checkout's
15178
15292
  * `reopenable_attempts`; the attempt becomes the payment's active one again
15179
15293
  * and `redirect_url` sends the buyer back to it. Refused (`IR_16`) when the
15180
15294
  * payment no longer awaits a method, a payment is under way on the checkout,
@@ -16090,4 +16204,4 @@ export {
16090
16204
  decodeNativePanes,
16091
16205
  encodeNativePanes
16092
16206
  };
16093
- //# sourceMappingURL=chunk-GHDAF4L4.js.map
16207
+ //# sourceMappingURL=chunk-SL2XR4QR.js.map