# Apply payment schedule scheme to an invoice

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


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

Applying a payment schedule scheme to an invoice creates payment schedules, enabling the invoice to be paid in multiple, scheduled payments.

**Note:** The invoice must be in `payment_due` .

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/invoices/__demo_inv__4/apply_payment_schedule_scheme \
     -u {site_api_key}:\
     -d scheme_id="HmeBDXhU50lPuS3i0" \
     -d amount=100000
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Invoice.ApplyPaymentScheduleScheme("__demo_inv__4")
		.SchemeId("HmeBDXhU50lPuS3i0")
		.Amount(100000)
		.Request();

Invoice invoice = result.Invoice;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    invoiceAction "github.com/chargebee/chargebee-go/v3/actions/invoice"
    "github.com/chargebee/chargebee-go/v3/models/invoice"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := invoiceAction.ApplyPaymentScheduleScheme("__demo_inv__4", &invoice.ApplyPaymentScheduleSchemeRequestParams{
        SchemeId : "HmeBDXhU50lPuS3i0",
        Amount : chargebee.Int64(100000),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
    }
}
```

#### 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.InvoiceApplyPaymentScheduleSchemeRequest{
    SchemeId : "HmeBDXhU50lPuS3i0",
    Amount : chargebee.Int64(100000),
}
  res, err := client.Invoice.ApplyPaymentScheduleScheme("__demo_inv__4", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
    }
}
```

#### 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 = Invoice.applyPaymentScheduleScheme("__demo_inv__4")
            .schemeId("HmeBDXhU50lPuS3i0")
            .amount(100000L)
            .request();

        Invoice invoice = result.invoice();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.invoice.params.InvoiceApplyPaymentScheduleSchemeParams;
import com.chargebee.v4.models.invoice.responses.InvoiceApplyPaymentScheduleSchemeResponse;

public class InvoiceApplyPaymentScheduleScheme {

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

        InvoiceApplyPaymentScheduleSchemeParams params = InvoiceApplyPaymentScheduleSchemeParams.builder()
            .schemeId("HmeBDXhU50lPuS3i0")
            .amount(100000L)
            .build();

        InvoiceApplyPaymentScheduleSchemeResponse response = client
            .invoices()
            .applyPaymentScheduleScheme("__demo_inv__4", params);

        Invoice invoice = response.getInvoice();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.invoice.applyPaymentScheduleScheme("__demo_inv__4", {
        scheme_id: "HmeBDXhU50lPuS3i0",
        amount: 100000
    });

    console.log(result);
    const invoice = result.invoice;
} 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->invoice()->applyPaymentScheduleScheme("__demo_inv__4", [
    "scheme_id" => "HmeBDXhU50lPuS3i0",
    "amount" => 100000
]);
$invoice = $result->invoice;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Invoice.apply_payment_schedule_scheme("__demo_inv__4",
    cb_client.Invoice.ApplyPaymentScheduleSchemeParams(
        scheme_id="HmeBDXhU50lPuS3i0",
        amount=100000
    )
)
invoice = response.invoice
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Invoice.apply_payment_schedule_scheme("__demo_inv__4",{
  :scheme_id => "HmeBDXhU50lPuS3i0",
  :amount => 100000
})

invoice = result.invoice
```

## Sample Response

```json
{
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 0,
    "amount_paid": 1000,
    "amount_to_collect": 0,
    "applied_credits": {},
    "base_currency_code": "USD",
    "billing_address": {
      "first_name": "Rachel",
      "last_name": "Green",
      "object": "billing_address",
      "validation_status": "not_validated"
    },
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__8asxfSOcTzpo2s",
    "date": 1612796839,
    "deleted": false,
    "due_date": 1612796839,
    "dunning_attempts": [
      {
        "attempt": 0,
        "created_at": 1612796840,
        "dunning_type": "auto_collect",
        "retry_engine": "chargebee",
        "transaction_id": "txn___test__8asxfSOcU2Ku3v",
        "txn_amount": 1000,
        "txn_status": "failure"
      },
      {..}
    ],
    "dunning_status": "stopped",
    "exchange_rate": 1,
    "first_invoice": false,
    "has_advance_charges": false,
    "id": "__demo_inv__4",
    "is_gifted": false,
    "issued_credit_notes": {},
    "line_items": [
      {
        "amount": 1000,
        "customer_id": "__test__8asxfSOcTzpo2s",
        "date_from": 1612796839,
        "date_to": 1612883239,
        "description": "Basic USD 2",
        "discount_amount": 0,
        "entity_id": "basic-USD2",
        "entity_type": "plan_item_price",
        "id": "li___test__8asxfSOcU2D83u",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "per_unit",
        "quantity": 1,
        "subscription_id": "__test__8asxfSOcTzpo2s",
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 1000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": [
      {
        "applied_amount": 1000,
        "applied_at": 1517490444,
        "txn_amount": 1000,
        "txn_date": 1517490444,
        "txn_id": "txn___test__8asyKSOcU2bm5W",
        "txn_status": "success"
      },
      {..}
    ],
    "net_term_days": 0,
    "object": "invoice",
    "paid_at": 1517490444,
    "price_type": "tax_exclusive",
    "recurring": true,
    "resource_version": 1517490444979,
    "round_off_amount": 0,
    "status": "paid",
    "sub_total": 1000,
    "subscription_id": "__test__8asxfSOcTzpo2s",
    "tax": 0,
    "term_finalized": true,
    "total": 1000,
    "updated_at": 1517490444,
    "write_off_amount": 0
  },
  "transaction": {
    "amount": 1000,
    "amount_unused": 0,
    "base_currency_code": "USD",
    "currency_code": "USD",
    "customer_id": "__test__8asxfSOcTzpo2s",
    "date": 1517490444,
    "deleted": false,
    "exchange_rate": 1,
    "gateway": "chargebee",
    "gateway_account_id": "gw___test__8asxfSOcTyhc1y",
    "id": "txn___test__8asyKSOcU2bm5W",
    "id_at_gateway": "cb___test__8asyKSOcU2bq5X",
    "linked_invoices": [
      {
        "applied_amount": 1000,
        "applied_at": 1517490444,
        "invoice_date": 1612796839,
        "invoice_id": "__demo_inv__4",
        "invoice_status": "paid",
        "invoice_total": 1000
      },
      {..}
    ],
    "linked_refunds": {},
    "masked_card_number": "***********0005",
    "object": "transaction",
    "payment_method": "card",
    "payment_source_id": "pm___test__8asyKSOcU2Zm5P",
    "resource_version": 1517490444979,
    "status": "success",
    "subscription_id": "__test__8asxfSOcTzpo2s",
    "type": "payment",
    "updated_at": 1517490444
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/invoices/{invoice-id}/apply_payment_schedule_scheme

## Input Parameters

- `scheme_id` (required, string)
  The identifier of the `payment_schedule_scheme` , used to create the payment schedules.

- `amount` (optional, in cents, min=0)
  The part of the `invoice.amount_due` to be distributed across the payment schedules. If not specified, the entire `invoice.amount_due` is considered by default.

## Returns

- `invoice` (Invoice object)
  Resource object representing invoice
