🪝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
- To set up Webhooks for your application go to the Coinflow Admin Dashboard > Webhooks:
- Copy your Webhook Validation Key.
Keep this Validation Key secret, but if it gets leaked you can easily regenerate it.
- 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)
- 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.
- The format of the webhook request data will vary based on selected version:
{
signature: string,
wallet: string,
webhookInfo: object,
subtotal: {cents: number},
fees: {cents: number},
gasFees: {cents: number},
total: {cents: number},
id: string,
}
{
eventType: string,
created: string, // UTC ISO string
data: object,
}
- 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'}}
/>
- 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
EventType | Description | Version | Schema |
---|---|---|---|
Payment Authorized | A card payment has been successfully authorized | Version 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 Declined | A card payment has been declined | Version 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 Initiated | An ACH payment has been started | Version 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 Success | An ACH payment has been accepted by the bank | Version 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 Returned | The bank has marked the ACH payment as returned | Version 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 Failed | An ACH payment was denied by the bank | Version 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
EventType | Description | Versions | Schema |
---|---|---|---|
Settled | Coinflow credits have been minted or USDC has been sent | Version 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 Authorized | A card payment has been successfully authorized | Version 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 Declined | A card payment has been declined | Version 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 Initiated | An ACH payment has been started | Version 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 Batched | An ACH payment has been batched (accepted) by the bank | Version 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 Returned | The bank has marked the ACH payment as returned | Version 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 Failed | An ACH payment was denied by the bank | Version 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 Received | Your 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 Opened | A chargeback investigation had been initiated for a payment | Version 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 Won | A chargeback investigation had been won for a payment | Version 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 Lost | A chargeback investigation had been lost for a payment | Version 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 Fraud | A payment has been identified as potential fraud | Version 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; } } |
Updated 2 months ago