# Reconcile transaction

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


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

Update selected attributes of the transaction resource: `status`, `id_at_gateway`, and `customer_id`. Use this API for reconciliation purposes where the status of a transaction is in `[needs_attention](/docs/api/transactions/transaction-object#status)` that can be updated to either `[success](/docs/api/transactions/transaction-object#status)` or `[failure](/docs/api/transactions/transaction-object#status)` status.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/transactions/txn___test__KyVnHhSBWlwT42q7/reconcile \
     -u {site_api_key}:\
     -d id_at_gateway="cb___test__KyVnHhSBWlv4q2pU" \
     -d customer_id="__test__KyVnHhSBWlv242pN" \
     -d status="SUCCESS"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Transaction.Reconcile("txn___test__KyVnHhSBWlwT42q7")
		.IdAtGateway("cb___test__KyVnHhSBWlv4q2pU")
		.CustomerId("__test__KyVnHhSBWlv242pN")
		.Status(Transaction.StatusEnum.Success)
		.Request();

Transaction transaction = result.Transaction;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    transactionAction "github.com/chargebee/chargebee-go/v3/actions/transaction"
    "github.com/chargebee/chargebee-go/v3/models/transaction"
    transactionEnum "github.com/chargebee/chargebee-go/v3/models/transaction/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := transactionAction.Reconcile("txn___test__KyVnHhSBWlwT42q7", &transaction.ReconcileRequestParams{
        IdAtGateway : "cb___test__KyVnHhSBWlv4q2pU",
        CustomerId : "__test__KyVnHhSBWlv242pN",
        Status : transactionEnum.StatusSuccess,
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        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.TransactionReconcileRequest{
    IdAtGateway : "cb___test__KyVnHhSBWlv4q2pU",
    CustomerId : "__test__KyVnHhSBWlv242pN",
    Status : chargebee.TransactionStatusSuccess,
}
  res, err := client.Transaction.Reconcile("txn___test__KyVnHhSBWlwT42q7", req)
      if err != nil {
        fmt.Println(err)
    } else {
        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 = Transaction.reconcile("txn___test__KyVnHhSBWlwT42q7")
            .idAtGateway("cb___test__KyVnHhSBWlv4q2pU")
            .customerId("__test__KyVnHhSBWlv242pN")
            .status(Transaction.Status.SUCCESS)
            .request();

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

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.transaction.Transaction;
import com.chargebee.v4.models.transaction.params.TransactionReconcileParams;
import com.chargebee.v4.models.transaction.responses.TransactionReconcileResponse;

public class TransactionReconcile {

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

        TransactionReconcileParams params = TransactionReconcileParams.builder()
            .idAtGateway("cb___test__KyVnHhSBWlv4q2pU")
            .customerId("__test__KyVnHhSBWlv242pN")
            .status(TransactionReconcileParams.Status.SUCCESS)
            .build();

        TransactionReconcileResponse response = client
            .transactions()
            .reconcile("txn___test__KyVnHhSBWlwT42q7", params);

        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.transaction.reconcile("txn___test__KyVnHhSBWlwT42q7", {
        id_at_gateway: "cb___test__KyVnHhSBWlv4q2pU",
        customer_id: "__test__KyVnHhSBWlv242pN",
        status: "success"
    });

    console.log(result);
    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->transaction()->reconcile("txn___test__KyVnHhSBWlwT42q7", [
    "id_at_gateway" => "cb___test__KyVnHhSBWlv4q2pU",
    "customer_id" => "__test__KyVnHhSBWlv242pN",
    "status" => "success"
]);
$transaction = $result->transaction;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Transaction.reconcile("txn___test__KyVnHhSBWlwT42q7",
    cb_client.Transaction.ReconcileParams(
        id_at_gateway="cb___test__KyVnHhSBWlv4q2pU",
        customer_id="__test__KyVnHhSBWlv242pN",
        status=chargebee.Transaction.Status.SUCCESS
    )
)
transaction = response.transaction
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Transaction.reconcile("txn___test__KyVnHhSBWlwT42q7",{
  :id_at_gateway => "cb___test__KyVnHhSBWlv4q2pU",
  :customer_id => "__test__KyVnHhSBWlv242pN",
  :status => "SUCCESS"
})

transaction = result.transaction
```

## Sample Response

```json
{
  "transaction": {
    "amount": 1395,
    "amount_unused": 0,
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWlv242pN",
    "date": 1517505921,
    "deleted": false,
    "exchange_rate": 1,
    "gateway": "chargebee",
    "gateway_account_id": "gw___test__KyVnGlSBWltEk29Z",
    "id": "txn___test__KyVnHhSBWlwT42q7",
    "id_at_gateway": "cb___test__KyVnHhSBWlv4q2pU",
    "linked_invoices": [
      {
        "applied_amount": 1395,
        "applied_at": 1517505921,
        "invoice_date": 1517505920,
        "invoice_id": "__demo_inv__3",
        "invoice_status": "paid",
        "invoice_total": 1395
      },
      {..}
    ],
    "linked_refunds": {},
    "masked_card_number": "************1111",
    "object": "transaction",
    "payment_method": "card",
    "payment_source_id": "pm___test__KyVnHhSBWlv2z2pP",
    "resource_version": 1517505921000,
    "status": "success",
    "subscription_id": "__test__KyVnHhSBWlv242pN",
    "type": "payment",
    "updated_at": 1517505921
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/transactions/{transaction-id}/reconcile

## Input Parameters

- `id_at_gateway` (optional, string, max chars=100)
  The identifier with which this transaction is referred in gateway. The `id_at_gateway` can only be updated when the transaction status is in `[needs_attention](/docs/api/transactions/transaction-object#status)`.
  
  **Note**:
  
  -   It is mandatory to pass this parameter value for updating the transaction status from `needs_attention` to `success`. It is recommended to pass this value if available in the gateway.
  -   An error occurs when the provided `id_at_gateway` value does not match the `id_at_gateway` value stored against the transaction in Chargebee.

- `customer_id` (optional, string, max chars=50)
  Unique identifier of the customer for which this transaction is made. This is needed only when the transaction is successful but not associated with any customer.
  
  **Note**:
  
  An error occurs when the provided `customer_id` value does not match the `customer_id` value stored against the transaction in Chargebee.

- `status` (optional, enumerated string)
  The status of this transaction. The status can only be updated when the transaction status is in `[needs_attention](/docs/api/transactions/transaction-object#status)` state.
  Possible enum values:
    - `success`
      When the transaction is successful.
      
      **Note**:
      
      When the transaction is updated to `[success](/docs/api/transactions/transaction-object#status)` status, - and the invoice is associated with the transaction, the transaction `[amount](/docs/api/transactions/transaction-object#amount)` will be applied to the invoice.
      
      -   and no invoice is associated but the customer is associated with the transaction, `[customer_excess_payments](/docs/api/customers/customer-object#excess_payments)` will be updated.
    - `failure`
      When the transaction is in failure status.
      
      **Note**:
      
      When the transaction is updated to `[failure](/docs/api/transactions/transaction-object#status)` status and the invoice is associated with the transaction,
      
      -   the invoice will be moved to the `[payment_due](/docs/api/invoices/invoice-object#status)` status if the `[dunning](https://www.chargebee.com/docs/payments/2.0/dunning-v2.html)` is configured.
      -   the invoice will be moved to the `[not_paid](/docs/api/invoices/invoice-object#status)` status if the `[dunning](https://www.chargebee.com/docs/payments/2.0/dunning-v2.html)` is not configured.

## Returns

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