Build a CoinStack integration with an AI coding assistant
To build a CoinStack integration with an AI coding assistant, give it the docs in a form it can read. Use docs.coinstack.net/llms-full.txt (every page in one file), the OpenAPI 3.1 file at docs.coinstack.net/openapi.json, or the docs MCP server at docs.coinstack.net/mcp, which lets the tool search the docs as it works. Then review the code against the 6 points the docs say integrations most often get wrong, and prove it with a $1 checkout paid from your own wallet.
Which CoinStack docs file should you give the assistant?
The Build with AI page lists the formats. They suit different tools and different jobs.
| Format | What it holds | Use it when |
|---|---|---|
/llms-full.txt | Every page of the docs in one file | A chat assistant or agent that can fetch a URL. One request gives it the guides, the plugin pages and the API reference |
/llms.txt | A list of every page with a one-line description and a link | The tool should pick the pages it needs instead of reading everything |
Any page URL with .md added | That page as Markdown, such as /guides/webhooks.md | You are working on one piece, such as the webhook handler, and want a short context |
/openapi.json | The whole API as an OpenAPI 3.1 file | Generating a typed client, or giving the agent the source of truth for endpoints, fields and error messages |
/mcp | A server the tool can query | Your editor or agent supports MCP and you want it to look things up while it writes |
The llms.txt convention comes from a proposal by Jeremy Howard dated September 3, 2024, which describes it as a file "to provide information to help agents use a website". The full-text file is the simplest choice and needs nothing installed.
Pick the OpenAPI file when the question is "what fields does this endpoint take". Pick the guides when the question is "what should my code do when this happens". The reference covers the shape of each request. Rules such as fulfilling only on completed, or deciding what to do with a checkout.completed event for an order you already cancelled, live in the guides, so an agent that reads only the OpenAPI file can write requests that are valid and handlers that are wrong. For a whole integration, give it both.
Every page of the docs also has a menu at the top that copies the page as Markdown or opens it in an AI assistant. That works for a quick question in a chat window.
How do you add the CoinStack docs MCP server?
MCP (Model Context Protocol) is, in the words of its own documentation, "an open-source standard for connecting AI applications to external systems". With the docs server added, the tool searches the CoinStack docs when it needs an answer instead of loading all of them up front. The docs give the setup for 4 tools.
In Claude, open Settings, then Connectors, select Add custom connector, and enter https://docs.coinstack.net/mcp.
In Claude Code, run:
claude mcp add --transport http coinstack-docs https://docs.coinstack.net/mcpIn Cursor, add this to mcp.json:
{
"mcpServers": {
"coinstack-docs": {
"url": "https://docs.coinstack.net/mcp"
}
}
}In VS Code, add this to .vscode/mcp.json:
{
"servers": {
"coinstack-docs": {
"type": "http",
"url": "https://docs.coinstack.net/mcp"
}
}
}The server answers questions about the documentation. Your API key never goes into this setup, and it should not: the key belongs in your server's environment, where the generated code reads it.
A starting prompt for a CoinStack integration
Rules written into the prompt do not depend on the agent finding the right paragraph in the docs. This prompt restates the docs' guidance as instructions. Change the first two lines to match your stack and your task.
Read https://docs.coinstack.net/llms-full.txt before writing any code.
Task: in our Express app, when a customer places an order, create a
CoinStack checkout for the order total, save its checkout_id on the
order, and redirect the customer to its url. Mark the order paid from
a webhook.
Rules:
- Base URL is https://coinstack.net/api/v1. Call it only from the
server, with Authorization: Bearer and the key from COINSTACK_API_KEY.
- Every response is {"success": true, "response": {...}} or
{"success": false, "response": "message"}. Check success and the
HTTP status. Never branch on the message text.
- Amounts are strings. Never convert them to floating-point numbers.
- Send our order ID as reference. If a create request times out, list
checkouts by that reference before trying again.
- Mark an order paid only when its checkout status is completed or
resolved. Never on the customer reaching success_url.
- Verify the CoinStack-Signature header on the raw request body before
parsing it. Reject timestamps older than five minutes.
- Store each event_id and skip events already handled. Events can
repeat and arrive out of order.
- Return 2xx within 10 seconds and do slow work afterwards.
- Only call endpoints that appear in https://docs.coinstack.net/openapi.json.The last line matters more than it looks. The API has 18 operations in 6 groups (checkouts, quotes, payments, tokens, webhooks and events), and every call in the generated code should match one of them. Refunds are sent from your own wallet, because CoinStack never holds your funds, so no endpoint is needed for them.
The 6 points the docs say integrations get wrong
The docs list these as "the points integrations most often get wrong". Each one produces code that runs and then fails with real money.
| Point from the docs | What the wrong code does | What happens |
|---|---|---|
Base URL https://coinstack.net/api/v1, Bearer key sent from a server, never a browser | Calls the API from front-end JavaScript | The key ships to every visitor, and anyone who has it can create checkouts on your account |
Every response is {"success": ..., "response": ...} | Reads body.checkout instead of body.response.checkout, or treats response as an object on errors | Crashes on the first failed request, where response is a string |
| Amounts are strings, and token amounts on quotes and payments are in the smallest unit | Parses amounts as floats, or shows "25000000" as the amount | Rounding drift in totals, or a customer told to send 25 million of a token |
Fulfil when the checkout's status is completed, not when the customer returns to success_url | Marks the order paid on the return page | Anyone who visits the return URL directly gets the goods, and customers who close the tab never get them |
Verify CoinStack-Signature on every webhook, using the raw request body | Skips verification, or verifies a re-serialized body | Forged requests are accepted, or every real one is rejected |
| The same event can arrive more than once | Fulfils on every delivery | A second license key, credit or shipment for one payment |
Two of these deserve a closer look because the bug is easy to miss.
The amounts point catches code that looks careful. A token amount of "25000000" for USDC, which has 6 decimals, is 25 USDC: move the decimal point left by decimals places. Decimal strings such as "25.00000000" can have varying numbers of places, so the API overview says to parse them with a decimal type instead of comparing strings. Watch for formatting helpers too. The docs say to use no more decimal places than the currency has, so code that formats every amount with 2 decimals breaks for JPY, which has none.
The signature point usually fails in the framework, not the crypto. In Express, a global express.json() registered before the webhook route parses the body first, and turning it back into text can change the bytes. The docs' Node.js sample uses express.raw({ type: "application/json" }) on that one route. The signed string is the timestamp, a full stop and the raw body. The secret is the whole string including its whsec_ prefix, and the comparison must be constant-time. How to verify payment webhooks covers the same trap in other frameworks.
A review checklist for AI-written payment code
Run through this list before you merge. Each item names something you can find in the diff.
- Search the front-end bundle and the repository for
sk_. The key should appear only in server code that reads an environment variable. - Find every place that decides an order is paid. Each should check
statusforcompletedorresolved. None should usereceived, which is lower thanvalueon a fully paid checkout because the fee comes out first. In the docs example, a $25 USDC payment on Base settles 24.776432 USDC (24.99375 value, minus 0.19995 fee, minus 0.017368 network cost), so areceived >= 25check would leave a paid order unpaid. - Check that paid status comes from the checkout, not from a payment. A completed payment can still leave its checkout
partial. - Look at the create call's retry logic. Creating a checkout twice makes two checkouts, so a generic retry wrapper can bill a customer twice. The errors page says to list checkouts by
referenceafter a timeout, and to retry only500errors and timeouts. - Confirm the webhook route reads the raw body, compares with
crypto.timingSafeEqual,hmac.compare_digestorhash_equals, and rejects atmore than 300 seconds old. - Confirm the handler matches
checkout_idto an order you created before it fulfils anything, and returns2xxwithin 10 seconds. A redirect counts as a failure. - Find where
event_idis stored, and check that the store enforces uniqueness. When order matters, the handler should get the checkout and act on its currentstatus. - Read what happens to a
checkout.completedevent withlateset to true, for an order you already cancelled. The docs ask you to decide this in advance, and the code should reflect that decision. - If the code builds its own payment screen, check that it hides tokens whose
minimumis above the checkout'svalue, handlesInvalid tokenfor methods you switched off under Payment methods, and refreshes quotes when they expire.
Item 9 applies only if you skip the hosted page. The quote flow has enough moving parts to deserve its own walkthrough, in building your own crypto checkout UI with quotes. Retries and ordering get a fuller treatment in reliable payment webhooks.
How to test what the assistant wrote
A checkout is paid with real crypto, so test in this order and spend money last.
- In the dashboard, open Developers, select Add webhook, and point it at the new handler. Copy the signing secret that starts with
whsec_. It is shown only once. - Select Send test. CoinStack sends a sample
checkout.completedevent for 10 US dollars with the referencetest. The dashboard reports "Test delivered" or the status code your server returned. A correct handler verifies the signature, finds no matching order, fulfils nothing and still answers2xx. - Send the handler a request yourself with a made-up
CoinStack-Signatureheader. It should answer400and change nothing. - Under Recent events, select Resend on the test event. The
event_idstays the same on a resend, so the handler should skip it. - Create a checkout for $1, the smallest allowed, and pay it from your own wallet. The order should move to paid once, from the webhook, whether or not you click the return link.
A $1 test paid in USDC on Base costs a few cents in fee and network cost, and the rest settles to your wallet. How to test a crypto checkout before launch lists the underpaid, overpaid and late cases worth running next.
If your store runs on WHMCS, WooCommerce, Blesta or PrestaShop, you may not need generated code at all. The official plugins register their own webhook, so setup is pasting one API key. Getting started with CoinStack walks through that path, and the API quickstart is the hand-written baseline to compare an assistant's output against.
Frequently asked questions
Should I give my CoinStack API key to an AI assistant?
Not in the prompt or the chat. Generated code should read the key from an environment variable, as the docs samples do with COINSTACK_API_KEY. If you want an agent to query your account while it debugs, create a separate key with Read only access. It can list and get checkouts, payments and tokens, and gets a 403 on everything else. Delete it when you are done, and it stops working at once.
Which languages do the CoinStack docs have samples for?
The guides and API reference show cURL, Node.js, Python and PHP. The samples show the request in each language, so they translate directly to any other language your assistant writes. If generated code imports a package, check that it is one you chose on purpose.
Can I generate a client library from the CoinStack OpenAPI file?
Yes. The docs suggest the OpenAPI 3.1 file for that, and for giving an agent the source of truth on endpoints, fields and error messages. A generated client still needs the rules from the guides: fulfil on completed, verify signatures on the raw body and skip duplicate events. The file describes requests and responses, and your code decides what to do with them.
What does the CoinStack docs MCP server do?
It lets an MCP-capable tool such as Claude, Claude Code, Cursor or VS Code search the CoinStack docs on demand instead of reading all of them first. The server is at docs.coinstack.net/mcp. Creating checkouts and reading payments is the job of your own server code, calling the API with your key.
Why did my AI-written webhook handler reject a real event?
The usual cause is the body. If your framework parsed the JSON before verification and the code turned it back into text, the bytes can differ from what was signed. Verify against the raw body. Other causes are a secret missing its whsec_ prefix, a server clock off by more than five minutes, and a secret that was rotated, since the old one stops working straight away.