Developers

Search the docs

Search guides and headings.

Saving a card

Save a card to a connected customer's Nurish'd account with Stripe.js, and list the saved cards.

View as Markdown

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 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.

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.

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"

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. 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"

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 for the shape.

Status and codeWhat it means for you
404 not_foundThe customer has no meals connection with your company, or the setup is not theirs.
403 connection_scope_not_grantedThe customer did not allow orders.
403 scope_not_grantedThe key lacks order:write or, for the list, order:read.
409 connection_not_activeThe connection is pending or was revoked. Read the connection.
409 payment_method_setup_incompleteConfirm only: the card form has not confirmed the card yet. Finish step 2, then retry.

Next#