In review · not yet published
6 min readLaunchapp
Keeping PCI scope small
Hosted fields, webhook-driven state, idempotency and pricing decided before paywalls: the unglamorous payment decisions that pay for themselves.
Payments reward the teams that get the unglamorous parts right. Card forms are a solved problem. What sinks a payments product is everything around the form: where card data travels, what your system believes when a confirmation arrives late or twice, and whether anyone decided what you are charging for before the billing code was written.
We have worked on payments in three very different settings: a B2B e-commerce payments product at Worldpay, healthcare payments at Phreesia, and a restaurant point of sale that takes real card payments every day. The first two are prior roles of Rafael Aleksandryan, who leads product at Launchapp; the third we built ourselves. The same four decisions mattered in all three.
1. Keep card data out of your servers
Every system that stores, processes or transmits card data is in scope for PCI DSS, and scope is cost: more controls, more evidence, a longer assessment. The PCI Security Standards Council publishes the self-assessment questionnaires that define how much applies to you in its document library; the shortest ones are for merchants who have fully outsourced card handling to a validated provider.
So the first design question is not "which processor" but "which of our systems will ever see a card number". The answer we aim for is none.
Hosted fields or hosted pages make that possible. The card form is rendered by the processor, inside your page or on theirs. The browser sends card data straight to the processor, and your server receives a token that is useless to anyone who steals it. We design so card data stays out of your servers where the processor allows.
Three habits keep the scope small after launch, which is when it usually grows:
- No card data in logs. Request logging is added by people who are not thinking about payments. Payment routes get an explicit allowlist of fields that may be logged.
- No "temporary" proxying. The quick fix that forwards a card form through your API to add a field puts your API in scope. If the processor's hosted form cannot do something, that is a product conversation, not a workaround.
- Support tooling uses the same tokens. Refunds and lookups go through the processor's references. Nobody in support needs a card number, and the tooling should make it impossible to paste one in.
The cheapest PCI control is the one that never applies to you.
In person, the same idea holds. The point of sale we built for Dina Cocina processes real customer card payments through Mercado Pago every day, and the card interaction belongs to the provider's hardware and software. Our system records an order and a payment reference.
2. Let webhooks, not redirects, decide what is true
The naive flow trusts the browser: the customer pays, lands on a success page, and the success page marks the order paid. Then a customer closes the tab early, or a local payment method confirms an hour later, or a card is disputed next week. None of those events pass through your success page.
The processor is the source of truth, and it tells you what happened asynchronously. So payment state is driven by webhooks, and the redirect is only a hint about what to show.
That gives every payment an honest set of states. A payment is pending from the moment it is created until the provider confirms it. This matters most with methods that confirm late; in Mexico, where Dina Cocina operates, local methods that confirm late are modeled as pending until the provider confirms, and the kitchen display and the order status follow that state instead of guessing.
A webhook handler is small, and almost all of it is defence:
export async function handlePaymentEvent(request: Request) {
const payload = await request.text();
if (!verifySignature(payload, request.headers.get("x-signature"))) {
return new Response(null, { status: 400 });
}
const event = JSON.parse(payload) as PaymentEvent;
const first = await events.insertIfAbsent(event.id, event.type);
if (!first) return new Response(null, { status: 200 });
await payments.transition(event.paymentId, event.type);
return new Response(null, { status: 200 });
}
This is a sketch of the shape, not code from a client system. Each line answers a way webhooks go wrong: the signature check rejects forgeries, recording the event id first makes a redelivered event a no-op, and the state transition is a function that refuses illegal moves, such as marking a refunded payment as paid.
3. Assume everything happens twice
Networks retry. Customers double-click. A mobile app loses signal after sending the request and before reading the response, then sends it again. If "create payment" is not idempotent, some of those become double charges.
Idempotency keys fix this at the boundary. The client generates a key for each intended payment and sends it with every attempt. The server stores the key with the result, and a repeated key returns the stored result without touching the processor again. The key must be created when the customer forms the intent, when the checkout screen is shown, not when the request is sent, or a retry mints a new key and defeats the point.
The same rule runs through the whole system:
- Webhook deliveries are deduplicated by event id, as above.
- State transitions are safe to replay. Applying "confirmed" to a confirmed payment changes nothing.
- Fulfilment, such as sending an order to the kitchen or provisioning a subscription, is triggered by the transition, exactly once, and not by the HTTP request that happened to carry it.
Then comes the part no retry logic covers: daily reconciliation. Once a day, the ledger is compared with the processor's report of what settled. Differences are rare and each one is a bug, a dropped webhook or a refund issued from the processor's dashboard. Finding them the next morning is routine. Finding them at the end of the quarter is an audit.
4. Decide pricing before you build paywalls
Engineering teams like to start with billing code because it is concrete. It is also the most expensive thing to change once customers are on it. Packaging and the metric that matters should be decided before billing is built.
That means answering, in writing, before the first plan is coded:
- What is the unit of value? Seats, transactions, locations, usage. The metric you charge on should grow when the customer gets more value, and it should be something the customer can predict.
- What is in which package? The difference between tiers should be explainable in one sentence to a buyer.
- Is it an add-on, a tier or usage-based? Each implies a different billing model and a different sales conversation.
The outcomes this discipline produces are measurable. At Phreesia, a healthcare payments company, our product lead oversaw a 25% increase in payment revenue and a 20% increase in transactions, and grew a SaaS add-on subscription to $1M+ in revenue with 100% ARR growth. At Worldpay, the work was a new B2B e-commerce payments product taken from idea to go-to-market, at $650M in projected annual volume, including onboarding, pricing, sales, marketing and support readiness for launch.
Those were product results before they were engineering results. The billing system's job is to implement a pricing decision, and it can only be as good as the decision.
Launch readiness is part of the product
A payments product that works in staging is half finished. Onboarding, support and partner integrations have to be ready on day one, because the first failed payment will arrive on day one. Before launch we want to see a support runbook for the five most likely failures, a tested refund path, a way to answer "did this customer pay?" in under a minute, and the reconciliation job running against real data.
What we built
The work behind this post: the B2B payments product at Worldpay and healthcare payments growth at Phreesia, both from our product lead's prior roles, and the Dina Cocina restaurant platform, whose point of sale takes live card payments in production. The cards below link to each.
Proof
The work behind this post
Delivered
B2B payments product at Worldpay
A new B2B e-commerce payments product taken from ideation to go-to-market.
- projected annual volume
- $650M
- projected annual volume
Delivered
Healthcare payments growth at Phreesia
Payment revenue up 25%, a subscription add-on grown to $1M+ revenue, and $500K a year in savings.
- payment revenue
- +25%
- payment revenue
- add-on revenue
- $1M+
- add-on revenue
- saved per year
- $500K
- saved per year
Built
Dina Cocina restaurant platform
A working restaurant in Querétaro runs on a POS built in days, then about three months of upgrades into a full platform: live payments, kitchen display, inventory and a tablet fleet.
- to a working POS
- Days
- to a working POS
- native tablet apps
- 10
- native tablet apps
- card payments in production
- Live
- card payments in production
Founder-led
Building something like this? A founder will reply personally.
Scope a project