# Remove payment from an invoice

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


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

Removes a [payment](/docs/api/invoices/apply-payments-for-an-invoice) [transaction](/docs/api/invoices) that was applied to an invoice and moves the amount to the customer's excess payments balance.

This API does not refund the payment to the customer. To refund a payment transaction, use one of the following APIs:

-   For online payments, use [Refund a payment](/docs/api/transactions/refund-a-payment).
-   For offline payments, use [Record an offline refund](/docs/api/transactions/record-an-offline-refund).

### Prerequisites & Constraints

-   The invoice must not have any refunds or refundable credits issued. Specifically, there must be no [`issued_credit_notes`](/docs/api/invoices/invoice-object#issued_credit_notes) with a `cn_status` value of `refunded` or `refund_due` for the invoice.
-   The specified transaction must be linked to the invoice. It must match one of the [`linked_payments[].txn_id`](#invoice_linked_payments) for the invoice.
-   The [`status`](/docs/api/transactions/transaction-object#status) of the transaction must be `success`, `in_progress`, or `needs_attention`.

### Impacts

**

Invoice

**

-   The [`amount_due`](/docs/api/invoices/invoice-object#amount_due) on the invoice increases by the amount of the removed payment.
-   If the invoice [status](/docs/api/invoices/invoice-object#status) was `payment_due`, `not_paid`, or `posted`, the status does not change after a payment is removed.
-   If the invoice status was `paid`:
    -   The status changes to `posted` if the [`due_date`](/docs/api/invoices/invoice-object#due_date) is in the future.
    -   The status changes to `payment_due` if the `due_date` is in the past and [`auto_collection`](/docs/api/customers/customer-object#auto_collection) is `off`, or if `auto_collection` is `on` and dunning is in progress for the invoice.
    -   The status changes to `not_paid` if the due date is in the past, [`auto_collection`](/docs/api/customers/customer-object#auto_collection) is `on`, and dunning was **not** in progress for the invoice.

**

Transaction

**

The [`amount_unused`](/docs/api/transactions/transaction-object#amount_unused) on the transaction increases by the amount of the removed payment.

**

Customer excess payments balance

**

The customer's [`excess_payments`](/docs/api/customers/customer-object#excess_payments) balance increases by the amount of the removed payment.

**

Invoice dunning process

**

-   If the invoice status was `payment_due` before this operation, and dunning was in progress for the invoice, the dunning process continues as configured.
-   If the invoice status was `paid` before this operation, the dunning process **does not** resume.

### Implementation Notes

Before you call this API, make sure that:

-   There are no [`issued_credit_notes`](/docs/api/invoices/invoice-object#issued_credit_notes) with a `cn_status` value of `refunded` or `refund_due` for the invoice.
-   The specified transaction matches one of the [`linked_payments[].txn_id`](#invoice_linked_payments) for the invoice.
-   The [`status`](/docs/api/transactions/transaction-object#status) of the transaction is `success`, `in_progress`, or `needs_attention`.

#### Related APIs

Refund a payment

Record an offline refund

### FAQs

#### 

Can I remove payments from multiple invoices at once?

Yes. To remove payments from multiple invoices in bulk, go to **Settings** > **Import** > **Export Data** > **Bulk Operation**, and select **Remove payment from Invoice**.

#### 

How can I track the history of payments removed from invoices?

You can view the history of payments removed from invoices in the **Activity Log** section of the invoice. The log shows all actions taken, including payments removed.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/invoices/__demo_inv__4/remove_payment \
     -u {site_api_key}:\
     -d "transaction[id]"="txn___test__8asyKSOcUWoQ6y"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Invoice.RemovePayment("__demo_inv__4")
		.TransactionId("txn___test__8asyKSOcUWoQ6y")
		.Request();

Invoice invoice = result.Invoice;
Transaction transaction = result.Transaction;
```

#### 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.RemovePayment("__demo_inv__4", &invoice.RemovePaymentRequestParams{
        Transaction : &invoice.RemovePaymentTransactionParams{
            Id : "txn___test__8asyKSOcUWoQ6y",
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
        Transaction := res.Transaction
    }
}
```

#### 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.InvoiceRemovePaymentRequest{
    Transaction : &chargebee.InvoiceRemovePaymentTransaction{
        Id : "txn___test__8asyKSOcUWoQ6y",
    },
}
  res, err := client.Invoice.RemovePayment("__demo_inv__4", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
        Transaction := res.Transaction
    }
}
```

#### 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.removePayment("__demo_inv__4")
            .transactionId("txn___test__8asyKSOcUWoQ6y")
            .request();

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

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.invoice.params.InvoiceRemovePaymentParams;
import com.chargebee.v4.models.invoice.responses.InvoiceRemovePaymentResponse;
import com.chargebee.v4.models.transaction.Transaction;

public class InvoiceRemovePayment {

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

        InvoiceRemovePaymentParams.TransactionParams transactionParams =
            InvoiceRemovePaymentParams.TransactionParams.builder()
                .id("txn___test__8asyKSOcUWoQ6y")
                .build();

        InvoiceRemovePaymentParams params = InvoiceRemovePaymentParams.builder()
            .transaction(transactionParams)
            .build();

        InvoiceRemovePaymentResponse response = client
            .invoices()
            .removePayment("__demo_inv__4", params);

        Invoice invoice = response.getInvoice();
        Transaction transaction = response.getTransaction();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.invoice.removePayment("__demo_inv__4", {
        transaction: {
            id: "txn___test__8asyKSOcUWoQ6y"
        }
    });

    console.log(result);
    const invoice = result.invoice;
    const transaction = result.transaction;
} 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()->removePayment("__demo_inv__4", [
    "transaction" => [
        "id" => "txn___test__8asyKSOcUWoQ6y"
    ]
]);
$invoice = $result->invoice;
$transaction = $result->transaction;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Invoice.remove_payment("__demo_inv__4",
    cb_client.Invoice.RemovePaymentParams(
        transaction=cb_client.Invoice.RemovePaymentTransactionParams(
            id="txn___test__8asyKSOcUWoQ6y"
        )
    )
)
invoice = response.invoice
transaction = response.transaction
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Invoice.remove_payment("__demo_inv__4",{
  :transaction => {
    :id => "txn___test__8asyKSOcUWoQ6y"
  }
})

invoice = result.invoice
transaction = result.transaction
```

## Sample Response

```json
{
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 1000,
    "amount_paid": 0,
    "amount_to_collect": 1000,
    "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__8aso8SOcUUT02s",
    "date": 1612796956,
    "deleted": false,
    "due_date": 1612796956,
    "dunning_attempts": [
      {
        "attempt": 0,
        "created_at": 1612796957,
        "dunning_type": "auto_collect",
        "retry_engine": "chargebee",
        "transaction_id": "txn___test__8aso8SOcUWbP3v",
        "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__8aso8SOcUUT02s",
        "date_from": 1612796956,
        "date_to": 1612883356,
        "description": "Basic USD 2",
        "discount_amount": 0,
        "entity_id": "basic-USD2",
        "entity_type": "plan_item_price",
        "id": "li___test__8aso8SOcUWYm3u",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "per_unit",
        "quantity": 1,
        "subscription_id": "__test__8aso8SOcUUT02s",
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 1000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": [
      {
        "applied_amount": 1000,
        "applied_at": 1612796957,
        "txn_amount": 1000,
        "txn_date": 1612796957,
        "txn_id": "txn___test__8aso8SOcUWbP3v",
        "txn_status": "failure"
      },
      {..}
    ],
    "net_term_days": 0,
    "object": "invoice",
    "price_type": "tax_exclusive",
    "recurring": true,
    "resource_version": 1517490561162,
    "round_off_amount": 0,
    "status": "posted",
    "sub_total": 1000,
    "subscription_id": "__test__8aso8SOcUUT02s",
    "tax": 0,
    "term_finalized": true,
    "total": 1000,
    "updated_at": 1517490561,
    "write_off_amount": 0
  },
  "transaction": {
    "amount": 1000,
    "amount_unused": 1000,
    "base_currency_code": "USD",
    "currency_code": "USD",
    "customer_id": "__test__8aso8SOcUUT02s",
    "date": 1517490561,
    "deleted": false,
    "exchange_rate": 1,
    "gateway": "chargebee",
    "gateway_account_id": "gw___test__8aso8SOcUTvz1y",
    "id": "txn___test__8asyKSOcUWoQ6y",
    "id_at_gateway": "cb___test__8asyKSOcUWoU6z",
    "linked_invoices": {},
    "linked_refunds": {},
    "masked_card_number": "***********0005",
    "object": "transaction",
    "payment_method": "card",
    "payment_source_id": "pm___test__8asyKSOcUWmm6r",
    "resource_version": 1517490561166,
    "status": "success",
    "type": "payment",
    "updated_at": 1517490561
  }
}
```

## URL Format

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

## Input Parameters

- `transaction` (optional, string)
  Parameters for transaction
  - `id` (required, string, max chars=40)
    Uniquely identifies the transaction.

## Returns

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

- `transaction` (Transaction object)
  Resource object representing transaction
