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

# Plaid integration for ACH payments

> Connect your existing Plaid integration to Straddle to convert Plaid Link bank connections into paykeys for ACH charges, payouts, and verification.

![Plaid Logo](https://mintcdn.com/straddle/yfacwvdaNnY4Xjbu/logo/plaidlogo.png?fit=max\&auto=format\&n=yfacwvdaNnY4Xjbu\&q=85\&s=779a489a8118c156a08bce81e3cfc50f)

This guide provides a detailed walkthrough on integrating Plaid with Straddle for fast and secure account-to-account payments. By leveraging Plaid's bank connections and Straddle's payment infrastructure, you can offer a seamless and secure payment experience to your users.

## Prerequisites

Before you begin, ensure you have:

* [A Straddle account with API access](https://accounts.straddle.com/sign-up)

* [A Plaid account with API access](https://my.plaid.com/sign-up/how-plaid-works)

* Enable Straddle's Plaid integration in your Plaid [account settings](https://dashboard.plaid.com/team/integrations). If you need assistance with this step, reach out to your Account Manager with Plaid.

* Customize Plaid Link's account selection to only be "[enabled for one account](https://dashboard.plaid.com/link/account-select)."

## Implementation steps

> [accordion] 1. Set up Plaid Link for user bank account connection
>
> Integrate Plaid Link into your frontend to allow users to securely connect their bank account. Plaid Link is the front-end module that facilitates the connection between the user's bank account and your application.

> [accordion] 2. Obtain an access token from Plaid
>
> Once the user connects their bank account using Plaid Link, Plaid returns a public token. Exchange this public token for an access token via Plaid’s API, which allows you to access the user's account information.

> [accordion] 3. Use the access token to get a Straddle processor token from Plaid
>
> With the access token obtained from Plaid, request a Straddle processor token from Plaid. This token allows you to link the user's bank account to Straddle's payment processing system.

> [accordion] 4. Use the Straddle processor token to create a secure payment token via Straddle's Bridge API
>
> Pass the Straddle processor token to Straddle's Bridge API. Straddle returns a `paykey` which is linked to the user's bank account, allowing future transactions to be processed.

> [accordion] 5. Store and use the paykey for future transactions
>
> Store the `paykey` securely in your system. Use this `paykey` to create charges, initiate payments, or perform other transactions via Straddle's API in the future.

## Setting up Plaid

### Configure Plaid product and Link settings in the Plaid dashboard

To get the most out of the Straddle integration with Plaid, be sure to enable the following core services in your [Plaid dashboard](https://dashboard.plaid.com/settings/team/products).

![](https://unicorn-images.b-cdn.net/8305e162-9f09-4be7-9b66-5c9cbc026599?optimizer=gif\&width=1132\&height=686)

Once that's complete, remember to style and customize your [Link application UI](https://dashboard.plaid.com/link). It's especially important to define a "use case" in the [Data Transparency Messaging](https://plaid.com/docs/link/data-transparency-messaging-migration-guide/) configuration.

![](https://unicorn-images.b-cdn.net/88480a8c-692f-493c-8624-c63caedfc6ab?optimizer=gif\&width=686\&height=896)

> [!TIP]
>
> Data transparency messaging ensures compliance with the latest open-banking regulations. Check out this article on [CFPB's 1033 Final Rule](https://plaid.com/resources/compliance/section-1033/) to learn more.

### Intro to Link

Plaid Link is the client-side component that your users interact with to link their accounts to Plaid and allow you to access their accounts via the Plaid API.

![](https://plaid.com/_next/image?url=/assets/img/docs/docs-link-overview.png\&w=1920\&q=75)

Plaid Link handles credential validation, multi-factor authentication, and error handling for each institution that Plaid supports. Link is supported via SDKs for all modern browsers and platforms, including [web](https://plaid.com/docs/link/web/), [iOS](https://plaid.com/docs/link/ios/), [Android](https://plaid.com/docs/link/android/), as well as via [React Native](https://plaid.com/docs/link/react-native/), along with community-supported wrappers for [Flutter](https://github.com/jorgefspereira/plaid_flutter), [Angular](https://github.com/mike-roberts/ngx-plaid-link), and [Vue](https://github.com/jclaessens97/vue-plaid-link/).

For webview-based integrations or integrations that don't have a frontend, Plaid also provides a drop-in [Hosted Link](https://plaid.com/docs/link/hosted-link/) integration mode.

To try Link, see [Plaid Link Demo](https://plaid.com/demo/).

> [!NOTE]
>
> This guide gives you a rundown of the steps required to start building on Plaid and connect to Straddle. However, you should always treat [Plaid's official documentation](https://plaid.com/docs/link/#introduction-to-link) as the ultimate source of truth during integration with their platform.

### Create a `link_token`

Now you're ready to start building. To integrate with Plaid Link, you first need to create a `link_token`. A `link_token` is a short-lived, one-time use token that is used to authenticate your app with Link and initiate a session for a user.

To create one, make a [`/link/token/create`](https://plaid.com/docs/api/link/#linktokencreate) request with your `client_id`, `secret`, and a few other required parameters from your app server.

> [!NOTE]
>
> View the [`/link/token/create`](https://plaid.com/docs/api/link/#linktokencreate) documentation for a full list of configurations.

To see your `client_id` and `secret`, visit the [Plaid Dashboard](https://dashboard.plaid.com/developers/keys).

```bash theme={null}
curl -X POST https://sandbox.plaid.com/link/token/create \
-H 'Content-Type: application/json' \
-d '{
  "client_id": "${PLAID_CLIENT_ID}",
  "secret": "${PLAID_SECRET}",
  "client_name": "Plaid Test App",
  "user": { "client_user_id": "${UNIQUE_USER_ID}" },
  "products": ["auth"],
  "country_codes": ["US"],
  "language": "en",
  "webhook": "https://webhook.example.com",
  "redirect_uri": "https://domainname.com/oauth-page.html"
}'
```

### Initialize Link

Once you have a `link_token`, all it takes is a few lines of client-side JavaScript to [initialize Link](https://plaid.com/docs/link/#initializing-link). Then, in the `onSuccess` callback, you can call a simple server-side handler to exchange the Link `public_token` for a Plaid `access_token` and -- ultimately -- a Straddle `processor_token`.

```javascript theme={null}
<button id="linkButton">Open Link - Institution Select</button>
<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
<script>
  (async function(){
    var linkHandler = Plaid.create({
      // Make a request to your server to fetch a new link_token.
      token: (await $.post('/create_link_token')).link_token,
      onLoad: function() {
          // The Link module finished loading.
      },
      onSuccess: function(public_token, metadata) {
        // The onSuccess function is called when the user has
        // successfully authenticated and selected an account to
        // use.
        //
        // When called, you will send the public_token and the selected accounts,
        // metadata.accounts, to your backend app server.

        sendDataToBackendServer({
           public_token: public_token,
           accounts: metadata.accounts
        });
      },
        console.log('Public Token: ' + public_token);
        console.log('Customer-selected account ID: ' + metadata.account_id);
      },
      onExit: function(err, metadata) {
        // The user exited the Link flow.
        if (err != null) {
            // The user encountered a Plaid API error
            // prior to exiting.
        }
        // metadata contains information about the institution
        // that the user selected and the most recent
        // API request IDs.
        // Storing this information can be helpful for support.
      },
    });
  })();

  // Trigger the authentication view
  document.getElementById('linkButton').onclick = function() {
    linkHandler.open();
  };
</script>
```

## Obtaining a Straddle processor token from Plaid

Once you have the access token, you can use it to obtain a Straddle [processor token](https://plaid.com/docs/api/processors/#processortokencreate) from Plaid. This token is specific to Straddle and allows secure communication between Plaid and Straddle.

```javascript theme={null}
# Exchange the public token from Plaid Link for an access token.
curl \
  -H 'Content-Type: application/json' \
  -d '{
    "client_id": "${PLAID_CLIENT_ID}",
    "secret": "${PLAID_SECRET}",
    "public_token": "${PUBLIC_TOKEN}"
  }' \
  -X POST \
  https://sandbox.plaid.com/item/public_token/exchange

# Create a processor token for a specific account id.
curl \
  -H 'Content-Type: application/json' \
  -d '{
    "client_id": "${PLAID_CLIENT_ID}",
    "secret": "${PLAID_SECRET}",
    "access_token": "${ACCESS_TOKEN}",
    "account_id": "${ACCOUNT_ID}",
    "processor": "straddle"
  }' \
  -X POST \
  https://sandbox.plaid.com/processor/token/create
```

Note that `straddle` is the specific processor you're requesting the token for. This tells Plaid to generate a token compatible with Straddle's systems.

## Using the Straddle Bridge API with a Plaid token

Once you have obtained the Straddle processor token from Plaid, you can use it to create a [paykey](https://docs.straddle.com/guides/bridge/paykeys.md) via Straddle's [Bridge API](https://docs.straddle.com/api-reference/bridge/plaid-token.md). Here's the correct HTTP request format:

```bash Bridge a Plaid Token theme={null}
curl -X POST https://sandbox.straddle.com/v1/bridge/plaid \
  -H "Authorization: Bearer YOUR_STRADDLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "0191ef41-8de5-716c-bfa4-41cd79e85705",
    "plaid_token": "straddle-sandbox-123abc...",
    "metadata": {
      "nickname": "My Bank Account"
    }
  }'
```

Replace `YOUR_STRADDLE_API_KEY` with your actual Straddle API key, and fill in the appropriate values for `customer_id` and `plaid_token`. The `metadata` field is optional but can be useful for storing additional information related to the Plaid account.

> [!NOTE]
>
> Straddle interacts with Plaid [/auth](https://plaid.com/docs/api/products/auth/) and [/identity](https://plaid.com/docs/api/products/identity/) endpoints on your behalf to resolve the user's bank account details and ownership information.

## Handling the Straddle API response

The Straddle API responds with a paykey object. Here's an example of what you might receive:

```json theme={null}
{
  "data": {
    "paykey": "05f5d55cb14f7e8a0ec2e5689376e3b4665efc34834d30995babbd5010b39913",
    "bank_data": {
      "routing_number": "011000138",
      "account_number": "******7890",
      "account_type": "checking"
    },
    "id": "0191ef49-892c-7460-99d1-f5589d7d9989",
    "customer_id": "0191ef41-8de5-716c-bfa4-41cd79e85705",
    "label": "CHASE BANK - *7890",
    "source": "plaid",
    "institution_name": "CHASE BANK",
    "status": "active",
    "created_at": "2024-09-14T06:47:39.5648743Z",
    "updated_at": "2024-09-14T06:47:39.5648746Z",
    "metadata": {
      "plaid_account_id": "5f7a8b9c0d1e2f3g4h5i6j7k"
    }
  },
  "meta": {
    "api_request_id": "243431dd-7deb-4445-820d-55a942ace70f"
  },
  "response_type": "object"
}
```

Note that the `source` field is set to `plaid` in this case, indicating that the paykey was created using a Plaid token.

You should store this `paykey` securely for future use in transactions. When it's time to get paid, [create a charge](https://docs.straddle.com/api-reference/charges/create.md) and Straddle automatically attempts to verify the account's balance prior to origination.

## Best practices and security considerations

1. **Token Security**: Never expose Plaid access tokens or Straddle processor tokens to the frontend. Always handle these server-side.

2. **Error Handling**: Implement robust error handling for both Plaid and Straddle API calls.

3. **Metadata Usage**: Use the metadata field to store relevant information, such as the Plaid account ID, for future reference.

4. **Token Refreshing**: Be aware of token expiration policies for both Plaid and Straddle. Implement token refresh mechanisms as needed.

5. **Compliance**: Ensure you're complying with both Plaid and Straddle's terms of service and data handling requirements.

6. **Logging**: Implement comprehensive logging for debugging and audit purposes, but be careful not to log sensitive information.

## Troubleshooting common issues

1. **Invalid Processor Token**: Ensure you're using `straddle` as the processor when requesting the token from Plaid.

2. **Authentication Errors**: Double-check your API keys for both Plaid and Straddle.

3. **Expired Tokens**: If you're getting authentication errors, your tokens might have expired. Implement a token refresh mechanism.

4. **Account Not Supported**: Some bank accounts may not be supported for ACH transactions. Handle these cases gracefully in your UI.

5. **Rate Limiting**: Be aware of rate limits on both Plaid and Straddle APIs. Implement appropriate backoff strategies if you hit these limits.

By following this guide, you should be able to successfully integrate Plaid with Straddle, leveraging the strengths of both platforms to provide a robust, secure payment solution for your users.


## Related topics

- [Quiltt integration for ACH payments](https://docs.straddle.com/integrations/open-banking/quiltt.md)
- [Zapier integration for Straddle webhooks](https://docs.straddle.com/integrations/webhooks/zapier.md)
- [Payment status and lifecycle reference](https://docs.straddle.com/guides/payments/statuses.md)
- [ACH payments basics](https://docs.straddle.com/help/ACH101/ach-basics.md)
- [ACH payment authorization guide](https://docs.straddle.com/help/Payment-Compliance/ach-auth.md)


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