> ## Documentation Index
> Fetch the complete documentation index at: https://x402-docs.ftptech.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Other languages

> Take x402 payments in Go and Python with FTP's plugins for the official x402 SDKs.

FTP's plugins add Canton to the official [x402 SDKs](https://github.com/x402-foundation/x402) for Go and Python. Payments settle through FTP's facilitator. The payer is charged only after your handler answers 2xx, and each payment is served once.

## Before you start

The party you are paid to needs a live `TransferPreapproval`. Create it with the Node wallet, as on the [merchant page](https://x402-docs.ftptech.xyz/x402-merchant.md):

```bash theme={null}
npx @ftptech/canton-agent-wallet create --relay-url https://facilitator.ftptech.xyz
npx @ftptech/canton-agent-wallet address       # your party id: payTo
# send it a few CC, then
npx @ftptech/canton-agent-wallet claim
npx @ftptech/canton-agent-wallet preapproval   # lasts 30 days, run it again before then
```

For a CIP-56 token, also run `preapproval --admin <admin> --id <id>` once per token you price.

## Go

```bash theme={null}
go get github.com/FTP-Tech-LLC/x402-canton-merchant/go/canton
```

Needs Go 1.26.10 or newer and the official SDK `github.com/x402-foundation/x402/go/v2` v2.31.0 or newer. Works with `net/http`, gin and echo v4.

```go theme={null}
paid, err := canton.NewGate(ctx, canton.Config{
	Routes: map[string]canton.Route{
		"GET /v1/data": {PayTo: "<your party id>", Price: canton.CC("0.01")},
	},
})
if err != nil {
	log.Fatal(err)
}
mux := http.NewServeMux()
mux.HandleFunc("GET /v1/data", func(w http.ResponseWriter, r *http.Request) {
	payer, _ := canton.PayerFrom(r.Context())
	fmt.Fprintf(w, `{"payer":%q}`, payer)
})
log.Fatal(http.ListenAndServe(":8080", paid.Middleware()(mux)))
```

The [module README](https://github.com/FTP-Tech-LLC/x402-canton-merchant/tree/main/go) covers gin and echo, token prices, Redis and shutdown.

## Python

```bash theme={null}
pip install "ftptech-x402-canton[fastapi]"
```

Needs Python 3.10 or newer and the official SDK `x402` 2.28. Works with FastAPI and Starlette (ASGI) and Flask (WSGI).

```python theme={null}
server = CantonServer(Config(routes={
    "GET /v1/data": Route(pay_to="<your party id>", price=cc("0.01")),
}))
app = FastAPI(lifespan=server.lifespan)
app.add_middleware(CantonPaymentMiddleware, server=server)

@app.get("/v1/data")
def data(request: Request) -> dict:
    return {"payer": payer_from(request)}
```

The [package README](https://github.com/FTP-Tech-LLC/x402-canton-merchant/tree/main/python) has the Flask example, the supported servers and Redis.

## Money safety

* A 4xx or 5xx from your handler is not charged. A 3xx becomes 502 and is not charged.
* A replay of a served payment gets 402 `payment_already_redeemed`.
* 503 `do NOT pay again; retry the same payment` means the payment may have moved. The client resends the same signature and is served once. The retry runs your handler again, so keep paid side effects idempotent.
* Use Redis in production: Go `goredis.NewStore`, Python `RedisStore.from_url`. The default memory store forgets payments on restart.
* Limit per payer (`canton.PayerFrom`, `payer_from`), not only per IP, and let retries through (`canton.IsRetry`, `is_retry`).

## Deployment

* Proxies must accept a 32 KiB `PAYMENT-SIGNATURE` header. nginx: `large_client_header_buffers 4 32k;`.
* Set the proxy read timeout and the shutdown grace to at least the plugin's request budget: Go `canton.RequestBudget(cfg)`, 505 s by default; Python `request_budget(config)`, 465 s.
* Python: gunicorn `--limit-request-field_size 32768 --timeout 470 --graceful-timeout 470`, waitress `channel_request_lookahead=1`, and TLS ended at a proxy.
* Your handler must finish within the payment's lifetime, 120 s by default. A slower one lets the payment expire, and nothing is charged.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.