# Track the fulfillment of an order

> Send delivery progress for a paid order and read it back, without changing the payment.

Source: https://docs.tappay.mn/guides/fulfillment/

## Overview {#overview}

A [payment](https://docs.tappay.mn/glossary.md#payment) tells you that the money arrived. [Fulfillment](https://docs.tappay.mn/glossary.md#fulfillment) tells your [customer](https://docs.tappay.mn/glossary.md#customer) how the service is going, such as a delivery or a ticket booking. You send each update from your server, and it never changes the payment `status`.

## Before you begin {#before-you-begin}

Your key needs the `fulfillment:write` [scope](https://docs.tappay.mn/glossary.md#scope), and you use your [secret key](https://docs.tappay.mn/glossary.md#secret-key), shown below as `sk_test_YOUR_SECRET_KEY`. The example also creates and pays an [invoice](https://docs.tappay.mn/glossary.md#invoice), so the key needs `payments:write` too. Use a [sandbox](https://docs.tappay.mn/glossary.md#sandbox) key while you build.

## Steps {#steps}

### Create the invoice {#create-the-invoice}

Create an invoice as in the [QR payments guide](https://docs.tappay.mn/guides/qr-payments.md). Fulfillment opens only when the invoice is paid, so there is nothing to update yet. The response has the `invoiceId` and the `intentId` that you use next.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/invoices" \
  -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 '{"terminalId":"YOUR_TERMINAL_ID","amount":1000,"description":"Order 1","orderId":"order-'"$(uuidgen)"'"}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const invoice = await tappay.invoices.create({
  body: {
    terminalId: 'YOUR_TERMINAL_ID',
    amount: 1000,
    description: 'Order 1',
    orderId: `order-${crypto.randomUUID()}`,
  },
});
console.log(JSON.stringify(invoice));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$invoice = $tappay->invoices->create([
    'body' => [
        'terminalId' => 'YOUR_TERMINAL_ID',
        'amount' => 1000,
        'description' => 'Order 1',
        'orderId' => 'order-' . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)) . '',
    ],
]);
echo json_encode($invoice);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
invoice = client.invoices.create({
    "body": {
        "terminalId": "YOUR_TERMINAL_ID",
        "amount": 1000,
        "description": "Order 1",
        "orderId": "order-" + str(uuid.uuid4()) + "",
    },
})
print(json.dumps(invoice))
```

### Pay in the sandbox {#pay-in-the-sandbox}

Let the [simulator](https://docs.tappay.mn/glossary.md#simulator) pay the invoice for the customer. This works only with a sandbox key. When the invoice is paid, TapPay opens its fulfillment with the status `PENDING`.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/sandbox/intents/INTENT_ID/simulate" \
  -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 '{"channel":"QR","outcome":"SUCCEEDED"}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const result = await tappay.sandbox.simulateIntent({ id: 'INTENT_ID', body: { channel: 'QR', outcome: 'SUCCEEDED' } });
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->sandbox->simulateIntent(['id' => 'INTENT_ID', 'body' => ['channel' => 'QR', 'outcome' => 'SUCCEEDED']]);
echo json_encode($result);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
result = client.sandbox.simulate_intent({"id": "INTENT_ID", "body": {"channel": "QR", "outcome": "SUCCEEDED"}})
print(json.dumps(result))
```

### Start the fulfillment {#start-the-fulfillment}

Send the `status` `IN_PROGRESS` with a `stage` and a `message` in your own words. The `stage` uses capital letters, digits and underscores, up to 64 characters. The `message` can have up to 500 characters. TapPay does not explain either one to the customer.

```bash title="curl"
curl -sS -X PUT "https://api.tappay.mn/api/v1/invoices/INVOICE_ID/fulfillment" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Content-Type: application/json" \
  -d '{"status":"IN_PROGRESS","stage":"OUT_FOR_DELIVERY","message":"The order is on its way."}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const invoice = await tappay.invoices.putFulfillment({
  id: 'INVOICE_ID',
  body: {
    status: 'IN_PROGRESS',
    stage: 'OUT_FOR_DELIVERY',
    message: 'The order is on its way.',
  },
});
console.log(JSON.stringify(invoice));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$invoice = $tappay->invoices->putFulfillment([
    'id' => 'INVOICE_ID',
    'body' => [
        'status' => 'IN_PROGRESS',
        'stage' => 'OUT_FOR_DELIVERY',
        'message' => 'The order is on its way.',
    ],
]);
echo json_encode($invoice);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
invoice = client.invoices.put_fulfillment({
    "id": "INVOICE_ID",
    "body": {
        "status": "IN_PROGRESS",
        "stage": "OUT_FOR_DELIVERY",
        "message": "The order is on its way.",
    },
})
print(json.dumps(invoice))
```

### Finish the fulfillment {#finish-the-fulfillment}

When you deliver the order, send `COMPLETED`. If you cannot deliver it, send `FAILED` or `CANCELLED` with a `message` that explains why. These three statuses are final, so you cannot change them later.

```bash title="curl"
curl -sS -X PUT "https://api.tappay.mn/api/v1/invoices/INVOICE_ID/fulfillment" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Content-Type: application/json" \
  -d '{"status":"COMPLETED","stage":"DELIVERED","message":"The order was delivered."}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const invoice = await tappay.invoices.putFulfillment({
  id: 'INVOICE_ID',
  body: {
    status: 'COMPLETED',
    stage: 'DELIVERED',
    message: 'The order was delivered.',
  },
});
console.log(JSON.stringify(invoice));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$invoice = $tappay->invoices->putFulfillment([
    'id' => 'INVOICE_ID',
    'body' => [
        'status' => 'COMPLETED',
        'stage' => 'DELIVERED',
        'message' => 'The order was delivered.',
    ],
]);
echo json_encode($invoice);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
invoice = client.invoices.put_fulfillment({
    "id": "INVOICE_ID",
    "body": {
        "status": "COMPLETED",
        "stage": "DELIVERED",
        "message": "The order was delivered.",
    },
})
print(json.dumps(invoice))
```

### Read the fulfillment {#read-the-fulfillment}

Read the invoice and check `fulfillment`. It has the `status`, your `stage` and `message`, and `updatedAt`. Reading a payment of the invoice returns the same object.

```bash title="curl"
curl -sS "https://api.tappay.mn/api/v1/invoices/INVOICE_ID" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27"
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const invoice = await tappay.invoices.retrieve({ id: 'INVOICE_ID' });
console.log(JSON.stringify(invoice));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$invoice = $tappay->invoices->retrieve(['id' => 'INVOICE_ID']);
echo json_encode($invoice);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
invoice = client.invoices.retrieve({"id": "INVOICE_ID"})
print(json.dumps(invoice))
```

> **Note:** **A payment without an invoice**
>
> A payment that belongs to an invoice follows the fulfillment of that invoice. Only a payment without an invoice, such as a POS payment, has its own fulfillment. Set it with [Set payment fulfillment](https://docs.tappay.mn/reference/fulfillment/put-payment.md). TapPay rejects that call for a payment that has an invoice.

## Verify {#verify}

Read the invoice with `GET` and check `fulfillment.status`. It starts as `PENDING`, moves to `IN_PROGRESS` and ends as `COMPLETED`, `FAILED` or `CANCELLED`. The payment `status` stays `SUCCEEDED` in every case. TapPay sends the `fulfillment.updated` [event](https://docs.tappay.mn/glossary.md#event) to the wallet of the customer, and it does not send it to your own [webhook endpoint](https://docs.tappay.mn/glossary.md#webhook-endpoint).

## Common mistakes {#common-mistakes}

- Updating the fulfillment before the invoice is paid. It opens only when the invoice closes, so TapPay rejects the call until then.
- Reading `FAILED` as a failed payment. The payment stays `SUCCEEDED`. To return the money, make a [refund](https://docs.tappay.mn/glossary.md#refund) as in the [refunds guide](https://docs.tappay.mn/guides/refunds.md).
- Changing a final status. `COMPLETED`, `FAILED` and `CANCELLED` cannot move to another status, and TapPay rejects the update.
- Sending a `stage` with lowercase letters or spaces. Use capital letters, digits and underscores, such as `OUT_FOR_DELIVERY`.
- Waiting for a webhook about your own update. TapPay sends `fulfillment.updated` only to the wallet, so read the status with `GET` instead.

## Next steps {#next-steps}

Return money for an order you could not deliver with the [refunds guide](https://docs.tappay.mn/guides/refunds.md). See every field in [Set invoice fulfillment](https://docs.tappay.mn/reference/fulfillment/put-invoice.md), [Set payment fulfillment](https://docs.tappay.mn/reference/fulfillment/put-payment.md) and [Retrieve an invoice](https://docs.tappay.mn/reference/invoices/get.md).
