# Create a virtual bank account using permanent token

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

Creates a virtual bank account (VBA) for a [customer](/docs/api/customers) using a [permanent token](https://www.chargebee.com/docs/payments/2.0/payment-gateways-and-configuration/stripe-automated-bank-transfer#supported-token-formats) obtained from a payment gateway.

Use this operation when you have already created a payment source at the gateway and obtained a permanent token (reference ID) for it.

### Prerequisites & Constraints

-   The customer must not already have an active VBA for the same [`scheme`](/docs/api/virtual_bank_accounts#scheme). For example, if the customer already has a VBA with `scheme` set to `us_automated_bank_transfer`, you cannot create another VBA with the same scheme.

### Impacts

**

Virtual bank account

**

-   A new virtual bank account resource is created and associated with the customer. The virtual bank account includes details such as bank account number, routing number (or IBAN), bank name, and other payment instructions retrieved from the gateway using the provided reference ID.
-   The [email address](/docs/api/virtual_bank_accounts#email) for the VBA is set at the gateway from the [`customer.email`](/docs/api/customers#email) attribute. Later, if the email address is updated for the customer, the email address for the VBA is also updated.

### Implementation Notes

-   Check if the customer already has a virtual bank account for the same scheme by calling the [List virtual bank accounts API](/docs/api/virtual_bank_accounts/list-virtual-bank-accounts) with the [customer ID](/docs/api/customers/list-customers#list_customers_id) filter. If a virtual bank account exists for the same scheme, the API returns a `payment_method_already_exists` error.
    
-   Validate that the required currency for the scheme is enabled. Use the [List currencies API](/docs/api/currencies/list-currencies) to check if the currency is enabled.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/virtual_bank_accounts/create_using_permanent_token \
     -u {site_api_key}:\
     -d customer_id="__test__KyVnHhSBWSv7Y5F" \
     -d reference_id="cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = VirtualBankAccount.CreateUsingPermanentToken()
		.CustomerId("__test__KyVnHhSBWSv7Y5F")
		.ReferenceId("cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax")
		.Request();

VirtualBankAccount virtualBankAccount = result.VirtualBankAccount;
Customer customer = result.Customer;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    virtualbankaccountAction "github.com/chargebee/chargebee-go/v3/actions/virtualbankaccount"
    "github.com/chargebee/chargebee-go/v3/models/virtualbankaccount"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := virtualbankaccountAction.CreateUsingPermanentToken(&virtualbankaccount.CreateUsingPermanentTokenRequestParams{
        CustomerId : "__test__KyVnHhSBWSv7Y5F",
        ReferenceId : "cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        VirtualBankAccount := res.VirtualBankAccount
        Customer := res.Customer
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.VirtualBankAccountCreateUsingPermanentTokenRequest{
    CustomerId : "__test__KyVnHhSBWSv7Y5F",
    ReferenceId : "cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax",
}
  res, err := client.VirtualBankAccount.CreateUsingPermanentToken(req)
      if err != nil {
        fmt.Println(err)
    } else {
        VirtualBankAccount := res.VirtualBankAccount
        Customer := res.Customer
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = VirtualBankAccount.createUsingPermanentToken()
            .customerId("__test__KyVnHhSBWSv7Y5F")
            .referenceId("cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax")
            .request();

        VirtualBankAccount virtualBankAccount = result.virtualBankAccount();
        Customer customer = result.customer();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.virtualBankAccount.VirtualBankAccount;
import com.chargebee.v4.models.virtualBankAccount.params.VirtualBankAccountCreateUsingPermanentTokenParams;
import com.chargebee.v4.models.virtualBankAccount.responses.VirtualBankAccountCreateUsingPermanentTokenResponse;

public class VirtualBankAccountCreateUsingPermanentToken {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        VirtualBankAccountCreateUsingPermanentTokenParams params = VirtualBankAccountCreateUsingPermanentTokenParams.builder()
            .customerId("__test__KyVnHhSBWSv7Y5F")
            .referenceId("cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax")
            .build();

        VirtualBankAccountCreateUsingPermanentTokenResponse response = client.virtualBankAccounts().createUsingPermanentToken(params);

        VirtualBankAccount virtualBankAccount = response.getVirtualBankAccount();
        Customer customer = response.getCustomer();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.virtualBankAccount.createUsingPermanentToken({
        customer_id: "__test__KyVnHhSBWSv7Y5F",
        reference_id: "cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax"
    });

    console.log(result);
    const virtualBankAccount = result.virtual_bank_account;
    const customer = result.customer;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->virtualBankAccount()->createUsingPermanentToken([
    "customer_id" => "__test__KyVnHhSBWSv7Y5F",
    "reference_id" => "cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax"
]);
$virtualBankAccount = $result->virtual_bank_account;
$customer = $result->customer;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.VirtualBankAccount.create_using_permanent_token(
    cb_client.VirtualBankAccount.CreateUsingPermanentTokenParams(
        customer_id="__test__KyVnHhSBWSv7Y5F",
        reference_id="cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax"
    )
)
virtual_bank_account = response.virtual_bank_account
customer = response.customer
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::VirtualBankAccount.create_using_permanent_token({
  :customer_id => "__test__KyVnHhSBWSv7Y5F",
  :reference_id => "cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax"
})

virtual_bank_account = result.virtual_bank_account
customer = result.customer
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "billing_address": {
      "city": "Walnut",
      "country": "US",
      "first_name": "Mark",
      "last_name": "Henry",
      "line1": "PO Box 9999",
      "object": "billing_address",
      "state": "California",
      "state_code": "CA",
      "validation_status": "not_validated",
      "zip": "91789"
    },
    "card_status": "no_card",
    "created_at": 1517501394,
    "deleted": false,
    "email": "apple@apple.com",
    "excess_payments": 0,
    "first_name": "Mark",
    "id": "__test__KyVnHhSBWSv7Y5F",
    "last_name": "Henry",
    "net_term_days": 0,
    "object": "customer",
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517501395000,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517501395
  },
  "virtual_bank_account": {
    "account_number": "test_544b835aab71",
    "bank_name": "TEST BANK",
    "created_at": 1517501395,
    "customer_id": "__test__KyVnHhSBWSv7Y5F",
    "deleted": false,
    "email": "apple@apple.com",
    "gateway": "stripe",
    "gateway_account_id": "gw___test__KyVnGlSBWSv3GHt",
    "id": "vba___test__KyVnHhSBWSvqH5J",
    "object": "virtual_bank_account",
    "reference_id": "cus_I57FgHUl6NNqeT/src_1HUx14Jv9j0DyntJqopyd9ax",
    "resource_version": 1517501395000,
    "routing_number": "110000000",
    "scheme": "ach_credit",
    "swift_code": "TSTEZ122",
    "updated_at": 1517501395
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/virtual_bank_accounts/create_using_permanent_token

## Input Parameters

- `customer_id` (required, string, max chars=50)
  The unique identifier of the [customer](/docs/api/customers) for whom you want to create a virtual bank account.

- `reference_id` (required, string, max chars=150)
  The identifier (permanent token) used to fetch the payment source details from the gateway. For example, in Stripe it may be only the Stripe Customer ID (for example, cus\_63MnDn0t6kfDW7), or a combination of Stripe Customer ID and Stripe Source ID separated by a forward slash (for example, cus\_63MnDn0t6kfDW7/src\_6WjCF20vT9WN1G).
  
  **Constraints**
  
  -   If `gateway_account_id` is provided, the `reference_id` must belong to the gateway account.
  -   If the `gateway_account_id` is not provided, the `reference_id` must belong to the gateway account selected based on the [gateway routing rules](https://www.chargebee.com/docs/payments/2.0/payment-gateways-and-configuration/gateway_settings#smart-routing) for the payment method type and currency combination.

- `gateway_account_id` (optional, string, max chars=50)
  Identifier of the payment gateway account to use when creating the virtual bank account.
  
  **Default behavior** When not provided, Chargebee selects an applicable gateway account for the chosen `scheme`. Selection follows your site's [Smart Routing](https://www.chargebee.com/docs/payments/2.0/payment-gateways-and-configuration/gateway_settings#smart-routing) rules.

- `scheme` (optional, enumerated string, default=ach_credit)
  The type of automated bank transfer scheme for the virtual bank account.
  
  **Prerequisites**
  
  -   If billing address validation is enabled for your site, the customer must have a billing address with a country code.
  Possible enum values:
    - `ach_credit`
      **Deprecated**
      
      -   This scheme is deprecated. Use `us_automated_bank_transfer` instead.
      
      ACH Credit Transfer scheme for US-based customers.
    - `sepa_credit`
      **Deprecated**
      
      -   This scheme is deprecated. Use `eu_automated_bank_transfer` instead.
      
      SEPA Credit Transfer scheme for customers in the European Union.
    - `us_automated_bank_transfer`
      US Automated Bank Transfer scheme for US-based customers.
      
      **Prerequisites**
      
      -   USD currency must be [enabled](https://www.chargebee.com/docs/billing/2.0/site-configuration/multi-currency-pricing) for the site.
      -   The customer's [`billing_address.country`](/docs/api/customers#billing_address_country) must be `US`.
      
      US Automated Bank Transfer
    - `gb_automated_bank_transfer`
      UK Automated Bank Transfer scheme for UK-based customers.
      
      **Prerequisites**
      
      -   GBP currency must be [enabled](https://www.chargebee.com/docs/billing/2.0/site-configuration/multi-currency-pricing) for the site.
      -   The customer's [`billing_address.country`](/docs/api/customers#billing_address_country) must be `GB`.
    - `eu_automated_bank_transfer`
      EU Automated Bank Transfer scheme for customers in the European Union.
      
      **Prerequisites**
      
      -   EUR currency must be [enabled](https://www.chargebee.com/docs/billing/2.0/site-configuration/multi-currency-pricing) for the site.
      -   The customer's [`billing_address.country`](/docs/api/customers#billing_address_country) must be in a SEPA-supported region.
    - `jp_automated_bank_transfer`
      Japan Automated Bank Transfer scheme for Japan-based customers.
      
      **Prerequisites**
      
      -   JPY currency must be [enabled](https://www.chargebee.com/docs/billing/2.0/site-configuration/multi-currency-pricing) for the site.
      -   The customer's [`billing_address.country`](/docs/api/customers#billing_address_country) must be `JP`.
    - `mx_automated_bank_transfer`
      Mexico Automated Bank Transfer scheme for Mexico-based customers.
      
      **Prerequisites**
      
      -   MXN currency must be [enabled](https://www.chargebee.com/docs/billing/2.0/site-configuration/multi-currency-pricing) for the site.
      -   The customer's [`billing_address.country`](/docs/api/customers#billing_address_country) must be `MX`.

## Returns

- `virtual_bank_account` (Virtual bank account object)
  Resource object representing virtual\_bank\_account

- `customer` (Customer object)
  Resource object representing customer
