Blog

Build a CoinStack integration with an AI coding assistant

CoinStackUpdated 11 min read
Product

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.

FormatWhat it holdsUse it when
/llms-full.txtEvery page of the docs in one fileA chat assistant or agent that can fetch a URL. One request gives it the guides, the plugin pages and the API reference
/llms.txtA list of every page with a one-line description and a linkThe tool should pick the pages it needs instead of reading everything
Any page URL with .md addedThat page as Markdown, such as /guides/webhooks.mdYou are working on one piece, such as the webhook handler, and want a short context
/openapi.jsonThe whole API as an OpenAPI 3.1 fileGenerating a typed client, or giving the agent the source of truth for endpoints, fields and error messages
/mcpA server the tool can queryYour 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/mcp

In 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 docsWhat the wrong code doesWhat happens
Base URL https://coinstack.net/api/v1, Bearer key sent from a server, never a browserCalls the API from front-end JavaScriptThe 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 errorsCrashes on the first failed request, where response is a string
Amounts are strings, and token amounts on quotes and payments are in the smallest unitParses amounts as floats, or shows "25000000" as the amountRounding 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_urlMarks the order paid on the return pageAnyone 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 bodySkips verification, or verifies a re-serialized bodyForged requests are accepted, or every real one is rejected
The same event can arrive more than onceFulfils on every deliveryA 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.

  1. Search the front-end bundle and the repository for sk_. The key should appear only in server code that reads an environment variable.
  2. Find every place that decides an order is paid. Each should check status for completed or resolved. None should use received, which is lower than value on 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 a received >= 25 check would leave a paid order unpaid.
  3. Check that paid status comes from the checkout, not from a payment. A completed payment can still leave its checkout partial.
  4. 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 reference after a timeout, and to retry only 500 errors and timeouts.
  5. Confirm the webhook route reads the raw body, compares with crypto.timingSafeEqual, hmac.compare_digest or hash_equals, and rejects a t more than 300 seconds old.
  6. Confirm the handler matches checkout_id to an order you created before it fulfils anything, and returns 2xx within 10 seconds. A redirect counts as a failure.
  7. Find where event_id is stored, and check that the store enforces uniqueness. When order matters, the handler should get the checkout and act on its current status.
  8. Read what happens to a checkout.completed event with late set to true, for an order you already cancelled. The docs ask you to decide this in advance, and the code should reflect that decision.
  9. If the code builds its own payment screen, check that it hides tokens whose minimum is above the checkout's value, handles Invalid token for 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.

  1. 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.
  2. Select Send test. CoinStack sends a sample checkout.completed event for 10 US dollars with the reference test. 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 answers 2xx.
  3. Send the handler a request yourself with a made-up CoinStack-Signature header. It should answer 400 and change nothing.
  4. Under Recent events, select Resend on the test event. The event_id stays the same on a resend, so the handler should skip it.
  5. 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.

More posts