Salting an order ID hash before an affiliate network postback is meant to keep the original order reference out of the network’s records. The network still needs a transaction ID it can use to recognise a retry, match a refund, and reconcile a payout. For most integrations, a keyed hash gives you both: a stable external reference without exposing the order ID or making it easy to guess.

The test is simple: the same order should produce the same reference whenever you post it to the same network, unless the network explicitly requires a separate event ID. Other networks should receive different references. A value that changes on every retry can turn one sale into two conversion records; one that never changes across partners can make the same sale easy to link across exports.

Use a keyed hash, not a public salt

Order IDs are often sequential or drawn from a predictable range. If you send a plain SHA-256 hash of an order number, someone who has the hash can try likely order numbers and compare the results. Appending a public salt changes the output, but it does not stop that person from testing guesses against an individual record. A random salt generated for every post creates a different problem: the resulting ID changes when you retry the same conversion.

Use HMAC-SHA-256 with a secret key when the network accepts an opaque transaction reference. HMAC is a standard keyed construction, not a plain hash with a secret tacked onto the end. Keep the key in your secret manager and calculate the reference on the server. The network receives the resulting token, not the key or the original order ID. If your postback runs in the browser, generate the token on the server before making it available to the browser.

Scope the token to the network and, where relevant, the advertiser account. Separate keys per integration are one way to do that. Another is to include stable network and account identifiers in the HMAC input alongside the internal order ID, using an unambiguous format. Separate keys also limit the effect of a key leak to the integrations that use that key. Neither approach makes the conversion anonymous: a network may still associate it with a click ID, timestamp, or other data in the postback.

Design the reference around the network’s rules

Confirm what the transaction field actually does

Check whether the network uses its order reference for deduplication, reporting, adjustments, or some combination of the three. The field called “transaction ID” in a postback is not necessarily the field a network expects in a refund request. Some networks require the original advertiser-supplied reference; others assign their own conversion ID and expect you to use that for later changes. Record both if the network returns its own ID.

Keep the order token separate from the click ID. The click ID ties the conversion to an affiliate visit; the order token identifies the sale. Replacing one with the other can break attribution or cause distinct sales from the same click to collapse into one record. The same checks you use to validate network macros should confirm that the token lands in the transaction field and the click ID lands in the attribution field.

Choose a format the network preserves

A full SHA-256 HMAC takes 64 characters in hexadecimal. Lowercase hex is straightforward to transport, but it will not fit every network field. Check the accepted character set, maximum length, and whether the network changes case or silently truncates values. Test the value as it appears in the network’s export as well as the value you submit. An HTTP success response does not prove that the full string survived.

If you need a shorter reference, consider a denser encoding such as unpadded base64url where the network preserves case and permits its characters. If you still need to truncate the output, pick a length based on the number of transactions that will share the same deduplication scope, not on what looks tidy in a dashboard. A 32-character hex token retains 128 bits; an eight-character hex token retains only 32. If the field is too narrow to hold a suitably long token, use a stored surrogate with a uniqueness constraint that matches the network’s rules, or ask for a supported alternative.

Generate once and reuse the reference

Build the HMAC input from identifiers that will remain stable throughout the conversion lifecycle. Use a canonical representation of the internal order ID and preserve leading zeroes if your order system treats them as significant. Don’t include payout amount, order status, timestamps, or other values that can change between the sale and the refund. If you combine multiple fields, use a defined structured encoding or length-prefixed fields so that different sets of inputs cannot produce the same input string by accident.

  1. Look up the order and destination integration using their internal identifiers.
  2. Check whether a network-facing reference already exists. If it does, reuse it.
  3. For a new reference, compute the HMAC, encode it in the agreed format, and save the final token and key version before sending the postback. Use a database uniqueness constraint so concurrent workers cannot create separate mappings for the same order and destination.
  4. Send the stored token, then capture the network’s response, acceptance status, and returned conversion ID if available.
  5. On retries, refunds, and reversals, retrieve the saved mapping and follow the network’s rules for referencing the original sale. If an adjustment also needs its own event ID, store that separately.

Saving before sending matters when the network receives the sale but your request times out before the acknowledgement arrives. On retry, your worker can send the same reference rather than guessing whether to generate another one. Confirm how the network handles a duplicate submission: it might accept it without creating a new record, return a duplicate error, or require a status lookup. Your retry logic should distinguish that outcome from a rejection caused by a malformed postback.

Keep key rotation from breaking refunds

Changing the HMAC key changes the result, even when the order and network stay the same. Use the new key for new mappings and keep sending the saved references for existing conversions. If you rely on recomputing old tokens instead of storing them, you will need to retain the old keys and know which version was used for each record. Storing the reference is usually simpler, especially when a reversal can arrive well after the original sale.

Keep the internal order-to-token mapping available for reconciliation, but restrict access to it. Log the reference, destination, timestamps, and delivery outcome rather than dumping raw order IDs or secrets into postback logs. When you migrate an integration that already sent plain order numbers, apply the new format to new sales. Continue using the original network reference for adjustments to earlier sales unless the network provides a documented way to update those records.

Verify the full conversion and payout cycle

Before rolling out the new format, test a sale, a retry after a simulated timeout, and a refund. If the integration supports partial refunds or multiple commissionable events per order, test those separately. Compare the posted reference with what appears in the network’s report. Confirm that the click is credited correctly, the retry does not produce an extra payable conversion, and the refund adjusts the intended record. Test the same internal order ID against another destination to verify that its reference differs.

Once the integration is live, use the stored transaction reference or returned network conversion ID to match your evidence against network exports during payout reconciliation. Track unmatched rows, duplicates, rejected references, and orphaned adjustments separately. An unmatched row after a deploy points first to a field-mapping or format change; an adjustment that cannot find its original sale may point to a lost mapping or a key rotation that regenerated the token. Watching those failures separately makes it easier to fix the cause before the next payout run.