For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
RegisterLoginSandbox Login
GuidesRecipesAPI Reference
GuidesRecipesAPI Reference
  • Recipes
    • Add 3DS Challenge (Angular)
    • Add Dynamic Height to Coinflow UI Component
    • Add Dynamic Height to Apple Pay Button
    • Add Dynamic Height to Coinflow iframe
    • Add Dynamic Loading to Coinflow iframe
    • Apple Pay Payouts API Implementation
    • Complete Checkout with 3DS Challenge (React)
    • Listen for Purchase Events
    • Listen for Successful Account Link Messages
    • Listen to Client-Side Messages on Swift iOS
    • Listen to Payment Success Messages
    • PCI Compliant Card Tokenization
    • Tokenize Card Data via API for Checkout
    • Tokenize Card Data via API for Debit Card Payouts
    • Tokenize Cards for Saved Card Checkout (Vue)
    • Tokenize Debit Cards for Withdraws
    • Upload files to Coinflow storage
LogoLogo
RegisterLoginSandbox Login
On this page
  • Retrieve API key
  • Configure webhook settings
  • Create a POST request
  • Extract data from the request
  • Validate authorization
  • Pass in ‘webhookInfo’ on frontend
  • Return status 200
Recipes

Listen for purchase events

Was this page helpful?
Previous

Listen for Successful Account Link Messages

Next
Built with
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