POST /checkouts/{id}/cancel curl --fail-with-body --silent --show-error \
-X POST \
-H "Authorization: Bearer $MEREU_API_KEY" \
-H 'Accept: application/json' \
-H "Idempotency-Key: $CANCEL_OPERATION_ID" \
-H 'Content-Type: application/json' \
"https://mereu.md/api/v1/checkouts/$CHECKOUT_ID/cancel" \
--data-binary @- <<JSON
{
"expected_revision": $CHECKOUT_REVISION,
"reason": "$REASON"
}
JSON
// Node.js 24+. Run on your server; set the named environment variables.
const env = (name) => {
const value = process.env[name];
if (!value) throw new Error("Missing environment variable: " + name);
return value;
};
const integer = (name, minimum = 0) => {
const value = env(name);
const number = Number(value);
if (!/^[0-9]+$/.test(value) || !Number.isSafeInteger(number) || number < minimum)
throw new Error("Expected an integer in minor units or a revision: " + name);
return number;
};
const url = new URL("https://mereu.md/api/v1/checkouts/" + encodeURIComponent(env("CHECKOUT_ID")) + "/cancel");
const body = {
"expected_revision": integer("CHECKOUT_REVISION", 1),
"reason": env("REASON")
};
const response = await fetch(url, {
method: "POST",
redirect: "error",
signal: AbortSignal.timeout(15000),
headers: {
"Authorization": "Bearer " + env("MEREU_API_KEY"),
"Accept": "application/json",
"Idempotency-Key": env("CANCEL_OPERATION_ID"),
"Content-Type": "application/json"
},
body: JSON.stringify(body)
});
const result = await response.json();
if (!response.ok) {
throw Object.assign(new Error(result.error?.code || "API_ERROR"), {
status: response.status,
requestId: result.error?.request_id || response.headers.get("X-Request-Id"),
retryAfter: response.headers.get("Retry-After")
});
}
console.log(JSON.stringify(result, null, 2));
# Python 3, standard library only. Run on your server.
import json
import os
import re
from urllib.parse import quote, urlencode
from urllib.request import Request, build_opener, HTTPRedirectHandler
from urllib.error import HTTPError
def env(name):
value = os.environ.get(name)
if not value:
raise ValueError("Missing environment variable: " + name)
return value
def integer(name, minimum=0):
value = env(name)
if not re.fullmatch(r"[0-9]+", value):
raise ValueError("Expected an integer: " + name)
number = int(value)
if not minimum <= number <= 9007199254740991:
raise ValueError("Integer outside the supported range: " + name)
return number
class NoRedirect(HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, headers, newurl):
return None
url = "https://mereu.md/api/v1/checkouts/" + quote(env("CHECKOUT_ID"), safe="") + "/cancel"
body = {
"expected_revision": integer("CHECKOUT_REVISION", 1),
"reason": env("REASON")
}
headers = {
"Authorization": "Bearer " + env("MEREU_API_KEY"),
"Accept": "application/json",
"Idempotency-Key": env("CANCEL_OPERATION_ID"),
"Content-Type": "application/json"
}
request = Request(url, method="POST", headers=headers,
data=json.dumps(body, separators=(",", ":")).encode("utf-8"))
try:
with build_opener(NoRedirect()).open(request, timeout=15) as response:
result = json.load(response)
except HTTPError as error:
try:
code = json.load(error).get("error", {}).get("code", "API_ERROR")
except (ValueError, AttributeError):
code = "INVALID_RESPONSE"
raise SystemExit("HTTP " + str(error.code) + ": " + code
+ "; request_id=" + str(error.headers.get("X-Request-Id"))
+ "; retry_after=" + str(error.headers.get("Retry-After"))) from None
print(json.dumps(result, indent=2))
The JavaScript (Node.js 24+) and Python 3 examples are self-contained. Run them on your server and set the environment variables shown in the code.
JSON response · example JSON
{
"data": {
"id": "97616496-f557-4dc3-b035-f0020a965738",
"status": "cancelled",
"card_id": "e4babb11-474a-4132-93de-6611f03cb8f1",
"quote_id": "1dd27d46-ee33-4858-ba32-2ace6adf3b36",
"revision": 2,
"updated_at": "2026-11-05T00:13:44.647145+02:00",
"location_id": "9788420f-8230-4e89-a189-6e557783346e",
"external_ref": {
"id": "DOCS-CANCEL",
"source": "my_pos",
"account_id": "merchant-1",
"location_id": "store-1"
},
"review_reason": null,
"reserved_until": "2026-11-05T00:23:44.645222+02:00",
"transaction_id": null
}
}
Illustrative data from isolated checks. These identifiers do not belong to your account.