# Захиалга дуусгах

> Захиалгыг дууссан болгож, pre-auth төлбөрийг эцэслэнэ.

Эх: https://docs.tappay.mn/mn/reference/orders/complete/

Захиалгыг дууссан болгоно. [Pre-auth](https://docs.tappay.mn/mn/glossary.md#pre-auth) захиалгад `final_lines` илгээвэл TapPay [төлбөрийг](https://docs.tappay.mn/mn/glossary.md#payment) тэдгээрийн нийлбэрээр эцэслэнэ.

`POST /api/v1/commerce/orders/{order_id}/complete` Хувилбар 2026-09-27

### Нэвтрэлт

Secret key (Bearer)

### Header

| Нэр | Төрөл | Заавал | Утга | Тайлбар |
| - | - | - | - | - |
| `TapPay-Version` | string | үгүй | | |
| `TapPay-Timestamp` | string | үгүй | | |
| `TapPay-Nonce` | string | үгүй | | |
| `TapPay-Signature` | string | үгүй | | |
| `Idempotency-Key` | string | тийм | | |

### Замын параметр

| Нэр | Төрөл | Заавал | Утга | Тайлбар |
| - | - | - | - | - |
| `order_id` | string (uuid) | тийм | | |

### Хүсэлтийн бие

| Нэр | Төрөл | Заавал | Утга | Тайлбар |
| - | - | - | - | - |
| `final_lines` | array\<object> | үгүй | | |
| `final_lines[].line_id` | string | үгүй | | |
| `final_lines[].offering_id` | string (uuid) | тийм | | |
| `final_lines[].quantity` | integer | тийм | | |
| `final_lines[].amount` | integer | тийм | | |

### Хариу 200

| Нэр | Төрөл | Заавал | Утга | Тайлбар |
| - | - | - | - | - |
| `success` | boolean | тийм | `true` | |
| `data` | object | тийм | | |
| `data.order_id` | string (uuid) | тийм | | |
| `data.order_no` | string | тийм | | |
| `data.channel` | string | тийм | | |
| `data.status` | string | тийм | `CREATED`, `ACCEPTED`, `AWAITING_PAYMENT`, `CONFIRMED`, `IN_PROGRESS`, `READY`, `COMPLETED`, `CANCELLED`, `REJECTED`, `EXPIRED`, `FAILED` | |
| `data.version` | integer | тийм | | |
| `data.merchant` | object | тийм | | |
| `data.merchant.merchant_code` | string | тийм | | |
| `data.merchant.name` | string | тийм | | |
| `data.location_id` | string (uuid) | тийм | | |
| `data.fulfillment` | object | тийм | | |
| `data.fulfillment.mode` | string | тийм | | |
| `data.fulfillment.label` | string | тийм | | |
| `data.fulfillment.address` | object \| null | тийм | | |
| `data.fulfillment.address.label` | string \| null | тийм | | |
| `data.fulfillment.address.text` | string | тийм | | |
| `data.fulfillment.address.entrance` | string \| null | үгүй | | |
| `data.fulfillment.address.floor` | string \| null | үгүй | | |
| `data.fulfillment.address.door` | string \| null | үгүй | | |
| `data.fulfillment.address.note` | string \| null | үгүй | | |
| `data.fulfillment.address.location` | object \| null | тийм | | |
| `data.fulfillment.address.location.lat` | number | тийм | | |
| `data.fulfillment.address.location.lng` | number | тийм | | |
| `data.fulfillment.address.district` | string \| null | үгүй | | |
| `data.fulfillment.address.khoroo` | string \| null | үгүй | | |
| `data.fulfillment.scheduled_at` | string \| null | тийм | | |
| `data.fulfillment.ends_at` | string \| null | тийм | | |
| `data.lines` | array\<object> | тийм | | |
| `data.lines[].line_id` | string | тийм | | |
| `data.lines[].offering_id` | string | тийм | | |
| `data.lines[].name` | string | тийм | | |
| `data.lines[].quantity` | integer | тийм | | |
| `data.lines[].variant_id` | string \| null | тийм | | |
| `data.lines[].option_ids` | array\<string> | тийм | | |
| `data.lines[].inputs` | object | тийм | | |
| `data.lines[].amount` | number | тийм | | |
| `data.lines[].status` | string | тийм | | |
| `data.lines[].final_amount` | number \| null | тийм | | |
| `data.breakup` | array\<object> | тийм | | |
| `data.breakup[].kind` | string | тийм | | |
| `data.breakup[].label` | string | тийм | | |
| `data.breakup[].amount` | number | тийм | | |
| `data.breakup[].ref` | string \| null | үгүй | | |
| `data.total` | number | тийм | | |
| `data.fees` | array\<object> | тийм | | |
| `data.fees[].kind` | string | тийм | | |
| `data.fees[].label` | string | тийм | | |
| `data.fees[].amount` | number | тийм | | |
| `data.fees[].estimated` | boolean | тийм | | |
| `data.payable_total` | number | тийм | | |
| `data.authorization_type` | string | тийм | | |
| `data.authorization_amount` | number \| null | тийм | | |
| `data.accepted_total` | number \| null | тийм | | |
| `data.final_amount` | number \| null | тийм | | |
| `data.stage` | object \| null | тийм | | |
| `data.stage.code` | string | тийм | | |
| `data.stage.label` | string | тийм | | |
| `data.stage.description` | string \| null | үгүй | | |
| `data.timeline` | array\<object> | тийм | | |
| `data.timeline[].at` | string | тийм | | |
| `data.timeline[].label` | string | тийм | | |
| `data.timeline[].status` | string \| null | үгүй | | |
| `data.eta_at` | string \| null | тийм | | |
| `data.tracking` | object \| null | тийм | | |
| `data.tracking.agent` | object \| null | тийм | | |
| `data.tracking.agent.name` | string | тийм | | |
| `data.tracking.agent.phone_masked` | string \| null | тийм | | |
| `data.tracking.agent.photo_url` | string \| null | тийм | | |
| `data.tracking.agent.provider_label` | string \| null | тийм | | |
| `data.tracking.location` | object \| null | тийм | | |
| `data.tracking.location.lat` | number | тийм | | |
| `data.tracking.location.lng` | number | тийм | | |
| `data.tracking.location.at` | string | тийм | | |
| `data.tracking.eta_at` | string \| null | тийм | | |
| `data.tracking.tracking_url` | string \| null | тийм | | |
| `data.tracking.static_map_url` | string \| null | тийм | | |
| `data.artifacts` | array\<object> | тийм | | |
| `data.artifacts[].artifact_id` | string | тийм | | |
| `data.artifacts[].kind` | string | тийм | | |
| `data.artifacts[].label` | string | тийм | | |
| `data.artifacts[].value` | string \| null | үгүй | | |
| `data.artifacts[].url` | string \| null | үгүй | | |
| `data.artifacts[].valid_from` | string \| null | үгүй | | |
| `data.artifacts[].valid_to` | string \| null | үгүй | | |
| `data.artifacts[].fallback_url` | string | тийм | | |
| `data.actions` | array\<object> | тийм | | |
| `data.actions[].kind` | string | тийм | | |
| `data.actions[].allowed` | boolean | тийм | | |
| `data.actions[].deadline` | string | үгүй | | |
| `data.actions[].label` | string | тийм | | |
| `data.actions[].url` | string | үгүй | | |
| `data.next_action` | object \| null | тийм | | |
| `data.next_action.type` | string | тийм | | |
| `data.next_action.intent_id` | string | үгүй | | |
| `data.next_action.diff` | object | үгүй | | |
| `data.next_action.diff.lines` | array\<object> | тийм | | |
| `data.next_action.diff.lines[].offering_id` | string | тийм | | |
| `data.next_action.diff.lines[].before` | object \| null | тийм | | |
| `data.next_action.diff.lines[].before.quantity` | integer | тийм | | |
| `data.next_action.diff.lines[].before.amount` | number | тийм | | |
| `data.next_action.diff.lines[].after` | object \| null | тийм | | |
| `data.next_action.diff.lines[].after.quantity` | integer | тийм | | |
| `data.next_action.diff.lines[].after.amount` | number | тийм | | |
| `data.next_action.diff.total_before` | number | тийм | | |
| `data.next_action.diff.total_after` | number | тийм | | |
| `data.next_action.diff.schedule` | object | үгүй | | |
| `data.next_action.diff.schedule.before` | object | тийм | | |
| `data.next_action.diff.schedule.before.scheduled_at` | string \| null | тийм | | |
| `data.next_action.diff.schedule.before.ends_at` | string \| null | үгүй | | |
| `data.next_action.diff.schedule.after` | object | тийм | | |
| `data.next_action.diff.schedule.after.scheduled_at` | string \| null | тийм | | |
| `data.next_action.diff.schedule.after.ends_at` | string \| null | үгүй | | |
| `data.next_action.url` | string | үгүй | | |
| `data.next_action.until` | string | үгүй | | |
| `data.web_url` | string | тийм | | |
| `data.payment_id` | string \| null | тийм | | |
| `data.cancelled_by` | string \| null | тийм | | |
| `data.reason_code` | string \| null | тийм | | |
| `data.created_at` | string | тийм | | |
| `data.updated_at` | string | тийм | | |
| `data.promotions` | array\<object> | үгүй | | |
| `data.promotions[].promotion_id` | string (uuid) | тийм | | |
| `data.promotions[].kind` | string | тийм | | |
| `data.promotions[].amount` | number | тийм | | |
| `data.customer` | object | тийм | | |
| `data.customer.contact_name` | string \| null | тийм | | |
| `data.customer.contact_phone` | string \| null | тийм | | |
| `data.note` | string \| null | тийм | | |
| `data.accept_due_at` | string \| null | тийм | | |
| `data.pending_reschedule` | object \| null | тийм | | |
| `data.pending_reschedule.scheduled_at` | string | тийм | | |
| `data.pending_reschedule.ends_at` | string \| null | тийм | | |
| `data.handler_system` | string | тийм | | |
| `data.payment_due_at` | string \| null | тийм | | |
| `data.source` | object | тийм | | |
| `data.source.channel` | string | тийм | | |
| `data.source.partner_name` | string \| null | тийм | | |
| `data.source.sticker` | object \| null | тийм | | |
| `data.source.sticker.name` | string \| null | тийм | | |

### Алдаа

| Код | Status | Мессеж |
| - | - | - |
| [`AUTH-001`](https://docs.tappay.mn/mn/errors.md#AUTH-001) | 401 | API key байхгүй, буруу эсвэл хүчингүй болсон байна. |
| [`EVT-206`](https://docs.tappay.mn/mn/errors.md#EVT-206) | 401 | Production key sandbox-д хүлээн авахгүй. Sandbox key (sk_test\_/pk_test\_) ашиглана уу. |
| [`EVT-207`](https://docs.tappay.mn/mn/errors.md#EVT-207) | 401 | Sandbox key production-д хүлээн авахгүй. Production key (sk_live\_/pk_live\_) ашиглана уу. |
| [`AUTH-018`](https://docs.tappay.mn/mn/errors.md#AUTH-018) | 403 | Хүсэлт түлхүүрийн зөвшөөрөгдсөн IP жагсаалтад ороогүй хаягаас ирсэн. |
| [`AUTH-058`](https://docs.tappay.mn/mn/errors.md#AUTH-058) | 403 | API key-д энэ үйлдэлд шаардлагатай scope байхгүй байна. |
| [`SIG-002`](https://docs.tappay.mn/mn/errors.md#SIG-002) | 401 | Хүсэлтийн цагийн тэмдэг зөвшөөрөгдсөн хугацааны гадна байна. |
| [`SIG-003`](https://docs.tappay.mn/mn/errors.md#SIG-003) | 401 | Хүсэлтийн гарын үсэг байхгүй эсвэл таарахгүй байна. |
| [`SIG-005`](https://docs.tappay.mn/mn/errors.md#SIG-005) | 409 | Энэ хүсэлтийн nonce өмнө нь ашиглагдсан байна. |
| [`VAL-014`](https://docs.tappay.mn/mn/errors.md#VAL-014) | 400 | TapPay-Version header нь мэдэгдэх API хувилбар биш байна. |
| [`BIZ-004`](https://docs.tappay.mn/mn/errors.md#BIZ-004) | 403 | Terminal идэвхгүй байна. |
| [`BIZ-005`](https://docs.tappay.mn/mn/errors.md#BIZ-005) | 403 | Мерчантын данс энэ хүсэлтийг зөвшөөрөх төлөвт байхгүй байна. |
| [`VAL-002`](https://docs.tappay.mn/mn/errors.md#VAL-002) | 400 | Заавал байх талбар эсвэл header дутуу байна. |
| [`VAL-010`](https://docs.tappay.mn/mn/errors.md#VAL-010) | 409 | Энэ Idempotency-Key өөр хүсэлтийн биетэй өмнө нь ашиглагдсан байна. |
| [`VAL-013`](https://docs.tappay.mn/mn/errors.md#VAL-013) | 409 | Энэ Idempotency-Key-тэй хүсэлт боловсруулагдаж байна. |
| [`ORD-001`](https://docs.tappay.mn/mn/errors.md#ORD-001) | 409 | Захиалгын төлөв энэ үйлдлийг зөвшөөрөхгүй. |
| [`ORD-010`](https://docs.tappay.mn/mn/errors.md#ORD-010) | 403 | Энэ захиалгыг өөр систем хүлээн авдаг. |
| [`ORD-014`](https://docs.tappay.mn/mn/errors.md#ORD-014) | 404 | Захиалга олдсонгүй. |

Playground-д туршиж үзэх: https://docs.tappay.mn/mn/reference/orders/complete/

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/commerce/orders/ORDER_ID/complete" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)"
```

```js title="Node.js"
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const result = await tappay.commerce.complete({ order_id: 'ORDER_ID' });
console.log(JSON.stringify(result));
```

```php title="PHP"
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$result = $tappay->commerce->complete(['order_id' => 'ORDER_ID']);
echo json_encode($result);
```

```python title="Python"
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
result = client.commerce.complete({"order_id": "ORDER_ID"})
print(json.dumps(result))
```

```json title="Response"
{
  "success": true,
  "data": {
    "order_id": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9f02",
    "order_no": "A-1001",
    "channel": "WALLET",
    "status": "COMPLETED",
    "version": 6,
    "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": 18000,
    "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": "Completed",
        "status": "COMPLETED"
      }
    ],
    "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": null,
    "reason_code": null,
    "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
    }
  }
}
```

Бүтэн урсгалыг [захиалгын гарын авлагаас](https://docs.tappay.mn/mn/guides/orders.md) үзнэ үү.
