I built a small hotel booking integration for George Town and ran it end to end in 's sandbox: search rates in ringgit, prebook, book, read the booking back and cancel it. Nothing was charged, and every test booking was cancelled.
The bookings themselves worked. What needed care was everything around them. These are the seven checks I'd go through with any partner before a hotel API takes real bookings in a new market, each with what the sandbox actually returned.
Where the checks fit
1. Ask for the guest's nationality. Don't guess it
Rates and taxes depend on who the guest is, and the search won't run without it: leave guestNationality out and the API answers 400, code 4002. Take it from the guest's passport rather than their location, because travellers search from abroad all the time.
With guestNationality set to MY, a Malaysian guest, a George Town rate still listed this as payable at the hotel:
{
"included": false,
"description": "Malaysian Tourist Tax For Foreign Citizen only: All year round - night 1 onwards. For guidance only, subject to change.",
"amount": 20,
"currency": "MYR"
}A “Tourism fee” of RM 20.20 came back the same way. Malaysia's tourism tax is RM 10 per room per night, and only foreign guests pay it. Show these lines as they come, and you tell a Malaysian guest they owe a tax they don't. The kit's splitTaxes(), further down, flags both.
2. Show pay-at-hotel taxes before the guest books
Every George Town hotel in the test had taxes marked "included": false: not in the price, but paid at the hotel. They were the heritage or city tax, about RM 6 for a two-night stay, and on some rates the tourism tax, RM 20 to 20.20.
Split each offer into what the guest pays now and what they pay at the hotel, and show both before payment. Otherwise the guest meets the difference at check-in, and blames you for it.
3. Map local tax names, and show each tax once
George Town's heritage tax came back under three names and four amounts:
- “Heritage Tax”, RM 6.02
- “City Tax”, RM 6.00 and RM 6.06
- “George Town Heritage/ City Tax”, RM 6.00
And one hotel listed its main tax as “VAT”. Malaysia has no VAT: its tax is SST, the Sales and Service Tax. Normalise tax names for each country before you show them, so the guest sees one heritage tax, under its real name.
4. Give cancellation deadlines in the hotel's time, not GMT
The cancellation policy came back like this:
"cancelTime": "2027-01-07 10:00:00",
"timezone": "GMT"That's 6pm in Penang, eight hours later. Show “free cancellation until Thursday 7 January, 6:00 pm, hotel time”, converted to the hotel's own time zone. One setting per country isn't enough: Indonesia alone has three time zones.
5. Re-check price, policy and meals right before booking
The prebook step re-checks the offer and says what changed since the search, in three fields:
"priceDifferencePercent": 0,
"cancellationChanged": false,
"boardChanged": falseIn George Town nothing changed: the price held. If any of the three does change, stop and show the guest before taking payment. And two prebook errors mean search again, not retry: 4040, an outdated offer, and 4016, a prebook timeout.
6. Don't assume non-refundable is cheaper
The same suite, for the same dates, came back refundable at RM 614.74 and non-refundable at RM 614.99. A “save with non-refundable” badge there would have the guest pay more for less. Compare the two totals before you label any rate the best price, and show the guest both.
7. Give each booking one reference, and reuse it
After a timeout, you can't tell whether a booking went through. In the sandbox, booking the same prebook again with a new clientReference made a second booking while the first was still confirmed. Repeating the same clientReference is refused instead, with code 4005.
So the safe pattern is:
- Choose the reference before the first attempt.
- After a timeout or an unclear answer, look the booking up first:
GET /bookings?clientReference=...- Only if it isn't there, try again, with the same reference.
Nuitée's own webhook docs give the same advice: don't retry the same prebookId. The kit's bookSafely() does all three steps.
The checklist
- Ask for the guest's nationality. Don't guess it.
- Show pay-at-hotel taxes before the guest books.
- Map local tax names, and show each tax once.
- Give cancellation deadlines in the hotel's time.
- Re-check price, policy and meals before payment.
- Compare refundable and non-refundable totals.
- Give each booking one reference, and reuse it on retries.
The kit
Everything above comes from , a small Node.js project with no dependencies. It runs the full booking flow for George Town, triggers each documented error for real, receives webhooks, and has 28 offline tests. It also has that sorts 15 problems the way an integration manager would, and for Southeast Asia.
The two files behind the checks above, in full:
src/taxes.js (60 lines)
// Splits a rate's taxes and fees into what's already in the price and what the guest pays at the
// hotel, and flags two Malaysian cases seen in the sandbox (George Town, 25 Nov 2026):
// - Malaysia's tourism tax is for foreign guests only (RM10 per room per night), yet it was
// listed as payable at the hotel for a guest whose nationality was Malaysian.
// - One supplier labelled a Malaysian tax "VAT". Malaysia has no VAT: its tax is SST
// (Sales and Service Tax).
// A partner that shows only the price, without the pay-at-hotel part, surprises the guest at check-in.
/**
* @param {Array<{included: boolean, description?: string, amount: number, currency: string}>} items
* a rate's retailRate.taxesAndFees
* @param {{ guestNationality?: string, hotelCountry?: string }} context two-letter country codes
*/
export function splitTaxes(items = [], { guestNationality, hotelCountry } = {}) {
const included = [];
const payAtHotel = [];
const notes = [];
for (const item of items ?? []) {
const line = {
description: String(item.description ?? "Tax or fee").trim(),
amount: Number(item.amount) || 0,
currency: item.currency ?? null,
};
(item.included ? included : payAtHotel).push(line);
const note = noteFor(line, Boolean(item.included), guestNationality, hotelCountry);
if (note) notes.push(note);
}
return { included, payAtHotel, payAtHotelTotal: totalsByCurrency(payAtHotel), notes };
}
function noteFor(line, included, guestNationality, hotelCountry) {
const guest = guestNationality?.toUpperCase();
const country = hotelCountry?.toUpperCase();
if (!included && guest && guest === country && /foreign/i.test(line.description)) {
return `"${shorten(line.description)}" is listed for this ${guest} guest, but it's for foreign citizens only.`;
}
// Suppliers also call Malaysia's tourism tax "Tourism fee" or "Tourist Tax", without saying
// it's for foreigners: the same tax, so the same note for a Malaysian guest.
if (!included && country === "MY" && guest === "MY" && /touris[mt]\s+(tax|fee)/i.test(line.description)) {
return `"${shorten(line.description)}" looks like Malaysia's tourism tax, which foreign guests pay (RM10 per room per night). A Malaysian guest shouldn't owe it.`;
}
if (country === "MY" && /\bVAT\b/.test(line.description)) {
return `"${shorten(line.description)}": Malaysia has no VAT, so this is most likely SST (Sales and Service Tax) under another name.`;
}
return null;
}
/** { MYR: 26 } from [{ amount: 20, currency: "MYR" }, { amount: 6, currency: "MYR" }] */
export function totalsByCurrency(lines) {
const totals = {};
for (const { amount, currency } of lines) {
const key = currency ?? "unknown";
totals[key] = Math.round(((totals[key] ?? 0) + amount) * 100) / 100;
}
return totals;
}
function shorten(text) {
return text.length > 60 ? `${text.slice(0, 57)}...` : text;
}src/booking.js (132 lines)
// The booking rules a partner needs on top of the raw API: choosing an offer, reading what the
// prebook says changed, booking without ever booking twice, and showing cancellation deadlines in
// the hotel's own time.
import { splitTaxes } from "./taxes.js";
/**
* Every offer in a search answer, cheapest first. By default only refundable offers, so a test
* booking can be cancelled for free.
* @param {object} search the JSON from POST /hotels/rates (with includeHotelData: true for names)
*/
export function listOffers(search, { refundableOnly = true, guestNationality } = {}) {
const hotels = new Map((search?.hotels ?? []).map((h) => [h.id, h]));
const offers = [];
for (const hotel of search?.data ?? []) {
const info = hotels.get(hotel.hotelId);
const hotelCountry = info?.country_code?.toUpperCase() ?? null;
for (const roomType of hotel.roomTypes ?? []) {
const rate = roomType.rates?.[0];
// offerRetailRate is the whole offer (every room); a rate's total is one room.
const price = roomType.offerRetailRate ?? rate?.retailRate?.total?.[0];
if (!rate || !price || !roomType.offerId) continue;
const refundable = rate.cancellationPolicies?.refundableTag === "RFN";
if (refundableOnly && !refundable) continue;
offers.push({
hotelId: hotel.hotelId,
hotelName: info?.name ?? hotel.hotelId,
hotelCountry,
offerId: roomType.offerId,
rateName: rate.name,
board: rate.boardName,
amount: price.amount,
currency: price.currency,
refundable,
cancelPolicies: rate.cancellationPolicies?.cancelPolicyInfos ?? [],
taxes: splitTaxes(rate.retailRate?.taxesAndFees, { guestNationality, hotelCountry }),
});
}
}
return offers.sort((a, b) => a.amount - b.amount);
}
/**
* What the prebook says changed since the search. A partner must show any change to the guest
* before booking: the price, the cancellation policy, or the board (meals).
*/
export function checkPrebook(prebook, offer) {
const changes = [];
const percent = Number(prebook?.priceDifferencePercent) || 0;
if (percent !== 0 || (offer && Number(prebook?.price) !== Number(offer.amount))) {
changes.push(`the price is now ${prebook?.price} ${prebook?.currency} (was ${offer?.amount} ${offer?.currency}, ${percent}% different)`);
}
if (prebook?.cancellationChanged) changes.push("the cancellation policy changed");
if (prebook?.boardChanged) changes.push("the board (meals) changed");
return { ok: changes.length === 0, changes };
}
/**
* Books a prebook without ever risking a second booking.
*
* In the sandbox on 25 Nov 2026, one prebook was booked twice while the first booking was still
* confirmed, because the two attempts used different clientReferences. Nuitée refuses a repeated
* clientReference with code 4005, so the safe pattern is:
* - choose the clientReference once, before the first attempt, and reuse it for every retry;
* - after an unclear answer (no answer, HTTP 409, or 5xx), look the booking up by
* clientReference before doing anything else;
* - only then try again, with the same clientReference.
*
* @returns {Promise<{ booking: object, outcome: string }>}
*/
export async function bookSafely(client, request, { sleep = defaultSleep, lookups = 4, waitMs = 3000, log = () => {} } = {}) {
if (!request?.clientReference) throw new Error("bookSafely needs a clientReference, chosen once before the first attempt.");
const lookup = async () => {
const answer = await client.findByClientReference(request.clientReference);
const list = Array.isArray(answer?.data) ? answer.data : answer?.data ? [answer.data] : [];
return list.find((b) => b.clientReference === request.clientReference) ?? list[0] ?? null;
};
try {
return { booking: (await client.book(request)).data, outcome: "booked" };
} catch (error) {
if (error.code === 4005) {
// This clientReference already has a booking, so an earlier attempt went through.
const existing = await lookup();
if (existing) return { booking: existing, outcome: "already booked by an earlier attempt" };
throw error;
}
const unclear = error.network || error.status === 409 || (error.status ?? 0) >= 500;
if (!unclear) throw error; // a clear refusal (for example 400 code 4002, or 410 code 4012): nothing was booked
log(`Unclear answer (${error.message}). Checking by clientReference before trying again.`);
for (let i = 0; i < lookups; i++) {
await sleep(waitMs);
const existing = await lookup().catch(() => null);
if (existing) return { booking: existing, outcome: "found by clientReference after an unclear answer" };
}
// Still nothing: try once more with the same clientReference. If the first attempt lands in
// the meantime, Nuitée answers 4005 instead of booking twice.
try {
return { booking: (await client.book(request)).data, outcome: "booked on a retry with the same clientReference" };
} catch (retryError) {
if (retryError.code === 4005) {
const existing = await lookup();
if (existing) return { booking: existing, outcome: "already booked by an earlier attempt" };
}
throw retryError;
}
}
}
// Time zones for the hotel countries this kit was tried with. Indonesia spans three zones;
// Jakarta's is used here, so a partner covering Bali or eastern Indonesia needs the hotel's own zone.
const TIME_ZONES = { MY: "Asia/Kuala_Lumpur", SG: "Asia/Singapore", ID: "Asia/Jakarta", TH: "Asia/Bangkok", PH: "Asia/Manila", VN: "Asia/Ho_Chi_Minh" };
/**
* Nuitée gives cancellation deadlines like "2027-01-07 10:00:00" with timezone "GMT".
* This shows one in the hotel's local time: "7 Jan 2027, 18:00 (Asia/Kuala_Lumpur)".
*/
export function localDeadline(cancelTime, timezone = "GMT", hotelCountry = "MY") {
if (!cancelTime) return null;
const isUtc = !timezone || /^(GMT|UTC)$/i.test(timezone);
const instant = new Date(`${String(cancelTime).replace(" ", "T")}${isUtc ? "Z" : ""}`);
if (Number.isNaN(instant.getTime())) return null;
const zone = TIME_ZONES[hotelCountry?.toUpperCase()] ?? "UTC";
const text = new Intl.DateTimeFormat("en-GB", { timeZone: zone, day: "numeric", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit", hour12: false }).format(instant);
return `${text} (${zone})`;
}
function defaultSleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}To run it yourself, you need Node.js 22.9 or newer and a free sandbox key from . The README has the steps.