# **Handover Note: Stripe Webhook Logging Issue in OpenSaaS/Wasp Project** --- ## **Background & Problem Statement** - **Project Context:** This is an OpenSaaS project using the Wasp framework, with Stripe integrated for payment processing (both subscriptions and one-time credits). - **Goal:** When a user purchases credits via Stripe, a webhook should be triggered, and the user’s credits should be incremented in the database. - **Current Issue:** Stripe webhooks are now reaching the server (confirmed by Stripe Dashboard and server logs), but **custom `console.log` statements inside the webhook handler are not appearing in the Wasp server logs**. This makes it difficult to debug the webhook logic and confirm that the handler is executing as expected. --- ## **Key Files & Code Patterns** ### 1. **Webhook Handler** **File:** `frontend/loist/app/src/payment/stripe/webhook.ts` **Current Handler Structure:** ```typescript import type { PaymentsWebhook } from 'wasp/server/api'; import { requireNodeEnvVar } from '../../server/utils'; export const stripeWebhook: PaymentsWebhook = async (request, response, context) => { console.log('stripeWebhook called', request.body); try { const secret = requireNodeEnvVar('STRIPE_WEBHOOK_SECRET'); const sig = request.headers['stripe-signature']; // ... Stripe event verification and switch logic ... response.json({ received: true }); // Stripe expects a 200 response } catch (err) { console.error('Error in stripeWebhook:', err); throw err; } }; ``` - **Note:** The `console.log('stripeWebhook called', request.body);` at the top should always print if the handler is invoked. The `try/catch` block is in place to log any errors. ### 2. **Handler Registration** **File:** `frontend/loist/app/main.wasp` ```wasp api paymentsWebhook { fn: import { stripeWebhook } from "@src/payment/stripe/webhook", entities: [User], httpRoute: (POST, "/payments-webhook") } ``` - This ensures the webhook is registered at `/payments-webhook`. ### 3. **Stripe Dashboard** - Stripe webhooks are being delivered to the correct endpoint and are acknowledged by the server (HTTP 200). --- ## **Recent Debugging Steps** - Confirmed that Stripe webhooks are reaching the server. - Added `console.log` at the top of the handler and inside a `try/catch` block. - Restarted the Wasp server to ensure the latest code is running. - Still, **no custom log output appears in the server logs** for webhook events, even though the endpoint is being hit. --- ## **What’s Working** - Stripe checkout and webhook delivery are functioning. - The server acknowledges webhook events (HTTP 200). - The correct Stripe price ID is being used in the checkout flow. --- ## **What’s Not Working** - Custom `console.log` statements inside the webhook handler do **not** appear in the Wasp server logs. - This makes it unclear whether the handler logic is executing as expected, or if there is an early exit, error, or misconfiguration. --- ## **Recommended Next Steps for the Next Agent** 1. **Confirm Log Output** - Double-check that logs from other server files/routes do appear, to rule out a global logging issue. - Try adding a log at the very top of the file (outside any function) to confirm the file is loaded: ```typescript console.log('stripe/webhook.ts loaded'); ``` 2. **Check for Silent Errors** - Ensure the `try/catch` block is catching all errors and logging them. - Consider logging the entire `request` object to see if it’s being parsed as expected. 3. **Verify Handler Registration** - Confirm that `main.wasp` is pointing to the correct handler file and function. - Ensure there are no duplicate or conflicting routes. 4. **Force a Clean Rebuild** - Stop the Wasp server completely and restart it to ensure the latest code is running. 5. **Check for Environment-Specific Issues** - If running in Docker or a cloud environment, ensure logs are not being redirected or filtered. 6. **Test with a Simple Log** - Temporarily replace the handler logic with just a log and a 200 response to see if the log appears: ```typescript export const stripeWebhook: PaymentsWebhook = async (request, response, context) => { console.log('TEST LOG: stripeWebhook called'); response.json({ received: true }); }; ``` 7. **If Logs Still Don’t Appear** - There may be a deeper issue with how Wasp or Node is handling logs for this route. Investigate Wasp’s server logging configuration or consider raising an issue with the Wasp framework maintainers. --- ## **Summary Table** | Step | What to Check/Do | |-----------------------------|------------------------------------------------------| | Log at top of handler | Should always print if handler is called | | Log at top of file | Confirms file is loaded | | try/catch with error log | Catches and logs any thrown errors | | Confirm handler registration| main.wasp points to correct file/function | | Force server restart | Ensures latest code is running | | Test with simple log | Rules out logic errors in handler | --- ## **Contact** - If you need more context or want to see the full code for the handler, check `frontend/loist/app/src/payment/stripe/webhook.ts`. - For Wasp configuration, see `frontend/loist/app/main.wasp`. --- **Let the next agent know:** - The Stripe integration is working, but debugging is blocked by missing log output from the webhook handler. - The immediate goal is to get logging working in the webhook handler to confirm the logic is executing as expected. ---