@paid-ai/paid-node 1.0.1-alpha0 → 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.
- package/dist/cjs/Client.js +2 -2
- package/dist/cjs/api/resources/plans/client/Client.d.ts +70 -0
- package/dist/cjs/api/resources/plans/client/Client.js +282 -2
- package/dist/cjs/api/resources/plans/client/requests/PlansSubscribeRequest.d.ts +13 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansSubscribeRequest.js +3 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansUnsubscribeRequest.d.ts +10 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansUnsubscribeRequest.js +3 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansUpgradeRequest.d.ts +16 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansUpgradeRequest.js +3 -0
- package/dist/cjs/api/resources/plans/client/requests/index.d.ts +3 -0
- package/dist/cjs/api/resources/usage/client/Client.d.ts +3 -3
- package/dist/cjs/api/resources/usage/client/Client.js +3 -3
- package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.ts +3 -3
- package/dist/cjs/api/types/Plan.d.ts +33 -0
- package/dist/cjs/api/types/Plan.js +19 -0
- package/dist/cjs/api/types/PlanWithFeatures.d.ts +67 -0
- package/dist/cjs/api/types/PlanWithFeatures.js +22 -0
- package/dist/cjs/api/types/SignalV2.d.ts +5 -5
- package/dist/cjs/api/types/index.d.ts +1 -0
- package/dist/cjs/api/types/index.js +1 -0
- package/dist/cjs/integrations/adapters/expressjs/index.d.ts +2 -2
- package/dist/cjs/integrations/adapters/expressjs/index.js +2 -1
- package/dist/cjs/integrations/adapters/expressjs/routes.d.ts +16 -0
- package/dist/cjs/integrations/adapters/expressjs/routes.js +28 -0
- package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
- package/dist/cjs/integrations/adapters/nextjs/index.js +6 -1
- package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +75 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.js +101 -0
- package/dist/cjs/integrations/controllers/index.d.ts +1 -0
- package/dist/cjs/integrations/controllers/index.js +13 -1
- package/dist/cjs/integrations/controllers/orders.js +52 -17
- package/dist/cjs/integrations/controllers/plans.d.ts +208 -0
- package/dist/cjs/integrations/controllers/plans.js +365 -0
- package/dist/cjs/integrations/types.d.ts +5 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.mjs +2 -2
- package/dist/esm/api/resources/plans/client/Client.d.mts +70 -0
- package/dist/esm/api/resources/plans/client/Client.mjs +282 -2
- package/dist/esm/api/resources/plans/client/requests/PlansSubscribeRequest.d.mts +13 -0
- package/dist/esm/api/resources/plans/client/requests/PlansSubscribeRequest.mjs +2 -0
- package/dist/esm/api/resources/plans/client/requests/PlansUnsubscribeRequest.d.mts +10 -0
- package/dist/esm/api/resources/plans/client/requests/PlansUnsubscribeRequest.mjs +2 -0
- package/dist/esm/api/resources/plans/client/requests/PlansUpgradeRequest.d.mts +16 -0
- package/dist/esm/api/resources/plans/client/requests/PlansUpgradeRequest.mjs +2 -0
- package/dist/esm/api/resources/plans/client/requests/index.d.mts +3 -0
- package/dist/esm/api/resources/usage/client/Client.d.mts +3 -3
- package/dist/esm/api/resources/usage/client/Client.mjs +3 -3
- package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.mts +3 -3
- package/dist/esm/api/types/Plan.d.mts +33 -0
- package/dist/esm/api/types/Plan.mjs +18 -1
- package/dist/esm/api/types/PlanWithFeatures.d.mts +67 -0
- package/dist/esm/api/types/PlanWithFeatures.mjs +19 -0
- package/dist/esm/api/types/SignalV2.d.mts +5 -5
- package/dist/esm/api/types/index.d.mts +1 -0
- package/dist/esm/api/types/index.mjs +1 -0
- package/dist/esm/integrations/adapters/expressjs/index.d.mts +2 -2
- package/dist/esm/integrations/adapters/expressjs/index.mjs +2 -2
- package/dist/esm/integrations/adapters/expressjs/routes.d.mts +16 -0
- package/dist/esm/integrations/adapters/expressjs/routes.mjs +27 -0
- package/dist/esm/integrations/adapters/nextjs/index.d.mts +1 -1
- package/dist/esm/integrations/adapters/nextjs/index.mjs +1 -1
- package/dist/esm/integrations/adapters/nextjs/routes.d.mts +75 -0
- package/dist/esm/integrations/adapters/nextjs/routes.mjs +96 -0
- package/dist/esm/integrations/controllers/index.d.mts +1 -0
- package/dist/esm/integrations/controllers/index.mjs +1 -0
- package/dist/esm/integrations/controllers/orders.mjs +52 -17
- package/dist/esm/integrations/controllers/plans.d.mts +208 -0
- package/dist/esm/integrations/controllers/plans.mjs +353 -0
- package/dist/esm/integrations/types.d.mts +5 -2
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +36 -2
- package/reference.md +280 -3
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { PaidClient } from "../../Client.js";
|
|
2
|
+
import type { PlanGroup } from "../../api/types/PlanGroup.js";
|
|
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";
|
|
11
|
+
/**
|
|
12
|
+
* Get a plan by ID
|
|
13
|
+
*
|
|
14
|
+
* @param client - PaidClient instance
|
|
15
|
+
* @param planId - Plan's ID
|
|
16
|
+
* @returns Plan data
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const plan = await getPlanById(client, 'plan-123');
|
|
21
|
+
* console.log(plan.name, plan.id);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function getPlanById(client: PaidClient, planId: string): Promise<Plan>;
|
|
25
|
+
/**
|
|
26
|
+
* Get a plan group by ID
|
|
27
|
+
*
|
|
28
|
+
* @param client - PaidClient instance
|
|
29
|
+
* @param planGroupId - Plan group's ID
|
|
30
|
+
* @returns Plan group data
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const planGroup = await getPlanGroupById(client, 'plan-group-123');
|
|
35
|
+
* console.log(planGroup.name, planGroup.id);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function getPlanGroupById(client: PaidClient, planGroupId: string): Promise<PlanGroup>;
|
|
39
|
+
/**
|
|
40
|
+
* Create a framework-agnostic handler for fetching a plan group by ID
|
|
41
|
+
*
|
|
42
|
+
* This handler can be used with any framework adapter.
|
|
43
|
+
* The plan group ID should be provided either in params or query string.
|
|
44
|
+
*
|
|
45
|
+
* @returns Handler function
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // In Next.js route: /api/plans/[planGroupId]/route.ts
|
|
50
|
+
* import { createGetPlanGroupByIdHandler } from '@paid-ai/paid-node/integrations';
|
|
51
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
52
|
+
*
|
|
53
|
+
* const handler = createGetPlanGroupByIdHandler();
|
|
54
|
+
* export const GET = nextjsAdapter(handler);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
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>;
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getPlanById = getPlanById;
|
|
13
|
+
exports.getPlanGroupById = getPlanGroupById;
|
|
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;
|
|
23
|
+
const base_handler_js_1 = require("../utils/base-handler.js");
|
|
24
|
+
/**
|
|
25
|
+
* Get a plan by ID
|
|
26
|
+
*
|
|
27
|
+
* @param client - PaidClient instance
|
|
28
|
+
* @param planId - Plan's ID
|
|
29
|
+
* @returns Plan data
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const plan = await getPlanById(client, 'plan-123');
|
|
34
|
+
* console.log(plan.name, plan.id);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function getPlanById(client, planId) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const plan = yield client.plans.getById(planId);
|
|
40
|
+
return plan;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get a plan group by ID
|
|
45
|
+
*
|
|
46
|
+
* @param client - PaidClient instance
|
|
47
|
+
* @param planGroupId - Plan group's ID
|
|
48
|
+
* @returns Plan group data
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const planGroup = await getPlanGroupById(client, 'plan-group-123');
|
|
53
|
+
* console.log(planGroup.name, planGroup.id);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function getPlanGroupById(client, planGroupId) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const planGroup = yield client.plans.getGroupById(planGroupId);
|
|
59
|
+
return planGroup;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a framework-agnostic handler for fetching a plan group by ID
|
|
64
|
+
*
|
|
65
|
+
* This handler can be used with any framework adapter.
|
|
66
|
+
* The plan group ID should be provided either in params or query string.
|
|
67
|
+
*
|
|
68
|
+
* @returns Handler function
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* // In Next.js route: /api/plans/[planGroupId]/route.ts
|
|
73
|
+
* import { createGetPlanGroupByIdHandler } from '@paid-ai/paid-node/integrations';
|
|
74
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
75
|
+
*
|
|
76
|
+
* const handler = createGetPlanGroupByIdHandler();
|
|
77
|
+
* export const GET = nextjsAdapter(handler);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
function createGetPlanGroupByIdHandler() {
|
|
81
|
+
return (0, base_handler_js_1.createHandler)((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const planGroupId = params === null || params === void 0 ? void 0 : params.planGroupId;
|
|
83
|
+
if (!planGroupId) {
|
|
84
|
+
return {
|
|
85
|
+
success: false,
|
|
86
|
+
error: "planGroupId is required",
|
|
87
|
+
status: 400,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const planGroup = yield getPlanGroupById(client, planGroupId);
|
|
91
|
+
return { success: true, data: planGroup };
|
|
92
|
+
}), {
|
|
93
|
+
allowedMethods: ['GET'],
|
|
94
|
+
requireOrganizationId: false,
|
|
95
|
+
});
|
|
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
|
+
}
|
|
@@ -41,18 +41,20 @@ export interface OrderConfig {
|
|
|
41
41
|
customerId: string;
|
|
42
42
|
customerExternalId: string;
|
|
43
43
|
billingContactId?: string;
|
|
44
|
-
agentExternalId
|
|
44
|
+
agentExternalId?: string;
|
|
45
45
|
name?: string;
|
|
46
46
|
description?: string;
|
|
47
47
|
startDate?: string;
|
|
48
48
|
endDate?: string;
|
|
49
49
|
currency?: string;
|
|
50
50
|
orderLines?: OrderLineConfig[];
|
|
51
|
+
planId?: string;
|
|
51
52
|
}
|
|
52
53
|
export interface OrderLineConfig {
|
|
53
54
|
agentExternalId: string;
|
|
54
55
|
name?: string;
|
|
55
56
|
description?: string;
|
|
57
|
+
planProductId?: string;
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
60
|
* Note: orderLines is not required because if agentExternalId is provided,
|
|
@@ -62,13 +64,14 @@ export interface CompleteOrderConfig {
|
|
|
62
64
|
customerId: string;
|
|
63
65
|
customerExternalId: string;
|
|
64
66
|
billingContactId?: string;
|
|
65
|
-
agentExternalId
|
|
67
|
+
agentExternalId?: string;
|
|
66
68
|
name: string;
|
|
67
69
|
description: string;
|
|
68
70
|
startDate: string;
|
|
69
71
|
endDate: string;
|
|
70
72
|
currency: string;
|
|
71
73
|
orderLines: OrderLineConfig[];
|
|
74
|
+
planId?: string;
|
|
72
75
|
}
|
|
73
76
|
export interface OrderOptions {
|
|
74
77
|
/**
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.1-
|
|
1
|
+
export declare const SDK_VERSION = "1.0.1-alpha2";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/Client.mjs
CHANGED
|
@@ -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-
|
|
18
|
-
"User-Agent": "@paid-ai/paid-node/1.0.1-
|
|
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) });
|