Hold and finalize a payment with pre-auth
Overview
Pre-auth lets you reserve an amount when the final price is not known yet, such as a hotel stay. You create the invoice with authorizationType PREAUTH. Later you finalize the payment with the final amount.
Before you begin
Your key needs the payments:write scope, and you use your secret key, shown below as sk_test_YOUR_SECRET_KEY. Pre-auth must be switched on for your account: the preauth_enabled setting is granted by your partner or by TapPay, and without it TapPay returns 422 PRE-001. Use a sandbox key while you build.
Steps
Create a pre-auth invoice
Send authorizationType PREAUTH when you create the invoice. The optional preauthFinalizeDays sets how many days you have to finalize. If you leave it out, the default of 7 days applies, and your partner sets the highest value.
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":"Room deposit","orderId":"order-'"$(uuidgen)"'","authorizationType":"PREAUTH","preauthFinalizeDays":7}'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: 'Room deposit',
orderId: `order-${crypto.randomUUID()}`,
authorizationType: 'PREAUTH',
preauthFinalizeDays: 7,
},
});
console.log(JSON.stringify(invoice));<?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' => 'Room deposit',
'orderId' => 'order-' . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)) . '',
'authorizationType' => 'PREAUTH',
'preauthFinalizeDays' => 7,
],
]);
echo json_encode($invoice);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": "Room deposit",
"orderId": "order-" + str(uuid.uuid4()) + "",
"authorizationType": "PREAUTH",
"preauthFinalizeDays": 7,
},
})
print(json.dumps(invoice))Authorize in the sandbox
Let the simulator pay with a test card. It works only with a sandbox key. The card here always succeeds, and any other number gives 422 EVT-202. The response has the payment id.
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":"CARD","card":"4242424242424242"}'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: 'CARD', card: '4242424242424242' } });
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' => 'CARD', 'card' => '4242424242424242']]);
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": "CARD", "card": "4242424242424242"}})
print(json.dumps(result))Read the open payment
Read the payment. Its authorizationType is PREAUTH, its preauthStatus is OPEN, and finalizeDueAt is the last time you can finalize. The preauthMode field shows how TapPay holds the money.
curl -sS "https://api.tappay.mn/api/v1/payments/PAYMENT_ID" \
-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 payment = await tappay.payments.retrieve({ id: 'PAYMENT_ID' });
console.log(JSON.stringify(payment));<?php
require 'vendor/autoload.php';
use TapPay\TapPay;
$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$payment = $tappay->payments->retrieve(['id' => 'PAYMENT_ID']);
echo json_encode($payment);import json
import tappay
client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
payment = client.payments.retrieve({"id": "PAYMENT_ID"})
print(json.dumps(payment))TapPay holds the money in one of two modes.
preauthMode | What happens |
|---|---|
CHARGE_REFUND | TapPay charges the full amount, and the payment is SUCCEEDED. You see the full amount in your balance. |
HOLD | TapPay only reserves the amount on the card, and the payment is AUTHORIZED. Nothing is added to your balance until you finalize. |
Finalize with the final amount
Send the final amount as a string, which must not be higher than the held amount. You can finalize only once. In CHARGE_REFUND mode TapPay refunds the difference to the customer from your balance, with the reason PREAUTH_ADJUSTMENT. In HOLD mode TapPay captures the final amount and releases the rest.
curl -sS -X POST "https://api.tappay.mn/api/v1/payments/PAYMENT_ID/finalize" \
-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":"600"}'import { TapPay } from '@tappay-mn/node';
const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const payment = await tappay.payments.finalize({ id: 'PAYMENT_ID', body: { amount: '600' } });
console.log(JSON.stringify(payment));<?php
require 'vendor/autoload.php';
use TapPay\TapPay;
$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$payment = $tappay->payments->finalize(['id' => 'PAYMENT_ID', 'body' => ['amount' => '600']]);
echo json_encode($payment);import json
import tappay
client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
payment = client.payments.finalize({"id": "PAYMENT_ID", "body": {"amount": "600"}})
print(json.dumps(payment))Read the final payment
Read the payment again. The preauthStatus is now FINALIZED, and finalAmount shows the amount that you finalized. In CHARGE_REFUND mode, preauthRefundId points to the refund of the difference.
curl -sS "https://api.tappay.mn/api/v1/payments/PAYMENT_ID" \
-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 payment = await tappay.payments.retrieve({ id: 'PAYMENT_ID' });
console.log(JSON.stringify(payment));<?php
require 'vendor/autoload.php';
use TapPay\TapPay;
$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$payment = $tappay->payments->retrieve(['id' => 'PAYMENT_ID']);
echo json_encode($payment);import json
import tappay
client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
payment = client.payments.retrieve({"id": "PAYMENT_ID"})
print(json.dumps(payment))In the sandbox you can also call Simulate automatic finalization on a new pre-auth payment. It finalizes the full amount, as if the due time had passed. To try HOLD mode, send preauthMode HOLD to the simulator on a PREAUTH intent. The holdCapture field then sets the result of the capture.
Verify
When you finalize, TapPay sends the payment.finalized event to your webhook endpoint. In HOLD mode it sends payment.authorized first. Handle them as described in the webhooks guide, then read the payment with the request in the last step.
Common mistakes
- Expecting a smaller final amount to lower the fee. The fee stays on the full amount, and the refund of the difference does not return any fee.
- Finalizing for more than the held amount. TapPay returns PRE-008, because the final amount must not be higher.
- Finalizing twice. The second call returns
409PRE-006, because a pre-auth can be finalized only once. - Never finalizing. After
preauthFinalizeDaysTapPay finalizes the full amount itself and setspreauthStatustoAUTO_FINALIZED, and a later call returns PRE-007. - Having too little balance for the refund of the difference. TapPay takes the missing amount from your next incoming payments.
- Combining
PREAUTHwithpartialModeLINES. TapPay rejects the invoice with422PAY-021. - Expecting the tax receipt before you finalize. The eBarimt receipt is issued after finalize, for the final amount.
- Cancelling the intent of an authorized payment. TapPay returns
409PRE-015, so finalize the payment instead.
Next steps
Listen for payment.finalized with the webhooks guide. Learn how payments move between states in Statuses. See every field in Finalize a held payment, Create an invoice and Retrieve a payment.