Issue and return tax receipts
Overview
A receipt is the tax receipt, called eBarimt, of a payment. The 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
Your key needs ebarimt:write, checkout:write and refunds:write in its scope, and you use your secret key, shown below as sk_test_YOUR_SECRET_KEY. Use a 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
Create a payment
A receipt belongs to a payment that has succeeded. Create a checkout session as in the checkout guide.
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"}'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
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);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
Let the simulator pay for the customer. The response has the id of the payment, and every later step uses it.
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"}'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
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);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 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.
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"}]}'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
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);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
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.
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"}'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
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]]);
}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
A receipt is returned after a 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.
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"}'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
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);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
After a 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.
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"}'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
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);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
A receipt has status PENDING, REGISTERED, FAILED or RETURNED. TapPay sends these merchant events 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 to close. A 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 payment gets its receipt after 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.
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"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
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);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
- Treating
PENDINGas a failure. The receipt staysPENDINGuntil it is registered, and onlyFAILEDis final. - Not sending the receipt in time. After 24 hours the receipt becomes
FAILEDwithMERCHANT_TIMEOUT, and TapPay sendsebarimt.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. TheMERCHANTandNODEissuers cannot work at the same time. - Leaving
defaultClassificationCode,defaultItemNameor the branch fields empty forNODE. TapPay returns422. - Waiting for
receipt.*events. Those events are for the payer’s wallet, and you receiveebarimt.*events.
Next steps
Return a receipt after a refund, and follow ebarimt.* events with the webhooks guide. See Submit a receipt, Retrieve a receipt, Return a receipt and Simulate eBarimt.