# Payment Cancellation
source: https://developer.mastercard.com/payment-acceptance-api/documentation/tutorials-and-guides/payment-cancellation-tutorial/index.md

## Overview {#overview}

This tutorial illustrates all the steps of the payment cancellation process in Commercial Direct Payments (CDP).
>
> #### What you will learn {#what-you-will-learn}
>
> * How to update the payment status for the cancellation request.

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

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

* Registered with the CDP API Service.
* The payment status should be the in `SUBMITTED` status.
* Make sure that the `<requestedExecutionDate>` for the payment transaction is in the future or today.

Note: CDP rejects the cancellation requests for the transactions with a `<requestedExecutionDate>` in the past.

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

At the end of this tutorial, you will be able to cancel the payment successfully.

## Debtor Agent initiates the cancellation request {#debtor-agent-initiates-the-cancellation-request}

The Debtor Agent uses this endpoint to initiate the payment cancellation request.
Diagram pmtcancel1

1. The Debtor Agent submits the \[PUT\] payment status update (cancellation) request to the CDP.

## CDP validates the payment cancellation request {#cdp-validates-the-payment-cancellation-request}

Diagram pmtcancel2

1. CDP validates the payment cancellation request.
2. CDP sends an acknowledgment of the cancellation request to the Debtor Agent.

## CDP sends the cancellation request status to the Creditor Agent {#cdp-sends-the-cancellation-request-status-to-the-creditor-agent}

Diagram pmtcancel3

1. CDP invokes the Creditor Agent webhook using a POST request and sends a CANCELLATION_REQUESTED status notification.
2. The Creditor Agent acknowledges the webhook by responding to CDP.

## Creditor Agent sends cancellation status to the CDP {#creditor-agent-sends-cancellation-status-to-the-cdp}

The Creditor Agent sends CANCELLATION_ACCEPTED or CANCELLATION_REJECTED status to the CDP.
Diagram pmtcancel4

1. The Creditor Agent sends a CANCELLATION_ACCEPTED or CANCELLATION_REJECTED status to CDP using the PUT updatePaymentStatus call.

## 1. Review the sample event notification associated with this step. {#1-review-the-sample-event-notification-associated-with-this-step}

A JSON sample for the CANCELLATION_ACCEPTED status looks like:
* JSON

```JSON
{
    "status": "CANCELLATION_ACCEPTED"
}
```

<br />

A JSON sample for the CANCELLATION_REJECTED status looks like:
* JSON

```JSON
{
    "status": "CANCELLATION_REJECTED",
    "statusReasonInformation": [
        {
            "reasonCode": "CARD_DEBITED",
            "description": "Card was debited for already."
        }
    ]
}
```

## 2. Review the status codes and reason codes associated with this request. {#2-review-the-status-codes-and-reason-codes-associated-with-this-request}

Once the Creditor Agent responds to the cancellation request, CDP may receive any of the following status:

|        Status         |            Description            |                                               Usage                                                |
|-----------------------|-----------------------------------|----------------------------------------------------------------------------------------------------|
| CANCELLATION_ACCEPTED | Cancellation request is accepted. | The Creditor Agent sends this status to the CDP when the payment cancellation request is accepted. |
| CANCELLATION_REJECTED | Cancellation request is rejected. | The Creditor Agent sends this status to the CDP when the payment cancellation request is rejected. |

When a cancellation request is rejected, you may receive one or more of the following error codes. These errors occur when required information is missing or when the data provided is incorrect. For more details, refer to the [Cancellation Rejected Request Error Codes](https://developer.mastercard.com/payment-acceptance-api/documentation/code-and-formats/index.md#cancellation-rejected-request-error-codes).

## CDP sends the cancellation status to the Debtor Agent {#cdp-sends-the-cancellation-status-to-the-debtor-agent}

There is no action required for the Creditor Agent at this step.
Diagram pmtcancel5

1. CDP sends a cancellation status notification to the Debtor Agent indicating CANCELLATION_ACCEPTED or CANCELLATION_REJECTED.
