@solvapay/next 1.0.9-preview.1 → 1.0.9
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/index.cjs +101 -151
- package/dist/index.d.cts +221 -55
- package/dist/index.d.ts +221 -55
- package/dist/index.js +92 -147
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
|
-
import
|
|
3
|
-
import { AuthenticatedUser, SolvaPay, CustomerBalanceResult, ActivatePlanResult, listPlansCore } from '@solvapay/server';
|
|
2
|
+
import { AuthenticatedUser, SolvaPay } from '@solvapay/server';
|
|
4
3
|
export { AuthMiddlewareOptions, SupabaseAuthMiddlewareOptions, createAuthMiddleware, createSupabaseAuthMiddleware } from './middleware.cjs';
|
|
5
4
|
import '@solvapay/auth';
|
|
6
5
|
|
|
@@ -189,11 +188,24 @@ declare function getAuthenticatedUser(request: globalThis.Request, options?: {
|
|
|
189
188
|
*/
|
|
190
189
|
|
|
191
190
|
/**
|
|
192
|
-
*
|
|
191
|
+
* Get the authenticated customer's SolvaPay reference.
|
|
193
192
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
193
|
+
* Unlike the other route-wrapper helpers, this one returns the raw customer
|
|
194
|
+
* reference string on success so callers can use it to build their own
|
|
195
|
+
* response body. Errors are still returned as a `NextResponse`.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* // app/api/sync-customer/route.ts
|
|
200
|
+
* import { NextResponse } from 'next/server'
|
|
201
|
+
* import { syncCustomer } from '@solvapay/next/helpers'
|
|
202
|
+
*
|
|
203
|
+
* export async function POST(request: Request) {
|
|
204
|
+
* const result = await syncCustomer(request)
|
|
205
|
+
* if (result instanceof NextResponse) return result
|
|
206
|
+
* return NextResponse.json({ customerRef: result })
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
197
209
|
*/
|
|
198
210
|
declare function syncCustomer(request: globalThis.Request, options?: {
|
|
199
211
|
solvaPay?: SolvaPay;
|
|
@@ -201,16 +213,37 @@ declare function syncCustomer(request: globalThis.Request, options?: {
|
|
|
201
213
|
includeName?: boolean;
|
|
202
214
|
}): Promise<string | NextResponse>;
|
|
203
215
|
/**
|
|
204
|
-
*
|
|
216
|
+
* Next.js route wrapper for GET /api/customer-balance.
|
|
205
217
|
*
|
|
206
|
-
* @
|
|
207
|
-
*
|
|
208
|
-
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* // app/api/customer-balance/route.ts
|
|
221
|
+
* import { getCustomerBalance } from '@solvapay/next/helpers'
|
|
222
|
+
* export const GET = (request: Request) => getCustomerBalance(request)
|
|
223
|
+
* ```
|
|
209
224
|
*/
|
|
210
225
|
declare function getCustomerBalance(request: globalThis.Request, options?: {
|
|
211
226
|
solvaPay?: SolvaPay;
|
|
212
|
-
}): Promise<
|
|
227
|
+
}): Promise<NextResponse>;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Next.js Payment Helpers
|
|
231
|
+
*/
|
|
213
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Next.js route wrapper for POST /api/create-payment-intent.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* // app/api/create-payment-intent/route.ts
|
|
239
|
+
* import { createPaymentIntent } from '@solvapay/next/helpers'
|
|
240
|
+
*
|
|
241
|
+
* export async function POST(request: Request) {
|
|
242
|
+
* const { planRef, productRef } = await request.json()
|
|
243
|
+
* return createPaymentIntent(request, { planRef, productRef })
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
214
247
|
declare function createPaymentIntent(request: globalThis.Request, body: {
|
|
215
248
|
planRef: string;
|
|
216
249
|
productRef: string;
|
|
@@ -218,13 +251,21 @@ declare function createPaymentIntent(request: globalThis.Request, body: {
|
|
|
218
251
|
solvaPay?: SolvaPay;
|
|
219
252
|
includeEmail?: boolean;
|
|
220
253
|
includeName?: boolean;
|
|
221
|
-
}): Promise<
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
254
|
+
}): Promise<NextResponse>;
|
|
255
|
+
/**
|
|
256
|
+
* Next.js route wrapper for POST /api/create-topup-payment-intent.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* // app/api/create-topup-payment-intent/route.ts
|
|
261
|
+
* import { createTopupPaymentIntent } from '@solvapay/next/helpers'
|
|
262
|
+
*
|
|
263
|
+
* export async function POST(request: Request) {
|
|
264
|
+
* const { amount, currency, description } = await request.json()
|
|
265
|
+
* return createTopupPaymentIntent(request, { amount, currency, description })
|
|
266
|
+
* }
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
228
269
|
declare function createTopupPaymentIntent(request: globalThis.Request, body: {
|
|
229
270
|
amount: number;
|
|
230
271
|
currency: string;
|
|
@@ -233,25 +274,46 @@ declare function createTopupPaymentIntent(request: globalThis.Request, body: {
|
|
|
233
274
|
solvaPay?: SolvaPay;
|
|
234
275
|
includeEmail?: boolean;
|
|
235
276
|
includeName?: boolean;
|
|
236
|
-
}): Promise<
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
277
|
+
}): Promise<NextResponse>;
|
|
278
|
+
/**
|
|
279
|
+
* Next.js route wrapper for POST /api/process-payment.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```ts
|
|
283
|
+
* // app/api/process-payment/route.ts
|
|
284
|
+
* import { processPaymentIntent } from '@solvapay/next/helpers'
|
|
285
|
+
*
|
|
286
|
+
* export async function POST(request: Request) {
|
|
287
|
+
* const { paymentIntentId, productRef, planRef } = await request.json()
|
|
288
|
+
* return processPaymentIntent(request, { paymentIntentId, productRef, planRef })
|
|
289
|
+
* }
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
243
292
|
declare function processPaymentIntent(request: globalThis.Request, body: {
|
|
244
293
|
paymentIntentId: string;
|
|
245
294
|
productRef: string;
|
|
246
295
|
planRef?: string;
|
|
247
296
|
}, options?: {
|
|
248
297
|
solvaPay?: SolvaPay;
|
|
249
|
-
}): Promise<
|
|
298
|
+
}): Promise<NextResponse>;
|
|
250
299
|
|
|
251
300
|
/**
|
|
252
301
|
* Next.js Checkout Helpers
|
|
253
302
|
*/
|
|
254
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Next.js route wrapper for POST /api/create-checkout-session.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```ts
|
|
308
|
+
* // app/api/create-checkout-session/route.ts
|
|
309
|
+
* import { createCheckoutSession } from '@solvapay/next/helpers'
|
|
310
|
+
*
|
|
311
|
+
* export async function POST(request: Request) {
|
|
312
|
+
* const { productRef, planRef } = await request.json()
|
|
313
|
+
* return createCheckoutSession(request, { productRef, planRef })
|
|
314
|
+
* }
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
255
317
|
declare function createCheckoutSession(request: globalThis.Request, body: {
|
|
256
318
|
productRef: string;
|
|
257
319
|
planRef?: string;
|
|
@@ -261,19 +323,40 @@ declare function createCheckoutSession(request: globalThis.Request, body: {
|
|
|
261
323
|
includeEmail?: boolean;
|
|
262
324
|
includeName?: boolean;
|
|
263
325
|
returnUrl?: string;
|
|
264
|
-
}): Promise<
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
326
|
+
}): Promise<NextResponse>;
|
|
327
|
+
/**
|
|
328
|
+
* Next.js route wrapper for POST /api/create-customer-session.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```ts
|
|
332
|
+
* // app/api/create-customer-session/route.ts
|
|
333
|
+
* import { createCustomerSession } from '@solvapay/next/helpers'
|
|
334
|
+
* export const POST = (request: Request) => createCustomerSession(request)
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
268
337
|
declare function createCustomerSession(request: globalThis.Request, options?: {
|
|
269
338
|
solvaPay?: SolvaPay;
|
|
270
339
|
includeEmail?: boolean;
|
|
271
340
|
includeName?: boolean;
|
|
272
|
-
}): Promise<
|
|
273
|
-
sessionId: string;
|
|
274
|
-
customerUrl: string;
|
|
275
|
-
} | NextResponse>;
|
|
341
|
+
}): Promise<NextResponse>;
|
|
276
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Next.js route wrapper for POST /api/activate-plan.
|
|
345
|
+
*
|
|
346
|
+
* Clears the purchase cache for the authenticated user on success so the
|
|
347
|
+
* next `checkPurchase` sees the new plan immediately.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* // app/api/activate-plan/route.ts
|
|
352
|
+
* import { activatePlan } from '@solvapay/next/helpers'
|
|
353
|
+
*
|
|
354
|
+
* export async function POST(request: Request) {
|
|
355
|
+
* const { productRef, planRef } = await request.json()
|
|
356
|
+
* return activatePlan(request, { productRef, planRef })
|
|
357
|
+
* }
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
277
360
|
declare function activatePlan(request: globalThis.Request, body: {
|
|
278
361
|
productRef: string;
|
|
279
362
|
planRef: string;
|
|
@@ -281,49 +364,125 @@ declare function activatePlan(request: globalThis.Request, body: {
|
|
|
281
364
|
solvaPay?: SolvaPay;
|
|
282
365
|
includeEmail?: boolean;
|
|
283
366
|
includeName?: boolean;
|
|
284
|
-
}): Promise<
|
|
367
|
+
}): Promise<NextResponse>;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Next.js route wrapper around `getPaymentMethodCore`.
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```ts
|
|
374
|
+
* // app/api/payment-method/route.ts
|
|
375
|
+
* import { getPaymentMethod } from '@solvapay/next/helpers'
|
|
376
|
+
* export const GET = (request: Request) => getPaymentMethod(request)
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
declare function getPaymentMethod(request: globalThis.Request, options?: {
|
|
380
|
+
solvaPay?: SolvaPay;
|
|
381
|
+
includeEmail?: boolean;
|
|
382
|
+
includeName?: boolean;
|
|
383
|
+
}): Promise<NextResponse>;
|
|
285
384
|
|
|
286
385
|
/**
|
|
287
386
|
* Next.js Purchase Cancellation & Reactivation Helpers
|
|
288
387
|
*/
|
|
289
388
|
/**
|
|
290
|
-
*
|
|
389
|
+
* Next.js route wrapper for POST /api/cancel-renewal.
|
|
291
390
|
*
|
|
292
|
-
* @
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```ts
|
|
393
|
+
* // app/api/cancel-renewal/route.ts
|
|
394
|
+
* import { cancelRenewal } from '@solvapay/next/helpers'
|
|
395
|
+
*
|
|
396
|
+
* export async function POST(request: Request) {
|
|
397
|
+
* const { purchaseRef, reason } = await request.json()
|
|
398
|
+
* return cancelRenewal(request, { purchaseRef, reason })
|
|
399
|
+
* }
|
|
400
|
+
* ```
|
|
296
401
|
*/
|
|
297
402
|
declare function cancelRenewal(request: globalThis.Request, body: {
|
|
298
403
|
purchaseRef: string;
|
|
299
404
|
reason?: string;
|
|
300
405
|
}, options?: {
|
|
301
406
|
solvaPay?: SolvaPay;
|
|
302
|
-
}): Promise<
|
|
407
|
+
}): Promise<NextResponse>;
|
|
303
408
|
/**
|
|
304
|
-
*
|
|
409
|
+
* Next.js route wrapper for POST /api/reactivate-renewal.
|
|
305
410
|
*
|
|
306
411
|
* Undoes a pending cancellation, restoring auto-renewal.
|
|
307
412
|
*
|
|
308
|
-
* @
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
413
|
+
* @example
|
|
414
|
+
* ```ts
|
|
415
|
+
* // app/api/reactivate-renewal/route.ts
|
|
416
|
+
* import { reactivateRenewal } from '@solvapay/next/helpers'
|
|
417
|
+
*
|
|
418
|
+
* export async function POST(request: Request) {
|
|
419
|
+
* const { purchaseRef } = await request.json()
|
|
420
|
+
* return reactivateRenewal(request, { purchaseRef })
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
312
423
|
*/
|
|
313
424
|
declare function reactivateRenewal(request: globalThis.Request, body: {
|
|
314
425
|
purchaseRef: string;
|
|
315
426
|
}, options?: {
|
|
316
427
|
solvaPay?: SolvaPay;
|
|
317
|
-
}): Promise<
|
|
428
|
+
}): Promise<NextResponse>;
|
|
318
429
|
|
|
319
|
-
type ListPlansSuccess = Exclude<Awaited<ReturnType<typeof listPlansCore>>, {
|
|
320
|
-
error: string;
|
|
321
|
-
}>;
|
|
322
430
|
/**
|
|
323
|
-
* Next.js
|
|
431
|
+
* Next.js route wrapper for GET /api/list-plans?productRef=...
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```ts
|
|
435
|
+
* // app/api/list-plans/route.ts
|
|
436
|
+
* import { listPlans } from '@solvapay/next/helpers'
|
|
437
|
+
* export const GET = (request: Request) => listPlans(request)
|
|
438
|
+
* ```
|
|
324
439
|
*/
|
|
325
|
-
declare function listPlans(request: globalThis.Request
|
|
440
|
+
declare function listPlans(request: globalThis.Request, options?: {
|
|
441
|
+
solvaPay?: SolvaPay;
|
|
442
|
+
}): Promise<NextResponse>;
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Next.js route wrapper for GET /api/merchant.
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```ts
|
|
449
|
+
* // app/api/merchant/route.ts
|
|
450
|
+
* import { getMerchant } from '@solvapay/next/helpers'
|
|
451
|
+
* export const GET = (request: Request) => getMerchant(request)
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
declare function getMerchant(request: globalThis.Request, options?: {
|
|
455
|
+
solvaPay?: SolvaPay;
|
|
456
|
+
}): Promise<NextResponse>;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Next.js route wrapper for GET /api/get-product?productRef=...
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```ts
|
|
463
|
+
* // app/api/get-product/route.ts
|
|
464
|
+
* import { getProduct } from '@solvapay/next/helpers'
|
|
465
|
+
* export const GET = (request: Request) => getProduct(request)
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
declare function getProduct(request: globalThis.Request, options?: {
|
|
469
|
+
solvaPay?: SolvaPay;
|
|
470
|
+
}): Promise<NextResponse>;
|
|
326
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Next.js route wrapper for POST /api/track-usage.
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```ts
|
|
477
|
+
* // app/api/track-usage/route.ts
|
|
478
|
+
* import { trackUsage } from '@solvapay/next/helpers'
|
|
479
|
+
*
|
|
480
|
+
* export async function POST(request: Request) {
|
|
481
|
+
* const body = await request.json()
|
|
482
|
+
* return trackUsage(request, body)
|
|
483
|
+
* }
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
327
486
|
declare function trackUsage(request: globalThis.Request, body: {
|
|
328
487
|
actionType?: 'transaction' | 'api_call' | 'hour' | 'email' | 'storage' | 'custom';
|
|
329
488
|
units?: number;
|
|
@@ -382,7 +541,14 @@ interface CheckPurchaseOptions {
|
|
|
382
541
|
*
|
|
383
542
|
* Delegates to `checkPurchaseCore` from `@solvapay/server` for the actual logic,
|
|
384
543
|
* wrapping with Next.js-specific deduplication and response formatting.
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* ```ts
|
|
547
|
+
* // app/api/check-purchase/route.ts
|
|
548
|
+
* import { checkPurchase } from '@solvapay/next'
|
|
549
|
+
* export const GET = (request: Request) => checkPurchase(request)
|
|
550
|
+
* ```
|
|
385
551
|
*/
|
|
386
|
-
declare function checkPurchase(request: Request, options?: CheckPurchaseOptions): Promise<
|
|
552
|
+
declare function checkPurchase(request: Request, options?: CheckPurchaseOptions): Promise<NextResponse>;
|
|
387
553
|
|
|
388
|
-
export { type CheckPurchaseOptions, type PurchaseCheckResult, type RequestDeduplicationOptions, activatePlan, cancelRenewal, checkPurchase, clearAllPurchaseCache, clearPurchaseCache, createCheckoutSession, createCustomerSession, createPaymentIntent, createTopupPaymentIntent, getAuthenticatedUser, getCustomerBalance, getPurchaseCacheStats, listPlans, processPaymentIntent, reactivateRenewal, syncCustomer, trackUsage };
|
|
554
|
+
export { type CheckPurchaseOptions, type PurchaseCheckResult, type RequestDeduplicationOptions, activatePlan, cancelRenewal, checkPurchase, clearAllPurchaseCache, clearPurchaseCache, createCheckoutSession, createCustomerSession, createPaymentIntent, createTopupPaymentIntent, getAuthenticatedUser, getCustomerBalance, getMerchant, getPaymentMethod, getProduct, getPurchaseCacheStats, listPlans, processPaymentIntent, reactivateRenewal, syncCustomer, trackUsage };
|