---
title: Saving a card
description: Save a card to a connected customer's Nurish'd account with Stripe.js, and list the saved cards.
section: Meals
order: 3
---

# Saving a card

You will save a card to a customer's Nurish'd account, confirm it with Stripe.js on your own page, and list the saved cards.

The flow is the same as for a patient. [Saving a card](/docs/care/saving-a-card) explains each step and the Stripe.js code in full. This page lists the meals routes.

A saved card lets the customer pay for orders you place for them without typing the card in each time. How an order is paid is on [Orders](/docs/meals/orders).

Starting and confirming need the `order:write` scope. Listing needs `order:read`. The customer must have an `active` connection that allows `meals.orders`. Nurish'd Connect keeps no record of card numbers: the customer types the card into Stripe's own form on your page.

> **Warning.** The card is saved to the customer's Nurish'd account and may be charged for orders the customer confirms. Tell the customer so before they type the card in.

## Step 1: start the setup

`POST /meals/v1/customer/{customer_id}/payment-method/setup/create/document` takes no body. `customer_id` is the id from the create-customer answer.

```bash
curl -X POST https://api.dev.nurishd.ca/meals/v1/customer/6f1c0d2e-0000-4000-8000-000000000101/payment-method/setup/create/document \
  -H "X-Partner-API-Key: $NURISHD_API_KEY"
```

```javascript
const customerId = '6f1c0d2e-0000-4000-8000-000000000101';
const res = await fetch(
	`https://api.dev.nurishd.ca/meals/v1/customer/${customerId}/payment-method/setup/create/document`,
	{
		method: 'POST',
		headers: { 'X-Partner-API-Key': process.env.NURISHD_API_KEY },
	},
);
const setup = await res.json();
```

```python
import os
import requests

customer_id = "6f1c0d2e-0000-4000-8000-000000000101"
res = requests.post(
    f"https://api.dev.nurishd.ca/meals/v1/customer/{customer_id}/payment-method/setup/create/document",
    headers={"X-Partner-API-Key": os.environ["NURISHD_API_KEY"]},
)
setup = res.json()
```

```json
{
	"id": "seti_example",
	"client_secret": "seti_example_secret_example",
	"status": "requires_payment_method",
	"stripe_publishable_key": "pk_test_example"
}
```

`stripe_publishable_key` is `null` when Stripe is not configured yet. Calling start again returns the same open setup while it is less than a day old. Never log `client_secret`.

## Step 2: confirm the card in the browser

Send `stripe_publishable_key` and `client_secret` to your page and call `stripe.confirmCardSetup` there. The snippet is in [Saving a card](/docs/care/saving-a-card). It runs in the browser, never on your server.

## Step 3: record the card

`PUT /meals/v1/customer/{customer_id}/payment-method/setup/{setup_id}/confirm/document` takes no body. `setup_id` is the `id` of the start answer.

```bash
curl -X PUT https://api.dev.nurishd.ca/meals/v1/customer/6f1c0d2e-0000-4000-8000-000000000101/payment-method/setup/seti_example/confirm/document \
  -H "X-Partner-API-Key: $NURISHD_API_KEY"
```

```javascript
const res = await fetch(
	`https://api.dev.nurishd.ca/meals/v1/customer/${customerId}/payment-method/setup/${setup.id}/confirm/document`,
	{
		method: 'PUT',
		headers: { 'X-Partner-API-Key': process.env.NURISHD_API_KEY },
	},
);
const card = await res.json();
```

```python
setup_id = setup["id"]
res = requests.put(
    f"https://api.dev.nurishd.ca/meals/v1/customer/{customer_id}/payment-method/setup/{setup_id}/confirm/document",
    headers={"X-Partner-API-Key": os.environ["NURISHD_API_KEY"]},
)
card = res.json()
```

```json
{
	"id": "pm_example",
	"card": {
		"brand": "visa",
		"last4": "4242",
		"exp_month": 12,
		"exp_year": 2030
	},
	"is_default": true
}
```

When the customer had no default card, the saved card becomes their default and the answer says `is_default: true`. A customer who already has a default card keeps it, and the answer says `is_default: false`. Calling confirm again for the same setup is safe.

## List saved cards

`GET /meals/v1/customer/{customer_id}/payment-method/query/documents` returns the saved cards, at most 10, in one page. A customer with no card gets an empty `data` list. The customer can also add, remove and choose cards in their own account, so the list can change without you.

```bash
curl https://api.dev.nurishd.ca/meals/v1/customer/6f1c0d2e-0000-4000-8000-000000000101/payment-method/query/documents \
  -H "X-Partner-API-Key: $NURISHD_API_KEY"
```

The answer has the same shape as the care list: `data` holds cards with `id`, `card` (`brand`, `exp_month`, `exp_year` and `last4`) and `is_default`, next to the page fields. `is_default` is `true` for the customer's default card.

## Errors

See [Errors](/docs/concepts/errors) for the shape.

| Status and code                       | What it means for you                                                                  |
| ------------------------------------- | -------------------------------------------------------------------------------------- |
| `404 not_found`                       | The customer has no meals connection with your company, or the setup is not theirs.    |
| `403 connection_scope_not_granted`    | The customer did not allow orders.                                                     |
| `403 scope_not_granted`               | The key lacks `order:write` or, for the list, `order:read`.                            |
| `409 connection_not_active`           | The connection is `pending` or was revoked. Read the connection.                       |
| `409 payment_method_setup_incomplete` | Confirm only: the card form has not confirmed the card yet. Finish step 2, then retry. |

## Next

- [Orders](/docs/meals/orders): place an order for a connected customer.
- [Customers](/docs/meals/customers): connect the customer first.
- [Saving a card for a patient](/docs/care/saving-a-card): the full explanation.
