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

# Create Card

> Documentation for the Create Card action for Stripe

![images/stripe.svg](https://mintcdn.com/morfhealth/EU2WCxuXGIUQcziR/images/stripe.svg?fit=max\&auto=format\&n=EU2WCxuXGIUQcziR\&q=85\&s=3273b1407219957e10015da6551db0e4)

## Authorization Hold Endpoint (Morf Forms)

Integrate a form with Morf's Stripe endpoint to generate a customer, card, and authorization hold from a Stripe token. Find out in real time if a credit card is eligible to charge.

1. A token is generated by the form builder for one-time use.
2. Morf passes the token to Stripe and:
   * Creates and associates a Stripe customer if one isn't already associated with the Morf profile.
   * Creates a card using the token.
   * Charges and immediately refunds \$1 to the card.
3. The endpoint returns Stripe details, letting users know immediately that their card went through.

### Inputs

* `morfOrgId`
* `patientId`
* `stripeToken` *(generated in form)*

### Outputs

* `stripeCustomerId`
* `stripePaymentSourceId`
* `stripePaymentIntentId`
* `stripePaymentIntentStatus`
* `message` *(only returned in the case of an error)*

### Morf Form Setup

Coming soon! Reach out to Morf support if you're interested in implementing a Stripe auth hold in your Morf form.

### Formsort Setup

> [accordion] Formsort setup instructions
>
> #### Integrate your form with Stripe
>
> From your form, navigate to **Integrations > Stripe**. Add credentials for your Stripe test and live keys to their corresponding Formsort environment.
>
> #### Integrate Morf with Stripe
>
> 1. In your Morf dashboard, navigate to **Integrations** and click **+ New Integration**.
> 2. Select **Stripe** and enter your Stripe access token.
> 3. Stripe staging and production environments must each be set up in their respective Morf organizations.
>
> #### Add a step for credit card entry
>
> 1. Navigate to your variant and add a step for credit card collection.
> 2. Add a payment to the step and name it `stripe_token_id`. Select **Stripe** as the provider.
> 3. Leave all other payment settings off.
>
> #### Create Formsort variables
>
> * **`morf_org_id`** *(calculated variable)* — This variable likely already exists in your form. If not, create a new calculated variable with type `string` and set **Blocks advancing from current step** to `true`. Enable **Use other variables** and add `formsort_environment`. Add the following to the **Getter Function Body**:
>
>   ```jsx theme={null}
>   if (formsort_environment == "staging") {
>     return "<morf-staging-id>"
>   } else {
>     return "<morf-prod-id>"
>   }
>   ```
>
> * **`stripe_charge_card`** *(API variable)* — A `POST` request to `https://questions.morf.health/api/createCustomerAndStoreCard`. Configure the variable settings and API parameters per your form's field mapping.
>
>   ![](https://mintcdn.com/morfhealth/nPXB9VnqEsa3Ru-D/images/formsort_stripe_api_variable.png?fit=max\&auto=format\&n=nPXB9VnqEsa3Ru-D\&q=85\&s=f31c14e7cf5650dbe5a300311bb2752b)
>
> #### Handle credit card errors
>
> 1. After the credit card collection step, add a new step for credit card errors. Users will be directed to this step if the Stripe API call fails to create the customer, card, or authorization hold.
> 2. Under step logic, set **Show conditionally** to `true` and configure the condition based on the `stripe_charge_card` response.
>
> #### (Optional) Allow credit card retry
>
> If a card fails, allow users to try a different card.
>
> **Add logic and steps**
>
> * Update your credit card error step to serve as a retry step. Add messaging informing the user they can try again with a different card.
> * Add a payment field to the step named `stripe_token_retry` and select **Stripe** as the provider.
>
> **Create retry variables**
>
> * **`stripe_charge_card_retry`** *(API variable)* — A `POST` request to `https://questions.morf.health/api/createCustomerAndStoreCard`. Configure variable settings and API parameters using `stripe_token_retry`.
>
> * **`stripe_info`** *(calculated variable)* — Contains the most recent result of the Stripe API call. Add the following to the **Getter Function Body**:
>
>   ```jsx theme={null}
>   if (stripe_card_charge_retry) { return stripe_card_charge_retry }
>   return stripe_charge_card
>   ```
>
> **Handle retry errors**
>
> After the credit card retry step, add a new step for retry errors. Users will be directed here if the Stripe API call fails on the retry attempt. Set **Show conditionally** to `true` and configure the condition based on the `stripe_charge_card_retry` response.

## Workflow Action Reference

The sections below document the Create Card workflow action.

# Parameters

**Action** `Parameters`

**parameters**

**Customer ID** `string`

`ID`
This field maps to the destination API `customer` field.

**Source** `string` *required*

`ID` `PII`
This field maps to the destination API `source` field.

```json Result Object Example theme={null}
{
  "$result_object_key": {
    "customer_id": "cus_J2m3K4L5N6O7P8Q9R0S",
    "id": "card_1NGTaT2eZvKYlo2CZWSctn5n"
  }
}
```

```json Result Object Description theme={null}
{
  "$result_object_key": {
    "customer_id": "Unique identifier for the customer",
    "id": "Unique identifier for the payment source"
  }
}
```

### Result Object Field Details

You can use the result of the action's data as inputs to downstream workflow actions.

Each fetch action requires an object name, which nests the action's result data inside the downstream data context in the workflow. See [Passing Data Between Actions](https://docs.morf.health/docs/knowledge_base/passing_data_between_actions.md) for how to set it and reference the result from downstream nodes.

Here we demonstrate how to refer to this data using the prefix `$result_object_key`.

**PaymentSource** `Fetch Action Response Object`

**fields**

**id** `string` *required*

Unique identifier for the payment source

```json CEL theme={null}
$result_object_key.id
```

```json Example theme={null}
"card_1NGTaT2eZvKYlo2CZWSctn5n"
```

**customer\_id** `string`

Unique identifier for the customer

```json CEL theme={null}
$result_object_key.customer_id
```

```json Example theme={null}
"cus_J2m3K4L5N6O7P8Q9R0S"
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.