Kelly Michels 13 min read Payments

Building Your Own Billing Screens on Stripe

Everything around the card box is yours to build. The card box never is.

You can replace Stripe's hosted billing portal with pages inside your own product in a few days of focused work, as long as one thing stays with Stripe: the box where the card number is typed. This post covers what was built for WindsockEHS, what you need before you start, and the decisions that are easy to miss.

Before: Stripe's hosted customer portal.
After: the same plan on the WindsockEHS Billing page, inside the app.

Both run in Stripe's test mode with sample data.

Why WindsockEHS left the hosted portal

Stripe's customer portal is the fastest way to give customers self-service billing. WindsockEHS launched with it. Three things led to replacing it:

  • Branding is account-wide. A portal configuration holds a headline, links and features. The logo, colors and business name come from the Stripe account. If several products share one account, they all share one look. WindsockEHS moved to its own Stripe account first, and the portal still did not feel like part of the product.
  • No dark mode and no accessibility mode. WindsockEHS follows a Theme switch and an Accessibility switch on every page. The portal has one appearance. A customer who works in high contrast was dropped into a page that ignored that choice.
  • It is a different place. The customer leaves your app, loses your menu and has to find the way back. For something as sensitive as money, that jump costs trust.

The hosted portal still has a job in WindsockEHS. It is the fallback when the in-app page cannot load, and it is a good answer for many teams. More on that at the end.

The one thing you must not build

Never build your own card number field. Card details go into Stripe's Payment Element, which Stripe serves in an iframe from its own domain. Your server never sees the number, the expiry or the security code.

That single rule decides your PCI scope. With every card field hosted by Stripe, a merchant can usually self-assess with the shortest questionnaire, SAQ A. Put one card input in your own HTML and you move to a far longer one, with scans and controls a small company does not want. Confirm your own scope with Stripe's PCI guide or your acquirer. This post is not an assessment.

Everything around that box is yours to build: the plan summary, usage, invoices, the buttons, the dialogs and the words.

Staying compliant

Stripe carries most of the weight, but not all of it. Three things decide whether a custom billing page stays inside the light end of the rules: which PCI questionnaire applies, how 3D Secure is handled, and the everyday habits that quietly pull card data back into your systems.

PCI DSS: what SAQ A means and what it still asks

PCI DSS is the card industry's security standard. Every business that takes cards must confirm it complies each year, usually with a self-assessment questionnaire (SAQ). Which questionnaire applies depends on where card data travels:

SetupQuestionnaireWhat that means
Every card field is a Stripe iframe (Payment Element, Checkout or the hosted portal)SAQ AThe shortest form. Card data never touches your servers or your page's own code.
Your page builds its own card fields and sends them to Stripe from your scriptSAQ A-EPA much longer form. Your web server and page scripts are now in scope.
Card numbers pass through or are stored on your serversSAQ DThe full standard: scans, penetration tests, logging and access controls.

SAQ A is not "nothing to do". It still expects you to:

  • Serve every billing page over HTTPS and keep the TLS setup current.
  • Control the scripts on your payment pages. PCI DSS 4.0 added rules about scripts on pages that host a payment form, because attackers skim cards by injecting a script into the parent page. For SAQ A, the PCI Security Standards Council turned those rules into an eligibility check in 2025: you confirm your site is protected against script attacks that could affect the payment form. In practice that means a content security policy, a short and reviewed list of scripts on billing pages, and no tag managers or marketing pixels there.
  • Protect the accounts that can change billing: strong passwords and two-step sign-in for the Stripe dashboard and for your own admin accounts.
  • Fill in the questionnaire every year. Stripe can pre-fill SAQ A for accounts that use only its hosted fields. Look for it under compliance in the Stripe dashboard.

The questionnaires change between versions. Read the current SAQ A eligibility criteria before you rely on it.

3D Secure and strong customer authentication

3D Secure is the step where the card's bank asks the cardholder to confirm a payment, usually in their banking app or with a one-time code. In the European Economic Area and the UK, strong customer authentication (SCA) rules require it for many online payments. Elsewhere a bank can still ask for it at any time, and a payment it asks to confirm will not go through until the customer does.

  • Let Stripe decide when to ask. The Payment Element and Stripe.js show the bank's challenge for you. Do not try to skip it or build your own.
  • Handle "needs action" everywhere money moves. A SetupIntent or PaymentIntent can come back as requires_action. Your page must call Stripe.js to show the challenge, then check the result on your server. That applies to a new card, an upgrade charged today and paying an overdue invoice.
  • Save cards for later charges. Confirm the card with a SetupIntent when the customer is present, so renewals can run while they are away. Stripe marks those later charges as merchant-initiated, which banks usually let through without a challenge.
  • Plan for renewals the bank still challenges. Sometimes a bank asks for confirmation on a renewal anyway. Email the customer a link back to the Billing page, where the open invoice can be paid and confirmed. Do not just retry the charge quietly.
  • Liability usually shifts. When a payment passes 3D Secure, fraud chargebacks on it usually move to the card's bank. That is one more reason not to bypass it.

Things that break compliance without anyone noticing

Most compliance failures are not a hack. They are a convenience someone added. Avoid all of these:

  • Building your own card number, expiry or security code field, even one that forwards straight to Stripe. That moves you from SAQ A to SAQ A-EP.
  • Copying Stripe.js or bundling it into your own build. Load it from js.stripe.com every time.
  • Taking card numbers by email, chat, support ticket or phone and typing them in for the customer. Send a link to the Billing page instead. If phone payments are a must, use a dedicated tool for them, not your own admin screens.
  • Logging or storing card data anywhere: request logs, error trackers, analytics, database fields, spreadsheets or support notes. Never ask for or keep the security code, and never store a full card number. Show only the brand, last four digits and expiry that Stripe returns.
  • Putting session replay, screen recording, heatmaps, chat widgets or marketing tags on billing pages. They add script risk to the page that hosts the card form and may capture what customers type around it.
  • Putting card details or secrets in URLs or query strings, where they end up in browser history, server logs and referrer headers.
  • Exposing the secret key. It belongs on the server only, never in browser code, a mobile app, the repository or a chat message. Use a restricted key where you can, and rotate any key that leaked.
  • Accepting webhooks without checking the signature. An unsigned webhook lets anyone mark an invoice paid or a plan active.
  • Turning off HTTPS, mixing in http content, or loosening the content security policy to get a third-party script working on a billing page.
  • Letting staff accounts share logins for the Stripe dashboard or skip two-step sign-in.

A simple rule covers most of it: card data goes from the customer's keyboard into Stripe's iframe and nowhere else. If a change would let card data pass anywhere else, or adds a script to the page that hosts the form, stop and check it first.

Requirements before you start

You needWhy
A publishable key (pk_test_ or pk_live_) in the browserStripe.js needs it to draw the card form. It is public by design.
A secret key on the server onlyEvery read and change goes through your server. The secret key never reaches the browser, your logs or your repository.
A restricted key if you canGive the app only the permissions it uses: customers, subscriptions, invoices, setup intents.
Stripe.js loaded from js.stripe.comStripe requires it to be loaded from their domain, not bundled or self-hosted.
HTTPS on every page that shows the card formStripe.js refuses to run in live mode over plain http.
A content security policy that allows StripeAllow js.stripe.com for scripts and frames, and api.stripe.com for connections.
A webhook endpoint with signature checkingYour database learns about renewals, failed payments and cancellations from webhooks, not from the page.
Your own customer and subscription ids stored per accountEvery call must name the customer that belongs to the signed-in workspace. Never take a customer id from the browser.
A role checkDecide who may open Billing. WindsockEHS allows workspace Admins only.
An audit logWrite down who changed the card, the plan or the cancel state, and when.
Test mode and live mode kept apartSeparate keys, separate price ids, separate webhooks. A test customer does not exist in live mode.

Two more things are easy to forget. Tell customers in your terms how renewals and refunds work, because your page now shows the Cancel button. And decide who answers billing email, because the page will name an address.

The screens, and the Stripe call behind each

ScreenWhat the customer seesWhat happens underneath
OverviewPlan, price, renewal date, status, card on file, usageOne subscription read with the payment method and customer expanded
InvoicesDate, amount, status, links to view and downloadThe customer's invoice list. Stripe hosts the invoice page and PDF.
Update cardStripe's card form inside your dialogCreate a SetupIntent, confirm it in the browser, then make the new card the default
Billing detailsCompany name, invoice email, addressUpdate the customer
Change planPlans, the price today and the price at renewalPreview an invoice, then update the subscription or book a schedule
CancelEnd date, what is kept, an optional reasonSet cancel at period end. Undo clears it.

A few notes from building them:

  1. Read from Stripe when the page opens. Whether a plan is set to cancel, which card is on file and what is booked for renewal all live in Stripe. WindsockEHS shows them live and keeps only the plan and status in its own database. That removed a whole class of out-of-date screens.
  2. Check the SetupIntent on the server. After the browser confirms the card, the server fetches the SetupIntent and checks that it succeeded and belongs to this workspace's customer before using its card. The browser's word is not enough.
  3. Update in place. After each action, re-read the subscription and redraw the cards on the page. No full reload, no lost scroll position.
  4. Survive Stripe being slow. If the read fails, show what your database knows, say that live details are unavailable, and offer the hosted portal as a way through.

Decisions the hosted portal used to make for you

Once the page is yours, so are the rules. Write these down before you write code.

When does a plan change take effect?

The WindsockEHS rule: a bigger plan or a longer term starts now, and a smaller plan or a shorter term starts at the next renewal. Customers get what they paid for either way, and you never owe a refund for unused time.

  • Upgrade now. Preview the invoice with a fixed proration date and show the amount due today. Then update the subscription with the same proration date, so the amount charged is the amount shown.
  • Downgrade at renewal. Use a subscription schedule with two phases: the current plan until the period ends, then the new one. Offer an undo that releases the schedule.
  • Check that the smaller plan fits. Refuse a downgrade while the account uses more seats or sites than the new plan allows, and say exactly what is over.

What happens when the upgrade payment fails?

Ask Stripe to leave the subscription unchanged until the payment succeeds. A declined card and a card that needs bank confirmation both come back as a pending update with an open invoice. Confirm the payment in the page. If the customer gives up, void that invoice so the pending update is dropped and the plan stays as it was. Decline, bank confirmation, abandon and retry were all tested before shipping.

How does cancelling work?

Cancel at the end of the paid period, never at once, and show the end date before the customer confirms. Offer a way to keep the plan until that date. One trap: Stripe refuses to set cancel at period end while a schedule manages the subscription, so release a booked downgrade first.

What happens when a plan ends or a payment stays unpaid?

Do not lock people out of their own records. WindsockEHS workspaces become read-only: everyone can still sign in, view and export, and an Admin can reach Billing to fix it. The first version suspended the workspace, which also locked out the one person who could pay.

Who is told before a renewal?

Stripe can send renewal emails, but you cannot fully control their wording or timing. WindsockEHS sends its own for 6-month and annual plans at 30, 7 and 2 days before renewal, and none for monthly plans. The link in the email is a signed pointer to that workspace's Billing page. It never signs anyone in: it ends any open session, asks for sign-in and works over HTTPS only.

Tax, refunds and receipts

Decide whether Stripe Tax collects tax and whether checkout collects a tax id. Keep refunds in the Stripe dashboard with a named owner. A refund button in the app is a support policy, not a feature.

Making the card form look like your app

The card form is an iframe, so your stylesheet cannot reach it. Stripe's Appearance API is the way in. You pass colors, font, corner radius and spacing, and Stripe draws its fields to match.

  • Light and dark. Start from Stripe's stripe theme for light and night for dark, then set your own background, text, border and primary colors. When the customer flips your theme switch with the dialog open, call elements.update with the new appearance so the form changes in place.
  • Contrast. Check text, placeholder, border and error colors against WCAG 2.2 AA in both themes. Placeholder text is the usual failure.
  • Size. Raise the font size and field padding when your app's larger text or accessibility mode is on. Keep tap targets at 44 pixels or more on phones.
  • Labels and focus. Keep Stripe's visible field labels and give the focus ring a color that shows on your background.
  • Your own buttons. Save and Cancel sit outside the iframe and are yours. Disable Save while the request runs, and put errors in an element that screen readers announce.

Open the dialog on a phone before you call it done. The first pass wrapped the invoice table and left the dialog body narrower than the dialog.

Testing, and what cost the most time

Test against Stripe's test mode, not only against fakes. The WindsockEHS unit tests fake Stripe and run in seconds. The real surprises came from the real API.

  • A phase needs a duration. The second phase of the schedule was refused until it carried a duration that matched the new price's billing interval.
  • A free period hides payment paths. The first test subscription had free days, so nothing was charged and the decline path never ran. Test upgrades on a subscription that really charges.
  • Use Stripe's test cards. There is one for success, one for a decline and one that asks for bank confirmation. Run every money-moving button with all three.
  • Existing customers behave differently at checkout. Collecting a tax id for a customer that already exists needs checkout to be allowed to update that customer's name. New-customer tests never hit it.
  • A plan set by hand has no subscription. An account you set up manually has a plan in your database and nothing in Stripe. Give it its own message instead of an error.
  • A stored customer can vanish. Switching Stripe accounts or modes leaves customer ids that no longer exist. Detect that and fall back to choosing a plan.
  • Keys are read at start-up. A new publishable key in the environment file does nothing until the app restarts.

Keep a short checklist for going live: live keys, live prices, a live webhook with its own signing secret, and no test subscriptions left in your revenue numbers.

When the hosted portal is still the right answer

Stay on Stripe's portal if you have one product on the account, no theme or accessibility modes of your own, and simple plans. It is secure, maintained by Stripe and takes an afternoon. Building your own pages means you own every rule above and every edge case after it.

Build your own when billing has to look and behave like the rest of your product, when your plan rules are more specific than the portal's switches, or when leaving the app would lose the customer's settings. Keep the portal wired up as a fallback either way. In WindsockEHS it is one link at the bottom of the page, for the day the in-app page cannot reach Stripe.

The Billing page in this post is part of WindsockEHS. Questions? Get in touch. ← Back to Blog