Plaid logo
Docs
ALL DOCS

Auth

  • Introduction to Auth
  • Add Auth to your app
  • Move money with our partners
  • Add institution coverage
Plaid logo
Docs
Plaid.com
Get API keys
Open nav

Add Astra to your app

Use Astra with Plaid Auth to send and receive payments!

Partnership Astra logo

Overview

Plaid and Astra have partnered to help businesses offer automated ACH transfers to their users. Using Plaid’s Auth product in tandem with the Astra automation platform gives fintech developers the ability to build advanced self-driving product experiences and enable programmatic money movement for their customers.

Getting Started

You'll first want to familiarize yourself with Plaid Link, a drop-in client-side integration for the Plaid API that handles input validation, error handling, and multi-factor authentication. You will also need to have a verified Astra account to add a bank funding source.

Your customers will use Link to authenticate with their financial institution and select the bank account they wish to use for payment transactions. From there, you'll receive a Plaid access_token and a Astra processor_token, which allows you to quickly and securely verify a bank funding source via Astra's API without having to store any sensitive banking information. Utilizing Plaid + Astra enables a seamless workflow for sending and receiving payments.

Instructions

Set up your accounts

You'll need accounts at both Plaid and Astra in order to use the Plaid + Astra integration. You'll also need to enable your Plaid account for the Astra integration.

First, you will need to work with the Astra team to sign up for a Astra account, if you do not already have one.

Next, verify that your Plaid account is enabled for the integration. If you do not have a Plaid account, create one.

To enable your Plaid account for the integration, go to the Integrations section of the account dashboard. If the integration is off, simply click the 'Enable' button for Astra to enable the integration.

Finally, you'll need to complete your Plaid Application Profile in the Dashboard, which involves filling out basic information about your app, such as your company name and website. This step helps your end-users learn more how your product uses their bank information and is also required for connecting to some banks.

Create a link_token

In order to integrate with Plaid Link, you will 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. To create one, make a /link/token/create request with your client_id, secret, and a few other required parameters from your app server. For a full list of link_token configurations, see /link/token/create.

To see your client_id and secret, visit the Plaid Dashboard.

Select group for content switcher
Select Language
Copy
1app.post('/api/create_link_token', async function (request, response) {
2 // Get the client_user_id by searching for the current user
3 const user = await User.find(...);
4 const clientUserId = user.id;
5 const request = {
6 user: {
7 // This should correspond to a unique id for the current user.
8 client_user_id: clientUserId,
9 },
10 client_name: 'Plaid Test App',
11 products: ['auth'],
12 language: 'en',
13 webhook: 'https://webhook.example.com',
14 redirect_uri: 'https://domainname.com/oauth-page.html',
15 country_codes: ['US'],
16 };
17 try {
18 const createTokenResponse = await client.linkTokenCreate(request);
19 response.json(createTokenResponse.data);
20 } catch (error) {
21 // handle error
22 }
23});
Integrate with Plaid Link

Once you have a link_token, all it takes is a few lines of client-side JavaScript to launch 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 a Astra processor_token.

Copy
1<button id="linkButton">Open Link - Institution Select</button>
2<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
3<script>
4 (async function(){
5 var linkHandler = Plaid.create({
6 // Make a request to your server to fetch a new link_token.
7 token: (await $.post('/create_link_token')).link_token,
8 onSuccess: function(public_token, metadata) {
9 // The onSuccess function is called when the user has successfully
10 // authenticated and selected an account to use.
11 //
12 // When called, you will send the public_token and the selected accounts,
13 // metadata.accounts, to your backend app server.
14 sendDataToBackendServer({
15 public_token: public_token,
16 accounts: metadata.accounts
17 });
18 },
19 onExit: function(err, metadata) {
20 // The user exited the Link flow.
21 if (err != null) {
22 // The user encountered a Plaid API error prior to exiting.
23 }
24 // metadata contains information about the institution
25 // that the user selected and the most recent API request IDs.
26 // Storing this information can be helpful for support.
27 },
28 });
29 })();
30
31 // Trigger the authentication view
32 document.getElementById('linkButton').onclick = function() {
33 // Link will automatically detect the institution ID
34 // associated with the public token and present the
35 // credential view to your user.
36 linkHandler.open();
37 };
38</script>

See the Link parameter reference for complete documentation on possible configurations.

Plaid.create accepts one argument, a configuration Object, and returns an Object with three functions, open, exit, and destroy. Calling open will display the "Institution Select" view, calling exit will close Link, and calling destroy will clean up the iframe.

Write server-side handler

The Link module handles the entire onboarding flow securely and quickly, but does not actually retrieve account data for a user. Instead, the Link module returns a public_token and an accounts array, which is a property on the metadata object, via the onSuccess callback. Exchange this public_token for a Plaid access_token using the /item/public_token/exchange API endpoint.

The accounts array will contain information about bank accounts associated with the credentials entered by the user, and may contain multiple accounts if the user has more than one bank account at the institution. If you want the user to specify only a single account to link so you know which account to use with Astra, set Account Select to "enabled for one account" in the Plaid Developer Dashboard. When this setting is selected, the accounts array will always contain exactly one account.

Once you have identified the account you will use, you will send the access_token and account_id property of the account to Plaid via the /processor/token/create endpoint in order to create a Astra processor_token. You'll send this token to Astra and they will use it to securely retrieve account and routing numbers from Plaid.

You can create Astra processor_tokens in all three API environments:

  • Sandbox (https://sandbox.plaid.com): test simulated users
  • Development (https://development.plaid.com): test live users
  • Production (https://production.plaid.com): production environment for when you're ready to go live and have valid Astra Production credentials
Select group for content switcher
Select Language
Copy
1const { Configuration, PlaidApi, PlaidEnvironments, ProcessorTokenCreateRequest } = require('plaid');
2
3// Change sandbox to development to test with live users;
4// Change to production when you're ready to go live!
5const configuration = new Configuration({
6 basePath: PlaidEnvironments[process.env.PLAID_ENV],
7 baseOptions: {
8 headers: {
9 'PLAID-CLIENT-ID': process.env.PLAID_CLIENT_ID,
10 'PLAID-SECRET': process.env.PLAID_SECRET,
11 'Plaid-Version': '2020-09-14',
12 },
13 },
14});
15
16const plaidClient = new PlaidApi(configuration);
17
18try {
19 // Exchange the public_token from Plaid Link for an access token.
20 const tokenResponse = await plaidClient.itemPublicTokenExchange({
21 public_token: publicToken,
22 });
23 const accessToken = tokenResponse.data.access_token;
24
25 // Create a processor token for a specific account id.
26 const request: ProcessorTokenCreateRequest = {
27 access_token: accessToken,
28 account_id: accountID,
29 processor: 'astra',
30 };
31 const processorTokenResponse = await plaidClient.processorTokenCreate(
32 request,
33 );
34 const processorToken = processorTokenResponse.data.processor_token;
35} catch (error) {
36 // handle error
37}

For a valid request, the API will return a JSON response similar to:

Copy
1{
2 "processor_token": "processor-sandbox-0asd1-a92nc",
3 "request_id": "m8MDnv9okwxFNBV"
4}

For possible error codes, see the full listing of Plaid error codes.

Example code in Plaid Pattern

For a real-life example of an app that incorporates the creation of processor tokens, see the Node-based Plaid Pattern Account Funding sample app. Pattern Account Funding is a sample account funding app that creates a processor token to send to your payment partner. The processor token creation code can be found in items.js

Launching to Production

Test with Sandbox credentials

To test the integration in Sandbox mode, simply use the Plaid Sandbox credentials along when launching Link with a link_token created in the Sandbox environment.

When testing in the Sandbox, you have the option to use the /sandbox/public_token/create endpoint instead of the end-to-end Link flow to create a public_token. When using the /sandbox/public_token/create-based flow, the Account Select flow will be bypassed and the accounts array will not be populated. On Sandbox, instead of using the accounts array, you can call /accounts/get and test with any returned account ID associated with an account with the subtype checking or savings.

Get ready for production

Your account is immediately enabled for our Sandbox environment (https://sandbox.plaid.com). To move to Production, please request access from the Dashboard. You will need Astra Production credentials prior to initiating live payment transactions in the Astra API with Plaid.

Support and questions

Find answers to many common integration questions and concerns—such as pricing, sandbox and test mode usage, and more, in our docs.

If you're still stuck, open a support ticket with information describing the issue that you're experiencing and we'll get back to you as soon as we can.

Was this helpful?
Developer community
GitHub
GitHub
Stack Overflow
Stack Overflow
YouTube
YouTube
Twitter
Twitter
Discord
Discord