Payment Tracking (Stripe)
Payment tracking captures completed purchases and triggers commission calculation. This is where partners actually earn money.
Integration Methods
Section titled “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
Section titled “Affitor Pay”Redirect affiliate-referred customers to Affitor’s hosted checkout. Affitor handles payment collection and tracking automatically.
Implementation
Section titled “Implementation”// When customer clicks "Buy" or "Subscribe"window.affitor.redirectToCheckout({ price: 99.99, currency: 'USD', product_name: 'Pro Plan'});Parameters
Section titled “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
Section titled “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
Section titled “Bill Flow”Add Affitor metadata to your existing Stripe Checkout sessions. You collect payment normally; Affitor tracks via webhooks and invoices you weekly.
Implementation
Section titled “Implementation”Include these metadata fields when creating Stripe Checkout:
One-Time Payment:
Section titled “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:
Section titled “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
Section titled “Getting Cookie Values”// Helper functions to get Affitor cookiesfunction 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)
Section titled “Server-Side (Node.js)”// Parse cookies from requestfunction 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 endpointapp.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
Section titled “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)
How It Works
Section titled “How It Works”- Customer clicks buy → your checkout with Affitor metadata
- Customer completes payment via your Stripe
- Stripe webhook fires → Affitor receives event
- Affitor reads metadata → attributes to partner
- Commission calculated → Affitor invoices you weekly
- You and Affitor manually review via dashboard + Stripe data
Pros: Use your existing checkout, full branding control
Cons: Requires metadata setup, weekly invoice payment
Metadata Reference
Section titled “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 |
Handling Missing Cookies
Section titled “Handling Missing Cookies”const partnerCode = getPartnerCode();const customerCode = getCustomerCode();
// Only include metadata if cookies existconst metadata = {};if (partnerCode && customerCode) { metadata.partner_code = partnerCode; metadata.customer_code = customerCode; metadata.program_id = 'YOUR_PROGRAM_ID';}
const session = await stripe.checkout.sessions.create({ // ... config metadata: Object.keys(metadata).length > 0 ? metadata : undefined});Verifying Payment Tracking
Section titled “Verifying Payment Tracking”Test a Purchase
Section titled “Test a Purchase”- Visit your site with
?ref=TEST123 - Complete a test purchase (use Stripe test mode)
- Check Affitor dashboard → Transactions
- Verify conversion appears with correct partner
Check Webhook Delivery
Section titled “Check Webhook Delivery”- Go to Stripe Dashboard → Developers → Webhooks
- Find Affitor endpoint
- Check recent deliveries for success/failure
Integration Status
Section titled “Integration Status”- Go to Affitor dashboard → Settings → Integration
- Payment tracking should show “Connected”
Troubleshooting
Section titled “Troubleshooting”Conversion Not Tracked
Section titled “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
Section titled “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
Section titled “Subscription Renewals Not Tracked”Check:
subscription_data.metadataincluded (not just session metadata)invoice.payment_succeededwebhook event selected- Partner within commission duration window
Next Steps
Section titled “Next Steps”Payment tracking is set up. See the complete flow: