@deliverart/sdk-js-subscription 0.0.0-dev-20260721002647
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 +294 -0
- package/dist/index.cjs +2871 -0
- package/dist/index.d.cts +9635 -0
- package/dist/index.d.ts +9635 -0
- package/dist/index.js +2556 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# @deliverart/sdk-js-subscription
|
|
2
|
+
|
|
3
|
+
Subscription management package for the Deliverart JavaScript SDK.
|
|
4
|
+
|
|
5
|
+
## Highlights
|
|
6
|
+
|
|
7
|
+
- subscription plan CRUD for backoffice/admin flows
|
|
8
|
+
- public catalog for purchasable subscription plans
|
|
9
|
+
- initial subscription purchase flow with payment start and offline payment resolution
|
|
10
|
+
- subscription CRUD for `infinite`, `consumption` and `time_based`
|
|
11
|
+
- renewal CRUD for `consumption` and `time_based`
|
|
12
|
+
- subscription overview from point of sale
|
|
13
|
+
- admin billing queue and billing overview
|
|
14
|
+
- credit adjustments for consumption subscriptions
|
|
15
|
+
- renewal payment initialization for `stripe` and `bank_transfer`
|
|
16
|
+
- manual renewal payment resolution for offline payment methods
|
|
17
|
+
- purchase lifecycle actions: `cancel`, `retry_payment`, `refund`
|
|
18
|
+
- renewal lifecycle actions: `cancel`, `retry_payment`, `refund`
|
|
19
|
+
|
|
20
|
+
## Subscription Plan Catalog
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { GetSubscriptionPlanCatalog } from '@deliverart/sdk-js-subscription'
|
|
24
|
+
|
|
25
|
+
const plans = await sdk.call(new GetSubscriptionPlanCatalog())
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Each catalog item exposes the plan configuration plus `priceOptions`, already sorted by threshold.
|
|
29
|
+
|
|
30
|
+
Preview the self-service charge before creating a purchase:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { CalculateSubscriptionPlanPurchaseQuote } from '@deliverart/sdk-js-subscription'
|
|
34
|
+
|
|
35
|
+
const quote = await sdk.call(
|
|
36
|
+
new CalculateSubscriptionPlanPurchaseQuote('plan-id', {
|
|
37
|
+
pointOfSale: '/point_of_sales/pos-id',
|
|
38
|
+
startsAt: '2026-04-05',
|
|
39
|
+
}),
|
|
40
|
+
)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The response includes `threshold`, `unitPrice`, `amount`, `type`, `startsAt` and the effective `autoRenewal`.
|
|
44
|
+
|
|
45
|
+
## Admin Plan Assignment
|
|
46
|
+
|
|
47
|
+
Assign a plan directly to a point of sale without going through the public purchase flow:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { AssignSubscriptionPlan } from '@deliverart/sdk-js-subscription'
|
|
51
|
+
|
|
52
|
+
const subscription = await sdk.call(
|
|
53
|
+
new AssignSubscriptionPlan('plan-id', {
|
|
54
|
+
pointOfSale: '/point_of_sales/pos-id',
|
|
55
|
+
startsAt: '2026-04-01',
|
|
56
|
+
}),
|
|
57
|
+
)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
This operation is intended for admin/backoffice flows, including `adminOnly` and `infinite` plans.
|
|
61
|
+
|
|
62
|
+
## Subscription Purchase
|
|
63
|
+
|
|
64
|
+
Create a purchase from a public plan:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { CreateSubscriptionPurchase } from '@deliverart/sdk-js-subscription'
|
|
68
|
+
|
|
69
|
+
const purchase = await sdk.call(
|
|
70
|
+
new CreateSubscriptionPurchase({
|
|
71
|
+
pointOfSale: '/point_of_sales/pos-id',
|
|
72
|
+
plan: '/subscription_plans/plan-id',
|
|
73
|
+
}),
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Start payment for the purchase:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { PaySubscriptionPurchase } from '@deliverart/sdk-js-subscription'
|
|
81
|
+
|
|
82
|
+
const payment = await sdk.call(
|
|
83
|
+
new PaySubscriptionPurchase('purchase-id', 'bank_transfer'),
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Subscription billing is platform-level:
|
|
88
|
+
|
|
89
|
+
- order and ecommerce payments still use each POS payment configuration
|
|
90
|
+
- subscription purchases and renewals use the central platform billing account
|
|
91
|
+
- the SDK therefore accepts only `stripe` and `bank_transfer` for subscription payment start and retry
|
|
92
|
+
|
|
93
|
+
Resolve offline payment:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { ResolveSubscriptionPurchasePayment } from '@deliverart/sdk-js-subscription'
|
|
97
|
+
|
|
98
|
+
await sdk.call(
|
|
99
|
+
new ResolveSubscriptionPurchasePayment('purchase-id', {
|
|
100
|
+
status: 'paid',
|
|
101
|
+
response: 'verified by admin',
|
|
102
|
+
}),
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
For `bank_transfer`, the purchase or renewal moves to `pending_verification` until a
|
|
107
|
+
`ROLE_SUBSCRIPTION_BILLING_ADMIN`, `ROLE_SUBSCRIPTION_ADMIN` or `ROLE_SUPER_ADMIN`
|
|
108
|
+
approves or rejects it.
|
|
109
|
+
|
|
110
|
+
Cancel a non-completed purchase:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { CancelSubscriptionPurchase } from '@deliverart/sdk-js-subscription'
|
|
114
|
+
|
|
115
|
+
await sdk.call(
|
|
116
|
+
new CancelSubscriptionPurchase('purchase-id', {
|
|
117
|
+
response: 'customer cancelled before payment',
|
|
118
|
+
}),
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Retry a failed purchase payment:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { RetrySubscriptionPurchasePayment } from '@deliverart/sdk-js-subscription'
|
|
126
|
+
|
|
127
|
+
const payment = await sdk.call(
|
|
128
|
+
new RetrySubscriptionPurchasePayment('purchase-id', 'bank_transfer'),
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
If the retry method is `bank_transfer`, the returned purchase status becomes `pending_verification`.
|
|
133
|
+
|
|
134
|
+
Refund a completed offline purchase:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import { RefundSubscriptionPurchase } from '@deliverart/sdk-js-subscription'
|
|
138
|
+
|
|
139
|
+
await sdk.call(
|
|
140
|
+
new RefundSubscriptionPurchase('purchase-id', {
|
|
141
|
+
response: 'manual refund approved',
|
|
142
|
+
}),
|
|
143
|
+
)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Renewal Payment Start
|
|
147
|
+
|
|
148
|
+
Consumption renewal:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { PaySubscriptionConsumptionRenewal } from '@deliverart/sdk-js-subscription'
|
|
152
|
+
|
|
153
|
+
const payment = await sdk.call(
|
|
154
|
+
new PaySubscriptionConsumptionRenewal('renewal-id', 'bank_transfer'),
|
|
155
|
+
)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Time-based renewal:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { PaySubscriptionTimeBasedRenewal } from '@deliverart/sdk-js-subscription'
|
|
162
|
+
|
|
163
|
+
const payment = await sdk.call(
|
|
164
|
+
new PaySubscriptionTimeBasedRenewal('renewal-id', 'stripe'),
|
|
165
|
+
)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Both requests return the same `PaymentInfo` shape used by the payment SDK area.
|
|
169
|
+
|
|
170
|
+
## Renewal Payment Resolution
|
|
171
|
+
|
|
172
|
+
Consumption renewal:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import { ResolveSubscriptionConsumptionRenewalPayment } from '@deliverart/sdk-js-subscription'
|
|
176
|
+
|
|
177
|
+
await sdk.call(
|
|
178
|
+
new ResolveSubscriptionConsumptionRenewalPayment('renewal-id', {
|
|
179
|
+
status: 'paid',
|
|
180
|
+
response: 'verified by admin',
|
|
181
|
+
}),
|
|
182
|
+
)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Time-based renewal:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { ResolveSubscriptionTimeBasedRenewalPayment } from '@deliverart/sdk-js-subscription'
|
|
189
|
+
|
|
190
|
+
await sdk.call(
|
|
191
|
+
new ResolveSubscriptionTimeBasedRenewalPayment('renewal-id', {
|
|
192
|
+
status: 'failed',
|
|
193
|
+
response: 'bank transfer rejected',
|
|
194
|
+
}),
|
|
195
|
+
)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Allowed statuses are `paid`, `failed` and `canceled`.
|
|
199
|
+
|
|
200
|
+
The renewal must typically be in `pending_verification` before manual approval.
|
|
201
|
+
|
|
202
|
+
## Admin Billing Read Models
|
|
203
|
+
|
|
204
|
+
Pending verification queue:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import { GetSubscriptionBillingPendingVerification } from '@deliverart/sdk-js-subscription'
|
|
208
|
+
|
|
209
|
+
const queue = await sdk.call(
|
|
210
|
+
new GetSubscriptionBillingPendingVerification({
|
|
211
|
+
query: {
|
|
212
|
+
kind: 'purchase',
|
|
213
|
+
olderThanHours: 24,
|
|
214
|
+
limit: 20,
|
|
215
|
+
},
|
|
216
|
+
}),
|
|
217
|
+
)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Billing overview counters:
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
import { GetSubscriptionBillingOverview } from '@deliverart/sdk-js-subscription'
|
|
224
|
+
|
|
225
|
+
const overview = await sdk.call(new GetSubscriptionBillingOverview())
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
The overview payload exposes:
|
|
229
|
+
|
|
230
|
+
- pending verification counts for purchases and renewals
|
|
231
|
+
- failed payment counts
|
|
232
|
+
- open purchase counts
|
|
233
|
+
- pending renewal counts
|
|
234
|
+
- a `queuePreview` array with the same item shape returned by the pending verification queue
|
|
235
|
+
|
|
236
|
+
## Renewal Lifecycle Actions
|
|
237
|
+
|
|
238
|
+
Consumption renewal:
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
import {
|
|
242
|
+
CancelSubscriptionConsumptionRenewal,
|
|
243
|
+
RetrySubscriptionConsumptionRenewalPayment,
|
|
244
|
+
RefundSubscriptionConsumptionRenewal,
|
|
245
|
+
} from '@deliverart/sdk-js-subscription'
|
|
246
|
+
|
|
247
|
+
await sdk.call(
|
|
248
|
+
new CancelSubscriptionConsumptionRenewal('renewal-id', {
|
|
249
|
+
response: 'operator canceled renewal',
|
|
250
|
+
}),
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
const payment = await sdk.call(
|
|
254
|
+
new RetrySubscriptionConsumptionRenewalPayment('renewal-id', 'bank_transfer'),
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
await sdk.call(
|
|
258
|
+
new RefundSubscriptionConsumptionRenewal('renewal-id', {
|
|
259
|
+
response: 'manual credit refund',
|
|
260
|
+
}),
|
|
261
|
+
)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Time-based renewal:
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
import {
|
|
268
|
+
CancelSubscriptionTimeBasedRenewal,
|
|
269
|
+
RetrySubscriptionTimeBasedRenewalPayment,
|
|
270
|
+
RefundSubscriptionTimeBasedRenewal,
|
|
271
|
+
} from '@deliverart/sdk-js-subscription'
|
|
272
|
+
|
|
273
|
+
await sdk.call(
|
|
274
|
+
new CancelSubscriptionTimeBasedRenewal('renewal-id', {
|
|
275
|
+
response: 'operator canceled renewal',
|
|
276
|
+
}),
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
const payment = await sdk.call(
|
|
280
|
+
new RetrySubscriptionTimeBasedRenewalPayment('renewal-id', 'bank_transfer'),
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
await sdk.call(
|
|
284
|
+
new RefundSubscriptionTimeBasedRenewal('renewal-id', {
|
|
285
|
+
response: 'manual time-based refund',
|
|
286
|
+
}),
|
|
287
|
+
)
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
`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.
|
|
291
|
+
|
|
292
|
+
## Renewal Payment Relation
|
|
293
|
+
|
|
294
|
+
Renewal list/detail schemas now expose the linked `payment` IRI when a payment attempt already exists.
|