@paid-ai/paid-node 1.0.1-alpha1 → 1.0.1-alpha2

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.
Files changed (50) hide show
  1. package/dist/cjs/Client.js +2 -2
  2. package/dist/cjs/api/resources/plans/client/Client.d.ts +58 -0
  3. package/dist/cjs/api/resources/plans/client/Client.js +220 -0
  4. package/dist/cjs/api/resources/plans/client/requests/PlansSubscribeRequest.d.ts +13 -0
  5. package/dist/cjs/api/resources/plans/client/requests/PlansSubscribeRequest.js +3 -0
  6. package/dist/cjs/api/resources/plans/client/requests/PlansUnsubscribeRequest.d.ts +10 -0
  7. package/dist/cjs/api/resources/plans/client/requests/PlansUnsubscribeRequest.js +3 -0
  8. package/dist/cjs/api/resources/plans/client/requests/PlansUpgradeRequest.d.ts +16 -0
  9. package/dist/cjs/api/resources/plans/client/requests/PlansUpgradeRequest.js +3 -0
  10. package/dist/cjs/api/resources/plans/client/requests/index.d.ts +3 -0
  11. package/dist/cjs/api/types/Plan.d.ts +33 -0
  12. package/dist/cjs/api/types/Plan.js +19 -0
  13. package/dist/cjs/api/types/PlanWithFeatures.d.ts +33 -0
  14. package/dist/cjs/api/types/PlanWithFeatures.js +19 -0
  15. package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
  16. package/dist/cjs/integrations/adapters/nextjs/index.js +5 -1
  17. package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +60 -0
  18. package/dist/cjs/integrations/adapters/nextjs/routes.js +80 -0
  19. package/dist/cjs/integrations/controllers/index.d.ts +1 -1
  20. package/dist/cjs/integrations/controllers/index.js +11 -1
  21. package/dist/cjs/integrations/controllers/plans.d.ts +158 -0
  22. package/dist/cjs/integrations/controllers/plans.js +277 -0
  23. package/dist/cjs/version.d.ts +1 -1
  24. package/dist/cjs/version.js +1 -1
  25. package/dist/esm/Client.mjs +2 -2
  26. package/dist/esm/api/resources/plans/client/Client.d.mts +58 -0
  27. package/dist/esm/api/resources/plans/client/Client.mjs +220 -0
  28. package/dist/esm/api/resources/plans/client/requests/PlansSubscribeRequest.d.mts +13 -0
  29. package/dist/esm/api/resources/plans/client/requests/PlansSubscribeRequest.mjs +2 -0
  30. package/dist/esm/api/resources/plans/client/requests/PlansUnsubscribeRequest.d.mts +10 -0
  31. package/dist/esm/api/resources/plans/client/requests/PlansUnsubscribeRequest.mjs +2 -0
  32. package/dist/esm/api/resources/plans/client/requests/PlansUpgradeRequest.d.mts +16 -0
  33. package/dist/esm/api/resources/plans/client/requests/PlansUpgradeRequest.mjs +2 -0
  34. package/dist/esm/api/resources/plans/client/requests/index.d.mts +3 -0
  35. package/dist/esm/api/types/Plan.d.mts +33 -0
  36. package/dist/esm/api/types/Plan.mjs +18 -1
  37. package/dist/esm/api/types/PlanWithFeatures.d.mts +33 -0
  38. package/dist/esm/api/types/PlanWithFeatures.mjs +18 -1
  39. package/dist/esm/integrations/adapters/nextjs/index.d.mts +1 -1
  40. package/dist/esm/integrations/adapters/nextjs/index.mjs +1 -1
  41. package/dist/esm/integrations/adapters/nextjs/routes.d.mts +60 -0
  42. package/dist/esm/integrations/adapters/nextjs/routes.mjs +77 -1
  43. package/dist/esm/integrations/controllers/index.d.mts +1 -1
  44. package/dist/esm/integrations/controllers/index.mjs +1 -1
  45. package/dist/esm/integrations/controllers/plans.d.mts +158 -0
  46. package/dist/esm/integrations/controllers/plans.mjs +269 -0
  47. package/dist/esm/version.d.mts +1 -1
  48. package/dist/esm/version.mjs +1 -1
  49. package/package.json +1 -1
  50. package/reference.md +228 -0
@@ -10,6 +10,10 @@ exports.createPayInvoiceRoute = createPayInvoiceRoute;
10
10
  exports.createProvisioningRoute = createProvisioningRoute;
11
11
  exports.createSetupIntentRoute = createSetupIntentRoute;
12
12
  exports.createGetPlanGroupByIdRoute = createGetPlanGroupByIdRoute;
13
+ exports.createGetGroupPlansRoute = createGetGroupPlansRoute;
14
+ exports.createSubscribeRoute = createSubscribeRoute;
15
+ exports.createUnsubscribeRoute = createUnsubscribeRoute;
16
+ exports.createUpgradeRoute = createUpgradeRoute;
13
17
  const base_adapter_js_1 = require("./base-adapter.js");
14
18
  const contacts_js_1 = require("../../controllers/contacts.js");
15
19
  const invoices_js_1 = require("../../controllers/invoices.js");
@@ -274,3 +278,79 @@ function createGetPlanGroupByIdRoute(config = {}) {
274
278
  const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
275
279
  return (request, context) => adaptedHandler(request, context, config);
276
280
  }
281
+ /**
282
+ * Create a Next.js API route handler for getting all plans in a plan group
283
+ *
284
+ * @param config - Handler configuration options
285
+ * @returns Next.js route handler function
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * // src/app/api/plans/[planGroupId]/plans/route.ts
290
+ * import { createGetGroupPlansRoute } from '@paid-ai/paid-node/integrations/nextjs';
291
+ *
292
+ * export const GET = createGetGroupPlansRoute();
293
+ * ```
294
+ */
295
+ function createGetGroupPlansRoute(config = {}) {
296
+ const handler = (0, plans_js_1.createGetGroupPlansHandler)();
297
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
298
+ return (request, context) => adaptedHandler(request, context, config);
299
+ }
300
+ /**
301
+ * Create a Next.js API route handler for subscribing a customer to a plan
302
+ *
303
+ * @param config - Handler configuration options
304
+ * @returns Next.js route handler function
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * // src/app/api/plans/[planId]/subscribe/route.ts
309
+ * import { createSubscribeRoute } from '@paid-ai/paid-node/integrations/nextjs';
310
+ *
311
+ * export const POST = createSubscribeRoute();
312
+ * ```
313
+ */
314
+ function createSubscribeRoute(config = {}) {
315
+ const handler = (0, plans_js_1.createSubscribeHandler)();
316
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
317
+ return (request, context) => adaptedHandler(request, context, config);
318
+ }
319
+ /**
320
+ * Create a Next.js API route handler for unsubscribing a customer from a plan
321
+ *
322
+ * @param config - Handler configuration options
323
+ * @returns Next.js route handler function
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * // src/app/api/plans/[planId]/unsubscribe/route.ts
328
+ * import { createUnsubscribeRoute } from '@paid-ai/paid-node/integrations/nextjs';
329
+ *
330
+ * export const POST = createUnsubscribeRoute();
331
+ * ```
332
+ */
333
+ function createUnsubscribeRoute(config = {}) {
334
+ const handler = (0, plans_js_1.createUnsubscribeHandler)();
335
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
336
+ return (request, context) => adaptedHandler(request, context, config);
337
+ }
338
+ /**
339
+ * Create a Next.js API route handler for upgrading a customer's plan
340
+ *
341
+ * @param config - Handler configuration options
342
+ * @returns Next.js route handler function
343
+ *
344
+ * @example
345
+ * ```typescript
346
+ * // src/app/api/plans/upgrade/route.ts
347
+ * import { createUpgradeRoute } from '@paid-ai/paid-node/integrations/nextjs';
348
+ *
349
+ * export const POST = createUpgradeRoute();
350
+ * ```
351
+ */
352
+ function createUpgradeRoute(config = {}) {
353
+ const handler = (0, plans_js_1.createUpgradeHandler)();
354
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
355
+ return (request, context) => adaptedHandler(request, context, config);
356
+ }
@@ -4,4 +4,4 @@ export { createOrder, createOrderWithDefaults, createOrdersHandler, } from "./or
4
4
  export { payInvoice, createPayInvoiceHandler, type PayInvoiceConfig, type PayInvoiceRequest, type PayInvoiceResult, activateOrderSync, createActivateOrderSyncHandler, type ActivateOrderSyncConfig, type ActivateOrderSyncRequest, type ActivateOrderSyncResult, createSetupIntent, createSetupIntentHandler, type SetupIntentConfig, type SetupIntentRequest, type SetupIntentResponse, } from "./billing.js";
5
5
  export { getCustomerInvoices, createCustomerInvoicesHandler, type CustomerInvoicesResult, } from "./invoices.js";
6
6
  export { provisionNewUser, createProvisioningHandler, } from "./provision-users.js";
7
- export { createGetPlanGroupByIdHandler, } from "./plans.js";
7
+ export { getPlanById, getPlanGroupById, createGetPlanGroupByIdHandler, getGroupPlans, createGetGroupPlansHandler, subscribe, createSubscribeHandler, unsubscribe, createUnsubscribeHandler, upgrade, createUpgradeHandler, } from "./plans.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createGetPlanGroupByIdHandler = exports.createProvisioningHandler = exports.provisionNewUser = exports.createCustomerInvoicesHandler = exports.getCustomerInvoices = exports.createSetupIntentHandler = exports.createSetupIntent = exports.createActivateOrderSyncHandler = exports.activateOrderSync = exports.createPayInvoiceHandler = exports.payInvoice = exports.createOrdersHandler = exports.createOrderWithDefaults = exports.createOrder = exports.createContactsHandler = exports.createContactWithDefaults = exports.createContact = exports.createCustomersHandler = exports.createGetCustomerHandler = exports.getCustomer = exports.createCustomerWithDefaults = exports.createCustomer = void 0;
3
+ exports.createUpgradeHandler = exports.upgrade = exports.createUnsubscribeHandler = exports.unsubscribe = exports.createSubscribeHandler = exports.subscribe = exports.createGetGroupPlansHandler = exports.getGroupPlans = exports.createGetPlanGroupByIdHandler = exports.getPlanGroupById = exports.getPlanById = exports.createProvisioningHandler = exports.provisionNewUser = exports.createCustomerInvoicesHandler = exports.getCustomerInvoices = exports.createSetupIntentHandler = exports.createSetupIntent = exports.createActivateOrderSyncHandler = exports.activateOrderSync = exports.createPayInvoiceHandler = exports.payInvoice = exports.createOrdersHandler = exports.createOrderWithDefaults = exports.createOrder = exports.createContactsHandler = exports.createContactWithDefaults = exports.createContact = exports.createCustomersHandler = exports.createGetCustomerHandler = exports.getCustomer = exports.createCustomerWithDefaults = exports.createCustomer = void 0;
4
4
  var customers_js_1 = require("./customers.js");
5
5
  Object.defineProperty(exports, "createCustomer", { enumerable: true, get: function () { return customers_js_1.createCustomer; } });
6
6
  Object.defineProperty(exports, "createCustomerWithDefaults", { enumerable: true, get: function () { return customers_js_1.createCustomerWithDefaults; } });
@@ -29,4 +29,14 @@ var provision_users_js_1 = require("./provision-users.js");
29
29
  Object.defineProperty(exports, "provisionNewUser", { enumerable: true, get: function () { return provision_users_js_1.provisionNewUser; } });
30
30
  Object.defineProperty(exports, "createProvisioningHandler", { enumerable: true, get: function () { return provision_users_js_1.createProvisioningHandler; } });
31
31
  var plans_js_1 = require("./plans.js");
32
+ Object.defineProperty(exports, "getPlanById", { enumerable: true, get: function () { return plans_js_1.getPlanById; } });
33
+ Object.defineProperty(exports, "getPlanGroupById", { enumerable: true, get: function () { return plans_js_1.getPlanGroupById; } });
32
34
  Object.defineProperty(exports, "createGetPlanGroupByIdHandler", { enumerable: true, get: function () { return plans_js_1.createGetPlanGroupByIdHandler; } });
35
+ Object.defineProperty(exports, "getGroupPlans", { enumerable: true, get: function () { return plans_js_1.getGroupPlans; } });
36
+ Object.defineProperty(exports, "createGetGroupPlansHandler", { enumerable: true, get: function () { return plans_js_1.createGetGroupPlansHandler; } });
37
+ Object.defineProperty(exports, "subscribe", { enumerable: true, get: function () { return plans_js_1.subscribe; } });
38
+ Object.defineProperty(exports, "createSubscribeHandler", { enumerable: true, get: function () { return plans_js_1.createSubscribeHandler; } });
39
+ Object.defineProperty(exports, "unsubscribe", { enumerable: true, get: function () { return plans_js_1.unsubscribe; } });
40
+ Object.defineProperty(exports, "createUnsubscribeHandler", { enumerable: true, get: function () { return plans_js_1.createUnsubscribeHandler; } });
41
+ Object.defineProperty(exports, "upgrade", { enumerable: true, get: function () { return plans_js_1.upgrade; } });
42
+ Object.defineProperty(exports, "createUpgradeHandler", { enumerable: true, get: function () { return plans_js_1.createUpgradeHandler; } });
@@ -1,6 +1,13 @@
1
1
  import { PaidClient } from "../../Client.js";
2
2
  import type { PlanGroup } from "../../api/types/PlanGroup.js";
3
3
  import type { Plan } from "../../api/types/Plan.js";
4
+ import type { PlanWithFeatures } from "../../api/types/PlanWithFeatures.js";
5
+ import type { Order } from "../../api/types/Order.js";
6
+ import type { CancelRenewalResponse } from "../../api/types/CancelRenewalResponse.js";
7
+ import type { ProrationUpgradeResponse } from "../../api/types/ProrationUpgradeResponse.js";
8
+ import type { PlansSubscribeRequest } from "../../api/resources/plans/client/requests/PlansSubscribeRequest.js";
9
+ import type { PlansUnsubscribeRequest } from "../../api/resources/plans/client/requests/PlansUnsubscribeRequest.js";
10
+ import type { PlansUpgradeRequest } from "../../api/resources/plans/client/requests/PlansUpgradeRequest.js";
4
11
  /**
5
12
  * Get a plan by ID
6
13
  *
@@ -48,3 +55,154 @@ export declare function getPlanGroupById(client: PaidClient, planGroupId: string
48
55
  * ```
49
56
  */
50
57
  export declare function createGetPlanGroupByIdHandler(): (request: any, response: any, config?: any) => Promise<any>;
58
+ /**
59
+ * Get all plans in a plan group
60
+ *
61
+ * @param client - PaidClient instance
62
+ * @param planGroupId - Plan group's ID
63
+ * @returns Array of plans with features
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const plans = await getGroupPlans(client, 'plan-group-123');
68
+ * console.log(plans.length);
69
+ * ```
70
+ */
71
+ export declare function getGroupPlans(client: PaidClient, planGroupId: string): Promise<PlanWithFeatures[]>;
72
+ /**
73
+ * Create a framework-agnostic handler for fetching plans in a plan group
74
+ *
75
+ * This handler can be used with any framework adapter.
76
+ * The plan group ID should be provided either in params or query string.
77
+ *
78
+ * @returns Handler function
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // In Next.js route: /api/plans/[planGroupId]/plans/route.ts
83
+ * import { createGetGroupPlansHandler } from '@paid-ai/paid-node/integrations';
84
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
85
+ *
86
+ * const handler = createGetGroupPlansHandler();
87
+ * export const GET = nextjsAdapter(handler);
88
+ * ```
89
+ */
90
+ export declare function createGetGroupPlansHandler(): (request: any, response: any, config?: any) => Promise<any>;
91
+ /**
92
+ * Subscribe a customer to a plan
93
+ *
94
+ * Creates a new order for a customer based on the specified plan, automatically converting plan products to order lines.
95
+ *
96
+ * @param client - PaidClient instance
97
+ * @param planId - Plan's ID
98
+ * @param request - Subscribe request with customer external ID and currency
99
+ * @returns Created order
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const order = await subscribe(client, 'plan-123', {
104
+ * customerExternalId: 'customer-123',
105
+ * currency: 'USD'
106
+ * });
107
+ * console.log(order.id);
108
+ * ```
109
+ */
110
+ export declare function subscribe(client: PaidClient, planId: string, request: PlansSubscribeRequest): Promise<Order>;
111
+ /**
112
+ * Create a framework-agnostic handler for subscribing a customer to a plan
113
+ *
114
+ * This handler can be used with any framework adapter.
115
+ * The plan ID should be provided either in params or query string.
116
+ * The request body should contain customerExternalId and currency.
117
+ *
118
+ * @returns Handler function
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // In Next.js route: /api/plans/[planId]/subscribe/route.ts
123
+ * import { createSubscribeHandler } from '@paid-ai/paid-node/integrations';
124
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
125
+ *
126
+ * const handler = createSubscribeHandler();
127
+ * export const POST = nextjsAdapter(handler);
128
+ * ```
129
+ */
130
+ export declare function createSubscribeHandler(): (request: any, response: any, config?: any) => Promise<any>;
131
+ /**
132
+ * Unsubscribe a customer from a plan
133
+ *
134
+ * Cancels the renewal of an order associated with the specified plan. The order will remain active until the cancellation date.
135
+ *
136
+ * @param client - PaidClient instance
137
+ * @param planId - Plan's ID
138
+ * @param request - Unsubscribe request with customer external ID
139
+ * @returns Cancel renewal response
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const response = await unsubscribe(client, 'plan-123', {
144
+ * customerExternalId: 'customer-123'
145
+ * });
146
+ * console.log(response.message);
147
+ * ```
148
+ */
149
+ export declare function unsubscribe(client: PaidClient, planId: string, request: PlansUnsubscribeRequest): Promise<CancelRenewalResponse>;
150
+ /**
151
+ * Create a framework-agnostic handler for unsubscribing a customer from a plan
152
+ *
153
+ * This handler can be used with any framework adapter.
154
+ * The plan ID should be provided either in params or query string.
155
+ * The request body should contain customerExternalId.
156
+ *
157
+ * @returns Handler function
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // In Next.js route: /api/plans/[planId]/unsubscribe/route.ts
162
+ * import { createUnsubscribeHandler } from '@paid-ai/paid-node/integrations';
163
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
164
+ *
165
+ * const handler = createUnsubscribeHandler();
166
+ * export const POST = nextjsAdapter(handler);
167
+ * ```
168
+ */
169
+ export declare function createUnsubscribeHandler(): (request: any, response: any, config?: any) => Promise<any>;
170
+ /**
171
+ * Upgrade a customer from their current plan to a new plan
172
+ *
173
+ * Upgrades a customer from their current plan to a new plan with automatic proration calculation. This schedules a plan change and applies credits for the unused portion of the current billing period.
174
+ *
175
+ * @param client - PaidClient instance
176
+ * @param request - Upgrade request with customer external ID, old plan ID, and new plan ID
177
+ * @returns Proration upgrade response
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * const response = await upgrade(client, {
182
+ * customerExternalId: 'customer-123',
183
+ * oldPlanId: 'plan-123',
184
+ * newPlanId: 'plan-456'
185
+ * });
186
+ * console.log(response.order.id);
187
+ * ```
188
+ */
189
+ export declare function upgrade(client: PaidClient, request: PlansUpgradeRequest): Promise<ProrationUpgradeResponse>;
190
+ /**
191
+ * Create a framework-agnostic handler for upgrading a customer's plan
192
+ *
193
+ * This handler can be used with any framework adapter.
194
+ * The request body should contain customerExternalId, oldPlanId, and newPlanId.
195
+ *
196
+ * @returns Handler function
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * // In Next.js route: /api/plans/upgrade/route.ts
201
+ * import { createUpgradeHandler } from '@paid-ai/paid-node/integrations';
202
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
203
+ *
204
+ * const handler = createUpgradeHandler();
205
+ * export const POST = nextjsAdapter(handler);
206
+ * ```
207
+ */
208
+ export declare function createUpgradeHandler(): (request: any, response: any, config?: any) => Promise<any>;
@@ -12,6 +12,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getPlanById = getPlanById;
13
13
  exports.getPlanGroupById = getPlanGroupById;
14
14
  exports.createGetPlanGroupByIdHandler = createGetPlanGroupByIdHandler;
15
+ exports.getGroupPlans = getGroupPlans;
16
+ exports.createGetGroupPlansHandler = createGetGroupPlansHandler;
17
+ exports.subscribe = subscribe;
18
+ exports.createSubscribeHandler = createSubscribeHandler;
19
+ exports.unsubscribe = unsubscribe;
20
+ exports.createUnsubscribeHandler = createUnsubscribeHandler;
21
+ exports.upgrade = upgrade;
22
+ exports.createUpgradeHandler = createUpgradeHandler;
15
23
  const base_handler_js_1 = require("../utils/base-handler.js");
16
24
  /**
17
25
  * Get a plan by ID
@@ -86,3 +94,272 @@ function createGetPlanGroupByIdHandler() {
86
94
  requireOrganizationId: false,
87
95
  });
88
96
  }
97
+ /**
98
+ * Get all plans in a plan group
99
+ *
100
+ * @param client - PaidClient instance
101
+ * @param planGroupId - Plan group's ID
102
+ * @returns Array of plans with features
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const plans = await getGroupPlans(client, 'plan-group-123');
107
+ * console.log(plans.length);
108
+ * ```
109
+ */
110
+ function getGroupPlans(client, planGroupId) {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ const plans = yield client.plans.getGroupPlans(planGroupId);
113
+ return plans;
114
+ });
115
+ }
116
+ /**
117
+ * Create a framework-agnostic handler for fetching plans in a plan group
118
+ *
119
+ * This handler can be used with any framework adapter.
120
+ * The plan group ID should be provided either in params or query string.
121
+ *
122
+ * @returns Handler function
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * // In Next.js route: /api/plans/[planGroupId]/plans/route.ts
127
+ * import { createGetGroupPlansHandler } from '@paid-ai/paid-node/integrations';
128
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
129
+ *
130
+ * const handler = createGetGroupPlansHandler();
131
+ * export const GET = nextjsAdapter(handler);
132
+ * ```
133
+ */
134
+ function createGetGroupPlansHandler() {
135
+ return (0, base_handler_js_1.createHandler)((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
136
+ const planGroupId = params === null || params === void 0 ? void 0 : params.planGroupId;
137
+ if (!planGroupId) {
138
+ return {
139
+ success: false,
140
+ error: "planGroupId is required",
141
+ status: 400,
142
+ };
143
+ }
144
+ const plans = yield getGroupPlans(client, planGroupId);
145
+ return { success: true, data: plans };
146
+ }), {
147
+ allowedMethods: ['GET'],
148
+ requireOrganizationId: false,
149
+ });
150
+ }
151
+ /**
152
+ * Subscribe a customer to a plan
153
+ *
154
+ * Creates a new order for a customer based on the specified plan, automatically converting plan products to order lines.
155
+ *
156
+ * @param client - PaidClient instance
157
+ * @param planId - Plan's ID
158
+ * @param request - Subscribe request with customer external ID and currency
159
+ * @returns Created order
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const order = await subscribe(client, 'plan-123', {
164
+ * customerExternalId: 'customer-123',
165
+ * currency: 'USD'
166
+ * });
167
+ * console.log(order.id);
168
+ * ```
169
+ */
170
+ function subscribe(client, planId, request) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ const order = yield client.plans.subscribe(planId, request);
173
+ return order;
174
+ });
175
+ }
176
+ /**
177
+ * Create a framework-agnostic handler for subscribing a customer to a plan
178
+ *
179
+ * This handler can be used with any framework adapter.
180
+ * The plan ID should be provided either in params or query string.
181
+ * The request body should contain customerExternalId and currency.
182
+ *
183
+ * @returns Handler function
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // In Next.js route: /api/plans/[planId]/subscribe/route.ts
188
+ * import { createSubscribeHandler } from '@paid-ai/paid-node/integrations';
189
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
190
+ *
191
+ * const handler = createSubscribeHandler();
192
+ * export const POST = nextjsAdapter(handler);
193
+ * ```
194
+ */
195
+ function createSubscribeHandler() {
196
+ return (0, base_handler_js_1.createHandler)((client, body, params) => __awaiter(this, void 0, void 0, function* () {
197
+ const planId = params === null || params === void 0 ? void 0 : params.planId;
198
+ if (!planId) {
199
+ return {
200
+ success: false,
201
+ error: "planId is required",
202
+ status: 400,
203
+ };
204
+ }
205
+ if (!body.customerExternalId) {
206
+ return {
207
+ success: false,
208
+ error: "customerExternalId is required",
209
+ status: 400,
210
+ };
211
+ }
212
+ if (!body.currency) {
213
+ return {
214
+ success: false,
215
+ error: "currency is required",
216
+ status: 400,
217
+ };
218
+ }
219
+ const order = yield subscribe(client, planId, body);
220
+ return { success: true, data: order };
221
+ }), {
222
+ allowedMethods: ['POST'],
223
+ requireOrganizationId: false,
224
+ });
225
+ }
226
+ /**
227
+ * Unsubscribe a customer from a plan
228
+ *
229
+ * Cancels the renewal of an order associated with the specified plan. The order will remain active until the cancellation date.
230
+ *
231
+ * @param client - PaidClient instance
232
+ * @param planId - Plan's ID
233
+ * @param request - Unsubscribe request with customer external ID
234
+ * @returns Cancel renewal response
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * const response = await unsubscribe(client, 'plan-123', {
239
+ * customerExternalId: 'customer-123'
240
+ * });
241
+ * console.log(response.message);
242
+ * ```
243
+ */
244
+ function unsubscribe(client, planId, request) {
245
+ return __awaiter(this, void 0, void 0, function* () {
246
+ const response = yield client.plans.unsubscribe(planId, request);
247
+ return response;
248
+ });
249
+ }
250
+ /**
251
+ * Create a framework-agnostic handler for unsubscribing a customer from a plan
252
+ *
253
+ * This handler can be used with any framework adapter.
254
+ * The plan ID should be provided either in params or query string.
255
+ * The request body should contain customerExternalId.
256
+ *
257
+ * @returns Handler function
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * // In Next.js route: /api/plans/[planId]/unsubscribe/route.ts
262
+ * import { createUnsubscribeHandler } from '@paid-ai/paid-node/integrations';
263
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
264
+ *
265
+ * const handler = createUnsubscribeHandler();
266
+ * export const POST = nextjsAdapter(handler);
267
+ * ```
268
+ */
269
+ function createUnsubscribeHandler() {
270
+ return (0, base_handler_js_1.createHandler)((client, body, params) => __awaiter(this, void 0, void 0, function* () {
271
+ const planId = params === null || params === void 0 ? void 0 : params.planId;
272
+ if (!planId) {
273
+ return {
274
+ success: false,
275
+ error: "planId is required",
276
+ status: 400,
277
+ };
278
+ }
279
+ if (!body.customerExternalId) {
280
+ return {
281
+ success: false,
282
+ error: "customerExternalId is required",
283
+ status: 400,
284
+ };
285
+ }
286
+ const response = yield unsubscribe(client, planId, body);
287
+ return { success: true, data: response };
288
+ }), {
289
+ allowedMethods: ['POST'],
290
+ requireOrganizationId: false,
291
+ });
292
+ }
293
+ /**
294
+ * Upgrade a customer from their current plan to a new plan
295
+ *
296
+ * Upgrades a customer from their current plan to a new plan with automatic proration calculation. This schedules a plan change and applies credits for the unused portion of the current billing period.
297
+ *
298
+ * @param client - PaidClient instance
299
+ * @param request - Upgrade request with customer external ID, old plan ID, and new plan ID
300
+ * @returns Proration upgrade response
301
+ *
302
+ * @example
303
+ * ```typescript
304
+ * const response = await upgrade(client, {
305
+ * customerExternalId: 'customer-123',
306
+ * oldPlanId: 'plan-123',
307
+ * newPlanId: 'plan-456'
308
+ * });
309
+ * console.log(response.order.id);
310
+ * ```
311
+ */
312
+ function upgrade(client, request) {
313
+ return __awaiter(this, void 0, void 0, function* () {
314
+ const response = yield client.plans.upgrade(request);
315
+ return response;
316
+ });
317
+ }
318
+ /**
319
+ * Create a framework-agnostic handler for upgrading a customer's plan
320
+ *
321
+ * This handler can be used with any framework adapter.
322
+ * The request body should contain customerExternalId, oldPlanId, and newPlanId.
323
+ *
324
+ * @returns Handler function
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * // In Next.js route: /api/plans/upgrade/route.ts
329
+ * import { createUpgradeHandler } from '@paid-ai/paid-node/integrations';
330
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
331
+ *
332
+ * const handler = createUpgradeHandler();
333
+ * export const POST = nextjsAdapter(handler);
334
+ * ```
335
+ */
336
+ function createUpgradeHandler() {
337
+ return (0, base_handler_js_1.createHandler)((client, body) => __awaiter(this, void 0, void 0, function* () {
338
+ if (!body.customerExternalId) {
339
+ return {
340
+ success: false,
341
+ error: "customerExternalId is required",
342
+ status: 400,
343
+ };
344
+ }
345
+ if (!body.oldPlanId) {
346
+ return {
347
+ success: false,
348
+ error: "oldPlanId is required",
349
+ status: 400,
350
+ };
351
+ }
352
+ if (!body.newPlanId) {
353
+ return {
354
+ success: false,
355
+ error: "newPlanId is required",
356
+ status: 400,
357
+ };
358
+ }
359
+ const response = yield upgrade(client, body);
360
+ return { success: true, data: response };
361
+ }), {
362
+ allowedMethods: ['POST'],
363
+ requireOrganizationId: false,
364
+ });
365
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.1-alpha1";
1
+ export declare const SDK_VERSION = "1.0.1-alpha2";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "1.0.1-alpha1";
4
+ exports.SDK_VERSION = "1.0.1-alpha2";
@@ -14,8 +14,8 @@ export class PaidClient {
14
14
  this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
15
15
  "X-Fern-Language": "JavaScript",
16
16
  "X-Fern-SDK-Name": "@paid-ai/paid-node",
17
- "X-Fern-SDK-Version": "1.0.1-alpha1",
18
- "User-Agent": "@paid-ai/paid-node/1.0.1-alpha1",
17
+ "X-Fern-SDK-Version": "1.0.1-alpha2",
18
+ "User-Agent": "@paid-ai/paid-node/1.0.1-alpha2",
19
19
  "X-Fern-Runtime": core.RUNTIME.type,
20
20
  "X-Fern-Runtime-Version": core.RUNTIME.version,
21
21
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -42,6 +42,62 @@ export declare class Plans {
42
42
  */
43
43
  getUsage(planId: string, request: Paid.PlansGetUsageRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.UsageSummariesResponse>;
44
44
  private __getUsage;
45
+ /**
46
+ * Creates a new order for a customer subscribing to a plan. The order will be created with the plan's products and pricing attributes.
47
+ *
48
+ * @param {string} planId - The ID of the plan
49
+ * @param {Paid.PlansSubscribeRequest} request
50
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
51
+ *
52
+ * @throws {@link Paid.BadRequestError}
53
+ * @throws {@link Paid.ForbiddenError}
54
+ * @throws {@link Paid.NotFoundError}
55
+ *
56
+ * @example
57
+ * await client.plans.subscribe("planId", {
58
+ * customerExternalId: "customerExternalId",
59
+ * currency: "currency"
60
+ * })
61
+ */
62
+ subscribe(planId: string, request: Paid.PlansSubscribeRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.Order>;
63
+ private __subscribe;
64
+ /**
65
+ * Cancels the renewal of an active order for a customer's plan subscription. The order will remain active until the cancellation date.
66
+ *
67
+ * @param {string} planId - The ID of the plan
68
+ * @param {Paid.PlansUnsubscribeRequest} request
69
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
70
+ *
71
+ * @throws {@link Paid.BadRequestError}
72
+ * @throws {@link Paid.ForbiddenError}
73
+ * @throws {@link Paid.NotFoundError}
74
+ *
75
+ * @example
76
+ * await client.plans.unsubscribe("planId", {
77
+ * customerExternalId: "customerExternalId"
78
+ * })
79
+ */
80
+ unsubscribe(planId: string, request: Paid.PlansUnsubscribeRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.CancelRenewalResponse>;
81
+ private __unsubscribe;
82
+ /**
83
+ * Upgrades a customer from one plan to another with automatic proration. Credits are applied for the unused portion of the current billing period, and the order is updated with the new plan's pricing.
84
+ *
85
+ * @param {Paid.PlansUpgradeRequest} request
86
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
87
+ *
88
+ * @throws {@link Paid.BadRequestError}
89
+ * @throws {@link Paid.ForbiddenError}
90
+ * @throws {@link Paid.NotFoundError}
91
+ *
92
+ * @example
93
+ * await client.plans.upgrade({
94
+ * customerExternalId: "customerExternalId",
95
+ * oldPlanId: "oldPlanId",
96
+ * newPlanId: "newPlanId"
97
+ * })
98
+ */
99
+ upgrade(request: Paid.PlansUpgradeRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.ProrationUpgradeResponse>;
100
+ private __upgrade;
45
101
  /**
46
102
  * @param {string} planGroupId - The ID of the plan group
47
103
  * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
@@ -55,6 +111,8 @@ export declare class Plans {
55
111
  getGroupById(planGroupId: string, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.PlanGroup>;
56
112
  private __getGroupById;
57
113
  /**
114
+ * Retrieves all plans in a plan group with their features (product-attribute pairs)
115
+ *
58
116
  * @param {string} planGroupId - The ID of the plan group
59
117
  * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
60
118
  *