# Quickstart (/docs/payments/quickstart)

By the end of this page your server will create a real Swop checkout for one of your products, a buyer will pay it, and you'll see it flip to `paid`.

<Callout type="warn" title="Real money">
Swop has no sandbox yet, so this quickstart moves real (small) amounts. Use a cheap product of your own and pay it from a **different** wallet than the one that owns the store.
</Callout>

## What you need [#what-you-need]

- A Swop account with at least one product listed. Create one in the Swop app.
- A server you control (Node 18+, Python 3.9+ or anything that can make HTTPS requests).

## 1. Create an API key [#1-create-an-api-key]

1. Open the Swop web app and go to **Dashboard → Developer** (`swopme.app/dashboard/developer`).
2. Under **Create an API key**, give it a name and tick **`commerce.read`** and **`commerce.checkout`**.
3. Copy the secret. It starts with `swop_sk_` and is **shown once**.

Store it in an environment variable on your server, never in browser code:

```bash
export SWOP_MERCHANT_KEY="swop_sk_..."
```

## 2. Check the key works [#2-check-the-key-works]

```bash tab="curl"
curl https://apps.apiswop.co/api/v5/merchant/me \
  -H "Authorization: Bearer $SWOP_MERCHANT_KEY"
```

```js tab="Node"
const res = await fetch('https://apps.apiswop.co/api/v5/merchant/me', {
  headers: { Authorization: `Bearer ${process.env.SWOP_MERCHANT_KEY}` },
});
console.log(await res.json());
```

```python tab="Python"
import os, requests

r = requests.get(
    "https://apps.apiswop.co/api/v5/merchant/me",
    headers={"Authorization": f"Bearer {os.environ['SWOP_MERCHANT_KEY']}"},
)
print(r.json())
```

```json title="Response"
{
  "state": "success",
  "data": {
    "merchant": { "id": "65f0c1…", "name": "Acme", "ens": "acme.swop.id" },
    "keyId": "mk_Q3x…",
    "effectiveScopes": ["commerce.read", "commerce.checkout"],
    "cardEnabled": false
  }
}
```

`effectiveScopes` is what the key can do **right now**. `cardEnabled: false` just means buyers will pay in USDC; that's fine for this quickstart.

## 3. Find a product ID [#3-find-a-product-id]

```bash tab="curl"
curl "https://apps.apiswop.co/api/v5/merchant/products?limit=5" \
  -H "Authorization: Bearer $SWOP_MERCHANT_KEY"
```

```js tab="Node"
const res = await fetch('https://apps.apiswop.co/api/v5/merchant/products?limit=5', {
  headers: { Authorization: `Bearer ${process.env.SWOP_MERCHANT_KEY}` },
});
const { data } = await res.json();
console.log(data.items.map((p) => [p._id, p.title, p.price]));
```

```python tab="Python"
import os, requests

r = requests.get(
    "https://apps.apiswop.co/api/v5/merchant/products",
    params={"limit": 5},
    headers={"Authorization": f"Bearer {os.environ['SWOP_MERCHANT_KEY']}"},
)
for p in r.json()["data"]["items"]:
    print(p["_id"], p["title"], p["price"])
```

Copy the `_id` of a cheap **digital** product (digital products need no shipping address, which keeps this short).

## 4. Create a checkout [#4-create-a-checkout]

Send the product ID and a quantity. **Never send a price**: Swop prices every item from your catalogue, and a request that includes `price`, `amount` or `unitPrice` on an item is rejected.

```bash tab="curl"
curl -X POST https://apps.apiswop.co/api/v5/merchant/checkout-intents \
  -H "Authorization: Bearer $SWOP_MERCHANT_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "items": [ { "productId": "PRODUCT_ID", "quantity": 1 } ] }'
```

```js tab="Node"
const res = await fetch('https://apps.apiswop.co/api/v5/merchant/checkout-intents', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SWOP_MERCHANT_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ items: [{ productId: 'PRODUCT_ID', quantity: 1 }] }),
});
const { data } = await res.json();
console.log(data.intentId, data.fees.totalDueAmount, data.paymentRequest?.url);
```

```python tab="Python"
import os, requests

r = requests.post(
    "https://apps.apiswop.co/api/v5/merchant/checkout-intents",
    headers={"Authorization": f"Bearer {os.environ['SWOP_MERCHANT_KEY']}"},
    json={"items": [{"productId": "PRODUCT_ID", "quantity": 1}]},
)
data = r.json()["data"]
print(data["intentId"], data["fees"]["totalDueAmount"], data["paymentRequest"]["url"])
```

The response (`201`) is the checkout. Three fields matter now:

| Field | What it is |
|---|---|
| `intentId` | The checkout's ID, like `co_7Hk2mPq9xR4s`. Save it with your order. |
| `fees.totalDueAmount` | What the buyer pays, in USDC. Show this. |
| `paymentRequest.url` | A `solana:` payment link for USDC. Any Solana wallet can open it. |

## 5. Pay it [#5-pay-it]

Turn `paymentRequest.url` into a QR code (or open it on a phone with a Solana wallet) and pay from a **different** wallet. Swop watches the blockchain and records the payment by itself; there's nothing to confirm.

## 6. See it paid [#6-see-it-paid]

```bash tab="curl"
curl https://apps.apiswop.co/api/v5/merchant/checkout-intents/co_7Hk2mPq9xR4s \
  -H "Authorization: Bearer $SWOP_MERCHANT_KEY"
```

```js tab="Node"
async function waitForPaid(intentId) {
  for (;;) {
    const res = await fetch(
      `https://apps.apiswop.co/api/v5/merchant/checkout-intents/${intentId}`,
      { headers: { Authorization: `Bearer ${process.env.SWOP_MERCHANT_KEY}` } },
    );
    const { data } = await res.json();
    if (['paid', 'settled'].includes(data.status)) return data;
    if (['expired', 'cancelled'].includes(data.status)) throw new Error(data.status);
    await new Promise((r) => setTimeout(r, 3000));
  }
}
```

```python tab="Python"
import os, time, requests

def wait_for_paid(intent_id):
    while True:
        r = requests.get(
            f"https://apps.apiswop.co/api/v5/merchant/checkout-intents/{intent_id}",
            headers={"Authorization": f"Bearer {os.environ['SWOP_MERCHANT_KEY']}"},
        )
        data = r.json()["data"]
        if data["status"] in ("paid", "settled"):
            return data
        if data["status"] in ("expired", "cancelled"):
            raise RuntimeError(data["status"])
        time.sleep(3)
```

When `status` is `paid`, the order exists, the buyer has a receipt, and the sale shows in your Swop app. That's a working integration.

## Next steps [#next-steps]

<Cards>
  <Card title="Build a real checkout page" href="/docs/payments/headless-checkout" description="Carts, shipping, card payments and the statuses to show buyers." />
  <Card title="Get notified with webhooks" href="/docs/webhooks" description="Stop polling: Swop calls your server when an order is paid." />
  <Card title="Understand payouts" href="/docs/payments/statuses-and-escrow" description="Why paid doesn't always mean you've been paid yet." />
</Cards>
