# Build with AI

You can ask an AI coding assistant (Claude, ChatGPT, Cursor, GitHub Copilot and others) to integrate OnCharge for you. Give it the right context and it can write the session endpoint, checkout page, webhook handler, shipment reporting and tests for your stack. Everything on this page is free to use.

> Whatever tool you use: keep your API secret and webhook secret out of the chat, out of the browser and out of your repository. Put them in your server's environment, and review generated code before you deploy it.

## 1. Point the assistant at the docs

| Resource | Use it for |
|---|---|
| [`https://oncharge.io/llms.txt`](https://oncharge.io/llms.txt) | An index of these docs in the [llms.txt](https://llmstxt.org) format. |
| [`https://oncharge.io/llms-full.txt`](https://oncharge.io/llms-full.txt) | All of these docs in one Markdown file. Paste or attach it when the assistant cannot browse. |
| [`https://oncharge.io/openapi.json`](https://oncharge.io/openapi.json) | The OpenAPI 3.1 spec of the merchant API and webhooks. |
| `https://oncharge.io/docs/<page>.md` | Any single page as Markdown, e.g. [`/docs/webhooks.md`](https://oncharge.io/docs/webhooks.md) (the overview is `/docs/index.md`). |

In Cursor, add `https://oncharge.io/llms-full.txt` under **Docs** and mention `@OnCharge` in your prompt. In Claude or ChatGPT, attach `llms-full.txt` or paste its URL.

## 2. Use a prompt for your stack

The [AI prompt library](https://oncharge.io/docs/ai-prompts) has copy-paste prompts for Next.js, React with a backend, plain HTML with a Node or PHP backend, a custom WooCommerce theme, Magento, Wix, a headless Shopify (Hydrogen) storefront, and Webflow or Framer. Each one tells the assistant exactly what to build, which endpoints to call, how to sign requests and verify webhooks, how to report shipments, when to add the RUO compliance feed, and what never to do.

## 3. Claude: the OnCharge skill

The **oncharge-checkout** [Agent Skill](https://agentskills.io) teaches Claude the OnCharge integration: the workflow, the signing rules, and reference files it loads only when needed.

**Claude Code.** Download and unzip it into your personal skills folder:

```bash
mkdir -p ~/.claude/skills && cd ~/.claude/skills
curl -fsSLO https://oncharge.io/docs/ai-files/oncharge-checkout-skill.zip
unzip -o oncharge-checkout-skill.zip && rm oncharge-checkout-skill.zip
```

Unzip it into `.claude/skills/` inside a project instead to share it with your team through the repository.

**Claude apps.** Download [`oncharge-checkout-skill.zip`](https://oncharge.io/docs/ai-files/oncharge-checkout-skill.zip) and upload it under **Settings → Capabilities → Skills** (skills must be available on your plan).

The individual files are also published: [`SKILL.md`](https://oncharge.io/docs/ai-files/claude-skill/oncharge-checkout/SKILL.md).

Then ask, for example: "Add OnCharge checkout to this project."

## 4. ChatGPT: the OnCharge Integration Assistant GPT

You can create a custom GPT that knows these docs and can look pages up while it works:

1. In ChatGPT, open **Explore GPTs → Create → Configure**.
2. **Name:** OnCharge Integration Assistant. **Description:** Integrates OnCharge checkout into your store.
3. **Instructions:** paste [`gpt-instructions.md`](https://oncharge.io/docs/ai-files/chatgpt/gpt-instructions.md).
4. **Conversation starters:** add the four lines from [`conversation-starters.txt`](https://oncharge.io/docs/ai-files/chatgpt/conversation-starters.txt).
5. **Knowledge:** upload [`llms-full.txt`](https://oncharge.io/llms-full.txt) and [`openapi.json`](https://oncharge.io/openapi.json).
6. **Capabilities:** turn on Web Search and Code Interpreter.
7. **Actions → Create new action → Import from URL:** `https://oncharge.io/docs/ai-files/chatgpt/actions.openapi.json`. Authentication: **None**. Privacy policy: `https://oncharge.io/privacy`.

The actions only read the public docs (search and fetch pages). The GPT never calls the OnCharge merchant API: requests must be signed with your API secret, which should never be pasted into a chat. For live API calls from an assistant, use the MCP server below on your own machine.

## 5. MCP server: docs and live API tools

`@oncharge/mcp` is a [Model Context Protocol](https://modelcontextprotocol.io) server that runs locally over stdio. It gives any MCP client (Claude Code, Claude Desktop, Cursor, VS Code, Windsurf and others):

| Tool | What it does |
|---|---|
| `search_docs`, `read_doc`, `list_docs` | Search and read these docs offline (bundled with the server). |
| `create_checkout_session` | `POST /api/v1/checkout/sessions` |
| `get_checkout_session` | `GET /api/v1/checkout/sessions/{id}` |
| `attach_order` | `POST /api/v1/checkout/sessions/{id}/order` |
| `report_shipment` | `POST /api/v1/shipments` |
| `get_delivery_status` | `GET /api/v1/shipments?session_id=…` |
| `create_refund` | `POST /api/v1/refunds` (moves money; your client asks before running it) |
| `verify_webhook_signature` | Checks an `OnCharge-Signature` header against a raw body. |
| `explain_signature` | Shows the signing string and signature for a request, to debug your own code. |

The docs tools work without credentials. The API tools appear when `ONCHARGE_API_KEY` and `ONCHARGE_API_SECRET` are set; `ONCHARGE_BASE_URL` defaults to `https://app.oncharge.io`, and `ONCHARGE_WEBHOOK_SECRET` is used by `verify_webhook_signature` when no secret is passed.

> **Coming soon to npm.** Until `@oncharge/mcp` is published, OnCharge can provide the built package; replace `npx -y @oncharge/mcp` below with `node /path/to/oncharge-mcp/dist/index.js`.

**Claude Code**

```bash
claude mcp add oncharge \
  --env ONCHARGE_API_KEY=oc_key_... \
  --env ONCHARGE_API_SECRET=oc_sec_... \
  -- npx -y @oncharge/mcp
```

**Claude Desktop** (`claude_desktop_config.json`), **Cursor** (`.cursor/mcp.json`) and most other clients:

```json title="MCP client configuration"
{
  "mcpServers": {
    "oncharge": {
      "command": "npx",
      "args": ["-y", "@oncharge/mcp"],
      "env": {
        "ONCHARGE_API_KEY": "oc_key_...",
        "ONCHARGE_API_SECRET": "oc_sec_...",
        "ONCHARGE_BASE_URL": "https://app.oncharge.io"
      }
    }
  }
}
```

**VS Code** (`.vscode/mcp.json`):

```json title=".vscode/mcp.json"
{
  "servers": {
    "oncharge": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@oncharge/mcp"],
      "env": { "ONCHARGE_API_KEY": "${input:onchargeKey}", "ONCHARGE_API_SECRET": "${input:onchargeSecret}" }
    }
  },
  "inputs": [
    { "id": "onchargeKey", "type": "promptString", "description": "OnCharge API key" },
    { "id": "onchargeSecret", "type": "promptString", "description": "OnCharge API secret", "password": true }
  ]
}
```

Leave the `env` block out to use only the docs tools. MCP configuration files contain your secret: keep them out of version control.

## What a good AI-built integration has

Use this to review what the assistant produced:

- Sessions are created on the server, with the amount from your database and an `Idempotency-Key`.
- The API secret never reaches the browser or the repository.
- The checkout is shown by redirect or an iframe on a registered domain, and `postMessage` events are checked against `https://app.oncharge.io`.
- Orders are marked paid only from a verified webhook (or a server-side status check).
- The webhook handler verifies `OnCharge-Signature` on the raw body, deduplicates event IDs and replies within 10 seconds.
- Shipping addresses are sent for physical goods, and tracking numbers are reported when orders ship.
- Tests cover the [signing test vector](https://oncharge.io/docs/authentication#test-vector) and webhook verification.
