How to sell prepaid credits for an AI tool without granting them twice
The payment says what the customer bought. The credit ledger says where it went. Keep both records and test what happens when delivery runs twice.
Sell prepaid credits for an AI tool by saving the chosen pack and workspace before sending the buyer to card checkout. Add credits only after the payment matches that order, and record the grant once in your app's credit ledger. Railbed for AI tools explains the checkout options for selling credits and collecting invoices. Your application still owns the balance, usage rules and delivery history.
Before you wire checkout, define what a credit buys
A credit balance is a product feature, not a currency balance. Name the work a credit can buy, when a reservation counts as usage and what happens if your service cannot finish a job. If a thumbnail and a high-resolution export consume different amounts, show the rule before the buyer starts the job. When the rules change, decide how current balances will be affected and make that decision visible. Avoid promising an exact number of outputs from a pack if their cost depends on which options the customer picks.
Suppose an AI editor offers previews and finished exports. A preview uses one credit; an export in this example uses five. A pack of 100 credits might cover 20 exports if none of the credits go to previews. It would not necessarily cover 20 completed projects. Changing the export rule later should not alter the record of what the customer previously bought. Save the pack version and advertised terms with the order so your team can answer questions about an earlier sale.
Consider which entity owns the balance. An individual purchase might belong to a person. A team purchase might belong to a workspace that survives when its billing administrator leaves. Make the destination visible on the purchase screen and save its internal identifier. Verify the signed-in person's authority to buy for it. An email typed on the payment page should not decide which workspace gets the credits. The payer and the user who runs jobs can be different people.
Pick the purchase model before you pick the screen
| What you sell | Best for | Record your product needs | Limitation |
|---|---|---|---|
| Reusable fixed offer | A simple product with a reliable delivery check | Individual payment and authorized account mapping | A shared link alone does not identify the signed-in workspace |
| Order-specific credit pack | A self-serve tool whose user buys inside a workspace | Immutable pack choice, workspace, currency and payment reference | Requires the application to own order matching and credit delivery |
| Itemized invoice | A known company buying credits under agreed terms | Invoice reference and the authorized workspace or allocation | An issued invoice is not a verified payment |
Railbed card checkout is best suited to AI tools that want prepaid packs with settlement to a wallet they control and can own the credit ledger themselves. If you need the checkout to meter usage, determine the right enterprise workspace or decide the cost of a model run, those are separate application responsibilities. Railbed subscriptions bill by invoice each period, so a recurring agreement should be clearly distinguished from a one-off credit purchase. For the difference between collecting for a fixed offer and collecting for a specific customer, see hosted checkout versus payment links.
Save the purchase before the customer leaves your app
- Show the pack, price, currency and destination workspace on the final purchase screen. Explain any applicable limits or expiry from your published rules. Confirm the user can buy for that workspace.
- Have your server read the current offer from your catalog. Save the pack version, exact number of units, price, currency and workspace on an order. Do not let a display string supplied by the customer become the final price.
- Create the hosted payment from that saved order using the documented integration. Save the identifier returned for the payment and tie it to your order. If the request is interrupted, check for the existing attempt under the documented retry rules before starting another.
- Send the buyer to the hosted payment page. Give the original workspace a way to revisit status without the buyer having to keep the checkout tab open. Do not add credits just because the customer visits a return page.
At the end of these steps you should see one saved order for the right workspace and an identifiable payment attempt. You should not see a new credit balance yet. Treat that absence as a test requirement rather than a cosmetic delay to hide. If your app shows an optimistic balance before the payment is verified, the customer can start a job they did not pay for and support cannot explain why the figures later changed.
When a workspace owner changes the selected pack before accepting the offer, let the store recalculate the purchase and show the new total. Do not replace the original order's agreed pack after the buyer has started paying. Preserve the relationship between a payment attempt and the exact order terms it was meant to cover. A confirmed payment for a smaller pack shouldn't silently fulfill a later, larger pack. If the buyer actually completed two attempts, investigate both records rather than assuming that one event must be a retry.
In Railbed's card flow the buyer enters card details on the provider's page. Buyer ID checks depend on the provider. Don't collect card details or identity documents in the app's assistant to help someone get past a payment step. Explain what the customer can expect, then use your authorized records to check the outcome if the customer returns without a confirmation. The customer who paid through a colleague needs the same reliable lookup path as the one who stayed in the original browser.
Give the payment and the credit ledger different jobs
The payment record answers whether the specific purchase was confirmed. The credit ledger answers how the workspace balance changed. Use the confirmed provider record to authorize the purchased credit grant, but keep the grant in an application record with a reference to its order. Follow the agent checkout payment verification guide to match the payment identifier, order reference, expected amount, currency and environment. Held, unresolved or mismatched records do not authorize a routine grant.
An accurate balance is not enough if you cannot explain it. Keep durable entries for purchases, usage, corrections and any reserves for work in progress. Store the time, unit count, reason and related event or order. For example, a purchase that grants 100 credits and two completed exports that consume five apiece leave 90 credits before other movements. An employee should be able to play that history back from the ledger. They should not need to remember a conversation where a different balance was shown yesterday.
Make repeat processing harmless
A single payment confirmation may reach your system more than once. Your credit ledger needs a durable rule that the same purchase does not grant twice, including when two workers process it near the same time. In an app with a database, one approach is to record a unique purchase grant tied to the order and apply the balance change in the same transaction. Confirming receipt of a notification and recording a grant are not always the same thing. If fulfillment runs later, save the work durably and make its retry safe as well.
Imagine the order is verified, the worker adds credits, and its connection drops before it can tell the rest of the system. The next worker shouldn't have to guess whether the first one succeeded. It checks the ledger for that purchase and resumes any separate notification without granting the credits again. In the opposite case, if the grant didn't commit, the next worker should still be able to deliver it. Define success by the ledger result, not by one log line saying a worker started.
A credit pack purchase and a goodwill correction are different actions. If support grants extra units because the customer's job failed, make the reason and authority visible rather than editing the original purchase grant. When reversing a mistaken grant, retain the original entry and record the correction under your policy. If credits were spent already, the right response is a decision by your team, not an unannounced negative balance caused by deleting part of the ledger.
Keep usage from racing the credit balance
Buying credits is only one side of the flow. Decide when jobs reserve them, when completed work consumes them and when failed work releases them. For a short task the app might record the usage when it accepts the job. For a long task whose output can fail, the app may need a reservation visible to both the buyer and support. Do not call reserved credits spent unless you have defined that behavior and explained it. The same number can have different consequences for someone deciding whether to order another pack.
Suppose a team has 10 credits and two colleagues start jobs priced at eight credits each. If each job reads the same old balance and neither checks the other, both can appear allowable. Have the system that owns the ledger make the reservation or spending decision. When the service receives a retry for the same job, it should find the original reservation instead of spending again. Verify what happens to the balance when a job never returns a result. These are separate tests from paying for a pack successfully.
If the system distinguishes purchased, promotional and restored credits, write down how it spends them. A promotional grant might expire under terms that do not apply to a paid pack. A support correction might inherit the original pack terms. Do not make support classify a credit by the balance alone. Save the source and relevant terms with each entry. That makes a customer complaint about expiry possible to investigate without rewriting history first.
Give the customer two useful messages
One message should say what happened to the payment. The other should say what happened to the pack. For an order confirmed but waiting for delivery, tell the customer the purchase was received and the workspace balance is being updated. If payment remains unconfirmed, say you are checking the existing attempt. Only a verified grant should produce a message such as “100 credits added to the Studio workspace.” Put the destination in the message so a buyer who works with multiple teams knows where to look.
Do not let the missing balance become a prompt to buy again. Have support locate the original payment and then the credit entry. If no verified payment exists, explain what information is missing and where to look. If the payment exists and the credit entry does not, recover the original grant. If both exist, look at later usage, reservations or workspace selection. These paths can explain the same initial complaint without causing a second payment.
Prove the workflow before a real buyer uses it
Run one Test purchase from the same screen your users will use. Open the saved order, match the Test payment and confirm that the right workspace receives the correct units. Repeat processing of that legitimate Test payment and check that there is still one purchase entry. Next start a checkout and stop before paying. Returning to the app should not add anything. Run a separate case in which fulfillment is interrupted after the payment is confirmed. Recover the original grant or verify it was already applied instead of encouraging a new purchase.
Add a case involving two workspaces. Buy in one workspace, switch to another in the app, then confirm the first order. The destination should stay the one in the saved order. If the product is sold to companies as well as people, rehearse a case where procurement pays but somebody else uses the credits. Support should be able to explain the payment and grant without assuming the email on the receipt was the user who needed access.
Record the steps and observed results in your project's CHECKOUTS.md. Railbed maintains checkouts.md for documenting offers, checkout wiring, fulfillment and evidence in agent-built applications. Record which business and mode you tested and how another developer can confirm that the ledger is correct. Do not include secrets or sensitive buyer details. For how to organize the file, see using CHECKOUTS.md to document payments for AI agents.
What finance sees after the first legitimate sale
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 does not mean a cardholder cannot raise a dispute or the business never owes a refund. Have finance match paid orders to wallet receipts, then track any later bank withdrawal separately. A credit grant is not a bank deposit. See how to reconcile USDC settlements with bank withdrawals for the evidence behind each step.
For a tool with significant compute costs, review the economics of the credits independently from checkout. A completed payment tells you the purchase was funded. It does not tell you whether your application let accounts claim repeated promotional grants or run more work than it debited. Decide what a new account can do, how you will identify duplicate grants and which service costs an operator should review. If your business sells restricted products or services, use lawful offers and retain any applicable eligibility controls. Changing payment routes does not change those duties.
Begin with one narrow offer in Live once your team approves the launch. Watch the first genuine order through its payment, grant and wallet receipt. If a confirmed payment credits the wrong workspace or the same sale grants twice, stop new traffic to that path and resolve existing payments before expanding the catalog. Leave buyers a way to track orders already underway. A Test checklist followed by a traceable Live receipt gives your team a better launch record than a page that simply shows a working Buy button.
FAQ
Can I sell prepaid AI credits by card with Railbed?
Yes. A customer can pay for a documented offer through hosted card checkout. Your application owns the credit balance and grants the units from a verified payment matched to its order.
What should I save before creating checkout?
Save the approved pack version, unit count, price, currency, destination workspace and an internal order reference. Store the returned payment identifier against that order's payment attempt.
How do I stop payment notifications from adding credits twice?
Give each purchase one durable grant in the application ledger. Reprocessing the same confirmed payment should find that grant and leave the credit balance unchanged.
What if the buyer pays but cannot see their credits?
Check the matched payment and the ledger for the saved workspace. Recover the original grant if it didn't happen, or check later usage and workspace selection if it did. Don't ask for another payment without checking the first.
Should an invoice for a credit pack increase the customer's balance?
Not merely because it was issued. Grant the agreed credits only when the invoice payment is verified and matched to the right workspace and order.
Does the customer need to use a crypto wallet to buy credits by card?
No. The customer pays on the provider's card page. Railbed's card proceeds settle to a wallet the merchant controls, almost always as USDC on Polygon.
What should a credit pack Test purchase prove?
It should prove that the saved order matches the payment, the right workspace gets the purchased units once, and an unfinished purchase grants nothing. Test a delivery interruption separately.
Keep the balance explainable
Make every change to a credit balance traceable to one paid purchase, one job or one authorized correction. If another person can use the order and ledger to explain why the customer's balance changed, your system is ready for a more useful pilot than a successful checkout demo alone.