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
- Customer clicks buy →
redirectToCheckout()called - Affitor creates Stripe Checkout session with tracking metadata
- Customer completes payment on Affitor-hosted page
- Webhook fires → conversion tracked → commission calculated
- 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'
}
}
});Getting Cookie Values
// 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:
- Go to Developers → Webhooks
- Add endpoint:
https://api.affitor.com/api/stripe/webhooks - Select events:
checkout.session.completedpayment_intent.succeededinvoice.payment_succeeded
- 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_codecookie 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.metadataincluded (not just session metadata)invoice.payment_succeededwebhook event selected- Partner within commission duration window