Payment Tracking (Stripe)

Payment tracking captures completed purchases and triggers commission calculation. This is where partners actually earn money.


Integration Methods

Choose based on your setup:

| Method | How it works | Best for | |--------|--------------|----------| | Affitor Pay | Redirect to Affitor checkout | Fastest setup, no Stripe changes | | Bill Flow | Add metadata to your Stripe checkout | Existing Stripe integration |

Coming Soon: Split Pay – Automatic fund splitting via Stripe Connect


Affitor Pay

Redirect affiliate-referred customers to Affitor's hosted checkout. Affitor handles payment collection and tracking automatically.

Implementation

// When customer clicks "Buy" or "Subscribe"
window.affitor.redirectToCheckout({
price: 99.99,
currency: 'USD',
product_name: 'Pro Plan'
});

Parameters

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | price | number | Yes | Product price | | currency | string | No | Currency code (default: USD) | | product_name | string | No | Product name for checkout |

How It Works

  1. Customer clicks buy → redirectToCheckout() called
  2. Affitor creates Stripe Checkout session with tracking metadata
  3. Customer completes payment on Affitor-hosted page
  4. Webhook fires → conversion tracked → commission calculated
  5. You receive payment minus commission and platform fee

Pros: Zero Stripe configuration needed Cons: Customers see Affitor checkout, not your branded checkout


Bill Flow

Add Affitor metadata to your existing Stripe Checkout sessions. You collect payment normally; Affitor tracks via webhooks and invoices you weekly.

One-Time Payment

const session = await stripe.checkout.sessions.create({
line_items: [{
  price: 'price_xxx',
  quantity: 1,
}],
mode: 'payment',
success_url: 'https://yoursite.com/success',
cancel_url: 'https://yoursite.com/cancel',

// REQUIRED: Affitor tracking metadata
metadata: {
  partner_code: getPartnerCode(),    // From cookie
  customer_code: getCustomerCode(),  // From cookie
  program_id: 'YOUR_PROGRAM_ID'
}
});

Subscription

const session = await stripe.checkout.sessions.create({
line_items: [{
  price: 'price_xxx',
  quantity: 1,
}],
mode: 'subscription',
success_url: 'https://yoursite.com/success',
cancel_url: 'https://yoursite.com/cancel',

// REQUIRED: Session metadata (first payment)
metadata: {
  partner_code: getPartnerCode(),
  customer_code: getCustomerCode(),
  program_id: 'YOUR_PROGRAM_ID'
},

// REQUIRED: Subscription metadata (recurring payments)
subscription_data: {
  metadata: {
    partner_code: getPartnerCode(),
    customer_code: getCustomerCode(),
    program_id: 'YOUR_PROGRAM_ID'
  }
}
});
// Helper functions to get Affitor cookies
function getPartnerCode() {
return getCookie('partner_code') || null;
}

function getCustomerCode() {
return getCookie('customer_code') || null;
}

function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
return null;
}

Server-Side (Node.js)

// Parse cookies from request
function getAffitorCookies(req) {
const cookies = req.headers.cookie || '';
const parsed = {};

cookies.split(';').forEach(cookie => {
  const [name, value] = cookie.trim().split('=');
  parsed[name] = value;
});

return {
  partner_code: parsed.partner_code || null,
  customer_code: parsed.customer_code || null
};
}

// In your checkout endpoint
app.post('/api/create-checkout', async (req, res) => {
const { partner_code, customer_code } = getAffitorCookies(req);

const session = await stripe.checkout.sessions.create({
  // ... your config
  metadata: {
    partner_code,
    customer_code,
    program_id: process.env.AFFITOR_PROGRAM_ID
  }
});

res.json({ url: session.url });
});

Webhook Setup

Affitor receives Stripe webhooks to track payments. Configure in Stripe Dashboard:

  1. Go to Developers → Webhooks
  2. Add endpoint: https://api.affitor.com/api/stripe/webhooks
  3. Select events:
    • checkout.session.completed
    • payment_intent.succeeded
    • invoice.payment_succeeded
  4. Copy webhook signing secret (Affitor team will configure)

Contact Affitor support to complete webhook setup. We need your Stripe webhook signing secret.


Metadata Reference

| Field | Type | Required | Description | |-------|------|----------|-------------| | partner_code | string | Yes | Partner's referral code (from cookie) | | customer_code | string | Yes | Visitor tracking ID (from cookie) | | program_id | string | Yes | Your Affitor program ID |

Missing metadata = no attribution. Always verify cookies exist before creating checkout.


Troubleshooting

Conversion Not Tracked

Check:

  • Metadata included in Stripe session
  • Webhook endpoint configured correctly
  • Webhook events selected (checkout.session.completed)
  • Cookies exist before checkout creation

Wrong Partner Attributed

Check:

  • partner_code cookie value matches expected partner
  • Customer clicked partner's link before purchasing
  • No cookie overwrites between click and purchase

Subscription Renewals Not Tracked

Check:

  • subscription_data.metadata included (not just session metadata)
  • invoice.payment_succeeded webhook event selected
  • Partner within commission duration window

Next Steps