🪝Webhooks

Configure Coinflow Webhooks to know when users make purchases

Webhooks allow your application to subscribe to updates from Coinflow and react when users make purchases.

Use this recipe for a guided walkthrough

Setup

  1. To set up Webhooks for your application go to the Coinflow Admin Dashboard > Webhooks:
  1. Copy your Webhook Validation Key.

🚧

Keep this Validation Key secret, but if it gets leaked you can easily regenerate it.

  1. Enter your webhook settings configuration. In this example, we are going to listen for all successful credit card payments & Coinflow Credit purchases:
  • Enter a URL route to your server endpoint
  • Select the webhook version (this will determine available event types and payload format)

Legacy: the original webhook format that will only notify when Coinflow Credits are minted

Version 1 or Version 2 (Recommended): updated webhook format that provides multiple event types & more payload detail

  • Select the event types that should post notification (see addendum for event type detail)
  1. In your server create a route that accepts a POST request on that url and route

🚧

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

router.post('/credits-purchase-webhook', async (req, res) => {  
	try { 
    // Version 2 Coinflow webhook response
    const {data} = req.body;
    const {webhookInfo, wallet, subtotal} = data;
    
    console.log(`Coinflow purchase from ${wallet}`);
    
    const authHeader = req.get('Authorization');
    
    // Authorize using your validation key
    if (authHeader !== process.env.COINFLOW_VALIDATION_KEY)
      throw new ControllerError('User not allowed', 401);
    else handlePurchase() // react to purchase
    
    res.sendStatus(200);
  } catch (e) {  
    handleError(res, e);  
  }  
});

📘

Webhooks will retry until your server returns a 200 response code

or until it times out after 36 hours. Webhooks will also time out after 5 seconds without a response and will retry, so make sure your server responds within 5 seconds.

  1. The format of the webhook request data will vary based on selected version:
Legacy:
{
  signature: string,
  wallet: string,
  webhookInfo: object,
  subtotal: {cents: number},
  fees: {cents: number},
  gasFees: {cents: number},
  total: {cents: number},
  id: string,
}
Version 1 & 2:
{
  eventType: string,
  created: string, // UTC ISO string
  data: object,
}
  1. Configure your CoinflowPurchase component:

Add the webhookInfo property to your CoinflowPurchase component. That information will be passed as the webhookInfo property in the webhook your server will receive.

<CoinflowPurchase
	...
  webhookInfo={{item: 'sword'}}
/>
  1. Done! Try listening to different event types by subscribing to the different options below:

Event Types

  • Credits Minted/Settled (Popular): The credits have been minted for the transaction or USDC has been sent
  • Card Payment Authorized (Popular): the credit card payment has been authorized for the transaction

V1 Event Types

EventTypeDescriptionVersionSchema
Payment AuthorizedA card payment has been successfully authorizedVersion 1{ eventType: "Payment Authorized", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: Cents; fees: Cents; gasFees: Cents; total: Cents; } }
Card Payment DeclinedA card payment has been declinedVersion 1{ eventType: "Card Payment Declined", created: string; // UTC ISO string data: { id: string; declineCode: string; declineDescription: string; wallet: string; webhookInfo: object | undefined | null; subtotal: Cents; fees: Cents; gasFees: Cents; total: Cents; } }
ACH InitiatedAn ACH payment has been startedVersion 1{ eventType: "ACH Initiated", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: {cents: number}; fees: {cents: number}; gasFees: {cents: number}; total: {cents: number}; } }
ACH SuccessAn ACH payment has been accepted by the bankVersion 1{ eventType: "ACH Success", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: {cents: number}; fees: {cents: number}; gasFees: {cents: number}; total: {cents: number}; } }
ACH ReturnedThe bank has marked the ACH payment as returnedVersion 1{ eventType: "ACH Returned", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: {cents: number}; fees: {cents: number}; gasFees: {cents: number}; total: {cents: number}; } }
ACH FailedAn ACH payment was denied by the bankVersion 1{ eventType: "ACH Failed", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: {cents: number}; fees: {cents: number}; gasFees: {cents: number}; total: {cents: number}; } }

V2 Event Types

EventTypeDescriptionVersionsSchema
SettledCoinflow credits have been minted or USDC has been sentVersion 2{ eventType: "Settled", created: string; // UTC ISO string data: { wallet: string; signature: string; webhookInfo: object | undefined | null; subtotal: Cents; fees: Cents; gasFees: Cents; total: Cents; } }
Card Payment AuthorizedA card payment has been successfully authorizedVersion 2{ eventType: "Card Payment Authorized", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: Cents; fees: Cents; gasFees: Cents; total: Cents; } }
Card Payment DeclinedA card payment has been declinedVersion 2{ eventType: "Card Payment Declined", created: string; // UTC ISO string data: { id: string; declineCode: string; declineDescription: string; wallet: string; webhookInfo: object | undefined | null; subtotal: Cents; fees: Cents; gasFees: Cents; total: Cents; } }
ACH InitiatedAn ACH payment has been startedVersion 2{ eventType: "ACH Initiated", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: {cents: number}; fees: {cents: number}; gasFees: {cents: number}; total: {cents: number}; } }
ACH BatchedAn ACH payment has been batched (accepted) by the bankVersion 2{ eventType: "ACH Batched", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: {cents: number}; fees: {cents: number}; gasFees: {cents: number}; total: {cents: number}; } }
ACH ReturnedThe bank has marked the ACH payment as returnedVersion 2{ eventType: "ACH Returned", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: {cents: number}; fees: {cents: number}; gasFees: {cents: number}; total: {cents: number}; } }
ACH FailedAn ACH payment was denied by the bankVersion 2{ eventType: "ACH Failed", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: {cents: number}; fees: {cents: number}; gasFees: {cents: number}; total: {cents: number}; } }
USDC Payment ReceivedYour account as received a USDC payment from a user.Version 2{ eventType: "Settled", created: string; // UTC ISO string data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: Cents; fees: Cents; gasFees: Cents; total: Cents; } }
Card Payment Chargeback OpenedA chargeback investigation had been initiated for a paymentVersion 2{ eventType: "Card Payment Chargeback Opened", created: string; data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: Cents; fees: Cents; gasFees: Cents; total: Cents; } }
Card Payment Chargeback WonA chargeback investigation had been won for a paymentVersion 2{ eventType: "Card Payment Chargeback Won", created: string; data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: Cents; fees: Cents; gasFees: Cents; total: Cents; } }
Card Payment Chargeback LostA chargeback investigation had been lost for a paymentVersion 2{ eventType: "Card Payment Chargeback Lost", created: string; data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: Cents; fees: Cents; gasFees: Cents; total: Cents; } }
Card Payment Suspected FraudA payment has been identified as potential fraudVersion 2{ eventType: "Card Payment Suspected Fraud", created: string; data: { id: string; wallet: string; webhookInfo: object | undefined | null; subtotal: Cents; fees: Cents; gasFees: Cents; total: Cents; } }