# Payment Cancellation
source: https://developer.mastercard.com/payment-initiation-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}
>
> In this tutorial, you will learn how to:
>
> * Initiate a payment cancellation

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

Before beginning this tutorial, ensure that you have completed the following prerequisites:

* Registered with the CDP API Service.
* A card payment initiation request has been submitted in ISO 20022 format.
* 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, the payment cancellation process is successfully completed.

## Next steps {#next-steps}

Click **Next** to get started.

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

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

The Debtor Agent initiates the updatePaymentStatus request and sends a CANCELLATION_REQUESTED status to CDP.
Diagram pmtcancel1

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

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

A sample updatePaymentStatus call for the CANCELLATION_REQUESTED status looks like:
* JSON

```JSON
{
    "status": "CANCELLATION_REQUESTED",
    "statusReasonInformation": [
        {
            "reasonCode": "SPA_REQUESTED",
            "description": "SPA has requested to cancel the transaction."
        }
    ]
}
```

### 3. Review the status code associated with this request. {#3-review-the-status-code-associated-with-this-request}

Once the Debtor Agent initiates the cancellation request, CDP will receive the following status:

|         Status         |            Description            |                                         Usage                                          |
|------------------------|-----------------------------------|----------------------------------------------------------------------------------------|
| CANCELLATION_REQUESTED | Cancellation request is received. | The Debtor Agent sends this request to the CDP and initiates the cancellation request. |

When you submit a cancellation request, you may receive one or more applicable error codes if required data is missing or if the information provided is incorrect.
For more details, refer to the [Payment Cancellation Request Error Codes](https://developer.mastercard.com/payment-initiation-api/documentation/code-and-formats/index.md#payment-cancellation-request-error-codes).

#### Click Next {#click-next}

## 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.

#### Click Next {#click-next-1}

### CDP sends the cancellation status to the Creditor Agent {#cdp-sends-the-cancellation-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.

#### Click Next {#click-next-2}

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

### 1. The Creditor Agent sends CANCELLATION_ACCEPTED or CANCELLATION_REJECTED status to the CDP. {#1-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.

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

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."
        }
    ]
}
```

### 3. Review the status code associated with this request. {#3-review-the-status-code-associated-with-this-request-1}

Once the Debtor Agent initiates the cancellation request, CDP will receive 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 applicable error codes if required data is missing or if the information provided is incorrect.
For more details, refer to the [Payment Cancellation Rejected Error Codes](https://developer.mastercard.com/payment-initiation-api/documentation/code-and-formats/index.md#payment-cancellation-rejected-error-codes).

#### Click Next {#click-next-3}

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

Diagram pmtcancel5

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