@delopay/sdk 0.189.0 → 0.192.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
@@ -330,6 +330,67 @@ const all = await delopay.subscriptions.list({ limit: 20 }, opts);
330
330
  Each billing cycle raises an invoice (`sub.invoice`) with its own payment leg
331
331
  (`sub.payment`); track cycle outcomes via the subscription/invoice webhooks.
332
332
 
333
+ **Bill on a catalog product.** Instead of the processor's `item_price_id`, name a
334
+ recurring product of the shop (and optionally one of its prices). The server
335
+ resolves it to the reference the billing account holds and refuses the request
336
+ before anything is charged when the processor's price no longer matches. Check
337
+ first which prices can start a subscription:
338
+
339
+ ```typescript
340
+ const { prices } = await delopay.products.billingReadiness(['prd_pro'], profileId);
341
+ // state: 'ready' | 'unverified' | 'other_environment' | 'needs_reference'
342
+
343
+ await delopay.subscriptions.createAndConfirm(
344
+ { product_id: 'prd_pro', customer_id: 'cus_abc123', payment_details: { payment_method_id: pm } },
345
+ opts,
346
+ );
347
+ await delopay.subscriptions.update(sub.id, { product_id: 'prd_pro', price_id: 'prc_yearly' }, opts);
348
+ ```
349
+
350
+ **Mirror the processor.** `subscriptions.sync({ subscription_ids })` (1 to 50) and
351
+ `subscriptions.syncOne(id)` read subscriptions back from the processor and mirror
352
+ what it reports; nothing is written there.
353
+
354
+ **Take existing processor subscriptions over.** `subscriptions.importPreview`
355
+ lists what a billing account holds and classifies each row; `importApply` adopts
356
+ up to 25 of them. Word `capabilities.reason_code` and each row's `note_code`
357
+ yourself; the English `reason` / `note` beside them are for API callers.
358
+
359
+ ```typescript
360
+ const preview = await delopay.subscriptions.importPreview({ merchant_connector_id: mca }, opts);
361
+
362
+ if (!preview.capabilities.listing || !preview.capabilities.adoption) {
363
+ // PayPal cannot be listed (`reason_code: 'listing_unsupported'`); an
364
+ // account may list without allowing adoption. Say why, and stop.
365
+ showUnavailable(preview.capabilities.reason_code);
366
+ } else {
367
+ // Rows whose buyer is already a DeloPay customer can be taken over as they
368
+ // are; `needs_customer` rows need a customer named first.
369
+ const picks = preview.items.flatMap((row) =>
370
+ row.classification === 'new' && row.customer_id
371
+ ? [{ external_subscription_id: row.external_subscription_id, customer_id: row.customer_id }]
372
+ : [],
373
+ );
374
+ // The route takes 1 to 25 selections: send nothing when there is nothing
375
+ // to take over, and batch anything larger.
376
+ for (let i = 0; i < picks.length; i += 25) {
377
+ const { results } = await delopay.subscriptions.importApply(
378
+ { merchant_connector_id: mca, items: picks.slice(i, i + 25) },
379
+ opts,
380
+ );
381
+ // One result per selection: `adopted`, `already_held`, or `failed` with a `reason_code`.
382
+ }
383
+ }
384
+ ```
385
+
386
+ **A buyer returning from the processor's checkout** can read the subscription's
387
+ status with the return token (`rt`) the return URL carried, from the browser:
388
+
389
+ ```typescript
390
+ const session = new CheckoutSession({ merchantId, paymentId: subscriptionId });
391
+ const { status, awaiting_processor } = await session.subscriptionReturnStatus(rt);
392
+ ```
393
+
333
394
  ### Platform fee rules
334
395
 
335
396
  Price the platform fee by payment method, connector, amount, currency or card
@@ -3073,6 +3073,12 @@ var Routing = class {
3073
3073
  * Every account named must belong to this shop; one that does not is refused.
3074
3074
  * So is an amount cap without a `currency`, and a payment cap with one.
3075
3075
  *
3076
+ * An account may appear twice — a payment count and a budget — and never
3077
+ * twice in one `unit`. Re-send a range with its `limit_max`, or it is stored
3078
+ * as its bottom. Never re-send `current_limit` as `set_current_limit`: the
3079
+ * value read belongs to the window it was read in, and pinning it into a
3080
+ * window that has since reset is a limit nobody chose.
3081
+ *
3076
3082
  * `PUT /routing/connector-caps/{profileId}`
3077
3083
  */
3078
3084
  async setConnectorCaps(profileId, params) {
@@ -4034,6 +4040,33 @@ var Users = class {
4034
4040
  async changeMemberScope(params) {
4035
4041
  return this.request("POST", "/user/employees/change-scope", { body: params });
4036
4042
  }
4043
+ /**
4044
+ * One member of your merchant, with the person fields the member list
4045
+ * omits. `GET /user/employees/{user_id}/details`
4046
+ *
4047
+ * Answers only for a member `listUsersInLineage` shows you. Any other id,
4048
+ * unknown or not yours, is a 404 `UR_68` with `data.reason:
4049
+ * 'member_not_found'`.
4050
+ */
4051
+ async getTeamMemberDetails(userId) {
4052
+ return this.request("GET", `/user/employees/${encodeURIComponent(userId)}/details`);
4053
+ }
4054
+ /**
4055
+ * Replace a team member's password with a temporary one, returned once.
4056
+ * `POST /user/employees/{user_id}/reset-password`
4057
+ *
4058
+ * Needs the *Users* write permission and the *Impersonation* permission,
4059
+ * and the member must be one you could sign in as with
4060
+ * `impersonateEmployee`. The member's sessions end, and their next sign-in
4061
+ * asks them to choose a new password. Two-factor authentication is left as
4062
+ * it is. `TeamMemberDetails.can_reset_password` answers the same rule. A
4063
+ * refusal is a `UR_68` error whose `data` is a {@link TeamMemberRefusal}.
4064
+ */
4065
+ async resetTeamMemberPassword(userId, params) {
4066
+ return this.request("POST", `/user/employees/${encodeURIComponent(userId)}/reset-password`, {
4067
+ body: params
4068
+ });
4069
+ }
4037
4070
  /** Sign in via OIDC. `POST /user/oidc` */
4038
4071
  async signInOidc(params) {
4039
4072
  return this.request("POST", "/user/oidc", { body: params });
@@ -5036,6 +5069,25 @@ var Products = class {
5036
5069
  query: { ...query }
5037
5070
  });
5038
5071
  }
5072
+ /**
5073
+ * Which active prices of the named recurring products can start a
5074
+ * subscription on the shop's billing processor account, in the environment
5075
+ * the account is in now. `GET /products/billing-readiness`
5076
+ *
5077
+ * Reads only; subscribing still checks the processor's price before
5078
+ * anything is billed. Unknown ids, one-time products and archived prices
5079
+ * are left out of the answer.
5080
+ *
5081
+ * @param productIds - 1 to 100 product ids.
5082
+ * @param profileId - The shop the products belong to.
5083
+ */
5084
+ async billingReadiness(productIds, profileId, options) {
5085
+ return this.request("GET", "/products/billing-readiness", {
5086
+ ...this.scoped(profileId, options),
5087
+ // One comma-separated value, as the route reads it — not repeated keys.
5088
+ query: { product_ids: productIds.join(",") }
5089
+ });
5090
+ }
5039
5091
  /**
5040
5092
  * Change a product's name, description, image, metadata or category
5041
5093
  * (`category_id: null` makes it uncategorized).
@@ -5685,6 +5737,31 @@ var Subscriptions = class {
5685
5737
  ...options
5686
5738
  });
5687
5739
  }
5740
+ /**
5741
+ * {@link getItems}, with whether the list is only the first part of what the
5742
+ * processor holds. `GET /subscriptions/items`
5743
+ *
5744
+ * The backend states that in the `X-Delopay-Items-Truncated` response
5745
+ * header (Stripe Billing lists its first 100 products), which the plain
5746
+ * {@link getItems} cannot return. Without `limit` and `offset` every item
5747
+ * the billing account offers is listed, up to 500.
5748
+ */
5749
+ async getItemsPage(params, options) {
5750
+ let truncated = false;
5751
+ const items = await this.request(
5752
+ "GET",
5753
+ "/subscriptions/items",
5754
+ {
5755
+ query: params,
5756
+ ...options,
5757
+ onDownloadProgress: (event) => {
5758
+ truncated = event.headers.get("x-delopay-items-truncated")?.toLowerCase() === "true";
5759
+ options?.onDownloadProgress?.(event);
5760
+ }
5761
+ }
5762
+ );
5763
+ return { items, truncated };
5764
+ }
5688
5765
  /**
5689
5766
  * Pause a subscription. `POST /subscriptions/{subscriptionId}/pause`
5690
5767
  *
@@ -5705,13 +5782,64 @@ var Subscriptions = class {
5705
5782
  ...options
5706
5783
  });
5707
5784
  }
5708
- /** Cancel a subscription. `POST /subscriptions/{subscriptionId}/cancel` */
5785
+ /**
5786
+ * Cancel a subscription. `POST /subscriptions/{subscriptionId}/cancel`
5787
+ *
5788
+ * A subscription in a state it cannot be cancelled from is refused with
5789
+ * `DE_11`; `error.data.reason` then names why (`SubscriptionActionRefusal`).
5790
+ */
5709
5791
  async cancel(subscriptionId, params, options) {
5710
5792
  return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`, {
5711
5793
  body: params ?? {},
5712
5794
  ...options
5713
5795
  });
5714
5796
  }
5797
+ /**
5798
+ * Read 1 to 50 subscriptions back from their billing processor and mirror
5799
+ * what it reports. `POST /subscriptions/sync`
5800
+ *
5801
+ * Nothing is written at the processor. A status is mirrored only with the
5802
+ * time the processor stamped it with, and never over a newer event already
5803
+ * recorded; a plan only with its own stamp. One result per id, in request
5804
+ * order; one that fails does not stop the others.
5805
+ */
5806
+ async sync(params, options) {
5807
+ return this.request("POST", "/subscriptions/sync", { body: params, ...options });
5808
+ }
5809
+ /**
5810
+ * Read one subscription back from its billing processor and mirror what it
5811
+ * reports, as {@link sync} does, with what the processor reported beside
5812
+ * what the mirror now holds. `POST /subscriptions/{subscriptionId}/sync`
5813
+ */
5814
+ async syncOne(subscriptionId, options) {
5815
+ return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/sync`, {
5816
+ ...options
5817
+ });
5818
+ }
5819
+ /**
5820
+ * List the subscriptions a billing account holds at its processor, and how
5821
+ * each relates to DeloPay's: already held, new (its buyer is a DeloPay
5822
+ * customer), needing a customer, ended, or not adoptable here.
5823
+ * `POST /subscriptions/import/preview`
5824
+ *
5825
+ * Reads only; nothing is written here or at the processor. Creem and
5826
+ * Stripe Billing can be listed; PayPal cannot, which `capabilities` states
5827
+ * (`reason_code: 'listing_unsupported'`).
5828
+ */
5829
+ async importPreview(params, options) {
5830
+ return this.request("POST", "/subscriptions/import/preview", { body: params, ...options });
5831
+ }
5832
+ /**
5833
+ * Take 1 to 25 processor subscriptions over, each through {@link adopt}
5834
+ * with every one of its checks, one after another.
5835
+ * `POST /subscriptions/import/apply`
5836
+ *
5837
+ * One result per selection, in request order; one refused does not stop
5838
+ * the others.
5839
+ */
5840
+ async importApply(params, options) {
5841
+ return this.request("POST", "/subscriptions/import/apply", { body: params, ...options });
5842
+ }
5715
5843
  /**
5716
5844
  * Resolve which of the given payments were raised by a subscription.
5717
5845
  * `POST /subscriptions/payments/lookup`
@@ -9971,6 +10099,38 @@ var CheckoutSession = class {
9971
10099
  }
9972
10100
  );
9973
10101
  }
10102
+ /**
10103
+ * The status a buyer coming back from the processor's checkout may read:
10104
+ * the subscription's status, and whether the processor has reported it yet
10105
+ * (`awaiting_processor`). Construct the session with the `sub_…` id in the
10106
+ * `paymentId` slot.
10107
+ *
10108
+ * Authenticated with the return token (`rt`) the return URL carried, sent as
10109
+ * `Authorization: Bearer <rt>`. That token reads only this, for a day; it is
10110
+ * never the client secret, which this call does not send.
10111
+ *
10112
+ * `GET /subscriptions/return-status/{merchantId}/{subscriptionId}`
10113
+ */
10114
+ async subscriptionReturnStatus(returnToken, options) {
10115
+ if (!returnToken) {
10116
+ throw new DelopayError("This call requires the return token (rt) from the return URL", {
10117
+ status: 0,
10118
+ code: "MISSING_CREDENTIAL",
10119
+ type: "invalid_request"
10120
+ });
10121
+ }
10122
+ return this.client.request(
10123
+ "GET",
10124
+ `/subscriptions/return-status/${encodeURIComponent(this.merchantId)}/${encodeURIComponent(this.paymentId)}`,
10125
+ {
10126
+ ...options,
10127
+ headers: {
10128
+ ...withoutCredentialHeaders(options?.headers),
10129
+ Authorization: `Bearer ${returnToken}`
10130
+ }
10131
+ }
10132
+ );
10133
+ }
9974
10134
  /**
9975
10135
  * Confirm a subscription (PayPal approval rail). The client secret is
9976
10136
  * attached automatically; the shop's profile id travels as the
@@ -10938,4 +11098,4 @@ export {
10938
11098
  decodeNativePanes,
10939
11099
  encodeNativePanes
10940
11100
  };
10941
- //# sourceMappingURL=chunk-7M6HDH2Q.js.map
11101
+ //# sourceMappingURL=chunk-BIAYMQN7.js.map