# Create your first payment link

Take a $100 order from checkout to fulfilment. Keep the order ID in your system and send the customer one link.

You’ll need a [server access token](https://cadmospay.com/developers/guides/sign-in.md). Running the create command makes a real checkout.

## 1. Give the order an ID

Use `order-42` as your own order number. Generate a separate `requestId` once and store it with the order. If the request times out, retry with that same ID and body.

```bash
export REQUEST_ID=$(node -p "require('node:crypto').randomUUID()")
```

## 2. Create the link and share it

Send the price as `"100.00"`. For a donation or another open-amount payment, omit `amountUsd` and the customer chooses the amount.

```bash
curl --fail-with-body 'https://api.cadmospay.com/machine/v1/gateway/links' \
  -H "Authorization: Bearer ${CADMOS_ACCESS_TOKEN:?Set CADMOS_ACCESS_TOKEN}" \
  -H "Content-Type: application/json" \
  --data-binary @- <<JSON
{
  "description": "Order #42",
  "externalReference": "order-42",
  "amountUsd": "100.00",
  "requestId": "${REQUEST_ID:?Set REQUEST_ID}"
}
JSON
```

```javascript
const { CADMOS_ACCESS_TOKEN, REQUEST_ID } = process.env;
if (!CADMOS_ACCESS_TOKEN || !REQUEST_ID) {
  throw new Error("Set CADMOS_ACCESS_TOKEN and REQUEST_ID");
}

const url = new URL("https://api.cadmospay.com/machine/v1/gateway/links");
const body = {
  "description": "Order #42",
  "externalReference": "order-42",
  "amountUsd": "100.00",
  "requestId": REQUEST_ID
};
const response = await fetch(url, {
  method: "POST",
  redirect: "error",
  headers: {
    Authorization: "Bearer " + CADMOS_ACCESS_TOKEN,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
});
console.log(response.status, await response.json());
```

```python
from http.client import HTTPSConnection
import json
import os

conn = HTTPSConnection("api.cadmospay.com", timeout=30)
path = "/machine/v1/gateway/links"
body = json.dumps({
  "description": "Order #42",
  "externalReference": "order-42",
  "amountUsd": "100.00",
  "requestId": os.environ["REQUEST_ID"]
})
headers = {
    "Authorization": "Bearer " + os.environ["CADMOS_ACCESS_TOKEN"],
    "Content-Type": "application/json",
}
conn.request("POST", path, body=body, headers=headers)
response = conn.getresponse()
print(response.status, response.read().decode())
conn.close()
```

On `201`, save `uuid` with the order and send `checkoutUrl` to the customer. This example accepts crypto. To offer Whish, see [payment methods and fees](https://cadmospay.com/developers/guides/methods-and-fees.md).

## 3. Check whether to fulfil the order

```bash
curl --fail-with-body 'https://api.cadmospay.com/machine/v1/gateway/links' \
  -H "Authorization: Bearer ${CADMOS_ACCESS_TOKEN:?Set CADMOS_ACCESS_TOKEN}" \
  --get \
  --data-urlencode "uuid=${REQUEST_ID:?Set REQUEST_ID}"
```

```javascript
const { CADMOS_ACCESS_TOKEN, REQUEST_ID } = process.env;
if (!CADMOS_ACCESS_TOKEN || !REQUEST_ID) {
  throw new Error("Set CADMOS_ACCESS_TOKEN and REQUEST_ID");
}

const url = new URL("https://api.cadmospay.com/machine/v1/gateway/links");
url.searchParams.set("uuid", REQUEST_ID);
const response = await fetch(url, {
  method: "GET",
  redirect: "error",
  headers: {
    Authorization: "Bearer " + CADMOS_ACCESS_TOKEN,
  },
});
console.log(response.status, await response.json());
```

```python
from http.client import HTTPSConnection
from urllib.parse import urlencode
import os

conn = HTTPSConnection("api.cadmospay.com", timeout=30)
path = "/machine/v1/gateway/links"
path += "?" + urlencode({"uuid": os.environ["REQUEST_ID"]})
headers = {
    "Authorization": "Bearer " + os.environ["CADMOS_ACCESS_TOKEN"],
}
conn.request("GET", path, headers=headers)
response = conn.getresponse()
print(response.status, response.read().decode())
conn.close()
```

For this $100 order, check `paid`. If it is `false`, `leftUsd` tells you what is still due. If it is `true`, fulfil the order once. A link can be `active` before anyone pays it.

Open-amount links have no target and always return `paid: false`. Record each settlement as it arrives. To automate this, [receive payment notifications](https://cadmospay.com/developers/guides/webhooks-guide.md).
