Custom / server setup
For stores on your own stack. Two jobs: keep the click ID through checkout, then call the postback from your server.
1. Capture the click ID
Set your landing URL to https://yoursite.com/?s2s_click={click_id}. When the visitor arrives, read s2s_click from the query string and store it in a first-party cookie (30 days is typical) or in their session.
2. Save it with the order
At checkout, copy the stored value onto the order record, for example in an s2s_click column. That lets you send the postback later, even from a background job.
3. Call the postback
Send a GET (or POST) from your server once the order is paid. Don't send it from the browser.
cURL
curl "https://affn.io/api/public/postback?click_id=CLICK_ID&amount=125.00&order_id=1001&sku=SHOE-1"Node.js
// After the order is paid
const res = await fetch(`https://affn.io/api/public/postback?${new URLSearchParams({ click_id: order.s2sClick, amount: String(order.total), order_id: order.id })}`);
if (res.status !== 200 && res.status !== 409) {
// retry later (queue / cron) – 409 means already recorded
}PHP
$url = 'https://affn.io/api/public/postback?' . http_build_query(['click_id' => $order->s2s_click, 'amount' => $order->total, 'order_id' => $order->id]);
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10]);
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);Python
import requests
r = requests.get("https://affn.io/api/public/postback", params={"click_id": order.s2s_click, "amount": order.total, "order_id": order.id}, timeout=10)
if r.status_code not in (200, 409):
schedule_retry(order.id)Parameters
click_id(required): the value you captured.amount(optional): order total in USD, used for percent commissions. Also acceptssku,order_id,event=lead, andpayoutto set the commission directly.status(optional):pendingto hold the sale for review. The default isapproved.
Responses
200: recorded. Body:{"success":true}400: missing or invalid click_id or amount. Fix the request; don't retry as-is.404: unknown click_id. Usually a typo or a test value.409: already recorded. Safe to treat as success.5xx: temporary problem. Retry with backoff.
Test your setup
- Landing on your site with ?s2s_click=… stores the value
- A test order saves s2s_click on the order record
- Your server logs a 200 from the postback
- The conversion appears under Conversions in AFFN