@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.
- package/dist/cjs/Client.js +2 -2
- package/dist/cjs/api/resources/plans/client/Client.d.ts +58 -0
- package/dist/cjs/api/resources/plans/client/Client.js +220 -0
- 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/types/Plan.d.ts +33 -0
- package/dist/cjs/api/types/Plan.js +19 -0
- package/dist/cjs/api/types/PlanWithFeatures.d.ts +33 -0
- package/dist/cjs/api/types/PlanWithFeatures.js +19 -0
- package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
- package/dist/cjs/integrations/adapters/nextjs/index.js +5 -1
- package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +60 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.js +80 -0
- package/dist/cjs/integrations/controllers/index.d.ts +1 -1
- package/dist/cjs/integrations/controllers/index.js +11 -1
- package/dist/cjs/integrations/controllers/plans.d.ts +158 -0
- package/dist/cjs/integrations/controllers/plans.js +277 -0
- 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 +58 -0
- package/dist/esm/api/resources/plans/client/Client.mjs +220 -0
- 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/types/Plan.d.mts +33 -0
- package/dist/esm/api/types/Plan.mjs +18 -1
- package/dist/esm/api/types/PlanWithFeatures.d.mts +33 -0
- package/dist/esm/api/types/PlanWithFeatures.mjs +18 -1
- 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 +60 -0
- package/dist/esm/integrations/adapters/nextjs/routes.mjs +77 -1
- package/dist/esm/integrations/controllers/index.d.mts +1 -1
- package/dist/esm/integrations/controllers/index.mjs +1 -1
- package/dist/esm/integrations/controllers/plans.d.mts +158 -0
- package/dist/esm/integrations/controllers/plans.mjs +269 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/reference.md +228 -0
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { PaidClient } from "../../Client.mjs";
|
|
2
2
|
import type { PlanGroup } from "../../api/types/PlanGroup.mjs";
|
|
3
3
|
import type { Plan } from "../../api/types/Plan.mjs";
|
|
4
|
+
import type { PlanWithFeatures } from "../../api/types/PlanWithFeatures.mjs";
|
|
5
|
+
import type { Order } from "../../api/types/Order.mjs";
|
|
6
|
+
import type { CancelRenewalResponse } from "../../api/types/CancelRenewalResponse.mjs";
|
|
7
|
+
import type { ProrationUpgradeResponse } from "../../api/types/ProrationUpgradeResponse.mjs";
|
|
8
|
+
import type { PlansSubscribeRequest } from "../../api/resources/plans/client/requests/PlansSubscribeRequest.mjs";
|
|
9
|
+
import type { PlansUnsubscribeRequest } from "../../api/resources/plans/client/requests/PlansUnsubscribeRequest.mjs";
|
|
10
|
+
import type { PlansUpgradeRequest } from "../../api/resources/plans/client/requests/PlansUpgradeRequest.mjs";
|
|
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>;
|
|
@@ -82,3 +82,272 @@ export function createGetPlanGroupByIdHandler() {
|
|
|
82
82
|
requireOrganizationId: false,
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Get all plans in a plan group
|
|
87
|
+
*
|
|
88
|
+
* @param client - PaidClient instance
|
|
89
|
+
* @param planGroupId - Plan group's ID
|
|
90
|
+
* @returns Array of plans with features
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const plans = await getGroupPlans(client, 'plan-group-123');
|
|
95
|
+
* console.log(plans.length);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export function getGroupPlans(client, planGroupId) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const plans = yield client.plans.getGroupPlans(planGroupId);
|
|
101
|
+
return plans;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create a framework-agnostic handler for fetching plans in a plan group
|
|
106
|
+
*
|
|
107
|
+
* This handler can be used with any framework adapter.
|
|
108
|
+
* The plan group ID should be provided either in params or query string.
|
|
109
|
+
*
|
|
110
|
+
* @returns Handler function
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* // In Next.js route: /api/plans/[planGroupId]/plans/route.ts
|
|
115
|
+
* import { createGetGroupPlansHandler } from '@paid-ai/paid-node/integrations';
|
|
116
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
117
|
+
*
|
|
118
|
+
* const handler = createGetGroupPlansHandler();
|
|
119
|
+
* export const GET = nextjsAdapter(handler);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function createGetGroupPlansHandler() {
|
|
123
|
+
return createHandler((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const planGroupId = params === null || params === void 0 ? void 0 : params.planGroupId;
|
|
125
|
+
if (!planGroupId) {
|
|
126
|
+
return {
|
|
127
|
+
success: false,
|
|
128
|
+
error: "planGroupId is required",
|
|
129
|
+
status: 400,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const plans = yield getGroupPlans(client, planGroupId);
|
|
133
|
+
return { success: true, data: plans };
|
|
134
|
+
}), {
|
|
135
|
+
allowedMethods: ['GET'],
|
|
136
|
+
requireOrganizationId: false,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Subscribe a customer to a plan
|
|
141
|
+
*
|
|
142
|
+
* Creates a new order for a customer based on the specified plan, automatically converting plan products to order lines.
|
|
143
|
+
*
|
|
144
|
+
* @param client - PaidClient instance
|
|
145
|
+
* @param planId - Plan's ID
|
|
146
|
+
* @param request - Subscribe request with customer external ID and currency
|
|
147
|
+
* @returns Created order
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const order = await subscribe(client, 'plan-123', {
|
|
152
|
+
* customerExternalId: 'customer-123',
|
|
153
|
+
* currency: 'USD'
|
|
154
|
+
* });
|
|
155
|
+
* console.log(order.id);
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export function subscribe(client, planId, request) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const order = yield client.plans.subscribe(planId, request);
|
|
161
|
+
return order;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Create a framework-agnostic handler for subscribing a customer to a plan
|
|
166
|
+
*
|
|
167
|
+
* This handler can be used with any framework adapter.
|
|
168
|
+
* The plan ID should be provided either in params or query string.
|
|
169
|
+
* The request body should contain customerExternalId and currency.
|
|
170
|
+
*
|
|
171
|
+
* @returns Handler function
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* // In Next.js route: /api/plans/[planId]/subscribe/route.ts
|
|
176
|
+
* import { createSubscribeHandler } from '@paid-ai/paid-node/integrations';
|
|
177
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
178
|
+
*
|
|
179
|
+
* const handler = createSubscribeHandler();
|
|
180
|
+
* export const POST = nextjsAdapter(handler);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export function createSubscribeHandler() {
|
|
184
|
+
return createHandler((client, body, params) => __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
const planId = params === null || params === void 0 ? void 0 : params.planId;
|
|
186
|
+
if (!planId) {
|
|
187
|
+
return {
|
|
188
|
+
success: false,
|
|
189
|
+
error: "planId is required",
|
|
190
|
+
status: 400,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
if (!body.customerExternalId) {
|
|
194
|
+
return {
|
|
195
|
+
success: false,
|
|
196
|
+
error: "customerExternalId is required",
|
|
197
|
+
status: 400,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (!body.currency) {
|
|
201
|
+
return {
|
|
202
|
+
success: false,
|
|
203
|
+
error: "currency is required",
|
|
204
|
+
status: 400,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const order = yield subscribe(client, planId, body);
|
|
208
|
+
return { success: true, data: order };
|
|
209
|
+
}), {
|
|
210
|
+
allowedMethods: ['POST'],
|
|
211
|
+
requireOrganizationId: false,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Unsubscribe a customer from a plan
|
|
216
|
+
*
|
|
217
|
+
* Cancels the renewal of an order associated with the specified plan. The order will remain active until the cancellation date.
|
|
218
|
+
*
|
|
219
|
+
* @param client - PaidClient instance
|
|
220
|
+
* @param planId - Plan's ID
|
|
221
|
+
* @param request - Unsubscribe request with customer external ID
|
|
222
|
+
* @returns Cancel renewal response
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const response = await unsubscribe(client, 'plan-123', {
|
|
227
|
+
* customerExternalId: 'customer-123'
|
|
228
|
+
* });
|
|
229
|
+
* console.log(response.message);
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
export function unsubscribe(client, planId, request) {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
const response = yield client.plans.unsubscribe(planId, request);
|
|
235
|
+
return response;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Create a framework-agnostic handler for unsubscribing a customer from a plan
|
|
240
|
+
*
|
|
241
|
+
* This handler can be used with any framework adapter.
|
|
242
|
+
* The plan ID should be provided either in params or query string.
|
|
243
|
+
* The request body should contain customerExternalId.
|
|
244
|
+
*
|
|
245
|
+
* @returns Handler function
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* // In Next.js route: /api/plans/[planId]/unsubscribe/route.ts
|
|
250
|
+
* import { createUnsubscribeHandler } from '@paid-ai/paid-node/integrations';
|
|
251
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
252
|
+
*
|
|
253
|
+
* const handler = createUnsubscribeHandler();
|
|
254
|
+
* export const POST = nextjsAdapter(handler);
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
export function createUnsubscribeHandler() {
|
|
258
|
+
return createHandler((client, body, params) => __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
const planId = params === null || params === void 0 ? void 0 : params.planId;
|
|
260
|
+
if (!planId) {
|
|
261
|
+
return {
|
|
262
|
+
success: false,
|
|
263
|
+
error: "planId is required",
|
|
264
|
+
status: 400,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
if (!body.customerExternalId) {
|
|
268
|
+
return {
|
|
269
|
+
success: false,
|
|
270
|
+
error: "customerExternalId is required",
|
|
271
|
+
status: 400,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const response = yield unsubscribe(client, planId, body);
|
|
275
|
+
return { success: true, data: response };
|
|
276
|
+
}), {
|
|
277
|
+
allowedMethods: ['POST'],
|
|
278
|
+
requireOrganizationId: false,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Upgrade a customer from their current plan to a new plan
|
|
283
|
+
*
|
|
284
|
+
* 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.
|
|
285
|
+
*
|
|
286
|
+
* @param client - PaidClient instance
|
|
287
|
+
* @param request - Upgrade request with customer external ID, old plan ID, and new plan ID
|
|
288
|
+
* @returns Proration upgrade response
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```typescript
|
|
292
|
+
* const response = await upgrade(client, {
|
|
293
|
+
* customerExternalId: 'customer-123',
|
|
294
|
+
* oldPlanId: 'plan-123',
|
|
295
|
+
* newPlanId: 'plan-456'
|
|
296
|
+
* });
|
|
297
|
+
* console.log(response.order.id);
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
export function upgrade(client, request) {
|
|
301
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
+
const response = yield client.plans.upgrade(request);
|
|
303
|
+
return response;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Create a framework-agnostic handler for upgrading a customer's plan
|
|
308
|
+
*
|
|
309
|
+
* This handler can be used with any framework adapter.
|
|
310
|
+
* The request body should contain customerExternalId, oldPlanId, and newPlanId.
|
|
311
|
+
*
|
|
312
|
+
* @returns Handler function
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```typescript
|
|
316
|
+
* // In Next.js route: /api/plans/upgrade/route.ts
|
|
317
|
+
* import { createUpgradeHandler } from '@paid-ai/paid-node/integrations';
|
|
318
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
319
|
+
*
|
|
320
|
+
* const handler = createUpgradeHandler();
|
|
321
|
+
* export const POST = nextjsAdapter(handler);
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
export function createUpgradeHandler() {
|
|
325
|
+
return createHandler((client, body) => __awaiter(this, void 0, void 0, function* () {
|
|
326
|
+
if (!body.customerExternalId) {
|
|
327
|
+
return {
|
|
328
|
+
success: false,
|
|
329
|
+
error: "customerExternalId is required",
|
|
330
|
+
status: 400,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
if (!body.oldPlanId) {
|
|
334
|
+
return {
|
|
335
|
+
success: false,
|
|
336
|
+
error: "oldPlanId is required",
|
|
337
|
+
status: 400,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
if (!body.newPlanId) {
|
|
341
|
+
return {
|
|
342
|
+
success: false,
|
|
343
|
+
error: "newPlanId is required",
|
|
344
|
+
status: 400,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
const response = yield upgrade(client, body);
|
|
348
|
+
return { success: true, data: response };
|
|
349
|
+
}), {
|
|
350
|
+
allowedMethods: ['POST'],
|
|
351
|
+
requireOrganizationId: false,
|
|
352
|
+
});
|
|
353
|
+
}
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.1-
|
|
1
|
+
export declare const SDK_VERSION = "1.0.1-alpha2";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.1-
|
|
1
|
+
export const SDK_VERSION = "1.0.1-alpha2";
|
package/package.json
CHANGED
package/reference.md
CHANGED
|
@@ -2775,6 +2775,220 @@ await client.plans.getUsage("planId", {
|
|
|
2775
2775
|
</dl>
|
|
2776
2776
|
|
|
2777
2777
|
|
|
2778
|
+
</dd>
|
|
2779
|
+
</dl>
|
|
2780
|
+
</details>
|
|
2781
|
+
|
|
2782
|
+
<details><summary><code>client.plans.<a href="/src/api/resources/plans/client/Client.ts">subscribe</a>(planId, { ...params }) -> Paid.Order</code></summary>
|
|
2783
|
+
<dl>
|
|
2784
|
+
<dd>
|
|
2785
|
+
|
|
2786
|
+
#### 📝 Description
|
|
2787
|
+
|
|
2788
|
+
<dl>
|
|
2789
|
+
<dd>
|
|
2790
|
+
|
|
2791
|
+
<dl>
|
|
2792
|
+
<dd>
|
|
2793
|
+
|
|
2794
|
+
Creates a new order for a customer subscribing to a plan. The order will be created with the plan's products and pricing attributes.
|
|
2795
|
+
</dd>
|
|
2796
|
+
</dl>
|
|
2797
|
+
</dd>
|
|
2798
|
+
</dl>
|
|
2799
|
+
|
|
2800
|
+
#### 🔌 Usage
|
|
2801
|
+
|
|
2802
|
+
<dl>
|
|
2803
|
+
<dd>
|
|
2804
|
+
|
|
2805
|
+
<dl>
|
|
2806
|
+
<dd>
|
|
2807
|
+
|
|
2808
|
+
```typescript
|
|
2809
|
+
await client.plans.subscribe("planId", {
|
|
2810
|
+
customerExternalId: "customerExternalId",
|
|
2811
|
+
currency: "currency"
|
|
2812
|
+
});
|
|
2813
|
+
|
|
2814
|
+
```
|
|
2815
|
+
</dd>
|
|
2816
|
+
</dl>
|
|
2817
|
+
</dd>
|
|
2818
|
+
</dl>
|
|
2819
|
+
|
|
2820
|
+
#### ⚙️ Parameters
|
|
2821
|
+
|
|
2822
|
+
<dl>
|
|
2823
|
+
<dd>
|
|
2824
|
+
|
|
2825
|
+
<dl>
|
|
2826
|
+
<dd>
|
|
2827
|
+
|
|
2828
|
+
**planId:** `string` — The ID of the plan
|
|
2829
|
+
|
|
2830
|
+
</dd>
|
|
2831
|
+
</dl>
|
|
2832
|
+
|
|
2833
|
+
<dl>
|
|
2834
|
+
<dd>
|
|
2835
|
+
|
|
2836
|
+
**request:** `Paid.PlansSubscribeRequest`
|
|
2837
|
+
|
|
2838
|
+
</dd>
|
|
2839
|
+
</dl>
|
|
2840
|
+
|
|
2841
|
+
<dl>
|
|
2842
|
+
<dd>
|
|
2843
|
+
|
|
2844
|
+
**requestOptions:** `Plans.RequestOptions`
|
|
2845
|
+
|
|
2846
|
+
</dd>
|
|
2847
|
+
</dl>
|
|
2848
|
+
</dd>
|
|
2849
|
+
</dl>
|
|
2850
|
+
|
|
2851
|
+
|
|
2852
|
+
</dd>
|
|
2853
|
+
</dl>
|
|
2854
|
+
</details>
|
|
2855
|
+
|
|
2856
|
+
<details><summary><code>client.plans.<a href="/src/api/resources/plans/client/Client.ts">unsubscribe</a>(planId, { ...params }) -> Paid.CancelRenewalResponse</code></summary>
|
|
2857
|
+
<dl>
|
|
2858
|
+
<dd>
|
|
2859
|
+
|
|
2860
|
+
#### 📝 Description
|
|
2861
|
+
|
|
2862
|
+
<dl>
|
|
2863
|
+
<dd>
|
|
2864
|
+
|
|
2865
|
+
<dl>
|
|
2866
|
+
<dd>
|
|
2867
|
+
|
|
2868
|
+
Cancels the renewal of an active order for a customer's plan subscription. The order will remain active until the cancellation date.
|
|
2869
|
+
</dd>
|
|
2870
|
+
</dl>
|
|
2871
|
+
</dd>
|
|
2872
|
+
</dl>
|
|
2873
|
+
|
|
2874
|
+
#### 🔌 Usage
|
|
2875
|
+
|
|
2876
|
+
<dl>
|
|
2877
|
+
<dd>
|
|
2878
|
+
|
|
2879
|
+
<dl>
|
|
2880
|
+
<dd>
|
|
2881
|
+
|
|
2882
|
+
```typescript
|
|
2883
|
+
await client.plans.unsubscribe("planId", {
|
|
2884
|
+
customerExternalId: "customerExternalId"
|
|
2885
|
+
});
|
|
2886
|
+
|
|
2887
|
+
```
|
|
2888
|
+
</dd>
|
|
2889
|
+
</dl>
|
|
2890
|
+
</dd>
|
|
2891
|
+
</dl>
|
|
2892
|
+
|
|
2893
|
+
#### ⚙️ Parameters
|
|
2894
|
+
|
|
2895
|
+
<dl>
|
|
2896
|
+
<dd>
|
|
2897
|
+
|
|
2898
|
+
<dl>
|
|
2899
|
+
<dd>
|
|
2900
|
+
|
|
2901
|
+
**planId:** `string` — The ID of the plan
|
|
2902
|
+
|
|
2903
|
+
</dd>
|
|
2904
|
+
</dl>
|
|
2905
|
+
|
|
2906
|
+
<dl>
|
|
2907
|
+
<dd>
|
|
2908
|
+
|
|
2909
|
+
**request:** `Paid.PlansUnsubscribeRequest`
|
|
2910
|
+
|
|
2911
|
+
</dd>
|
|
2912
|
+
</dl>
|
|
2913
|
+
|
|
2914
|
+
<dl>
|
|
2915
|
+
<dd>
|
|
2916
|
+
|
|
2917
|
+
**requestOptions:** `Plans.RequestOptions`
|
|
2918
|
+
|
|
2919
|
+
</dd>
|
|
2920
|
+
</dl>
|
|
2921
|
+
</dd>
|
|
2922
|
+
</dl>
|
|
2923
|
+
|
|
2924
|
+
|
|
2925
|
+
</dd>
|
|
2926
|
+
</dl>
|
|
2927
|
+
</details>
|
|
2928
|
+
|
|
2929
|
+
<details><summary><code>client.plans.<a href="/src/api/resources/plans/client/Client.ts">upgrade</a>({ ...params }) -> Paid.ProrationUpgradeResponse</code></summary>
|
|
2930
|
+
<dl>
|
|
2931
|
+
<dd>
|
|
2932
|
+
|
|
2933
|
+
#### 📝 Description
|
|
2934
|
+
|
|
2935
|
+
<dl>
|
|
2936
|
+
<dd>
|
|
2937
|
+
|
|
2938
|
+
<dl>
|
|
2939
|
+
<dd>
|
|
2940
|
+
|
|
2941
|
+
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.
|
|
2942
|
+
</dd>
|
|
2943
|
+
</dl>
|
|
2944
|
+
</dd>
|
|
2945
|
+
</dl>
|
|
2946
|
+
|
|
2947
|
+
#### 🔌 Usage
|
|
2948
|
+
|
|
2949
|
+
<dl>
|
|
2950
|
+
<dd>
|
|
2951
|
+
|
|
2952
|
+
<dl>
|
|
2953
|
+
<dd>
|
|
2954
|
+
|
|
2955
|
+
```typescript
|
|
2956
|
+
await client.plans.upgrade({
|
|
2957
|
+
customerExternalId: "customerExternalId",
|
|
2958
|
+
oldPlanId: "oldPlanId",
|
|
2959
|
+
newPlanId: "newPlanId"
|
|
2960
|
+
});
|
|
2961
|
+
|
|
2962
|
+
```
|
|
2963
|
+
</dd>
|
|
2964
|
+
</dl>
|
|
2965
|
+
</dd>
|
|
2966
|
+
</dl>
|
|
2967
|
+
|
|
2968
|
+
#### ⚙️ Parameters
|
|
2969
|
+
|
|
2970
|
+
<dl>
|
|
2971
|
+
<dd>
|
|
2972
|
+
|
|
2973
|
+
<dl>
|
|
2974
|
+
<dd>
|
|
2975
|
+
|
|
2976
|
+
**request:** `Paid.PlansUpgradeRequest`
|
|
2977
|
+
|
|
2978
|
+
</dd>
|
|
2979
|
+
</dl>
|
|
2980
|
+
|
|
2981
|
+
<dl>
|
|
2982
|
+
<dd>
|
|
2983
|
+
|
|
2984
|
+
**requestOptions:** `Plans.RequestOptions`
|
|
2985
|
+
|
|
2986
|
+
</dd>
|
|
2987
|
+
</dl>
|
|
2988
|
+
</dd>
|
|
2989
|
+
</dl>
|
|
2990
|
+
|
|
2991
|
+
|
|
2778
2992
|
</dd>
|
|
2779
2993
|
</dl>
|
|
2780
2994
|
</details>
|
|
@@ -2832,6 +3046,20 @@ await client.plans.getGroupById("planGroupId");
|
|
|
2832
3046
|
<dl>
|
|
2833
3047
|
<dd>
|
|
2834
3048
|
|
|
3049
|
+
#### 📝 Description
|
|
3050
|
+
|
|
3051
|
+
<dl>
|
|
3052
|
+
<dd>
|
|
3053
|
+
|
|
3054
|
+
<dl>
|
|
3055
|
+
<dd>
|
|
3056
|
+
|
|
3057
|
+
Retrieves all plans in a plan group with their features (product-attribute pairs)
|
|
3058
|
+
</dd>
|
|
3059
|
+
</dl>
|
|
3060
|
+
</dd>
|
|
3061
|
+
</dl>
|
|
3062
|
+
|
|
2835
3063
|
#### 🔌 Usage
|
|
2836
3064
|
|
|
2837
3065
|
<dl>
|