Integrations · E-commerce
Validate emails of Whop members
Check the email address behind each new Whop membership. One TypeScript file with no dependencies, on your own server, receives your Whop webhook, checks Whop's signature, reads the membership and its member back from Whop, checks the member's address and writes the answer into four keys of the membership's metadata: status, reason, check time and a hash of the address (never the address). A membership whose member's address cannot receive mail is easy to find before its receipts, license keys and access mails bounce. By default only a definite invalid is flagged.
It never touches money or access. It never cancels, pauses, extends or changes a membership, its billing or a payment: it reads a membership and its member and writes four metadata keys, nothing else. What you do with a flagged membership is yours. A flagged membership is a hint to look (a typo is common and harmless), not a verdict on the buyer.
It cannot stop Whop's hosted checkout. Whop runs nothing of yours before a buyer pays on its checkout page, so the receiver hears of a membership once the buyer has paid. Where your own server has the address first (your own sign-up form before you send the buyer to a Whop checkout), createCheckoutCheck answers before you send the buyer on (below).
Status: set up from this page. There is no Whop app listing: you run the file on your server, with your own Whop account API key. It has not yet been tried on a real Whop account, so try it in Whop's sandbox first.
Download it: email-validation-whop.zip holds the file as TypeScript (email-validation-whop.ts) and as JavaScript (email-validation-whop.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 Whop account. Signing up is free (Whop's pricing). Start in Whop's sandbox at sandbox.whop.com, a separate sign-up that moves no real money and has its own keys and webhooks (Whop's sandbox guide).
- A Whop account API key from the Developer page of your Whop dashboard (Account API Keys → Create, Whop's quickstart), with a custom permission set holding
member:basic:read(to read a member),member:email:read(without it Whop shows no address) andmember:manage(to write a membership's metadata). Sandbox and production keys are separate. - A server with an HTTPS address that Whop can reach from the internet and that runs
fetchand Web Crypto: Next.js, Remix, Hono, Bun, Deno, Cloudflare Workers or Node 22 or later. Copyemail-validation-whop.tsinto a TypeScript project, oremail-validation-whop.mjsinto a JavaScript one.
Our key goes only to our API, the Whop key only to Whop's API host for the server you name (production or sandbox), always in the Authorization header. Nothing here logs or answers an address, a key or the webhook secret.
Set it up
Put the receiver at an HTTPS address of your server, with the keys from your environment:
// app/api/whop/route.ts (Next.js); any framework with web Requests works the same way import { after } from 'next/server'; import { createWhopHook } from './email-validation-whop'; const hook = createWhopHook({ apiKey: process.env.EMAIL_VALIDATION_API_KEY, webhookSecret: process.env.WHOP_WEBHOOK_SECRET, whop: { apiKey: process.env.WHOP_API_KEY, server: 'sandbox' }, // 'production' once it works waitUntil: after, // keeps the work after the answer running on serverless hosts onResult: (r) => { if (r.outcome === 'flagged') console.log('Look at Whop membership', r.membershipId, r.decision.status); }, }); export const POST = (request: Request) => hook(request);On 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) };On the Developer page of your Whop dashboard, choose Create webhook: the receiver's address, API version v1 and the event membership.activated (Whop's webhooks guide). Whop's older v2 and v5 webhooks are not signed the same way, so the receiver would refuse every delivery from them with
403.Copy the webhook's secret (it starts
ws_) intoWHOP_WEBHOOK_SECRETexactly as Whop shows it, prefix included. Sandbox and production have separate webhooks, secrets and keys: set the production ones andserver: 'production'once the sandbox works.
How it works
- Signature first. Whop signs each delivery in the Standard Webhooks format. The receiver checks the signature in constant time, and that the delivery is no more than 5 minutes old, before it reads anything in the body; anything else is answered
403. - Answered at once. Whop waits 5 seconds for an answer. A delivery the receiver takes is answered
202, and the rest runs after the answer (waitUntilon serverless hosts), within 25 seconds by default. A delivery it cannot work on now (a pause, below, or a burst its budget cannot hold) is answered503, so Whop sends it again: Whop retries a failed delivery for about 3 days with the same delivery id. - Read back from Whop. Only the membership id is taken from the delivery. The receiver reads the membership, then its member, from Whop's API, and checks the address in Whop's answer. A member with no address (a key without
member:email:read) is reportedno_addressand costs nothing. - One check per member and address. The hash written is the SHA-256 of the member id with the SHA-256 of the address. When the membership already holds this address's hash with a definite status, nothing is checked or written (
already_checked). A second membership of the same member is written from the answer the instance remembers, or yourstoreholds, without a new check; without astore, another instance or a restart checks the address again. - Written only if it still holds. After the check the member is read again, and the answer is written only while the member still has the address checked, in one update of the membership's metadata with only the four keys
ev_email_status,ev_email_reason,ev_email_checked_atandev_email_hash. Whop merges them into the metadata, so no key of yours is dropped. A membership whose metadata has no room for four more keys (the receiver keeps to 50) is left as it is. - Reported.
onResultgets the delivery id, the event, the membership and member ids, the outcome (flagged,allowed,already_checked,no_address,address_changed,keptorunchecked) and the decision.
Our own timeout or failure writes nothing and is reported unchecked. An unknown answer never overwrites a definite status for the same address, nor one your team set without a hash (kept). With membership.activated alone a membership is heard of once, so one left unchecked stays as it is: add the event payment.succeeded (and list it in events) to have each renewal look again, or use onResult to list the memberships left unchecked.
Before your server sends a buyer to Whop
import { createCheckoutCheck } from './email-validation-whop';
const checkoutCheck = createCheckoutCheck({ apiKey: process.env.EMAIL_VALIDATION_API_KEY });
// in your own sign-up route, before you send the buyer to a Whop checkout
const { allow, decision } = await checkoutCheck(email);
if (!allow) return { error: 'Please use an email address that can receive mail.' }; // decision.reason says whyIt never rejects and fails open: no key, a timeout, an error answer or an unknown answers allow: true. Only a definite answer whose status you flag answers allow: false. The buyer can still type another address on Whop's checkout page; the receiver then checks that membership afterwards. A checkout link shared with every buyer has no address to check first. createEmailCheck gives the plain check of an address you already have.
Try it free first
First on your machine: save this as try.mjs beside email-validation-whop.mjs and run it with node try.mjs and your key in EMAIL_VALIDATION_API_KEY.
import { createEmailCheck } from './email-validation-whop.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 Whop's sandbox: join one of your sandbox products yourself with your own email address, paying with Whop's test card 4242 4242 4242 4242 (Whop's sandbox guide). Whop mails its members, so never use a test or invented address there. onResult reports the membership with its outcome and status, and the membership's metadata holds the four keys. 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 read or checked. |
region | us | eu checks the address in the EU and stores its result there (same keys and credits). |
webhookSecret | required | The webhook's secret as Whop shows it (ws_…). |
whop | required | { apiKey, server, requestsPerMinute }: your Whop key; production (default) or sandbox; 1 to 600 Whop calls a minute per instance (default 600). |
events | ['membership.activated'] | Add payment.succeeded to look again at the membership a payment is billed against. |
metadataKeys | ev_email_* | { status, reason, checkedAt, hash }: four different keys of 1 to 40 characters. |
flag | ['invalid'] | Statuses that flag a membership: invalid, disposable, catch_all, unknown. |
store | memory | A { get, set } wrapper around Workers KV or Redis: answers shared across instances, no address in it. |
timeoutMs | 6000 | How long a check may take before the membership stays unchecked (whole milliseconds, at most 60000). |
budgetMs | 25000 | The most one delivery's work may take, waits included: at least timeoutMs + 14000 + three times the spacing between Whop calls (+ 4000 with a store), at most 300000. |
waitUntil | none | Keeps the work after the answer running on a serverless host. |
onResult | none | Called for each 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 membership that already holds the address's answer costs nothing; an answer the instance remembers, or your store holds, costs nothing either.
Whop allows 600 requests a minute per API operation and key by default, shared with your own use of the key (Whop's troubleshooting guide). Each instance keeps its Whop calls evenly spaced (100 ms apart at the default); on a host that runs many instances, or to leave room for your own calls, set requestsPerMinute lower. A new address costs Whop three reads and one write.
Whop refusing the key pauses Whop calls for 10 minutes; our API refusing the key, out of credits or over the key's daily cap pauses checks for 5 minutes. Deliveries meanwhile are answered 503, so Whop sends them again. Whop emails a warning after a day of failed deliveries and disables a webhook after 72 hours of them, and the events it missed while disabled are not sent again: keep credits on the key, and re-enable the webhook in Whop if it happens.
It fails open: no key, a timeout, a network error, a rate limit or any error answer leaves the membership as it is.