Payments

Cancel a Payment

Cancel a pending or processing transaction before the customer completes payment.

Cancel a Payment

POST /v1/transactions/:reference/cancel

Cancels a transaction and fires a payment.cancelled webhook. Only transactions in pending or processing status can be cancelled.

Cancellation is irreversible. Once cancelled, the checkout session is invalidated and the customer cannot complete the payment.


Request

raw HTTP
npm install @e-pay/node
pip install epay
composer require epay-et/php-sdk
go get github.com/epay-et/go-sdk
curl https://api.e-pay.et/v1/transactions/PAB12CD3420260813/cancel \
  -X POST \
  -H "Authorization: Bearer sk_live_your_key_here"
import { Epay, EpayBadRequestError } from '@e-pay/node';

const epay = new Epay({ apiKey: process.env.EPAY_SECRET_KEY });

try {
await epay.payments.cancel(reference); // resolves on 204
} catch (error) {
// Already completed, failed, or cancelled.
if (error instanceof EpayBadRequestError) return 'not cancellable';
throw error;
}
const res = await fetch('https://api.e-pay.et/v1/transactions/PAB12CD3420260813/cancel', {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.EPAY_SECRET_KEY}` },
});

// 204 No Content on success — no body
if (res.status !== 204) {
  throw new Error(`ePay ${res.status}: ${await res.text()}`);
}
from epay import Epay, EpayBadRequestError

epay = Epay() # reads EPAY_SECRET_KEY

try:
epay.payments.cancel(reference) # returns None on 204
except EpayBadRequestError: # Already completed, failed, or cancelled.
return "not cancellable"
import os
import requests

res = requests.post(
    "https://api.e-pay.et/v1/transactions/PAB12CD3420260813/cancel",
    headers={"Authorization": f"Bearer {os.environ['EPAY_SECRET_KEY']}"},
    timeout=30,
)

# 204 No Content on success — no body
if res.status_code != 204:
    raise RuntimeError(f"ePay {res.status_code}: {res.text}")
use Epay\Epay;
use Epay\Exception\EpayBadRequestException;

$epay = new Epay(); // reads EPAY_SECRET_KEY

try {
$epay->payments->cancel($reference); // returns void on 204
} catch (EpayBadRequestException) {
// Already completed, failed, or cancelled.
return 'not cancellable';
}
$ch = curl_init('https://api.e-pay.et/v1/transactions/PAB12CD3420260813/cancel');

curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('EPAY_SECRET_KEY')],
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

// 204 No Content on success — no body
if ($status !== 204) {
    throw new RuntimeException("ePay {$status}: {$body}");
}
err := client.Payments.Cancel(ctx, reference)

switch {
case errors.Is(err, epay.ErrBadRequest):
// Already completed, failed, or cancelled.
return errNotCancellable
case err != nil:
return err
}
req, _ := http.NewRequestWithContext(ctx, http.MethodPost, "https://api.e-pay.et/v1/transactions/PAB12CD3420260813/cancel", nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("EPAY_SECRET_KEY"))

res, err := http.DefaultClient.Do(req)
if err != nil {
	return err
}
defer res.Body.Close()

// 204 No Content on success — no body
if res.StatusCode != http.StatusNoContent {
	return fmt.Errorf("ePay %d", res.StatusCode)
}

Path Parameters

Prop

Type


Response

Returns 204 No Content on success. No response body.


Errors

StatusDescription
400Transaction is not in a cancellable status (completed or failed cannot be cancelled).
401Missing or invalid API key.
404No transaction found for the given reference under your account.

Next: Webhooks — receive payment.cancelled and other events without polling.

On this page