@paid-ai/paid-node 0.5.0-alpha1 → 0.5.0-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 (27) hide show
  1. package/dist/cjs/Client.js +2 -2
  2. package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
  3. package/dist/cjs/integrations/adapters/nextjs/index.js +3 -1
  4. package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +51 -0
  5. package/dist/cjs/integrations/adapters/nextjs/routes.js +54 -0
  6. package/dist/cjs/integrations/controllers/billing.d.ts +83 -0
  7. package/dist/cjs/integrations/controllers/billing.js +104 -1
  8. package/dist/cjs/integrations/controllers/customers.d.ts +33 -0
  9. package/dist/cjs/integrations/controllers/customers.js +56 -0
  10. package/dist/cjs/integrations/controllers/index.d.ts +2 -2
  11. package/dist/cjs/integrations/controllers/index.js +5 -1
  12. package/dist/cjs/version.d.ts +1 -1
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/esm/Client.mjs +2 -2
  15. package/dist/esm/integrations/adapters/nextjs/index.d.mts +1 -1
  16. package/dist/esm/integrations/adapters/nextjs/index.mjs +1 -1
  17. package/dist/esm/integrations/adapters/nextjs/routes.d.mts +51 -0
  18. package/dist/esm/integrations/adapters/nextjs/routes.mjs +54 -2
  19. package/dist/esm/integrations/controllers/billing.d.mts +83 -0
  20. package/dist/esm/integrations/controllers/billing.mjs +102 -1
  21. package/dist/esm/integrations/controllers/customers.d.mts +33 -0
  22. package/dist/esm/integrations/controllers/customers.mjs +54 -0
  23. package/dist/esm/integrations/controllers/index.d.mts +2 -2
  24. package/dist/esm/integrations/controllers/index.mjs +2 -2
  25. package/dist/esm/version.d.mts +1 -1
  26. package/dist/esm/version.mjs +1 -1
  27. package/package.json +1 -1
@@ -60,8 +60,8 @@ class PaidClient {
60
60
  this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
61
61
  "X-Fern-Language": "JavaScript",
62
62
  "X-Fern-SDK-Name": "@paid-ai/paid-node",
63
- "X-Fern-SDK-Version": "0.5.0-alpha1",
64
- "User-Agent": "@paid-ai/paid-node/0.5.0-alpha1",
63
+ "X-Fern-SDK-Version": "0.5.0-alpha2",
64
+ "User-Agent": "@paid-ai/paid-node/0.5.0-alpha2",
65
65
  "X-Fern-Runtime": core.RUNTIME.type,
66
66
  "X-Fern-Runtime-Version": core.RUNTIME.version,
67
67
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -2,4 +2,4 @@
2
2
  * Next.js API Route handlers for Paid integration
3
3
  * Drop-in handlers for Next.js App Router
4
4
  */
5
- export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, } from './routes.js';
5
+ export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from './routes.js';
@@ -4,12 +4,14 @@
4
4
  * Drop-in handlers for Next.js App Router
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.createProvisioningRoute = exports.createPayInvoiceRoute = exports.createOrdersRoute = exports.createCustomersRoute = exports.createCustomerInvoicesRoute = exports.createContactsRoute = exports.createActivateOrderSyncRoute = void 0;
7
+ exports.createSetupIntentRoute = exports.createProvisioningRoute = exports.createPayInvoiceRoute = exports.createOrdersRoute = exports.createGetCustomerRoute = exports.createCustomersRoute = exports.createCustomerInvoicesRoute = exports.createContactsRoute = exports.createActivateOrderSyncRoute = void 0;
8
8
  var routes_js_1 = require("./routes.js");
9
9
  Object.defineProperty(exports, "createActivateOrderSyncRoute", { enumerable: true, get: function () { return routes_js_1.createActivateOrderSyncRoute; } });
10
10
  Object.defineProperty(exports, "createContactsRoute", { enumerable: true, get: function () { return routes_js_1.createContactsRoute; } });
11
11
  Object.defineProperty(exports, "createCustomerInvoicesRoute", { enumerable: true, get: function () { return routes_js_1.createCustomerInvoicesRoute; } });
12
12
  Object.defineProperty(exports, "createCustomersRoute", { enumerable: true, get: function () { return routes_js_1.createCustomersRoute; } });
13
+ Object.defineProperty(exports, "createGetCustomerRoute", { enumerable: true, get: function () { return routes_js_1.createGetCustomerRoute; } });
13
14
  Object.defineProperty(exports, "createOrdersRoute", { enumerable: true, get: function () { return routes_js_1.createOrdersRoute; } });
14
15
  Object.defineProperty(exports, "createPayInvoiceRoute", { enumerable: true, get: function () { return routes_js_1.createPayInvoiceRoute; } });
15
16
  Object.defineProperty(exports, "createProvisioningRoute", { enumerable: true, get: function () { return routes_js_1.createProvisioningRoute; } });
17
+ Object.defineProperty(exports, "createSetupIntentRoute", { enumerable: true, get: function () { return routes_js_1.createSetupIntentRoute; } });
@@ -74,6 +74,18 @@ export declare function createContactsRoute(config?: BaseHandlerConfig): (reques
74
74
  * ```
75
75
  */
76
76
  export declare function createCustomerInvoicesRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
77
+ /**
78
+ * Create a Next.js API route handler for fetching a customer by external ID
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // src/app/api/customers/[customerExternalId]/route.ts
83
+ * import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/nextjs';
84
+ *
85
+ * export const GET = createGetCustomerRoute();
86
+ * ```
87
+ */
88
+ export declare function createGetCustomerRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
77
89
  /**
78
90
  * Create a Next.js API route handler for customer creation
79
91
  *
@@ -172,3 +184,42 @@ export interface ProvisioningRouteConfig extends BaseHandlerConfig {
172
184
  * ```
173
185
  */
174
186
  export declare function createProvisioningRoute(config?: ProvisioningRouteConfig): (request: any, context?: any) => Promise<any>;
187
+ export interface SetupIntentRouteConfig extends BaseHandlerConfig {
188
+ /**
189
+ * Default return URL for setup flow
190
+ * Can be overridden by request body
191
+ */
192
+ defaultReturnUrl?: string;
193
+ }
194
+ /**
195
+ * Create a Next.js API route handler for setup intent creation
196
+ *
197
+ * Setup intents are used to add payment methods without immediate charge.
198
+ * This is useful for saving payment methods for future billing.
199
+ *
200
+ * Organization ID is automatically fetched from the API key.
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * // src/app/api/payment-methods/setup/route.ts
205
+ * import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/nextjs';
206
+ *
207
+ * export const POST = createSetupIntentRoute({
208
+ * defaultReturnUrl: process.env.NEXT_PUBLIC_BASE_URL + '/billing'
209
+ * });
210
+ * ```
211
+ *
212
+ * @example Client-side usage
213
+ * ```typescript
214
+ * await fetch('/api/payment-methods/setup', {
215
+ * method: 'POST',
216
+ * body: JSON.stringify({
217
+ * customerId: 'cus_123',
218
+ * confirmationToken: 'seti_123_secret_456',
219
+ * returnUrl: 'https://example.com/billing',
220
+ * metadata: { source: 'settings_page' }
221
+ * })
222
+ * });
223
+ * ```
224
+ */
225
+ export declare function createSetupIntentRoute(config?: SetupIntentRouteConfig): (request: any, context?: any) => Promise<any>;
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createActivateOrderSyncRoute = createActivateOrderSyncRoute;
4
4
  exports.createContactsRoute = createContactsRoute;
5
5
  exports.createCustomerInvoicesRoute = createCustomerInvoicesRoute;
6
+ exports.createGetCustomerRoute = createGetCustomerRoute;
6
7
  exports.createCustomersRoute = createCustomersRoute;
7
8
  exports.createOrdersRoute = createOrdersRoute;
8
9
  exports.createPayInvoiceRoute = createPayInvoiceRoute;
9
10
  exports.createProvisioningRoute = createProvisioningRoute;
11
+ exports.createSetupIntentRoute = createSetupIntentRoute;
10
12
  const base_adapter_js_1 = require("./base-adapter.js");
11
13
  const contacts_js_1 = require("../../controllers/contacts.js");
12
14
  const invoices_js_1 = require("../../controllers/invoices.js");
@@ -93,6 +95,22 @@ function createCustomerInvoicesRoute(config = {}) {
93
95
  const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
94
96
  return (request, context) => adaptedHandler(request, context, config);
95
97
  }
98
+ /**
99
+ * Create a Next.js API route handler for fetching a customer by external ID
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * // src/app/api/customers/[customerExternalId]/route.ts
104
+ * import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/nextjs';
105
+ *
106
+ * export const GET = createGetCustomerRoute();
107
+ * ```
108
+ */
109
+ function createGetCustomerRoute(config = {}) {
110
+ const handler = (0, customers_js_1.createGetCustomerHandler)();
111
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
112
+ return (request, context) => adaptedHandler(request, context, config);
113
+ }
96
114
  /**
97
115
  * Create a Next.js API route handler for customer creation
98
116
  *
@@ -190,3 +208,39 @@ function createProvisioningRoute(config = {}) {
190
208
  const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
191
209
  return (request, context) => adaptedHandler(request, context, config);
192
210
  }
211
+ /**
212
+ * Create a Next.js API route handler for setup intent creation
213
+ *
214
+ * Setup intents are used to add payment methods without immediate charge.
215
+ * This is useful for saving payment methods for future billing.
216
+ *
217
+ * Organization ID is automatically fetched from the API key.
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * // src/app/api/payment-methods/setup/route.ts
222
+ * import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/nextjs';
223
+ *
224
+ * export const POST = createSetupIntentRoute({
225
+ * defaultReturnUrl: process.env.NEXT_PUBLIC_BASE_URL + '/billing'
226
+ * });
227
+ * ```
228
+ *
229
+ * @example Client-side usage
230
+ * ```typescript
231
+ * await fetch('/api/payment-methods/setup', {
232
+ * method: 'POST',
233
+ * body: JSON.stringify({
234
+ * customerId: 'cus_123',
235
+ * confirmationToken: 'seti_123_secret_456',
236
+ * returnUrl: 'https://example.com/billing',
237
+ * metadata: { source: 'settings_page' }
238
+ * })
239
+ * });
240
+ * ```
241
+ */
242
+ function createSetupIntentRoute(config = {}) {
243
+ const handler = (0, billing_js_1.createSetupIntentHandler)(config.defaultReturnUrl);
244
+ const adaptedHandler = (0, base_adapter_js_1.nextjsAdapter)(handler);
245
+ return (request, context) => adaptedHandler(request, context, config);
246
+ }
@@ -110,4 +110,87 @@ interface ActivateOrderSyncRequestBody {
110
110
  * @returns Handler function
111
111
  */
112
112
  export declare function createActivateOrderSyncHandler(defaultReturnUrl?: string): (request: import("../utils/base-handler.js").BaseRequestContext<ActivateOrderSyncRequestBody, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;
113
+ export interface SetupIntentRequest {
114
+ customerId: string;
115
+ confirmationToken: string;
116
+ returnUrl?: string;
117
+ metadata?: Record<string, any>;
118
+ }
119
+ export interface SetupIntentResponse {
120
+ setupIntent: {
121
+ id: string;
122
+ client_secret: string;
123
+ status: string;
124
+ usage: string;
125
+ customer: string;
126
+ };
127
+ message: string;
128
+ }
129
+ export interface SetupIntentConfig {
130
+ apiUrl: string;
131
+ apiKey: string;
132
+ organizationId: string;
133
+ }
134
+ /**
135
+ * Create a setup intent for adding payment methods without immediate charge
136
+ *
137
+ * Setup intents are used to save payment methods for future use without
138
+ * charging the customer immediately. This is useful for:
139
+ * - Adding payment methods for subscription billing
140
+ * - Updating payment methods
141
+ * - Pre-authorizing payment methods
142
+ *
143
+ * @param config - API configuration with organization context
144
+ * @param request - Setup intent request with customer ID and confirmation token
145
+ * @returns Setup intent result with payment method details
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * const result = await createSetupIntent(
150
+ * {
151
+ * apiUrl: 'https://api.agentpaid.io',
152
+ * apiKey: process.env.PAID_API_KEY,
153
+ * organizationId: 'org_123'
154
+ * },
155
+ * {
156
+ * customerId: 'cus_123',
157
+ * confirmationToken: 'seti_123_secret_456',
158
+ * returnUrl: 'https://example.com/return',
159
+ * metadata: { source: 'web' }
160
+ * }
161
+ * );
162
+ * ```
163
+ */
164
+ export declare function createSetupIntent(config: SetupIntentConfig, request: SetupIntentRequest): Promise<SetupIntentResponse>;
165
+ /**
166
+ * Create a framework-agnostic handler for setup intent creation
167
+ *
168
+ * This handler can be used with any framework adapter.
169
+ *
170
+ * @param defaultReturnUrl - Optional default return URL
171
+ * @returns Handler function
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * // Next.js API route
176
+ * import { createSetupIntentHandler } from '@paid-ai/paid-node/integrations';
177
+ *
178
+ * const handler = createSetupIntentHandler('https://myapp.com/billing');
179
+ *
180
+ * export async function POST(req: Request) {
181
+ * return handler(
182
+ * {
183
+ * body: await req.json(),
184
+ * headers: Object.fromEntries(req.headers),
185
+ * method: 'POST'
186
+ * },
187
+ * {
188
+ * json: (data, status = 200) => Response.json(data, { status }),
189
+ * error: (message, status) => Response.json({ error: message }, { status })
190
+ * }
191
+ * );
192
+ * }
193
+ * ```
194
+ */
195
+ export declare function createSetupIntentHandler(defaultReturnUrl?: string): (request: import("../utils/base-handler.js").BaseRequestContext<SetupIntentRequest, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;
113
196
  export {};
@@ -13,6 +13,8 @@ exports.payInvoice = payInvoice;
13
13
  exports.createPayInvoiceHandler = createPayInvoiceHandler;
14
14
  exports.activateOrderSync = activateOrderSync;
15
15
  exports.createActivateOrderSyncHandler = createActivateOrderSyncHandler;
16
+ exports.createSetupIntent = createSetupIntent;
17
+ exports.createSetupIntentHandler = createSetupIntentHandler;
16
18
  const api_fetch_js_1 = require("../utils/api-fetch.js");
17
19
  const base_handler_js_1 = require("../utils/base-handler.js");
18
20
  /**
@@ -117,7 +119,7 @@ function activateOrderSync(config, request) {
117
119
  if (!confirmationToken) {
118
120
  throw new Error("confirmationToken is required");
119
121
  }
120
- const data = yield (0, api_fetch_js_1.paidApiFetch)(config, `/api/organizations/${config.organizationId}/orders/${orderId}/activate-sync`, {
122
+ const data = yield (0, api_fetch_js_1.paidApiFetch)(config, `/api/organizations/${config.organizationId}/orders/${orderId}/activate-and-pay`, {
121
123
  method: "POST",
122
124
  body: Object.assign({ confirmationToken }, (returnUrl && { returnUrl })),
123
125
  });
@@ -162,3 +164,104 @@ function createActivateOrderSyncHandler(defaultReturnUrl) {
162
164
  requireOrganizationId: true,
163
165
  });
164
166
  }
167
+ /**
168
+ * Create a setup intent for adding payment methods without immediate charge
169
+ *
170
+ * Setup intents are used to save payment methods for future use without
171
+ * charging the customer immediately. This is useful for:
172
+ * - Adding payment methods for subscription billing
173
+ * - Updating payment methods
174
+ * - Pre-authorizing payment methods
175
+ *
176
+ * @param config - API configuration with organization context
177
+ * @param request - Setup intent request with customer ID and confirmation token
178
+ * @returns Setup intent result with payment method details
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const result = await createSetupIntent(
183
+ * {
184
+ * apiUrl: 'https://api.agentpaid.io',
185
+ * apiKey: process.env.PAID_API_KEY,
186
+ * organizationId: 'org_123'
187
+ * },
188
+ * {
189
+ * customerId: 'cus_123',
190
+ * confirmationToken: 'seti_123_secret_456',
191
+ * returnUrl: 'https://example.com/return',
192
+ * metadata: { source: 'web' }
193
+ * }
194
+ * );
195
+ * ```
196
+ */
197
+ function createSetupIntent(config, request) {
198
+ return __awaiter(this, void 0, void 0, function* () {
199
+ const { customerId, confirmationToken, returnUrl, metadata } = request;
200
+ if (!customerId) {
201
+ throw new Error("customerId is required");
202
+ }
203
+ if (!confirmationToken) {
204
+ throw new Error("confirmationToken is required");
205
+ }
206
+ const data = yield (0, api_fetch_js_1.paidApiFetch)(config, `/api/organizations/${config.organizationId}/payments/setup-intents-external`, {
207
+ method: "POST",
208
+ body: Object.assign(Object.assign({ customerId,
209
+ confirmationToken }, (returnUrl && { returnUrl })), (metadata && { metadata })),
210
+ });
211
+ return {
212
+ setupIntent: data.setupIntent || data,
213
+ message: "Setup intent created successfully",
214
+ };
215
+ });
216
+ }
217
+ /**
218
+ * Create a framework-agnostic handler for setup intent creation
219
+ *
220
+ * This handler can be used with any framework adapter.
221
+ *
222
+ * @param defaultReturnUrl - Optional default return URL
223
+ * @returns Handler function
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * // Next.js API route
228
+ * import { createSetupIntentHandler } from '@paid-ai/paid-node/integrations';
229
+ *
230
+ * const handler = createSetupIntentHandler('https://myapp.com/billing');
231
+ *
232
+ * export async function POST(req: Request) {
233
+ * return handler(
234
+ * {
235
+ * body: await req.json(),
236
+ * headers: Object.fromEntries(req.headers),
237
+ * method: 'POST'
238
+ * },
239
+ * {
240
+ * json: (data, status = 200) => Response.json(data, { status }),
241
+ * error: (message, status) => Response.json({ error: message }, { status })
242
+ * }
243
+ * );
244
+ * }
245
+ * ```
246
+ */
247
+ function createSetupIntentHandler(defaultReturnUrl) {
248
+ return (0, base_handler_js_1.createHandler)((client, body, _params, organizationId) => __awaiter(this, void 0, void 0, function* () {
249
+ var _a, _b;
250
+ const apiKey = (_a = client._options) === null || _a === void 0 ? void 0 : _a.token;
251
+ const baseUrl = ((_b = client._options) === null || _b === void 0 ? void 0 : _b.baseUrl) || 'https://api.agentpaid.io/api/v1';
252
+ const apiUrl = baseUrl.replace('/api/v1', '');
253
+ const result = yield createSetupIntent({ apiUrl, apiKey, organizationId: organizationId }, {
254
+ customerId: body.customerId,
255
+ confirmationToken: body.confirmationToken,
256
+ returnUrl: body.returnUrl || defaultReturnUrl,
257
+ metadata: body.metadata,
258
+ });
259
+ return {
260
+ success: true,
261
+ data: result,
262
+ };
263
+ }), {
264
+ requiredFields: ['customerId', 'confirmationToken'],
265
+ requireOrganizationId: true,
266
+ });
267
+ }
@@ -61,3 +61,36 @@ export declare function createCustomer(client: PaidClient, data: Required<Omit<C
61
61
  * @returns Handler function
62
62
  */
63
63
  export declare function createCustomersHandler(): (request: import("../utils/base-handler.js").BaseRequestContext<CustomerData, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;
64
+ /**
65
+ * Get a customer by external ID
66
+ *
67
+ * @param client - PaidClient instance
68
+ * @param customerExternalId - Customer's external ID
69
+ * @returns Customer data
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const customer = await getCustomer(client, 'user-123');
74
+ * console.log(customer.name, customer.email);
75
+ * ```
76
+ */
77
+ export declare function getCustomer(client: PaidClient, customerExternalId: string): Promise<any>;
78
+ /**
79
+ * Create a framework-agnostic handler for fetching a customer by external ID
80
+ *
81
+ * This handler can be used with any framework adapter.
82
+ * The customer external ID should be provided either in params or query string.
83
+ *
84
+ * @returns Handler function
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * // In Next.js route: /api/customers/[customerExternalId]/route.ts
89
+ * import { createGetCustomerHandler } from '@paid-ai/paid-node/integrations';
90
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
91
+ *
92
+ * const handler = createGetCustomerHandler();
93
+ * export const GET = nextjsAdapter(handler);
94
+ * ```
95
+ */
96
+ export declare function createGetCustomerHandler(): (request: import("../utils/base-handler.js").BaseRequestContext<any, Record<string, string>>, response: import("../utils/base-handler.js").BaseResponseContext, config?: import("../utils/base-handler.js").BaseHandlerConfig) => Promise<any>;
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createCustomerWithDefaults = createCustomerWithDefaults;
13
13
  exports.createCustomer = createCustomer;
14
14
  exports.createCustomersHandler = createCustomersHandler;
15
+ exports.getCustomer = getCustomer;
16
+ exports.createGetCustomerHandler = createGetCustomerHandler;
15
17
  const base_handler_js_1 = require("../utils/base-handler.js");
16
18
  /**
17
19
  * Generate placeholder values for missing customer fields
@@ -148,3 +150,57 @@ function createCustomersHandler() {
148
150
  return { success: true, data: customer };
149
151
  }), { requiredFields: ['externalId'] });
150
152
  }
153
+ /**
154
+ * Get a customer by external ID
155
+ *
156
+ * @param client - PaidClient instance
157
+ * @param customerExternalId - Customer's external ID
158
+ * @returns Customer data
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * const customer = await getCustomer(client, 'user-123');
163
+ * console.log(customer.name, customer.email);
164
+ * ```
165
+ */
166
+ function getCustomer(client, customerExternalId) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ const customer = yield client.customers.getByExternalId(customerExternalId);
169
+ return customer;
170
+ });
171
+ }
172
+ /**
173
+ * Create a framework-agnostic handler for fetching a customer by external ID
174
+ *
175
+ * This handler can be used with any framework adapter.
176
+ * The customer external ID should be provided either in params or query string.
177
+ *
178
+ * @returns Handler function
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // In Next.js route: /api/customers/[customerExternalId]/route.ts
183
+ * import { createGetCustomerHandler } from '@paid-ai/paid-node/integrations';
184
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
185
+ *
186
+ * const handler = createGetCustomerHandler();
187
+ * export const GET = nextjsAdapter(handler);
188
+ * ```
189
+ */
190
+ function createGetCustomerHandler() {
191
+ return (0, base_handler_js_1.createHandler)((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
192
+ const customerExternalId = params === null || params === void 0 ? void 0 : params.customerExternalId;
193
+ if (!customerExternalId) {
194
+ return {
195
+ success: false,
196
+ error: "customerExternalId is required",
197
+ status: 400,
198
+ };
199
+ }
200
+ const customer = yield getCustomer(client, customerExternalId);
201
+ return { success: true, data: customer };
202
+ }), {
203
+ allowedMethods: ['GET'],
204
+ requireOrganizationId: false,
205
+ });
206
+ }
@@ -1,6 +1,6 @@
1
- export { createCustomer, createCustomerWithDefaults, createCustomersHandler, } from "./customers.js";
1
+ export { createCustomer, createCustomerWithDefaults, getCustomer, createGetCustomerHandler, createCustomersHandler, } from "./customers.js";
2
2
  export { createContact, createContactWithDefaults, createContactsHandler, } from "./contacts.js";
3
3
  export { createOrder, createOrderWithDefaults, createOrdersHandler, } from "./orders.js";
4
- export { payInvoice, createPayInvoiceHandler, type PayInvoiceConfig, type PayInvoiceRequest, type PayInvoiceResult, activateOrderSync, createActivateOrderSyncHandler, type ActivateOrderSyncConfig, type ActivateOrderSyncRequest, type ActivateOrderSyncResult, } from "./billing.js";
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";
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createProvisioningHandler = exports.provisionNewUser = exports.createCustomerInvoicesHandler = exports.getCustomerInvoices = exports.createActivateOrderSyncHandler = exports.activateOrderSync = exports.createPayInvoiceHandler = exports.payInvoice = exports.createOrdersHandler = exports.createOrderWithDefaults = exports.createOrder = exports.createContactsHandler = exports.createContactWithDefaults = exports.createContact = exports.createCustomersHandler = exports.createCustomerWithDefaults = exports.createCustomer = void 0;
3
+ 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; } });
7
+ Object.defineProperty(exports, "getCustomer", { enumerable: true, get: function () { return customers_js_1.getCustomer; } });
8
+ Object.defineProperty(exports, "createGetCustomerHandler", { enumerable: true, get: function () { return customers_js_1.createGetCustomerHandler; } });
7
9
  Object.defineProperty(exports, "createCustomersHandler", { enumerable: true, get: function () { return customers_js_1.createCustomersHandler; } });
8
10
  var contacts_js_1 = require("./contacts.js");
9
11
  Object.defineProperty(exports, "createContact", { enumerable: true, get: function () { return contacts_js_1.createContact; } });
@@ -18,6 +20,8 @@ Object.defineProperty(exports, "payInvoice", { enumerable: true, get: function (
18
20
  Object.defineProperty(exports, "createPayInvoiceHandler", { enumerable: true, get: function () { return billing_js_1.createPayInvoiceHandler; } });
19
21
  Object.defineProperty(exports, "activateOrderSync", { enumerable: true, get: function () { return billing_js_1.activateOrderSync; } });
20
22
  Object.defineProperty(exports, "createActivateOrderSyncHandler", { enumerable: true, get: function () { return billing_js_1.createActivateOrderSyncHandler; } });
23
+ Object.defineProperty(exports, "createSetupIntent", { enumerable: true, get: function () { return billing_js_1.createSetupIntent; } });
24
+ Object.defineProperty(exports, "createSetupIntentHandler", { enumerable: true, get: function () { return billing_js_1.createSetupIntentHandler; } });
21
25
  var invoices_js_1 = require("./invoices.js");
22
26
  Object.defineProperty(exports, "getCustomerInvoices", { enumerable: true, get: function () { return invoices_js_1.getCustomerInvoices; } });
23
27
  Object.defineProperty(exports, "createCustomerInvoicesHandler", { enumerable: true, get: function () { return invoices_js_1.createCustomerInvoicesHandler; } });
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.5.0-alpha1";
1
+ export declare const SDK_VERSION = "0.5.0-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 = "0.5.0-alpha1";
4
+ exports.SDK_VERSION = "0.5.0-alpha2";
@@ -24,8 +24,8 @@ export class PaidClient {
24
24
  this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
25
25
  "X-Fern-Language": "JavaScript",
26
26
  "X-Fern-SDK-Name": "@paid-ai/paid-node",
27
- "X-Fern-SDK-Version": "0.5.0-alpha1",
28
- "User-Agent": "@paid-ai/paid-node/0.5.0-alpha1",
27
+ "X-Fern-SDK-Version": "0.5.0-alpha2",
28
+ "User-Agent": "@paid-ai/paid-node/0.5.0-alpha2",
29
29
  "X-Fern-Runtime": core.RUNTIME.type,
30
30
  "X-Fern-Runtime-Version": core.RUNTIME.version,
31
31
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -2,4 +2,4 @@
2
2
  * Next.js API Route handlers for Paid integration
3
3
  * Drop-in handlers for Next.js App Router
4
4
  */
5
- export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, } from './routes.mjs';
5
+ export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from './routes.mjs';
@@ -2,4 +2,4 @@
2
2
  * Next.js API Route handlers for Paid integration
3
3
  * Drop-in handlers for Next.js App Router
4
4
  */
5
- export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, } from './routes.mjs';
5
+ export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, } from './routes.mjs';
@@ -74,6 +74,18 @@ export declare function createContactsRoute(config?: BaseHandlerConfig): (reques
74
74
  * ```
75
75
  */
76
76
  export declare function createCustomerInvoicesRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
77
+ /**
78
+ * Create a Next.js API route handler for fetching a customer by external ID
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // src/app/api/customers/[customerExternalId]/route.ts
83
+ * import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/nextjs';
84
+ *
85
+ * export const GET = createGetCustomerRoute();
86
+ * ```
87
+ */
88
+ export declare function createGetCustomerRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
77
89
  /**
78
90
  * Create a Next.js API route handler for customer creation
79
91
  *
@@ -172,3 +184,42 @@ export interface ProvisioningRouteConfig extends BaseHandlerConfig {
172
184
  * ```
173
185
  */
174
186
  export declare function createProvisioningRoute(config?: ProvisioningRouteConfig): (request: any, context?: any) => Promise<any>;
187
+ export interface SetupIntentRouteConfig extends BaseHandlerConfig {
188
+ /**
189
+ * Default return URL for setup flow
190
+ * Can be overridden by request body
191
+ */
192
+ defaultReturnUrl?: string;
193
+ }
194
+ /**
195
+ * Create a Next.js API route handler for setup intent creation
196
+ *
197
+ * Setup intents are used to add payment methods without immediate charge.
198
+ * This is useful for saving payment methods for future billing.
199
+ *
200
+ * Organization ID is automatically fetched from the API key.
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * // src/app/api/payment-methods/setup/route.ts
205
+ * import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/nextjs';
206
+ *
207
+ * export const POST = createSetupIntentRoute({
208
+ * defaultReturnUrl: process.env.NEXT_PUBLIC_BASE_URL + '/billing'
209
+ * });
210
+ * ```
211
+ *
212
+ * @example Client-side usage
213
+ * ```typescript
214
+ * await fetch('/api/payment-methods/setup', {
215
+ * method: 'POST',
216
+ * body: JSON.stringify({
217
+ * customerId: 'cus_123',
218
+ * confirmationToken: 'seti_123_secret_456',
219
+ * returnUrl: 'https://example.com/billing',
220
+ * metadata: { source: 'settings_page' }
221
+ * })
222
+ * });
223
+ * ```
224
+ */
225
+ export declare function createSetupIntentRoute(config?: SetupIntentRouteConfig): (request: any, context?: any) => Promise<any>;
@@ -1,10 +1,10 @@
1
1
  import { nextjsAdapter } from "./base-adapter.mjs";
2
2
  import { createContactsHandler } from "../../controllers/contacts.mjs";
3
3
  import { createCustomerInvoicesHandler } from "../../controllers/invoices.mjs";
4
- import { createCustomersHandler } from "../../controllers/customers.mjs";
4
+ import { createCustomersHandler, createGetCustomerHandler } from "../../controllers/customers.mjs";
5
5
  import { createOrdersHandler } from "../../controllers/orders.mjs";
6
6
  import { createProvisioningHandler } from "../../controllers/provision-users.mjs";
7
- import { createActivateOrderSyncHandler, createPayInvoiceHandler } from "../../controllers/billing.mjs";
7
+ import { createActivateOrderSyncHandler, createPayInvoiceHandler, createSetupIntentHandler } from "../../controllers/billing.mjs";
8
8
  /**
9
9
  * Create a Next.js API route handler for synchronous order activation
10
10
  *
@@ -84,6 +84,22 @@ export function createCustomerInvoicesRoute(config = {}) {
84
84
  const adaptedHandler = nextjsAdapter(handler);
85
85
  return (request, context) => adaptedHandler(request, context, config);
86
86
  }
87
+ /**
88
+ * Create a Next.js API route handler for fetching a customer by external ID
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * // src/app/api/customers/[customerExternalId]/route.ts
93
+ * import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/nextjs';
94
+ *
95
+ * export const GET = createGetCustomerRoute();
96
+ * ```
97
+ */
98
+ export function createGetCustomerRoute(config = {}) {
99
+ const handler = createGetCustomerHandler();
100
+ const adaptedHandler = nextjsAdapter(handler);
101
+ return (request, context) => adaptedHandler(request, context, config);
102
+ }
87
103
  /**
88
104
  * Create a Next.js API route handler for customer creation
89
105
  *
@@ -181,3 +197,39 @@ export function createProvisioningRoute(config = {}) {
181
197
  const adaptedHandler = nextjsAdapter(handler);
182
198
  return (request, context) => adaptedHandler(request, context, config);
183
199
  }
200
+ /**
201
+ * Create a Next.js API route handler for setup intent creation
202
+ *
203
+ * Setup intents are used to add payment methods without immediate charge.
204
+ * This is useful for saving payment methods for future billing.
205
+ *
206
+ * Organization ID is automatically fetched from the API key.
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * // src/app/api/payment-methods/setup/route.ts
211
+ * import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/nextjs';
212
+ *
213
+ * export const POST = createSetupIntentRoute({
214
+ * defaultReturnUrl: process.env.NEXT_PUBLIC_BASE_URL + '/billing'
215
+ * });
216
+ * ```
217
+ *
218
+ * @example Client-side usage
219
+ * ```typescript
220
+ * await fetch('/api/payment-methods/setup', {
221
+ * method: 'POST',
222
+ * body: JSON.stringify({
223
+ * customerId: 'cus_123',
224
+ * confirmationToken: 'seti_123_secret_456',
225
+ * returnUrl: 'https://example.com/billing',
226
+ * metadata: { source: 'settings_page' }
227
+ * })
228
+ * });
229
+ * ```
230
+ */
231
+ export function createSetupIntentRoute(config = {}) {
232
+ const handler = createSetupIntentHandler(config.defaultReturnUrl);
233
+ const adaptedHandler = nextjsAdapter(handler);
234
+ return (request, context) => adaptedHandler(request, context, config);
235
+ }
@@ -110,4 +110,87 @@ interface ActivateOrderSyncRequestBody {
110
110
  * @returns Handler function
111
111
  */
112
112
  export declare function createActivateOrderSyncHandler(defaultReturnUrl?: string): (request: import("../utils/base-handler.mjs").BaseRequestContext<ActivateOrderSyncRequestBody, Record<string, string>>, response: import("../utils/base-handler.mjs").BaseResponseContext, config?: import("../utils/base-handler.mjs").BaseHandlerConfig) => Promise<any>;
113
+ export interface SetupIntentRequest {
114
+ customerId: string;
115
+ confirmationToken: string;
116
+ returnUrl?: string;
117
+ metadata?: Record<string, any>;
118
+ }
119
+ export interface SetupIntentResponse {
120
+ setupIntent: {
121
+ id: string;
122
+ client_secret: string;
123
+ status: string;
124
+ usage: string;
125
+ customer: string;
126
+ };
127
+ message: string;
128
+ }
129
+ export interface SetupIntentConfig {
130
+ apiUrl: string;
131
+ apiKey: string;
132
+ organizationId: string;
133
+ }
134
+ /**
135
+ * Create a setup intent for adding payment methods without immediate charge
136
+ *
137
+ * Setup intents are used to save payment methods for future use without
138
+ * charging the customer immediately. This is useful for:
139
+ * - Adding payment methods for subscription billing
140
+ * - Updating payment methods
141
+ * - Pre-authorizing payment methods
142
+ *
143
+ * @param config - API configuration with organization context
144
+ * @param request - Setup intent request with customer ID and confirmation token
145
+ * @returns Setup intent result with payment method details
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * const result = await createSetupIntent(
150
+ * {
151
+ * apiUrl: 'https://api.agentpaid.io',
152
+ * apiKey: process.env.PAID_API_KEY,
153
+ * organizationId: 'org_123'
154
+ * },
155
+ * {
156
+ * customerId: 'cus_123',
157
+ * confirmationToken: 'seti_123_secret_456',
158
+ * returnUrl: 'https://example.com/return',
159
+ * metadata: { source: 'web' }
160
+ * }
161
+ * );
162
+ * ```
163
+ */
164
+ export declare function createSetupIntent(config: SetupIntentConfig, request: SetupIntentRequest): Promise<SetupIntentResponse>;
165
+ /**
166
+ * Create a framework-agnostic handler for setup intent creation
167
+ *
168
+ * This handler can be used with any framework adapter.
169
+ *
170
+ * @param defaultReturnUrl - Optional default return URL
171
+ * @returns Handler function
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * // Next.js API route
176
+ * import { createSetupIntentHandler } from '@paid-ai/paid-node/integrations';
177
+ *
178
+ * const handler = createSetupIntentHandler('https://myapp.com/billing');
179
+ *
180
+ * export async function POST(req: Request) {
181
+ * return handler(
182
+ * {
183
+ * body: await req.json(),
184
+ * headers: Object.fromEntries(req.headers),
185
+ * method: 'POST'
186
+ * },
187
+ * {
188
+ * json: (data, status = 200) => Response.json(data, { status }),
189
+ * error: (message, status) => Response.json({ error: message }, { status })
190
+ * }
191
+ * );
192
+ * }
193
+ * ```
194
+ */
195
+ export declare function createSetupIntentHandler(defaultReturnUrl?: string): (request: import("../utils/base-handler.mjs").BaseRequestContext<SetupIntentRequest, Record<string, string>>, response: import("../utils/base-handler.mjs").BaseResponseContext, config?: import("../utils/base-handler.mjs").BaseHandlerConfig) => Promise<any>;
113
196
  export {};
@@ -111,7 +111,7 @@ export function activateOrderSync(config, request) {
111
111
  if (!confirmationToken) {
112
112
  throw new Error("confirmationToken is required");
113
113
  }
114
- const data = yield paidApiFetch(config, `/api/organizations/${config.organizationId}/orders/${orderId}/activate-sync`, {
114
+ const data = yield paidApiFetch(config, `/api/organizations/${config.organizationId}/orders/${orderId}/activate-and-pay`, {
115
115
  method: "POST",
116
116
  body: Object.assign({ confirmationToken }, (returnUrl && { returnUrl })),
117
117
  });
@@ -156,3 +156,104 @@ export function createActivateOrderSyncHandler(defaultReturnUrl) {
156
156
  requireOrganizationId: true,
157
157
  });
158
158
  }
159
+ /**
160
+ * Create a setup intent for adding payment methods without immediate charge
161
+ *
162
+ * Setup intents are used to save payment methods for future use without
163
+ * charging the customer immediately. This is useful for:
164
+ * - Adding payment methods for subscription billing
165
+ * - Updating payment methods
166
+ * - Pre-authorizing payment methods
167
+ *
168
+ * @param config - API configuration with organization context
169
+ * @param request - Setup intent request with customer ID and confirmation token
170
+ * @returns Setup intent result with payment method details
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * const result = await createSetupIntent(
175
+ * {
176
+ * apiUrl: 'https://api.agentpaid.io',
177
+ * apiKey: process.env.PAID_API_KEY,
178
+ * organizationId: 'org_123'
179
+ * },
180
+ * {
181
+ * customerId: 'cus_123',
182
+ * confirmationToken: 'seti_123_secret_456',
183
+ * returnUrl: 'https://example.com/return',
184
+ * metadata: { source: 'web' }
185
+ * }
186
+ * );
187
+ * ```
188
+ */
189
+ export function createSetupIntent(config, request) {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ const { customerId, confirmationToken, returnUrl, metadata } = request;
192
+ if (!customerId) {
193
+ throw new Error("customerId is required");
194
+ }
195
+ if (!confirmationToken) {
196
+ throw new Error("confirmationToken is required");
197
+ }
198
+ const data = yield paidApiFetch(config, `/api/organizations/${config.organizationId}/payments/setup-intents-external`, {
199
+ method: "POST",
200
+ body: Object.assign(Object.assign({ customerId,
201
+ confirmationToken }, (returnUrl && { returnUrl })), (metadata && { metadata })),
202
+ });
203
+ return {
204
+ setupIntent: data.setupIntent || data,
205
+ message: "Setup intent created successfully",
206
+ };
207
+ });
208
+ }
209
+ /**
210
+ * Create a framework-agnostic handler for setup intent creation
211
+ *
212
+ * This handler can be used with any framework adapter.
213
+ *
214
+ * @param defaultReturnUrl - Optional default return URL
215
+ * @returns Handler function
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * // Next.js API route
220
+ * import { createSetupIntentHandler } from '@paid-ai/paid-node/integrations';
221
+ *
222
+ * const handler = createSetupIntentHandler('https://myapp.com/billing');
223
+ *
224
+ * export async function POST(req: Request) {
225
+ * return handler(
226
+ * {
227
+ * body: await req.json(),
228
+ * headers: Object.fromEntries(req.headers),
229
+ * method: 'POST'
230
+ * },
231
+ * {
232
+ * json: (data, status = 200) => Response.json(data, { status }),
233
+ * error: (message, status) => Response.json({ error: message }, { status })
234
+ * }
235
+ * );
236
+ * }
237
+ * ```
238
+ */
239
+ export function createSetupIntentHandler(defaultReturnUrl) {
240
+ return createHandler((client, body, _params, organizationId) => __awaiter(this, void 0, void 0, function* () {
241
+ var _a, _b;
242
+ const apiKey = (_a = client._options) === null || _a === void 0 ? void 0 : _a.token;
243
+ const baseUrl = ((_b = client._options) === null || _b === void 0 ? void 0 : _b.baseUrl) || 'https://api.agentpaid.io/api/v1';
244
+ const apiUrl = baseUrl.replace('/api/v1', '');
245
+ const result = yield createSetupIntent({ apiUrl, apiKey, organizationId: organizationId }, {
246
+ customerId: body.customerId,
247
+ confirmationToken: body.confirmationToken,
248
+ returnUrl: body.returnUrl || defaultReturnUrl,
249
+ metadata: body.metadata,
250
+ });
251
+ return {
252
+ success: true,
253
+ data: result,
254
+ };
255
+ }), {
256
+ requiredFields: ['customerId', 'confirmationToken'],
257
+ requireOrganizationId: true,
258
+ });
259
+ }
@@ -61,3 +61,36 @@ export declare function createCustomer(client: PaidClient, data: Required<Omit<C
61
61
  * @returns Handler function
62
62
  */
63
63
  export declare function createCustomersHandler(): (request: import("../utils/base-handler.mjs").BaseRequestContext<CustomerData, Record<string, string>>, response: import("../utils/base-handler.mjs").BaseResponseContext, config?: import("../utils/base-handler.mjs").BaseHandlerConfig) => Promise<any>;
64
+ /**
65
+ * Get a customer by external ID
66
+ *
67
+ * @param client - PaidClient instance
68
+ * @param customerExternalId - Customer's external ID
69
+ * @returns Customer data
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const customer = await getCustomer(client, 'user-123');
74
+ * console.log(customer.name, customer.email);
75
+ * ```
76
+ */
77
+ export declare function getCustomer(client: PaidClient, customerExternalId: string): Promise<any>;
78
+ /**
79
+ * Create a framework-agnostic handler for fetching a customer by external ID
80
+ *
81
+ * This handler can be used with any framework adapter.
82
+ * The customer external ID should be provided either in params or query string.
83
+ *
84
+ * @returns Handler function
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * // In Next.js route: /api/customers/[customerExternalId]/route.ts
89
+ * import { createGetCustomerHandler } from '@paid-ai/paid-node/integrations';
90
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
91
+ *
92
+ * const handler = createGetCustomerHandler();
93
+ * export const GET = nextjsAdapter(handler);
94
+ * ```
95
+ */
96
+ export declare function createGetCustomerHandler(): (request: import("../utils/base-handler.mjs").BaseRequestContext<any, Record<string, string>>, response: import("../utils/base-handler.mjs").BaseResponseContext, config?: import("../utils/base-handler.mjs").BaseHandlerConfig) => Promise<any>;
@@ -143,3 +143,57 @@ export function createCustomersHandler() {
143
143
  return { success: true, data: customer };
144
144
  }), { requiredFields: ['externalId'] });
145
145
  }
146
+ /**
147
+ * Get a customer by external ID
148
+ *
149
+ * @param client - PaidClient instance
150
+ * @param customerExternalId - Customer's external ID
151
+ * @returns Customer data
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const customer = await getCustomer(client, 'user-123');
156
+ * console.log(customer.name, customer.email);
157
+ * ```
158
+ */
159
+ export function getCustomer(client, customerExternalId) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ const customer = yield client.customers.getByExternalId(customerExternalId);
162
+ return customer;
163
+ });
164
+ }
165
+ /**
166
+ * Create a framework-agnostic handler for fetching a customer by external ID
167
+ *
168
+ * This handler can be used with any framework adapter.
169
+ * The customer external ID should be provided either in params or query string.
170
+ *
171
+ * @returns Handler function
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * // In Next.js route: /api/customers/[customerExternalId]/route.ts
176
+ * import { createGetCustomerHandler } from '@paid-ai/paid-node/integrations';
177
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
178
+ *
179
+ * const handler = createGetCustomerHandler();
180
+ * export const GET = nextjsAdapter(handler);
181
+ * ```
182
+ */
183
+ export function createGetCustomerHandler() {
184
+ return createHandler((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
185
+ const customerExternalId = params === null || params === void 0 ? void 0 : params.customerExternalId;
186
+ if (!customerExternalId) {
187
+ return {
188
+ success: false,
189
+ error: "customerExternalId is required",
190
+ status: 400,
191
+ };
192
+ }
193
+ const customer = yield getCustomer(client, customerExternalId);
194
+ return { success: true, data: customer };
195
+ }), {
196
+ allowedMethods: ['GET'],
197
+ requireOrganizationId: false,
198
+ });
199
+ }
@@ -1,6 +1,6 @@
1
- export { createCustomer, createCustomerWithDefaults, createCustomersHandler, } from "./customers.mjs";
1
+ export { createCustomer, createCustomerWithDefaults, getCustomer, createGetCustomerHandler, createCustomersHandler, } from "./customers.mjs";
2
2
  export { createContact, createContactWithDefaults, createContactsHandler, } from "./contacts.mjs";
3
3
  export { createOrder, createOrderWithDefaults, createOrdersHandler, } from "./orders.mjs";
4
- export { payInvoice, createPayInvoiceHandler, type PayInvoiceConfig, type PayInvoiceRequest, type PayInvoiceResult, activateOrderSync, createActivateOrderSyncHandler, type ActivateOrderSyncConfig, type ActivateOrderSyncRequest, type ActivateOrderSyncResult, } from "./billing.mjs";
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.mjs";
5
5
  export { getCustomerInvoices, createCustomerInvoicesHandler, type CustomerInvoicesResult, } from "./invoices.mjs";
6
6
  export { provisionNewUser, createProvisioningHandler, } from "./provision-users.mjs";
@@ -1,6 +1,6 @@
1
- export { createCustomer, createCustomerWithDefaults, createCustomersHandler, } from "./customers.mjs";
1
+ export { createCustomer, createCustomerWithDefaults, getCustomer, createGetCustomerHandler, createCustomersHandler, } from "./customers.mjs";
2
2
  export { createContact, createContactWithDefaults, createContactsHandler, } from "./contacts.mjs";
3
3
  export { createOrder, createOrderWithDefaults, createOrdersHandler, } from "./orders.mjs";
4
- export { payInvoice, createPayInvoiceHandler, activateOrderSync, createActivateOrderSyncHandler, } from "./billing.mjs";
4
+ export { payInvoice, createPayInvoiceHandler, activateOrderSync, createActivateOrderSyncHandler, createSetupIntent, createSetupIntentHandler, } from "./billing.mjs";
5
5
  export { getCustomerInvoices, createCustomerInvoicesHandler, } from "./invoices.mjs";
6
6
  export { provisionNewUser, createProvisioningHandler, } from "./provision-users.mjs";
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.5.0-alpha1";
1
+ export declare const SDK_VERSION = "0.5.0-alpha2";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.5.0-alpha1";
1
+ export const SDK_VERSION = "0.5.0-alpha2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paid-ai/paid-node",
3
- "version": "0.5.0-alpha1",
3
+ "version": "0.5.0-alpha2",
4
4
  "private": false,
5
5
  "repository": "https://github.com/paid-ai/paid-node",
6
6
  "type": "commonjs",