feat: add POST /webhook-endpoint/send-test for test API keys - #62
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a new internal HTTP endpoint, POST /api/v1/internals/webhook-endpoint/send-test, that lets holders of a test-mode API key trigger a synthetic payment.succeeded webhook delivery to their configured endpoint. This mirrors the production webhook-forwarding path used by createdCheckout.ts, providing a self-service way to verify webhook receivers without performing a real test checkout.
Changes:
- New
handleSendTestWebhookhandler that authenticates the caller, enforcesauth.role === "test", verifies a configured webhook endpoint exists, and invokesforwardWebhookwith a synthetic payment.succeeded event. - Registers the new route in
registerApiRoutesunder the existing/api/v1/internals/webhook-endpoint/...namespace.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/routes/http/api/webhookEndpoints.ts | Adds handleSendTestWebhook handler that sends a synthetic test webhook event for test API keys. |
| src/routes/http/api/registerApiRoutes.ts | Wires the new POST /api/v1/internals/webhook-endpoint/send-test route to the new handler. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const endpoint = await getWebhookEndpointByApiKeyId(auth.apiKeyId); | ||
|
|
||
| if (!endpoint) { | ||
| builder.setError(404, { | ||
| type: "NotFoundError", | ||
| message: "No webhook endpoint configured for this API key", | ||
| }); | ||
| reply.code(404); | ||
| return { error: "No webhook endpoint configured for this API key" }; | ||
| } | ||
|
|
||
| const now = DateTime.utc(); | ||
|
|
||
| await forwardWebhook(auth.apiKeyId, { | ||
| eventType: "payment.succeeded", | ||
| resource: "payment", | ||
| action: "succeeded", | ||
| data: { | ||
| paymentId: "test_pay_000000000000000000000", | ||
| checkoutSessionId: "test_cks_0000000000000000000", | ||
| userId: "test-user-00000000-0000-0000-0000-000000000000", | ||
| amount: 1000, | ||
| currency: "usd", | ||
| mode: "test", | ||
| billed_upto: now.toISO(), | ||
| createdAt: now.toISO(), | ||
| }, | ||
| }); |
No description provided.