Skip to content

Cancel an order

View as Markdown

Cancels an order before it is completed. If the customer has paid, TapPay refunds the full amount.

Changes in 2026-09-27

POST /api/v1/commerce/orders/{order_id}/cancelSince 2026-09-27

Authentication

Secret key (Bearer)

Headers

NameTypeRequiredValuesDescription
TapPay-Versionstringno
TapPay-Timestampstringno
TapPay-Noncestringno
TapPay-Signaturestringno
Idempotency-Keystringyes

Path parameters

NameTypeRequiredValuesDescription
order_idstring (uuid)yes

Request body

NameTypeRequiredValuesDescription
reason_codestringyes
messagestringno

Response 200

NameTypeRequiredValuesDescription
successbooleanyestrue
dataobjectyes
data.order_idstring (uuid)yes
data.order_nostringyes
data.channelstringyes
data.statusstringyesCREATED, ACCEPTED, AWAITING_PAYMENT, CONFIRMED, IN_PROGRESS, READY, COMPLETED, CANCELLED, REJECTED, EXPIRED, FAILED
data.versionintegeryes
data.merchantobjectyes
data.merchant.merchant_codestringyes
data.merchant.namestringyes
data.location_idstring (uuid)yes
data.fulfillmentobjectyes
data.fulfillment.modestringyes
data.fulfillment.labelstringyes
data.fulfillment.addressobject | nullyes
data.fulfillment.address.labelstring | nullyes
data.fulfillment.address.textstringyes
data.fulfillment.address.entrancestring | nullno
data.fulfillment.address.floorstring | nullno
data.fulfillment.address.doorstring | nullno
data.fulfillment.address.notestring | nullno
data.fulfillment.address.locationobject | nullyes
data.fulfillment.address.location.latnumberyes
data.fulfillment.address.location.lngnumberyes
data.fulfillment.address.districtstring | nullno
data.fulfillment.address.khoroostring | nullno
data.fulfillment.scheduled_atstring | nullyes
data.fulfillment.ends_atstring | nullyes
data.linesarray<object>yes
data.lines[].line_idstringyes
data.lines[].offering_idstringyes
data.lines[].namestringyes
data.lines[].quantityintegeryes
data.lines[].variant_idstring | nullyes
data.lines[].option_idsarray<string>yes
data.lines[].inputsobjectyes
data.lines[].amountnumberyes
data.lines[].statusstringyes
data.lines[].final_amountnumber | nullyes
data.breakuparray<object>yes
data.breakup[].kindstringyes
data.breakup[].labelstringyes
data.breakup[].amountnumberyes
data.breakup[].refstring | nullno
data.totalnumberyes
data.feesarray<object>yes
data.fees[].kindstringyes
data.fees[].labelstringyes
data.fees[].amountnumberyes
data.fees[].estimatedbooleanyes
data.payable_totalnumberyes
data.authorization_typestringyes
data.authorization_amountnumber | nullyes
data.accepted_totalnumber | nullyes
data.final_amountnumber | nullyes
data.stageobject | nullyes
data.stage.codestringyes
data.stage.labelstringyes
data.stage.descriptionstring | nullno
data.timelinearray<object>yes
data.timeline[].atstringyes
data.timeline[].labelstringyes
data.timeline[].statusstring | nullno
data.eta_atstring | nullyes
data.trackingobject | nullyes
data.tracking.agentobject | nullyes
data.tracking.agent.namestringyes
data.tracking.agent.phone_maskedstring | nullyes
data.tracking.agent.photo_urlstring | nullyes
data.tracking.agent.provider_labelstring | nullyes
data.tracking.locationobject | nullyes
data.tracking.location.latnumberyes
data.tracking.location.lngnumberyes
data.tracking.location.atstringyes
data.tracking.eta_atstring | nullyes
data.tracking.tracking_urlstring | nullyes
data.tracking.static_map_urlstring | nullyes
data.artifactsarray<object>yes
data.artifacts[].artifact_idstringyes
data.artifacts[].kindstringyes
data.artifacts[].labelstringyes
data.artifacts[].valuestring | nullno
data.artifacts[].urlstring | nullno
data.artifacts[].valid_fromstring | nullno
data.artifacts[].valid_tostring | nullno
data.artifacts[].fallback_urlstringyes
data.actionsarray<object>yes
data.actions[].kindstringyes
data.actions[].allowedbooleanyes
data.actions[].deadlinestringno
data.actions[].labelstringyes
data.actions[].urlstringno
data.next_actionobject | nullyes
data.next_action.typestringyes
data.next_action.intent_idstringno
data.next_action.diffobjectno
data.next_action.diff.linesarray<object>yes
data.next_action.diff.lines[].offering_idstringyes
data.next_action.diff.lines[].beforeobject | nullyes
data.next_action.diff.lines[].before.quantityintegeryes
data.next_action.diff.lines[].before.amountnumberyes
data.next_action.diff.lines[].afterobject | nullyes
data.next_action.diff.lines[].after.quantityintegeryes
data.next_action.diff.lines[].after.amountnumberyes
data.next_action.diff.total_beforenumberyes
data.next_action.diff.total_afternumberyes
data.next_action.diff.scheduleobjectno
data.next_action.diff.schedule.beforeobjectyes
data.next_action.diff.schedule.before.scheduled_atstring | nullyes
data.next_action.diff.schedule.before.ends_atstring | nullno
data.next_action.diff.schedule.afterobjectyes
data.next_action.diff.schedule.after.scheduled_atstring | nullyes
data.next_action.diff.schedule.after.ends_atstring | nullno
data.next_action.urlstringno
data.next_action.untilstringno
data.web_urlstringyes
data.payment_idstring | nullyes
data.cancelled_bystring | nullyes
data.reason_codestring | nullyes
data.created_atstringyes
data.updated_atstringyes
data.promotionsarray<object>no
data.promotions[].promotion_idstring (uuid)yes
data.promotions[].kindstringyes
data.promotions[].amountnumberyes
data.customerobjectyes
data.customer.contact_namestring | nullyes
data.customer.contact_phonestring | nullyes
data.notestring | nullyes
data.accept_due_atstring | nullyes
data.pending_rescheduleobject | nullyes
data.pending_reschedule.scheduled_atstringyes
data.pending_reschedule.ends_atstring | nullyes
data.handler_systemstringyes
data.payment_due_atstring | nullyes
data.sourceobjectyes
data.source.channelstringyes
data.source.partner_namestring | nullyes
data.source.stickerobject | nullyes
data.source.sticker.namestring | nullyes

Errors

CodeStatusMessage
AUTH-001401The API key is missing, invalid or revoked.
EVT-206401Production keys are not accepted in the sandbox. Use a sandbox key (sk_test_/pk_test_).
EVT-207401Sandbox keys are not accepted in production. Use a production key (sk_live_/pk_live_).
AUTH-018403The request came from an IP address that is not on the key's allowlist.
AUTH-058403The API key does not have the scope this operation requires.
SIG-002401The request timestamp is outside the allowed time window.
SIG-003401The request signature is missing or does not match.
SIG-005409This request nonce was already used.
VAL-014400The TapPay-Version header is not a known API version.
BIZ-004403The terminal is not active.
BIZ-005403The merchant account is not in a state that allows this request.
VAL-002400A required field or header is missing.
VAL-010409This Idempotency-Key was already used with a different request body.
VAL-013409A request with this Idempotency-Key is still being processed.
ORD-001409The order is not in a state that allows this action.
ORD-010403This order is handled by another system.
ORD-014404Order not found.
ORD-012409A payment is in progress. Wait for it to finish.
curl -sS -X POST "https://api.tappay.mn/api/v1/commerce/orders/ORDER_ID/cancel" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"reason_code":"OUT_OF_STOCK","message":"Milk ran out"}'
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const result = await tappay.commerce.cancel({ order_id: 'ORDER_ID', body: { reason_code: 'OUT_OF_STOCK', message: 'Milk ran out' } });
console.log(JSON.stringify(result));
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$result = $tappay->commerce->cancel([
    'order_id' => 'ORDER_ID',
    'body' => [
        'reason_code' => 'OUT_OF_STOCK',
        'message' => 'Milk ran out',
    ],
]);
echo json_encode($result);
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
result = client.commerce.cancel({"order_id": "ORDER_ID", "body": {"reason_code": "OUT_OF_STOCK", "message": "Milk ran out"}})
print(json.dumps(result))
{
  "success": true,
  "data": {
    "order_id": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9f02",
    "order_no": "A-1001",
    "channel": "WALLET",
    "status": "CANCELLED",
    "version": 5,
    "merchant": {
      "merchant_code": "M-SANDBOX-01",
      "name": "Sandbox Cafe"
    },
    "location_id": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9f01",
    "fulfillment": {
      "mode": "PICKUP",
      "label": "Pickup",
      "address": null,
      "scheduled_at": null,
      "ends_at": null
    },
    "lines": [
      {
        "line_id": "l1",
        "offering_id": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9f03",
        "name": "Latte (M)",
        "quantity": 2,
        "variant_id": null,
        "option_ids": [],
        "inputs": {},
        "amount": 18000,
        "status": "ACTIVE",
        "final_amount": null
      }
    ],
    "breakup": [
      {
        "kind": "ITEM",
        "label": "Latte (M) x 2",
        "amount": 18000,
        "ref": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9f03"
      }
    ],
    "total": 18000,
    "fees": [],
    "payable_total": 18000,
    "authorization_type": "FINAL",
    "authorization_amount": null,
    "accepted_total": 18000,
    "final_amount": null,
    "stage": null,
    "timeline": [
      {
        "at": "2026-10-03T08:15:00.000Z",
        "label": "Order created",
        "status": "CREATED"
      },
      {
        "at": "2026-10-03T08:20:00.000Z",
        "label": "Order accepted",
        "status": "ACCEPTED"
      },
      {
        "at": "2026-10-03T08:20:00.000Z",
        "label": "Paid",
        "status": "CONFIRMED"
      },
      {
        "at": "2026-10-03T08:35:00.000Z",
        "label": "Cancelled by the merchant",
        "status": "CANCELLED"
      }
    ],
    "eta_at": null,
    "tracking": null,
    "artifacts": [],
    "actions": [],
    "next_action": null,
    "web_url": "https://pay.tappay.mn/o/ord_7f3k2m9q",
    "payment_id": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9f04",
    "cancelled_by": "MERCHANT",
    "reason_code": "OUT_OF_STOCK",
    "created_at": "2026-10-03T08:15:00.000Z",
    "updated_at": "2026-10-03T08:35:00.000Z",
    "promotions": [],
    "customer": {
      "contact_name": "Bat",
      "contact_phone": "+97699000000"
    },
    "note": null,
    "accept_due_at": null,
    "pending_reschedule": null,
    "handler_system": "MERCHANT_SYSTEM",
    "payment_due_at": null,
    "source": {
      "channel": "WALLET",
      "partner_name": "Sandbox Bank",
      "sticker": null
    }
  }
}

For the full flow, read the orders guide.