@solvapay/next 1.0.0-preview.19 → 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/README.md CHANGED
@@ -14,23 +14,23 @@ npm install @solvapay/next @solvapay/server next
14
14
 
15
15
  All helpers return either a success result or a `NextResponse` error, making them easy to use in Next.js API routes.
16
16
 
17
- ### Check Subscription
17
+ ### Check Purchase
18
18
 
19
- Check user subscription status with built-in request deduplication and caching:
19
+ Check user purchase status with built-in request deduplication and caching:
20
20
 
21
21
  ```typescript
22
22
  import { NextRequest, NextResponse } from 'next/server'
23
- import { checkSubscription } from '@solvapay/next'
23
+ import { checkPurchase } from '@solvapay/next'
24
24
 
25
25
  export async function GET(request: NextRequest) {
26
- const result = await checkSubscription(request)
26
+ const result = await checkPurchase(request)
27
27
 
28
28
  // If result is a NextResponse, it's an error response - return it
29
29
  if (result instanceof NextResponse) {
30
30
  return result
31
31
  }
32
32
 
33
- // Otherwise, return the subscription data
33
+ // Otherwise, return the purchase data
34
34
  return NextResponse.json(result)
35
35
  }
36
36
  ```
@@ -115,22 +115,22 @@ export async function GET(request: NextRequest) {
115
115
  }
116
116
  ```
117
117
 
118
- ### Cancel Subscription
118
+ ### Cancel Renewal
119
119
 
120
- Cancel a user's subscription:
120
+ Cancel renewal of a user's purchase:
121
121
 
122
122
  ```typescript
123
123
  import { NextRequest, NextResponse } from 'next/server'
124
- import { cancelSubscription } from '@solvapay/next'
124
+ import { cancelRenewal } from '@solvapay/next'
125
125
 
126
126
  export async function POST(request: NextRequest) {
127
- const { subscriptionRef, reason } = await request.json()
127
+ const { purchaseRef, reason } = await request.json()
128
128
 
129
- if (!subscriptionRef) {
130
- return NextResponse.json({ error: 'Missing subscriptionRef' }, { status: 400 })
129
+ if (!purchaseRef) {
130
+ return NextResponse.json({ error: 'Missing purchaseRef' }, { status: 400 })
131
131
  }
132
132
 
133
- const result = await cancelSubscription(request, { subscriptionRef, reason })
133
+ const result = await cancelRenewal(request, { purchaseRef, reason })
134
134
  return result instanceof NextResponse ? result : NextResponse.json(result)
135
135
  }
136
136
  ```
@@ -195,19 +195,19 @@ export async function GET(request: NextRequest) {
195
195
 
196
196
  ```typescript
197
197
  import {
198
- clearSubscriptionCache,
199
- clearAllSubscriptionCache,
200
- getSubscriptionCacheStats,
198
+ clearPurchaseCache,
199
+ clearAllPurchaseCache,
200
+ getPurchaseCacheStats,
201
201
  } from '@solvapay/next'
202
202
 
203
203
  // Clear cache for a specific user
204
- clearSubscriptionCache(userId)
204
+ clearPurchaseCache(userId)
205
205
 
206
206
  // Clear all cache entries
207
- clearAllSubscriptionCache()
207
+ clearAllPurchaseCache()
208
208
 
209
209
  // Get cache statistics
210
- const stats = getSubscriptionCacheStats()
210
+ const stats = getPurchaseCacheStats()
211
211
  console.log(`In-flight: ${stats.inFlight}, Cached: ${stats.cached}`)
212
212
  ```
213
213
 
@@ -222,12 +222,12 @@ All helper functions follow the same pattern:
222
222
 
223
223
  **Available Helpers:**
224
224
 
225
- - `checkSubscription(request, options?)` - Check subscription with caching
225
+ - `checkPurchase(request, options?)` - Check purchase with caching
226
226
  - `syncCustomer(request, options?)` - Sync customer with backend
227
227
  - `createPaymentIntent(request, body, options?)` - Create payment intent
228
228
  - `processPayment(request, body, options?)` - Process payment
229
229
  - `listPlans(request)` - List available plans (public)
230
- - `cancelSubscription(request, body, options?)` - Cancel subscription
230
+ - `cancelRenewal(request, body, options?)` - Cancel renewal
231
231
  - `createCheckoutSession(request, body, options?)` - Create hosted checkout
232
232
  - `createCustomerSession(request, options?)` - Create customer portal
233
233
  - `getAuthenticatedUser(request, options?)` - Get user info
package/dist/index.cjs CHANGED
@@ -30,19 +30,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- cancelSubscription: () => cancelSubscription,
34
- checkSubscription: () => checkSubscription,
35
- clearAllSubscriptionCache: () => clearAllSubscriptionCache,
36
- clearSubscriptionCache: () => clearSubscriptionCache,
33
+ cancelRenewal: () => cancelRenewal,
34
+ checkPurchase: () => checkPurchase,
35
+ clearAllPurchaseCache: () => clearAllPurchaseCache,
36
+ clearPurchaseCache: () => clearPurchaseCache,
37
37
  createAuthMiddleware: () => createAuthMiddleware,
38
38
  createCheckoutSession: () => createCheckoutSession,
39
39
  createCustomerSession: () => createCustomerSession,
40
40
  createPaymentIntent: () => createPaymentIntent,
41
41
  createSupabaseAuthMiddleware: () => createSupabaseAuthMiddleware,
42
42
  getAuthenticatedUser: () => getAuthenticatedUser,
43
- getSubscriptionCacheStats: () => getSubscriptionCacheStats,
43
+ getPurchaseCacheStats: () => getPurchaseCacheStats,
44
44
  listPlans: () => listPlans,
45
- processPayment: () => processPayment,
45
+ processPaymentIntent: () => processPaymentIntent,
46
46
  syncCustomer: () => syncCustomer
47
47
  });
48
48
  module.exports = __toCommonJS(index_exports);
@@ -152,10 +152,10 @@ function createRequestDeduplicator(options = {}) {
152
152
  getStats
153
153
  };
154
154
  }
155
- var sharedSubscriptionDeduplicator = null;
155
+ var sharedPurchaseDeduplicator = null;
156
156
  function getSharedDeduplicator(options) {
157
- if (!sharedSubscriptionDeduplicator) {
158
- sharedSubscriptionDeduplicator = createRequestDeduplicator({
157
+ if (!sharedPurchaseDeduplicator) {
158
+ sharedPurchaseDeduplicator = createRequestDeduplicator({
159
159
  cacheTTL: 2e3,
160
160
  // Cache results for 2 seconds
161
161
  maxCacheSize: 1e3,
@@ -165,17 +165,17 @@ function getSharedDeduplicator(options) {
165
165
  ...options
166
166
  });
167
167
  }
168
- return sharedSubscriptionDeduplicator;
168
+ return sharedPurchaseDeduplicator;
169
169
  }
170
- function clearSubscriptionCache(userId) {
170
+ function clearPurchaseCache(userId) {
171
171
  const deduplicator = getSharedDeduplicator();
172
172
  deduplicator.clearCache(userId);
173
173
  }
174
- function clearAllSubscriptionCache() {
174
+ function clearAllPurchaseCache() {
175
175
  const deduplicator = getSharedDeduplicator();
176
176
  deduplicator.clearAllCache();
177
177
  }
178
- function getSubscriptionCacheStats() {
178
+ function getPurchaseCacheStats() {
179
179
  const deduplicator = getSharedDeduplicator();
180
180
  return deduplicator.getStats();
181
181
  }
@@ -223,14 +223,14 @@ async function createPaymentIntent(request, body, options = {}) {
223
223
  try {
224
224
  const userResult = await (0, import_server7.getAuthenticatedUserCore)(request);
225
225
  if (!(0, import_server6.isErrorResult)(userResult)) {
226
- clearSubscriptionCache(userResult.userId);
226
+ clearPurchaseCache(userResult.userId);
227
227
  }
228
228
  } catch {
229
229
  }
230
230
  return result;
231
231
  }
232
- async function processPayment(request, body, options = {}) {
233
- const result = await (0, import_server6.processPaymentCore)(request, body, options);
232
+ async function processPaymentIntent(request, body, options = {}) {
233
+ const result = await (0, import_server6.processPaymentIntentCore)(request, body, options);
234
234
  if ((0, import_server6.isErrorResult)(result)) {
235
235
  return import_server5.NextResponse.json(
236
236
  { error: result.error, details: result.details },
@@ -240,7 +240,7 @@ async function processPayment(request, body, options = {}) {
240
240
  try {
241
241
  const userResult = await (0, import_server7.getAuthenticatedUserCore)(request);
242
242
  if (!(0, import_server6.isErrorResult)(userResult)) {
243
- clearSubscriptionCache(userResult.userId);
243
+ clearPurchaseCache(userResult.userId);
244
244
  }
245
245
  } catch {
246
246
  }
@@ -271,12 +271,12 @@ async function createCustomerSession(request, options = {}) {
271
271
  return result;
272
272
  }
273
273
 
274
- // src/helpers/subscription.ts
274
+ // src/helpers/renewal.ts
275
275
  var import_server10 = require("next/server");
276
276
  var import_server11 = require("@solvapay/server");
277
277
  var import_server12 = require("@solvapay/server");
278
- async function cancelSubscription(request, body, options = {}) {
279
- const result = await (0, import_server11.cancelSubscriptionCore)(request, body, options);
278
+ async function cancelRenewal(request, body, options = {}) {
279
+ const result = await (0, import_server11.cancelPurchaseCore)(request, body, options);
280
280
  if ((0, import_server11.isErrorResult)(result)) {
281
281
  return import_server10.NextResponse.json(
282
282
  { error: result.error, details: result.details },
@@ -286,7 +286,7 @@ async function cancelSubscription(request, body, options = {}) {
286
286
  try {
287
287
  const userResult = await (0, import_server12.getAuthenticatedUserCore)(request);
288
288
  if (!(0, import_server11.isErrorResult)(userResult)) {
289
- clearSubscriptionCache(userResult.userId);
289
+ clearPurchaseCache(userResult.userId);
290
290
  }
291
291
  } catch {
292
292
  }
@@ -378,7 +378,7 @@ function createSupabaseAuthMiddleware(options = {}) {
378
378
  }
379
379
 
380
380
  // src/index.ts
381
- async function checkSubscription(request, options = {}) {
381
+ async function checkPurchase(request, options = {}) {
382
382
  try {
383
383
  const { requireUserId, getUserEmailFromRequest, getUserNameFromRequest } = await import("@solvapay/auth");
384
384
  const userIdOrError = requireUserId(request);
@@ -397,14 +397,14 @@ async function checkSubscription(request, options = {}) {
397
397
  const customer = await solvaPay.getCustomer({ customerRef: cachedCustomerRef });
398
398
  if (customer && customer.customerRef) {
399
399
  if (customer.externalRef && customer.externalRef === userId) {
400
- const filteredSubscriptions = (customer.subscriptions || []).filter(
401
- (sub) => sub.status === "active"
400
+ const filteredPurchases = (customer.purchases || []).filter(
401
+ (p) => p.status === "active"
402
402
  );
403
403
  return {
404
404
  customerRef: customer.customerRef,
405
405
  email: customer.email,
406
406
  name: customer.name,
407
- subscriptions: filteredSubscriptions
407
+ purchases: filteredPurchases
408
408
  };
409
409
  }
410
410
  }
@@ -419,51 +419,51 @@ async function checkSubscription(request, options = {}) {
419
419
  name: name || void 0
420
420
  });
421
421
  const customer = await solvaPay.getCustomer({ customerRef: ensuredCustomerRef });
422
- const filteredSubscriptions = (customer.subscriptions || []).filter(
423
- (sub) => sub.status === "active"
422
+ const filteredPurchases = (customer.purchases || []).filter(
423
+ (p) => p.status === "active"
424
424
  );
425
425
  const result = {
426
426
  customerRef: customer.customerRef || userId,
427
427
  email: customer.email,
428
428
  name: customer.name,
429
- subscriptions: filteredSubscriptions
429
+ purchases: filteredPurchases
430
430
  };
431
431
  return result;
432
432
  } catch (error) {
433
- console.error("[checkSubscription] Error fetching customer:", error);
433
+ console.error("[checkPurchase] Error fetching customer:", error);
434
434
  return {
435
435
  customerRef: userId,
436
- subscriptions: []
436
+ purchases: []
437
437
  };
438
438
  }
439
439
  });
440
440
  return response;
441
441
  } catch (error) {
442
- console.error("Check subscription failed:", error);
442
+ console.error("Check purchase failed:", error);
443
443
  if (error instanceof import_core.SolvaPayError) {
444
444
  return import_server16.NextResponse.json({ error: error.message }, { status: 500 });
445
445
  }
446
446
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
447
447
  return import_server16.NextResponse.json(
448
- { error: "Failed to check subscription", details: errorMessage },
448
+ { error: "Failed to check purchase", details: errorMessage },
449
449
  { status: 500 }
450
450
  );
451
451
  }
452
452
  }
453
453
  // Annotate the CommonJS export names for ESM import in node:
454
454
  0 && (module.exports = {
455
- cancelSubscription,
456
- checkSubscription,
457
- clearAllSubscriptionCache,
458
- clearSubscriptionCache,
455
+ cancelRenewal,
456
+ checkPurchase,
457
+ clearAllPurchaseCache,
458
+ clearPurchaseCache,
459
459
  createAuthMiddleware,
460
460
  createCheckoutSession,
461
461
  createCustomerSession,
462
462
  createPaymentIntent,
463
463
  createSupabaseAuthMiddleware,
464
464
  getAuthenticatedUser,
465
- getSubscriptionCacheStats,
465
+ getPurchaseCacheStats,
466
466
  listPlans,
467
- processPayment,
467
+ processPaymentIntent,
468
468
  syncCustomer
469
469
  });
package/dist/index.d.cts CHANGED
@@ -4,9 +4,9 @@ import { AuthenticatedUser, SolvaPay } from '@solvapay/server';
4
4
  import { AuthAdapter } from '@solvapay/auth';
5
5
 
6
6
  /**
7
- * Subscription Cache Utilities
7
+ * Purchase Cache Utilities
8
8
  *
9
- * Cache management functions for subscription data.
9
+ * Cache management functions for purchase data.
10
10
  * Separated from index.ts to avoid circular dependencies.
11
11
  */
12
12
  /**
@@ -30,46 +30,46 @@ interface RequestDeduplicationOptions {
30
30
  cacheErrors?: boolean;
31
31
  }
32
32
  /**
33
- * Subscription check result
33
+ * Purchase check result
34
34
  */
35
- interface SubscriptionCheckResult {
35
+ interface PurchaseCheckResult {
36
36
  customerRef: string;
37
37
  email?: string;
38
38
  name?: string;
39
- subscriptions: Array<{
39
+ purchases: Array<{
40
40
  reference: string;
41
41
  planName?: string;
42
- agentName?: string;
42
+ productReference?: string;
43
43
  status?: string;
44
44
  startDate?: string;
45
45
  [key: string]: unknown;
46
46
  }>;
47
47
  }
48
48
  /**
49
- * Clear subscription cache for a specific user.
49
+ * Clear purchase cache for a specific user.
50
50
  *
51
- * Useful when you know subscription status has changed (e.g., after a successful
52
- * checkout, subscription update, or cancellation). This forces the next
53
- * `checkSubscription()` call to fetch fresh data from the backend.
51
+ * Useful when you know purchase status has changed (e.g., after a successful
52
+ * checkout, purchase update, or cancellation). This forces the next
53
+ * `checkPurchase()` call to fetch fresh data from the backend.
54
54
  *
55
55
  * @param userId - User ID to clear cache for
56
56
  *
57
57
  * @example
58
58
  * ```typescript
59
- * import { clearSubscriptionCache } from '@solvapay/next';
59
+ * import { clearPurchaseCache } from '@solvapay/next';
60
60
  *
61
61
  * // After successful payment
62
62
  * await processPayment(request, body);
63
- * clearSubscriptionCache(userId); // Force refresh on next check
63
+ * clearPurchaseCache(userId); // Force refresh on next check
64
64
  * ```
65
65
  *
66
- * @see {@link checkSubscription} for subscription checking
67
- * @see {@link clearAllSubscriptionCache} to clear all cache entries
66
+ * @see {@link checkPurchase} for purchase checking
67
+ * @see {@link clearAllPurchaseCache} to clear all cache entries
68
68
  * @since 1.0.0
69
69
  */
70
- declare function clearSubscriptionCache(userId: string): void;
70
+ declare function clearPurchaseCache(userId: string): void;
71
71
  /**
72
- * Clear all subscription cache entries.
72
+ * Clear all purchase cache entries.
73
73
  *
74
74
  * Useful for testing, debugging, or when you need to force fresh lookups
75
75
  * for all users. This clears both the in-flight request cache and the
@@ -77,23 +77,23 @@ declare function clearSubscriptionCache(userId: string): void;
77
77
  *
78
78
  * @example
79
79
  * ```typescript
80
- * import { clearAllSubscriptionCache } from '@solvapay/next';
80
+ * import { clearAllPurchaseCache } from '@solvapay/next';
81
81
  *
82
82
  * // In a test setup
83
83
  * beforeEach(() => {
84
- * clearAllSubscriptionCache();
84
+ * clearAllPurchaseCache();
85
85
  * });
86
86
  * ```
87
87
  *
88
- * @see {@link clearSubscriptionCache} to clear cache for a specific user
89
- * @see {@link getSubscriptionCacheStats} for cache monitoring
88
+ * @see {@link clearPurchaseCache} to clear cache for a specific user
89
+ * @see {@link getPurchaseCacheStats} for cache monitoring
90
90
  * @since 1.0.0
91
91
  */
92
- declare function clearAllSubscriptionCache(): void;
92
+ declare function clearAllPurchaseCache(): void;
93
93
  /**
94
- * Get subscription cache statistics for monitoring and debugging.
94
+ * Get purchase cache statistics for monitoring and debugging.
95
95
  *
96
- * Returns the current state of the subscription cache, including:
96
+ * Returns the current state of the purchase cache, including:
97
97
  * - Number of in-flight requests (being deduplicated)
98
98
  * - Number of cached results
99
99
  *
@@ -103,11 +103,11 @@ declare function clearAllSubscriptionCache(): void;
103
103
  *
104
104
  * @example
105
105
  * ```typescript
106
- * import { getSubscriptionCacheStats } from '@solvapay/next';
106
+ * import { getPurchaseCacheStats } from '@solvapay/next';
107
107
  *
108
108
  * // In a monitoring endpoint
109
109
  * export async function GET() {
110
- * const stats = getSubscriptionCacheStats();
110
+ * const stats = getPurchaseCacheStats();
111
111
  * return Response.json({
112
112
  * cache: {
113
113
  * inFlight: stats.inFlight,
@@ -117,10 +117,10 @@ declare function clearAllSubscriptionCache(): void;
117
117
  * }
118
118
  * ```
119
119
  *
120
- * @see {@link checkSubscription} for subscription checking
120
+ * @see {@link checkPurchase} for purchase checking
121
121
  * @since 1.0.0
122
122
  */
123
- declare function getSubscriptionCacheStats(): {
123
+ declare function getPurchaseCacheStats(): {
124
124
  inFlight: number;
125
125
  cached: number;
126
126
  };
@@ -188,17 +188,9 @@ declare function syncCustomer(request: globalThis.Request, options?: {
188
188
  includeName?: boolean;
189
189
  }): Promise<string | NextResponse>;
190
190
 
191
- /**
192
- * Create payment intent - Next.js wrapper
193
- *
194
- * @param request - Next.js request object
195
- * @param body - Payment intent parameters
196
- * @param options - Configuration options
197
- * @returns Payment intent response or NextResponse error
198
- */
199
191
  declare function createPaymentIntent(request: globalThis.Request, body: {
200
192
  planRef: string;
201
- agentRef: string;
193
+ productRef: string;
202
194
  }, options?: {
203
195
  solvaPay?: SolvaPay;
204
196
  includeEmail?: boolean;
@@ -210,17 +202,9 @@ declare function createPaymentIntent(request: globalThis.Request, body: {
210
202
  accountId?: string;
211
203
  customerRef: string;
212
204
  } | NextResponse>;
213
- /**
214
- * Process payment - Next.js wrapper
215
- *
216
- * @param request - Next.js request object
217
- * @param body - Payment processing parameters
218
- * @param options - Configuration options
219
- * @returns Process payment result or NextResponse error
220
- */
221
- declare function processPayment(request: globalThis.Request, body: {
205
+ declare function processPaymentIntent(request: globalThis.Request, body: {
222
206
  paymentIntentId: string;
223
- agentRef: string;
207
+ productRef: string;
224
208
  planRef?: string;
225
209
  }, options?: {
226
210
  solvaPay?: SolvaPay;
@@ -228,20 +212,10 @@ declare function processPayment(request: globalThis.Request, body: {
228
212
 
229
213
  /**
230
214
  * Next.js Checkout Helpers
231
- *
232
- * Next.js-specific wrappers for checkout helpers.
233
215
  */
234
216
 
235
- /**
236
- * Create checkout session - Next.js wrapper
237
- *
238
- * @param request - Next.js request object
239
- * @param body - Checkout session parameters
240
- * @param options - Configuration options
241
- * @returns Checkout session response or NextResponse error
242
- */
243
217
  declare function createCheckoutSession(request: globalThis.Request, body: {
244
- agentRef: string;
218
+ productRef: string;
245
219
  planRef?: string;
246
220
  returnUrl?: string;
247
221
  }, options?: {
@@ -253,13 +227,6 @@ declare function createCheckoutSession(request: globalThis.Request, body: {
253
227
  sessionId: string;
254
228
  checkoutUrl: string;
255
229
  } | NextResponse>;
256
- /**
257
- * Create customer session - Next.js wrapper
258
- *
259
- * @param request - Next.js request object
260
- * @param options - Configuration options
261
- * @returns Customer session response or NextResponse error
262
- */
263
230
  declare function createCustomerSession(request: globalThis.Request, options?: {
264
231
  solvaPay?: SolvaPay;
265
232
  includeEmail?: boolean;
@@ -270,20 +237,18 @@ declare function createCustomerSession(request: globalThis.Request, options?: {
270
237
  } | NextResponse>;
271
238
 
272
239
  /**
273
- * Next.js Subscription Helpers
274
- *
275
- * Next.js-specific wrappers for subscription helpers.
240
+ * Next.js Purchase Cancellation Helpers
276
241
  */
277
242
  /**
278
- * Cancel subscription - Next.js wrapper
243
+ * Cancel purchase - Next.js wrapper
279
244
  *
280
245
  * @param request - Next.js request object
281
246
  * @param body - Cancellation parameters
282
247
  * @param options - Configuration options
283
- * @returns Cancelled subscription response or NextResponse error
248
+ * @returns Cancelled purchase response or NextResponse error
284
249
  */
285
- declare function cancelSubscription(request: globalThis.Request, body: {
286
- subscriptionRef: string;
250
+ declare function cancelRenewal(request: globalThis.Request, body: {
251
+ purchaseRef: string;
287
252
  reason?: string;
288
253
  }, options?: {
289
254
  solvaPay?: SolvaPay;
@@ -291,19 +256,10 @@ declare function cancelSubscription(request: globalThis.Request, body: {
291
256
 
292
257
  /**
293
258
  * Next.js Plans Helper
294
- *
295
- * Next.js-specific wrapper for plans helper.
296
- * This is a public route - no authentication required.
297
- */
298
- /**
299
- * List plans - Next.js wrapper
300
- *
301
- * @param request - Next.js request object
302
- * @returns Plans response or NextResponse error
303
259
  */
304
260
  declare function listPlans(request: globalThis.Request): Promise<{
305
261
  plans: Array<Record<string, unknown>>;
306
- agentRef: string;
262
+ productRef: string;
307
263
  } | NextResponse>;
308
264
 
309
265
  /**
@@ -489,9 +445,9 @@ declare function createSupabaseAuthMiddleware(options?: SupabaseAuthMiddlewareOp
489
445
  */
490
446
 
491
447
  /**
492
- * Options for checking subscriptions
448
+ * Options for checking purchases
493
449
  */
494
- interface CheckSubscriptionOptions {
450
+ interface CheckPurchaseOptions {
495
451
  /**
496
452
  * Request deduplication options
497
453
  *
@@ -518,9 +474,9 @@ interface CheckSubscriptionOptions {
518
474
  includeName?: boolean;
519
475
  }
520
476
  /**
521
- * Check user subscription status with automatic deduplication and caching.
477
+ * Check user purchase status with automatic deduplication and caching.
522
478
  *
523
- * This Next.js helper function provides optimized subscription checking with:
479
+ * This Next.js helper function provides optimized purchase checking with:
524
480
  * - Automatic request deduplication (concurrent requests share the same promise)
525
481
  * - Short-term caching (2 seconds) to prevent duplicate sequential requests
526
482
  * - Fast path optimization using cached customer references from client
@@ -531,7 +487,7 @@ interface CheckSubscriptionOptions {
531
487
  * 2. Gets user email and name from Supabase JWT token (if available)
532
488
  * 3. Validates cached customer reference (if provided via header)
533
489
  * 4. Ensures customer exists in SolvaPay backend
534
- * 5. Returns customer subscription information
490
+ * 5. Returns customer purchase information
535
491
  *
536
492
  * @param request - Next.js request object (NextRequest extends Request)
537
493
  * @param options - Configuration options
@@ -539,15 +495,15 @@ interface CheckSubscriptionOptions {
539
495
  * @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
540
496
  * @param options.includeEmail - Whether to include email in response (default: true)
541
497
  * @param options.includeName - Whether to include name in response (default: true)
542
- * @returns Subscription check result with customer data and subscriptions, or NextResponse error
498
+ * @returns Purchase check result with customer data and purchases, or NextResponse error
543
499
  *
544
500
  * @example
545
501
  * ```typescript
546
502
  * import { NextRequest, NextResponse } from 'next/server';
547
- * import { checkSubscription } from '@solvapay/next';
503
+ * import { checkPurchase } from '@solvapay/next';
548
504
  *
549
505
  * export async function GET(request: NextRequest) {
550
- * const result = await checkSubscription(request);
506
+ * const result = await checkPurchase(request);
551
507
  *
552
508
  * if (result instanceof NextResponse) {
553
509
  * return result; // Error response
@@ -557,10 +513,10 @@ interface CheckSubscriptionOptions {
557
513
  * }
558
514
  * ```
559
515
  *
560
- * @see {@link clearSubscriptionCache} for cache management
561
- * @see {@link getSubscriptionCacheStats} for cache monitoring
516
+ * @see {@link clearPurchaseCache} for cache management
517
+ * @see {@link getPurchaseCacheStats} for cache monitoring
562
518
  * @since 1.0.0
563
519
  */
564
- declare function checkSubscription(request: Request, options?: CheckSubscriptionOptions): Promise<SubscriptionCheckResult | NextResponse>;
520
+ declare function checkPurchase(request: Request, options?: CheckPurchaseOptions): Promise<PurchaseCheckResult | NextResponse>;
565
521
 
566
- export { type AuthMiddlewareOptions, type CheckSubscriptionOptions, type RequestDeduplicationOptions, type SubscriptionCheckResult, type SupabaseAuthMiddlewareOptions, cancelSubscription, checkSubscription, clearAllSubscriptionCache, clearSubscriptionCache, createAuthMiddleware, createCheckoutSession, createCustomerSession, createPaymentIntent, createSupabaseAuthMiddleware, getAuthenticatedUser, getSubscriptionCacheStats, listPlans, processPayment, syncCustomer };
522
+ export { type AuthMiddlewareOptions, type CheckPurchaseOptions, type PurchaseCheckResult, type RequestDeduplicationOptions, type SupabaseAuthMiddlewareOptions, cancelRenewal, checkPurchase, clearAllPurchaseCache, clearPurchaseCache, createAuthMiddleware, createCheckoutSession, createCustomerSession, createPaymentIntent, createSupabaseAuthMiddleware, getAuthenticatedUser, getPurchaseCacheStats, listPlans, processPaymentIntent, syncCustomer };
package/dist/index.d.ts CHANGED
@@ -4,9 +4,9 @@ import { AuthenticatedUser, SolvaPay } from '@solvapay/server';
4
4
  import { AuthAdapter } from '@solvapay/auth';
5
5
 
6
6
  /**
7
- * Subscription Cache Utilities
7
+ * Purchase Cache Utilities
8
8
  *
9
- * Cache management functions for subscription data.
9
+ * Cache management functions for purchase data.
10
10
  * Separated from index.ts to avoid circular dependencies.
11
11
  */
12
12
  /**
@@ -30,46 +30,46 @@ interface RequestDeduplicationOptions {
30
30
  cacheErrors?: boolean;
31
31
  }
32
32
  /**
33
- * Subscription check result
33
+ * Purchase check result
34
34
  */
35
- interface SubscriptionCheckResult {
35
+ interface PurchaseCheckResult {
36
36
  customerRef: string;
37
37
  email?: string;
38
38
  name?: string;
39
- subscriptions: Array<{
39
+ purchases: Array<{
40
40
  reference: string;
41
41
  planName?: string;
42
- agentName?: string;
42
+ productReference?: string;
43
43
  status?: string;
44
44
  startDate?: string;
45
45
  [key: string]: unknown;
46
46
  }>;
47
47
  }
48
48
  /**
49
- * Clear subscription cache for a specific user.
49
+ * Clear purchase cache for a specific user.
50
50
  *
51
- * Useful when you know subscription status has changed (e.g., after a successful
52
- * checkout, subscription update, or cancellation). This forces the next
53
- * `checkSubscription()` call to fetch fresh data from the backend.
51
+ * Useful when you know purchase status has changed (e.g., after a successful
52
+ * checkout, purchase update, or cancellation). This forces the next
53
+ * `checkPurchase()` call to fetch fresh data from the backend.
54
54
  *
55
55
  * @param userId - User ID to clear cache for
56
56
  *
57
57
  * @example
58
58
  * ```typescript
59
- * import { clearSubscriptionCache } from '@solvapay/next';
59
+ * import { clearPurchaseCache } from '@solvapay/next';
60
60
  *
61
61
  * // After successful payment
62
62
  * await processPayment(request, body);
63
- * clearSubscriptionCache(userId); // Force refresh on next check
63
+ * clearPurchaseCache(userId); // Force refresh on next check
64
64
  * ```
65
65
  *
66
- * @see {@link checkSubscription} for subscription checking
67
- * @see {@link clearAllSubscriptionCache} to clear all cache entries
66
+ * @see {@link checkPurchase} for purchase checking
67
+ * @see {@link clearAllPurchaseCache} to clear all cache entries
68
68
  * @since 1.0.0
69
69
  */
70
- declare function clearSubscriptionCache(userId: string): void;
70
+ declare function clearPurchaseCache(userId: string): void;
71
71
  /**
72
- * Clear all subscription cache entries.
72
+ * Clear all purchase cache entries.
73
73
  *
74
74
  * Useful for testing, debugging, or when you need to force fresh lookups
75
75
  * for all users. This clears both the in-flight request cache and the
@@ -77,23 +77,23 @@ declare function clearSubscriptionCache(userId: string): void;
77
77
  *
78
78
  * @example
79
79
  * ```typescript
80
- * import { clearAllSubscriptionCache } from '@solvapay/next';
80
+ * import { clearAllPurchaseCache } from '@solvapay/next';
81
81
  *
82
82
  * // In a test setup
83
83
  * beforeEach(() => {
84
- * clearAllSubscriptionCache();
84
+ * clearAllPurchaseCache();
85
85
  * });
86
86
  * ```
87
87
  *
88
- * @see {@link clearSubscriptionCache} to clear cache for a specific user
89
- * @see {@link getSubscriptionCacheStats} for cache monitoring
88
+ * @see {@link clearPurchaseCache} to clear cache for a specific user
89
+ * @see {@link getPurchaseCacheStats} for cache monitoring
90
90
  * @since 1.0.0
91
91
  */
92
- declare function clearAllSubscriptionCache(): void;
92
+ declare function clearAllPurchaseCache(): void;
93
93
  /**
94
- * Get subscription cache statistics for monitoring and debugging.
94
+ * Get purchase cache statistics for monitoring and debugging.
95
95
  *
96
- * Returns the current state of the subscription cache, including:
96
+ * Returns the current state of the purchase cache, including:
97
97
  * - Number of in-flight requests (being deduplicated)
98
98
  * - Number of cached results
99
99
  *
@@ -103,11 +103,11 @@ declare function clearAllSubscriptionCache(): void;
103
103
  *
104
104
  * @example
105
105
  * ```typescript
106
- * import { getSubscriptionCacheStats } from '@solvapay/next';
106
+ * import { getPurchaseCacheStats } from '@solvapay/next';
107
107
  *
108
108
  * // In a monitoring endpoint
109
109
  * export async function GET() {
110
- * const stats = getSubscriptionCacheStats();
110
+ * const stats = getPurchaseCacheStats();
111
111
  * return Response.json({
112
112
  * cache: {
113
113
  * inFlight: stats.inFlight,
@@ -117,10 +117,10 @@ declare function clearAllSubscriptionCache(): void;
117
117
  * }
118
118
  * ```
119
119
  *
120
- * @see {@link checkSubscription} for subscription checking
120
+ * @see {@link checkPurchase} for purchase checking
121
121
  * @since 1.0.0
122
122
  */
123
- declare function getSubscriptionCacheStats(): {
123
+ declare function getPurchaseCacheStats(): {
124
124
  inFlight: number;
125
125
  cached: number;
126
126
  };
@@ -188,17 +188,9 @@ declare function syncCustomer(request: globalThis.Request, options?: {
188
188
  includeName?: boolean;
189
189
  }): Promise<string | NextResponse>;
190
190
 
191
- /**
192
- * Create payment intent - Next.js wrapper
193
- *
194
- * @param request - Next.js request object
195
- * @param body - Payment intent parameters
196
- * @param options - Configuration options
197
- * @returns Payment intent response or NextResponse error
198
- */
199
191
  declare function createPaymentIntent(request: globalThis.Request, body: {
200
192
  planRef: string;
201
- agentRef: string;
193
+ productRef: string;
202
194
  }, options?: {
203
195
  solvaPay?: SolvaPay;
204
196
  includeEmail?: boolean;
@@ -210,17 +202,9 @@ declare function createPaymentIntent(request: globalThis.Request, body: {
210
202
  accountId?: string;
211
203
  customerRef: string;
212
204
  } | NextResponse>;
213
- /**
214
- * Process payment - Next.js wrapper
215
- *
216
- * @param request - Next.js request object
217
- * @param body - Payment processing parameters
218
- * @param options - Configuration options
219
- * @returns Process payment result or NextResponse error
220
- */
221
- declare function processPayment(request: globalThis.Request, body: {
205
+ declare function processPaymentIntent(request: globalThis.Request, body: {
222
206
  paymentIntentId: string;
223
- agentRef: string;
207
+ productRef: string;
224
208
  planRef?: string;
225
209
  }, options?: {
226
210
  solvaPay?: SolvaPay;
@@ -228,20 +212,10 @@ declare function processPayment(request: globalThis.Request, body: {
228
212
 
229
213
  /**
230
214
  * Next.js Checkout Helpers
231
- *
232
- * Next.js-specific wrappers for checkout helpers.
233
215
  */
234
216
 
235
- /**
236
- * Create checkout session - Next.js wrapper
237
- *
238
- * @param request - Next.js request object
239
- * @param body - Checkout session parameters
240
- * @param options - Configuration options
241
- * @returns Checkout session response or NextResponse error
242
- */
243
217
  declare function createCheckoutSession(request: globalThis.Request, body: {
244
- agentRef: string;
218
+ productRef: string;
245
219
  planRef?: string;
246
220
  returnUrl?: string;
247
221
  }, options?: {
@@ -253,13 +227,6 @@ declare function createCheckoutSession(request: globalThis.Request, body: {
253
227
  sessionId: string;
254
228
  checkoutUrl: string;
255
229
  } | NextResponse>;
256
- /**
257
- * Create customer session - Next.js wrapper
258
- *
259
- * @param request - Next.js request object
260
- * @param options - Configuration options
261
- * @returns Customer session response or NextResponse error
262
- */
263
230
  declare function createCustomerSession(request: globalThis.Request, options?: {
264
231
  solvaPay?: SolvaPay;
265
232
  includeEmail?: boolean;
@@ -270,20 +237,18 @@ declare function createCustomerSession(request: globalThis.Request, options?: {
270
237
  } | NextResponse>;
271
238
 
272
239
  /**
273
- * Next.js Subscription Helpers
274
- *
275
- * Next.js-specific wrappers for subscription helpers.
240
+ * Next.js Purchase Cancellation Helpers
276
241
  */
277
242
  /**
278
- * Cancel subscription - Next.js wrapper
243
+ * Cancel purchase - Next.js wrapper
279
244
  *
280
245
  * @param request - Next.js request object
281
246
  * @param body - Cancellation parameters
282
247
  * @param options - Configuration options
283
- * @returns Cancelled subscription response or NextResponse error
248
+ * @returns Cancelled purchase response or NextResponse error
284
249
  */
285
- declare function cancelSubscription(request: globalThis.Request, body: {
286
- subscriptionRef: string;
250
+ declare function cancelRenewal(request: globalThis.Request, body: {
251
+ purchaseRef: string;
287
252
  reason?: string;
288
253
  }, options?: {
289
254
  solvaPay?: SolvaPay;
@@ -291,19 +256,10 @@ declare function cancelSubscription(request: globalThis.Request, body: {
291
256
 
292
257
  /**
293
258
  * Next.js Plans Helper
294
- *
295
- * Next.js-specific wrapper for plans helper.
296
- * This is a public route - no authentication required.
297
- */
298
- /**
299
- * List plans - Next.js wrapper
300
- *
301
- * @param request - Next.js request object
302
- * @returns Plans response or NextResponse error
303
259
  */
304
260
  declare function listPlans(request: globalThis.Request): Promise<{
305
261
  plans: Array<Record<string, unknown>>;
306
- agentRef: string;
262
+ productRef: string;
307
263
  } | NextResponse>;
308
264
 
309
265
  /**
@@ -489,9 +445,9 @@ declare function createSupabaseAuthMiddleware(options?: SupabaseAuthMiddlewareOp
489
445
  */
490
446
 
491
447
  /**
492
- * Options for checking subscriptions
448
+ * Options for checking purchases
493
449
  */
494
- interface CheckSubscriptionOptions {
450
+ interface CheckPurchaseOptions {
495
451
  /**
496
452
  * Request deduplication options
497
453
  *
@@ -518,9 +474,9 @@ interface CheckSubscriptionOptions {
518
474
  includeName?: boolean;
519
475
  }
520
476
  /**
521
- * Check user subscription status with automatic deduplication and caching.
477
+ * Check user purchase status with automatic deduplication and caching.
522
478
  *
523
- * This Next.js helper function provides optimized subscription checking with:
479
+ * This Next.js helper function provides optimized purchase checking with:
524
480
  * - Automatic request deduplication (concurrent requests share the same promise)
525
481
  * - Short-term caching (2 seconds) to prevent duplicate sequential requests
526
482
  * - Fast path optimization using cached customer references from client
@@ -531,7 +487,7 @@ interface CheckSubscriptionOptions {
531
487
  * 2. Gets user email and name from Supabase JWT token (if available)
532
488
  * 3. Validates cached customer reference (if provided via header)
533
489
  * 4. Ensures customer exists in SolvaPay backend
534
- * 5. Returns customer subscription information
490
+ * 5. Returns customer purchase information
535
491
  *
536
492
  * @param request - Next.js request object (NextRequest extends Request)
537
493
  * @param options - Configuration options
@@ -539,15 +495,15 @@ interface CheckSubscriptionOptions {
539
495
  * @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
540
496
  * @param options.includeEmail - Whether to include email in response (default: true)
541
497
  * @param options.includeName - Whether to include name in response (default: true)
542
- * @returns Subscription check result with customer data and subscriptions, or NextResponse error
498
+ * @returns Purchase check result with customer data and purchases, or NextResponse error
543
499
  *
544
500
  * @example
545
501
  * ```typescript
546
502
  * import { NextRequest, NextResponse } from 'next/server';
547
- * import { checkSubscription } from '@solvapay/next';
503
+ * import { checkPurchase } from '@solvapay/next';
548
504
  *
549
505
  * export async function GET(request: NextRequest) {
550
- * const result = await checkSubscription(request);
506
+ * const result = await checkPurchase(request);
551
507
  *
552
508
  * if (result instanceof NextResponse) {
553
509
  * return result; // Error response
@@ -557,10 +513,10 @@ interface CheckSubscriptionOptions {
557
513
  * }
558
514
  * ```
559
515
  *
560
- * @see {@link clearSubscriptionCache} for cache management
561
- * @see {@link getSubscriptionCacheStats} for cache monitoring
516
+ * @see {@link clearPurchaseCache} for cache management
517
+ * @see {@link getPurchaseCacheStats} for cache monitoring
562
518
  * @since 1.0.0
563
519
  */
564
- declare function checkSubscription(request: Request, options?: CheckSubscriptionOptions): Promise<SubscriptionCheckResult | NextResponse>;
520
+ declare function checkPurchase(request: Request, options?: CheckPurchaseOptions): Promise<PurchaseCheckResult | NextResponse>;
565
521
 
566
- export { type AuthMiddlewareOptions, type CheckSubscriptionOptions, type RequestDeduplicationOptions, type SubscriptionCheckResult, type SupabaseAuthMiddlewareOptions, cancelSubscription, checkSubscription, clearAllSubscriptionCache, clearSubscriptionCache, createAuthMiddleware, createCheckoutSession, createCustomerSession, createPaymentIntent, createSupabaseAuthMiddleware, getAuthenticatedUser, getSubscriptionCacheStats, listPlans, processPayment, syncCustomer };
522
+ export { type AuthMiddlewareOptions, type CheckPurchaseOptions, type PurchaseCheckResult, type RequestDeduplicationOptions, type SupabaseAuthMiddlewareOptions, cancelRenewal, checkPurchase, clearAllPurchaseCache, clearPurchaseCache, createAuthMiddleware, createCheckoutSession, createCustomerSession, createPaymentIntent, createSupabaseAuthMiddleware, getAuthenticatedUser, getPurchaseCacheStats, listPlans, processPaymentIntent, syncCustomer };
package/dist/index.js CHANGED
@@ -105,10 +105,10 @@ function createRequestDeduplicator(options = {}) {
105
105
  getStats
106
106
  };
107
107
  }
108
- var sharedSubscriptionDeduplicator = null;
108
+ var sharedPurchaseDeduplicator = null;
109
109
  function getSharedDeduplicator(options) {
110
- if (!sharedSubscriptionDeduplicator) {
111
- sharedSubscriptionDeduplicator = createRequestDeduplicator({
110
+ if (!sharedPurchaseDeduplicator) {
111
+ sharedPurchaseDeduplicator = createRequestDeduplicator({
112
112
  cacheTTL: 2e3,
113
113
  // Cache results for 2 seconds
114
114
  maxCacheSize: 1e3,
@@ -118,17 +118,17 @@ function getSharedDeduplicator(options) {
118
118
  ...options
119
119
  });
120
120
  }
121
- return sharedSubscriptionDeduplicator;
121
+ return sharedPurchaseDeduplicator;
122
122
  }
123
- function clearSubscriptionCache(userId) {
123
+ function clearPurchaseCache(userId) {
124
124
  const deduplicator = getSharedDeduplicator();
125
125
  deduplicator.clearCache(userId);
126
126
  }
127
- function clearAllSubscriptionCache() {
127
+ function clearAllPurchaseCache() {
128
128
  const deduplicator = getSharedDeduplicator();
129
129
  deduplicator.clearAllCache();
130
130
  }
131
- function getSubscriptionCacheStats() {
131
+ function getPurchaseCacheStats() {
132
132
  const deduplicator = getSharedDeduplicator();
133
133
  return deduplicator.getStats();
134
134
  }
@@ -168,7 +168,7 @@ async function syncCustomer(request, options = {}) {
168
168
  import { NextResponse as NextResponse3 } from "next/server";
169
169
  import {
170
170
  createPaymentIntentCore,
171
- processPaymentCore,
171
+ processPaymentIntentCore,
172
172
  isErrorResult as isErrorResult3
173
173
  } from "@solvapay/server";
174
174
  import { getAuthenticatedUserCore as getAuthenticatedUserCore2 } from "@solvapay/server";
@@ -183,14 +183,14 @@ async function createPaymentIntent(request, body, options = {}) {
183
183
  try {
184
184
  const userResult = await getAuthenticatedUserCore2(request);
185
185
  if (!isErrorResult3(userResult)) {
186
- clearSubscriptionCache(userResult.userId);
186
+ clearPurchaseCache(userResult.userId);
187
187
  }
188
188
  } catch {
189
189
  }
190
190
  return result;
191
191
  }
192
- async function processPayment(request, body, options = {}) {
193
- const result = await processPaymentCore(request, body, options);
192
+ async function processPaymentIntent(request, body, options = {}) {
193
+ const result = await processPaymentIntentCore(request, body, options);
194
194
  if (isErrorResult3(result)) {
195
195
  return NextResponse3.json(
196
196
  { error: result.error, details: result.details },
@@ -200,7 +200,7 @@ async function processPayment(request, body, options = {}) {
200
200
  try {
201
201
  const userResult = await getAuthenticatedUserCore2(request);
202
202
  if (!isErrorResult3(userResult)) {
203
- clearSubscriptionCache(userResult.userId);
203
+ clearPurchaseCache(userResult.userId);
204
204
  }
205
205
  } catch {
206
206
  }
@@ -235,12 +235,12 @@ async function createCustomerSession(request, options = {}) {
235
235
  return result;
236
236
  }
237
237
 
238
- // src/helpers/subscription.ts
238
+ // src/helpers/renewal.ts
239
239
  import { NextResponse as NextResponse5 } from "next/server";
240
- import { cancelSubscriptionCore, isErrorResult as isErrorResult5 } from "@solvapay/server";
240
+ import { cancelPurchaseCore, isErrorResult as isErrorResult5 } from "@solvapay/server";
241
241
  import { getAuthenticatedUserCore as getAuthenticatedUserCore3 } from "@solvapay/server";
242
- async function cancelSubscription(request, body, options = {}) {
243
- const result = await cancelSubscriptionCore(request, body, options);
242
+ async function cancelRenewal(request, body, options = {}) {
243
+ const result = await cancelPurchaseCore(request, body, options);
244
244
  if (isErrorResult5(result)) {
245
245
  return NextResponse5.json(
246
246
  { error: result.error, details: result.details },
@@ -250,7 +250,7 @@ async function cancelSubscription(request, body, options = {}) {
250
250
  try {
251
251
  const userResult = await getAuthenticatedUserCore3(request);
252
252
  if (!isErrorResult5(userResult)) {
253
- clearSubscriptionCache(userResult.userId);
253
+ clearPurchaseCache(userResult.userId);
254
254
  }
255
255
  } catch {
256
256
  }
@@ -342,7 +342,7 @@ function createSupabaseAuthMiddleware(options = {}) {
342
342
  }
343
343
 
344
344
  // src/index.ts
345
- async function checkSubscription(request, options = {}) {
345
+ async function checkPurchase(request, options = {}) {
346
346
  try {
347
347
  const { requireUserId, getUserEmailFromRequest, getUserNameFromRequest } = await import("@solvapay/auth");
348
348
  const userIdOrError = requireUserId(request);
@@ -361,14 +361,14 @@ async function checkSubscription(request, options = {}) {
361
361
  const customer = await solvaPay.getCustomer({ customerRef: cachedCustomerRef });
362
362
  if (customer && customer.customerRef) {
363
363
  if (customer.externalRef && customer.externalRef === userId) {
364
- const filteredSubscriptions = (customer.subscriptions || []).filter(
365
- (sub) => sub.status === "active"
364
+ const filteredPurchases = (customer.purchases || []).filter(
365
+ (p) => p.status === "active"
366
366
  );
367
367
  return {
368
368
  customerRef: customer.customerRef,
369
369
  email: customer.email,
370
370
  name: customer.name,
371
- subscriptions: filteredSubscriptions
371
+ purchases: filteredPurchases
372
372
  };
373
373
  }
374
374
  }
@@ -383,50 +383,50 @@ async function checkSubscription(request, options = {}) {
383
383
  name: name || void 0
384
384
  });
385
385
  const customer = await solvaPay.getCustomer({ customerRef: ensuredCustomerRef });
386
- const filteredSubscriptions = (customer.subscriptions || []).filter(
387
- (sub) => sub.status === "active"
386
+ const filteredPurchases = (customer.purchases || []).filter(
387
+ (p) => p.status === "active"
388
388
  );
389
389
  const result = {
390
390
  customerRef: customer.customerRef || userId,
391
391
  email: customer.email,
392
392
  name: customer.name,
393
- subscriptions: filteredSubscriptions
393
+ purchases: filteredPurchases
394
394
  };
395
395
  return result;
396
396
  } catch (error) {
397
- console.error("[checkSubscription] Error fetching customer:", error);
397
+ console.error("[checkPurchase] Error fetching customer:", error);
398
398
  return {
399
399
  customerRef: userId,
400
- subscriptions: []
400
+ purchases: []
401
401
  };
402
402
  }
403
403
  });
404
404
  return response;
405
405
  } catch (error) {
406
- console.error("Check subscription failed:", error);
406
+ console.error("Check purchase failed:", error);
407
407
  if (error instanceof SolvaPayError) {
408
408
  return NextResponse8.json({ error: error.message }, { status: 500 });
409
409
  }
410
410
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
411
411
  return NextResponse8.json(
412
- { error: "Failed to check subscription", details: errorMessage },
412
+ { error: "Failed to check purchase", details: errorMessage },
413
413
  { status: 500 }
414
414
  );
415
415
  }
416
416
  }
417
417
  export {
418
- cancelSubscription,
419
- checkSubscription,
420
- clearAllSubscriptionCache,
421
- clearSubscriptionCache,
418
+ cancelRenewal,
419
+ checkPurchase,
420
+ clearAllPurchaseCache,
421
+ clearPurchaseCache,
422
422
  createAuthMiddleware,
423
423
  createCheckoutSession,
424
424
  createCustomerSession,
425
425
  createPaymentIntent,
426
426
  createSupabaseAuthMiddleware,
427
427
  getAuthenticatedUser,
428
- getSubscriptionCacheStats,
428
+ getPurchaseCacheStats,
429
429
  listPlans,
430
- processPayment,
430
+ processPaymentIntent,
431
431
  syncCustomer
432
432
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solvapay/next",
3
- "version": "1.0.0-preview.19",
3
+ "version": "1.0.0-preview.20",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -29,9 +29,9 @@
29
29
  },
30
30
  "sideEffects": false,
31
31
  "dependencies": {
32
- "@solvapay/auth": "1.0.0-preview.19",
33
- "@solvapay/core": "1.0.0-preview.19",
34
- "@solvapay/server": "1.0.0-preview.19"
32
+ "@solvapay/auth": "1.0.0-preview.20",
33
+ "@solvapay/core": "1.0.0-preview.20",
34
+ "@solvapay/server": "1.0.0-preview.20"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "next": ">=13.0.0"