E-commerce & payments
Validate customer emails and phone numbers in Stripe
Verify the email and phone of each new Stripe customer from a signed customer.created webhook, write the result to metadata, and check the IP before a payment.
Updated 2026-11-26
This recipe checks the email and phone number of every new Stripe customer. A signed customer.created webhook reaches a small receiver, the receiver calls the API, and the verdict goes back to the customer as metadata. A second, optional part checks the IP address of the checkout request in your backend before it creates a PaymentIntent. Stripe has no native Qelka app, so the receiver sits in between.
What you need
- A Stripe account and a secret key (
STRIPE_SECRET_KEY). A restricted Stripe key with write access to Customers and PaymentIntents is enough. - A Qelka API key in
QELKA_API_KEY. Ask_test_key returns simulated results and never spends credits: see Test mode. Use one with Stripe's sandbox, and a live key with live mode. - A Node.js 18 or later server reachable over HTTPS, with
npm install express stripe @qelka/sdk.
Steps
1. Create the event destination
In the Stripe Dashboard, open Workbench, then the Webhooks tab, and create an event destination for your account. Choose the Snapshot payload, so each event carries the customer object, and select the customer.created event. Enter your receiver's HTTPS URL, for example https://example.com/stripe/webhook. Stripe then shows a signing secret that starts with whsec_: put it in STRIPE_WEBHOOK_SECRET.
To test on your machine first, the Stripe CLI forwards events to a local port and prints its own whsec_ secret:
stripe listen --events customer.created --forward-to localhost:3000/stripe/webhook
2. The receiver
import express from 'express'
import Stripe from 'stripe'
import { ApiConnectionError, ApiError, Client } from '@qelka/sdk'
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { timeout: 10000 })
const validation = new Client({ apiKey: process.env.QELKA_API_KEY, timeoutMs: 8000 })
const app = express()
async function settle(task) {
try {
return await task()
} catch (error) {
if (!(error instanceof ApiError) && !(error instanceof ApiConnectionError)) throw error
if (error instanceof ApiError && error.type === 'unprocessable_input') return null
console.error('validation skipped', error instanceof ApiError ? `${error.type} ${error.requestId}` : 'unreachable')
return null
}
}
async function checkCustomer(customerId) {
const customer = await stripe.customers.retrieve(customerId)
if (customer.deleted || customer.metadata.email_status) return
const country = customer.address?.country || undefined
const [email, phone] = await Promise.all([
customer.email ? settle(() => validation.email.verify({ email: customer.email })) : null,
customer.phone ? settle(() => validation.phone.validate({ phone: customer.phone, country })) : null,
])
const metadata = {}
if (customer.email) {
metadata.email_status = email ? email.status : 'unchecked'
if (email?.reason) metadata.email_reason = email.reason
if (email?.did_you_mean) metadata.email_suggestion = email.did_you_mean
}
if (customer.phone) {
metadata.phone_status = phone ? phone.status : 'unchecked'
if (phone?.e164) metadata.phone_e164 = phone.e164
if (phone?.line_type) metadata.phone_line_type = phone.line_type
}
if (Object.keys(metadata).length > 0) await stripe.customers.update(customer.id, { metadata })
}
app.post('/stripe/webhook', express.raw({ type: 'application/json' }), (req, res) => {
let event
try {
event = stripe.webhooks.constructEvent(req.body, req.get('Stripe-Signature'), process.env.STRIPE_WEBHOOK_SECRET)
} catch (error) {
return res.status(400).send(`Signature verification failed: ${error.message}`)
}
res.sendStatus(200)
if (event.type === 'customer.created') {
checkCustomer(event.data.object.id).catch((error) => console.error('customer check failed', event.id, error.message))
}
})
app.listen(3000)
Four details matter here:
express.rawkeeps the body as bytes.constructEventverifies theStripe-Signatureheader against the raw body and the signing secret, and rejects old timestamps to stop replays. A body that a JSON parser touched first fails verification.- The route answers
200before it calls any API, because Stripe expects a quick2xxand retries otherwise. checkCustomerreads the customer again instead of trusting the snapshot, and skips it whenemail_statusis already set. Stripe can deliver the same event twice, and a repeat check would cost credits again.countrycomes from the customer's address and lets the API read a phone number written without+. It is left out, not sent asnull, when there is no address.
3. Read the metadata
| Key | Values | Suggested action |
|---|---|---|
email_status |
undeliverable |
Receipts and invoices will bounce: ask the customer for another address, show email_suggestion to support |
risky |
Read email_reason: disposable deserves review on trials and free tiers |
|
deliverable or unknown |
Nothing to do | |
unchecked |
The API was unreachable or refused the key: re-check later | |
phone_status |
valid |
Use phone_e164 for calls and SMS |
invalid |
Do not text it | |
unknown |
No + and no country: collect the country |
Find the customers to fix with the Search API, for example stripe.customers.search({ query: 'metadata["email_status"]:"undeliverable"' }). Search results can lag behind recent changes, so do not use it right after a write.
Updating metadata sends a customer.updated event, not a new customer.created, so the receiver does not loop.
4. Check the IP before a payment (optional)
The webhook never sees the shopper's IP address, but your backend does when it creates the PaymentIntent. Check it there and ask for 3D Secure when the request looks risky:
app.set('trust proxy', 1)
app.post('/create-payment-intent', express.json(), async (req, res) => {
const lookup = await settle(() => validation.ip.lookup({ ip: req.ip }))
const risky = lookup !== null && (lookup.risk.level === 'high' || lookup.flags.tor)
const paymentIntent = await stripe.paymentIntents.create({
amount: await orderTotalInCents(req.body.cartId),
currency: 'usd',
automatic_payment_methods: { enabled: true },
metadata: {
ip_risk: lookup ? lookup.risk.level : 'unchecked',
ip_flags: lookup ? Object.keys(lookup.flags).filter((flag) => lookup.flags[flag]).join(',') : '',
},
...(risky ? { payment_method_options: { card: { request_three_d_secure: 'challenge' } } } : {}),
})
res.json({ clientSecret: paymentIntent.client_secret })
})
orderTotalInCents is your own function: always compute the amount on the server. trust proxy makes req.ip the client address behind one proxy or load balancer; set it to match your hosting. A private or local address, as in development, comes back as 422 unprocessable_input, which settle treats as "no signal". request_three_d_secure: 'challenge' asks Stripe to run 3D Secure with a challenge; the card issuer has the last word, and cards without 3D Secure proceed normally. The flags are written to the PaymentIntent's metadata, which Stripe copies to the charge, so a Radar rule can read them if your Radar plan has custom rules. See Flag VPN and data center traffic for what each flag means.
Do not refuse payments on a VPN flag alone: many honest people use one. Ask for more proof instead.
Handle errors and rate limits
Nothing is billed on errors. The SDK retries 429, 502 and 503, waiting Retry-After. 401 invalid_api_key, 403 forbidden and 402 insufficient_credits end as unchecked here and in the logs with the request id, so alert on them. A key allows 200 requests per 10 seconds; importing many customers at once fires many customer.created events, so for existing customers export them and run a bulk file check instead. Each email check costs 1 credit, each basic phone check 1 and each IP lookup 1. See Errors and Rate limits.
Related
Frequently asked questions
Can Stripe block a customer with a bad email by itself?
Why write the result to metadata?
Does the IP check replace Radar?
More in E-commerce & payments
All integrationsPut this check in your product
Get an API key in under a minute. 100 free credits every month, no card required.
- 100 free credits a month
- No card
- Test keys spend nothing
- Cancel any time