Saving a card
Save a card to a connected patient's Nurish'd account with Stripe.js, so a visit can be booked for them.
You will save a card to a patient's Nurish'd account, confirm it with Stripe.js on your own page, and list the saved cards.
Why a card comes first#
A visit charges nothing when it is booked. The visit, a late-cancellation fee and a no-show fee are charged later to the patient's default saved card. A patient made through a company has no card. So a patient with no default card cannot be booked: booking answers 409 payment_method_required and books nothing.
The order of calls is:
- Connect the patient. See Connecting a patient.
- Save a card. This page.
- Book. See Booking a visit.
Every route on this page needs the patient:write scope, an active connection and a connection that allows care.bookings. patient:write needs a signed BAA. See BAA handling.
Nurish'd Connect keeps no record of card numbers. The patient types the card into Stripe's own form on your page. The number never reaches your server or Nurish'd's.
Step 1: start the setup#
POST /care/v1/patient/{patient_id}/payment-method/setup/create/document starts saving a card. It takes no body. patient_id is the id from the create-patient answer.
curl -X POST https://api.dev.nurishd.ca/care/v1/patient/6f1c0d2e-0000-4000-8000-000000000101/payment-method/setup/create/document \
-H "X-Partner-API-Key: $NURISHD_API_KEY"const patientId = '6f1c0d2e-0000-4000-8000-000000000101';
const res = await fetch(
`https://api.dev.nurishd.ca/care/v1/patient/${patientId}/payment-method/setup/create/document`,
{
method: 'POST',
headers: { 'X-Partner-API-Key': process.env.NURISHD_API_KEY },
},
);
const setup = await res.json();import os
import requests
patient_id = "6f1c0d2e-0000-4000-8000-000000000101"
res = requests.post(
f"https://api.dev.nurishd.ca/care/v1/patient/{patient_id}/payment-method/setup/create/document",
headers={"X-Partner-API-Key": os.environ["NURISHD_API_KEY"]},
)
setup = res.json(){
"id": "seti_example",
"client_secret": "seti_example_secret_example",
"status": "requires_payment_method",
"stripe_publishable_key": "pk_test_example"
}| Field | Meaning |
|---|---|
id | The id of the setup. You send it to the confirm route in step 3. |
client_secret | The secret the card form confirms the card with. Give it to Stripe.js only. Never log it. |
status | Where the setup is. It is requires_payment_method until a card is typed in. |
stripe_publishable_key | The Stripe publishable key to load Stripe.js with. null when none is configured. |
Calling start again returns the same open setup while it is less than a day old.
stripe_publishable_key can be null in an environment where Stripe is not configured yet. Your page cannot load Stripe.js then. Show an error and try again later.
Step 2: confirm the card in the browser#
Send stripe_publishable_key and client_secret to your page. Never send your API key. The code below runs in the browser, on your company's page, not on your server. It uses Stripe.js and a card element that you mounted.
// Runs in the browser, on your page. Not server code.
const stripe = Stripe(publishableKey);
const { error, setupIntent } = await stripe.confirmCardSetup(clientSecret, {
payment_method: { card: cardElement },
});
if (error) {
// Show error.message to the patient. Do not call the confirm route.
} else {
// The card form accepted the card. Tell your server to run step 3.
}confirmCardSetup is the Stripe.js call for a setup secret like the one the answer carries, which starts with seti_. When Stripe.js reports success, call the confirm route right away. It does not wait for any notification.
Step 3: record the card#
PUT /care/v1/patient/{patient_id}/payment-method/setup/{setup_id}/confirm/document checks the setup and records the card on the patient's account. It takes no body. setup_id is the id from step 1.
curl -X PUT https://api.dev.nurishd.ca/care/v1/patient/6f1c0d2e-0000-4000-8000-000000000101/payment-method/setup/seti_example/confirm/document \
-H "X-Partner-API-Key: $NURISHD_API_KEY"const res = await fetch(
`https://api.dev.nurishd.ca/care/v1/patient/${patientId}/payment-method/setup/${setup.id}/confirm/document`,
{
method: 'PUT',
headers: { 'X-Partner-API-Key': process.env.NURISHD_API_KEY },
},
);
const card = await res.json();setup_id = setup["id"]
res = requests.put(
f"https://api.dev.nurishd.ca/care/v1/patient/{patient_id}/payment-method/setup/{setup_id}/confirm/document",
headers={"X-Partner-API-Key": os.environ["NURISHD_API_KEY"]},
)
card = res.json(){
"id": "pm_example",
"card": {
"brand": "visa",
"last4": "4242",
"exp_month": 12,
"exp_year": 2030
},
"is_default": true
}Calling confirm again for the same setup is safe.
Which card is the default#
When the patient had no default card, the saved card becomes the default, and the answer says is_default: true. A patient who already has a default card keeps it, and the answer says is_default: false. Visits and fees are charged to the default card.
List saved cards#
GET /care/v1/patient/{patient_id}/payment-method/query/documents returns the cards saved to the patient's account, at most 10, in one page. A patient with no card gets an empty data list. Each card has id, card (brand, exp_month, exp_year and last4) and is_default, which is true for the card visits and fees are charged to.
curl https://api.dev.nurishd.ca/care/v1/patient/6f1c0d2e-0000-4000-8000-000000000101/payment-method/query/documents \
-H "X-Partner-API-Key: $NURISHD_API_KEY"const res = await fetch(
`https://api.dev.nurishd.ca/care/v1/patient/${patientId}/payment-method/query/documents`,
{ headers: { 'X-Partner-API-Key': process.env.NURISHD_API_KEY } },
);
const cards = await res.json();res = requests.get(
f"https://api.dev.nurishd.ca/care/v1/patient/{patient_id}/payment-method/query/documents",
headers={"X-Partner-API-Key": os.environ["NURISHD_API_KEY"]},
)
cards = res.json(){
"data": [
{
"id": "pm_example",
"card": {
"brand": "visa",
"last4": "4242",
"exp_month": 12,
"exp_year": 2030
},
"is_default": true
}
],
"total": 1,
"total_pages": 1,
"page": 1,
"size": 10,
"has_next": false,
"has_previous": false
}The patient can also add, remove and choose cards in their own Nurish'd account, so the list can change without you. Read it before you book if you need to know.
Errors#
See Errors for the shape. All three routes share the connection errors.
| Status and code | What it means for you |
|---|---|
404 not_found | The patient has no care connection with your company, or the setup is not this patient's. |
403 connection_scope_not_granted | The patient did not allow bookings. Create the patient again with a key that holds booking:write. |
403 scope_not_granted | The key lacks patient:write. See Scopes. |
409 connection_not_active | The connection is pending or was revoked. Read the connection and wait for approval. |
409 payment_method_setup_incomplete | Confirm only: the card form has not confirmed the card yet. Finish step 2, then call confirm again. |
What the Sandbox does#
Next#
- Booking a visit: book once a card is saved.
- Connecting a patient: the step before this one.
- Scopes: what
patient:writeallows.
Something wrong on this page? Email hello@nurishd.io with the page address.