Custom API Integration

Use our flexible API to integrate Revshare with any payment provider. Whether you use Paddle, Lemon Squeezy, Gumroad, Razorpay, or a custom payment solution, our API works seamlessly with your existing setup.

Emil Klitmose

Written by Emil Klitmose

Updated recently

Overview

The Custom API integration allows you to track affiliate sales with any payment provider. The Custom API gives you complete control over when and how commissions are recorded.

This integration works with Paddle, Lemon Squeezy, Gumroad, Razorpay, PayPal, Polar, Dodo, and any custom payment solution. As long as your payment provider supports webhooks or payment confirmations, you can integrate with Revshare.

How It Works

The integration follows a simple flow:

  1. Visitor clicks affiliate link: When someone clicks an affiliate link (e.g., yoursite.com?ref=john123), our tracking script captures the referral code and stores it in a cookie.
  2. Pass referral to checkout: When opening your payment provider's checkout, pass the referral code from window.revshare_metadata.ref_code to your payment provider's custom data, metadata, or notes field.
  3. Customer makes purchase: When a customer completes a purchase, your payment provider sends a webhook to your backend.
  4. Extract referral data: In your webhook handler, extract the referral code and sale details from the webhook payload.
  5. Call Revshare API: Make a POST request to our Referral API endpoint with the sale details (amount, currency, transaction ID, referral code).
  6. Commission recorded: Revshare calculates and records the commission based on your program settings. The affiliate can see the sale in their dashboard.

Setup Steps

Follow these steps to set up the Custom API integration:

  1. Add Tracking Script: Copy the tracking script from your Revshare dashboard and add it to your website's HTML, typically in the <head> section. This script automatically captures affiliate referral codes from URLs.
  2. Pass Referral to Checkout: When opening your payment provider's checkout, pass the referral code from window.revshare_metadata.ref_code, and the click ID from window.revshare_metadata.click_id, to your payment provider's custom data/metadata fields. The exact field name depends on your provider (e.g., custom_data for Paddle, custom for Lemon Squeezy).
  3. Get Your API Key: Find your API key in Dashboard → Account & Billing. The same key works for all your programs. Keep this key secure and never expose it in client-side code.
  4. Create Webhook Handler: Set up a webhook endpoint in your backend that receives payment confirmations from your payment provider. Verify the webhook signature to ensure requests are legitimate.
  5. Call Revshare API: When a payment is confirmed, extract the referral code and sale details from the webhook payload, then call our Referral API endpoint. Only call the API if there's a referral code present (not all sales will have one).
  6. Test Integration: Make a test purchase through an affiliate link and verify the commission appears in your dashboard. Check that the amount, currency, and affiliate are correct.

Security Note: Always call the Revshare API from your backend server, never from client-side code. This keeps your API key secure and prevents unauthorized access.

API Reference

The Referral API endpoint accepts sale data and records affiliate commissions:

Endpoint: POST https://www.revshare.so/api/referral

Header: x-api-key: YOUR_API_KEY

Content-Type: application/json

{
  "ref_code": "john123",           // required: affiliate referral code
  "click_id": "rc_3f9a1c7b2e5d4a8f9c0b1d2e", // optional: the click behind the sale
  "program_id": "YOUR_PROGRAM_ID", // required: your program ID
  "spent_amount": 5000,            // required: 50.00 in cents, never "50.00"
  "currency": "USD",               // optional: defaults to USD
  "transaction_id": "order_123",   // required: unique per order in your program
  "customer_id": "cust_456"        // recommended: the buyer, the same on every order
}

Request Parameters

ref_code string, required unless click_id is sent. The affiliate referral code from the tracking script

click_id string, optional. The click ID from the tracking script

program_id string, required. Your Revshare program ID

spent_amount integer, required. The sale amount in the smallest currency unit (50.00 USD = 5000)

transaction_id string, required. Your ID for this order, unique in your program

currency string, optional. ISO currency code (defaults to USD)

customer_id string, strongly recommended. Your ID for the buyer

Amounts are in the smallest currency unit. Send cents, not dollars: 50.00 USD is 5000. We do not convert decimals, so 50 or "50.00" is recorded as 50 cents. Currencies without decimals, such as JPY, are sent as they are. Send the amount you want to pay commission on, for example without VAT and shipping.

Always send customer_id. It is how Revshare knows that two orders come from the same buyer. Without it, every order counts as a new customer's first purchase: a program that pays on the first purchase only pays on every order, and a recurring period never ends. See our Recurring Revenue Guide for details.

Sending an order twice is safe. A transaction_id is recorded once per program, and a repeat returns the sale already recorded. If your program is set to manual approval, the sale arrives as pending and earns nothing until you approve it under Transactions.

Click ID

Every click on an affiliate link gets a click ID. The tracking script keeps it in window.revshare_metadata.click_id and in the cookie revshare_cid_YOUR_PROGRAM_ID, next to the referral code. Pass it to your checkout together with the referral code, and send it as click_id when you report the sale.

  • With a referral code: the sale is credited to the ref_code you send, and the click ID links it to the exact click behind the order.
  • Without a referral code: the affiliate is found from the click. Use this if you can only store one value on the order.
  • First click or latest click: the click ID and window.revshare_metadata.ref_code belong to the first affiliate the visitor clicked. The latest one is in window.revshare_metadata.last_click_ref. The API credits the referral code you send, so if your program pays the latest click, send that one and leave out click_id.

Refunds

There is no refund call in the API yet. A sale you have reported stays recorded, and a refund in your shop does not reach Revshare. Until there is one, choose one of these:

  • Report the sale after your return period. Instead of calling the API when the order is paid, call it when the order can no longer be returned, for example 30 days after delivery. Skip orders that were cancelled or refunded, and for a partial refund send the amount the customer kept. The affiliate sees the sale from that day.
  • Use manual approval. Set transactions to manual approval in your program settings. Sales then arrive as pending, and you approve or reject each one under Transactions. A rejected sale earns no commission.
  • Already recorded and refunded? Contact us with your program and the transaction_id, and we will take the sale out.

Examples

Here's a generic webhook handler pattern that works with any payment provider:

// Generic webhook handler (Next.js example)
export async function POST(req) {
  const event = await req.json();
  
  // 1. Verify webhook signature (provider-specific)
  // 2. Check if payment is successful
  // 3. Extract referral code from custom_data/metadata
  // 4. Extract sale amount, currency, transaction ID, customer ID
  
  if (event.status === 'completed' && event.ref_code) {
    await fetch('https://www.revshare.so/api/referral', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'x-api-key': process.env.REVSHARE_API_KEY,
      },
      body: JSON.stringify({
        ref_code: event.ref_code,
        program_id: event.program_id,
        spent_amount: event.amount,  // in cents: 50.00 is 5000
        currency: event.currency,
        transaction_id: event.id,
        click_id: event.click_id,        // optional
        customer_id: event.customer_id,  // the buyer, the same on every order
      }),
    });
  }
  
  return Response.json({ received: true });
}

The exact implementation depends on your payment provider. For provider-specific examples (Paddle, Lemon Squeezy, Gumroad, etc.), see our complete Integration Guide with detailed code examples for each provider.

Common Provider Patterns

Paddle: Extract from event.data.custom_data

Lemon Squeezy: Extract from event.data.attributes.custom_data

Gumroad: Extract from product metadata or custom fields

Razorpay: Extract from payment notes or metadata