@deliverart/sdk-js-subscription

中文文档
3.0.1发布于 2026/11/11TypeScriptESM + CJS近 30 天下载 2914

Deliverart JavaScript SDK for Subscription Management

原始使用文档
文档目录9 节
  1. Highlights
  2. Subscription Plan Catalog
  3. Admin Plan Assignment
  4. Subscription Purchase
  5. Renewal Payment Start
  6. Renewal Payment Resolution
  7. Admin Billing Read Models
  8. Renewal Lifecycle Actions
  9. Renewal Payment Relation

@deliverart/sdk-js-subscription

Subscription management package for the Deliverart JavaScript SDK.

Highlights

  • subscription plan CRUD for backoffice/admin flows
  • public catalog for purchasable subscription plans
  • initial subscription purchase flow with payment start and offline payment resolution
  • subscription CRUD for infinite, consumption and time_based
  • renewal CRUD for consumption and time_based
  • subscription overview from point of sale
  • admin billing queue and billing overview
  • credit adjustments for consumption subscriptions
  • renewal payment initialization for stripe and bank_transfer
  • manual renewal payment resolution for offline payment methods
  • purchase lifecycle actions: cancel, retry_payment, refund
  • renewal lifecycle actions: cancel, retry_payment, refund

Subscription Plan Catalog

import { GetSubscriptionPlanCatalog } from '@deliverart/sdk-js-subscription'

const plans = await sdk.call(new GetSubscriptionPlanCatalog())

Each catalog item exposes the plan configuration plus priceOptions, already sorted by threshold.

Preview the self-service charge before creating a purchase:

import { CalculateSubscriptionPlanPurchaseQuote } from '@deliverart/sdk-js-subscription'

const quote = await sdk.call(
  new CalculateSubscriptionPlanPurchaseQuote('plan-id', {
    pointOfSale: '/point_of_sales/pos-id',
    startsAt: '2026-04-05',
  }),
)

The response includes threshold, unitPrice, amount, type, startsAt and the effective autoRenewal.

Admin Plan Assignment

Assign a plan directly to a point of sale without going through the public purchase flow:

import { AssignSubscriptionPlan } from '@deliverart/sdk-js-subscription'

const subscription = await sdk.call(
  new AssignSubscriptionPlan('plan-id', {
    pointOfSale: '/point_of_sales/pos-id',
    startsAt: '2026-04-01',
  }),
)

This operation is intended for admin/backoffice flows, including adminOnly and infinite plans.

Subscription Purchase

Create a purchase from a public plan:

import { CreateSubscriptionPurchase } from '@deliverart/sdk-js-subscription'

const purchase = await sdk.call(
  new CreateSubscriptionPurchase({
    pointOfSale: '/point_of_sales/pos-id',
    plan: '/subscription_plans/plan-id',
  }),
)

Start payment for the purchase:

import { PaySubscriptionPurchase } from '@deliverart/sdk-js-subscription'

const payment = await sdk.call(
  new PaySubscriptionPurchase('purchase-id', 'bank_transfer'),
)

Subscription billing is platform-level:

  • order and ecommerce payments still use each POS payment configuration
  • subscription purchases and renewals use the central platform billing account
  • the SDK therefore accepts only stripe and bank_transfer for subscription payment start and retry

Resolve offline payment:

import { ResolveSubscriptionPurchasePayment } from '@deliverart/sdk-js-subscription'

await sdk.call(
  new ResolveSubscriptionPurchasePayment('purchase-id', {
    status: 'paid',
    response: 'verified by admin',
  }),
)

For bank_transfer, the purchase or renewal moves to pending_verification until a ROLE_SUBSCRIPTION_BILLING_ADMIN, ROLE_SUBSCRIPTION_ADMIN or ROLE_SUPER_ADMIN approves or rejects it.

Cancel a non-completed purchase:

import { CancelSubscriptionPurchase } from '@deliverart/sdk-js-subscription'

await sdk.call(
  new CancelSubscriptionPurchase('purchase-id', {
    response: 'customer cancelled before payment',
  }),
)

Retry a failed purchase payment:

import { RetrySubscriptionPurchasePayment } from '@deliverart/sdk-js-subscription'

const payment = await sdk.call(
  new RetrySubscriptionPurchasePayment('purchase-id', 'bank_transfer'),
)

If the retry method is bank_transfer, the returned purchase status becomes pending_verification.

Refund a completed offline purchase:

import { RefundSubscriptionPurchase } from '@deliverart/sdk-js-subscription'

await sdk.call(
  new RefundSubscriptionPurchase('purchase-id', {
    response: 'manual refund approved',
  }),
)

Renewal Payment Start

Consumption renewal:

import { PaySubscriptionConsumptionRenewal } from '@deliverart/sdk-js-subscription'

const payment = await sdk.call(
  new PaySubscriptionConsumptionRenewal('renewal-id', 'bank_transfer'),
)

Time-based renewal:

import { PaySubscriptionTimeBasedRenewal } from '@deliverart/sdk-js-subscription'

const payment = await sdk.call(
  new PaySubscriptionTimeBasedRenewal('renewal-id', 'stripe'),
)

Both requests return the same PaymentInfo shape used by the payment SDK area.

Renewal Payment Resolution

Consumption renewal:

import { ResolveSubscriptionConsumptionRenewalPayment } from '@deliverart/sdk-js-subscription'

await sdk.call(
  new ResolveSubscriptionConsumptionRenewalPayment('renewal-id', {
    status: 'paid',
    response: 'verified by admin',
  }),
)

Time-based renewal:

import { ResolveSubscriptionTimeBasedRenewalPayment } from '@deliverart/sdk-js-subscription'

await sdk.call(
  new ResolveSubscriptionTimeBasedRenewalPayment('renewal-id', {
    status: 'failed',
    response: 'bank transfer rejected',
  }),
)

Allowed statuses are paid, failed and canceled.

The renewal must typically be in pending_verification before manual approval.

Admin Billing Read Models

Pending verification queue:

import { GetSubscriptionBillingPendingVerification } from '@deliverart/sdk-js-subscription'

const queue = await sdk.call(
  new GetSubscriptionBillingPendingVerification({
    query: {
      kind: 'purchase',
      olderThanHours: 24,
      limit: 20,
    },
  }),
)

Billing overview counters:

import { GetSubscriptionBillingOverview } from '@deliverart/sdk-js-subscription'

const overview = await sdk.call(new GetSubscriptionBillingOverview())

The overview payload exposes:

  • pending verification counts for purchases and renewals
  • failed payment counts
  • open purchase counts
  • pending renewal counts
  • a queuePreview array with the same item shape returned by the pending verification queue

Renewal Lifecycle Actions

Consumption renewal:

import {
  CancelSubscriptionConsumptionRenewal,
  RetrySubscriptionConsumptionRenewalPayment,
  RefundSubscriptionConsumptionRenewal,
} from '@deliverart/sdk-js-subscription'

await sdk.call(
  new CancelSubscriptionConsumptionRenewal('renewal-id', {
    response: 'operator canceled renewal',
  }),
)

const payment = await sdk.call(
  new RetrySubscriptionConsumptionRenewalPayment('renewal-id', 'bank_transfer'),
)

await sdk.call(
  new RefundSubscriptionConsumptionRenewal('renewal-id', {
    response: 'manual credit refund',
  }),
)

Time-based renewal:

import {
  CancelSubscriptionTimeBasedRenewal,
  RetrySubscriptionTimeBasedRenewalPayment,
  RefundSubscriptionTimeBasedRenewal,
} from '@deliverart/sdk-js-subscription'

await sdk.call(
  new CancelSubscriptionTimeBasedRenewal('renewal-id', {
    response: 'operator canceled renewal',
  }),
)

const payment = await sdk.call(
  new RetrySubscriptionTimeBasedRenewalPayment('renewal-id', 'bank_transfer'),
)

await sdk.call(
  new RefundSubscriptionTimeBasedRenewal('renewal-id', {
    response: 'manual time-based refund',
  }),
)

cancel and retry_payment are for non-completed renewals. refund is for completed offline renewals and returns a lifecycle summary including payment info plus rolled-back credits or restored expiration.

Renewal Payment Relation

Renewal list/detail schemas now expose the linked payment IRI when a payment attempt already exists.

版本与发布记录

@deliverart/sdk-js-subscription 共发布 125 个版本,首次发布于 2026/03/24;过去 12 个月发布了 125 个版本。

版本发布日期距今
3.0.1latest2026/11/111 天前
3.0.02026/11/092 天前
3.0.0-dev.1dev2026/11/092 天前
2.48.12026/10/2518 天前
2.48.02026/10/2319 天前
2.47.02026/10/2319 天前

关于 @deliverart/sdk-js-subscription 的常见问题

@deliverart/sdk-js-subscription 是什么?

Deliverart JavaScript SDK for Subscription Management

如何安装 @deliverart/sdk-js-subscription?

在项目目录运行 npm install @deliverart/sdk-js-subscription,或使用 pnpm add / yarn add / bun add。

@deliverart/sdk-js-subscription 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@deliverart/sdk-js-subscription 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@deliverart/sdk-js-subscription 可以商用吗?

@deliverart/sdk-js-subscription 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@deliverart/sdk-js-subscription 的下载量有多少?

根据 npm 官方下载统计,@deliverart/sdk-js-subscription 在 2026/10/12 – 2026/11/10 这 30 天内被下载 2,914 次,日均约 97 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@deliverart/sdk-js-subscription 还在维护吗?

最新版本 3.0.1 发布于 2026/11/11(1 天前);至今共发布 125 个版本,其中过去 12 个月发布了 125 个;首次发布于 2026/03/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。