# Cancel a pending transaction

Cancelling a pending transaction endpoint allows you to block the payment flow for consumers that currently visiting the payment page and also block the payment page for new consumers - only for specific transaction.

{% hint style="info" %}
This API will not refund approved transactions, see [Refund a transaction](/sensepay/transaction-api/payment-flows/refund-a-transaction.md)
{% endhint %}

### API Interface

## Cancelling a pending transaction object (Payment Request)

<mark style="color:green;">`POST`</mark> `https://api.sensepass.com/api/transactions/cancel/{transactionNumber}`

#### Path Parameters

| Name                                                | Type   | Description                  |
| --------------------------------------------------- | ------ | ---------------------------- |
| transactionNumber<mark style="color:red;">\*</mark> | String | Transaction number to cancel |

**Authentication Request Body fields**

[See here our Authentication page](/sensepay/transaction-api/authentication.md)

{% tabs %}
{% tab title="201: OK OK" %}

```javascript
{
  "status": 200,
  "status_message": "Transaction Was Canceled"
}
```

{% endtab %}

{% tab title="400: Bad Request Invalid Input" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="500: Internal Server Error Internal Error" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="501: Not Implemented This transaction cannot be cancelled due to cosumers activity" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## Cancelling a pending transaction object using Device ID

<mark style="color:green;">`POST`</mark> `https://api.sensepass.com/api/transactions/cancelByDeviceId/{deviceId}`

#### This API will cancel the last pending transaction of a given device

#### Path Parameters

| Name                                       | Type   | Description                  |
| ------------------------------------------ | ------ | ---------------------------- |
| deviceId<mark style="color:red;">\*</mark> | String | Device ID of the transaction |

**Authentication Request Body fields**

[See here our Authentication page](/sensepay/transaction-api/authentication.md)

{% tabs %}
{% tab title="201: OK OK" %}

```javascript
{
  "status": 200,
  "status_message": "Transaction Was Canceled"
}
```

{% endtab %}
{% endtabs %}

###

### Flow Chart

[See our payment flow chart here](/sensepay/transaction-api/flow-charts/payment-flow.md)

### Transaction Status Flow

[See our transaction status flow here](/sensepay/transaction-api/flow-charts/transaction-status-flow.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sensepass.com/sensepay/transaction-api/payment-flows/cancel-a-pending-transaction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
