@solvapay/server 1.0.0-preview.1 → 1.0.0-preview.11

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
@@ -93,6 +93,36 @@ const result = await protectedHandler({
93
93
  });
94
94
  ```
95
95
 
96
+ ### Authentication Integration
97
+
98
+ You can integrate authentication adapters from `@solvapay/auth` with the `getCustomerRef` option:
99
+
100
+ ```ts
101
+ import { createSolvaPay } from '@solvapay/server';
102
+ import { SupabaseAuthAdapter } from '@solvapay/auth/supabase';
103
+
104
+ const auth = new SupabaseAuthAdapter({
105
+ jwtSecret: process.env.SUPABASE_JWT_SECRET!
106
+ });
107
+
108
+ const solvaPay = createSolvaPay({ apiKey: process.env.SOLVAPAY_SECRET_KEY! });
109
+
110
+ // Use with Next.js adapter
111
+ export const POST = solvaPay.payable({ agent: 'my-api' }).next(
112
+ async (args) => {
113
+ return { result: 'success' };
114
+ },
115
+ {
116
+ getCustomerRef: async (req) => {
117
+ const userId = await auth.getUserIdFromRequest(req);
118
+ return userId ?? 'anonymous';
119
+ }
120
+ }
121
+ );
122
+ ```
123
+
124
+ This automatically extracts the user ID from authentication tokens and uses it as the customer reference for paywall checks.
125
+
96
126
  ### When to Use Each Adapter
97
127
 
98
128
  Choose the adapter based on your context:
@@ -160,11 +190,7 @@ type Plan = components['schemas']['Plan'];
160
190
 
161
191
  ## Testing
162
192
 
163
- > **📖 For detailed integration test setup**, see:
164
- > - [`packages/test-utils/INTEGRATION_TESTING.md`](../test-utils/INTEGRATION_TESTING.md) - Complete setup guide
165
- > - [`SDK_INTEGRATION_TESTS_IMPLEMENTATION.md`](../../SDK_INTEGRATION_TESTS_IMPLEMENTATION.md) - Implementation details
166
-
167
- This package includes comprehensive tests for SDK functionality.
193
+ This package includes comprehensive tests for SDK functionality, including unit tests and integration tests with real backend.
168
194
 
169
195
  ### Running Tests
170
196
 
@@ -198,7 +224,7 @@ Unit tests (`__tests__/paywall.test.ts`) use a mock API client and test:
198
224
 
199
225
  ### Integration Tests
200
226
 
201
- Integration tests (`__tests__/paywall.integration.with-fetched-defaults.test.ts`) connect to a real SolvaPay backend and test:
227
+ Integration tests (`__tests__/backend.integration.test.ts`) connect to a real SolvaPay backend and test:
202
228
  - SDK API methods with real responses
203
229
  - Actual limit enforcement
204
230
  - Real usage tracking
@@ -213,17 +239,106 @@ Set environment variables before running tests:
213
239
  # Option 1: Export in your shell (persists in session)
214
240
  export USE_REAL_BACKEND=true
215
241
  export SOLVAPAY_SECRET_KEY=your_secret_key_here
216
- export SOLVAPAY_API_BASE_URL=https://api-dev.solvapay.com # optional
242
+ export SOLVAPAY_API_BASE_URL=http://localhost:3001 # optional, defaults to dev API
217
243
  pnpm test:integration
218
244
 
219
245
  # Option 2: Inline with command (single use)
220
246
  USE_REAL_BACKEND=true SOLVAPAY_SECRET_KEY=your_key pnpm test:integration
221
247
  ```
222
248
 
223
- **Note:** This follows the industry standard used by major SDKs (Stripe, AWS, Twilio). No `.env` file is required.
224
-
225
249
  **Note:** Integration tests are automatically skipped if `USE_REAL_BACKEND` or `SOLVAPAY_SECRET_KEY` are not set. This allows CI/CD to run unit tests without backend credentials.
226
250
 
251
+ ### Payment Integration Tests (Stripe)
252
+
253
+ Payment tests (`__tests__/payment-stripe.integration.test.ts`) verify the complete payment flow with Stripe:
254
+ - Creating payment intents
255
+ - Confirming payments with test cards
256
+ - Webhook processing (optional)
257
+ - Credit management and usage tracking
258
+
259
+ **Required Setup:**
260
+
261
+ ```bash
262
+ export USE_REAL_BACKEND=true
263
+ export SOLVAPAY_SECRET_KEY=your_secret_key_here
264
+ export STRIPE_TEST_SECRET_KEY=sk_test_your_stripe_key
265
+ export SOLVAPAY_API_BASE_URL=http://localhost:3001
266
+ ```
267
+
268
+ **Optional - Webhook Tests:**
269
+
270
+ The E2E webhook test is skipped by default because it requires Stripe webhooks to be forwarded to your local backend. To enable webhook testing:
271
+
272
+ 1. **Install Stripe CLI:**
273
+ ```bash
274
+ # macOS
275
+ brew install stripe/stripe-cli/stripe
276
+
277
+ # Linux / Windows - see https://stripe.com/docs/stripe-cli
278
+ ```
279
+
280
+ 2. **Login to Stripe:**
281
+ ```bash
282
+ stripe login
283
+ ```
284
+
285
+ 3. **Forward webhooks to your local backend:**
286
+ ```bash
287
+ # Terminal 1: Start your backend
288
+ cd path/to/solvapay-backend
289
+ pnpm dev
290
+
291
+ # Terminal 2: Forward Stripe webhooks
292
+ stripe listen --forward-to localhost:3001/webhooks/stripe
293
+ ```
294
+
295
+ 4. **Run payment tests with webhook testing enabled:**
296
+ ```bash
297
+ ENABLE_WEBHOOK_TESTS=true pnpm test:integration:payment
298
+ ```
299
+
300
+ The Stripe CLI will forward webhook events from Stripe to your local backend, allowing the E2E test to verify the complete payment flow including webhook processing.
301
+
302
+ ### Debugging and Logging
303
+
304
+ The SDK and tests provide environment variable controls for logging:
305
+
306
+ **SDK Debug Logging**
307
+
308
+ Enable detailed logging for SDK operations (API calls, responses, errors):
309
+
310
+ ```bash
311
+ # Enable SDK debug logging
312
+ export SOLVAPAY_DEBUG=true
313
+
314
+ # Run tests or your application
315
+ pnpm test:integration
316
+ ```
317
+
318
+ **Test Verbose Logging**
319
+
320
+ Enable verbose logging for integration test progress and debug information:
321
+
322
+ ```bash
323
+ # Enable verbose test logging (test setup, progress, debug info)
324
+ export VERBOSE_TEST_LOGS=true
325
+
326
+ # Run integration tests
327
+ pnpm test:integration
328
+ ```
329
+
330
+ **Combined Usage:**
331
+
332
+ ```bash
333
+ # Enable all logging for maximum debugging
334
+ SOLVAPAY_DEBUG=true VERBOSE_TEST_LOGS=true pnpm test:integration
335
+
336
+ # Quiet mode (default) - minimal output
337
+ pnpm test:integration
338
+ ```
339
+
340
+ By default, both are **disabled** to keep test output clean and readable. Enable them when troubleshooting test failures or debugging SDK behavior.
341
+
227
342
  ### CI/CD
228
343
 
229
344
  ```yaml