#Webhooks not capturing on cloudflare.
1 messages · Page 1 of 1 (latest)
To implement a Dodo Payments subscription payment gateway with webhooks on Cloudflare Pages, follow these steps:
-
Set Up Environment Variables:
- Ensure you have your
DODO_PAYMENTS_API_KEYandDODO_PAYMENTS_WEBHOOK_SECRETstored securely. Do not expose these keys in your client-side code or public repositories. Use environment variables in your deployment environment.
- Ensure you have your
-
Create a Subscription:
-
Use the Dodo Payments API to create a subscription. Here's an example of how to do this using Node.js:
import DodoPayments from 'dodopayments'; const client = new DodoPayments({ bearerToken: process.env.DODO_PAYMENTS_API_KEY, }); async function createSubscription() { const subscription = await client.subscriptions.create({ billing: { city: 'city', country: 'IN', state: 'state', street: 'street', zipcode: 89789, }, customer: { email: '[email protected]', name: 'John Doe', }, product_id: 'product_id', payment_link: true, return_url: 'https://yourdomain.com/success', quantity: 1, }); console.log(subscription.subscription_id); } createSubscription();
-
-
Implement Webhooks:
-
Set up an endpoint to handle webhook events from Dodo Payments. This will allow your application to react to events like successful payments, refunds, or subscription changes. Here is an example using Node.js:
import { Webhook } from "standardwebhooks"; import { headers } from "next/headers"; const webhook = new Webhook(process.env.DODO_PAYMENTS_WEBHOOK_SECRET); export async function POST(request) { const headersList = headers(); const rawBody = await request.text();
-
const webhookHeaders = {
"webhook-id": headersList.get("webhook-id") || "",
"webhook-signature": headersList.get("webhook-signature") || "",
"webhook-timestamp": headersList.get("webhook-timestamp") || "",
};
await webhook.verify(rawBody, webhookHeaders);
const payload = JSON.parse(rawBody);
// Process the payload according to your business logic
}
```
-
Configure Webhook on Dodo Dashboard:
- In your Dodo Payments dashboard, navigate to
Settings > Webhooksand create a new webhook endpoint. Enter the URL where your application is hosted and select the events you want to listen to, such assubscription.active,subscription.failed, etc.
- In your Dodo Payments dashboard, navigate to
-
Deploy on Cloudflare Pages:
- Deploy your application to Cloudflare Pages, ensuring that the webhook URL is publicly accessible and can receive POST requests.
-
Testing:
- Test the integration using test mode. You can simulate webhook events and verify that your application processes them correctly.
By following these steps, you should be able to successfully implement and test a subscription payment gateway with webhooks on Cloudflare Pages using Dodo Payments.
Helpful Links
The Dodo Payments API provides comprehensive endpoints for payment processing, subscription management, and digital product delivery. Our RESTful API follows industry standards with detailed responses for all operations.
This section provides an overview of the process to create a webhook for your Dodo Payments account.
Ngrok is wotking but clouflare is not working
What is the status code/message that you see on your Dodo Payments webhook dashboard?