Listen for purchase events

Server
1router.post('/credits-purchase-webhook', async (req, res) => {
2 try {
3 // Version 2 Coinflow webhook response
4 const {data, eventType, created} = req.body;
5 const {webhookInfo, wallet, subtotal} = data;
6
7 console.log(`Coinflow purchase from ${wallet}`);
8
9 const authHeader = req.get('Authorization');
10
11 // Authorize using your API key
12 if (authHeader !== process.env.COINFLOW_API_KEY)
13 throw new ControllerError('User not allowed', 401);
14 else handlePurchase() // react to purchase
15
16 res.sendStatus(200);
17 } catch (e) {
18 handleError(res, e);
19 }
20});
React
1<CoinflowPurchase
2 ...
3 webhookInfo={{item: 'sword'}}
4/>
Response Example
1{"success":true}

Retrieve API key

Go to the Coinflow Admin Dashboard. On the automation tab, you’ll find your API Key. If you don’t have one yet, generate a new one to get started. Copy the key for use in the next step.

Configure webhook settings

Enter your API route that will receive notifications. Ensure the version is set to version 2 (Coinflow’s recommended version) and the ‘Settled’ box is checked. If you care to listen to other events, feel free to check more event boxes.

Create a POST request

In your server, create a route that accepts a POST request on the same route you configured in your admin dashboard. This route will receive notifications.

Extract data from the request

The request body will contain the event type, timestamp and data of the notification. The data object will depend on the event type.

Validate authorization

Make sure the Authorization header in this request is equal to your API Key to validate that this request is coming from Coinflow

Pass in ‘webhookInfo’ on frontend

To provide extra data to your webhook, add a ‘webhookInfo’ param to the CoinflowPurchase component on the frontend. This can also be passed in a purchase API request.

Return status 200

Ensure to return status 200 from your endpoint or Coinflow will keep retrying for 36 hours