Integrations · E-commerce
Validate emails of ThriveCart buyers
Check the buyer's email address of each new ThriveCart order. One TypeScript file with no dependencies, on your own server, receives your ThriveCart webhook, checks the token in its URL and ThriveCart's secret word, checks the buyer's address and reports the answer to your code with ThriveCart's order and customer ids (never the address). An order whose address cannot receive mail reaches you right after the sale, before its receipts, course access mails and dunning mails bounce. By default only a definite invalid is flagged.
It reports; it cannot block a checkout. ThriveCart runs nothing of yours before it takes an order: its webhooks are sent after the event, so the order already exists when the receiver hears of it.
It cannot flag a ThriveCart order or customer. ThriveCart's API has no tag, note or custom field to write a verdict into, so the answer goes only to your onResult code: log it, forward it to your own system (your CRM, a sheet, a mail to your team) or act on the order yourself. The receiver takes no ThriveCart key and never calls ThriveCart, and it never refunds or changes an order.
Status: set up from this page. There is no ThriveCart app listing: you run the file on your server and add it as a webhook in your ThriveCart account. It has not yet been tried on a real ThriveCart account, so try it with a product in test mode first.
Download it: email-validation-thrivecart.zip holds the file as TypeScript (email-validation-thrivecart.ts) and as JavaScript (email-validation-thrivecart.mjs), and the MIT licence.
What you need
- An API key of ours from the API keys page with Validate addresses (on by default). Keep it on your server.
- A ThriveCart account. ThriveCart offers a 14-day free trial of its Standard monthly plan (ThriveCart's plans).
- Your ThriveCart secret word, from Settings → API & Webhooks → ThriveCart order validation.
- A token of your own for the webhook URL: at least 24 letters and digits, from your password manager's generator (or
openssl rand -hex 32). - A server with an HTTPS address that runs
fetchand Web Crypto: Next.js, Remix, Hono, Bun, Deno, Cloudflare Workers or Node 22 or later. Copyemail-validation-thrivecart.tsinto a TypeScript project, oremail-validation-thrivecart.mjsinto a JavaScript one.
Our key goes only to our API. Nothing here logs or answers an address, the token, the secret word or a key.
Set it up
Put the receiver at an HTTPS address of your server, with the key, token and secret word from your environment:
// app/api/thrivecart/route.ts (Next.js); any framework with web Requests works the same way import { after } from 'next/server'; import { createThrivecartHook } from './email-validation-thrivecart'; const hook = createThrivecartHook({ apiKey: process.env.EMAIL_VALIDATION_API_KEY, token: process.env.THRIVECART_WEBHOOK_TOKEN, secret: process.env.THRIVECART_SECRET, waitUntil: after, // keeps the work after the answer running on serverless hosts onResult: (r) => { if (r.outcome === 'flagged') console.log('Look at ThriveCart order', r.orderId, r.decision.status); }, }); export const POST = (request: Request) => hook(request); export const HEAD = (request: Request) => hook(request); // ThriveCart's check when the URL is savedOn Cloudflare Workers, build
hookthe same way withoutafter(drop its import and thewaitUntilline) and pass it the request's context, which keeps the work after the answer running:export default { fetch: (request: Request, env: Env, ctx: ExecutionContext) => hook(request, ctx) };In ThriveCart, open Settings → API & Webhooks → Webhooks & notifications and add a webhook with a name and the receiver's address with your token:
https://<your host>/api/thrivecart?token=<your token>(ThriveCart's webhooks guide). ThriveCart checks the address when you save it and needs a2xxanswer to both aHEADand aPOST: the receiver answers both200when the token is right, and does nothing for aPOSTthat names no event.ThriveCart's webhooks go out for every event and every product. The receiver takes order.success (a new order) and answers the rest
200with nothing done.
Keep the URL secret like a password: it shows in your server's access logs and in ThriveCart's webhook settings. To change the token, change it in your environment and in the webhook URL together; if you change the secret word in ThriveCart, change THRIVECART_SECRET too.
How it works
- Token first. ThriveCart does not sign its webhooks, and the same secret word goes to every webhook URL of your account (Zapier, your CRM, any tool you connected). So the receiver first compares the URL's
tokenwith yours, in constant time and before it reads the body; a missing or wrong token is answered401. - Then the secret word. A delivery that names an event must carry your secret word in
thrivecart_secret(compared in constant time), and withaccountset, your account name inthrivecart_account; otherwise it is answered401. An order more than a day old by its own date is a replay and is ignored. - Answered at once. A delivery it takes is answered
200, and the check runs after the answer (waitUntilon serverless hosts), within 25 seconds. - One check per address. The buyer's address (
customer[email]) is checked with our API. A definite answer is remembered for 30 days under a hash of the address (never the address itself), in the memory of the instance that checked it (up to 1,000 addresses) and in yourstoreif you pass one. A delivery ThriveCart sends again (samewebhook_id), the same order again, or the same buyer's next order costs nothing more when it reaches an instance that remembers it; without astore, another instance or a restart checks the address again. - Reported.
onResultgets the event, ThriveCart's order and customer ids, themode(liveortest), the outcome (flagged,allowed,no_addressorunchecked), whether the answer was remembered, and the decision.
Our own timeout or failure is unchecked: never flagged and never remembered, so it never replaces an earlier verdict. The delivery was already answered 200, so ThriveCart does not send it again: list the orders left unchecked from onResult if you want to look at them later. Test-mode orders are checked like live ones; mode tells them apart.
Try it free first
First on your machine: save this as try.mjs beside email-validation-thrivecart.mjs and run it with node try.mjs and your key in EMAIL_VALIDATION_API_KEY.
import { createEmailCheck } from './email-validation-thrivecart.mjs';
const check = createEmailCheck({ apiKey: process.env.EMAIL_VALIDATION_API_KEY });
const decision = await check('no_mailbox@sandbox.email-validation.org');
console.log(decision.flagged, decision.status, decision.reason); // prints: true invalid no_mailboxSandbox checks cost no credit. That domain receives no mail, so send it nothing.
Then in ThriveCart: set one product's status to Test mode and buy it once yourself on its checkout with your own email address and the test card your payment processor gives (ThriveCart's guide to testing your checkout). Webhooks fire for test orders, and ThriveCart still mails the buyer a receipt, so never use a test or invented address there. onResult reports the order with mode: 'test', its outcome and status. That check uses one credit unless the answer is unknown.
Options
| Option | Default | What it does |
|---|---|---|
apiKey | required | Our API key (Validate addresses). Missing: nothing is checked. |
region | us | eu checks the address in the EU and stores its result there (same keys and credits). |
token | required | The webhook URL's ?token=: at least 24 URL-safe characters. |
secret | required | Your ThriveCart secret word, compared with each delivery's thrivecart_secret. |
account | none | Your ThriveCart account name: a delivery naming another account is refused. |
events | ['order.success'] | Add cart.abandoned to check the address typed into a checkout that was left (ThriveCart shows no sample of that event yet). |
flag | ['invalid'] | Statuses that flag an order: invalid, disposable, catch_all, unknown. |
store | memory | A Workers KV namespace, or anything with get(key) and put(key, value, { expirationTtl }): answers shared across instances, no address in it. |
rememberDays | 30 | How long a definite answer stands in for a new check (1 to 365 days). |
timeoutMs | 6000 | How long a check may take before the order stays unchecked (whole milliseconds, at most 20000). |
waitUntil | none | Keeps the work after the answer running on a serverless host. |
onResult | none | Called once per delivery worked on, never with the address; what it throws is ignored. |
Credits and limits
Each check uses one credit; unknown results and sandbox addresses are free. A remembered answer costs nothing.
When our API asks it to slow down (429 or 503), the receiver waits as long as asked, at most 20 seconds a time and three tries, and never past the delivery's 25 seconds; a refused check is not charged.
It fails open: no key, a timeout, a network error, a rate limit or any error answer leaves the order as it is.