---
title: Save Venmo for purchase later with JavaScript SDK v5
description: Save a payer's Venmo account to the vault without a purchase, using
  app switch, QR code, or Venmo web login.
---

# Save Venmo for purchase later with JavaScript SDK v5 (/platforms/checkout/save-payment-methods/purchase-later/js-sdk/venmo)



Save Venmo accounts to charge payers after a set amount of time. For example, offer a free trial and charge payers after the trial expires. Payers don't need to be present when charged, and no checkout is required.

Customers with a saved Venmo account can:

* Be charged for recurring transactions or subscriptions without being present
* Check out on your site without re-entering payment details
* Manage their saved payment connections in Venmo Connected Businesses

## Availability [#availability]

Venmo is available only in the US.

## Use cases [#use-cases]

Save a Venmo account if you want customers to:

* Check out without re-entering a payment method
* Enroll in subscriptions or free trials where billing begins at a future date
* Pay after use, for example, for ride-sharing and food delivery

## Know before you code [#know-before-you-code]

Complete the following before you start:

* Identify each payer uniquely. For example, payers create an account and log in to your site.
* Get your sandbox account login information and access token from the Developer Dashboard. See [Get started](/platforms/get-started/).
* Have a PayPal Developer account.
* Onboard your sellers. See [Onboard sellers to save payment methods](/platforms/checkout/save-payment-methods/onboarding/).
* Add a server-side call that exchanges a setup token for a payment method token.

> **Warning:** PayPal requires Risk Data Acquisition (RDA) to reduce fraud. Collect device data with [FraudNet](/limited-release/fraudnet) and [Magnes](/limited-release/magnes). Send the client metadata ID (CMID) that FraudNet used in the `PayPal-Client-Metadata-Id` header on every customer-initiated transaction (CIT) that charges a saved Venmo payment token. When the payer isn't present, store the CMID from the session that collected the device data, and send it with the charge. A CMID with no matching FraudNet session doesn't link the charge to device data. Payment attempts without RDA data are likely to be declined because of insufficient risk identifiers.

## How it works [#how-it-works]

PayPal encrypts Venmo account information and stores it in a digital vault for that customer.

1. The payer saves their Venmo account.
2. For a first-time payer, PayPal creates a customer ID. Store the customer ID in your system for future use.
3. When the customer returns to your website, pass the PayPal-generated customer ID to the JavaScript SDK. The customer ID tells the SDK to reuse the saved payment method.
4. The payer authorizes the vault connection:
   * **Mobile:** The SDK prompts the payer to app switch to the Venmo app.
   * **Desktop:** The SDK shows a QR code. The payer scans it with a mobile camera or the Venmo in-app scanner, then approves in the Venmo app.
   * **Fallback:** If the Venmo app isn't installed or the QR code flow isn't available, the SDK opens Venmo web login.
5. After the payer approves, the SDK populates the checkout page with the saved Venmo account. The Venmo button shows the payer's Venmo username (@handle).

## 1. Check eligibility [#1-check-eligibility]

Confirm that PayPal approved your business account to save Venmo accounts.

1. Go to [paypal.com](https://www.paypal.com/) and log in to your business account.
2. Go to **Account Settings** > **Payment Preferences** > **Save PayPal and Venmo payment methods**.
3. Select **Get Started**.
4. Submit your profile details. PayPal reviews your eligibility.
5. Check your status: **Success**, **Need more information**, or **Denied**.

## 2. Set up your account to save payments [#2-set-up-your-account-to-save-payments]

Set up your sandbox and live business accounts to save payment methods.

1. Log in to the Developer Dashboard.
2. Under **REST API apps**, select your app name.
3. Under **Sandbox App Settings** > **App Feature Options**, select **Accept payments**.
4. Expand **Advanced options** and confirm that **Vault** is selected.

Only your sandbox business account is enabled to save payment methods. Your developer account is unaffected. To go live, start the vetting process from the Developer Dashboard.

## 3. Generate a user ID token for the payer [#3-generate-a-user-id-token-for-the-payer]

Set the `response_type` parameter of the PayPal OAuth 2.0 API to `id_token` to get a unique ID token for a payer. The `id_token` identifies each payer and expires in a few minutes. Generate a new token each time payment fields render on your page.

### Platform integration [#platform-integration]

Replace the following values, then run the code to generate a user ID token for a payer who saves a Venmo account for the first time:

The REST examples below use live endpoints. For sandbox testing, replace `https://api-m.paypal.com` with `https://api-m.sandbox.paypal.com` throughout this guide and use your sandbox app's credentials and tokens.

* `CLIENT-ID`: Your client ID.
* `CLIENT-SECRET`: Your client secret.
* `AUTH-ASSERTION-TOKEN`: Your [PayPal-Auth-Assertion](/api/rest/requests/#paypal-auth-assertion) token.
* `BN-CODE`: Your [PayPal Attribution ID](/api/rest/requests/#paypal-partner-attribution-id).

```bash
curl -s -X POST https://api-m.paypal.com/v1/oauth2/token \
  -u CLIENT-ID:CLIENT-SECRET \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'PayPal-Auth-Assertion: AUTH-ASSERTION-TOKEN' \
  -H 'PayPal-Partner-Attribution-Id: BN-CODE' \
  -d 'grant_type=client_credentials' \
  -d 'response_type=id_token'
```

For a returning payer, add the saved PayPal-generated customer ID in the `target_customer_id` body parameter. The `target_customer_id` value is available when you capture the order or retrieve saved payment information. This parameter is optional. Include it to show a recognized returning payer, so the Venmo button shows the payer's @handle.

Replace `CUSTOMER-ID` with the PayPal-generated customer ID stored in your system:

```bash
curl -s -X POST https://api-m.paypal.com/v1/oauth2/token \
  -u CLIENT-ID:CLIENT-SECRET \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'PayPal-Auth-Assertion: AUTH-ASSERTION-TOKEN' \
  -H 'PayPal-Partner-Attribution-Id: BN-CODE' \
  -d 'grant_type=client_credentials' \
  -d 'response_type=id_token' \
  -d 'target_customer_id=CUSTOMER-ID'
```

### Merchant integration [#merchant-integration]

Replace `CLIENT-ID` and `CLIENT-SECRET` with your client ID and client secret. Run the code to generate a user ID token for a payer who saves a Venmo account for the first time:

```bash
curl -s -X POST https://api-m.paypal.com/v1/oauth2/token \
  -u CLIENT-ID:CLIENT-SECRET \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=client_credentials' \
  -d 'response_type=id_token'
```

For a returning payer, replace `CUSTOMER-ID` with the PayPal-generated customer ID stored in your system:

```bash
curl -s -X POST https://api-m.paypal.com/v1/oauth2/token \
  -u CLIENT-ID:CLIENT-SECRET \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=client_credentials' \
  -d 'response_type=id_token' \
  -d 'target_customer_id=CUSTOMER-ID'
```

A successful response returns an `id_token` value. You pass it to the SDK in the next step.

## 4. Pass the user ID token to the JavaScript SDK [#4-pass-the-user-id-token-to-the-javascript-sdk]

Pass the `id_token` from your server to the JavaScript SDK in the `data-user-id-token` attribute. Add `enable-funding=venmo` as a query parameter to render the Venmo button.

Replace the following values:

* `CLIENT-ID`: Your client ID.
* `MERCHANT-ID`: Your merchant ID. Platform integrations only. Include this parameter when you process Venmo transactions for another merchant. See the [JavaScript SDK script configuration](/sdk/js/configuration/#merchant-id).
* `ID-TOKEN`: The `id_token` from the previous step.

```html
<script
  src="https://www.paypal.com/sdk/js?client-id=CLIENT-ID&merchant-id=MERCHANT-ID&enable-funding=venmo"
  data-user-id-token="ID-TOKEN">
</script>
```

## 5. Add the Venmo button [#5-add-the-venmo-button]

Add a container for the button and render it with the client-side callbacks that handle API calls, payer approval, and errors. Set `fundingSource` to `window.paypal.FUNDING.VENMO` so only the Venmo button renders. The `enable-funding=venmo` parameter makes Venmo eligible but doesn't hide other eligible buttons, and these callbacks create only Venmo setup tokens. Replace `venmo-buttons-container` with a container ID of your choice, and update `.render()` to match.

```html
<div id="venmo-buttons-container"></div>

<script>
    window.paypal.Buttons({
        fundingSource: window.paypal.FUNDING.VENMO,
        createVaultSetupToken: async () => {},
        onApprove: async ({ vaultSetupToken }) => {},
        onError: (error) => {}
    }).render("#venmo-buttons-container");
</script>
```

## 6. Create a setup token [#6-create-a-setup-token]

Request a setup token from your server, and pass it to the SDK in the `createVaultSetupToken` callback. The callback calls the server endpoint that creates the setup token and returns the token as a string. Errors that occur while the server creates a setup token appear in the `onError` callback.

| Callback                | Returns              | Description                                                                                                                               |
| ----------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `createVaultSetupToken` | Setup token (string) | Creates a setup token for Venmo on your server. The SDK saves the payment method and updates the setup token with payment method details. |

### Client-side code sample [#client-side-code-sample]

The following sample calls your server endpoint and returns the setup token:

```js
window.paypal.Buttons({
    fundingSource: window.paypal.FUNDING.VENMO,
  createVaultSetupToken: async () => {
    // Call your server API to generate a setup token
    // and return it here as a string
    const result = await fetch("/create/setup/token", {
      method: "POST"
    });
    const { id } = await result.json();
    return id;
  }
})
```

### Server-side code sample [#server-side-code-sample]

Set up your server to call the [Payment Method Tokens API](/api/payment-tokens/v3). The SDK uses this API to save Venmo accounts in the background.

Replace the following values:

* `ACCESS-TOKEN`: Your app's access token.
* `BN-CODE`: Your [PayPal Attribution ID](/api/rest/requests/#paypal-partner-attribution-id), for revenue attribution. Platform integrations only. To find your BN code, see [Code and credential reference](/platforms/create-account/#bn-code).
* `AUTH-ASSERTION-JWT`: Your [PayPal-Auth-Assertion](/api/rest/requests/#paypal-auth-assertion) token. Platform integrations only.
* `REQUEST-ID`: A unique alphanumeric string, such as a timestamp.

In the `createVaultSetupToken` callback, call this endpoint on your server and return the setup token string to the SDK.

#### Platform integration

```bash
curl -v -X POST https://api-m.paypal.com/v3/vault/setup-tokens \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ACCESS-TOKEN' \
  -H 'PayPal-Partner-Attribution-Id: BN-CODE' \
  -H 'PayPal-Auth-Assertion: AUTH-ASSERTION-JWT' \
  -H 'PayPal-Request-Id: REQUEST-ID' \
  -d '{
    "payment_source": {
      "venmo": {
        "usage_type": "PLATFORM",
        "experience_context": {
          "return_url": "https://example.com/returnUrl",
          "cancel_url": "https://example.com/cancelUrl",
          "app_switch_context": {
            "source": "NATIVE_APP"
          }
        }
      }
    }
  }'
```

#### Merchant integration

```bash
curl -v -X POST https://api-m.paypal.com/v3/vault/setup-tokens \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ACCESS-TOKEN' \
  -H 'PayPal-Request-Id: REQUEST-ID' \
  -d '{
    "payment_source": {
      "venmo": {
        "usage_type": "MERCHANT",
        "experience_context": {
          "return_url": "https://example.com/returnUrl",
          "cancel_url": "https://example.com/cancelUrl",
          "app_switch_context": {
            "source": "NATIVE_APP"
          }
        }
      }
    }
  }'
```

### Setup token response [#setup-token-response]

A `status` of `PAYER_ACTION_REQUIRED` means the payer needs to authorize the vault connection in the Venmo app. Return the `id` to your client to start the payer approval flow.

```json
{
  "id": "4G4976650J0948357",
  "customer": {},
  "status": "PAYER_ACTION_REQUIRED",
  "payment_source": {
    "venmo": {
      "usage_type": "PLATFORM",
      "experience_context": {
        "return_url": "https://example.com/returnUrl",
        "cancel_url": "https://example.com/cancelUrl"
      }
    }
  },
  "links": [
    {
      "href": "https://api-m.paypal.com/v3/vault/setup-tokens/4G4976650J0948357",
      "rel": "self",
      "method": "GET",
      "encType": "application/json"
    },
    {
      "href": "https://account.venmo.com/go/web/paypal?vault_token=4G4976650J0948357&return_flow=AUTO",
      "rel": "payer-action",
      "method": "GET",
      "encType": "application/json"
    }
  ]
}
```

### Payer approval [#payer-approval]

When the status is `PAYER_ACTION_REQUIRED`, the SDK starts the payer approval flow. The payer authorizes only the vault connection. The payer doesn't go through a traditional checkout, and no purchase amount appears.

* **Mobile (app switch):** The SDK prompts the payer to switch to the Venmo app. In Venmo, the payer agrees to save their account as a payment method.
* **Desktop (QR code):** The SDK shows a QR code. The payer scans it with a mobile camera or the Venmo in-app scanner, then approves the vault connection in the Venmo app. The desktop view then tells the payer to go to the Venmo app.
* **Fallback (Venmo web login):** If the Venmo app isn't installed or isn't available, the SDK opens Venmo web login.

## 7. Create a payment token [#7-create-a-payment-token]

Exchange the approved setup token for a permanent payment token. To save the payer's Venmo account to the vault, call the Payment Method Tokens API from your server.

Optionally, store a merchant customer ID that matches your system to simplify mapping customer information between your system and PayPal.

| Callback    | Returns                       | Description                                                                                                                                   |
| ----------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `onApprove` | `{ vaultSetupToken: string }` | Runs when the payer approves the vault connection in the Venmo app. Your server exchanges the returned `vaultSetupToken` for a payment token. |

### Client-side code sample [#client-side-code-sample-1]

The following sample sends the `vaultSetupToken` to your server:

```js
window.paypal.Buttons({
    fundingSource: window.paypal.FUNDING.VENMO,
    onApprove: async ({ vaultSetupToken }) => {
        // Send the vaultSetupToken to your server
        // so your server can generate a permanent payment token
        const response = await fetch("/create/payment/token", {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify({ vaultSetupToken })
        });
        if (!response.ok) throw new Error("Could not save the payment method");
        return response.json();
    },
})
```

### Server-side code sample [#server-side-code-sample-1]

Replace the following values:

* `ACCESS-TOKEN`: Your access token.
* `BN-CODE`: Your PayPal Attribution ID. Platform integrations only.
* `AUTH-ASSERTION-JWT`: Your PayPal-Auth-Assertion token. Platform integrations only.
* `REQUEST-ID`: A unique alphanumeric string, such as a timestamp.
* `SETUP-TOKEN-ID`: The setup token ID from the previous step.

#### Platform integration

```bash
curl -v -X POST https://api-m.paypal.com/v3/vault/payment-tokens \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ACCESS-TOKEN' \
  -H 'PayPal-Partner-Attribution-Id: BN-CODE' \
  -H 'PayPal-Auth-Assertion: AUTH-ASSERTION-JWT' \
  -H 'PayPal-Request-Id: REQUEST-ID' \
  -d '{
    "payment_source": {
      "token": {
        "id": "SETUP-TOKEN-ID",
        "type": "SETUP_TOKEN"
      }
    }
  }'
```

#### Merchant integration

```bash
curl -v -X POST https://api-m.paypal.com/v3/vault/payment-tokens \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ACCESS-TOKEN' \
  -H 'PayPal-Request-Id: REQUEST-ID' \
  -d '{
    "payment_source": {
      "token": {
        "id": "SETUP-TOKEN-ID",
        "type": "SETUP_TOKEN"
      }
    }
  }'
```

### Payment token response [#payment-token-response]

A successful request returns HTTP `201`, or `200` for an idempotent request. Store the `id` (the payment token) and the `customer.id` (the PayPal-generated customer ID) in your system for future transactions. The Venmo button shows the payer's Venmo username from the `user_name` field.

The response includes the following links:

| Rel      | Method   | Description                                         |
| -------- | -------- | --------------------------------------------------- |
| `self`   | `GET`    | Retrieve data about the saved Venmo payment method. |
| `delete` | `DELETE` | Delete the payment token.                           |

```json
{
  "id": "hg654s1t",
  "customer": {
    "id": "BygeLlrpZF",
    "merchant_customer_id": "your-customer-id-123"
  },
  "payment_source": {
    "venmo": {
      "description": "Description for Venmo to be shown to Venmo payer",
      "email_address": "payer@example.com",
      "user_name": "johndoe",
      "account_id": "VYYFH3WJ4JPJQ",
      "shipping": {
        "name": {
          "full_name": "Firstname Lastname"
        },
        "address": {
          "address_line_1": "123 Main St.",
          "address_line_2": "Unit 1",
          "admin_area_2": "San Jose",
          "admin_area_1": "CA",
          "postal_code": "95131",
          "country_code": "US"
        }
      },
      "usage_pattern": "IMMEDIATE",
      "usage_type": "MERCHANT",
      "customer_type": "CONSUMER",
      "name": {
        "given_name": "Firstname",
        "surname": "Lastname"
      },
      "address": {
        "address_line_1": "123 Main St.",
        "address_line_2": "Unit 1",
        "admin_area_1": "CA",
        "admin_area_2": "San Jose",
        "postal_code": "95131",
        "country_code": "US"
      }
    }
  },
  "links": [
    {
      "rel": "self",
      "href": "https://api-m.paypal.com/v3/vault/payment-tokens/hg654s1t",
      "method": "GET",
      "encType": "application/json"
    },
    {
      "rel": "delete",
      "href": "https://api-m.paypal.com/v3/vault/payment-tokens/hg654s1t",
      "method": "DELETE",
      "encType": "application/json"
    }
  ]
}
```

## 8. Integrate the back end [#8-integrate-the-back-end]

The following sample is a complete back-end integration that saves Venmo for purchase later. The `PayPal-Partner-Attribution-Id` and `PayPal-Auth-Assertion` headers apply to platform integrations only. Omit them for merchant integrations. Set the `ACCESS_TOKEN` environment variable to your app's access token before you run the sample.

```js
import "dotenv/config";
import express from "express";
const { PORT = 8888, ACCESS_TOKEN } = process.env;
const app = express();
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(express.json());

// Create setup token
app.post("/create/setup/token", async (req, res) => {
  try {
    const vaultResponse = await fetch("https://api-m.paypal.com/v3/vault/setup-tokens", {
      method: "POST",
      body: JSON.stringify({
        payment_source: {
          venmo: {
            usage_type: "MERCHANT",
            experience_context: {
              return_url: "https://example.com/returnUrl",
              cancel_url: "https://example.com/cancelUrl"
            }
          }
        }
      }),
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${ACCESS_TOKEN}`,
        "PayPal-Request-Id": Date.now(),
        "PayPal-Partner-Attribution-Id": "BN-CODE",    // Platform only
        "PayPal-Auth-Assertion": "AUTH-ASSERTION-JWT"  // Platform only
      }
    });
    const vaultData = await vaultResponse.json();
    res.json(vaultData);
  } catch (err) {
    res.status(500).send(err.message);
  }
});

// Create payment token from a setup token
app.post("/create/payment/token", async (req, res) => {
  const { vaultSetupToken } = req.body;
  try {
    const paymentTokenResult = await fetch(
      "https://api-m.paypal.com/v3/vault/payment-tokens",
      {
        method: "POST",
        body: JSON.stringify({
          payment_source: {
            token: {
              id: vaultSetupToken,
              type: "SETUP_TOKEN"
            }
          }
        }),
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${ACCESS_TOKEN}`,
          "PayPal-Request-Id": Date.now(),
          "PayPal-Partner-Attribution-Id": "BN-CODE",     // Platform only
          "PayPal-Auth-Assertion": "AUTH-ASSERTION-JWT"   // Platform only
        }
      }
    );
    const paymentTokenData = await paymentTokenResult.json();
    const paymentMethodToken = paymentTokenData.id;
    const customerId = paymentTokenData.customer.id;
    await save(paymentMethodToken, customerId);
    res.json(paymentTokenData);
  } catch (err) {
    res.status(500).send(err.message);
  }
});

const save = async function(paymentMethodToken, customerId) {
  // Specify where to save the payment method token and customer ID
  // Associate these with the payer in your system
};

app.listen(PORT, () => {
  console.log(`Server listening at http://localhost:${PORT}/`);
});
```

## 9. Integrate the front end [#9-integrate-the-front-end]

The following sample is a complete front-end integration that saves Venmo for purchase later. The `enable-funding=venmo` parameter renders the Venmo button.

```html
<div id="venmo-buttons-container"></div>

<script
  src="https://www.paypal.com/sdk/js?client-id=CLIENT-ID&merchant-id=MERCHANT-ID&enable-funding=venmo"
  data-user-id-token="ID-TOKEN">
</script>

<script>
    window.paypal.Buttons({
        fundingSource: window.paypal.FUNDING.VENMO,
        createVaultSetupToken: async () => {
            const result = await fetch("/create/setup/token", {
                method: "POST",
            });
            const { id } = await result.json();
            return id;
        },
        onApprove: async ({ vaultSetupToken }) => {
            const response = await fetch("/create/payment/token", {
                method: "POST",
                headers: { "Content-Type": "application/json" },
                body: JSON.stringify({ vaultSetupToken })
            });
            if (!response.ok) throw new Error("Could not save the payment method");
            return response.json();
        },
        onError: (error) => {
            console.log("An error occurred: ", error);
        }
    }).render("#venmo-buttons-container");
</script>
```

## 10. Show saved payment methods [#10-show-saved-payment-methods]

Create a page on your site where payers can see their saved Venmo accounts. Show the Venmo username from the `user_name` field in the payment token response, so payers recognize which account is on file.

## Restrictions [#restrictions]

The following restrictions apply to saving Venmo accounts:

* **Desktop app switch:** Not available. On desktop, the SDK shows a QR code for the payer to approve in the Venmo app.
* **iframes:** Venmo checkout and vaulting can't render in an iframe.
* **Teen accounts:** Not supported. Teen accounts see an error message.

## Use JavaScript SDK v6 [#use-javascript-sdk-v6]

This guide covers JavaScript SDK v5. JavaScript SDK v6 uses a different client-side integration and returns different callback payloads. To save Venmo with v6, see [Save Venmo for purchase later with JavaScript SDK v6](/platforms/checkout/save-payment-methods/purchase-later/js-sdk/venmo-v6/).

## Next steps [#next-steps]

Continue with the following:

* [Test and go live](/api/rest/production/) with this integration.
* [Create orders](/api/orders/v2/orders-create) for subsequent or recurring transactions by referencing the saved payment token.
* [Get a payment token](/api/payment-tokens/v3#payment-tokens_get), [list all payment tokens](/api/payment-tokens/v3#payment-tokens_payment-tokens), or [delete a payment token](/api/payment-tokens/v3#payment-tokens_delete) with the Payment Method Tokens API.

## See also [#see-also]

* [Save Venmo for purchase later with JavaScript SDK v6](/platforms/checkout/save-payment-methods/purchase-later/js-sdk/venmo-v6/)
* [Save Venmo for purchase later with the Payment Method Tokens API](/platforms/checkout/save-payment-methods/purchase-later/payment-tokens-api/venmo/)
* [Save Venmo with the JavaScript SDK (save during purchase)](/platforms/checkout/save-payment-methods/during-purchase/js-sdk/venmo/)
