# Cancel a payment request

There are two main ways for a payment request to be cancelled. Either via the ePOS or the card machine depending on the point within the transaction.

Given a payment request has been posted to POSLink and a card has not yet been presented to the card machine for payment, it is possible to cancel via ePOS. However, if the user has started the payment process by presenting their card to the card machine, an attempt to cancel this payment can only be made from the card machine.


```tabs
    tab:
      title: Cancelling via ePOS
      content:
        To cancel a payment request from ePOS:
        
        1. ePOS calls POSLink's **[Update a Payment Request API](/apis/poslink/apis#patch--poslink-v2-payment-requests--payment-request-id-)** submitting a status of `CANCELLING`. This is a *request* to cancel - not a confirmation that the payment was cancelled.
        2. A successful response means the cancellation request was accepted and the payment request has moved to `CANCELLING`. It does **not** mean the payment is cancelled. Whether the cancellation takes effect depends on the terminal: if the card has not yet been presented and processing has not started, the terminal cancels the payment request and its status becomes `CANCELLED` with a status reason of `CANCELLED_BY_EPOS`; if the terminal has already started processing, the payment continues to its final state (`SUCCESSFUL` or `FAILED`), which overrides `CANCELLING`.
        3. ePOS should follow the payment request's status updates via the [Retrieve a payment request API](/apis/poslink/apis#get--poslink-v3-payment-requests--payment-request-id-) until it reaches a final state (`CANCELLED`, `SUCCESSFUL` or `FAILED`). The payment is only cancelled when the status is `CANCELLED`.
        
        
        ```json title="Example request"
        PATCH /poslink/v2/payment-requests/{payment-request-id} HTTP/1.1
        Content-Type: application/json
        Authorization: 
        Host: api.teya.com
        Content-Length: 28
        
        {
          "status": "CANCELLING"
        }
        ```
        <br>
        
        ```json title="Example response"
        {
          "payment_request_id": "368dc71b-e9d4-4f30-a94c-0432e30043b6",
          "status": "CANCELLING",
          "updated_at": "2023-03-02T14:39:29.151Z"
        }
        
        ```
    tab:
      title: Cancelling via the terminal
      content:
        Terminal will post a cancel request to the terminal Integration API which will be passed to ePOS.
        
        1. The terminal will call the terminal Integration API to send cancel request.
        2. If the terminal receives a successful response to the API call, it is considered that the transaction request has been cancelled.
        3. The ePOS should reflect the cancelled state upon calling POSLink
```
## Status flow diagrams

Below are visual representations of status transitions for a Payment Request.

#### Payment request status flow

![poslink-payment-status.png](/poslink/images/poslink-payment-status-updated.png)
