Developers

Search the docs

Search guides and headings.

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.

View as Markdown

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:

  1. Connect the patient. See Connecting a patient.
  2. Save a card. This page.
  3. 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.

bash
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"
FieldMeaning
idThe id of the setup. You send it to the confirm route in step 3.
client_secretThe secret the card form confirms the card with. Give it to Stripe.js only. Never log it.
statusWhere the setup is. It is requires_payment_method until a card is typed in.
stripe_publishable_keyThe 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.

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

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

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.

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

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 codeWhat it means for you
404 not_foundThe patient has no care connection with your company, or the setup is not this patient's.
403 connection_scope_not_grantedThe patient did not allow bookings. Create the patient again with a key that holds booking:write.
403 scope_not_grantedThe key lacks patient:write. See Scopes.
409 connection_not_activeThe connection is pending or was revoked. Read the connection and wait for approval.
409 payment_method_setup_incompleteConfirm only: the card form has not confirmed the card yet. Finish step 2, then call confirm again.

What the Sandbox does#

Next#