Before you begin
- Load the browser SDK on your checkout page. See Browser SDK.
- Install a server SDK and set
FOIL_SECRET_KEYon the server that handles checkout. See Server verification. - Confirm that your server makes the request that creates or confirms the payment. If your checkout confirms payments from the browser, verify the Foil token in the server request that creates the payment instead.
How Foil helps at checkout
Automated checkout
Scripts and automated browsers carry out several kinds of checkout abuse. In card testing, an attacker with a list of stolen card numbers submits small payments to find out which cards are still active, and each attempt can cost you an authorization fee and raise your decline rate with your processor. Scalping bots buy limited-stock items at release faster than people can, and other bots guess gift card numbers to find ones with a balance. Foil returns abot verdict for these sessions, so you can decline them before the payment reaches your processor. The same device also tends to appear across many attempts even when the attacker rotates IP addresses, which lets you limit attempts per device.
Foil also returns bot for AI agents that operate a browser. If you want to accept purchases that customers make through an agent, fetch the session from the Sessions API before you decline it, and check attribution.labels for a label whose kind is actor and whose value is ai-agent.
Fraud that leads to chargebacks
Many fraud chargebacks come from purchases that a person makes with a stolen card in an ordinary browser, often from a device and network chosen to hide who they are. Foil returnshuman for these sessions, because a person is making the purchase, so the verdict alone doesn’t catch them. Instead, Foil gives your fraud rules and review team context that is hard to get from the payment details:
- The visitor fingerprint identifies the device across sessions, including after the browser’s cookies are cleared. You can count how many customer accounts, cards, and shipping addresses have been used from one device, and you can block a device after a confirmed fraud chargeback.
- The session’s network details report whether the connection came through a VPN, a proxy, a residential proxy, or Tor, and where the IP address is located, which you can compare with the billing and shipping addresses.
- The session’s runtime integrity details report whether the browser is misrepresenting its identity, which is common in tools that make one computer look like many different devices.
Disputes
Some disputes are filed by cardholders for purchases they made themselves. When a customer disputes a charge, the Foil session stored with the order shows the device, network, and location used for the purchase. If the same device placed earlier orders on the customer’s account that weren’t disputed, that history can support your response to the dispute.How the integration works
1
Start Foil when the checkout page loads
The browser SDK collects signals while the customer enters their payment details.
2
Request a session handoff when the customer submits payment
getSession() returns a sessionId and a sealedToken, which the page sends to your server with the payment request.3
Verify the token before you call your processor
Your server verifies the token locally with your secret key and checks that it was issued recently.
4
Apply your checkout policy
Decline
bot sessions and blocked devices, ask for 3-D Secure when the verdict is inconclusive, and send everything else to your processor.5
Record the session with the order
Store the Foil session ID and device ID with the order, and attach your customer ID to the Foil session.
6
Review orders before you fulfill them
For orders that need a closer look, fetch the session’s device and network details and pass them to your fraud rules or review queue.
7
Act on chargebacks
When a fraud chargeback arrives, block the order’s device. When you respond to a dispute, use the stored session as part of your evidence.
Token fields used at checkout
After verification, your server reads the following fields from the token.
For the full token shape, see Server verification.
Add Foil to the checkout page
Start Foil when the checkout page loads, and callgetSession() when the customer submits payment. getSession() waits for fingerprinting to finish before it returns a handoff, so you don’t need to call waitForFingerprint() first. Fingerprinting usually finishes within a few hundred milliseconds of page load, well before the customer has entered their payment details.
getSession() fails, the page sends the payment without a handoff. This keeps a network problem or a blocked script from stopping a real customer at checkout. The next section describes how the server handles a payment that arrives without a valid token.
Verify the token on your server
Verify the token before you call your payment processor, so that payments from automated sessions never reach it. The example below does the following:- Verifies the sealed token and treats it as missing if verification fails or if the token is more than five minutes old.
- Declines the payment if the verdict is
botor the device is on your blocklist. The Block devices after a fraud chargeback section describes how devices get there. - Passes the payment to your existing checkout with the Foil session ID, device ID, verdict, and risk score attached as metadata. If the verdict is
inconclusiveor the token is missing, it asks the processor to require 3-D Secure.
chargePayment stands in for your existing checkout, including how it creates orders, handles 3-D Secure, and responds to the page. isBlockedDevice stands in for your blocklist lookup. The DECLINED response should match what your checkout already returns for a card decline. Card-testing tools read the response to decide whether a card works, and if Foil declines look different from processor declines, the tool can recognize them and retry those cards later from a different setup.
Limit attempts per device
Card testers submit many cards from the same device, so a limit on payment attempts per device adds a second layer. The example above doesn’t include this limit, so add it yourself, right before the call to your checkout. Keep a counter pervisitor_fingerprint.id that expires after an hour, increment it before you call the processor, and decline when it passes a small number, such as three attempts that weren’t approved. Use an atomic increment, such as Redis INCR, so that parallel requests can’t all pass the check. When there is no valid token, count by IP address instead.
The limit also covers replayed tokens. The server SDKs don’t check a token’s age, which is why the example rejects tokens older than five minutes. Within that window, a token captured from a real browser session still carries the same device ID every time it’s reused, so an attempt limit stops it after a few tries.
Record the session with the order
Store the Foil session ID and device ID with the order in your own database, and pass them to your processor as payment metadata as the example does. Most processors show metadata in their dashboard, which lets your team see the Foil session next to the processor’s own risk information. Use thesession_id and visitor_fingerprint.id from the verified token rather than values that the browser sent.
After you create the order, attach your customer ID to the Foil session. This links the session to the customer’s account in the Foil dashboard and in the Sessions API.
Review orders before you fulfill them
The token gives you enough to decline automated sessions at checkout. For fraud that a person commits, the more useful information is in the session’s device and network details, which you fetch from the Sessions API. The lookup is a network call to Foil, so run it after the payment is authorized rather than in the checkout request, for example in the job that decides whether to capture the payment or release the order for shipping. You can fetch details for every order, or only for orders that meet your review criteria, such as high-value orders, orders from new customer accounts, or orders with aninconclusive verdict.
The following fields are the most useful for order review.
The example below fetches the session for an order and returns the fields that a rules engine or review queue needs.
verdict is returned as decision.automation_status. For the full mapping, see Verdicts & scoring.
Combine these fields with your own order data. Because you store the device ID with each order, you can also count how many customer accounts, cards, and shipping addresses have been used from the same device. The following are examples of rules that you can build:
- Hold the order for review if the device has placed orders under several customer accounts or with several different cards in the last 30 days.
- Hold the order for review if the IP address is in a different country from both the billing and shipping addresses and the connection went through a VPN or proxy.
- Hold the order for review if
identity_spoofingiselevatedorhigh_risk. - Show the
highlightssummaries to the person reviewing the order.
Block devices after a fraud chargeback
When you receive a chargeback for fraud, or your team confirms that an order was fraudulent, add the order’s device ID to your blocklist. The checkout example declines payments from blocked devices, so a person who returns with a new account and a different card is declined if they use the same device. The visitor fingerprint stays the same when the browser’s cookies are cleared or it opens a private window, which makes it harder to evade than a cookie or an account. A device can be shared by the people in a household, so a block can affect someone other than the person who committed the fraud. If this is a concern for your business, send payments from blocked devices to manual review instead of declining them. The blocklist only applies to payments that carry a valid token, because a request without one has no device ID to check. A blocked person could avoid the check by calling your checkout endpoint without a token. The example sends those payments through 3-D Secure, and an attempt limit, if you add one, counts them by IP address. If that isn’t enough for your risk level, decline payments that arrive without a valid token instead, and watch the share of those requests as described in Roll out the policy.Respond to disputes
When a customer disputes a charge, look up the Foil session stored with the order. The session shows the device, IP address, location, and network used for the purchase. If the same device ID or IP address appears on earlier orders from the same customer account that weren’t disputed, include that history in your response. Some card networks accept this kind of match as evidence against a fraud dispute. For example, Visa’s Compelling Evidence 3.0 rules for card-not-present fraud disputes consider a device ID or IP address that matches earlier undisputed transactions on the same account. Your processor can tell you which evidence it accepts and how to submit it.Roll out the policy
Declines at checkout have a direct cost in lost sales, so run the policy in log-only mode before you enforce it. For about a week, verify tokens and record what the policy would have done without declining any payments, then compare the payments that it would have declined with your processor’s outcomes and your dispute data. During this period, also track the share of payment requests that arrive without a valid token. This share should stay small and steady. A sudden increase usually means that someone is calling your checkout endpoint directly without loading the page. When the results look right, turn on thebot decline first, then the blocklist and any attempt limit. Add devices to the blocklist only for confirmed fraud, and start your review rules by holding orders rather than declining them. For a general rollout plan, see Going to production.
Common mistakes
- Calling the processor before you verify the token. The attempt then costs you an authorization fee and counts toward your decline rate, even if you cancel the order afterward.
- Treating a missing token as a
humanverdict. Scripts that call your checkout endpoint directly don’t send a token, so a payment without a valid token needs its own handling. - Skipping the token age check. Verification succeeds for a token of any age, so the age check is what prevents an attacker from reusing one captured token across many attempts.
- Returning a different response when Foil declines a payment. A distinct error tells a card-testing tool which attempts Foil stopped.
- Declining
inconclusivesessions. Real customers sometimes receive aninconclusiveverdict, so require 3-D Secure or another step-up check instead. - Treating a
humanverdict as proof that a payment is legitimate. The verdict means that a person made the purchase, not that the card belongs to them, so keep your other fraud checks in place. - Declining orders because of a VPN or proxy alone. Use network details to decide which orders to review.
What’s next
Login protection
Stop account takeover before an attacker reaches checkout.
Promo abuse
Limit discount and referral abuse by device.
Verdicts & scoring
How verdicts and risk scores are assigned.
Going to production
Move from log-only mode to enforcement.