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

# Pay with Card

> Create a card order through the Orders REST API and collect the card in the Embedded Checkout

<Snippet file="nft-checkout-not-self-serve.mdx" />

## Introduction

In this quickstart you sell an NFT for a card payment, including Apple Pay and Google Pay. Your server creates the order with the Orders REST API. Then your frontend renders the Crossmint Embedded Checkout component to collect the card, so your app does not handle raw card data.

> [!NOTE]
>
> This flow uses two API keys. Your **server** creates the order with a server-side API key. Your **frontend** renders the Embedded Checkout with a client-side API key and the `clientSecret` of the order. To let Crossmint handle the full flow, see the [Embedded quickstart](https://docs.crossmint.com/payments/embedded/quickstarts/credit-card.md).

## Prerequisites

<Snippet file="headless-checkout-prereqs.mdx" />

* **Client-side API key:** create a client-side API key in the same project for the Embedded Checkout.
* **React app:** the frontend example uses React and `@crossmint/client-sdk-react-ui`.

## Integration Steps

**1. Create the order on your server**

Create an order with the recipient, the card payment method, and the collection. Refer to the [Create Order API reference](https://docs.crossmint.com/api-reference/headless/create-order.md) for all parameters.

`POST` `https://staging.crossmint.com/api/2022-06-09/orders`

```bash cURL theme={null}
curl --request POST \
    --url https://staging.crossmint.com/api/2022-06-09/orders \
    --header 'Content-Type: application/json' \
    --header 'X-API-KEY: <your-server-api-key>' \
    --data '{
        "recipient": {
            "email": "<recipient-email>"
        },
        "payment": {
            "method": "card"
        },
        "lineItems": [
            {
                "collectionLocator": "crossmint:<your-collection-id>"
            }
        ]
    }'
```

```javascript Node.js theme={null}
const response = await fetch("https://staging.crossmint.com/api/2022-06-09/orders", {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "X-API-KEY": "<your-server-api-key>",
    },
    body: JSON.stringify({
        recipient: {
            email: "<recipient-email>",
        },
        payment: {
            method: "card",
        },
        lineItems: [
            {
                collectionLocator: "crossmint:<your-collection-id>",
            },
        ],
    }),
});
const { clientSecret, order } = await response.json();

console.log("Order ID:", order.orderId);
console.log("Client secret:", clientSecret);
```

```python Python theme={null}
import requests

response = requests.post(
    "https://staging.crossmint.com/api/2022-06-09/orders",
    headers={
        "Content-Type": "application/json",
        "X-API-KEY": "<your-server-api-key>",
    },
    json={
        "recipient": {
            "email": "<recipient-email>",
        },
        "payment": {
            "method": "card",
        },
        "lineItems": [
            {
                "collectionLocator": "crossmint:<your-collection-id>",
            },
        ],
    },
)
body = response.json()

print("Order ID:", body["order"]["orderId"])
print("Client secret:", body["clientSecret"])
```

Send `order.orderId` and `clientSecret` to your frontend for the next step.

> [!NOTE]
>
> A card order needs an email for the receipt. Crossmint uses `recipient.email`. If you deliver to `recipient.walletAddress` instead, also set `payment.receiptEmail`. Without an email, `payment.status` stays `requires-email` and the checkout cannot collect the card.

> [accordion] Example response
>
> ```json theme={null}
> {
>     "clientSecret": "_removed_",
>     "order": {
>         "orderId": "cc40e6af-f8dc-4ac2-8e26-d91a32f271cf",
>         "phase": "payment",
>         "lineItems": [
>             {
>                 "chain": "polygon-amoy",
>                 "quantity": 1,
>                 "metadata": {
>                     "name": "Headless Demo",
>                     "description": "NFT Checkout Demo",
>                     "imageUrl": "https://utfs.io/f/cd8545b7-3410-4fcd-988d-cd11951ed53c-g287ok.png"
>                 },
>                 "delivery": {
>                     "status": "awaiting-payment"
>                 }
>             }
>         ],
>         "quote": {
>             "status": "valid",
>             "totalPrice": {
>                 "amount": "1.06",
>                 "currency": "usd"
>             }
>         },
>         "payment": {
>             "status": "awaiting-payment"
>         }
>     }
> }
> ```

**2. Render the Embedded Checkout in your frontend**

Install the React SDK:

<Snippet file="client-sdk-react-ui-installation-cmd.mdx" />

Render `CrossmintEmbeddedCheckout` with the `orderId` and `clientSecret` from the previous step. The props below show only the card form, and hide the recipient and email inputs because the order already has them.

```tsx theme={null}
import { CrossmintEmbeddedCheckout, CrossmintProvider } from "@crossmint/client-sdk-react-ui";

export function CheckoutPage({ orderId, clientSecret }: { orderId: string; clientSecret: string }) {
    return (
        <CrossmintProvider apiKey="<your-client-api-key>">
            <CrossmintEmbeddedCheckout
                orderId={orderId}
                clientSecret={clientSecret}
                payment={{
                    crypto: { enabled: false },
                    fiat: { enabled: true },
                    defaultMethod: "fiat",
                }}
                appearance={{
                    rules: {
                        DestinationInput: { display: "hidden" },
                        ReceiptEmailInput: { display: "hidden" },
                    },
                }}
            />
        </CrossmintProvider>
    );
}
```

In staging, pay with the test card `4242 4242 4242 4242`, any future expiry date, and any CVC. See [Testing Tips](https://docs.crossmint.com/payments/advanced/testing-tips.md#test-credit-card-numbers) for more test cards. To change the look of the checkout, see [Appearance](https://docs.crossmint.com/payments/guides/appearance.md).

**3. Get the order status**

Call the [Get Order API](https://docs.crossmint.com/api-reference/headless/get-order.md) until `phase` is `completed`. The phase changes from `payment` to `delivery`, and then to `completed`.

`GET` `https://staging.crossmint.com/api/2022-06-09/orders/<orderId>`

```bash cURL theme={null}
curl --request GET \
    --url 'https://staging.crossmint.com/api/2022-06-09/orders/<orderId>' \
    --header 'X-API-KEY: <your-server-api-key>'
```

```javascript Node.js theme={null}
const orderId = "<orderId>";

while (true) {
    const response = await fetch(`https://staging.crossmint.com/api/2022-06-09/orders/${orderId}`, {
        headers: { "X-API-KEY": "<your-server-api-key>" },
    });
    const order = await response.json();
    console.log("Order phase:", order.phase);

    if (order.phase === "completed") {
        break;
    }
    await new Promise((resolve) => setTimeout(resolve, 3000));
}
```

```python Python theme={null}
import time

import requests

order_id = "<orderId>"

while True:
    response = requests.get(
        f"https://staging.crossmint.com/api/2022-06-09/orders/{order_id}",
        headers={"X-API-KEY": "<your-server-api-key>"},
    )
    order = response.json()
    print("Order phase:", order["phase"])

    if order["phase"] == "completed":
        break
    time.sleep(3)
```

When the order is complete, the recipient gets an email with a link to the NFT. If the card is declined or the payment is refunded, the order shows it in `payment.failureReason` or `payment.refunded`. See [Declines and Refunds](https://docs.crossmint.com/payments/concepts/how-checkout-works.md#declines-and-refunds).

## Sell Tokens Instead of NFTs

<Snippet file="enterprise-feature.mdx" />

To sell a fungible token, such as a Solana memecoin, change the order body in step 1. Use `tokenLocator` and `executionParameters` instead of `collectionLocator`, and deliver to a wallet address:

```json theme={null}
{
    "recipient": {
        "walletAddress": "<recipient-solana-address>"
    },
    "payment": {
        "method": "card",
        "receiptEmail": "<receipt-email>"
    },
    "lineItems": [
        {
            "tokenLocator": "solana:7EivYFyNfgGj8xbUymR7J4LuxUHLKRzpLaERHLvi7Dgu",
            "executionParameters": {
                "mode": "exact-in",
                "amount": "1",
                "maxSlippageBps": "500"
            }
        }
    ]
}
```

* `tokenLocator`: the token, in the format `<chain>:<tokenAddress>`. In staging, only the XMEME test token (`7EivYFyNfgGj8xbUymR7J4LuxUHLKRzpLaERHLvi7Dgu`) works.
* `executionParameters.mode`: `exact-in` means that the buyer spends an exact amount.
* `executionParameters.amount`: the amount in USD that the buyer spends.
* `executionParameters.maxSlippageBps`: optional. If you do not set it, Crossmint applies a default slippage.

A token quote expires after 1 minute. The Embedded Checkout refreshes the quote automatically. See [Select Items](https://docs.crossmint.com/payments/guides/select-items.md) for more `tokenLocator` formats.

<Snippet file="memecoins_important_notes.mdx" />

## Launching in Production

<Snippet file="headless-next-steps.mdx" />

## Learn More

> [card] [Appearance](https://docs.crossmint.com/payments/guides/appearance.md)
>
> Match the checkout to your brand

> [card] [Webhooks](https://docs.crossmint.com/payments/advanced/webhooks.md)
>
> Get order updates on your server

> [card] [Create Order API](https://docs.crossmint.com/api-reference/headless/create-order.md)
>
> Try the API in the playground
