@solvapay/server 1.0.0-preview.2 → 1.0.0-preview.20
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/LICENSE.md +21 -0
- package/README.md +66 -27
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/edge.d.ts +1423 -261
- package/dist/edge.js +889 -227
- package/dist/{esm-5GYCIXIY.js → esm-UW7WCMEK.js} +1 -1
- package/dist/index.cjs +901 -223
- package/dist/index.d.cts +1466 -261
- package/dist/index.d.ts +1466 -261
- package/dist/index.js +894 -228
- package/package.json +13 -4
- package/dist/chunk-R5U7XKVJ.js +0 -16
package/dist/edge.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
interface components {
|
|
2
2
|
schemas: {
|
|
3
|
+
UpdateProviderDto: Record<string, never>;
|
|
3
4
|
CreateSecretKey: Record<string, never>;
|
|
4
5
|
CheckName: Record<string, never>;
|
|
5
6
|
CreateAdminAgent: Record<string, never>;
|
|
6
7
|
UpdateAdminAgent: Record<string, never>;
|
|
8
|
+
Agent: Record<string, never>;
|
|
9
|
+
CreateAgentRequest: Record<string, never>;
|
|
10
|
+
UpdateAgentRequest: Record<string, never>;
|
|
7
11
|
Signup: Record<string, never>;
|
|
8
12
|
AuthResponse: Record<string, never>;
|
|
9
13
|
Login: Record<string, never>;
|
|
@@ -16,291 +20,660 @@ interface components {
|
|
|
16
20
|
UpdatePreferences: Record<string, never>;
|
|
17
21
|
ChangePassword: Record<string, never>;
|
|
18
22
|
RequestEmailChange: Record<string, never>;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
CreateProductRequest: {
|
|
24
|
+
/**
|
|
25
|
+
* Product name
|
|
26
|
+
* @example AI Writing Assistant
|
|
27
|
+
*/
|
|
28
|
+
name: string;
|
|
29
|
+
/**
|
|
30
|
+
* Product description
|
|
31
|
+
* @example AI-powered writing tool
|
|
32
|
+
*/
|
|
33
|
+
description?: string;
|
|
34
|
+
/** URL to the product image */
|
|
35
|
+
imageUrl?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Free-form product type defined by the provider
|
|
38
|
+
* @example Coding Assistant
|
|
39
|
+
*/
|
|
40
|
+
productType?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Whether this product uses MCP Pay proxy
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
isMcpPay: boolean;
|
|
46
|
+
/** Product-specific configuration */
|
|
47
|
+
config?: Record<string, never>;
|
|
48
|
+
/** Arbitrary key-value metadata */
|
|
49
|
+
metadata?: Record<string, never>;
|
|
50
|
+
};
|
|
51
|
+
SdkProductResponse: {
|
|
52
|
+
/**
|
|
53
|
+
* Product ID
|
|
54
|
+
* @example 507f1f77bcf86cd799439011
|
|
55
|
+
*/
|
|
56
|
+
id: string;
|
|
57
|
+
/**
|
|
58
|
+
* Product reference
|
|
59
|
+
* @example prd_1A2B3C4D
|
|
60
|
+
*/
|
|
61
|
+
reference: string;
|
|
62
|
+
/**
|
|
63
|
+
* Product name
|
|
64
|
+
* @example AI Writing Assistant
|
|
65
|
+
*/
|
|
66
|
+
name: string;
|
|
67
|
+
/** Product description */
|
|
68
|
+
description?: string;
|
|
69
|
+
/** URL to the product image */
|
|
70
|
+
imageUrl?: string;
|
|
71
|
+
/** Free-form product type */
|
|
72
|
+
productType?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Product status
|
|
75
|
+
* @example active
|
|
76
|
+
*/
|
|
77
|
+
status: string;
|
|
78
|
+
/**
|
|
79
|
+
* Product balance in cents
|
|
80
|
+
* @example 0
|
|
81
|
+
*/
|
|
82
|
+
balance: number;
|
|
83
|
+
/**
|
|
84
|
+
* Total number of transactions
|
|
85
|
+
* @example 0
|
|
86
|
+
*/
|
|
87
|
+
totalTransactions: number;
|
|
88
|
+
/**
|
|
89
|
+
* Whether this product uses MCP Pay proxy
|
|
90
|
+
* @example false
|
|
91
|
+
*/
|
|
92
|
+
isMcpPay: boolean;
|
|
93
|
+
/** Product-specific configuration */
|
|
94
|
+
config?: Record<string, never>;
|
|
95
|
+
/** Arbitrary key-value metadata */
|
|
96
|
+
metadata?: Record<string, never>;
|
|
97
|
+
/** Creation timestamp */
|
|
98
|
+
createdAt: string;
|
|
99
|
+
/** Last update timestamp */
|
|
100
|
+
updatedAt: string;
|
|
101
|
+
/** Plans associated with this product */
|
|
102
|
+
plans?: string[];
|
|
103
|
+
};
|
|
104
|
+
UpdateProductRequest: {
|
|
105
|
+
/** Product name */
|
|
106
|
+
name?: string;
|
|
107
|
+
/** Product description */
|
|
108
|
+
description?: string;
|
|
109
|
+
/** URL to the product image */
|
|
110
|
+
imageUrl?: string;
|
|
111
|
+
/** Free-form product type defined by the provider */
|
|
112
|
+
productType?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Product status
|
|
115
|
+
* @enum {string}
|
|
116
|
+
*/
|
|
117
|
+
status?: "active" | "inactive" | "suspended";
|
|
118
|
+
/** Product-specific configuration */
|
|
119
|
+
config?: Record<string, never>;
|
|
120
|
+
/** Arbitrary key-value metadata */
|
|
121
|
+
metadata?: Record<string, never>;
|
|
122
|
+
};
|
|
123
|
+
CreatePlanRequest: {
|
|
124
|
+
/**
|
|
125
|
+
* Plan name
|
|
126
|
+
* @example Basic Plan
|
|
127
|
+
*/
|
|
128
|
+
name: string;
|
|
129
|
+
/**
|
|
130
|
+
* Plan description
|
|
131
|
+
* @example Basic recurring plan with monthly billing
|
|
132
|
+
*/
|
|
133
|
+
description?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Plan type
|
|
136
|
+
* @example recurring
|
|
137
|
+
* @enum {string}
|
|
138
|
+
*/
|
|
139
|
+
type?: "recurring" | "usage-based" | "hybrid" | "one-time";
|
|
140
|
+
/**
|
|
141
|
+
* Billing cycle (required for recurring/hybrid, optional for post-paid usage-based)
|
|
142
|
+
* @example monthly
|
|
143
|
+
* @enum {string}
|
|
144
|
+
*/
|
|
145
|
+
billingCycle?: "weekly" | "monthly" | "quarterly" | "yearly" | "custom";
|
|
146
|
+
/**
|
|
147
|
+
* Plan price
|
|
148
|
+
* @example 29.99
|
|
149
|
+
*/
|
|
150
|
+
price?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Currency code (ISO 4217)
|
|
153
|
+
* @example USD
|
|
154
|
+
* @enum {string}
|
|
155
|
+
*/
|
|
156
|
+
currency?: "USD" | "EUR" | "GBP" | "SEK" | "NOK" | "DKK" | "CAD" | "AUD" | "JPY" | "CHF" | "PLN" | "CZK" | "HUF" | "RON" | "BGN" | "HRK" | "RSD" | "MKD" | "BAM" | "ALL" | "ISK" | "TRY" | "RUB" | "UAH" | "BYN" | "MDL" | "GEL" | "AMD" | "AZN" | "KZT" | "KGS" | "TJS" | "TMT" | "UZS" | "MNT" | "CNY" | "KRW" | "THB" | "VND" | "IDR" | "MYR" | "SGD" | "PHP" | "INR" | "PKR" | "BDT" | "LKR" | "NPR" | "AFN" | "IRR" | "IQD" | "JOD" | "KWD" | "LBP" | "OMR" | "QAR" | "SAR" | "SYP" | "AED" | "YER" | "ILS" | "EGP" | "MAD" | "TND" | "DZD" | "LYD" | "SDG" | "ETB" | "KES" | "TZS" | "UGX" | "RWF" | "BIF" | "DJF" | "SOS" | "ERN" | "SLL" | "GMD" | "GNF" | "CVE" | "STN" | "AOA" | "ZAR" | "BWP" | "SZL" | "LSL" | "NAD" | "ZMW" | "ZWL" | "MZN" | "MWK" | "MGA" | "MUR" | "SCR" | "KMF" | "MVR";
|
|
157
|
+
/**
|
|
158
|
+
* Setup fee
|
|
159
|
+
* @example 0
|
|
160
|
+
*/
|
|
161
|
+
setupFee?: number;
|
|
162
|
+
/**
|
|
163
|
+
* Trial days
|
|
164
|
+
* @example 7
|
|
165
|
+
*/
|
|
166
|
+
trialDays?: number;
|
|
167
|
+
/**
|
|
168
|
+
* Number of free units included
|
|
169
|
+
* @example 100
|
|
170
|
+
*/
|
|
171
|
+
freeUnits?: number;
|
|
172
|
+
/**
|
|
173
|
+
* Billing model for usage-based plans
|
|
174
|
+
* @example pre-paid
|
|
175
|
+
* @enum {string}
|
|
176
|
+
*/
|
|
177
|
+
billingModel?: "pre-paid" | "post-paid";
|
|
178
|
+
/**
|
|
179
|
+
* Price per unit for usage-based plans
|
|
180
|
+
* @example 0.01
|
|
181
|
+
*/
|
|
182
|
+
pricePerUnit?: number;
|
|
183
|
+
/**
|
|
184
|
+
* Unit name for usage-based plans
|
|
185
|
+
* @example request
|
|
186
|
+
*/
|
|
187
|
+
unit?: string;
|
|
188
|
+
/**
|
|
189
|
+
* Usage quota for usage-based plans
|
|
190
|
+
* @example 10000
|
|
191
|
+
*/
|
|
192
|
+
quota?: number;
|
|
193
|
+
/**
|
|
194
|
+
* Whether to rollover unused units
|
|
195
|
+
* @example false
|
|
196
|
+
*/
|
|
197
|
+
rolloverUnusedUnits?: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Base price for hybrid plans
|
|
200
|
+
* @example 29.99
|
|
201
|
+
*/
|
|
202
|
+
basePrice?: number;
|
|
203
|
+
/**
|
|
204
|
+
* Usage limits (shape varies by plan type)
|
|
205
|
+
* @example {
|
|
206
|
+
* "maxTransactions": 1000
|
|
207
|
+
* }
|
|
208
|
+
*/
|
|
209
|
+
limits?: Record<string, never>;
|
|
210
|
+
/**
|
|
211
|
+
* Plan features (generic key/value, shape is provider-defined)
|
|
212
|
+
* @example {
|
|
213
|
+
* "apiAccess": true,
|
|
214
|
+
* "prioritySupport": false
|
|
215
|
+
* }
|
|
216
|
+
*/
|
|
217
|
+
features?: Record<string, never>;
|
|
218
|
+
/**
|
|
219
|
+
* Whether this is a free tier plan
|
|
220
|
+
* @example false
|
|
221
|
+
*/
|
|
222
|
+
isFreeTier?: boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Whether payment is required
|
|
225
|
+
* @example true
|
|
226
|
+
*/
|
|
227
|
+
requiresPayment?: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Plan status
|
|
230
|
+
* @example active
|
|
231
|
+
* @enum {string}
|
|
232
|
+
*/
|
|
233
|
+
status?: "active" | "inactive" | "archived";
|
|
234
|
+
/**
|
|
235
|
+
* Maximum number of active users
|
|
236
|
+
* @example 10
|
|
237
|
+
*/
|
|
238
|
+
maxActiveUsers?: number;
|
|
239
|
+
/**
|
|
240
|
+
* Access expiry in days
|
|
241
|
+
* @example 30
|
|
242
|
+
*/
|
|
243
|
+
accessExpiryDays?: number;
|
|
244
|
+
/** Additional metadata */
|
|
245
|
+
metadata?: Record<string, never>;
|
|
246
|
+
/**
|
|
247
|
+
* Whether this is the default plan
|
|
248
|
+
* @example false
|
|
249
|
+
*/
|
|
250
|
+
default?: boolean;
|
|
251
|
+
};
|
|
22
252
|
UpdatePlanRequest: Record<string, never>;
|
|
23
|
-
|
|
24
|
-
ExecuteMultipleQueries: Record<string, never>;
|
|
25
|
-
CheckLimitRequest: {
|
|
253
|
+
CreateCheckoutSessionRequest: {
|
|
26
254
|
/**
|
|
27
|
-
*
|
|
255
|
+
* Customer reference
|
|
28
256
|
* @example cus_3c4d5e6f7g8h
|
|
29
257
|
*/
|
|
258
|
+
customerReference: string;
|
|
259
|
+
/**
|
|
260
|
+
* Plan reference (optional)
|
|
261
|
+
* @example pln_2b3c4d5e6f7g
|
|
262
|
+
*/
|
|
263
|
+
planRef?: string;
|
|
264
|
+
/**
|
|
265
|
+
* Product reference (required)
|
|
266
|
+
* @example prd_1a2b3c4d5e6f
|
|
267
|
+
*/
|
|
268
|
+
productRef: string;
|
|
269
|
+
};
|
|
270
|
+
CheckoutSessionResponse: {
|
|
271
|
+
/**
|
|
272
|
+
* Checkout session ID
|
|
273
|
+
* @example 507f1f77bcf86cd799439011
|
|
274
|
+
*/
|
|
275
|
+
id: string;
|
|
276
|
+
/**
|
|
277
|
+
* Public session ID used in checkout URL
|
|
278
|
+
* @example a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
|
|
279
|
+
*/
|
|
280
|
+
sessionId: string;
|
|
281
|
+
/**
|
|
282
|
+
* Amount in cents
|
|
283
|
+
* @example 2999
|
|
284
|
+
*/
|
|
285
|
+
amount: number;
|
|
286
|
+
/**
|
|
287
|
+
* Currency code
|
|
288
|
+
* @example USD
|
|
289
|
+
*/
|
|
290
|
+
currency: string;
|
|
291
|
+
/**
|
|
292
|
+
* Session status
|
|
293
|
+
* @example active
|
|
294
|
+
*/
|
|
295
|
+
status: string;
|
|
296
|
+
/**
|
|
297
|
+
* Checkout URL to open the checkout page
|
|
298
|
+
* @example https://solvapay.com/customer/checkout?id=a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
|
|
299
|
+
*/
|
|
300
|
+
checkoutUrl: string;
|
|
301
|
+
};
|
|
302
|
+
CancelRenewalRequest: Record<string, never>;
|
|
303
|
+
UpdateConnectedAccount: Record<string, never>;
|
|
304
|
+
CancelPurchaseRequest: {
|
|
305
|
+
/** Reason for cancellation */
|
|
306
|
+
reason?: string;
|
|
307
|
+
};
|
|
308
|
+
CheckLimitRequest: {
|
|
309
|
+
/**
|
|
310
|
+
* Customer reference identifier
|
|
311
|
+
* @example cus_3C4D5E6F
|
|
312
|
+
*/
|
|
30
313
|
customerRef: string;
|
|
31
314
|
/**
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
315
|
+
* Product reference identifier
|
|
316
|
+
* @example prd_1A2B3C4D
|
|
34
317
|
*/
|
|
35
|
-
|
|
318
|
+
productRef: string;
|
|
36
319
|
};
|
|
37
320
|
LimitResponse: {
|
|
38
321
|
/**
|
|
39
|
-
*
|
|
322
|
+
* Whether the customer is within their usage limits
|
|
40
323
|
* @example true
|
|
41
324
|
*/
|
|
42
325
|
withinLimits: boolean;
|
|
43
326
|
/**
|
|
44
|
-
*
|
|
327
|
+
* Remaining usage units before hitting the limit
|
|
45
328
|
* @example 997
|
|
46
329
|
*/
|
|
47
330
|
remaining: number;
|
|
48
331
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
332
|
+
* Checkout session ID if payment is required
|
|
333
|
+
* @example e3f1c2d4b6a89f001122334455667788
|
|
334
|
+
*/
|
|
335
|
+
checkoutSessionId?: string;
|
|
336
|
+
/**
|
|
337
|
+
* Checkout URL if payment is required
|
|
338
|
+
* @example https://solvapay.com/customer/checkout?id=e3f1c2d4b6a89f001122334455667788
|
|
51
339
|
*/
|
|
52
340
|
checkoutUrl?: string;
|
|
53
341
|
};
|
|
54
|
-
|
|
342
|
+
CreateCustomerSessionRequest: {
|
|
55
343
|
/**
|
|
56
|
-
*
|
|
344
|
+
* Customer reference identifier
|
|
57
345
|
* @example cus_3c4d5e6f7g8h
|
|
58
346
|
*/
|
|
59
347
|
customerRef: string;
|
|
348
|
+
};
|
|
349
|
+
CustomerSessionResponse: {
|
|
60
350
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
*/
|
|
64
|
-
agentRef: string;
|
|
65
|
-
/**
|
|
66
|
-
* @description Outcome of the action
|
|
67
|
-
* @example success
|
|
68
|
-
* @enum {string}
|
|
69
|
-
*/
|
|
70
|
-
outcome: "success" | "paywall" | "fail";
|
|
71
|
-
/**
|
|
72
|
-
* @description Optional action identifier
|
|
73
|
-
* @example generate_text
|
|
351
|
+
* Customer session ID
|
|
352
|
+
* @example 507f1f77bcf86cd799439011
|
|
74
353
|
*/
|
|
75
|
-
|
|
354
|
+
id: string;
|
|
76
355
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
356
|
+
* Public session ID used in customer URL
|
|
357
|
+
* @example e3f1c2d4b6a89f001122334455667788
|
|
79
358
|
*/
|
|
80
|
-
|
|
359
|
+
sessionId: string;
|
|
81
360
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
361
|
+
* Session status
|
|
362
|
+
* @example active
|
|
84
363
|
*/
|
|
85
|
-
|
|
364
|
+
status: string;
|
|
86
365
|
/**
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
366
|
+
* Customer URL to open the customer page
|
|
367
|
+
* @example https://solvapay.com/customer/manage?id=e3f1c2d4b6a89f001122334455667788
|
|
89
368
|
*/
|
|
90
|
-
|
|
369
|
+
customerUrl: string;
|
|
91
370
|
};
|
|
92
371
|
CreateCustomerRequest: {
|
|
93
372
|
/**
|
|
94
|
-
*
|
|
373
|
+
* Customer email address (required)
|
|
95
374
|
* @example customer@example.com
|
|
96
375
|
*/
|
|
97
376
|
email: string;
|
|
98
377
|
/**
|
|
99
|
-
*
|
|
378
|
+
* Customer full name (optional)
|
|
100
379
|
* @example John Doe
|
|
101
380
|
*/
|
|
102
381
|
name?: string;
|
|
382
|
+
/**
|
|
383
|
+
* External reference ID from your auth system to map this customer to an auth user (optional)
|
|
384
|
+
* @example auth_user_12345
|
|
385
|
+
*/
|
|
386
|
+
externalRef?: string;
|
|
103
387
|
};
|
|
104
|
-
|
|
388
|
+
PurchaseInfo: {
|
|
105
389
|
/**
|
|
106
|
-
*
|
|
390
|
+
* Purchase reference
|
|
107
391
|
* @example sub_abc123
|
|
108
392
|
*/
|
|
109
393
|
reference: string;
|
|
110
394
|
/**
|
|
111
|
-
*
|
|
395
|
+
* Plan name
|
|
112
396
|
* @example Pro Plan
|
|
113
397
|
*/
|
|
114
398
|
planName: string;
|
|
115
399
|
/**
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
400
|
+
* Product reference
|
|
401
|
+
* @example prd_abc123
|
|
118
402
|
*/
|
|
119
|
-
|
|
403
|
+
productReference?: string;
|
|
120
404
|
/**
|
|
121
|
-
*
|
|
405
|
+
* Purchase status
|
|
122
406
|
* @example active
|
|
123
407
|
*/
|
|
124
408
|
status: string;
|
|
125
409
|
/**
|
|
126
|
-
*
|
|
410
|
+
* Start date
|
|
127
411
|
* @example 2025-10-27T10:00:00Z
|
|
128
412
|
*/
|
|
129
413
|
startDate: string;
|
|
130
|
-
};
|
|
131
|
-
CustomerResponse: {
|
|
132
414
|
/**
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
415
|
+
* Amount paid in original currency (in cents)
|
|
416
|
+
* @example 9900
|
|
135
417
|
*/
|
|
136
|
-
|
|
418
|
+
amount: number;
|
|
137
419
|
/**
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
420
|
+
* Currency code
|
|
421
|
+
* @example USD
|
|
140
422
|
*/
|
|
141
|
-
|
|
423
|
+
currency: string;
|
|
142
424
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
425
|
+
* End date of purchase
|
|
426
|
+
* @example 2025-11-27T10:00:00Z
|
|
145
427
|
*/
|
|
146
|
-
|
|
147
|
-
/** @description Active subscriptions */
|
|
148
|
-
subscriptions?: components["schemas"]["SubscriptionInfo"][];
|
|
149
|
-
};
|
|
150
|
-
Agent: Record<string, never>;
|
|
151
|
-
CreateAgentRequest: Record<string, never>;
|
|
152
|
-
UpdateAgentRequest: Record<string, never>;
|
|
153
|
-
BasePlan: Record<string, never>;
|
|
154
|
-
SubscriptionResponse: {
|
|
428
|
+
endDate?: string;
|
|
155
429
|
/**
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
430
|
+
* When purchase was cancelled
|
|
431
|
+
* @example 2025-10-28T10:00:00Z
|
|
158
432
|
*/
|
|
159
|
-
|
|
433
|
+
cancelledAt?: string;
|
|
160
434
|
/**
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
435
|
+
* Reason for cancellation
|
|
436
|
+
* @example Customer request
|
|
163
437
|
*/
|
|
164
|
-
|
|
438
|
+
cancellationReason?: string;
|
|
439
|
+
};
|
|
440
|
+
CustomerResponse: {
|
|
165
441
|
/**
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
442
|
+
* Customer reference identifier
|
|
443
|
+
* @example cus_3c4d5e6f7g8h
|
|
168
444
|
*/
|
|
169
|
-
|
|
445
|
+
reference: string;
|
|
170
446
|
/**
|
|
171
|
-
*
|
|
447
|
+
* Customer full name
|
|
172
448
|
* @example John Doe
|
|
173
449
|
*/
|
|
174
|
-
|
|
450
|
+
name: string;
|
|
175
451
|
/**
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
452
|
+
* Customer email address
|
|
453
|
+
* @example customer@example.com
|
|
178
454
|
*/
|
|
179
|
-
|
|
455
|
+
email: string;
|
|
180
456
|
/**
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
457
|
+
* External reference ID from your auth system (if set during creation or update)
|
|
458
|
+
* @example auth_user_12345
|
|
183
459
|
*/
|
|
184
|
-
|
|
460
|
+
externalRef?: string;
|
|
461
|
+
/** Active purchases */
|
|
462
|
+
purchases?: components["schemas"]["PurchaseInfo"][];
|
|
463
|
+
};
|
|
464
|
+
CreateCustomerSessionResponse: {
|
|
185
465
|
/**
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
466
|
+
* Customer session ID/token
|
|
467
|
+
* @example e3f1c2d4b6a89f001122334455667788
|
|
188
468
|
*/
|
|
189
|
-
|
|
469
|
+
sessionId: string;
|
|
190
470
|
/**
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
471
|
+
* Full customer URL based on backend configuration (ready to redirect customer)
|
|
472
|
+
* @example https://solvapay.com/customer/manage?id=e3f1c2d4b6a89f001122334455667788
|
|
193
473
|
*/
|
|
194
|
-
|
|
474
|
+
customerUrl: string;
|
|
475
|
+
};
|
|
476
|
+
GetCustomerSessionResponse: {
|
|
195
477
|
/**
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* @enum {string}
|
|
478
|
+
* Customer session ID/token
|
|
479
|
+
* @example e3f1c2d4b6a89f001122334455667788
|
|
199
480
|
*/
|
|
200
|
-
|
|
481
|
+
sessionId: string;
|
|
201
482
|
/**
|
|
202
|
-
*
|
|
483
|
+
* Session status
|
|
203
484
|
* @example active
|
|
204
485
|
* @enum {string}
|
|
205
486
|
*/
|
|
206
|
-
status: "
|
|
487
|
+
status: "active" | "expired" | "used";
|
|
207
488
|
/**
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
489
|
+
* Full customer URL based on backend configuration (ready to redirect customer)
|
|
490
|
+
* @example https://solvapay.com/customer/manage?id=e3f1c2d4b6a89f001122334455667788
|
|
210
491
|
*/
|
|
211
|
-
|
|
492
|
+
customerUrl: string;
|
|
212
493
|
/**
|
|
213
|
-
*
|
|
214
|
-
* @example
|
|
494
|
+
* Session expiration date
|
|
495
|
+
* @example 2025-01-01T12:00:00.000Z
|
|
215
496
|
*/
|
|
216
|
-
|
|
497
|
+
expiresAt: string;
|
|
498
|
+
/** Customer object from session data */
|
|
499
|
+
customer: components["schemas"]["CustomerResponse"];
|
|
217
500
|
/**
|
|
218
|
-
*
|
|
219
|
-
* @example 2025-01-
|
|
501
|
+
* Session creation date
|
|
502
|
+
* @example 2025-01-01T11:45:00.000Z
|
|
220
503
|
*/
|
|
221
|
-
|
|
504
|
+
createdAt: string;
|
|
222
505
|
/**
|
|
223
|
-
*
|
|
224
|
-
* @example 2025-
|
|
506
|
+
* Session last update date
|
|
507
|
+
* @example 2025-01-01T11:45:00.000Z
|
|
225
508
|
*/
|
|
226
|
-
|
|
509
|
+
updatedAt: string;
|
|
510
|
+
};
|
|
511
|
+
DynamicClientRegistrationDto: {
|
|
512
|
+
/** @example My AI Agent */
|
|
513
|
+
client_name: string;
|
|
227
514
|
/**
|
|
228
|
-
* @
|
|
229
|
-
*
|
|
515
|
+
* @example [
|
|
516
|
+
* "https://agent.example.com/callback"
|
|
517
|
+
* ]
|
|
230
518
|
*/
|
|
231
|
-
|
|
232
|
-
/** @description Usage quota information (for usage-based plans) */
|
|
233
|
-
usageQuota?: Record<string, never>;
|
|
519
|
+
redirect_uris: string[];
|
|
234
520
|
/**
|
|
235
|
-
* @
|
|
236
|
-
*
|
|
521
|
+
* @example [
|
|
522
|
+
* "authorization_code",
|
|
523
|
+
* "refresh_token"
|
|
524
|
+
* ]
|
|
237
525
|
*/
|
|
238
|
-
|
|
526
|
+
grant_types?: string[];
|
|
239
527
|
/**
|
|
240
|
-
* @
|
|
241
|
-
*
|
|
528
|
+
* @example [
|
|
529
|
+
* "code"
|
|
530
|
+
* ]
|
|
242
531
|
*/
|
|
243
|
-
|
|
532
|
+
response_types?: string[];
|
|
533
|
+
/** @example agent-123 */
|
|
534
|
+
software_id?: string;
|
|
535
|
+
/** @example 1.0.0 */
|
|
536
|
+
software_version?: string;
|
|
537
|
+
/** @example https://example.com/logo.png */
|
|
538
|
+
logo_uri?: string;
|
|
539
|
+
/** @example https://example.com/tos */
|
|
540
|
+
tos_uri?: string;
|
|
541
|
+
/** @example https://example.com/policy */
|
|
542
|
+
policy_uri?: string;
|
|
543
|
+
/** @example https://example.com */
|
|
544
|
+
client_uri?: string;
|
|
545
|
+
};
|
|
546
|
+
DynamicClientRegistrationResponseDto: {
|
|
547
|
+
/** @example client-id-123 */
|
|
548
|
+
client_id: string;
|
|
549
|
+
/** @example client-secret-456 */
|
|
550
|
+
client_secret: string;
|
|
551
|
+
/** @example 1734567890 */
|
|
552
|
+
client_id_issued_at: number;
|
|
553
|
+
/** @example 0 */
|
|
554
|
+
client_secret_expires_at: number;
|
|
555
|
+
/** @example My AI Agent */
|
|
556
|
+
client_name: string;
|
|
244
557
|
/**
|
|
245
|
-
* @
|
|
246
|
-
*
|
|
558
|
+
* @example [
|
|
559
|
+
* "https://agent.example.com/callback"
|
|
560
|
+
* ]
|
|
247
561
|
*/
|
|
248
|
-
|
|
562
|
+
redirect_uris: string[];
|
|
249
563
|
/**
|
|
250
|
-
* @
|
|
251
|
-
*
|
|
564
|
+
* @example [
|
|
565
|
+
* "authorization_code",
|
|
566
|
+
* "refresh_token"
|
|
567
|
+
* ]
|
|
252
568
|
*/
|
|
253
|
-
|
|
569
|
+
grant_types: string[];
|
|
254
570
|
/**
|
|
255
|
-
* @
|
|
256
|
-
*
|
|
571
|
+
* @example [
|
|
572
|
+
* "code"
|
|
573
|
+
* ]
|
|
257
574
|
*/
|
|
258
|
-
|
|
575
|
+
response_types: string[];
|
|
576
|
+
/** @example openid profile email */
|
|
577
|
+
scope: string;
|
|
578
|
+
/** @example client_secret_basic */
|
|
579
|
+
token_endpoint_auth_method: string;
|
|
259
580
|
};
|
|
260
|
-
|
|
581
|
+
GoogleLoginDto: {
|
|
582
|
+
/** The authorization code returned by Google */
|
|
583
|
+
code: string;
|
|
584
|
+
/** The redirect URI used in the initial authorization request */
|
|
585
|
+
redirect_uri: string;
|
|
586
|
+
/** The state parameter returned by Google (contains client_id) */
|
|
587
|
+
state: string;
|
|
588
|
+
};
|
|
589
|
+
GithubLoginDto: {
|
|
590
|
+
/** The authorization code returned by GitHub */
|
|
591
|
+
code: string;
|
|
592
|
+
/** The redirect URI used in the initial authorization request */
|
|
593
|
+
redirect_uri: string;
|
|
594
|
+
/** The state parameter returned by GitHub (contains client_id) */
|
|
595
|
+
state: string;
|
|
596
|
+
};
|
|
597
|
+
ExecuteAnalyticsQuery: Record<string, never>;
|
|
598
|
+
ExecuteMultipleQueries: Record<string, never>;
|
|
599
|
+
UpdateThemePreferenceDto: {
|
|
261
600
|
/**
|
|
262
|
-
*
|
|
263
|
-
* @example
|
|
601
|
+
* Selected UI theme mode
|
|
602
|
+
* @example dark
|
|
603
|
+
* @enum {string}
|
|
264
604
|
*/
|
|
265
|
-
|
|
605
|
+
mode: "light" | "dark";
|
|
266
606
|
};
|
|
267
|
-
|
|
268
|
-
/** @description Page identifier */
|
|
269
|
-
id: string;
|
|
270
|
-
/** @description Page display name */
|
|
271
|
-
name: string;
|
|
272
|
-
/** @description Logo URL */
|
|
273
|
-
logo?: string;
|
|
607
|
+
ThemeModeColorsDto: {
|
|
274
608
|
/**
|
|
275
|
-
*
|
|
276
|
-
* @example #
|
|
609
|
+
* Page background color
|
|
610
|
+
* @example #f7f7f8
|
|
277
611
|
*/
|
|
278
|
-
|
|
612
|
+
background?: string;
|
|
279
613
|
/**
|
|
280
|
-
*
|
|
281
|
-
* @example #
|
|
614
|
+
* Card/surface background color
|
|
615
|
+
* @example #ffffff
|
|
282
616
|
*/
|
|
283
|
-
|
|
617
|
+
surface?: string;
|
|
284
618
|
/**
|
|
285
|
-
*
|
|
286
|
-
* @example #
|
|
619
|
+
* Primary text color
|
|
620
|
+
* @example #181818
|
|
287
621
|
*/
|
|
288
|
-
|
|
622
|
+
text?: string;
|
|
289
623
|
/**
|
|
290
|
-
*
|
|
291
|
-
* @example #
|
|
624
|
+
* Secondary/muted text color
|
|
625
|
+
* @example #5c5c5c
|
|
626
|
+
*/
|
|
627
|
+
secondary?: string;
|
|
628
|
+
};
|
|
629
|
+
ThemeOverridesDto: {
|
|
630
|
+
/** Light mode color overrides */
|
|
631
|
+
light?: components["schemas"]["ThemeModeColorsDto"];
|
|
632
|
+
/** Dark mode color overrides */
|
|
633
|
+
dark?: components["schemas"]["ThemeModeColorsDto"];
|
|
634
|
+
};
|
|
635
|
+
UpdateBrandThemeDto: {
|
|
636
|
+
/**
|
|
637
|
+
* Provider's brand name displayed on hosted pages
|
|
638
|
+
* @example Acme Corp
|
|
639
|
+
*/
|
|
640
|
+
brandName: string;
|
|
641
|
+
/**
|
|
642
|
+
* Primary/accent color in hex format
|
|
643
|
+
* @example #3182ce
|
|
292
644
|
*/
|
|
293
|
-
|
|
645
|
+
primaryColor: string;
|
|
294
646
|
/**
|
|
295
|
-
*
|
|
647
|
+
* Font family for hosted pages
|
|
648
|
+
* @default Inter
|
|
296
649
|
* @example Inter
|
|
297
650
|
*/
|
|
298
651
|
fontFamily: string;
|
|
299
652
|
/**
|
|
300
|
-
*
|
|
653
|
+
* Base font size
|
|
654
|
+
* @default 16px
|
|
301
655
|
* @example 16px
|
|
302
656
|
*/
|
|
303
657
|
fontSize: string;
|
|
658
|
+
/** Per-mode color overrides for light and dark themes */
|
|
659
|
+
themes?: components["schemas"]["ThemeOverridesDto"];
|
|
660
|
+
};
|
|
661
|
+
CreateWebhookEndpointDto: Record<string, never>;
|
|
662
|
+
UpdateWebhookEndpointDto: Record<string, never>;
|
|
663
|
+
CreatePreregistrationDto: {
|
|
664
|
+
/** @example jane@company.com */
|
|
665
|
+
email: string;
|
|
666
|
+
/** @example Jane Smith */
|
|
667
|
+
fullName: string;
|
|
668
|
+
/** @example Acme Corp */
|
|
669
|
+
companyName: string;
|
|
670
|
+
/** @example SaaS */
|
|
671
|
+
businessType?: string;
|
|
672
|
+
/** @example Purchase billing for our platform */
|
|
673
|
+
useCase?: string;
|
|
674
|
+
customFields?: {
|
|
675
|
+
[key: string]: string;
|
|
676
|
+
};
|
|
304
677
|
};
|
|
305
678
|
};
|
|
306
679
|
responses: never;
|
|
@@ -324,13 +697,41 @@ type LimitResponseWithPlan = components['schemas']['LimitResponse'] & {
|
|
|
324
697
|
};
|
|
325
698
|
/**
|
|
326
699
|
* Extended CustomerResponse with proper field mapping
|
|
700
|
+
*
|
|
701
|
+
* Note: The backend API returns purchases as PurchaseInfo objects.
|
|
702
|
+
* Additional fields (paidAt, nextBillingDate) may be present in the response.
|
|
327
703
|
*/
|
|
328
704
|
type CustomerResponseMapped = {
|
|
329
705
|
customerRef: string;
|
|
330
706
|
email?: string;
|
|
331
707
|
name?: string;
|
|
708
|
+
externalRef?: string;
|
|
332
709
|
plan?: string;
|
|
710
|
+
purchases?: Array<components['schemas']['PurchaseInfo'] & {
|
|
711
|
+
paidAt?: string;
|
|
712
|
+
nextBillingDate?: string;
|
|
713
|
+
}>;
|
|
333
714
|
};
|
|
715
|
+
/**
|
|
716
|
+
* One-time purchase information returned from payment processing
|
|
717
|
+
*/
|
|
718
|
+
interface OneTimePurchaseInfo {
|
|
719
|
+
reference: string;
|
|
720
|
+
productRef?: string;
|
|
721
|
+
amount: number;
|
|
722
|
+
currency: string;
|
|
723
|
+
creditsAdded?: number;
|
|
724
|
+
completedAt: string;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Result from processing a payment intent
|
|
728
|
+
*/
|
|
729
|
+
interface ProcessPaymentResult {
|
|
730
|
+
type: 'recurring' | 'one-time';
|
|
731
|
+
purchase?: components['schemas']['PurchaseInfo'];
|
|
732
|
+
oneTimePurchase?: OneTimePurchaseInfo;
|
|
733
|
+
status: 'completed';
|
|
734
|
+
}
|
|
334
735
|
/**
|
|
335
736
|
* SolvaPay API Client Interface
|
|
336
737
|
*
|
|
@@ -340,41 +741,57 @@ type CustomerResponseMapped = {
|
|
|
340
741
|
*/
|
|
341
742
|
interface SolvaPayClient {
|
|
342
743
|
checkLimits(params: components['schemas']['CheckLimitRequest']): Promise<LimitResponseWithPlan>;
|
|
343
|
-
trackUsage(params:
|
|
744
|
+
trackUsage(params: {
|
|
745
|
+
customerRef: string;
|
|
746
|
+
productRef: string;
|
|
344
747
|
planRef: string;
|
|
748
|
+
outcome: string;
|
|
749
|
+
action?: string;
|
|
750
|
+
requestId?: string;
|
|
751
|
+
actionDuration?: number;
|
|
752
|
+
timestamp?: string;
|
|
345
753
|
}): Promise<void>;
|
|
346
754
|
createCustomer?(params: components['schemas']['CreateCustomerRequest']): Promise<{
|
|
347
755
|
customerRef: string;
|
|
348
756
|
}>;
|
|
349
|
-
getCustomer
|
|
350
|
-
customerRef
|
|
757
|
+
getCustomer(params: {
|
|
758
|
+
customerRef?: string;
|
|
759
|
+
externalRef?: string;
|
|
760
|
+
email?: string;
|
|
351
761
|
}): Promise<CustomerResponseMapped>;
|
|
352
|
-
|
|
762
|
+
listProducts?(): Promise<Array<{
|
|
353
763
|
reference: string;
|
|
354
764
|
name: string;
|
|
355
765
|
description?: string;
|
|
766
|
+
status?: string;
|
|
356
767
|
}>>;
|
|
357
|
-
|
|
768
|
+
createProduct?(params: components['schemas']['CreateProductRequest']): Promise<{
|
|
358
769
|
reference: string;
|
|
359
770
|
name: string;
|
|
360
771
|
}>;
|
|
361
|
-
|
|
362
|
-
|
|
772
|
+
updateProduct?(productRef: string, params: components['schemas']['UpdateProductRequest']): Promise<components['schemas']['SdkProductResponse']>;
|
|
773
|
+
deleteProduct?(productRef: string): Promise<void>;
|
|
774
|
+
listPlans?(productRef: string): Promise<Array<{
|
|
363
775
|
reference: string;
|
|
364
776
|
name: string;
|
|
777
|
+
description?: string;
|
|
778
|
+
price?: number;
|
|
779
|
+
currency?: string;
|
|
780
|
+
interval?: string;
|
|
365
781
|
isFreeTier?: boolean;
|
|
366
782
|
freeUnits?: number;
|
|
367
|
-
|
|
783
|
+
metadata?: Record<string, unknown>;
|
|
784
|
+
[key: string]: unknown;
|
|
368
785
|
}>>;
|
|
369
786
|
createPlan?(params: components['schemas']['CreatePlanRequest'] & {
|
|
370
|
-
|
|
787
|
+
productRef: string;
|
|
371
788
|
}): Promise<{
|
|
372
789
|
reference: string;
|
|
373
790
|
name: string;
|
|
374
791
|
}>;
|
|
375
|
-
deletePlan?(
|
|
792
|
+
deletePlan?(productRef: string, planRef: string): Promise<void>;
|
|
376
793
|
createPaymentIntent?(params: {
|
|
377
|
-
|
|
794
|
+
productRef: string;
|
|
378
795
|
planRef: string;
|
|
379
796
|
customerRef: string;
|
|
380
797
|
idempotencyKey?: string;
|
|
@@ -384,6 +801,18 @@ interface SolvaPayClient {
|
|
|
384
801
|
publishableKey: string;
|
|
385
802
|
accountId?: string;
|
|
386
803
|
}>;
|
|
804
|
+
cancelPurchase?(params: {
|
|
805
|
+
purchaseRef: string;
|
|
806
|
+
reason?: string;
|
|
807
|
+
}): Promise<components['schemas']['PurchaseInfo']>;
|
|
808
|
+
processPaymentIntent?(params: {
|
|
809
|
+
paymentIntentId: string;
|
|
810
|
+
productRef: string;
|
|
811
|
+
customerRef: string;
|
|
812
|
+
planRef?: string;
|
|
813
|
+
}): Promise<ProcessPaymentResult>;
|
|
814
|
+
createCheckoutSession(params: components['schemas']['CreateCheckoutSessionRequest']): Promise<components['schemas']['CheckoutSessionResponse']>;
|
|
815
|
+
createCustomerSession(params: components['schemas']['CreateCustomerSessionRequest']): Promise<components['schemas']['CreateCustomerSessionResponse']>;
|
|
387
816
|
}
|
|
388
817
|
|
|
389
818
|
/**
|
|
@@ -395,7 +824,7 @@ interface SolvaPayClient {
|
|
|
395
824
|
* Arguments passed to protected handlers
|
|
396
825
|
*/
|
|
397
826
|
interface PaywallArgs {
|
|
398
|
-
[key: string]:
|
|
827
|
+
[key: string]: unknown;
|
|
399
828
|
auth?: {
|
|
400
829
|
customer_ref?: string;
|
|
401
830
|
};
|
|
@@ -404,7 +833,7 @@ interface PaywallArgs {
|
|
|
404
833
|
* Metadata for configuring paywall protection
|
|
405
834
|
*/
|
|
406
835
|
interface PaywallMetadata {
|
|
407
|
-
|
|
836
|
+
product?: string;
|
|
408
837
|
plan?: string;
|
|
409
838
|
}
|
|
410
839
|
/**
|
|
@@ -412,7 +841,7 @@ interface PaywallMetadata {
|
|
|
412
841
|
*/
|
|
413
842
|
interface PaywallStructuredContent {
|
|
414
843
|
kind: 'payment_required';
|
|
415
|
-
|
|
844
|
+
product: string;
|
|
416
845
|
checkoutUrl: string;
|
|
417
846
|
message: string;
|
|
418
847
|
}
|
|
@@ -439,7 +868,7 @@ interface PaywallToolResult {
|
|
|
439
868
|
/**
|
|
440
869
|
* Retry configuration options
|
|
441
870
|
*/
|
|
442
|
-
interface RetryOptions
|
|
871
|
+
interface RetryOptions {
|
|
443
872
|
/**
|
|
444
873
|
* Maximum number of retry attempts (default: 2)
|
|
445
874
|
*/
|
|
@@ -474,15 +903,15 @@ interface RetryOptions$1 {
|
|
|
474
903
|
*/
|
|
475
904
|
interface PayableOptions {
|
|
476
905
|
/**
|
|
477
|
-
*
|
|
906
|
+
* Product identifier
|
|
478
907
|
*/
|
|
479
|
-
|
|
908
|
+
product?: string;
|
|
480
909
|
/**
|
|
481
|
-
*
|
|
910
|
+
* Product reference (alias for product, preferred for consistency with backend API)
|
|
482
911
|
*/
|
|
483
|
-
|
|
912
|
+
productRef?: string;
|
|
484
913
|
/**
|
|
485
|
-
* Plan identifier (defaults to
|
|
914
|
+
* Plan identifier (defaults to product name if not provided)
|
|
486
915
|
*/
|
|
487
916
|
plan?: string;
|
|
488
917
|
/**
|
|
@@ -560,91 +989,286 @@ type ServerClientOptions = {
|
|
|
560
989
|
apiKey: string;
|
|
561
990
|
/**
|
|
562
991
|
* Base URL for the SolvaPay API (optional)
|
|
563
|
-
* Defaults to https://api
|
|
992
|
+
* Defaults to https://api.solvapay.com
|
|
564
993
|
*/
|
|
565
994
|
apiBaseUrl?: string;
|
|
566
995
|
};
|
|
567
996
|
/**
|
|
568
|
-
* Creates a SolvaPay API client that implements the full SolvaPayClient
|
|
569
|
-
*
|
|
997
|
+
* Creates a SolvaPay API client that implements the full SolvaPayClient interface.
|
|
998
|
+
*
|
|
999
|
+
* This function creates a low-level API client for direct communication with the
|
|
1000
|
+
* SolvaPay backend. For most use cases, use `createSolvaPay()` instead, which
|
|
1001
|
+
* provides a higher-level API with paywall protection.
|
|
570
1002
|
*
|
|
571
|
-
*
|
|
1003
|
+
* Use this function when you need:
|
|
1004
|
+
* - Direct API access for custom operations
|
|
1005
|
+
* - Testing with custom client implementations
|
|
1006
|
+
* - Advanced use cases not covered by the main API
|
|
1007
|
+
*
|
|
1008
|
+
* @param opts - Configuration options
|
|
1009
|
+
* @param opts.apiKey - Your SolvaPay API key (required)
|
|
1010
|
+
* @param opts.apiBaseUrl - Optional API base URL override
|
|
572
1011
|
* @returns A fully configured SolvaPayClient instance
|
|
573
1012
|
* @throws {SolvaPayError} If API key is missing
|
|
574
1013
|
*
|
|
575
1014
|
* @example
|
|
576
1015
|
* ```typescript
|
|
1016
|
+
* // Create API client directly
|
|
577
1017
|
* const client = createSolvaPayClient({
|
|
578
1018
|
* apiKey: process.env.SOLVAPAY_SECRET_KEY!,
|
|
579
1019
|
* apiBaseUrl: 'https://api.solvapay.com' // optional
|
|
580
1020
|
* });
|
|
1021
|
+
*
|
|
1022
|
+
* // Use client for custom operations
|
|
1023
|
+
* const products = await client.listProducts();
|
|
581
1024
|
* ```
|
|
1025
|
+
*
|
|
1026
|
+
* @see {@link createSolvaPay} for the recommended high-level API
|
|
1027
|
+
* @see {@link ServerClientOptions} for configuration options
|
|
1028
|
+
* @since 1.0.0
|
|
582
1029
|
*/
|
|
583
1030
|
declare function createSolvaPayClient(opts: ServerClientOptions): SolvaPayClient;
|
|
584
1031
|
|
|
585
1032
|
/**
|
|
586
|
-
* SolvaPay
|
|
1033
|
+
* Configuration for creating a SolvaPay instance.
|
|
587
1034
|
*
|
|
588
|
-
*
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
*
|
|
1035
|
+
* You can provide either an `apiKey` (for production) or an `apiClient` (for testing).
|
|
1036
|
+
* If neither is provided, the SDK will attempt to read `SOLVAPAY_SECRET_KEY` from
|
|
1037
|
+
* environment variables. If no API key is found, the SDK runs in stub mode.
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```typescript
|
|
1041
|
+
* // Production: Use API key
|
|
1042
|
+
* const config: CreateSolvaPayConfig = {
|
|
1043
|
+
* apiKey: process.env.SOLVAPAY_SECRET_KEY
|
|
1044
|
+
* };
|
|
1045
|
+
*
|
|
1046
|
+
* // Testing: Use mock client
|
|
1047
|
+
* const config: CreateSolvaPayConfig = {
|
|
1048
|
+
* apiClient: mockClient
|
|
1049
|
+
* };
|
|
1050
|
+
* ```
|
|
593
1051
|
*/
|
|
594
1052
|
interface CreateSolvaPayConfig {
|
|
595
1053
|
/**
|
|
596
|
-
* API key for production use (creates client automatically)
|
|
1054
|
+
* API key for production use (creates client automatically).
|
|
1055
|
+
* Defaults to `SOLVAPAY_SECRET_KEY` environment variable if not provided.
|
|
597
1056
|
*/
|
|
598
1057
|
apiKey?: string;
|
|
599
1058
|
/**
|
|
600
|
-
* API client for testing or custom implementations
|
|
1059
|
+
* API client for testing or custom implementations.
|
|
1060
|
+
* Use this for stub mode, testing, or custom client implementations.
|
|
601
1061
|
*/
|
|
602
1062
|
apiClient?: SolvaPayClient;
|
|
603
1063
|
/**
|
|
604
|
-
* Optional API base URL (only used with apiKey)
|
|
1064
|
+
* Optional API base URL override (only used with apiKey).
|
|
1065
|
+
* Defaults to production API URL if not provided.
|
|
605
1066
|
*/
|
|
606
1067
|
apiBaseUrl?: string;
|
|
607
1068
|
}
|
|
608
1069
|
/**
|
|
609
|
-
* Payable function that provides explicit adapters
|
|
1070
|
+
* Payable function that provides explicit adapters for different frameworks.
|
|
1071
|
+
*
|
|
1072
|
+
* Use the appropriate adapter method for your framework:
|
|
1073
|
+
* - `http()` - Express.js, Fastify, and other HTTP frameworks
|
|
1074
|
+
* - `next()` - Next.js App Router API routes
|
|
1075
|
+
* - `mcp()` - Model Context Protocol servers
|
|
1076
|
+
* - `function()` - Pure functions, background jobs, or testing
|
|
1077
|
+
*
|
|
1078
|
+
* @example
|
|
1079
|
+
* ```typescript
|
|
1080
|
+
* const payable = solvaPay.payable({ product: 'prd_myapi', plan: 'pln_premium' });
|
|
1081
|
+
*
|
|
1082
|
+
* // Express.js
|
|
1083
|
+
* app.post('/tasks', payable.http(createTask));
|
|
1084
|
+
*
|
|
1085
|
+
* // Next.js
|
|
1086
|
+
* export const POST = payable.next(createTask);
|
|
1087
|
+
*
|
|
1088
|
+
* // MCP Server
|
|
1089
|
+
* const handler = payable.mcp(createTask);
|
|
1090
|
+
*
|
|
1091
|
+
* // Pure function
|
|
1092
|
+
* const protectedFn = await payable.function(createTask);
|
|
1093
|
+
* ```
|
|
610
1094
|
*/
|
|
611
1095
|
interface PayableFunction {
|
|
612
1096
|
/**
|
|
613
|
-
* HTTP adapter for Express
|
|
1097
|
+
* HTTP adapter for Express.js, Fastify, and other HTTP frameworks.
|
|
1098
|
+
*
|
|
1099
|
+
* @param businessLogic - Your business logic function
|
|
1100
|
+
* @param options - Optional adapter configuration
|
|
1101
|
+
* @returns HTTP route handler function
|
|
1102
|
+
*
|
|
1103
|
+
* @example
|
|
1104
|
+
* ```typescript
|
|
1105
|
+
* app.post('/tasks', payable.http(async (req) => {
|
|
1106
|
+
* const { title } = req.body;
|
|
1107
|
+
* return { success: true, task: { title } };
|
|
1108
|
+
* }));
|
|
1109
|
+
* ```
|
|
614
1110
|
*/
|
|
615
|
-
http<T = any>(businessLogic: (args: any) => Promise<T>, options?: HttpAdapterOptions): (req: any, reply: any) => Promise<
|
|
1111
|
+
http<T = any>(businessLogic: (args: any) => Promise<T>, options?: HttpAdapterOptions): (req: any, reply: any) => Promise<unknown>;
|
|
616
1112
|
/**
|
|
617
|
-
* Next.js adapter for App Router
|
|
1113
|
+
* Next.js adapter for App Router API routes.
|
|
1114
|
+
*
|
|
1115
|
+
* @param businessLogic - Your business logic function
|
|
1116
|
+
* @param options - Optional adapter configuration
|
|
1117
|
+
* @returns Next.js route handler function
|
|
1118
|
+
*
|
|
1119
|
+
* @example
|
|
1120
|
+
* ```typescript
|
|
1121
|
+
* // app/api/tasks/route.ts
|
|
1122
|
+
* export const POST = payable.next(async (request) => {
|
|
1123
|
+
* const body = await request.json();
|
|
1124
|
+
* return Response.json({ success: true });
|
|
1125
|
+
* });
|
|
1126
|
+
* ```
|
|
618
1127
|
*/
|
|
619
1128
|
next<T = any>(businessLogic: (args: any) => Promise<T>, options?: NextAdapterOptions): (request: Request, context?: any) => Promise<Response>;
|
|
620
1129
|
/**
|
|
621
|
-
* MCP adapter for Model Context Protocol servers
|
|
1130
|
+
* MCP adapter for Model Context Protocol servers.
|
|
1131
|
+
*
|
|
1132
|
+
* @param businessLogic - Your tool implementation function
|
|
1133
|
+
* @param options - Optional adapter configuration
|
|
1134
|
+
* @returns MCP tool handler function
|
|
1135
|
+
*
|
|
1136
|
+
* @example
|
|
1137
|
+
* ```typescript
|
|
1138
|
+
* const handler = payable.mcp(async (args) => {
|
|
1139
|
+
* return { success: true, result: 'tool output' };
|
|
1140
|
+
* });
|
|
1141
|
+
* ```
|
|
622
1142
|
*/
|
|
623
|
-
mcp<T = any>(businessLogic: (args: any) => Promise<T>, options?: McpAdapterOptions): (args:
|
|
1143
|
+
mcp<T = any>(businessLogic: (args: any) => Promise<T>, options?: McpAdapterOptions): (args: Record<string, unknown>) => Promise<unknown>;
|
|
624
1144
|
/**
|
|
625
|
-
* Pure function adapter for direct function protection
|
|
626
|
-
*
|
|
1145
|
+
* Pure function adapter for direct function protection.
|
|
1146
|
+
*
|
|
1147
|
+
* Use this for testing, background jobs, or non-framework contexts.
|
|
1148
|
+
*
|
|
1149
|
+
* @param businessLogic - Your business logic function
|
|
1150
|
+
* @returns Protected function that requires customer reference in args
|
|
1151
|
+
*
|
|
1152
|
+
* @example
|
|
1153
|
+
* ```typescript
|
|
1154
|
+
* const protectedFn = await payable.function(async (args) => {
|
|
1155
|
+
* return { result: 'processed' };
|
|
1156
|
+
* });
|
|
1157
|
+
*
|
|
1158
|
+
* // Call with customer reference
|
|
1159
|
+
* const result = await protectedFn({
|
|
1160
|
+
* auth: { customer_ref: 'user_123' },
|
|
1161
|
+
* // ... other args
|
|
1162
|
+
* });
|
|
1163
|
+
* ```
|
|
627
1164
|
*/
|
|
628
1165
|
function<T = any>(businessLogic: (args: any) => Promise<T>): Promise<(args: any) => Promise<T>>;
|
|
629
1166
|
}
|
|
630
1167
|
/**
|
|
631
|
-
* SolvaPay instance with payable method and common API methods
|
|
1168
|
+
* SolvaPay instance with payable method and common API methods.
|
|
1169
|
+
*
|
|
1170
|
+
* This interface provides the main API for interacting with SolvaPay.
|
|
1171
|
+
* Use `createSolvaPay()` to create an instance.
|
|
1172
|
+
*
|
|
1173
|
+
* @example
|
|
1174
|
+
* ```typescript
|
|
1175
|
+
* const solvaPay = createSolvaPay();
|
|
1176
|
+
*
|
|
1177
|
+
* // Create payable handlers
|
|
1178
|
+
* const payable = solvaPay.payable({ product: 'prd_myapi', plan: 'pln_premium' });
|
|
1179
|
+
*
|
|
1180
|
+
* // Manage customers
|
|
1181
|
+
* const customerRef = await solvaPay.ensureCustomer('user_123', 'user_123', {
|
|
1182
|
+
* email: 'user@example.com'
|
|
1183
|
+
* });
|
|
1184
|
+
*
|
|
1185
|
+
* // Create payment intents
|
|
1186
|
+
* const intent = await solvaPay.createPaymentIntent({
|
|
1187
|
+
* productRef: 'prd_myapi',
|
|
1188
|
+
* planRef: 'pln_premium',
|
|
1189
|
+
* customerRef: 'user_123'
|
|
1190
|
+
* });
|
|
1191
|
+
* ```
|
|
632
1192
|
*/
|
|
633
1193
|
interface SolvaPay {
|
|
634
1194
|
/**
|
|
635
|
-
* Create a payable handler with explicit adapters
|
|
1195
|
+
* Create a payable handler with explicit adapters for different frameworks.
|
|
1196
|
+
*
|
|
1197
|
+
* @param options - Payable options including product and plan references
|
|
1198
|
+
* @returns PayableFunction with framework-specific adapters
|
|
1199
|
+
*
|
|
1200
|
+
* @example
|
|
1201
|
+
* ```typescript
|
|
1202
|
+
* const payable = solvaPay.payable({
|
|
1203
|
+
* product: 'prd_myapi',
|
|
1204
|
+
* plan: 'pln_premium'
|
|
1205
|
+
* });
|
|
1206
|
+
*
|
|
1207
|
+
* app.post('/tasks', payable.http(createTask));
|
|
1208
|
+
* ```
|
|
636
1209
|
*/
|
|
637
1210
|
payable(options?: PayableOptions): PayableFunction;
|
|
638
1211
|
/**
|
|
639
|
-
* Ensure customer exists (
|
|
640
|
-
*
|
|
1212
|
+
* Ensure customer exists in SolvaPay backend (idempotent).
|
|
1213
|
+
*
|
|
1214
|
+
* Creates a customer if they don't exist, or returns existing customer reference.
|
|
1215
|
+
* This is automatically called by the paywall system, but you can call it
|
|
1216
|
+
* explicitly for setup or testing.
|
|
1217
|
+
*
|
|
1218
|
+
* @param customerRef - The customer reference used as a cache key (e.g., Supabase user ID)
|
|
1219
|
+
* @param externalRef - Optional external reference for backend lookup (e.g., Supabase user ID).
|
|
1220
|
+
* If provided, will lookup existing customer by externalRef before creating new one.
|
|
1221
|
+
* The externalRef is stored on the SolvaPay backend for customer lookup.
|
|
1222
|
+
* @param options - Optional customer details for customer creation
|
|
1223
|
+
* @param options.email - Customer email address
|
|
1224
|
+
* @param options.name - Customer name
|
|
1225
|
+
* @returns Customer reference (backend customer ID)
|
|
1226
|
+
*
|
|
1227
|
+
* @example
|
|
1228
|
+
* ```typescript
|
|
1229
|
+
* // Ensure customer exists before processing payment
|
|
1230
|
+
* const customerRef = await solvaPay.ensureCustomer(
|
|
1231
|
+
* 'user_123', // customerRef (your user ID)
|
|
1232
|
+
* 'user_123', // externalRef (same or different)
|
|
1233
|
+
* {
|
|
1234
|
+
* email: 'user@example.com',
|
|
1235
|
+
* name: 'John Doe'
|
|
1236
|
+
* }
|
|
1237
|
+
* );
|
|
1238
|
+
* ```
|
|
641
1239
|
*/
|
|
642
|
-
ensureCustomer(customerRef: string
|
|
1240
|
+
ensureCustomer(customerRef: string, externalRef?: string, options?: {
|
|
1241
|
+
email?: string;
|
|
1242
|
+
name?: string;
|
|
1243
|
+
}): Promise<string>;
|
|
643
1244
|
/**
|
|
644
|
-
* Create a payment intent for a customer to
|
|
1245
|
+
* Create a Stripe payment intent for a customer to purchase a plan.
|
|
1246
|
+
*
|
|
1247
|
+
* This creates a payment intent that can be confirmed on the client side
|
|
1248
|
+
* using Stripe.js. After confirmation, call `processPaymentIntent()` to complete
|
|
1249
|
+
* the purchase.
|
|
1250
|
+
*
|
|
1251
|
+
* @param params - Payment intent parameters
|
|
1252
|
+
* @param params.productRef - Product reference
|
|
1253
|
+
* @param params.planRef - Plan reference to purchase
|
|
1254
|
+
* @param params.customerRef - Customer reference
|
|
1255
|
+
* @param params.idempotencyKey - Optional idempotency key for retry safety
|
|
1256
|
+
* @returns Payment intent with client secret and publishable key
|
|
1257
|
+
*
|
|
1258
|
+
* @example
|
|
1259
|
+
* ```typescript
|
|
1260
|
+
* const intent = await solvaPay.createPaymentIntent({
|
|
1261
|
+
* productRef: 'prd_myapi',
|
|
1262
|
+
* planRef: 'pln_premium',
|
|
1263
|
+
* customerRef: 'user_123',
|
|
1264
|
+
* idempotencyKey: 'unique-key-123'
|
|
1265
|
+
* });
|
|
1266
|
+
*
|
|
1267
|
+
* // Use intent.clientSecret with Stripe.js on client
|
|
1268
|
+
* ```
|
|
645
1269
|
*/
|
|
646
1270
|
createPaymentIntent(params: {
|
|
647
|
-
|
|
1271
|
+
productRef: string;
|
|
648
1272
|
planRef: string;
|
|
649
1273
|
customerRef: string;
|
|
650
1274
|
idempotencyKey?: string;
|
|
@@ -655,11 +1279,66 @@ interface SolvaPay {
|
|
|
655
1279
|
accountId?: string;
|
|
656
1280
|
}>;
|
|
657
1281
|
/**
|
|
658
|
-
*
|
|
1282
|
+
* Process a payment intent after client-side Stripe confirmation.
|
|
1283
|
+
*
|
|
1284
|
+
* Creates the purchase immediately, eliminating webhook delay.
|
|
1285
|
+
* Call this after the client has confirmed the payment intent with Stripe.js.
|
|
1286
|
+
*
|
|
1287
|
+
* @param params - Payment processing parameters
|
|
1288
|
+
* @param params.paymentIntentId - Stripe payment intent ID from client confirmation
|
|
1289
|
+
* @param params.productRef - Product reference
|
|
1290
|
+
* @param params.customerRef - Customer reference
|
|
1291
|
+
* @param params.planRef - Optional plan reference (if not in payment intent)
|
|
1292
|
+
* @returns Payment processing result with purchase details
|
|
1293
|
+
*
|
|
1294
|
+
* @example
|
|
1295
|
+
* ```typescript
|
|
1296
|
+
* // After client confirms payment with Stripe.js
|
|
1297
|
+
* const result = await solvaPay.processPaymentIntent({
|
|
1298
|
+
* paymentIntentId: 'pi_1234567890',
|
|
1299
|
+
* productRef: 'prd_myapi',
|
|
1300
|
+
* customerRef: 'user_123',
|
|
1301
|
+
* planRef: 'pln_premium'
|
|
1302
|
+
* });
|
|
1303
|
+
*
|
|
1304
|
+
* if (result.success) {
|
|
1305
|
+
* console.log('Purchase created:', result.purchase);
|
|
1306
|
+
* }
|
|
1307
|
+
* ```
|
|
1308
|
+
*/
|
|
1309
|
+
processPaymentIntent(params: {
|
|
1310
|
+
paymentIntentId: string;
|
|
1311
|
+
productRef: string;
|
|
1312
|
+
customerRef: string;
|
|
1313
|
+
planRef?: string;
|
|
1314
|
+
}): Promise<ProcessPaymentResult>;
|
|
1315
|
+
/**
|
|
1316
|
+
* Check if customer is within usage limits for a product.
|
|
1317
|
+
*
|
|
1318
|
+
* This method checks purchase status and usage limits without
|
|
1319
|
+
* executing business logic. Use `payable()` for automatic protection.
|
|
1320
|
+
*
|
|
1321
|
+
* @param params - Limit check parameters
|
|
1322
|
+
* @param params.customerRef - Customer reference
|
|
1323
|
+
* @param params.productRef - Product reference
|
|
1324
|
+
* @returns Limit check result with remaining usage and checkout URL if needed
|
|
1325
|
+
*
|
|
1326
|
+
* @example
|
|
1327
|
+
* ```typescript
|
|
1328
|
+
* const limits = await solvaPay.checkLimits({
|
|
1329
|
+
* customerRef: 'user_123',
|
|
1330
|
+
* productRef: 'prd_myapi'
|
|
1331
|
+
* });
|
|
1332
|
+
*
|
|
1333
|
+
* if (!limits.withinLimits) {
|
|
1334
|
+
* // Redirect to checkout
|
|
1335
|
+
* window.location.href = limits.checkoutUrl;
|
|
1336
|
+
* }
|
|
1337
|
+
* ```
|
|
659
1338
|
*/
|
|
660
1339
|
checkLimits(params: {
|
|
661
1340
|
customerRef: string;
|
|
662
|
-
|
|
1341
|
+
productRef: string;
|
|
663
1342
|
}): Promise<{
|
|
664
1343
|
withinLimits: boolean;
|
|
665
1344
|
remaining: number;
|
|
@@ -667,11 +1346,38 @@ interface SolvaPay {
|
|
|
667
1346
|
checkoutUrl?: string;
|
|
668
1347
|
}>;
|
|
669
1348
|
/**
|
|
670
|
-
* Track usage for a customer action
|
|
1349
|
+
* Track usage for a customer action.
|
|
1350
|
+
*
|
|
1351
|
+
* This is automatically called by the paywall system. You typically
|
|
1352
|
+
* don't need to call this manually unless implementing custom tracking.
|
|
1353
|
+
*
|
|
1354
|
+
* @param params - Usage tracking parameters
|
|
1355
|
+
* @param params.customerRef - Customer reference
|
|
1356
|
+
* @param params.productRef - Product reference
|
|
1357
|
+
* @param params.planRef - Plan reference
|
|
1358
|
+
* @param params.outcome - Action outcome ('success', 'paywall', or 'fail')
|
|
1359
|
+
* @param params.action - Optional action name for analytics
|
|
1360
|
+
* @param params.requestId - Unique request ID
|
|
1361
|
+
* @param params.actionDuration - Action duration in milliseconds
|
|
1362
|
+
* @param params.timestamp - ISO timestamp of the action
|
|
1363
|
+
*
|
|
1364
|
+
* @example
|
|
1365
|
+
* ```typescript
|
|
1366
|
+
* await solvaPay.trackUsage({
|
|
1367
|
+
* customerRef: 'user_123',
|
|
1368
|
+
* productRef: 'prd_myapi',
|
|
1369
|
+
* planRef: 'pln_premium',
|
|
1370
|
+
* outcome: 'success',
|
|
1371
|
+
* action: 'api_call',
|
|
1372
|
+
* requestId: 'req_123',
|
|
1373
|
+
* actionDuration: 150,
|
|
1374
|
+
* timestamp: new Date().toISOString()
|
|
1375
|
+
* });
|
|
1376
|
+
* ```
|
|
671
1377
|
*/
|
|
672
1378
|
trackUsage(params: {
|
|
673
1379
|
customerRef: string;
|
|
674
|
-
|
|
1380
|
+
productRef: string;
|
|
675
1381
|
planRef: string;
|
|
676
1382
|
outcome: 'success' | 'paywall' | 'fail';
|
|
677
1383
|
action?: string;
|
|
@@ -680,7 +1386,23 @@ interface SolvaPay {
|
|
|
680
1386
|
timestamp: string;
|
|
681
1387
|
}): Promise<void>;
|
|
682
1388
|
/**
|
|
683
|
-
* Create a new customer
|
|
1389
|
+
* Create a new customer in SolvaPay backend.
|
|
1390
|
+
*
|
|
1391
|
+
* Note: `ensureCustomer()` is usually preferred as it's idempotent.
|
|
1392
|
+
* Use this only if you need explicit control over customer creation.
|
|
1393
|
+
*
|
|
1394
|
+
* @param params - Customer creation parameters
|
|
1395
|
+
* @param params.email - Customer email address (required)
|
|
1396
|
+
* @param params.name - Optional customer name
|
|
1397
|
+
* @returns Created customer reference
|
|
1398
|
+
*
|
|
1399
|
+
* @example
|
|
1400
|
+
* ```typescript
|
|
1401
|
+
* const { customerRef } = await solvaPay.createCustomer({
|
|
1402
|
+
* email: 'user@example.com',
|
|
1403
|
+
* name: 'John Doe'
|
|
1404
|
+
* });
|
|
1405
|
+
* ```
|
|
684
1406
|
*/
|
|
685
1407
|
createCustomer(params: {
|
|
686
1408
|
email: string;
|
|
@@ -689,47 +1411,153 @@ interface SolvaPay {
|
|
|
689
1411
|
customerRef: string;
|
|
690
1412
|
}>;
|
|
691
1413
|
/**
|
|
692
|
-
* Get customer details
|
|
1414
|
+
* Get customer details including purchases and usage.
|
|
1415
|
+
*
|
|
1416
|
+
* Returns full customer information from the SolvaPay backend, including
|
|
1417
|
+
* all active purchases, usage history, and customer metadata.
|
|
1418
|
+
*
|
|
1419
|
+
* @param params - Customer lookup parameters
|
|
1420
|
+
* @param params.customerRef - Optional customer reference (SolvaPay ID)
|
|
1421
|
+
* @param params.externalRef - Optional external reference (e.g., Supabase ID)
|
|
1422
|
+
* @returns Customer details with purchases and metadata
|
|
1423
|
+
*
|
|
1424
|
+
* @example
|
|
1425
|
+
* ```typescript
|
|
1426
|
+
* // Lookup by SolvaPay customer ID
|
|
1427
|
+
* const customer = await solvaPay.getCustomer({
|
|
1428
|
+
* customerRef: 'cust_123'
|
|
1429
|
+
* });
|
|
1430
|
+
*
|
|
1431
|
+
* // Lookup by external ID (e.g. Supabase user ID)
|
|
1432
|
+
* const customer = await solvaPay.getCustomer({
|
|
1433
|
+
* externalRef: 'user_123'
|
|
1434
|
+
* });
|
|
1435
|
+
* ```
|
|
693
1436
|
*/
|
|
694
1437
|
getCustomer(params: {
|
|
1438
|
+
customerRef?: string;
|
|
1439
|
+
externalRef?: string;
|
|
1440
|
+
}): Promise<CustomerResponseMapped>;
|
|
1441
|
+
/**
|
|
1442
|
+
* Create a hosted checkout session for a customer.
|
|
1443
|
+
*
|
|
1444
|
+
* This creates a Stripe Checkout session that redirects the customer
|
|
1445
|
+
* to a hosted payment page. After payment, customer is redirected back.
|
|
1446
|
+
*
|
|
1447
|
+
* @param params - Checkout session parameters
|
|
1448
|
+
* @param params.productRef - Product reference
|
|
1449
|
+
* @param params.customerRef - Customer reference
|
|
1450
|
+
* @param params.planRef - Optional plan reference (if not specified, shows plan selector)
|
|
1451
|
+
* @param params.returnUrl - URL to redirect to after successful payment
|
|
1452
|
+
* @returns Checkout session with redirect URL
|
|
1453
|
+
*
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```typescript
|
|
1456
|
+
* const session = await solvaPay.createCheckoutSession({
|
|
1457
|
+
* productRef: 'prd_myapi',
|
|
1458
|
+
* customerRef: 'user_123',
|
|
1459
|
+
* planRef: 'pln_premium',
|
|
1460
|
+
* returnUrl: 'https://myapp.com/success'
|
|
1461
|
+
* });
|
|
1462
|
+
*
|
|
1463
|
+
* // Redirect customer to checkout
|
|
1464
|
+
* window.location.href = session.checkoutUrl;
|
|
1465
|
+
* ```
|
|
1466
|
+
*/
|
|
1467
|
+
createCheckoutSession(params: {
|
|
1468
|
+
productRef: string;
|
|
695
1469
|
customerRef: string;
|
|
1470
|
+
planRef?: string;
|
|
1471
|
+
returnUrl?: string;
|
|
696
1472
|
}): Promise<{
|
|
1473
|
+
sessionId: string;
|
|
1474
|
+
checkoutUrl: string;
|
|
1475
|
+
}>;
|
|
1476
|
+
/**
|
|
1477
|
+
* Create a customer portal session for managing purchases.
|
|
1478
|
+
*
|
|
1479
|
+
* This creates a Stripe Customer Portal session that allows customers
|
|
1480
|
+
* to manage their purchases, update payment methods, and view invoices.
|
|
1481
|
+
*
|
|
1482
|
+
* @param params - Customer session parameters
|
|
1483
|
+
* @param params.customerRef - Customer reference
|
|
1484
|
+
* @returns Customer portal session with redirect URL
|
|
1485
|
+
*
|
|
1486
|
+
* @example
|
|
1487
|
+
* ```typescript
|
|
1488
|
+
* const session = await solvaPay.createCustomerSession({
|
|
1489
|
+
* customerRef: 'user_123'
|
|
1490
|
+
* });
|
|
1491
|
+
*
|
|
1492
|
+
* // Redirect customer to portal
|
|
1493
|
+
* window.location.href = session.customerUrl;
|
|
1494
|
+
* ```
|
|
1495
|
+
*/
|
|
1496
|
+
createCustomerSession(params: {
|
|
697
1497
|
customerRef: string;
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
1498
|
+
}): Promise<{
|
|
1499
|
+
sessionId: string;
|
|
1500
|
+
customerUrl: string;
|
|
701
1501
|
}>;
|
|
702
1502
|
/**
|
|
703
|
-
* Direct access to the API client for advanced operations
|
|
704
|
-
*
|
|
1503
|
+
* Direct access to the API client for advanced operations.
|
|
1504
|
+
*
|
|
1505
|
+
* Use this for operations not exposed by the SolvaPay interface,
|
|
1506
|
+
* such as product/plan management or custom API calls.
|
|
1507
|
+
*
|
|
1508
|
+
* @example
|
|
1509
|
+
* ```typescript
|
|
1510
|
+
* // Access API client directly for custom operations
|
|
1511
|
+
* const products = await solvaPay.apiClient.listProducts();
|
|
1512
|
+
* ```
|
|
705
1513
|
*/
|
|
706
1514
|
apiClient: SolvaPayClient;
|
|
707
1515
|
}
|
|
708
1516
|
/**
|
|
709
|
-
* Create a SolvaPay instance
|
|
1517
|
+
* Create a SolvaPay instance with paywall protection capabilities.
|
|
1518
|
+
*
|
|
1519
|
+
* This factory function creates a SolvaPay instance that can be used to
|
|
1520
|
+
* protect API endpoints, functions, and MCP tools with usage limits and
|
|
1521
|
+
* purchase checks.
|
|
710
1522
|
*
|
|
711
|
-
* @param config -
|
|
712
|
-
* @
|
|
1523
|
+
* @param config - Optional configuration object
|
|
1524
|
+
* @param config.apiKey - API key for production use (defaults to `SOLVAPAY_SECRET_KEY` env var)
|
|
1525
|
+
* @param config.apiClient - Custom API client for testing or advanced use cases
|
|
1526
|
+
* @param config.apiBaseUrl - Optional API base URL override
|
|
1527
|
+
* @returns SolvaPay instance with payable() method and API client access
|
|
713
1528
|
*
|
|
714
1529
|
* @example
|
|
715
1530
|
* ```typescript
|
|
716
|
-
* // Production:
|
|
1531
|
+
* // Production: Use environment variable (recommended)
|
|
1532
|
+
* const solvaPay = createSolvaPay();
|
|
1533
|
+
*
|
|
1534
|
+
* // Production: Pass API key explicitly
|
|
717
1535
|
* const solvaPay = createSolvaPay({
|
|
718
1536
|
* apiKey: process.env.SOLVAPAY_SECRET_KEY
|
|
719
1537
|
* });
|
|
720
1538
|
*
|
|
721
|
-
* // Testing:
|
|
1539
|
+
* // Testing: Use mock client
|
|
722
1540
|
* const solvaPay = createSolvaPay({
|
|
723
1541
|
* apiClient: mockClient
|
|
724
1542
|
* });
|
|
725
1543
|
*
|
|
726
|
-
* // Create payable handlers
|
|
727
|
-
* const payable = solvaPay.payable({
|
|
728
|
-
*
|
|
729
|
-
*
|
|
1544
|
+
* // Create payable handlers for your product
|
|
1545
|
+
* const payable = solvaPay.payable({
|
|
1546
|
+
* product: 'prd_myapi',
|
|
1547
|
+
* plan: 'pln_premium'
|
|
1548
|
+
* });
|
|
1549
|
+
*
|
|
1550
|
+
* // Protect endpoints with framework-specific adapters
|
|
1551
|
+
* app.post('/tasks', payable.http(createTask)); // Express/Fastify
|
|
1552
|
+
* export const POST = payable.next(createTask); // Next.js App Router
|
|
1553
|
+
* const handler = payable.mcp(createTask); // MCP servers
|
|
730
1554
|
* ```
|
|
1555
|
+
*
|
|
1556
|
+
* @see {@link SolvaPay} for the returned instance interface
|
|
1557
|
+
* @see {@link CreateSolvaPayConfig} for configuration options
|
|
1558
|
+
* @since 1.0.0
|
|
731
1559
|
*/
|
|
732
|
-
declare function createSolvaPay(config
|
|
1560
|
+
declare function createSolvaPay(config?: CreateSolvaPayConfig): SolvaPay;
|
|
733
1561
|
|
|
734
1562
|
/**
|
|
735
1563
|
* SolvaPay SDK - Universal Paywall Protection
|
|
@@ -740,61 +1568,78 @@ declare function createSolvaPay(config: CreateSolvaPayConfig): SolvaPay;
|
|
|
740
1568
|
* - Class-based and functional programming
|
|
741
1569
|
*/
|
|
742
1570
|
|
|
1571
|
+
/**
|
|
1572
|
+
* Error thrown when a paywall is triggered (purchase required or usage limit exceeded).
|
|
1573
|
+
*
|
|
1574
|
+
* This error is automatically thrown by the paywall protection system when:
|
|
1575
|
+
* - Customer doesn't have required purchase
|
|
1576
|
+
* - Customer has exceeded usage limits
|
|
1577
|
+
* - Customer needs to upgrade their plan
|
|
1578
|
+
*
|
|
1579
|
+
* The error includes structured content with checkout URLs and metadata for
|
|
1580
|
+
* building custom paywall UIs.
|
|
1581
|
+
*
|
|
1582
|
+
* @example
|
|
1583
|
+
* ```typescript
|
|
1584
|
+
* import { PaywallError } from '@solvapay/server';
|
|
1585
|
+
*
|
|
1586
|
+
* try {
|
|
1587
|
+
* const result = await payable.http(createTask)(req, res);
|
|
1588
|
+
* return result;
|
|
1589
|
+
* } catch (error) {
|
|
1590
|
+
* if (error instanceof PaywallError) {
|
|
1591
|
+
* // Custom paywall handling
|
|
1592
|
+
* return res.status(402).json({
|
|
1593
|
+
* error: error.message,
|
|
1594
|
+
* checkoutUrl: error.structuredContent.checkoutUrl,
|
|
1595
|
+
* // Additional metadata available in error.structuredContent
|
|
1596
|
+
* });
|
|
1597
|
+
* }
|
|
1598
|
+
* throw error;
|
|
1599
|
+
* }
|
|
1600
|
+
* ```
|
|
1601
|
+
*
|
|
1602
|
+
* @see {@link PaywallStructuredContent} for the structured content format
|
|
1603
|
+
* @since 1.0.0
|
|
1604
|
+
*/
|
|
743
1605
|
declare class PaywallError extends Error {
|
|
744
1606
|
structuredContent: PaywallStructuredContent;
|
|
1607
|
+
/**
|
|
1608
|
+
* Creates a new PaywallError instance.
|
|
1609
|
+
*
|
|
1610
|
+
* @param message - Error message
|
|
1611
|
+
* @param structuredContent - Structured content with checkout URLs and metadata
|
|
1612
|
+
*/
|
|
745
1613
|
constructor(message: string, structuredContent: PaywallStructuredContent);
|
|
746
1614
|
}
|
|
747
1615
|
|
|
748
1616
|
/**
|
|
749
1617
|
* Utility functions for the SolvaPay Server SDK
|
|
750
1618
|
*/
|
|
1619
|
+
|
|
751
1620
|
/**
|
|
752
|
-
*
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
*/
|
|
758
|
-
maxRetries?: number;
|
|
759
|
-
/**
|
|
760
|
-
* Initial delay between retries in milliseconds (default: 500)
|
|
761
|
-
*/
|
|
762
|
-
initialDelay?: number;
|
|
763
|
-
/**
|
|
764
|
-
* Backoff strategy for calculating delay between retries (default: 'fixed')
|
|
765
|
-
* - 'fixed': Same delay between all retries
|
|
766
|
-
* - 'linear': Delay increases linearly (initialDelay * attempt)
|
|
767
|
-
* - 'exponential': Delay doubles each attempt (initialDelay * 2^(attempt-1))
|
|
768
|
-
*/
|
|
769
|
-
backoffStrategy?: 'fixed' | 'linear' | 'exponential';
|
|
770
|
-
/**
|
|
771
|
-
* Optional function to determine if a retry should be attempted based on the error
|
|
772
|
-
* @param error The error that was thrown
|
|
773
|
-
* @param attempt The current attempt number (0-indexed)
|
|
774
|
-
* @returns true if a retry should be attempted, false otherwise
|
|
775
|
-
*/
|
|
776
|
-
shouldRetry?: (error: Error, attempt: number) => boolean;
|
|
777
|
-
/**
|
|
778
|
-
* Optional callback invoked before each retry attempt
|
|
779
|
-
* @param error The error that triggered the retry
|
|
780
|
-
* @param attempt The current attempt number (0-indexed)
|
|
781
|
-
*/
|
|
782
|
-
onRetry?: (error: Error, attempt: number) => void;
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* Executes an async function with automatic retry logic
|
|
1621
|
+
* Execute an async function with automatic retry logic.
|
|
1622
|
+
*
|
|
1623
|
+
* This utility function provides configurable retry logic with exponential backoff,
|
|
1624
|
+
* conditional retry logic, and retry callbacks. Useful for handling transient
|
|
1625
|
+
* network errors or rate limiting.
|
|
786
1626
|
*
|
|
787
1627
|
* @template T The return type of the async function
|
|
788
1628
|
* @param fn The async function to execute
|
|
789
1629
|
* @param options Retry configuration options
|
|
1630
|
+
* @param options.maxRetries - Maximum number of retry attempts (default: 2)
|
|
1631
|
+
* @param options.initialDelay - Initial delay in milliseconds before first retry (default: 500)
|
|
1632
|
+
* @param options.backoffStrategy - Backoff strategy: 'fixed', 'linear', or 'exponential' (default: 'fixed')
|
|
1633
|
+
* @param options.shouldRetry - Optional function to determine if error should be retried
|
|
1634
|
+
* @param options.onRetry - Optional callback called before each retry attempt
|
|
790
1635
|
* @returns A promise that resolves with the function result or rejects with the last error
|
|
791
1636
|
*
|
|
792
1637
|
* @example
|
|
793
1638
|
* ```typescript
|
|
794
|
-
* // Simple retry with defaults
|
|
1639
|
+
* // Simple retry with defaults (2 retries, 500ms delay)
|
|
795
1640
|
* const result = await withRetry(() => apiCall());
|
|
796
1641
|
*
|
|
797
|
-
* // Custom retry with
|
|
1642
|
+
* // Custom retry with exponential backoff
|
|
798
1643
|
* const result = await withRetry(
|
|
799
1644
|
* () => apiCall(),
|
|
800
1645
|
* {
|
|
@@ -806,9 +1651,326 @@ interface RetryOptions {
|
|
|
806
1651
|
* }
|
|
807
1652
|
* );
|
|
808
1653
|
* ```
|
|
1654
|
+
*
|
|
1655
|
+
* @since 1.0.0
|
|
809
1656
|
*/
|
|
810
1657
|
declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
811
1658
|
|
|
1659
|
+
/**
|
|
1660
|
+
* Helper Types
|
|
1661
|
+
*
|
|
1662
|
+
* Shared types for route helpers
|
|
1663
|
+
*/
|
|
1664
|
+
/**
|
|
1665
|
+
* Error result returned by core helpers
|
|
1666
|
+
*/
|
|
1667
|
+
interface ErrorResult {
|
|
1668
|
+
error: string;
|
|
1669
|
+
status: number;
|
|
1670
|
+
details?: string;
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
* Authenticated user information
|
|
1674
|
+
*/
|
|
1675
|
+
interface AuthenticatedUser {
|
|
1676
|
+
userId: string;
|
|
1677
|
+
email?: string | null;
|
|
1678
|
+
name?: string | null;
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
/**
|
|
1682
|
+
* Error Handling Helper
|
|
1683
|
+
*
|
|
1684
|
+
* Generic error handling utilities for route helpers
|
|
1685
|
+
*/
|
|
1686
|
+
|
|
1687
|
+
/**
|
|
1688
|
+
* Check if a result is an error result
|
|
1689
|
+
*/
|
|
1690
|
+
declare function isErrorResult(result: unknown): result is ErrorResult;
|
|
1691
|
+
/**
|
|
1692
|
+
* Handle route errors and convert to ErrorResult
|
|
1693
|
+
*/
|
|
1694
|
+
declare function handleRouteError(error: unknown, operationName: string, defaultMessage?: string): ErrorResult;
|
|
1695
|
+
|
|
1696
|
+
/**
|
|
1697
|
+
* Authentication Helper (Core)
|
|
1698
|
+
*
|
|
1699
|
+
* Generic helper for extracting authenticated user information from requests.
|
|
1700
|
+
* Works with standard Web API Request (works everywhere).
|
|
1701
|
+
*/
|
|
1702
|
+
|
|
1703
|
+
/**
|
|
1704
|
+
* Extract authenticated user information from a standard Web API Request.
|
|
1705
|
+
*
|
|
1706
|
+
* This is a generic, framework-agnostic helper that extracts user ID, email,
|
|
1707
|
+
* and name from authenticated requests. Works with any framework that uses
|
|
1708
|
+
* the standard Web API Request (Express, Fastify, Next.js, Edge Functions, etc.).
|
|
1709
|
+
*
|
|
1710
|
+
* Uses dynamic imports to avoid requiring @solvapay/auth at build time,
|
|
1711
|
+
* making it suitable for edge runtime environments.
|
|
1712
|
+
*
|
|
1713
|
+
* @param request - Standard Web API Request object
|
|
1714
|
+
* @param options - Configuration options
|
|
1715
|
+
* @param options.includeEmail - Whether to extract email from JWT token (default: true)
|
|
1716
|
+
* @param options.includeName - Whether to extract name from JWT token (default: true)
|
|
1717
|
+
* @returns Authenticated user info or error result
|
|
1718
|
+
*
|
|
1719
|
+
* @example
|
|
1720
|
+
* ```typescript
|
|
1721
|
+
* // In an API route handler
|
|
1722
|
+
* export async function GET(request: Request) {
|
|
1723
|
+
* const userResult = await getAuthenticatedUserCore(request);
|
|
1724
|
+
*
|
|
1725
|
+
* if (isErrorResult(userResult)) {
|
|
1726
|
+
* return Response.json(userResult, { status: userResult.status });
|
|
1727
|
+
* }
|
|
1728
|
+
*
|
|
1729
|
+
* const { userId, email, name } = userResult;
|
|
1730
|
+
* // Use user info...
|
|
1731
|
+
* }
|
|
1732
|
+
* ```
|
|
1733
|
+
*
|
|
1734
|
+
* @see {@link AuthenticatedUser} for the return type
|
|
1735
|
+
* @see {@link ErrorResult} for error handling
|
|
1736
|
+
* @since 1.0.0
|
|
1737
|
+
*/
|
|
1738
|
+
declare function getAuthenticatedUserCore(request: Request, options?: {
|
|
1739
|
+
includeEmail?: boolean;
|
|
1740
|
+
includeName?: boolean;
|
|
1741
|
+
}): Promise<AuthenticatedUser | ErrorResult>;
|
|
1742
|
+
|
|
1743
|
+
/**
|
|
1744
|
+
* Customer Helper (Core)
|
|
1745
|
+
*
|
|
1746
|
+
* Generic helper for syncing customers with SolvaPay backend.
|
|
1747
|
+
* Works with standard Web API Request (works everywhere).
|
|
1748
|
+
*/
|
|
1749
|
+
|
|
1750
|
+
/**
|
|
1751
|
+
* Sync customer with SolvaPay backend (ensure customer exists).
|
|
1752
|
+
*
|
|
1753
|
+
* This helper ensures a customer exists in the SolvaPay backend by:
|
|
1754
|
+
* 1. Extracting authenticated user information from the request
|
|
1755
|
+
* 2. Creating or retrieving the customer using the user ID as external reference
|
|
1756
|
+
* 3. Syncing customer data (email, name) if provided
|
|
1757
|
+
*
|
|
1758
|
+
* Uses `externalRef` for consistent lookup and prevents duplicate customers.
|
|
1759
|
+
* The returned customer reference is the SolvaPay backend customer ID.
|
|
1760
|
+
*
|
|
1761
|
+
* @param request - Standard Web API Request object
|
|
1762
|
+
* @param options - Configuration options
|
|
1763
|
+
* @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
|
|
1764
|
+
* @param options.includeEmail - Whether to include email in customer data (default: true)
|
|
1765
|
+
* @param options.includeName - Whether to include name in customer data (default: true)
|
|
1766
|
+
* @returns Customer reference (backend customer ID) or error result
|
|
1767
|
+
*
|
|
1768
|
+
* @example
|
|
1769
|
+
* ```typescript
|
|
1770
|
+
* // In an API route handler
|
|
1771
|
+
* export async function POST(request: Request) {
|
|
1772
|
+
* const customerResult = await syncCustomerCore(request);
|
|
1773
|
+
*
|
|
1774
|
+
* if (isErrorResult(customerResult)) {
|
|
1775
|
+
* return Response.json(customerResult, { status: customerResult.status });
|
|
1776
|
+
* }
|
|
1777
|
+
*
|
|
1778
|
+
* const customerRef = customerResult;
|
|
1779
|
+
* // Use customer reference...
|
|
1780
|
+
* }
|
|
1781
|
+
* ```
|
|
1782
|
+
*
|
|
1783
|
+
* @see {@link getAuthenticatedUserCore} for user extraction
|
|
1784
|
+
* @see {@link ErrorResult} for error handling
|
|
1785
|
+
* @since 1.0.0
|
|
1786
|
+
*/
|
|
1787
|
+
declare function syncCustomerCore(request: Request, options?: {
|
|
1788
|
+
solvaPay?: SolvaPay;
|
|
1789
|
+
includeEmail?: boolean;
|
|
1790
|
+
includeName?: boolean;
|
|
1791
|
+
}): Promise<string | ErrorResult>;
|
|
1792
|
+
|
|
1793
|
+
/**
|
|
1794
|
+
* Create a Stripe payment intent for a customer to purchase a plan.
|
|
1795
|
+
*
|
|
1796
|
+
* This is a framework-agnostic helper that:
|
|
1797
|
+
* 1. Extracts authenticated user from the request
|
|
1798
|
+
* 2. Syncs customer with SolvaPay backend
|
|
1799
|
+
* 3. Creates a payment intent for the specified plan
|
|
1800
|
+
*
|
|
1801
|
+
* The payment intent can then be confirmed on the client side using Stripe.js.
|
|
1802
|
+
* After confirmation, use `processPaymentIntentCore()` to complete the purchase.
|
|
1803
|
+
*
|
|
1804
|
+
* @param request - Standard Web API Request object
|
|
1805
|
+
* @param body - Payment intent parameters
|
|
1806
|
+
* @param body.planRef - Plan reference to purchase (required)
|
|
1807
|
+
* @param body.productRef - Product reference (required)
|
|
1808
|
+
* @param options - Configuration options
|
|
1809
|
+
* @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
|
|
1810
|
+
* @param options.includeEmail - Whether to include email in customer data (default: true)
|
|
1811
|
+
* @param options.includeName - Whether to include name in customer data (default: true)
|
|
1812
|
+
* @returns Payment intent response with client secret and customer reference, or error result
|
|
1813
|
+
*
|
|
1814
|
+
* @example
|
|
1815
|
+
* ```typescript
|
|
1816
|
+
* // In an API route handler
|
|
1817
|
+
* export async function POST(request: Request) {
|
|
1818
|
+
* const body = await request.json();
|
|
1819
|
+
* const result = await createPaymentIntentCore(request, body);
|
|
1820
|
+
*
|
|
1821
|
+
* if (isErrorResult(result)) {
|
|
1822
|
+
* return Response.json(result, { status: result.status });
|
|
1823
|
+
* }
|
|
1824
|
+
*
|
|
1825
|
+
* return Response.json(result);
|
|
1826
|
+
* }
|
|
1827
|
+
* ```
|
|
1828
|
+
*
|
|
1829
|
+
* @see {@link processPaymentIntentCore} for processing confirmed payments
|
|
1830
|
+
* @see {@link ErrorResult} for error handling
|
|
1831
|
+
* @since 1.0.0
|
|
1832
|
+
*/
|
|
1833
|
+
declare function createPaymentIntentCore(request: Request, body: {
|
|
1834
|
+
planRef: string;
|
|
1835
|
+
productRef: string;
|
|
1836
|
+
}, options?: {
|
|
1837
|
+
solvaPay?: SolvaPay;
|
|
1838
|
+
includeEmail?: boolean;
|
|
1839
|
+
includeName?: boolean;
|
|
1840
|
+
}): Promise<{
|
|
1841
|
+
id: string;
|
|
1842
|
+
clientSecret: string;
|
|
1843
|
+
publishableKey: string;
|
|
1844
|
+
accountId?: string;
|
|
1845
|
+
customerRef: string;
|
|
1846
|
+
} | ErrorResult>;
|
|
1847
|
+
/**
|
|
1848
|
+
* Process a payment intent after client-side Stripe confirmation.
|
|
1849
|
+
*
|
|
1850
|
+
* This helper processes a payment intent that has been confirmed on the client
|
|
1851
|
+
* side using Stripe.js. It creates the purchase immediately,
|
|
1852
|
+
* eliminating webhook delay.
|
|
1853
|
+
*
|
|
1854
|
+
* Call this after the client has confirmed the payment intent with Stripe.js.
|
|
1855
|
+
*
|
|
1856
|
+
* @param request - Standard Web API Request object
|
|
1857
|
+
* @param body - Payment processing parameters
|
|
1858
|
+
* @param body.paymentIntentId - Stripe payment intent ID from client confirmation (required)
|
|
1859
|
+
* @param body.productRef - Product reference (required)
|
|
1860
|
+
* @param body.planRef - Optional plan reference (if not in payment intent)
|
|
1861
|
+
* @param options - Configuration options
|
|
1862
|
+
* @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
|
|
1863
|
+
* @returns Process payment result with purchase details, or error result
|
|
1864
|
+
*
|
|
1865
|
+
* @example
|
|
1866
|
+
* ```typescript
|
|
1867
|
+
* // In an API route handler
|
|
1868
|
+
* export async function POST(request: Request) {
|
|
1869
|
+
* const body = await request.json();
|
|
1870
|
+
* const result = await processPaymentIntentCore(request, body);
|
|
1871
|
+
*
|
|
1872
|
+
* if (isErrorResult(result)) {
|
|
1873
|
+
* return Response.json(result, { status: result.status });
|
|
1874
|
+
* }
|
|
1875
|
+
*
|
|
1876
|
+
* return Response.json(result);
|
|
1877
|
+
* }
|
|
1878
|
+
* ```
|
|
1879
|
+
*
|
|
1880
|
+
* @see {@link createPaymentIntentCore} for creating payment intents
|
|
1881
|
+
* @see {@link ErrorResult} for error handling
|
|
1882
|
+
* @since 1.0.0
|
|
1883
|
+
*/
|
|
1884
|
+
declare function processPaymentIntentCore(request: Request, body: {
|
|
1885
|
+
paymentIntentId: string;
|
|
1886
|
+
productRef: string;
|
|
1887
|
+
planRef?: string;
|
|
1888
|
+
}, options?: {
|
|
1889
|
+
solvaPay?: SolvaPay;
|
|
1890
|
+
}): Promise<ProcessPaymentResult | ErrorResult>;
|
|
1891
|
+
|
|
1892
|
+
/**
|
|
1893
|
+
* Checkout Helpers (Core)
|
|
1894
|
+
*
|
|
1895
|
+
* Generic helpers for checkout session operations.
|
|
1896
|
+
* Works with standard Web API Request (works everywhere).
|
|
1897
|
+
*/
|
|
1898
|
+
|
|
1899
|
+
/**
|
|
1900
|
+
* Create checkout session - core implementation
|
|
1901
|
+
*
|
|
1902
|
+
* @param request - Standard Web API Request
|
|
1903
|
+
* @param body - Checkout session parameters
|
|
1904
|
+
* @param options - Configuration options
|
|
1905
|
+
* @returns Checkout session response or error result
|
|
1906
|
+
*/
|
|
1907
|
+
declare function createCheckoutSessionCore(request: Request, body: {
|
|
1908
|
+
productRef: string;
|
|
1909
|
+
planRef?: string;
|
|
1910
|
+
returnUrl?: string;
|
|
1911
|
+
}, options?: {
|
|
1912
|
+
solvaPay?: SolvaPay;
|
|
1913
|
+
includeEmail?: boolean;
|
|
1914
|
+
includeName?: boolean;
|
|
1915
|
+
returnUrl?: string;
|
|
1916
|
+
}): Promise<{
|
|
1917
|
+
sessionId: string;
|
|
1918
|
+
checkoutUrl: string;
|
|
1919
|
+
} | ErrorResult>;
|
|
1920
|
+
/**
|
|
1921
|
+
* Create customer session - core implementation
|
|
1922
|
+
*
|
|
1923
|
+
* @param request - Standard Web API Request
|
|
1924
|
+
* @param options - Configuration options
|
|
1925
|
+
* @returns Customer session response or error result
|
|
1926
|
+
*/
|
|
1927
|
+
declare function createCustomerSessionCore(request: Request, options?: {
|
|
1928
|
+
solvaPay?: SolvaPay;
|
|
1929
|
+
includeEmail?: boolean;
|
|
1930
|
+
includeName?: boolean;
|
|
1931
|
+
}): Promise<{
|
|
1932
|
+
sessionId: string;
|
|
1933
|
+
customerUrl: string;
|
|
1934
|
+
} | ErrorResult>;
|
|
1935
|
+
|
|
1936
|
+
/**
|
|
1937
|
+
* Purchase Cancellation Helpers (Core)
|
|
1938
|
+
*
|
|
1939
|
+
* Generic helpers for purchase cancellation operations.
|
|
1940
|
+
* Works with standard Web API Request (works everywhere).
|
|
1941
|
+
*/
|
|
1942
|
+
|
|
1943
|
+
/**
|
|
1944
|
+
* Cancel purchase - core implementation
|
|
1945
|
+
*
|
|
1946
|
+
* @param request - Standard Web API Request
|
|
1947
|
+
* @param body - Cancellation parameters
|
|
1948
|
+
* @param options - Configuration options
|
|
1949
|
+
* @returns Cancelled purchase response or error result
|
|
1950
|
+
*/
|
|
1951
|
+
declare function cancelPurchaseCore(request: Request, body: {
|
|
1952
|
+
purchaseRef: string;
|
|
1953
|
+
reason?: string;
|
|
1954
|
+
}, options?: {
|
|
1955
|
+
solvaPay?: SolvaPay;
|
|
1956
|
+
}): Promise<Record<string, unknown> | ErrorResult>;
|
|
1957
|
+
|
|
1958
|
+
/**
|
|
1959
|
+
* Plans Helper (Core)
|
|
1960
|
+
*
|
|
1961
|
+
* Generic helper for listing plans.
|
|
1962
|
+
* Works with standard Web API Request (works everywhere).
|
|
1963
|
+
* This is a public route - no authentication required.
|
|
1964
|
+
*/
|
|
1965
|
+
|
|
1966
|
+
/**
|
|
1967
|
+
* List plans - core implementation
|
|
1968
|
+
*/
|
|
1969
|
+
declare function listPlansCore(request: Request): Promise<{
|
|
1970
|
+
plans: Record<string, unknown>[];
|
|
1971
|
+
productRef: string;
|
|
1972
|
+
} | ErrorResult>;
|
|
1973
|
+
|
|
812
1974
|
/**
|
|
813
1975
|
* SolvaPay Server SDK - Edge Runtime Entry Point
|
|
814
1976
|
*
|
|
@@ -836,10 +1998,10 @@ declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Pro
|
|
|
836
1998
|
* const event = await verifyWebhook({ body, signature, secret });
|
|
837
1999
|
* ```
|
|
838
2000
|
*/
|
|
839
|
-
declare function verifyWebhook({ body, signature, secret }: {
|
|
2001
|
+
declare function verifyWebhook({ body, signature, secret, }: {
|
|
840
2002
|
body: string;
|
|
841
2003
|
signature: string;
|
|
842
2004
|
secret: string;
|
|
843
2005
|
}): Promise<any>;
|
|
844
2006
|
|
|
845
|
-
export { type CreateSolvaPayConfig, type HttpAdapterOptions, type McpAdapterOptions, type NextAdapterOptions, type PayableFunction, type PayableOptions, type PaywallArgs, PaywallError, type PaywallMetadata, type PaywallStructuredContent, type PaywallToolResult, type RetryOptions
|
|
2007
|
+
export { type AuthenticatedUser, type CreateSolvaPayConfig, type ErrorResult, type HttpAdapterOptions, type McpAdapterOptions, type NextAdapterOptions, type PayableFunction, type PayableOptions, type PaywallArgs, PaywallError, type PaywallMetadata, type PaywallStructuredContent, type PaywallToolResult, type RetryOptions, type ServerClientOptions, type SolvaPay, type SolvaPayClient, cancelPurchaseCore, createCheckoutSessionCore, createCustomerSessionCore, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, getAuthenticatedUserCore, handleRouteError, isErrorResult, listPlansCore, processPaymentIntentCore, syncCustomerCore, verifyWebhook, withRetry };
|