better-auth-streampay 0.1.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/LICENSE +21 -0
- package/README.md +473 -0
- package/dist/client.cjs +13 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +12 -0
- package/dist/client.d.ts +12 -0
- package/dist/client.js +11 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +878 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +125 -0
- package/dist/index.d.ts +125 -0
- package/dist/index.js +863 -0
- package/dist/index.js.map +1 -0
- package/dist/streampay-DFc4fN8R.d.cts +1583 -0
- package/dist/streampay-DFc4fN8R.d.ts +1583 -0
- package/package.json +82 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,863 @@
|
|
|
1
|
+
import { createAuthEndpoint, getSessionFromCtx, APIError, sessionMiddleware } from 'better-auth/api';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { createHmac, timingSafeEqual } from 'crypto';
|
|
4
|
+
|
|
5
|
+
// src/plugins/checkout.ts
|
|
6
|
+
|
|
7
|
+
// src/utils/consumer.ts
|
|
8
|
+
async function findConsumerByExternalId(client, { externalId, maxPages = 10, pageSize = 100 }) {
|
|
9
|
+
const hit = await scanConsumers(
|
|
10
|
+
client,
|
|
11
|
+
{ maxPages, pageSize },
|
|
12
|
+
(c) => c.external_id === externalId
|
|
13
|
+
);
|
|
14
|
+
return hit?.id ?? null;
|
|
15
|
+
}
|
|
16
|
+
async function findConsumerByIdentifiers(client, identifiers, opts = {}) {
|
|
17
|
+
const { maxPages = 10, pageSize = 100 } = opts;
|
|
18
|
+
return scanConsumers(client, { maxPages, pageSize }, (c) => matchesAnyIdentifier(c, identifiers));
|
|
19
|
+
}
|
|
20
|
+
function matchesAnyIdentifier(consumer, identifiers) {
|
|
21
|
+
if (identifiers.email && consumer.email === identifiers.email) return true;
|
|
22
|
+
if (identifiers.phone_number && consumer.phone_number === identifiers.phone_number) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (identifiers.external_id && consumer.external_id === identifiers.external_id) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (identifiers.iban && consumer.iban === identifiers.iban) return true;
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
async function scanConsumers(client, { maxPages, pageSize }, predicate) {
|
|
32
|
+
for (let page = 1; page <= maxPages; page++) {
|
|
33
|
+
const response = await client.listConsumers({ page, size: pageSize });
|
|
34
|
+
const items = response.data ?? [];
|
|
35
|
+
const hit = items.find(predicate);
|
|
36
|
+
if (hit) return hit;
|
|
37
|
+
const total = response.pagination?.total_count ?? 0;
|
|
38
|
+
if (items.length < pageSize || page * pageSize >= total) return null;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/utils/session.ts
|
|
44
|
+
function asSessionUser(user) {
|
|
45
|
+
if (user === null || typeof user !== "object") return null;
|
|
46
|
+
if (!("id" in user) || typeof user.id !== "string") return null;
|
|
47
|
+
const result = { id: user.id };
|
|
48
|
+
if ("email" in user && typeof user.email === "string") {
|
|
49
|
+
result.email = user.email;
|
|
50
|
+
}
|
|
51
|
+
if ("name" in user && typeof user.name === "string") {
|
|
52
|
+
result.name = user.name;
|
|
53
|
+
}
|
|
54
|
+
if ("isAnonymous" in user && user.isAnonymous === true) {
|
|
55
|
+
result.isAnonymous = true;
|
|
56
|
+
}
|
|
57
|
+
if ("streampayConsumerId" in user) {
|
|
58
|
+
const value = user.streampayConsumerId;
|
|
59
|
+
if (typeof value === "string") {
|
|
60
|
+
result.streampayConsumerId = value;
|
|
61
|
+
} else if (value === null) {
|
|
62
|
+
result.streampayConsumerId = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/plugins/checkout.ts
|
|
69
|
+
var RelativeOrAbsoluteUrl = z.string().refine((val) => val.startsWith("/") || URL.canParse(val), {
|
|
70
|
+
message: "Must be a valid URL or a relative path starting with /"
|
|
71
|
+
});
|
|
72
|
+
var CheckoutBody = z.object({
|
|
73
|
+
products: z.union([
|
|
74
|
+
z.array(
|
|
75
|
+
z.object({
|
|
76
|
+
productId: z.string().uuid(),
|
|
77
|
+
quantity: z.number().int().positive().optional()
|
|
78
|
+
})
|
|
79
|
+
),
|
|
80
|
+
z.array(z.string().uuid()),
|
|
81
|
+
z.string().uuid()
|
|
82
|
+
]).optional(),
|
|
83
|
+
slug: z.string().optional(),
|
|
84
|
+
referenceId: z.string().optional(),
|
|
85
|
+
consumerId: z.string().uuid().optional(),
|
|
86
|
+
name: z.string().min(1).optional(),
|
|
87
|
+
description: z.string().optional(),
|
|
88
|
+
metadata: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
|
|
89
|
+
successUrl: RelativeOrAbsoluteUrl.optional(),
|
|
90
|
+
failureUrl: RelativeOrAbsoluteUrl.optional(),
|
|
91
|
+
maxNumberOfPayments: z.number().int().positive().optional(),
|
|
92
|
+
validUntil: z.string().datetime().optional(),
|
|
93
|
+
/**
|
|
94
|
+
* Coupon UUIDs to apply at the payment-link level. Maps directly to
|
|
95
|
+
* StreamPay's `CreatePaymentLinkDto.coupons`. Per-item coupons are
|
|
96
|
+
* not yet exposed — add them when an integrator needs them.
|
|
97
|
+
*/
|
|
98
|
+
couponIds: z.array(z.string().uuid()).optional(),
|
|
99
|
+
redirect: z.coerce.boolean().optional()
|
|
100
|
+
});
|
|
101
|
+
function buildItem(productId, quantity) {
|
|
102
|
+
return {
|
|
103
|
+
product_id: productId,
|
|
104
|
+
quantity,
|
|
105
|
+
allow_custom_quantity: false
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async function resolveProducts(body, options) {
|
|
109
|
+
if (body.slug) {
|
|
110
|
+
const pool = typeof options.products === "function" ? await options.products() : options.products;
|
|
111
|
+
const hit = pool?.find((p) => p.slug === body.slug);
|
|
112
|
+
if (!hit) {
|
|
113
|
+
throw new APIError("BAD_REQUEST", {
|
|
114
|
+
message: `Unknown product slug: ${body.slug}`
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return [buildItem(hit.productId, 1)];
|
|
118
|
+
}
|
|
119
|
+
if (body.products === void 0) {
|
|
120
|
+
throw new APIError("BAD_REQUEST", {
|
|
121
|
+
message: "Either `slug` or `products` is required."
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (typeof body.products === "string") {
|
|
125
|
+
return [buildItem(body.products, 1)];
|
|
126
|
+
}
|
|
127
|
+
if (body.products.length === 0) {
|
|
128
|
+
throw new APIError("BAD_REQUEST", {
|
|
129
|
+
message: "`products` must contain at least one item."
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return body.products.map(
|
|
133
|
+
(entry) => typeof entry === "string" ? buildItem(entry, 1) : buildItem(entry.productId, entry.quantity ?? 1)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
function resolveRedirectUrl(urlOrPath, request, baseURL) {
|
|
137
|
+
if (!urlOrPath) return void 0;
|
|
138
|
+
return new URL(urlOrPath, request?.url ?? baseURL).toString();
|
|
139
|
+
}
|
|
140
|
+
async function resolveConsumerId(client, body, user) {
|
|
141
|
+
if (body.consumerId) return body.consumerId;
|
|
142
|
+
if (!user) return null;
|
|
143
|
+
if (user.streampayConsumerId) return user.streampayConsumerId;
|
|
144
|
+
return findConsumerByExternalId(client, { externalId: user.id });
|
|
145
|
+
}
|
|
146
|
+
var checkout = (checkoutOptions = {}) => (client) => {
|
|
147
|
+
return {
|
|
148
|
+
checkout: createAuthEndpoint(
|
|
149
|
+
"/checkout",
|
|
150
|
+
{
|
|
151
|
+
method: "POST",
|
|
152
|
+
body: CheckoutBody
|
|
153
|
+
},
|
|
154
|
+
async (ctx) => {
|
|
155
|
+
const session = await getSessionFromCtx(ctx);
|
|
156
|
+
const sessionUser = asSessionUser(session?.user);
|
|
157
|
+
if (checkoutOptions.authenticatedUsersOnly) {
|
|
158
|
+
if (!sessionUser) {
|
|
159
|
+
throw new APIError("UNAUTHORIZED", {
|
|
160
|
+
message: "You must be logged in to checkout."
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (sessionUser.isAnonymous) {
|
|
164
|
+
throw new APIError("UNAUTHORIZED", {
|
|
165
|
+
message: "Anonymous users cannot checkout."
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const items = await resolveProducts(ctx.body, checkoutOptions);
|
|
170
|
+
const consumerId = await resolveConsumerId(client, ctx.body, sessionUser);
|
|
171
|
+
const successUrl = resolveRedirectUrl(
|
|
172
|
+
ctx.body.successUrl ?? checkoutOptions.successUrl,
|
|
173
|
+
ctx.request,
|
|
174
|
+
ctx.context.baseURL
|
|
175
|
+
);
|
|
176
|
+
const failureUrl = resolveRedirectUrl(
|
|
177
|
+
ctx.body.failureUrl ?? checkoutOptions.failureUrl,
|
|
178
|
+
ctx.request,
|
|
179
|
+
ctx.context.baseURL
|
|
180
|
+
);
|
|
181
|
+
const customMetadata = (() => {
|
|
182
|
+
const base = ctx.body.metadata ?? {};
|
|
183
|
+
const merged = ctx.body.referenceId ? { referenceId: ctx.body.referenceId, ...base } : base;
|
|
184
|
+
return Object.keys(merged).length > 0 ? merged : null;
|
|
185
|
+
})();
|
|
186
|
+
const payload = {
|
|
187
|
+
name: ctx.body.name ?? `Checkout ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
188
|
+
description: ctx.body.description ?? null,
|
|
189
|
+
items
|
|
190
|
+
};
|
|
191
|
+
if (consumerId !== null) payload.organization_consumer_id = consumerId;
|
|
192
|
+
if (successUrl) payload.success_redirect_url = successUrl;
|
|
193
|
+
if (failureUrl) payload.failure_redirect_url = failureUrl;
|
|
194
|
+
if (ctx.body.maxNumberOfPayments !== void 0) {
|
|
195
|
+
payload.max_number_of_payments = ctx.body.maxNumberOfPayments;
|
|
196
|
+
}
|
|
197
|
+
if (ctx.body.validUntil !== void 0) {
|
|
198
|
+
payload.valid_until = ctx.body.validUntil;
|
|
199
|
+
}
|
|
200
|
+
if (ctx.body.couponIds && ctx.body.couponIds.length > 0) {
|
|
201
|
+
payload.coupons = ctx.body.couponIds;
|
|
202
|
+
}
|
|
203
|
+
if (customMetadata !== null) payload.custom_metadata = customMetadata;
|
|
204
|
+
if (checkoutOptions.customFields) {
|
|
205
|
+
payload.custom_fields = checkoutOptions.customFields;
|
|
206
|
+
}
|
|
207
|
+
if (checkoutOptions.contactInformationType) {
|
|
208
|
+
payload.contact_information_type = checkoutOptions.contactInformationType;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
const link = await client.createPaymentLink(payload);
|
|
212
|
+
const url = client.getPaymentUrl(link);
|
|
213
|
+
if (!url) {
|
|
214
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
215
|
+
message: "StreamPay payment link created but no URL was returned."
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return ctx.json({
|
|
219
|
+
url,
|
|
220
|
+
id: link.id ?? null,
|
|
221
|
+
redirect: ctx.body.redirect ?? true
|
|
222
|
+
});
|
|
223
|
+
} catch (err) {
|
|
224
|
+
if (err instanceof APIError) throw err;
|
|
225
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
226
|
+
ctx.context.logger.error(`StreamPay checkout creation failed: ${message}`);
|
|
227
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
228
|
+
message: "StreamPay checkout creation failed."
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
var PaginationQuery = z.object({
|
|
236
|
+
page: z.coerce.number().int().positive().optional(),
|
|
237
|
+
limit: z.coerce.number().int().positive().max(200).optional()
|
|
238
|
+
}).optional();
|
|
239
|
+
async function requireConsumerId(client, user, maxPages) {
|
|
240
|
+
if (!user) {
|
|
241
|
+
throw new APIError("UNAUTHORIZED", { message: "Session user is missing." });
|
|
242
|
+
}
|
|
243
|
+
if (user.streampayConsumerId) return user.streampayConsumerId;
|
|
244
|
+
const resolved = await findConsumerByExternalId(client, {
|
|
245
|
+
externalId: user.id,
|
|
246
|
+
maxPages
|
|
247
|
+
});
|
|
248
|
+
if (!resolved) {
|
|
249
|
+
throw new APIError("NOT_FOUND", {
|
|
250
|
+
message: "No StreamPay consumer is linked to this user."
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
return resolved;
|
|
254
|
+
}
|
|
255
|
+
function toAPIError(message, err, logger) {
|
|
256
|
+
if (err instanceof APIError) throw err;
|
|
257
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
258
|
+
logger.error(`${message} ${detail}`);
|
|
259
|
+
throw new APIError("INTERNAL_SERVER_ERROR", { message });
|
|
260
|
+
}
|
|
261
|
+
function buildPagination(query) {
|
|
262
|
+
const result = {};
|
|
263
|
+
if (query?.page !== void 0) result.page = query.page;
|
|
264
|
+
if (query?.limit !== void 0) result.size = query.limit;
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
var portal = ({ consumerLookupMaxPages = 10 } = {}) => (client) => {
|
|
268
|
+
return {
|
|
269
|
+
state: createAuthEndpoint(
|
|
270
|
+
"/consumer/state",
|
|
271
|
+
{ method: "GET", use: [sessionMiddleware] },
|
|
272
|
+
async (ctx) => {
|
|
273
|
+
const user = asSessionUser(ctx.context.session?.user);
|
|
274
|
+
const consumerId = await requireConsumerId(client, user, consumerLookupMaxPages);
|
|
275
|
+
try {
|
|
276
|
+
const consumer = await client.getConsumer(consumerId);
|
|
277
|
+
return ctx.json(consumer);
|
|
278
|
+
} catch (err) {
|
|
279
|
+
toAPIError("StreamPay getConsumer failed.", err, ctx.context.logger);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
),
|
|
283
|
+
subscriptions: createAuthEndpoint(
|
|
284
|
+
"/consumer/subscriptions/list",
|
|
285
|
+
{
|
|
286
|
+
method: "GET",
|
|
287
|
+
query: PaginationQuery,
|
|
288
|
+
use: [sessionMiddleware]
|
|
289
|
+
},
|
|
290
|
+
async (ctx) => {
|
|
291
|
+
const user = asSessionUser(ctx.context.session?.user);
|
|
292
|
+
const consumerId = await requireConsumerId(client, user, consumerLookupMaxPages);
|
|
293
|
+
try {
|
|
294
|
+
const result = await client.listSubscriptions(buildPagination(ctx.query));
|
|
295
|
+
const items = result.data ?? [];
|
|
296
|
+
const filtered = items.filter((s) => s.organization_consumer_id === consumerId);
|
|
297
|
+
return ctx.json({
|
|
298
|
+
data: filtered,
|
|
299
|
+
pagination: result.pagination
|
|
300
|
+
});
|
|
301
|
+
} catch (err) {
|
|
302
|
+
toAPIError("StreamPay listSubscriptions failed.", err, ctx.context.logger);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
),
|
|
306
|
+
invoices: createAuthEndpoint(
|
|
307
|
+
"/consumer/invoices/list",
|
|
308
|
+
{
|
|
309
|
+
method: "GET",
|
|
310
|
+
query: PaginationQuery,
|
|
311
|
+
use: [sessionMiddleware]
|
|
312
|
+
},
|
|
313
|
+
async (ctx) => {
|
|
314
|
+
const user = asSessionUser(ctx.context.session?.user);
|
|
315
|
+
const consumerId = await requireConsumerId(client, user, consumerLookupMaxPages);
|
|
316
|
+
try {
|
|
317
|
+
const result = await client.listInvoices(buildPagination(ctx.query));
|
|
318
|
+
const items = result.data ?? [];
|
|
319
|
+
const filtered = items.filter(
|
|
320
|
+
(invoice) => invoice.organization_consumer_id === consumerId
|
|
321
|
+
);
|
|
322
|
+
return ctx.json({ data: filtered, pagination: result.pagination });
|
|
323
|
+
} catch (err) {
|
|
324
|
+
toAPIError("StreamPay listInvoices failed.", err, ctx.context.logger);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
),
|
|
328
|
+
payments: createAuthEndpoint(
|
|
329
|
+
"/consumer/payments/list",
|
|
330
|
+
{
|
|
331
|
+
method: "GET",
|
|
332
|
+
query: z.object({
|
|
333
|
+
page: z.coerce.number().int().positive().optional(),
|
|
334
|
+
limit: z.coerce.number().int().positive().max(200).optional(),
|
|
335
|
+
invoiceId: z.string().uuid().optional()
|
|
336
|
+
}).optional(),
|
|
337
|
+
use: [sessionMiddleware]
|
|
338
|
+
},
|
|
339
|
+
async (ctx) => {
|
|
340
|
+
const user = asSessionUser(ctx.context.session?.user);
|
|
341
|
+
await requireConsumerId(client, user, consumerLookupMaxPages);
|
|
342
|
+
const invoiceId = ctx.query?.invoiceId;
|
|
343
|
+
try {
|
|
344
|
+
const params = {};
|
|
345
|
+
if (invoiceId) params.invoice_id = invoiceId;
|
|
346
|
+
const result = await client.listPayments(params);
|
|
347
|
+
return ctx.json(result);
|
|
348
|
+
} catch (err) {
|
|
349
|
+
toAPIError("StreamPay listPayments failed.", err, ctx.context.logger);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
)
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
var CancelBody = z.object({
|
|
356
|
+
subscriptionId: z.string().uuid(),
|
|
357
|
+
cancelRelatedInvoices: z.boolean().optional()
|
|
358
|
+
});
|
|
359
|
+
var FreezeBody = z.object({
|
|
360
|
+
subscriptionId: z.string().uuid(),
|
|
361
|
+
freezeStartDatetime: z.string().datetime(),
|
|
362
|
+
freezeEndDatetime: z.string().datetime().nullable().optional(),
|
|
363
|
+
notes: z.string().optional()
|
|
364
|
+
});
|
|
365
|
+
async function assertOwnsSubscription(client, user, subscriptionId, maxPages) {
|
|
366
|
+
if (!user) {
|
|
367
|
+
throw new APIError("UNAUTHORIZED", { message: "Session user is missing." });
|
|
368
|
+
}
|
|
369
|
+
const consumerId = user.streampayConsumerId ?? await findConsumerByExternalId(client, { externalId: user.id, maxPages });
|
|
370
|
+
if (!consumerId) {
|
|
371
|
+
throw new APIError("NOT_FOUND", {
|
|
372
|
+
message: "No StreamPay consumer is linked to this user."
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
const subscription = await client.getSubscription(subscriptionId);
|
|
376
|
+
if (subscription.organization_consumer_id !== consumerId) {
|
|
377
|
+
throw new APIError("FORBIDDEN", {
|
|
378
|
+
message: "Subscription does not belong to this user."
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
var subscriptions = ({ consumerLookupMaxPages = 10 } = {}) => (client) => {
|
|
383
|
+
return {
|
|
384
|
+
cancelSubscription: createAuthEndpoint(
|
|
385
|
+
"/consumer/subscriptions/cancel",
|
|
386
|
+
{
|
|
387
|
+
method: "POST",
|
|
388
|
+
body: CancelBody,
|
|
389
|
+
use: [sessionMiddleware]
|
|
390
|
+
},
|
|
391
|
+
async (ctx) => {
|
|
392
|
+
const sessionUser = asSessionUser(ctx.context.session?.user);
|
|
393
|
+
await assertOwnsSubscription(
|
|
394
|
+
client,
|
|
395
|
+
sessionUser,
|
|
396
|
+
ctx.body.subscriptionId,
|
|
397
|
+
consumerLookupMaxPages
|
|
398
|
+
);
|
|
399
|
+
const payload = {
|
|
400
|
+
cancel_related_invoices: ctx.body.cancelRelatedInvoices ?? false
|
|
401
|
+
};
|
|
402
|
+
try {
|
|
403
|
+
const result = await client.cancelSubscription(ctx.body.subscriptionId, payload);
|
|
404
|
+
return ctx.json(result);
|
|
405
|
+
} catch (err) {
|
|
406
|
+
if (err instanceof APIError) throw err;
|
|
407
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
408
|
+
ctx.context.logger.error(`StreamPay cancelSubscription failed: ${message}`);
|
|
409
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
410
|
+
message: "Subscription cancellation failed."
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
),
|
|
415
|
+
freezeSubscription: createAuthEndpoint(
|
|
416
|
+
"/consumer/subscriptions/freeze",
|
|
417
|
+
{
|
|
418
|
+
method: "POST",
|
|
419
|
+
body: FreezeBody,
|
|
420
|
+
use: [sessionMiddleware]
|
|
421
|
+
},
|
|
422
|
+
async (ctx) => {
|
|
423
|
+
const sessionUser = asSessionUser(ctx.context.session?.user);
|
|
424
|
+
await assertOwnsSubscription(
|
|
425
|
+
client,
|
|
426
|
+
sessionUser,
|
|
427
|
+
ctx.body.subscriptionId,
|
|
428
|
+
consumerLookupMaxPages
|
|
429
|
+
);
|
|
430
|
+
const payload = {
|
|
431
|
+
freeze_start_datetime: ctx.body.freezeStartDatetime
|
|
432
|
+
};
|
|
433
|
+
if (ctx.body.freezeEndDatetime !== void 0) {
|
|
434
|
+
payload.freeze_end_datetime = ctx.body.freezeEndDatetime;
|
|
435
|
+
}
|
|
436
|
+
if (ctx.body.notes !== void 0) {
|
|
437
|
+
payload.notes = ctx.body.notes;
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
const result = await client.freezeSubscription(ctx.body.subscriptionId, payload);
|
|
441
|
+
return ctx.json(result);
|
|
442
|
+
} catch (err) {
|
|
443
|
+
if (err instanceof APIError) throw err;
|
|
444
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
445
|
+
ctx.context.logger.error(`StreamPay freezeSubscription failed: ${message}`);
|
|
446
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
447
|
+
message: "Subscription freeze failed."
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
)
|
|
452
|
+
};
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// src/webhooks/dispatcher.ts
|
|
456
|
+
var HANDLER_BY_EVENT = {
|
|
457
|
+
PAYMENT_SUCCEEDED: "onPaymentSucceeded",
|
|
458
|
+
PAYMENT_FAILED: "onPaymentFailed",
|
|
459
|
+
PAYMENT_CANCELED: "onPaymentCanceled",
|
|
460
|
+
PAYMENT_REFUNDED: "onPaymentRefunded",
|
|
461
|
+
PAYMENT_MARKED_AS_PAID: "onPaymentMarkedAsPaid",
|
|
462
|
+
INVOICE_CREATED: "onInvoiceCreated",
|
|
463
|
+
INVOICE_SENT: "onInvoiceSent",
|
|
464
|
+
INVOICE_ACCEPTED: "onInvoiceAccepted",
|
|
465
|
+
INVOICE_REJECTED: "onInvoiceRejected",
|
|
466
|
+
INVOICE_COMPLETED: "onInvoiceCompleted",
|
|
467
|
+
INVOICE_CANCELED: "onInvoiceCanceled",
|
|
468
|
+
INVOICE_UPDATED: "onInvoiceUpdated",
|
|
469
|
+
SUBSCRIPTION_CREATED: "onSubscriptionCreated",
|
|
470
|
+
SUBSCRIPTION_ACTIVATED: "onSubscriptionActivated",
|
|
471
|
+
SUBSCRIPTION_INACTIVATED: "onSubscriptionInactivated",
|
|
472
|
+
SUBSCRIPTION_CANCELED: "onSubscriptionCanceled",
|
|
473
|
+
SUBSCRIPTION_FROZEN: "onSubscriptionFrozen",
|
|
474
|
+
SUBSCRIPTION_CYCLE_RENEWAL_FAILED: "onSubscriptionCycleRenewalFailed",
|
|
475
|
+
SUBSCRIPTION_CANCEL_AT_PERIOD_END: "onSubscriptionCancelAtPeriodEnd",
|
|
476
|
+
SUBSCRIPTION_FREEZE_NOW: "onSubscriptionFreezeNow",
|
|
477
|
+
SUBSCRIPTION_UNFREEZE_NOW: "onSubscriptionUnfreezeNow",
|
|
478
|
+
SUBSCRIPTION_UNFREEZE_FUTURE: "onSubscriptionUnfreezeFuture",
|
|
479
|
+
SUBSCRIPTION_FREEZE_CANCEL: "onSubscriptionFreezeCancel",
|
|
480
|
+
PAYMENT_LINK_PAY_ATTEMPT_FAILED: "onPaymentLinkPayAttemptFailed"
|
|
481
|
+
};
|
|
482
|
+
async function dispatchWebhook(payload, handlers) {
|
|
483
|
+
if (handlers.onPayload) await handlers.onPayload(payload);
|
|
484
|
+
const handlerKey = HANDLER_BY_EVENT[payload.event_type];
|
|
485
|
+
if (!handlerKey) return;
|
|
486
|
+
const handler = handlers[handlerKey];
|
|
487
|
+
if (handler) await handler(payload);
|
|
488
|
+
}
|
|
489
|
+
var StreamPayWebhookError = class extends Error {
|
|
490
|
+
reason;
|
|
491
|
+
constructor(reason, message) {
|
|
492
|
+
super(message ?? reason);
|
|
493
|
+
this.name = "StreamPayWebhookError";
|
|
494
|
+
this.reason = reason;
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
function parseSignatureHeader(header) {
|
|
498
|
+
const parts = header.split(",");
|
|
499
|
+
let timestamp;
|
|
500
|
+
let signature;
|
|
501
|
+
for (const part of parts) {
|
|
502
|
+
const [key, ...rest] = part.trim().split("=");
|
|
503
|
+
const value = rest.join("=");
|
|
504
|
+
if (key === "t") timestamp = value;
|
|
505
|
+
else if (key === "v1") signature = value;
|
|
506
|
+
}
|
|
507
|
+
if (!timestamp || !signature) return null;
|
|
508
|
+
return { timestamp, signature };
|
|
509
|
+
}
|
|
510
|
+
function hexDecode(hex) {
|
|
511
|
+
if (hex.length === 0 || hex.length % 2 !== 0) return null;
|
|
512
|
+
if (!/^[0-9a-fA-F]+$/.test(hex)) return null;
|
|
513
|
+
return Buffer.from(hex, "hex");
|
|
514
|
+
}
|
|
515
|
+
function verifyWebhook(input) {
|
|
516
|
+
const { secret, rawBody, signatureHeader } = input;
|
|
517
|
+
const toleranceSeconds = input.toleranceSeconds ?? 300;
|
|
518
|
+
const now = input.now ?? (() => Math.floor(Date.now() / 1e3));
|
|
519
|
+
if (!signatureHeader) return { ok: false, reason: "MISSING_HEADER" };
|
|
520
|
+
const parsed = parseSignatureHeader(signatureHeader);
|
|
521
|
+
if (!parsed) return { ok: false, reason: "MALFORMED_HEADER" };
|
|
522
|
+
const ts = Number(parsed.timestamp);
|
|
523
|
+
if (!Number.isFinite(ts) || !Number.isInteger(ts) || ts <= 0) {
|
|
524
|
+
return { ok: false, reason: "INVALID_TIMESTAMP" };
|
|
525
|
+
}
|
|
526
|
+
const delta = Math.abs(now() - ts);
|
|
527
|
+
if (delta > toleranceSeconds) return { ok: false, reason: "EXPIRED" };
|
|
528
|
+
const expected = createHmac("sha256", secret).update(`${parsed.timestamp}.${rawBody}`).digest();
|
|
529
|
+
const provided = hexDecode(parsed.signature);
|
|
530
|
+
if (!provided || provided.length !== expected.length) {
|
|
531
|
+
return { ok: false, reason: "INVALID_SIGNATURE" };
|
|
532
|
+
}
|
|
533
|
+
if (!timingSafeEqual(expected, provided)) {
|
|
534
|
+
return { ok: false, reason: "INVALID_SIGNATURE" };
|
|
535
|
+
}
|
|
536
|
+
return { ok: true, timestamp: ts };
|
|
537
|
+
}
|
|
538
|
+
function verifyWebhookOrThrow(input) {
|
|
539
|
+
const result = verifyWebhook(input);
|
|
540
|
+
if (!result.ok) throw new StreamPayWebhookError(result.reason);
|
|
541
|
+
return result.timestamp;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// src/plugins/webhooks.ts
|
|
545
|
+
function isStreamPayWebhookPayload(value) {
|
|
546
|
+
if (!value || typeof value !== "object") return false;
|
|
547
|
+
return "event_type" in value && typeof value.event_type === "string";
|
|
548
|
+
}
|
|
549
|
+
function parseWebhookPayload(value) {
|
|
550
|
+
return isStreamPayWebhookPayload(value) ? value : null;
|
|
551
|
+
}
|
|
552
|
+
function toErrorCode(reason) {
|
|
553
|
+
return reason === "MISSING_HEADER" || reason === "INVALID_SIGNATURE" || reason === "EXPIRED" ? "UNAUTHORIZED" : "BAD_REQUEST";
|
|
554
|
+
}
|
|
555
|
+
var webhooks = (options) => (_client) => {
|
|
556
|
+
const { secret, toleranceSeconds, ...handlers } = options;
|
|
557
|
+
return {
|
|
558
|
+
streampayWebhooks: createAuthEndpoint(
|
|
559
|
+
"/streampay/webhooks",
|
|
560
|
+
{
|
|
561
|
+
method: "POST",
|
|
562
|
+
metadata: { isAction: false },
|
|
563
|
+
cloneRequest: true
|
|
564
|
+
},
|
|
565
|
+
async (ctx) => {
|
|
566
|
+
if (!secret) {
|
|
567
|
+
ctx.context.logger.error("StreamPay webhook secret is not configured.");
|
|
568
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
569
|
+
message: "StreamPay webhook secret is not configured."
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
if (!ctx.request) {
|
|
573
|
+
throw new APIError("BAD_REQUEST", { message: "Missing request body." });
|
|
574
|
+
}
|
|
575
|
+
const rawBody = await ctx.request.text();
|
|
576
|
+
const signatureHeader = ctx.request.headers.get("x-webhook-signature");
|
|
577
|
+
try {
|
|
578
|
+
verifyWebhookOrThrow({
|
|
579
|
+
secret,
|
|
580
|
+
rawBody,
|
|
581
|
+
signatureHeader,
|
|
582
|
+
toleranceSeconds: toleranceSeconds ?? 300
|
|
583
|
+
});
|
|
584
|
+
} catch (err) {
|
|
585
|
+
if (err instanceof StreamPayWebhookError) {
|
|
586
|
+
ctx.context.logger.warn(`StreamPay webhook rejected: ${err.reason}`);
|
|
587
|
+
throw new APIError(toErrorCode(err.reason), {
|
|
588
|
+
message: `Webhook verification failed: ${err.reason}`
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
throw err;
|
|
592
|
+
}
|
|
593
|
+
let parsed;
|
|
594
|
+
try {
|
|
595
|
+
parsed = JSON.parse(rawBody);
|
|
596
|
+
} catch {
|
|
597
|
+
throw new APIError("BAD_REQUEST", {
|
|
598
|
+
message: "Webhook body is not valid JSON."
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
const payload = parseWebhookPayload(parsed);
|
|
602
|
+
if (!payload) {
|
|
603
|
+
throw new APIError("BAD_REQUEST", {
|
|
604
|
+
message: "Webhook body is missing `event_type`."
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
try {
|
|
608
|
+
await dispatchWebhook(payload, handlers);
|
|
609
|
+
} catch (err) {
|
|
610
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
611
|
+
ctx.context.logger.error(`StreamPay webhook handler failed: ${message}`);
|
|
612
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
613
|
+
message: "Webhook handler failed. See server logs."
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
return ctx.json({ received: true });
|
|
617
|
+
}
|
|
618
|
+
)
|
|
619
|
+
};
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
// src/utils/format-error.ts
|
|
623
|
+
function formatStreamPayError(err) {
|
|
624
|
+
if (!(err instanceof Error)) return String(err);
|
|
625
|
+
if (!("body" in err)) return err.message;
|
|
626
|
+
const { body } = err;
|
|
627
|
+
if (!body || typeof body !== "object") return err.message;
|
|
628
|
+
const envelope = readEnvelopeMessage(body);
|
|
629
|
+
if (envelope !== null) return envelope;
|
|
630
|
+
const validation = readValidationMessage(body);
|
|
631
|
+
if (validation !== null) return validation;
|
|
632
|
+
try {
|
|
633
|
+
return JSON.stringify(body);
|
|
634
|
+
} catch {
|
|
635
|
+
return err.message;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function readEnvelopeMessage(body) {
|
|
639
|
+
if (!("error" in body) || !body.error || typeof body.error !== "object") {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
const error = body.error;
|
|
643
|
+
if ("additional_info" in error && typeof error.additional_info === "string") {
|
|
644
|
+
return error.additional_info;
|
|
645
|
+
}
|
|
646
|
+
if ("message" in error && typeof error.message === "string") {
|
|
647
|
+
return error.message;
|
|
648
|
+
}
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
function readValidationMessage(body) {
|
|
652
|
+
if (!("detail" in body) || !Array.isArray(body.detail) || body.detail.length === 0) {
|
|
653
|
+
return null;
|
|
654
|
+
}
|
|
655
|
+
return body.detail.map(formatValidationEntry).join("; ");
|
|
656
|
+
}
|
|
657
|
+
function formatValidationEntry(entry) {
|
|
658
|
+
if (!entry || typeof entry !== "object") return String(entry);
|
|
659
|
+
const loc = "loc" in entry && Array.isArray(entry.loc) ? entry.loc.join(".") : "?";
|
|
660
|
+
const msg = "msg" in entry && typeof entry.msg === "string" ? entry.msg : "invalid";
|
|
661
|
+
return `${loc}: ${msg}`;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// src/hooks/consumer.ts
|
|
665
|
+
var isAnonymous = (user) => "isAnonymous" in user && user.isAnonymous === true;
|
|
666
|
+
var onBeforeUserCreate = (options) => async (user, context) => {
|
|
667
|
+
if (!context || !options.createConsumerOnSignUp) return void 0;
|
|
668
|
+
if (isAnonymous(user)) return void 0;
|
|
669
|
+
if (!user.email) {
|
|
670
|
+
throw new APIError("BAD_REQUEST", {
|
|
671
|
+
message: "StreamPay requires an email address to create a consumer."
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
const extras = options.getConsumerCreateParams ? await options.getConsumerCreateParams({ user }) : {};
|
|
675
|
+
const createPayload = {
|
|
676
|
+
name: user.name || user.email,
|
|
677
|
+
email: user.email,
|
|
678
|
+
...extras
|
|
679
|
+
};
|
|
680
|
+
try {
|
|
681
|
+
const consumer = await options.client.createConsumer(createPayload);
|
|
682
|
+
if (!consumer.id) {
|
|
683
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
684
|
+
message: "StreamPay consumer was created but did not return an id."
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
return { data: { streampayConsumerId: consumer.id } };
|
|
688
|
+
} catch (err) {
|
|
689
|
+
if (err instanceof APIError) throw err;
|
|
690
|
+
if (isDuplicateConsumerError(err)) {
|
|
691
|
+
const reusedId = await resolveDuplicateConsumer(options, createPayload, context);
|
|
692
|
+
if (reusedId) {
|
|
693
|
+
return { data: { streampayConsumerId: reusedId } };
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
697
|
+
message: `StreamPay consumer creation failed: ${formatStreamPayError(err)}`
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
function isDuplicateConsumerError(err) {
|
|
702
|
+
if (!(err instanceof Error)) return false;
|
|
703
|
+
if (!("body" in err)) return false;
|
|
704
|
+
const { body } = err;
|
|
705
|
+
if (!body || typeof body !== "object") return false;
|
|
706
|
+
if (!("error" in body) || !body.error || typeof body.error !== "object") {
|
|
707
|
+
return false;
|
|
708
|
+
}
|
|
709
|
+
const error = body.error;
|
|
710
|
+
return "code" in error && typeof error.code === "string" && error.code === "DUPLICATE_CONSUMER";
|
|
711
|
+
}
|
|
712
|
+
async function resolveDuplicateConsumer(options, createPayload, context) {
|
|
713
|
+
const identifiers = {
|
|
714
|
+
email: createPayload.email ?? null,
|
|
715
|
+
phone_number: createPayload.phone_number ?? null,
|
|
716
|
+
external_id: createPayload.external_id ?? null,
|
|
717
|
+
iban: createPayload.iban ?? null
|
|
718
|
+
};
|
|
719
|
+
const existing = await findConsumerByIdentifiers(options.client, identifiers);
|
|
720
|
+
if (!existing?.id) {
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
if (existing.external_id) {
|
|
724
|
+
context.context.logger.error(
|
|
725
|
+
`StreamPay duplicate: consumer ${existing.id} is already linked to external_id=${existing.external_id}`
|
|
726
|
+
);
|
|
727
|
+
throw new APIError("CONFLICT", {
|
|
728
|
+
message: "This account cannot be created at this time. Please contact support."
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
return existing.id;
|
|
732
|
+
}
|
|
733
|
+
var onAfterUserCreate = (options) => async (user, context) => {
|
|
734
|
+
if (!context || !options.createConsumerOnSignUp) return;
|
|
735
|
+
if (isAnonymous(user)) return;
|
|
736
|
+
const sessionUser = asSessionUser(user);
|
|
737
|
+
if (!sessionUser?.streampayConsumerId) return;
|
|
738
|
+
try {
|
|
739
|
+
await options.client.updateConsumer(sessionUser.streampayConsumerId, {
|
|
740
|
+
external_id: sessionUser.id
|
|
741
|
+
});
|
|
742
|
+
} catch (err) {
|
|
743
|
+
context.context.logger.error(
|
|
744
|
+
`StreamPay consumer external_id link failed: ${formatStreamPayError(err)}`
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
var onUserUpdate = (options) => async (user, context) => {
|
|
749
|
+
if (!context || !options.createConsumerOnSignUp) return;
|
|
750
|
+
if (isAnonymous(user)) return;
|
|
751
|
+
const sessionUser = asSessionUser(user);
|
|
752
|
+
if (!sessionUser) return;
|
|
753
|
+
const consumerId = await resolveConsumerId2(options, sessionUser);
|
|
754
|
+
if (!consumerId) return;
|
|
755
|
+
const update = {};
|
|
756
|
+
if (sessionUser.name !== void 0) update.name = sessionUser.name;
|
|
757
|
+
if (sessionUser.email !== void 0) update.email = sessionUser.email;
|
|
758
|
+
try {
|
|
759
|
+
await options.client.updateConsumer(consumerId, update);
|
|
760
|
+
} catch (err) {
|
|
761
|
+
context.context.logger.error(
|
|
762
|
+
`StreamPay consumer update failed: ${formatStreamPayError(err)}`
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
var onUserDelete = (options) => async (user, context) => {
|
|
767
|
+
if (!context || !options.createConsumerOnSignUp) return;
|
|
768
|
+
if (isAnonymous(user)) return;
|
|
769
|
+
const sessionUser = asSessionUser(user);
|
|
770
|
+
if (!sessionUser) return;
|
|
771
|
+
const consumerId = await resolveConsumerId2(options, sessionUser);
|
|
772
|
+
if (!consumerId) return;
|
|
773
|
+
try {
|
|
774
|
+
await options.client.deleteConsumer(consumerId);
|
|
775
|
+
} catch (err) {
|
|
776
|
+
context.context.logger.error(
|
|
777
|
+
`StreamPay consumer delete failed: ${formatStreamPayError(err)}`
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
async function resolveConsumerId2(options, user) {
|
|
782
|
+
if (user.streampayConsumerId) return user.streampayConsumerId;
|
|
783
|
+
return findConsumerByExternalId(options.client, { externalId: user.id });
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// src/streampay.ts
|
|
787
|
+
var streampay = (options) => {
|
|
788
|
+
const endpoints = options.use.map((use) => use(options.client)).reduce((acc, plugin) => {
|
|
789
|
+
Object.assign(acc, plugin);
|
|
790
|
+
return acc;
|
|
791
|
+
}, {});
|
|
792
|
+
return {
|
|
793
|
+
id: "streampay",
|
|
794
|
+
endpoints,
|
|
795
|
+
schema: {
|
|
796
|
+
user: {
|
|
797
|
+
fields: {
|
|
798
|
+
streampayConsumerId: {
|
|
799
|
+
type: "string",
|
|
800
|
+
required: false,
|
|
801
|
+
input: false
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
},
|
|
806
|
+
init() {
|
|
807
|
+
return {
|
|
808
|
+
options: {
|
|
809
|
+
databaseHooks: {
|
|
810
|
+
user: {
|
|
811
|
+
create: {
|
|
812
|
+
before: onBeforeUserCreate(options),
|
|
813
|
+
after: onAfterUserCreate(options)
|
|
814
|
+
},
|
|
815
|
+
update: {
|
|
816
|
+
after: onUserUpdate(options)
|
|
817
|
+
},
|
|
818
|
+
delete: {
|
|
819
|
+
after: onUserDelete(options)
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
// src/webhooks/events.ts
|
|
830
|
+
var STREAMPAY_EVENT_TYPES = [
|
|
831
|
+
// Payment
|
|
832
|
+
"PAYMENT_SUCCEEDED",
|
|
833
|
+
"PAYMENT_FAILED",
|
|
834
|
+
"PAYMENT_CANCELED",
|
|
835
|
+
"PAYMENT_REFUNDED",
|
|
836
|
+
"PAYMENT_MARKED_AS_PAID",
|
|
837
|
+
// Invoice
|
|
838
|
+
"INVOICE_CREATED",
|
|
839
|
+
"INVOICE_SENT",
|
|
840
|
+
"INVOICE_ACCEPTED",
|
|
841
|
+
"INVOICE_REJECTED",
|
|
842
|
+
"INVOICE_COMPLETED",
|
|
843
|
+
"INVOICE_CANCELED",
|
|
844
|
+
"INVOICE_UPDATED",
|
|
845
|
+
// Subscription
|
|
846
|
+
"SUBSCRIPTION_CREATED",
|
|
847
|
+
"SUBSCRIPTION_ACTIVATED",
|
|
848
|
+
"SUBSCRIPTION_INACTIVATED",
|
|
849
|
+
"SUBSCRIPTION_CANCELED",
|
|
850
|
+
"SUBSCRIPTION_FROZEN",
|
|
851
|
+
"SUBSCRIPTION_CYCLE_RENEWAL_FAILED",
|
|
852
|
+
"SUBSCRIPTION_CANCEL_AT_PERIOD_END",
|
|
853
|
+
"SUBSCRIPTION_FREEZE_NOW",
|
|
854
|
+
"SUBSCRIPTION_UNFREEZE_NOW",
|
|
855
|
+
"SUBSCRIPTION_UNFREEZE_FUTURE",
|
|
856
|
+
"SUBSCRIPTION_FREEZE_CANCEL",
|
|
857
|
+
// Payment Link
|
|
858
|
+
"PAYMENT_LINK_PAY_ATTEMPT_FAILED"
|
|
859
|
+
];
|
|
860
|
+
|
|
861
|
+
export { CheckoutBody, STREAMPAY_EVENT_TYPES, StreamPayWebhookError, checkout, dispatchWebhook, findConsumerByExternalId, findConsumerByIdentifiers, formatStreamPayError, portal, streampay, subscriptions, verifyWebhook, verifyWebhookOrThrow, webhooks };
|
|
862
|
+
//# sourceMappingURL=index.js.map
|
|
863
|
+
//# sourceMappingURL=index.js.map
|