# Create a voucher payment method

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


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

Create a voucher payment method for the payment source.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/payment_sources/create_voucher_payment_source \
     -u {site_api_key}:\
     -d customer_id="__test__XpbTXGTSRp4Mg0Dr" \
     -d "voucher_payment_source[voucher_type]"="BOLETO" \
     -d "voucher_payment_source[tax_id]"="00000000000000" \
     -d "voucher_payment_source[gateway_account_id]"="gw_161my9TXG5oNYwgv" \
     -d "voucher_payment_source[billing_address]"='{"first_name":"John","last_name":"Doe","line1":"No 4 metro street","line2":"rio","country_code":"br","state_code":"ap","city":"rio","postal_code":"20080003","email":"johndoe@example.com"}'
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PaymentSource.CreateVoucherPaymentSource()
		.CustomerId("__test__XpbTXGTSRp4Mg0Dr")
		.VoucherPaymentSourceVoucherType(VoucherTypeEnum.Boleto)
		.VoucherPaymentSourceTaxId("00000000000000")
		.VoucherPaymentSourceGatewayAccountId("gw_161my9TXG5oNYwgv")
		.VoucherPaymentSourceBillingAddress("{\"first_name\":\"John\",\"last_name\":\"Doe\",\"line1\":\"No 4 metro street\",\"line2\":\"rio\",\"country_code\":\"br\",\"state_code\":\"ap\",\"city\":\"rio\",\"postal_code\":\"20080003\",\"email\":\"johndoe@example.com\"}")
		.Request();

Customer customer = result.Customer;
PaymentSource paymentSource = result.PaymentSource;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    paymentsourceAction "github.com/chargebee/chargebee-go/v3/actions/paymentsource"
    "github.com/chargebee/chargebee-go/v3/models/paymentsource"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := paymentsourceAction.CreateVoucherPaymentSource(&paymentsource.CreateVoucherPaymentSourceRequestParams{
        CustomerId : "__test__XpbTXGTSRp4Mg0Dr",
        VoucherPaymentSource : &paymentsource.CreateVoucherPaymentSourceVoucherPaymentSourceParams{
            VoucherType : enum.VoucherTypeBoleto,
            TaxId : "00000000000000",
            GatewayAccountId : "gw_161my9TXG5oNYwgv",
            BillingAddress : map[string]interface{}{
    "first_name" : "John",
    "last_name" : "Doe",
    "line1" : "No 4 metro street",
    "line2" : "rio",
    "country_code" : "br",
    "state_code" : "ap",
    "city" : "rio",
    "postal_code" : "20080003",
    "email" : "johndoe@example.com",
},
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        PaymentSource := res.PaymentSource
    }
}
```

#### 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.PaymentSourceCreateVoucherPaymentSourceRequest{
    CustomerId : "__test__XpbTXGTSRp4Mg0Dr",
    VoucherPaymentSource : &chargebee.PaymentSourceCreateVoucherPaymentSourceVoucherPaymentSource{
        VoucherType : chargebee.VoucherTypeBoleto,
        TaxId : "00000000000000",
        GatewayAccountId : "gw_161my9TXG5oNYwgv",
        BillingAddress : map[string]interface{}{
"first_name" : "John",
"last_name" : "Doe",
"line1" : "No 4 metro street",
"line2" : "rio",
"country_code" : "br",
"state_code" : "ap",
"city" : "rio",
"postal_code" : "20080003",
"email" : "johndoe@example.com",
},
    },
}
  res, err := client.PaymentSource.CreateVoucherPaymentSource(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        PaymentSource := res.PaymentSource
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;
import com.chargebee.org.json.JSONArray;
import com.chargebee.org.json.JSONObject;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = PaymentSource.createVoucherPaymentSource()
            .customerId("__test__XpbTXGTSRp4Mg0Dr")
            .voucherPaymentSourceVoucherType(VoucherType.BOLETO)
            .voucherPaymentSourceTaxId("00000000000000")
            .voucherPaymentSourceGatewayAccountId("gw_161my9TXG5oNYwgv")
            .voucherPaymentSourceBillingAddress(new JSONObject("{\"first_name\":\"John\",\"last_name\":\"Doe\",\"line1\":\"No 4 metro street\",\"line2\":\"rio\",\"country_code\":\"br\",\"state_code\":\"ap\",\"city\":\"rio\",\"postal_code\":\"20080003\",\"email\":\"johndoe@example.com\"}"))
            .request();

        Customer customer = result.customer();
        PaymentSource paymentSource = result.paymentSource();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.paymentSource.PaymentSource;
import com.chargebee.v4.models.paymentSource.params.CreateVoucherPaymentSourceParams;
import com.chargebee.v4.models.paymentSource.responses.CreateVoucherPaymentSourceResponse;
import java.util.List;
import java.util.Map;

public class CreateVoucherPaymentSource {

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

        CreateVoucherPaymentSourceParams.VoucherPaymentSourceParams voucherPaymentSourceParams =
            CreateVoucherPaymentSourceParams.VoucherPaymentSourceParams.builder()
                .voucherType(CreateVoucherPaymentSourceParams.VoucherPaymentSourceParams.VoucherType.BOLETO)
                .taxId("00000000000000")
                .gatewayAccountId("gw_161my9TXG5oNYwgv")
                .billingAddress(Map.of("first_name", "John", "last_name", "Doe", "line1", "No 4 metro street", "line2", "rio", "country_code", "br", "state_code", "ap", "city", "rio", "postal_code", "20080003", "email", "johndoe@example.com"))
                .build();

        CreateVoucherPaymentSourceParams params = CreateVoucherPaymentSourceParams.builder()
            .customerId("__test__XpbTXGTSRp4Mg0Dr")
            .voucherPaymentSource(voucherPaymentSourceParams)
            .build();

        CreateVoucherPaymentSourceResponse response = client.paymentSources().createVoucherPaymentSource(params);

        Customer customer = response.getCustomer();
        PaymentSource paymentSource = response.getPaymentSource();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.paymentSource.createVoucherPaymentSource({
        customer_id: "__test__XpbTXGTSRp4Mg0Dr",
        voucher_payment_source: {
            voucher_type: "boleto",
            tax_id: "00000000000000",
            gateway_account_id: "gw_161my9TXG5oNYwgv",
            billing_address: "{\"first_name\":\"John\",\"last_name\":\"Doe\",\"line1\":\"No 4 metro street\",\"line2\":\"rio\",\"country_code\":\"br\",\"state_code\":\"ap\",\"city\":\"rio\",\"postal_code\":\"20080003\",\"email\":\"johndoe@example.com\"}"
        }
    });

    console.log(result);
    const customer = result.customer;
    const paymentSource = result.payment_source;
} 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->paymentSource()->createVoucherPaymentSource([
    "customer_id" => "__test__XpbTXGTSRp4Mg0Dr",
    "voucher_payment_source" => [
        "voucher_type" => "boleto",
        "tax_id" => "00000000000000",
        "gateway_account_id" => "gw_161my9TXG5oNYwgv",
        "billing_address" => "{\"first_name\":\"John\",\"last_name\":\"Doe\",\"line1\":\"No 4 metro street\",\"line2\":\"rio\",\"country_code\":\"br\",\"state_code\":\"ap\",\"city\":\"rio\",\"postal_code\":\"20080003\",\"email\":\"johndoe@example.com\"}"
    ]
]);
$customer = $result->customer;
$paymentSource = $result->payment_source;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.PaymentSource.create_voucher_payment_source(
    cb_client.PaymentSource.CreateVoucherPaymentSourceParams(
        customer_id="__test__XpbTXGTSRp4Mg0Dr",
        voucher_payment_source=cb_client.PaymentSource.CreateVoucherPaymentSourceVoucherPaymentSourceParams(
            voucher_type=chargebee.VoucherType.BOLETO,
            tax_id="00000000000000",
            gateway_account_id="gw_161my9TXG5oNYwgv",
            billing_address='{"first_name":"John","last_name":"Doe","line1":"No 4 metro street","line2":"rio","country_code":"br","state_code":"ap","city":"rio","postal_code":"20080003","email":"johndoe@example.com"}'
        )
    )
)
customer = response.customer
payment_source = response.payment_source
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::PaymentSource.create_voucher_payment_source({
  :customer_id => "__test__XpbTXGTSRp4Mg0Dr",
  :voucher_payment_source => {
    :voucher_type => "BOLETO",
    :tax_id => "00000000000000",
    :gateway_account_id => "gw_161my9TXG5oNYwgv",
    :billing_address => "{\"first_name\":\"John\",\"last_name\":\"Doe\",\"line1\":\"No 4 metro street\",\"line2\":\"rio\",\"country_code\":\"br\",\"state_code\":\"ap\",\"city\":\"rio\",\"postal_code\":\"20080003\",\"email\":\"johndoe@example.com\"}"
  }
})

customer = result.customer
payment_source = result.payment_source
```

## Sample Response

```json
{
  "payment_source": {
    "id": "pm_HmhZXuiTcB6bEh1K9s",
    "updated_at": 1682183992,
    "resource_version": 1682183992360,
    "deleted": false,
    "object": "payment_source",
    "customer_id": "__test__XpbTXGTSRp4Mg0Dr",
    "type": "boleto",
    "reference_id": "cus_NlGdeYYqRj9ca9/pm_1Mzk6GK7ilSfRo7vhZxk82n8",
    "status": "valid",
    "gateway": "stripe",
    "gateway_account_id": "gw_161my9TXG5oNYwgv",
    "created_at": 1682183992,
    "boleto": {
      "last4": "0000",
      "first_name": "John",
      "last_name": "Doe",
      "email": "johndoe@example.com",
      "object": "cust_voucher_source"
    },
    "billing_address": {
      "line1": "No 4 metro street",
      "line2": "rio street",
      "city": "rio",
      "state_code": "ap",
      "validation_status": "not_validated",
      "object": "billing_address"
    },
    "business_entity_id": "org1"
  },
  "customer": {
    "id": "__test__XpbTXGTSRp4Mg0Dr",
    "first_name": "John",
    "last_name": "Doe",
    "email": "johndoe2@example.com",
    "auto_collection": "off",
    "offline_payment_method": "no_preference",
    "net_term_days": 0,
    "allow_direct_debit": false,
    "created_at": 1682180803,
    "taxability": "taxable",
    "updated_at": 1682183992,
    "pii_cleared": "active",
    "channel": "web",
    "resource_version": 1682183992357,
    "deleted": false,
    "object": "customer",
    "card_status": "no_card",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "excess_payments": 0,
    "unbilled_charges": 0,
    "preferred_currency_code": "BRL",
    "business_entity_id": "org1"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/payment_sources/create_voucher_payment_source

## Input Parameters

- `customer_id` (required, string, max chars=50)
  Identifier of the customer with whom this payment source is associated.

- `brand_id` (optional, string, max chars=50)
  The unique ID of the [brand](/docs/api/brands) this payment source should be linked to. Applicable only when multiple brands have been created for the site. This need not match the brand of the `customer_id`; when the two differ, the value provided here is used for the payment source. An alternative way of passing this parameter is by means of the `chargebee-brand-id` custom HTTP header; when both are provided, they must specify the same brand.
  
  **Default behavior**
  
  -   When not provided, the payment source is linked to the brand of the customer it is created for.

- `voucher_payment_source` (optional, enumerated string)
  Parameters for voucher\_payment\_source
  - `voucher_type` (required, enumerated string)
    Voucher based payment methods
    Possible enum values:
      - `boleto`
        Boleto
  - `gateway_account_id` (optional, string, max chars=50)
    The gateway account to which the payment method is associated.
  - `tax_id` (optional, string, max chars=20)
    Customer Tax id
  - `billing_address` (optional, jsonobject)
    The billing address of the customer. The value is a JSON object with the following keys and their values:- `first_name`:(string, max chars=150) The first name of the contact.
    
    -   `last_name`:(string, max chars=150) The last name of the contact.
    -   `line1`:(string, max chars=180) The first line of the address.
    -   `line2`:(string, max chars=180) The second line of the address.
    -   `country_code`:(string, max chars=50) The two-letter, [ISO 3166 alpha-2](https://www.iso.org/iso-3166-country-codes.html) country code for the address.
    -   `state_code`:(string, max chars=50) The [ISO 3166-2 state/province code](https://www.iso.org/obp/ui/#search/code/) without the country prefix.For instance, for Arizona (USA), set state\_code as `AZ` (not `US-AZ`). For Tamil Nadu (India), set as `TN` (not `IN-TN`). For British Columbia (Canada), set as `BC` (not `CA-BC)`.
    -   `city`:(string, max chars=50) The city name for the address.
    -   `postal_code`:(string, max chars=20) The postal or ZIP code for the address.
    -   `phone`:(string, max chars=50) The contact phone number for the address.
    -   `email`:(string, max chars=70) The contact email address for the address.

## Returns

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

- `payment_source` (Payment source object)
  Resource object representing payment\_source
