# Record an excess payment for a customer

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


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

Records an offline payment for a customer and adds it to the customer's [excess payments balance](/docs/api/customers#balances).

### Impacts

**

Invoices

**

-   Chargebee automatically applies excess payments to future invoices, subject to [limits set at the site level](https://www.chargebee.com/docs/billing/2.0/invoices-credit-notes-and-quotes/credit-notes#credits-flexibility) or overridden for subscriptions via [`subscription.billing_override`](/docs/api/subscriptions#billing_override).
-   Use the [Apply payments to an invoice API](/docs/api/invoices/apply-payments-for-an-invoice) to apply excess payments to an invoice on an ad-hoc basis.

#### Related APIs

Apply payments for an invoice

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/customers/__test__KyVnHhSBWlDEl2cz/record_excess_payment \
     -u {site_api_key}:\
     -d comment="Check payment received from John" \
     -d "transaction[amount]"=500 \
     -d "transaction[date]"=1600968152 \
     -d "transaction[payment_method]"="CHECK"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Customer.RecordExcessPayment("__test__KyVnHhSBWlDEl2cz")
		.Comment("Check payment received from John")
		.TransactionAmount(500)
		.TransactionDate(1600968152)
		.TransactionPaymentMethod(PaymentMethodEnum.Check)
		.Request();

Customer customer = result.Customer;
Transaction transaction = result.Transaction;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    customerAction "github.com/chargebee/chargebee-go/v3/actions/customer"
    "github.com/chargebee/chargebee-go/v3/models/customer"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := customerAction.RecordExcessPayment("__test__KyVnHhSBWlDEl2cz", &customer.RecordExcessPaymentRequestParams{
        Comment : "Check payment received from John",
        Transaction : &customer.RecordExcessPaymentTransactionParams{
            Amount : chargebee.Int64(500),
            Date : chargebee.Int64(1600968152),
            PaymentMethod : enum.PaymentMethodCheck,
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        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.CustomerRecordExcessPaymentRequest{
    Comment : "Check payment received from John",
    Transaction : &chargebee.CustomerRecordExcessPaymentTransaction{
        Amount : chargebee.Int64(500),
        Date : chargebee.Int64(1600968152),
        PaymentMethod : chargebee.PaymentMethodCheck,
    },
}
  res, err := client.Customer.RecordExcessPayment("__test__KyVnHhSBWlDEl2cz", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        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;
import java.sql.Timestamp;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Customer.recordExcessPayment("__test__KyVnHhSBWlDEl2cz")
            .comment("Check payment received from John")
            .transactionAmount(500L)
            .transactionDate(new Timestamp(1600968152L * 1000))
            .transactionPaymentMethod(PaymentMethod.CHECK)
            .request();

        Customer customer = result.customer();
        Transaction transaction = result.transaction();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.customer.params.CustomerRecordExcessPaymentParams;
import com.chargebee.v4.models.customer.responses.CustomerRecordExcessPaymentResponse;
import com.chargebee.v4.models.transaction.Transaction;
import java.sql.Timestamp;

public class CustomerRecordExcessPayment {

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

        CustomerRecordExcessPaymentParams.TransactionParams transactionParams =
            CustomerRecordExcessPaymentParams.TransactionParams.builder()
                .amount(500L)
                .date(new Timestamp(1600968152L * 1000))
                .paymentMethod(CustomerRecordExcessPaymentParams.TransactionParams.PaymentMethod.CHECK)
                .build();

        CustomerRecordExcessPaymentParams params = CustomerRecordExcessPaymentParams.builder()
            .comment("Check payment received from John")
            .transaction(transactionParams)
            .build();

        CustomerRecordExcessPaymentResponse response = client
            .customers()
            .recordExcessPayment("__test__KyVnHhSBWlDEl2cz", params);

        Customer customer = response.getCustomer();
        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.customer.recordExcessPayment("__test__KyVnHhSBWlDEl2cz", {
        comment: "Check payment received from John",
        transaction: {
            amount: 500,
            date: 1600968152,
            payment_method: "check"
        }
    });

    console.log(result);
    const customer = result.customer;
    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->customer()->recordExcessPayment("__test__KyVnHhSBWlDEl2cz", [
    "comment" => "Check payment received from John",
    "transaction" => [
        "amount" => 500,
        "date" => 1600968152,
        "payment_method" => "check"
    ]
]);
$customer = $result->customer;
$transaction = $result->transaction;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Customer.record_excess_payment("__test__KyVnHhSBWlDEl2cz",
    cb_client.Customer.RecordExcessPaymentParams(
        comment="Check payment received from John",
        transaction=cb_client.Customer.RecordExcessPaymentTransactionParams(
            amount=500,
            date=1600968152,
            payment_method=chargebee.PaymentMethod.CHECK
        )
    )
)
customer = response.customer
transaction = response.transaction
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Customer.record_excess_payment("__test__KyVnHhSBWlDEl2cz",{
  :comment => "Check payment received from John",
  :transaction => {
    :amount => 500,
    :date => 1600968152,
    :payment_method => "CHECK"
  }
})

customer = result.customer
transaction = result.transaction
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "balances": [
      {
        "balance_currency_code": "USD",
        "currency_code": "USD",
        "excess_payments": 500,
        "object": "customer_balance",
        "promotional_credits": 0,
        "refundable_credits": 0,
        "unbilled_charges": 0
      },
      {..}
    ],
    "card_status": "no_card",
    "created_at": 1517505752,
    "deleted": false,
    "excess_payments": 500,
    "first_name": "John",
    "id": "__test__KyVnHhSBWlDEl2cz",
    "last_name": "Doe",
    "net_term_days": 0,
    "object": "customer",
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517505752000,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517505752
  },
  "transaction": {
    "amount": 500,
    "amount_unused": 500,
    "base_currency_code": "USD",
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWlDEl2cz",
    "date": 1600968152,
    "deleted": false,
    "exchange_rate": 1,
    "gateway": "not_applicable",
    "id": "txn___test__KyVnHhSBWlDFn2d1",
    "linked_invoices": {},
    "linked_refunds": {},
    "object": "transaction",
    "payment_method": "check",
    "resource_version": 1517505752000,
    "status": "success",
    "type": "payment",
    "updated_at": 1517505752
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/customers/{customer-id}/record_excess_payment

## Input Parameters

- `comment` (optional, string, max chars=300)
  Remarks, if any, on the payment.

- `transaction` (optional, string)
  Parameters for transaction
  - `id` (optional, string, max chars=40)
    The unique ID of the transaction.
    
    **Constraints**
    
    -   The value must be unique within the site; it should not collide with any existing transaction ID.
  - `amount` (required, in cents, min=0)
    The payment transaction amount.
  - `currency_code` (required if Multicurrency is enabled, string, max chars=3)
    The currency code (ISO 4217 format) for the transaction.
  - `date` (required, timestamp(UTC) in seconds)
    Indicates when this transaction occurred.
  - `payment_method` (required, enumerated string)
    The payment method of this transaction
    Possible enum values:
      - `cash`
        Cash
      - `check`
        Check
      - `bank_transfer`
        Bank Transfer
      - `other`
        Payment Methods other than the above types
      - `custom`
        Custom payment method.
        
        **Prerequisite**
        
        -   [Custom payment methods](https://app.chargebee.com/login?forward=https://app.chargebee.com/request_access/custom-payment-methods&ref=feature) must be enabled in Chargebee Billing.
      - `dana`
      - `touch_n_go`
      - `tamara`
      - `qpay`
      - `ovo`
      - `momo`
      - `mercado_pago`
      - `nequi`
      - `nupay`
      - `picpay`
      - `thai_qr`
      - `blik`
      - `fpx`
      - `wero`
      - `p24`
      - `affirm_pay`
      - `rakuten_pay`
  - `reference_number` (optional, string, max chars=100)
    The reference number for this transaction. e.g check number in case of 'check' payments.
  - `custom_payment_method_id` (optional, string, max chars=50)
    Identifier of the custom payment method of this transaction.
    
    **Prerequisite**
    
    -   The `transaction[payment_method]` is `custom`.

## Returns

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

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