@paid-ai/paid-node 0.5.0-alpha1 → 0.5.0-alpha3
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/integrations/adapters/expressjs/base-adapter.d.ts +17 -0
- package/dist/cjs/integrations/adapters/expressjs/base-adapter.js +71 -0
- package/dist/cjs/integrations/adapters/expressjs/index.d.ts +6 -0
- package/dist/cjs/integrations/adapters/expressjs/index.js +20 -0
- package/dist/cjs/integrations/adapters/expressjs/routes.d.ts +162 -0
- package/dist/cjs/integrations/adapters/expressjs/routes.js +269 -0
- package/dist/cjs/integrations/adapters/nestjs/index.d.ts +7 -0
- package/dist/cjs/integrations/adapters/nestjs/index.js +23 -0
- package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
- package/dist/cjs/integrations/adapters/nextjs/index.js +3 -1
- package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +51 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.js +54 -0
- package/dist/cjs/integrations/controllers/billing.d.ts +83 -0
- package/dist/cjs/integrations/controllers/billing.js +104 -1
- package/dist/cjs/integrations/controllers/customers.d.ts +33 -0
- package/dist/cjs/integrations/controllers/customers.js +56 -0
- package/dist/cjs/integrations/controllers/index.d.ts +2 -2
- package/dist/cjs/integrations/controllers/index.js +5 -1
- 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/integrations/adapters/expressjs/base-adapter.d.mts +17 -0
- package/dist/esm/integrations/adapters/expressjs/base-adapter.mjs +67 -0
- package/dist/esm/integrations/adapters/expressjs/index.d.mts +6 -0
- package/dist/esm/integrations/adapters/expressjs/index.mjs +6 -0
- package/dist/esm/integrations/adapters/expressjs/routes.d.mts +162 -0
- package/dist/esm/integrations/adapters/expressjs/routes.mjs +258 -0
- package/dist/esm/integrations/adapters/nestjs/index.d.mts +7 -0
- package/dist/esm/integrations/adapters/nestjs/index.mjs +7 -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 +51 -0
- package/dist/esm/integrations/adapters/nextjs/routes.mjs +54 -2
- package/dist/esm/integrations/controllers/billing.d.mts +83 -0
- package/dist/esm/integrations/controllers/billing.mjs +102 -1
- package/dist/esm/integrations/controllers/customers.d.mts +33 -0
- package/dist/esm/integrations/controllers/customers.mjs +54 -0
- package/dist/esm/integrations/controllers/index.d.mts +2 -2
- package/dist/esm/integrations/controllers/index.mjs +2 -2
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +30 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS route helpers for Paid SDK
|
|
3
|
+
* These functions create handlers compatible with ExpressJS controllers
|
|
4
|
+
*/
|
|
5
|
+
import { Request, Response } from "express";
|
|
6
|
+
import { BaseHandlerConfig } from "../../utils/base-handler.mjs";
|
|
7
|
+
import { OrderOptions } from "../../types.mjs";
|
|
8
|
+
export interface ActivateOrderSyncRouteConfig extends BaseHandlerConfig {
|
|
9
|
+
defaultReturnUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create an Express handler for synchronous order activation
|
|
13
|
+
*
|
|
14
|
+
* Use this in your Express app to handle order activation with payment.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import express from 'express';
|
|
19
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/express';
|
|
20
|
+
*
|
|
21
|
+
* const app = express();
|
|
22
|
+
* const activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
23
|
+
*
|
|
24
|
+
* app.post('/paid/payments/activate-order-sync', activateOrderSyncHandler);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example With NestJS
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { Controller, Post, Req, Res } from '@nestjs/common';
|
|
30
|
+
* import { Request, Response } from 'express';
|
|
31
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nestjs';
|
|
32
|
+
*
|
|
33
|
+
* @Controller('paid/payments')
|
|
34
|
+
* export class PaymentsController {
|
|
35
|
+
* private activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
36
|
+
*
|
|
37
|
+
* @Post('activate-order-sync')
|
|
38
|
+
* async activateOrderSync(@Req() req: Request, @Res() res: Response) {
|
|
39
|
+
* return this.activateOrderSyncHandler(req, res);
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createActivateOrderSyncRoute(config?: ActivateOrderSyncRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* Create an Express handler for contact creation
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import express from 'express';
|
|
51
|
+
* import { createContactsRoute } from '@paid-ai/paid-node/integrations/express';
|
|
52
|
+
*
|
|
53
|
+
* const app = express();
|
|
54
|
+
* app.post('/paid/contacts', createContactsRoute());
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function createContactsRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
58
|
+
/**
|
|
59
|
+
* Create an Express handler for fetching customer invoices
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import express from 'express';
|
|
64
|
+
* import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/express';
|
|
65
|
+
*
|
|
66
|
+
* const app = express();
|
|
67
|
+
* app.get('/paid/customers/:customerExternalId/invoices', createCustomerInvoicesRoute());
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function createCustomerInvoicesRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
71
|
+
/**
|
|
72
|
+
* Create an Express handler for fetching a customer by external ID
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import express from 'express';
|
|
77
|
+
* import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/express';
|
|
78
|
+
*
|
|
79
|
+
* const app = express();
|
|
80
|
+
* app.get('/paid/customers/:customerExternalId', createGetCustomerRoute());
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function createGetCustomerRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
84
|
+
/**
|
|
85
|
+
* Create an Express handler for customer creation
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import express from 'express';
|
|
90
|
+
* import { createCustomersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
91
|
+
*
|
|
92
|
+
* const app = express();
|
|
93
|
+
* app.post('/paid/customers', createCustomersRoute());
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function createCustomersRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
97
|
+
export interface OrdersRouteConfig extends BaseHandlerConfig {
|
|
98
|
+
helperOptions?: OrderOptions;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create an Express handler for order creation
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import express from 'express';
|
|
106
|
+
* import { createOrdersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
107
|
+
*
|
|
108
|
+
* const app = express();
|
|
109
|
+
* app.post('/paid/orders', createOrdersRoute({ helperOptions: { autoActivate: true } }));
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function createOrdersRoute(config?: OrdersRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
113
|
+
/**
|
|
114
|
+
* Create an Express handler for invoice payment
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import express from 'express';
|
|
119
|
+
* import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/express';
|
|
120
|
+
*
|
|
121
|
+
* const app = express();
|
|
122
|
+
* app.post('/paid/invoices/:invoiceId/pay', createPayInvoiceRoute());
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function createPayInvoiceRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
|
|
126
|
+
export interface ProvisioningRouteConfig extends BaseHandlerConfig {
|
|
127
|
+
defaultAgentExternalId?: string;
|
|
128
|
+
orderOptions?: OrderOptions;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Create an Express handler for user provisioning
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* import express from 'express';
|
|
136
|
+
* import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/express';
|
|
137
|
+
*
|
|
138
|
+
* const app = express();
|
|
139
|
+
* app.post('/paid/provision', createProvisioningRoute({
|
|
140
|
+
* defaultAgentExternalId: process.env.PAID_AGENT_ID
|
|
141
|
+
* }));
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function createProvisioningRoute(config?: ProvisioningRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
145
|
+
export interface SetupIntentRouteConfig extends BaseHandlerConfig {
|
|
146
|
+
defaultReturnUrl?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Create an Express handler for setup intent creation
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* import express from 'express';
|
|
154
|
+
* import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/express';
|
|
155
|
+
*
|
|
156
|
+
* const app = express();
|
|
157
|
+
* app.post('/paid/payments/setup-intent', createSetupIntentRoute({
|
|
158
|
+
* defaultReturnUrl: process.env.APP_URL + '/billing'
|
|
159
|
+
* }));
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export declare function createSetupIntentRoute(config?: SetupIntentRouteConfig): (req: Request, res: Response) => Promise<any>;
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressJS route helpers for Paid SDK
|
|
3
|
+
* These functions create handlers compatible with ExpressJS controllers
|
|
4
|
+
*/
|
|
5
|
+
import { createExpressJSResponseContext } from "./base-adapter.mjs";
|
|
6
|
+
import { createContactsHandler } from "../../controllers/contacts.mjs";
|
|
7
|
+
import { createCustomerInvoicesHandler } from "../../controllers/invoices.mjs";
|
|
8
|
+
import { createCustomersHandler, createGetCustomerHandler } from "../../controllers/customers.mjs";
|
|
9
|
+
import { createOrdersHandler } from "../../controllers/orders.mjs";
|
|
10
|
+
import { createProvisioningHandler } from "../../controllers/provision-users.mjs";
|
|
11
|
+
import { createActivateOrderSyncHandler, createPayInvoiceHandler, createSetupIntentHandler, } from "../../controllers/billing.mjs";
|
|
12
|
+
/**
|
|
13
|
+
* Helper to extract headers from Express Request
|
|
14
|
+
*/
|
|
15
|
+
function extractHeaders(req) {
|
|
16
|
+
const headers = {};
|
|
17
|
+
Object.entries(req.headers).forEach(([key, value]) => {
|
|
18
|
+
if (typeof value === "string") {
|
|
19
|
+
headers[key] = value;
|
|
20
|
+
}
|
|
21
|
+
else if (Array.isArray(value)) {
|
|
22
|
+
headers[key] = value.join(", ");
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return headers;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create an Express handler for synchronous order activation
|
|
29
|
+
*
|
|
30
|
+
* Use this in your Express app to handle order activation with payment.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import express from 'express';
|
|
35
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/express';
|
|
36
|
+
*
|
|
37
|
+
* const app = express();
|
|
38
|
+
* const activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
39
|
+
*
|
|
40
|
+
* app.post('/paid/payments/activate-order-sync', activateOrderSyncHandler);
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example With NestJS
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { Controller, Post, Req, Res } from '@nestjs/common';
|
|
46
|
+
* import { Request, Response } from 'express';
|
|
47
|
+
* import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nestjs';
|
|
48
|
+
*
|
|
49
|
+
* @Controller('paid/payments')
|
|
50
|
+
* export class PaymentsController {
|
|
51
|
+
* private activateOrderSyncHandler = createActivateOrderSyncRoute();
|
|
52
|
+
*
|
|
53
|
+
* @Post('activate-order-sync')
|
|
54
|
+
* async activateOrderSync(@Req() req: Request, @Res() res: Response) {
|
|
55
|
+
* return this.activateOrderSyncHandler(req, res);
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function createActivateOrderSyncRoute(config = {}) {
|
|
61
|
+
const handler = createActivateOrderSyncHandler(config.defaultReturnUrl);
|
|
62
|
+
return (req, res) => {
|
|
63
|
+
return handler({
|
|
64
|
+
body: req.body,
|
|
65
|
+
headers: extractHeaders(req),
|
|
66
|
+
method: "POST",
|
|
67
|
+
params: req.params,
|
|
68
|
+
}, createExpressJSResponseContext(res), config);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create an Express handler for contact creation
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import express from 'express';
|
|
77
|
+
* import { createContactsRoute } from '@paid-ai/paid-node/integrations/express';
|
|
78
|
+
*
|
|
79
|
+
* const app = express();
|
|
80
|
+
* app.post('/paid/contacts', createContactsRoute());
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export function createContactsRoute(config = {}) {
|
|
84
|
+
const handler = createContactsHandler();
|
|
85
|
+
return (req, res) => {
|
|
86
|
+
return handler({
|
|
87
|
+
body: req.body,
|
|
88
|
+
headers: extractHeaders(req),
|
|
89
|
+
method: "POST",
|
|
90
|
+
params: req.params,
|
|
91
|
+
}, createExpressJSResponseContext(res), config);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create an Express handler for fetching customer invoices
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import express from 'express';
|
|
100
|
+
* import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/express';
|
|
101
|
+
*
|
|
102
|
+
* const app = express();
|
|
103
|
+
* app.get('/paid/customers/:customerExternalId/invoices', createCustomerInvoicesRoute());
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export function createCustomerInvoicesRoute(config = {}) {
|
|
107
|
+
const handler = createCustomerInvoicesHandler();
|
|
108
|
+
return (req, res) => {
|
|
109
|
+
return handler({
|
|
110
|
+
body: req.body,
|
|
111
|
+
headers: extractHeaders(req),
|
|
112
|
+
method: "GET",
|
|
113
|
+
params: req.params,
|
|
114
|
+
}, createExpressJSResponseContext(res), config);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Create an Express handler for fetching a customer by external ID
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* import express from 'express';
|
|
123
|
+
* import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/express';
|
|
124
|
+
*
|
|
125
|
+
* const app = express();
|
|
126
|
+
* app.get('/paid/customers/:customerExternalId', createGetCustomerRoute());
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export function createGetCustomerRoute(config = {}) {
|
|
130
|
+
const handler = createGetCustomerHandler();
|
|
131
|
+
return (req, res) => {
|
|
132
|
+
return handler({
|
|
133
|
+
body: req.body,
|
|
134
|
+
headers: extractHeaders(req),
|
|
135
|
+
method: "GET",
|
|
136
|
+
params: req.params,
|
|
137
|
+
}, createExpressJSResponseContext(res), config);
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create an Express handler for customer creation
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import express from 'express';
|
|
146
|
+
* import { createCustomersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
147
|
+
*
|
|
148
|
+
* const app = express();
|
|
149
|
+
* app.post('/paid/customers', createCustomersRoute());
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export function createCustomersRoute(config = {}) {
|
|
153
|
+
const handler = createCustomersHandler();
|
|
154
|
+
return (req, res) => {
|
|
155
|
+
return handler({
|
|
156
|
+
body: req.body,
|
|
157
|
+
headers: extractHeaders(req),
|
|
158
|
+
method: "POST",
|
|
159
|
+
params: req.params,
|
|
160
|
+
}, createExpressJSResponseContext(res), config);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Create an Express handler for order creation
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* import express from 'express';
|
|
169
|
+
* import { createOrdersRoute } from '@paid-ai/paid-node/integrations/express';
|
|
170
|
+
*
|
|
171
|
+
* const app = express();
|
|
172
|
+
* app.post('/paid/orders', createOrdersRoute({ helperOptions: { autoActivate: true } }));
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export function createOrdersRoute(config = {}) {
|
|
176
|
+
const handler = createOrdersHandler(config.helperOptions);
|
|
177
|
+
return (req, res) => {
|
|
178
|
+
return handler({
|
|
179
|
+
body: req.body,
|
|
180
|
+
headers: extractHeaders(req),
|
|
181
|
+
method: "POST",
|
|
182
|
+
params: req.params,
|
|
183
|
+
}, createExpressJSResponseContext(res), config);
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Create an Express handler for invoice payment
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* import express from 'express';
|
|
192
|
+
* import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/express';
|
|
193
|
+
*
|
|
194
|
+
* const app = express();
|
|
195
|
+
* app.post('/paid/invoices/:invoiceId/pay', createPayInvoiceRoute());
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export function createPayInvoiceRoute(config = {}) {
|
|
199
|
+
const handler = createPayInvoiceHandler();
|
|
200
|
+
return (req, res) => {
|
|
201
|
+
return handler({
|
|
202
|
+
body: req.body,
|
|
203
|
+
headers: extractHeaders(req),
|
|
204
|
+
method: "POST",
|
|
205
|
+
params: req.params,
|
|
206
|
+
}, createExpressJSResponseContext(res), config);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Create an Express handler for user provisioning
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* import express from 'express';
|
|
215
|
+
* import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/express';
|
|
216
|
+
*
|
|
217
|
+
* const app = express();
|
|
218
|
+
* app.post('/paid/provision', createProvisioningRoute({
|
|
219
|
+
* defaultAgentExternalId: process.env.PAID_AGENT_ID
|
|
220
|
+
* }));
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
export function createProvisioningRoute(config = {}) {
|
|
224
|
+
const handler = createProvisioningHandler(config.orderOptions, config.defaultAgentExternalId);
|
|
225
|
+
return (req, res) => {
|
|
226
|
+
return handler({
|
|
227
|
+
body: req.body,
|
|
228
|
+
headers: extractHeaders(req),
|
|
229
|
+
method: "POST",
|
|
230
|
+
params: req.params,
|
|
231
|
+
}, createExpressJSResponseContext(res), config);
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Create an Express handler for setup intent creation
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* import express from 'express';
|
|
240
|
+
* import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/express';
|
|
241
|
+
*
|
|
242
|
+
* const app = express();
|
|
243
|
+
* app.post('/paid/payments/setup-intent', createSetupIntentRoute({
|
|
244
|
+
* defaultReturnUrl: process.env.APP_URL + '/billing'
|
|
245
|
+
* }));
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
export function createSetupIntentRoute(config = {}) {
|
|
249
|
+
const handler = createSetupIntentHandler(config.defaultReturnUrl);
|
|
250
|
+
return (req, res) => {
|
|
251
|
+
return handler({
|
|
252
|
+
body: req.body,
|
|
253
|
+
headers: extractHeaders(req),
|
|
254
|
+
method: "POST",
|
|
255
|
+
params: req.params,
|
|
256
|
+
}, createExpressJSResponseContext(res), config);
|
|
257
|
+
};
|
|
258
|
+
}
|
|
@@ -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 {};
|