# Chargebacks tutorial
source: https://developer.mastercard.com/mastercom-extended/documentation/tutorials-and-guides/chargebacks-tutorial/index.md

## Overview {#overview}

This tutorial will show you how to acknowledge or reverse a chargeback.

#### What you will learn {#what-you-will-learn}

> * How to update (acknowledge) a chargeback
> * How to reverse a chargeback
> * How to update a chargeback reversal (*Applicable only for customers in India processing domestic disputes.*)

## Before you start {#before-you-start}

Before starting this tutorial, ensure that you have already completed the following:

* [Mastercom Extended API Client Generation Tutorial](https://developer.mastercard.com/mastercom-extended/documentation/tutorials-and-guides/clientgeneration-tutorial/index.md)
* [Quick Start Guide](https://developer.mastercard.com/mastercom-extended/documentation/quick-start-guide/index.md)

## Step 1: Acknowledge a chargeback {#step-1-acknowledge-a-chargeback}

An acquirer uses this endpoint to acknowledge a chargeback. The acquirer acknowledges the received chargeback to move the claim from the Acquirer First Chargeback Unworked queue to the Acquirer Worked queue.

*Applicable only for customers in India processing domestic disputes* :  

Issuers use this endpoint to acknowledge a rejected chargeback that was previously submitted. This moves the claim from the Reject queue to the Issuer Worked queue.

**Refer to the [Queues](https://developer.mastercard.com/mastercom-extended/documentation/tutorials-and-guides/queues-tutorial/index.md) tutorial for more specific information on Queues.**
Note: The acquirer may take further actions on acknowledged chargebacks.
API Reference: `PUT /claims/{claim_id}/chargebacks/{event_id}`

To update a chargeback, create a `ChargebacksApi` object. Then use method `chargebacksApi.updateChargeback` to acknowledge the chargeback.

This method expects the `claimId`, `eventId`, and request body to be provided. The request body is an instantiation of `ChargebackUpdate` object.

```java
public class Main {
  public static void main(String[] args) {
    // API client set up here...    

    ChargebacksApi chargebacksApi = new ChargebacksApi(client);
    
    String claimId = "713992756751";
    String eventId = "814345676342";
    
    ChargebackUpdate body = new ChargebackUpdate();
    body.setAcknowledged(true);
    
    try {
        // Update chargeback call has no return
        chargebacksApi.updateChargeback(claimId, eventId, body);
    } catch (ApiException e) {
        System.err.println("Exception when calling ChargebacksApi#updateChargeback");
        System.err.println("Status code: " + e.getCode());
        System.err.println("Reason: " + e.getResponseBody());
        System.err.println("Response headers: " + e.getResponseHeaders());
        e.printStackTrace();
    }
  }
}
```

#### Review the possible error codes associated with this request {#review-the-possible-error-codes-associated-with-this-request}

| HTTP Code |         Error          |             Error Description             |                                                   Error Code                                                   |
|-----------|------------------------|-------------------------------------------|----------------------------------------------------------------------------------------------------------------|
| 400       | INVALID_REQUEST        | Action is invalid at this time            | 200007                                                                                                         |
| 400       | INVALID_FORMAT         | Invalid format for field `fieldName`      | 220000                                                                                                         |
| 400       | INVALID_INPUT_VALUE    | Invalid input value for field `fieldName` | 230000                                                                                                         |
| 400       | INVALID_INPUT_VALUE    | INVALID_INPUT_VALUE                       | 230000                                                                                                         |
| 400       | INVALID_INPUT          | Invalid input                             | 230004, 230005, 230006, 230007, 230008, 230009, 230010, 230011, 230012, 230013, 230014, 230015, 230016, 230017 |
| 401       | NOT_AUTHORIZED_REQUEST | User is not authorized                    | 200010                                                                                                         |
| 404       | RESOURCE_UNKNOWN       | Resource unknown                          | 200004                                                                                                         |
| 404       | RESOURCE_NOT_FOUND     | Resource not found                        | 200005                                                                                                         |

Review additional error codes [here](https://developer.mastercard.com/mastercom-extended/documentation/code-and-formats/errorsandexceptions/index.md).

#### Verify response {#verify-response}

You should receive a 204 Success - No content response.

## Step 2: Reverse a chargeback {#step-2-reverse-a-chargeback}

If a previously created chargeback is no longer needed, issuers can use this endpoint to reverse the existing chargeback.

API Reference: `POST /claims/{claim_id}/chargebacks/{event_id}/reversals`

To reverse a chargeback, create a `ChargebacksApi` object. Then use method `chargebacksApi.reverseChargeback` to reverse the chargeback.

This method expects the `claimId`, `eventId`, and request body to be provided, the request body is an instantiation of a `ChargebackReversal` object.

```java
public class Main {
  public static void main(String[] args) {
    // API client set up here...    

    ChargebacksApi chargebacksApi = new ChargebacksApi(client);
    
    String claimId = "713992756751";
    String eventId = "814345676342";
    
    ChargebackSingleMessageReversal chargebackSingleMessageReversal = new ChargebackSingleMessageReversal();
    chargebackSingleMessageReversal.setControlNumber("99999");
    
    ChargebackReversal body = new ChargebackReversal();
    body.setReasonCode("03");
    body.setSingleMessage(chargebackSingleMessageReversal);
    
    try {
        ChargebackReversalEventId result = chargebacksApi.reverseChargeback(claimId, eventId, body);
        System.out.println(result.getEventId());
    } catch (ApiException e) {
        System.err.println("Exception when calling ChargebacksApi#reverseChargeback");
        System.err.println("Status code: " + e.getCode());
        System.err.println("Reason: " + e.getResponseBody());
        System.err.println("Response headers: " + e.getResponseHeaders());
        e.printStackTrace();
    }
  }
}
```

#### Review the possible error codes associated with this request {#review-the-possible-error-codes-associated-with-this-request-1}

| HTTP Code |         Error          |             Error Description             |                                                   Error Code                                                   |
|-----------|------------------------|-------------------------------------------|----------------------------------------------------------------------------------------------------------------|
| 400       | INVALID_REQUEST        | Action is invalid at this time            | 200007                                                                                                         |
| 400       | INVALID_FORMAT         | Invalid format for field `fieldName`      | 220000                                                                                                         |
| 400       | INVALID_INPUT_VALUE    | Invalid input value for field `fieldName` | 230000                                                                                                         |
| 400       | INVALID_INPUT_VALUE    | INVALID_INPUT_VALUE                       | 230000                                                                                                         |
| 400       | INVALID_INPUT          | Invalid input                             | 230004, 230005, 230006, 230007, 230008, 230009, 230010, 230011, 230012, 230013, 230014, 230015, 230016, 230017 |
| 400       | MISSING_REQUIRED_INPUT | Missing required field `fieldName`        | 250000                                                                                                         |
| 401       | NOT_AUTHORIZED_REQUEST | User is not authorized                    | 200010                                                                                                         |
| 404       | RESOURCE_UNKNOWN       | Resource unknown                          | 200004                                                                                                         |
| 404       | RESOURCE_NOT_FOUND     | Resource not found                        | 200005                                                                                                         |

Review additional error codes [here](https://developer.mastercard.com/mastercom-extended/documentation/code-and-formats/errorsandexceptions/index.md).

#### Verify response {#verify-response-1}

You should receive a 201 Created response. Returns the `eventId`.

## Step 3: Acknowledge a chargeback reversal {#step-3-acknowledge-a-chargeback-reversal}

*Applicable only for customers in India processing domestic disputes.*

An issuer uses this endpoint to acknowledge a rejected chargeback reversal that was previously submitted. This moves the claim from the Reject queue to the Issuer Worked queue.

API Reference: `PUT /claims/{claim_id}/chargebacks/{event_id}/reversals`

To update a chargeback, create a `ChargebacksApi` object. Then use method `chargebacksApi.updateChargebackReversal` to update the chargeback reversal.

This method expects the `claimId`, `eventId`, and request body to be provided. The request body is an instantiation of `ChargebackReversalUpdate` object.

```java
public class Main {
  public static void main(String[] args) {
    // API client set up here...

    ChargebacksApi chargebacksApi = new ChargebacksApi(client);

    String claimId = "713992756751";
    String eventId = "814345676342";

    ChargebackReversalUpdate body = new ChargebackReversalUpdate();
    body.setAcknowledgeReject(true);

    try {
      // Update chargeback reversal call has no return
      chargebacksApi.updateChargebackReversal(claimId, eventId, body);
    } catch (ApiException e) {
      System.err.println("Exception when calling ChargebacksApi#updateChargebackReversal");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Review the possible error codes associated with this request {#review-the-possible-error-codes-associated-with-this-request-2}

| HTTP Code |         Error          |             Error Description             |                                                   Error Code                                                   |
|-----------|------------------------|-------------------------------------------|----------------------------------------------------------------------------------------------------------------|
| 400       | INVALID_REQUEST        | Action is invalid at this time            | 200007                                                                                                         |
| 400       | INVALID_FORMAT         | Invalid format for field `fieldName`      | 220000                                                                                                         |
| 400       | INVALID_INPUT_VALUE    | Invalid input value for field `fieldName` | 230000                                                                                                         |
| 400       | INVALID_INPUT_VALUE    | INVALID_INPUT_VALUE                       | 230000                                                                                                         |
| 400       | INVALID_INPUT          | Invalid input                             | 230004, 230005, 230006, 230007, 230008, 230009, 230010, 230011, 230012, 230013, 230014, 230015, 230016, 230017 |
| 400       | MISSING_REQUIRED_INPUT | Missing required field `fieldName`        | 250000                                                                                                         |
| 401       | NOT_AUTHORIZED_REQUEST | User is not authorized                    | 200010                                                                                                         |
| 404       | RESOURCE_UNKNOWN       | Resource unknown                          | 200004                                                                                                         |
| 404       | RESOURCE_NOT_FOUND     | Resource not found                        | 200005                                                                                                         |

Review additional error codes [here](https://developer.mastercard.com/mastercom-extended/documentation/code-and-formats/errorsandexceptions/index.md).

#### Verify response {#verify-response-2}

You should receive a 204 Success - No content response.

Return to [Tutorials](https://developer.mastercard.com/mastercom-extended/documentation/tutorials-and-guides/index.md).
