600


This guide describes how to embed this pre-built Payment Flow UI in your application. The Payment Flow is currently tailored to collect domestic US account details and initiate ACH debits, but in the future global account types and payment types will be supported.

## 1. Retrieve your API Key

**Dashboard**: Go to your [API Keys page](🔗). There you will find your Organization ID and API keys. Your default Sandbox or Production keys have the appropriate permissions. Otherwise, create or modify an API key to have manage permissions for Developer Resources.

## 2. Create a Counterparty

**Server-side**: [Create a counterparty](🔗) for the end user whose bank account information you will be collecting.



The API request will return a [Counterparty](🔗) object, and the `id` will be used in the next step.



## 3. Create a Payment Flow

**Server-side**: [Create a Payment Flow](🔗)

In addition to the `counterparty_id`, specify the `originating_account_id` you want to initiate the payment from as well as the `amount`, `currency`, and `direction` of the payment. Modern Treasury will customize the embedded form to collect the necessary information required for this payment.



This API request will return a [Payment Flow](🔗) object. The `client_token` will be used in future steps.



Only use API Keys server-side

Please make sure you are creating `Counterparty` and `PaymentFlow` objects from your backend servers. API Keys are secret, and should not be used directly in client-side applications.

## 4. Retrieve Publishable API Key

**Dashboard**: Go to your [Publishable API Keys](🔗) page. There, you will find your Publishable API Keys. If you do not have one, create one.

## 5. Mount the Workflow

### **Add `modern-treasury-js` **

**Client-side**: You first need to add [`modern-treasury-js`](🔗) to your application. We recommend installing the library from NPM, but you can also directly install the script from our CDN.



### **Initialize `ModernTreasury`**

**Client-side**: Initialize `ModernTreasury` with your Publishable API Key from the previous step.



### **Create an Embeddable Flow**

**Client-side**: The next step is to create the `EmbeddableFlow`. You must pass the `client_token` from the previous step. While not required, we recommend defining an `onSuccess` callback to handle what happens after an end-user successfully completes the flow. Similarly, we recommend defining an `onError` callback to handle any unexpected errors. Visit [`createEmbeddableFlow`](🔗) documentation for full details.



#### **(_Optional_) Customize Appearance**

**Client-side**: You can customize the appearance of embeddable flows to match the look and feel of your application. Check out our [`createEmbeddableFlow`](🔗) documentation to see how to customize properties like colors and font.

### **Mount the Embeddable Flow**

**Client-side**: Now that you have an `EmbeddableFlow`, you need to add it to the DOM. You can [`mount`](🔗) the flow to a valid CSS selector or a DOM element. After successfully mounting, the end-user will be able to start progressing through the flow.



### **Summary**

After following all of these steps, you may have something that looks like this:



## 6. End-User Submits Account Details

**Client-side**: Once the flow is mounted, the end-user will follow the embedded Payment flow and submit their account details. Once complete, we will create an `ExternalAccount` associated with the given Counterparty and a `PaymentOrder` and save both of these to the `PaymentFlow`. We will also move the `PaymentFlow#status` to `completed` and call the `onSuccess` callback so that you can customize your success behavior and navigate to the next page.