Skip to main content

🚀 Connect Webhook

Webhooks allow your application to receive real-time updates for specific events occurring on the 1buy.io platform. By configuring a webhook, you can automate tasks such as order processing, transaction tracking, and customer notifications.


Setting Up the Webhook

Step 1: Register the Webhook URL

  1. Navigate to the Dashboard:

  2. Go to the Webhook Settings section in your dashboard.

  3. Enter the URL where you want to receive the webhook payloads.

    • Example: https://yourdomain.com/webhook-endpoint.
  4. Click Save to register the webhook URL.

Note: Ensure your webhook URL is publicly accessible and supports HTTPS.


Step 2: Catching the Webhook Response

To handle webhook events, you need to set up a server endpoint that listens for POST requests.

Steps:

  1. Create an Endpoint: Create a new endpoint in your server application that listens for POST requests.
  2. Receive Payload: The webhook data will be sent in the req.body of the POST request. Ensure your server can parse JSON payloads.

Example in Node.js:

const express = require("express");
const app = express();

app.use(express.json()); // Middleware to parse JSON payloads

app.post("/my-webhook-endpoint", (req, res) => {
const webhookPayload = req.body;
console.log("Received webhook:", webhookPayload);

// Process the webhook data
res.status(200).send("Received!");
});

app.listen(3000, () => {
console.log("Webhook server is running on port 3000");
});

Webhook Response Structure

When a webhook triggers, it sends a JSON response with the following structure:

{
"data": {
"id": "string", // Order ID
"custom_id": "string", // Your custom identifier to track customers
"user_id": "string", // User ID on the platform
"product_id": "string", // Your Product ID
"type": "string", // Event type (e.g., payment_started, order_complete)
"base": "string", // Crypto Currency used
"base_amount": "string", // Crypto Amount
"quote": "string", // Fiat Currency used
"quote_amount": "string", // Fiat Amount
"address": "string", // Wallet Address
"transaction_id": "string", // Blockchain transaction ID
"partner_data": "object",
"full_name": "string",
"date_of_birth": "string",
"phone": "string",
"email": "string",
"state": "string",
"country": "string",
"city": "string",
"street": "string",
"postal_code": "string",
"utm_source": "string",
"clickID": "string",
"campaignID": "string",
"fail_reason": "string",
"redirect_url": "string",
"fail_redirect_url": "string",
"redirect_page": "string",
"external_user_id": "strung" // User Id you can use to fetch user details For more details check API References > User Creation & Detail API
}
}

Response Fields

FieldTypeDescription
idstringOrder ID.
custom_idstringYour custom identifier to track your customers.
user_idstringUser ID associated with the transaction.
product_idstringProduct ID of the associated product.
typestringOrder status (e.g., payment_started, order_complete, order_failed, etc.).
basestringCryptocurrency used for the transaction.
base_amountstringAmount of cryptocurrency used.
quotestringFiat currency used for the transaction.
quote_amountstringAmount of fiat currency used.
addressstringWallet address used for the transaction.
transaction_idstringBlockchain transaction ID.
partner_dataobjectData related to the blueprint address and input.
full_namestringFull name of the user.
date_of_birthstringDate of birth of the user.
phonestringPhone number of the user.
emailstringEmail address of the user.
statestringState of the user.
countrystringCountry of the user.
citystringCity of the user.
streetstringStreet of the user.
postal_codestringPostal Code of the user.
utm_sourcestringUTM source for tracking.
clickIDstringClick ID for tracking.
campaignIDstringCampaign ID for tracking.
fail_reasonstringReason for transaction failure, if applicable.
redirect_urlstringURL to redirect after successful transaction.
fail_redirect_urlstringURL to redirect after a failed transaction.
redirect_pagestringSpecifies how the redirect happens (new or self).

Events

The webhook triggers for the following events:

Event TypeDescription
link_unopenedDefault event when your checkout URL is one-time hashed and hasn't been opened yet.
link_openedTriggered when the one-time hashed checkout URL is accessed by the user.
payment_startedTriggered when users reach the confirm purchase page.
payment_initiatedTriggered when the payment process is initiated.
order_completeTriggered when an order is successfully completed.
order_failedTriggered when an order fails (e.g., due to payment issues).
transfer_startedTriggered when a fund transfer to the wallet begins.
order_canceledTriggered when an order received “Cancelled” status.
refund_processedTriggered when a refund is successfully processed.
tx_smart_contract_failedTriggered when a transaction to the smart contract has failed.

Error Codes

Below are the possible error codes and their meanings, sent when a transaction fails:

Error CodeError Meaning
4000We weren't able to charge the user's card, and the order was not completed. The user can try again.
4001The transaction failed due to an incorrect CVV/CVC. The user should re-enter the correct CVV/CVC.
4002, 4010, 4012Payment was declined by the card issuer. The user should contact their card issuer for further details.
4003Incorrect card details were provided. The user should re-enter valid card details.
4004Insufficient balance on the card. The user should add funds and try again.
4005The card limit was exceeded. The user should use a different card to complete the purchase.
4011Card validation failed. The user should provide a valid card.
4013We weren't able to charge the user's card, and the order was not completed. The user should contact support for assistance.

Webhook Security

To ensure secure communication between your application and 1buy.io, follow these best practices:

Use HTTPS

  • Always use HTTPS for your webhook URL to encrypt data in transit and ensure secure communication.

Ensure POST Requests

  • Your webhook endpoint should only accept POST requests to avoid unauthorized access or invalid requests.
  • Reject any requests that do not use the POST method with an appropriate HTTP status code (e.g., 405 Method Not Allowed).

Respond with 200 OK

  • Ensure your webhook endpoint responds with a 200 OK status code to acknowledge successful processing of the event.

Log Events

  • Log all incoming webhook events for debugging and auditing purposes.
  • Maintain detailed records of webhook interactions to assist with troubleshooting and compliance.

Troubleshooting

Not Receiving Webhooks?

  • Ensure that the webhook URL is correctly configured in the dashboard.
  • Verify that your server is accessible from the internet and properly configured to receive POST requests.
  • Check your server logs for incoming requests or errors.

Invalid Data?

  • Validate the structure of the webhook payload.
  • Confirm that your server is correctly parsing the JSON data from the POST request.