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

> ## Agent Instructions
> NanoCorp's MCP server, the one that acts on a NanoCorp account, is https://mcp.nanocorp.so (OAuth sign-in).
> This documentation site's /mcp endpoint and its /.well-known/mcp files are a documentation search server, not NanoCorp.
> To connect an AI agent to NanoCorp, follow https://docs.nanocorp.so/agents.

# Unlocking a purchase

> Open a course, a download or a members page only to the people who paid for it, and check a purchase yourself.

When you sell something once that opens a page of your site (a course, a
download, a game pack, a members page), your site needs to know who paid before
it opens that page. NanoCorp keeps the record of every sale, so your site asks
NanoCorp instead of guessing.

> [!TIP]
>
> Ask your agent to "unlock the course after payment". It wires the checkout,
> the thank-you page and the check described below.

## How your site checks a purchase

1. When a buyer clicks **Buy**, your site creates an order with its own random
   reference and sends the buyer to the product's checkout link with that
   reference attached (`?client_reference_id=...`, see
   [Checkout link parameters](https://docs.nanocorp.so/checkout-links.md)). The reference stays on your
   site's server, tied to that visitor, never in a page address.
2. After paying, the buyer comes back to your thank-you page. Your site then
   asks NanoCorp whether the order with that reference is paid, for the product
   and the quantity of that order, and opens the page only when the answer is
   yes. A payment for another product never opens it.
3. Your site asks again on each later visit, so a refunded or disputed sale
   stops opening the page.

A buyer who paid through a plain buy link, with no order reference, still comes
back to your thank-you page with a payment id in its address. Your site checks
that payment the same way and saves it on the buyer's order or account, so the
first visitor who brings it is the one who gets access.

The thank-you page alone never opens anything: anyone can type its address.
The payment notification your site receives is for things like a receipt email
or a shipment, not for opening access.

For your agent: the check is `getPurchase({ reference })`, or
`getPurchase({ sessionId })` with the `session_id` the thank-you page receives,
from `@nanocorp/auth` 0.4.0 or later, called on the site's server, with the
signed-in `user` on a site that has Sign in with NanoCorp. It returns the
latest sale on that reference or session with its status (`paid`, `refunded` or
`disputed`), the product, the quantity, the amount and the buyer's email, or
`null` while there is none.

## What counts as paid

* A sale is **paid** until it is refunded in full or disputed by the buyer's
  bank. A partial refund stays paid, so you decide what the buyer keeps.
* A dispute that ends in your favor counts as paid again.
* The email on the sale is the one the buyer typed when paying. Your site
  shows it back ("Access goes to ...") so a typo is caught early.

## Testing it yourself

Pay your product's own test link with the test card `4242 4242 4242 4242`
(see [Testing your checkout](https://docs.nanocorp.so/testing-payments.md)). Your agent can hand it to you,
or run `nanocorp products link <product id>` and take the `test_checkout_url`.
Start an order on your site as a buyer would, then add that order's reference
and quantity to the test link: `?client_reference_id=<your reference>&qty=<quantity>`.
Do not use the all-products test link: it carries no reference and no product,
so it never opens a purchase. Your agent pays the same link without a browser,
with `nanocorp payments test-pay '<that link>'`.

* On a site with [Sign in with NanoCorp](https://docs.nanocorp.so/user-auth.md), sign in as yourself: your
  test purchase opens your own access, marked as a test. It never opens
  anything for anyone else, so a test link that leaks unlocks nothing.
* On any site, ask your agent to check the purchase, or run
  `nanocorp payments purchase --reference <your reference>`. Test purchases
  come back marked as a test and never count toward your revenue.

## Checking a customer's purchase

When someone writes in to say they paid, ask your agent to look them up by
their email, or run `nanocorp payments purchase --email <their email>`. You
see each of their purchases with its status.

## Payment notifications on new sites

Sites created from now on receive a signed payment notification, which your
site checks with `verifyWebhook(req)` from `@nanocorp/auth`. Sites created
before keep the unsigned one, and rely on the check above for anything that
matters. Nothing changes for an existing site until your agent uses these
calls.


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