-
Notifications
You must be signed in to change notification settings - Fork 1
Events not register correct #4
Description
No handler found for event type: customer.subscription.updated on First Attempt
📝 Description
When the AdonisJS server starts, the first time a Stripe webhook event (e.g., customer.subscription.updated) is sent, the system logs: No handler found for event type: customer.subscription.updated
However, on the second attempt, the event is handled correctly. This suggests that event handlers are not being registered at the right moment during the server initialization.
⚡ Steps to Reproduce
- Start the AdonisJS server.
- Send a Stripe event (e.g., using
stripe trigger customer.subscription.updated). - The first request logs: No handler found for event type: customer.subscription.updated
- Send the same event again, and now it works as expected.
✅ Expected Behavior
- The event handlers should be available immediately after the server starts.
- The first event from Stripe should be processed correctly, just like subsequent ones.
🚨 Current Workaround
A temporary fix was to register event listeners in the ready() method inside a custom provider:
export default class StripeProvider {
constructor(protected app: ApplicationService) {}
async ready() {
new PaymentService(new StripePaymentRepository())
}
}However, this seems like a hack rather than the proper solution. Ideally, event handlers should be available as soon as the server starts.
🛠 Possible Cause
The issue may be related to the order in which services are initialized in AdonisJS 6.
If the Stripe service is not fully ready when the app starts, the event handlers might not be registered properly until after the first webhook attempt.
💡 Suggested Fix
- Ensure that event handlers are registered as soon as the server starts (not on first use).
- Maybe expose a
ready()method in@vbusatta/adonis-stripeto allow proper event registration timing.
📌 Environment
- AdonisJS Version: 6.x
- Node.js Version: (v22.6.0)
- Stripe Package:
@vbusatta/adonis-stripe(latest version) - Database: PostgreSQL
🔎 Additional Notes
Would be great if someone could confirm if this is a known issue or if there's a better way to register event handlers on server boot.