How to add Railbed checkout to a Next.js app with an AI coding agent

Use the Next.js recipe to connect your pricing page, saved order, hosted payment and delivery. Prove each handoff before deploying Live.

By
Railbed
Published
Reading time
11 min
Centered isometric ivory application panels and navy checkout terminal beside mint connectors

To add Railbed checkout to a Next.js app, start with the checkouts.md recipe for Next.js and one offer. Have the app calculate the price on the server, save an order, and send the buyer to hosted payment. Verify the matching Railbed payment before granting access or releasing an order. Use your coding agent to connect the pieces and document the tests. The first useful result is a Test purchase your team can trace from the pricing page to the thing the buyer actually receives.

Identify the Next.js application that owns checkout

The documented recipe targets the Next.js App Router and uses route handlers on the Node.js runtime. It also discusses adapting the approach for the Pages Router or Edge runtime. Start by checking the repository you already have rather than assuming a newly generated starter is representative. A website can render its marketing pages in Next.js while a separate service owns the cart, account records and order database. If that's your setup, the pricing page is not automatically the best place to implement payment creation.

Ask the coding agent to find four things before editing: the Buy button or proposed entry page, the source of the approved price, the system that knows which customer is signed in, and the process that will deliver the purchase. Have it name the existing files or services and show where the proposed change belongs. If several sites share the project, name the one you intend to change. A correct integration applied to the wrong application still won't help the customer who is trying to buy.

The standard recipe assumes a database for orders and processed events. It shows PostgreSQL and discusses using an existing database layer instead. Keep your team's migration and deployment process. If you already have an order table with references used by support and finance, don't create an unrelated second ledger just to match a tutorial. Map the recipe to your existing records. For each field, establish who writes it and which later operation reads it. That mapping matters more than copying the example's file names.

Part of the project What to locate What it must not decide
Pricing page The approved offer and the entry point to checkout Whether a later payment is verified
Server checkout handler The current account, approved total and saved order A price supplied by a browser or chat message
Payment notification handler Verified notifications and a lookup of the matching payment Whether an unrelated record should release the purchase
Return page or order history The authorized buyer's saved order state Whether loading the page makes the order paid
Fulfillment service The item, shipment or access the paid order authorizes Whether a second notification buys a second delivery

A static export that cannot run server logic calls for a different choice. If you have one fixed offer and a manual way to connect each payment to the buyer, a reusable checkout may be enough. If you need a running server to bind a cart to a customer or grant a license, build that part where your application can actually execute and keep credentials private. See checkout session API versus hosted buy buttons for the decision before you start implementing.

Connect Test without putting credentials in the browser

Railbed's agent documentation explains the supported project connection and browser approval process. Use the Test environment first. Confirm the intended business and mode on the official page you initiated. Project credentials and payment notification secrets belong in the server's approved environment, not in a prompt, issue, screenshot or repository. A public environment variable intended for browser code is not a suitable place for either value. Use the names of the environment variables in your documentation and refer developers to the approved way to set them.

Decide what local development, a preview deployment and the production site are allowed to do. A preview page that looks exactly like production still should not take a real payment by accident. The Next.js recipe distinguishes the Test configuration from the production configuration. Keep the database and notification endpoint aligned with that choice as well. If a simulated payment appears in a real customer report, investigate how the environment was wired rather than filtering it out after the fact and calling the setup complete.

Consider an AI reporting tool where the founder is testing a paid bundle in two browser tabs. One is a deployment preview; the other is the main customer site. If the bundle label and branding are identical, a screenshot can't tell finance which app took the order. Record the environment with the order and the payment. Label Test in team-facing views. For a rehearsal, use a fictional customer and a known test account instead of copying an actual buyer's payment or identity information into the preview database.

Connecting Codex or another assistant to business records is a different job. The official assistant connection can read eligible records and turn supported changes into a proposal for your team to approve. It is not the credential that your deployed app uses when a customer clicks Buy. A project that needs only Test checkout code does not need an additional Live assistant connection. See how to use Codex to build and test a Railbed checkout for a way to scope the coding agent's work.

Save exactly what the buyer intends to purchase

The browser can identify the requested product or cart, but the server should resolve the amount and currency from records the business controls. For a fixed offer, the approved product record supplies both. For a variable cart, the server should check availability, discounts, taxes and delivery as applicable before creating the payment. Save the agreed item or cart, the expected amount and currency, the buying account or recipient, and an internal reference. Keep the returned payment identifier with the related attempt so a later confirmation can be matched to the saved order.

For example, a SaaS app sells subscriptions and separate prepaid exports. A support representative buys exports for a particular team workspace, but their finance colleague completes payment. The workspace on the saved order is where the paid exports belong. The payer's email isn't a replacement for the application's account record. If a buyer changes workspaces before starting checkout, the server should establish which account is buying rather than letting a recent browser action change the target of a purchase already under way. For billing and account examples, see Railbed for SaaS.

Keep the draft cart and the saved order distinct. A cart can change as a customer edits it. The payment for an order reflects the terms that existed when the authorized request was made. If the buyer changes quantity or destination, show the new total and record a new revision before asking them to pay under those terms. If an earlier attempt remains active, investigate its state before encouraging a second payment. A store should not silently deliver the updated basket against payment for the old one.

The recipe's repeat-request pattern helps handle an interrupted checkout creation request for the same saved order. Apply it according to the current documentation and your order model. It does not make a different basket the same request. Also decide what happens if the customer's click reaches your server twice before an order exists. The application needs its own clear rule about resuming an existing purchase or making a new one. A button that disables itself visually can improve the buyer experience, but it is not the only protection the business should rely on.

Make the hosted handoff clear without making the return page authoritative

In Railbed's documented card flow, the buyer enters payment details on the provider's page and completes any required steps there. Buyer ID checks depend on the provider. Your button should say what the customer is paying for and what to expect when they leave the app. Give buyers a way to find the same order again without relying on a tab to remain open. Keep identity documents, card details and banking codes out of the application's assistant or support conversation.

Design the return page around a question: “What does the store know about this order right now?” If the payment is still being checked, say so and provide a safe way to revisit status. If payment is confirmed but delivery is pending, tell the customer what happens next. If the request cannot be matched to an authorized buyer's order, do not show someone else's purchase details or assume that a reference visible in an address grants access. The receipt experience should report the results of verified processing, not be the mechanism that creates them.

Consider a customer on a phone who switches out to a banking app and later reopens the original order on a laptop. Your Next.js page may never see the expected browser return. The payment and fulfillment can still succeed if they depend on the server's matching order and payment records. Build your support instructions around that possibility. If the customer asks whether they need to pay again, check the original attempt. Do not ask them to reconstruct the browser steps just to establish whether the purchase was delivered.

Verify payment on the server and record fulfillment once

Follow the recipe and the Railbed fulfillment guide for authenticating payment notifications and checking the provider record. Verify messages using the documented signature method, then retrieve the matching payment. Compare the expected order reference, payment identifier, amount, currency and mode. A payment that is held or does not match the purchase needs the appropriate exception process. A visit to the success page is not proof of payment. See how to verify an agentic checkout payment before delivery for a fuller explanation of the confirmation checks.

The recipe gives the developer a place to connect the actual delivery. Do not leave a demo log in place of the paid feature, credit grant or warehouse handoff. Record the fulfillment decision against the saved order so processing a legitimate notification again cannot grant a second purchase. Where delivery is handled by another service, make the work durable before acknowledging a notification you intend to process asynchronously. If the service's response is uncertain, look up the existing work before starting a second shipment or entitlement grant.

Use a separate state for a paid order that is waiting for delivery. A software company should be able to explain that payment was confirmed while an access update is still pending. A shop should be able to identify a parcel whose payment matched but whose label hasn't been issued. This is useful to both the developer and the person replying to the buyer. Neither of them should have to interpret the absence of a shipping email as proof that the buyer's card was declined. If a later event updates an earlier attempt, preserve the already established delivery record and investigate any conflict instead of sending the purchase again.

Test the buyer, support and finance views

Run the first Test purchase from the actual app screen rather than creating only an isolated payment. Use a product and buying account you can verify. Check the saved price, the payment handoff, the payment record and the final access or order output. Then run an incomplete checkout: nothing should be granted by a return-page visit. For a third test, interrupt the delivery step under controlled conditions. When it recovers, the original purchase should be completed once without another payment. Add a repeat notification test with a legitimate Test payment and verify that it produces no duplicate delivery.

Give a colleague a support case without showing them your implementation notes. Ask them to find the order, confirm the payment state and tell the buyer what happens next. If they need the browser tab to have remained open or have to guess which account received the purchase, improve the order record first. Then have the finance owner identify what they would use to reconcile the first real payment. A single log entry marked successful is not evidence of delivery, and Test activity is not settlement evidence.

Before launch, have the coding agent update CHECKOUTS.md with the products, fulfillment rule, wiring and dated evidence. Railbed maintains checkouts.md as an open format for agent-built checkout. List what you observed and leave untested paths marked as such. The person who inherits the project needs to know which environment was tested, what the purchase did, and where to find the result. See how to document payments for AI agents for what belongs in the project file.

Release one offer and watch a real receipt

Have the team responsible for the business approve the production release and verify the host's production configuration. Begin with one defined offer and representative eligible buyers. If you run a high-risk business, keep the real product and destination rules in place and describe the purchase accurately. A Next.js integration does not change which buyers or products are eligible or guarantee they will finish payment. A legitimate Live pilot answers questions that a successful simulation cannot. Keep the remaining catalog on its existing path until you can support the new one.

Railbed never holds funds. Card sales settle to a wallet the merchant controls, almost always as USDC on Polygon. Settled sales can't be pulled back from your wallet. That describes settlement, not the absence of potential disputes or refund obligations. Have finance match the first real payment to the wallet receipt. If you move proceeds to a bank, record conversion and the later credit separately. An order shown as delivered is not proof that a separate withdrawal has reached the bank. The USDC reconciliation guide shows how to keep these records distinct.

Set a stop condition the team understands. A purchase granted to the wrong workspace, a duplicate shipment or an order taken under the wrong price justifies stopping new traffic while you investigate. Keep earlier attempts available for status checks and continue resolving confirmed orders. Put the shop's owner, engineering owner and finance owner on the same record of what was tested and what remains unknown. That document is more useful than a launch note that says only that the checkout was deployed.

FAQ

Can a coding agent add Railbed checkout to a Next.js app?

Yes. Start from the checkouts.md recipe that matches your application. Give the agent a defined product and a clear fulfillment rule, and ask it to show the matching order, payment and delivery in Test.

Does the Next.js recipe work for a site that is only a static export?

The documented App Router recipe uses server-side handlers and a database. A purely static site needs a hosted checkout that fits its offer or a separate server integration for order-specific purchases and verified fulfillment.

Where should Railbed credentials be stored?

Keep them in approved server-side environment storage. Do not expose them as browser variables, commit them to the repository, or paste them into an assistant conversation.

Should the client send the price when opening checkout?

Let the client identify the requested offer or cart. Have the server calculate, validate and save the final amount and currency from the application's approved records.

Can the Next.js success page grant an entitlement?

It should report the current authorized order state, not decide that the buyer paid. Use matched, verified payment evidence and record the fulfillment decision separately.

Does the test prove that all buyers can finish paying?

No. A simulated purchase proves specified application behavior. Buyer ID checks depend on the provider, and a limited Live pilot is needed to observe the actual buyer handoff.

What proves the checkout is ready to expand?

A paid order matches the right price and account, the app delivers once, support can explain unresolved cases, and finance can trace a legitimate Live settlement. Document which parts you actually verified.