Skip to main content

Adding Refindie to Your Website

Install tracking script and integrate with your payment system.

Integration Steps

1. Add the tracking script

Copy and paste the script below in the <head> section of your website. Script Parameters:
  • data-program-id - Your affiliate program ID (required)

2. Get referral data

The script sets a global object with referral information:
  • refindie_metadata.program_id (string | number)
  • refindie_metadata.ref_code (string)
  • refindie_metadata.is_new_visit (boolean)

3. Send data during payment

Include referral data in your payment API calls to attribute commissions.

Integration Options

  1. Connect your Stripe account in Settings > Integration
  2. Send window.refindie_metadata from your frontend to your server
  3. Attach it as metadata on the Stripe object that matches your payment flow (see the table below)
Refindie listens to your Stripe events and records the commission automatically.

Supported Stripe payment flows

Affiliate promotion codes are detected automatically on Checkout Sessions and invoices, even without metadata.

Metadata format

Refindie reads two keys, program_id and ref_code:
Passing the whole window.refindie_metadata object as metadata works too. In the examples below, refindieMetadata is the value of window.refindie_metadata sent by your frontend.
Put the metadata on the object you create. Stripe does not copy metadata between objects: the metadata of a Checkout Session does not appear on its PaymentIntent, and the metadata of a PaymentIntent does not appear on a subscription. Refindie knows where to look for each flow listed above.
  • Professional payment processing
  • Commission tracking via Stripe metadata
  • Payment history and manual payout verification

Option 2: Referral API

Use the server-to-server endpoint when you use a custom payment provider or want to record a referral manually.
  • Endpoint: POST /api/referral
  • Headers: x-api-key: <YOUR_PROGRAM_API_KEY>
  • Body (JSON):
    • ref_code (string)
    • program_id (string | number)
    • spent_amount (number, in cents)
    • currency (string, e.g. β€œUSD”)
    • transaction_id (string, unique)

Implementation Examples

React Component (Next.js)

API Route (app/api/checkout/route.ts)

AI Assistant Prompt

Copy this prompt into your AI assistant to implement this feature:

Tips and Help

πŸ’‘ Important Tips

  • Add the script to all your pages to never miss a referral
  • Referral data is available as soon as the script is loaded
  • Test the integration in development mode before production
  • Subscriptions: The first payment is tracked via the metadata (checkout session or subscription). Renewal payments are tracked automatically using the subscription ID, no extra work needed
  • Free trials: The commission is recorded on the first paid invoice, not when the trial starts
  • One payment, one commission: Refindie deduplicates on the Stripe invoice ID (or PaymentIntent ID for one-time payments). Don’t also call the Referral API for a payment that already goes through Stripe Connect

βœ… Verification

To verify that the integration works, open your browser console and type window.refindie_metadata. You should see the referral data. After a test payment, open the object you created in your Stripe dashboard (Checkout Session, PaymentIntent, subscription or invoice) and check that its metadata contains program_id and ref_code.

πŸ”Ž Troubleshooting

I see a payment_intent.succeeded event without Refindie metadata. If you use Stripe Checkout, this is expected: Stripe does not copy the session metadata to the PaymentIntent. Check the checkout.session.completed event instead. If there is no checkout.session.completed event, you are using the PaymentIntents API directly: put the metadata on the PaymentIntent. The commission is missing for a subscription with a free trial. It is recorded when the first invoice is paid, at the end of the trial. The commission is missing for a SEPA or bank transfer payment. It is recorded once Stripe confirms the payment, which can take a few days.

Support

If you encounter any difficulties, contact us at contact@refindie.com or consult our documentation.