# Issue and return tax receipts

> Send the eBarimt receipt that your merchant issues for a payment, follow its status, and return it after a refund.

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

## Overview {#overview}

A [receipt](https://docs.tappay.mn/glossary.md#receipt) is the tax receipt, called eBarimt, of a [payment](https://docs.tappay.mn/glossary.md#payment). The [receipt issuer](https://docs.tappay.mn/glossary.md#receipt-issuer) of your merchant decides who creates it. This guide covers the `MERCHANT` issuer, where you issue the receipt yourself and send it to TapPay.

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

Your key needs `ebarimt:write`, `checkout:write` and `refunds:write` in its [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`. Use a [sandbox](https://docs.tappay.mn/glossary.md#sandbox) key while you build. The issuer of your merchant must be `MERCHANT`. With `NODE`, TapPay issues the receipt, and with `NONE` you send a sales receipt or no receipt. `MERCHANT` and `NODE` never work together. With `NODE`, a missing `defaultClassificationCode` or `defaultItemName` returns `422`, and so does a branch without `branch_no`, `city` or `district`.

## Steps {#steps}

### Create a payment {#create-a-payment}

A receipt belongs to a payment that has succeeded. Create a [checkout session](https://docs.tappay.mn/glossary.md#checkout-session) as in the [checkout guide](https://docs.tappay.mn/guides/checkout.md#create-the-session).

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/checkout/sessions" \
  -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)"'","returnUrl":"https://example.com/return","cancelUrl":"https://example.com/cancel"}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const checkoutSession = await tappay.checkoutSessions.create({
  body: {
    terminalId: 'YOUR_TERMINAL_ID',
    amount: '1000',
    description: 'Order 1',
    orderId: `order-${crypto.randomUUID()}`,
    returnUrl: 'https://example.com/return',
    cancelUrl: 'https://example.com/cancel',
  },
});
console.log(JSON.stringify(checkoutSession));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$checkoutSession = $tappay->checkoutSessions->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)) . '',
        'returnUrl' => 'https://example.com/return',
        'cancelUrl' => 'https://example.com/cancel',
    ],
]);
echo json_encode($checkoutSession);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
checkout_session = client.checkout_sessions.create({
    "body": {
        "terminalId": "YOUR_TERMINAL_ID",
        "amount": "1000",
        "description": "Order 1",
        "orderId": "order-" + str(uuid.uuid4()) + "",
        "returnUrl": "https://example.com/return",
        "cancelUrl": "https://example.com/cancel",
    },
})
print(json.dumps(checkout_session))
```

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

Let the [simulator](https://docs.tappay.mn/glossary.md#simulator) pay for the [customer](https://docs.tappay.mn/glossary.md#customer). The response has the `id` of the payment, and every later step uses it.

```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))
```

### Send your receipt {#send-your-receipt}

Send the receipt that you issued. Use `receiptKind` `WITH_EBARIMT` and `receiptType` `B2C` for a consumer or `B2B` for an organization, with the `ddtd`, `amount`, `issuedAt` and `lines`. For a sales receipt, use `WITHOUT_EBARIMT` and `receiptType` `SALES`, without `ddtd` or `lottery`. The receipt is `PENDING` after you send it. It becomes `FAILED` with `MERCHANT_TIMEOUT` when `ebarimt_merchant_timeout`, 24 hours, passes.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/payments/PAYMENT_ID/receipt" \
  -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 '{"receiptKind":"WITH_EBARIMT","receiptType":"B2C","ddtd":"DDTD-EXAMPLE-0001","merchantReceiptNo":"rcpt-'"$(uuidgen)"'","amount":"1000","vat":"90.91","issuedAt":"2026-10-03T10:00:00Z","lines":[{"name":"Order 1","quantity":"1","unitPrice":"1000","totalAmount":"1000"}]}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const receipt = await tappay.receipts.submit({
  id: 'PAYMENT_ID',
  body: {
    receiptKind: 'WITH_EBARIMT',
    receiptType: 'B2C',
    ddtd: 'DDTD-EXAMPLE-0001',
    merchantReceiptNo: `rcpt-${crypto.randomUUID()}`,
    amount: '1000',
    vat: '90.91',
    issuedAt: '2026-10-03T10:00:00Z',
    lines: [
      {
        name: 'Order 1',
        quantity: '1',
        unitPrice: '1000',
        totalAmount: '1000',
      },
    ],
  },
});
console.log(JSON.stringify(receipt));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$receipt = $tappay->receipts->submit([
    'id' => 'PAYMENT_ID',
    'body' => [
        'receiptKind' => 'WITH_EBARIMT',
        'receiptType' => 'B2C',
        'ddtd' => 'DDTD-EXAMPLE-0001',
        'merchantReceiptNo' => 'rcpt-' . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)) . '',
        'amount' => '1000',
        'vat' => '90.91',
        'issuedAt' => '2026-10-03T10:00:00Z',
        'lines' => [
            [
                'name' => 'Order 1',
                'quantity' => '1',
                'unitPrice' => '1000',
                'totalAmount' => '1000',
            ],
        ],
    ],
]);
echo json_encode($receipt);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
receipt = client.receipts.submit({
    "id": "PAYMENT_ID",
    "body": {
        "receiptKind": "WITH_EBARIMT",
        "receiptType": "B2C",
        "ddtd": "DDTD-EXAMPLE-0001",
        "merchantReceiptNo": "rcpt-" + str(uuid.uuid4()) + "",
        "amount": "1000",
        "vat": "90.91",
        "issuedAt": "2026-10-03T10:00:00Z",
        "lines": [
            {
                "name": "Order 1",
                "quantity": "1",
                "unitPrice": "1000",
                "totalAmount": "1000",
            },
        ],
    },
})
print(json.dumps(receipt))
```

### Set the result in the sandbox {#set-the-result-in-the-sandbox}

The sandbox can set the registration result, but only while a receipt is `PENDING`. With the `MERCHANT` issuer you register the receipt yourself, so the sandbox accepts only `MERCHANT_TIMEOUT` for a `PENDING` receipt, which turns it into `FAILED`. The outcomes `REGISTERED` and `FAILED` are for the `NODE` issuer. This receipt is already `REGISTERED`, so the call below returns `422` with `AFP-151`.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/sandbox/payments/PAYMENT_ID/ebarimt" \
  -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 '{"outcome":"REGISTERED"}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
try {
  const result = await tappay.sandbox.simulateEbarimt({ id: 'PAYMENT_ID', body: { outcome: 'REGISTERED' } });
  console.log(JSON.stringify(result));
} catch (e) {
  if (!(e instanceof TapPayError)) throw e;
  console.log(JSON.stringify({ error: { code: e.code, status: e.status } }));
}
```

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

use TapPay\TapPay;
use TapPay\Exception\TapPayError;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
try {
    $result = $tappay->sandbox->simulateEbarimt(['id' => 'PAYMENT_ID', 'body' => ['outcome' => 'REGISTERED']]);
    echo json_encode($result);
} catch (TapPayError $e) {
    echo json_encode(['error' => ['code' => $e->code, 'status' => $e->status]]);
}
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
try:
    result = client.sandbox.simulate_ebarimt({"id": "PAYMENT_ID", "body": {"outcome": "REGISTERED"}})
    print(json.dumps(result))
except tappay.TapPayError as e:
    print(json.dumps({"error": {"code": e.code, "status": e.status}}))
```

### Refund the payment {#refund-the-payment}

A receipt is returned after a [refund](https://docs.tappay.mn/glossary.md#refund). This example refunds the full paid amount of 1000. The response is `202`, and the refund `status` starts as `PENDING`. TapPay sends `ebarimt.return_requested` for the receipt. Before a refund, returning the receipt gives `409` `AFP-056`.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/payments/PAYMENT_ID/refunds" \
  -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 '{"amount":"1000","reason":"Customer returned an item"}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const refund = await tappay.refunds.create({ paymentId: 'PAYMENT_ID', body: { amount: '1000', reason: 'Customer returned an item' } });
console.log(JSON.stringify(refund));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$refund = $tappay->refunds->create([
    'paymentId' => 'PAYMENT_ID',
    'body' => [
        'amount' => '1000',
        'reason' => 'Customer returned an item',
    ],
]);
echo json_encode($refund);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
refund = client.refunds.create({"paymentId": "PAYMENT_ID", "body": {"amount": "1000", "reason": "Customer returned an item"}})
print(json.dumps(refund))
```

### Return the receipt {#return-the-receipt}

After a [refund](https://docs.tappay.mn/glossary.md#refund), return the old receipt. To issue a new one for the new amount, send it as the `replacement`. Without a `replacement`, the receipt is only returned. The returned receipt becomes `RETURNED`, and the new receipt becomes the current `receipt`.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/payments/PAYMENT_ID/receipt/return" \
  -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 '{"returnedAt":"2026-10-03T11:00:00Z"}'
```

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

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const receipt = await tappay.receipts.createReturn({ id: 'PAYMENT_ID', body: { returnedAt: '2026-10-03T11:00:00Z' } });
console.log(JSON.stringify(receipt));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$receipt = $tappay->receipts->createReturn(['id' => 'PAYMENT_ID', 'body' => ['returnedAt' => '2026-10-03T11:00:00Z']]);
echo json_encode($receipt);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
receipt = client.receipts.create_return({"id": "PAYMENT_ID", "body": {"returnedAt": "2026-10-03T11:00:00Z"}})
print(json.dumps(receipt))
```

## Verify {#verify}

A receipt has `status` `PENDING`, `REGISTERED`, `FAILED` or `RETURNED`. TapPay sends these merchant [events](https://docs.tappay.mn/glossary.md#event) for the `MERCHANT` issuer. `ebarimt.receipt_requested` asks for your receipt, and `ebarimt.return_requested` asks you to return it after a refund. `ebarimt.issued`, `ebarimt.returned` and `ebarimt.failed` show the result. The `receipt.*` events belong to the payer's wallet, so you do not receive them.

TapPay issues one receipt for each payment, when the payment succeeds, and does not wait for the [invoice](https://docs.tappay.mn/glossary.md#invoice) to close. A [split](https://docs.tappay.mn/glossary.md#split) payment has a receipt for each part. After a payment, TapPay sends you the recipient, which is a citizen, an organization or none, and the e-mail address when you send the e-mail. Make your receipt for that recipient.

A [pre-auth](https://docs.tappay.mn/glossary.md#pre-auth) payment gets its receipt after [finalize](https://docs.tappay.mn/glossary.md#finalize), for the final amount.

Read the receipt of the payment. The response has the current `receipt` and a `history` of the receipts that were returned before. It returns `404` when the payment has no receipt.

```bash title="curl"
curl -sS "https://api.tappay.mn/api/v1/payments/PAYMENT_ID/receipt" \
  -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 receipt = await tappay.receipts.retrieve({ id: 'PAYMENT_ID' });
console.log(JSON.stringify(receipt));
```

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

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$receipt = $tappay->receipts->retrieve(['id' => 'PAYMENT_ID']);
echo json_encode($receipt);
```

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

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
receipt = client.receipts.retrieve({"id": "PAYMENT_ID"})
print(json.dumps(receipt))
```

## Common mistakes {#common-mistakes}

- Treating `PENDING` as a failure. The receipt stays `PENDING` until it is registered, and only `FAILED` is final.
- Not sending the receipt in time. After 24 hours the receipt becomes `FAILED` with `MERCHANT_TIMEOUT`, and TapPay sends `ebarimt.failed`.
- Changing a receipt after a refund. eBarimt does not reduce a receipt in part, so return it and send a new one for the new amount.
- Issuing the receipt yourself while the issuer is `NODE`. The `MERCHANT` and `NODE` issuers cannot work at the same time.
- Leaving `defaultClassificationCode`, `defaultItemName` or the branch fields empty for `NODE`. TapPay returns `422`.
- Waiting for `receipt.*` events. Those events are for the payer's wallet, and you receive `ebarimt.*` events.

## Next steps {#next-steps}

Return a receipt after a [refund](https://docs.tappay.mn/guides/refunds.md), and follow `ebarimt.*` events with the [webhooks guide](https://docs.tappay.mn/guides/webhooks.md). See [Submit a receipt](https://docs.tappay.mn/reference/receipts/submit.md), [Retrieve a receipt](https://docs.tappay.mn/reference/receipts/get.md), [Return a receipt](https://docs.tappay.mn/reference/receipts/return.md) and [Simulate eBarimt](https://docs.tappay.mn/reference/sandbox/simulate-ebarimt.md).
