# Create a voucher for the customer to initiate payment

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


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

Creates a voucher type payment source. If you create this voucher type payment source using customer details, like tax ID, you can then generate a voucher with that payment source.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/payment_vouchers \
     -u {site_api_key}:\
     -d customer_id="__test__XpbTXGTSRp4Mg0Dr" \
     -d "voucher_payment_source[voucher_type]"="BOLETO" \
     -d payment_source_id="pm___dev__8asu4TZd0GfCJs" \
     -d "invoice_allocations[invoice_id][0]"="__demo_inv__27"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PaymentVoucher.Create()
		.CustomerId("__test__XpbTXGTSRp4Mg0Dr")
		.VoucherPaymentSourceVoucherType(VoucherTypeEnum.Boleto)
		.PaymentSourceId("pm___dev__8asu4TZd0GfCJs")
		.InvoiceAllocationInvoiceId(0, "__demo_inv__27")
		.Request();

PaymentVoucher paymentVoucher = result.PaymentVoucher;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    paymentvoucherAction "github.com/chargebee/chargebee-go/v3/actions/paymentvoucher"
    "github.com/chargebee/chargebee-go/v3/models/paymentvoucher"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := paymentvoucherAction.Create(&paymentvoucher.CreateRequestParams{
        InvoiceAllocations : []*paymentvoucher.CreateInvoiceAllocationParams{
            {
                InvoiceId : "__demo_inv__27",
            },
        },
        CustomerId : "__test__XpbTXGTSRp4Mg0Dr",
        VoucherPaymentSource : &paymentvoucher.CreateVoucherPaymentSourceParams{
            VoucherType : enum.VoucherTypeBoleto,
        },
        PaymentSourceId : "pm___dev__8asu4TZd0GfCJs",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        PaymentVoucher := res.PaymentVoucher
    }
}
```

#### 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.PaymentVoucherCreateRequest{
    InvoiceAllocations : []*chargebee.PaymentVoucherCreateInvoiceAllocation{
        {
            InvoiceId : "__demo_inv__27",
        },
    },
    CustomerId : "__test__XpbTXGTSRp4Mg0Dr",
    VoucherPaymentSource : &chargebee.PaymentVoucherCreateVoucherPaymentSource{
        VoucherType : chargebee.VoucherTypeBoleto,
    },
    PaymentSourceId : "pm___dev__8asu4TZd0GfCJs",
}
  res, err := client.PaymentVoucher.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        PaymentVoucher := res.PaymentVoucher
    }
}
```

#### 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 = PaymentVoucher.create()
            .customerId("__test__XpbTXGTSRp4Mg0Dr")
            .voucherPaymentSourceVoucherType(VoucherType.BOLETO)
            .paymentSourceId("pm___dev__8asu4TZd0GfCJs")
            .invoiceAllocationInvoiceId(0, "__demo_inv__27")
            .request();

        PaymentVoucher paymentVoucher = result.paymentVoucher();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.paymentVoucher.PaymentVoucher;
import com.chargebee.v4.models.paymentVoucher.params.PaymentVoucherCreateParams;
import com.chargebee.v4.models.paymentVoucher.responses.PaymentVoucherCreateResponse;
import java.util.List;

public class PaymentVoucherCreate {

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

        PaymentVoucherCreateParams.VoucherPaymentSourceParams voucherPaymentSourceParams =
            PaymentVoucherCreateParams.VoucherPaymentSourceParams.builder()
                .voucherType(PaymentVoucherCreateParams.VoucherPaymentSourceParams.VoucherType.BOLETO)
                .build();

        PaymentVoucherCreateParams.InvoiceAllocationsParams invoiceAllocation0 =
            PaymentVoucherCreateParams.InvoiceAllocationsParams.builder()
                .invoiceId("__demo_inv__27")
                .build();

        List<PaymentVoucherCreateParams.InvoiceAllocationsParams> invoiceAllocationsList =
            List.of(invoiceAllocation0);

        PaymentVoucherCreateParams params = PaymentVoucherCreateParams.builder()
            .customerId("__test__XpbTXGTSRp4Mg0Dr")
            .voucherPaymentSource(voucherPaymentSourceParams)
            .paymentSourceId("pm___dev__8asu4TZd0GfCJs")
            .invoiceAllocations(invoiceAllocationsList)
            .build();

        PaymentVoucherCreateResponse response = client.paymentVouchers().create(params);

        PaymentVoucher paymentVoucher = response.getPaymentVoucher();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.paymentVoucher.create({
        invoice_allocations: [
            {
                invoice_id: "__demo_inv__27"
            }
        ],
        customer_id: "__test__XpbTXGTSRp4Mg0Dr",
        voucher_payment_source: {
            voucher_type: "boleto"
        },
        payment_source_id: "pm___dev__8asu4TZd0GfCJs"
    });

    console.log(result);
    const paymentVoucher = result.payment_voucher;
} 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->paymentVoucher()->create([
    "invoice_allocations" => [
        [
            "invoice_id" => "__demo_inv__27"
        ]
    ],
    "customer_id" => "__test__XpbTXGTSRp4Mg0Dr",
    "voucher_payment_source" => [
        "voucher_type" => "boleto"
    ],
    "payment_source_id" => "pm___dev__8asu4TZd0GfCJs"
]);
$paymentVoucher = $result->payment_voucher;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.PaymentVoucher.create(
    cb_client.PaymentVoucher.CreateParams(
        invoice_allocations=[
            cb_client.PaymentVoucher.CreateInvoiceAllocationParams(
              invoice_id="__demo_inv__27"
            )
        ],
        customer_id="__test__XpbTXGTSRp4Mg0Dr",
        voucher_payment_source=cb_client.PaymentVoucher.CreateVoucherPaymentSourceParams(
            voucher_type=chargebee.VoucherType.BOLETO
        ),
        payment_source_id="pm___dev__8asu4TZd0GfCJs"
    )
)
payment_voucher = response.payment_voucher
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::PaymentVoucher.create({
  :customer_id => "__test__XpbTXGTSRp4Mg0Dr",
  :voucher_payment_source => {
    :voucher_type => "BOLETO"
  },
  :payment_source_id => "pm___dev__8asu4TZd0GfCJs",
  :invoice_allocations => [
    {
      :invoice_id => "__demo_inv__27"
    }
  ]
})

payment_voucher = result.payment_voucher
```

## Sample Response

```json
{
  "payment_voucher": {
    "id": "pv_1mG11S1TcNM88A9Zm",
    "id_at_gateway": "pi_3N0VBuK7ilSfRo7v0D66epcC",
    "payment_voucher_type": "boleto",
    "expires_at": 1682365190,
    "status": "active",
    "amount": 17800,
    "gateway_account_id": "gw_161my9TXG5oNYwgv",
    "payment_source_id": "pm_1mG11S1TcNM3LP9ZX",
    "gateway": "stripe",
    "payload": "{\"url\":\"https://payments.stripe.com/boleto/voucher/test_YWNjdF8xTHZnMFRLN2lsU2ZSbzd2LF9ObTNJN2NoejBsYldJeDI0VTVxemkwbnJaZUVTN0FH0100PvfYwtjd\",\"voucher_number\":\"01010101010101010101010101010101010101010101010\",\"expiry\":\"1682365190\"}",
    "url": "http://john.chargebee.com/pages/v3/__dev__w5aPBsoEK5z6kIEt2mrEIH9GWLliHXrN/view_voucher",
    "date": 1682365010,
    "updated_at": 1682365010,
    "resource_version": 1682365010580,
    "object": "payment_voucher",
    "currency_code": "BRL",
    "customer_id": "test_d23ed22ew",
    "linked_invoices": [
      {
        "invoice_id": "61",
        "date": 1682364955,
        "total": 17800,
        "status": "payment_due"
      },
      {..}
    ]
  }
}
```

## URL Format

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

## Input Parameters

- `customer_id` (required, string, max chars=50)
  The unique identifier of the customer for whom you want to create the voucher.

- `payment_source_id` (optional, string, max chars=40)
  The identifier of the payment source used for generating the voucher.

- `voucher_payment_source` (optional, enumerated string)
  Parameters for voucher\_payment\_source
  - `voucher_type` (required, enumerated string)
    The type of voucher-based payment source.
    Possible enum values:
      - `boleto`
        The payment source is Boleto.

- `invoice_allocations` (optional, array)
  Parameters for `invoice_allocations`
  - `invoice_id` (required, string, max chars=50)
    The unique identifier of the invoice. You can pass multiple invoices IDs.

## Returns

- `payment_voucher` (Payment voucher object)
  Resource object representing payment\_voucher
