Robbie Ardiansyah
← All work

A payment terminal with no SDK

A self-service kiosk needed to take payments through a BCA EDC terminal plugged in over USB. BCA supplied protocol documentation and nothing else, so I implemented the protocol myself.

Product
OMNI Kiosk
When
2024 – 2025
Payments
QRIS, BCA cards
Built with
Kotlin, usb-serial-for-android

01The problem

OMNI Kiosk is the customer-facing ordering screen that sits in a restaurant. A customer builds an order, pays, and gets a receipt without speaking to anyone. For card and QRIS payments through BCA, that means an EDC terminal connected to the kiosk. The kiosk has to start a transaction on that terminal, wait while the customer taps a card or scans a QRIS code, and find out whether the payment went through.

02The constraint

Most payment integrations come with a vendor SDK that hides the transport. This one didn't. What we had was the protocol document: message layout, field definitions, and the expected request and response sequence. Everything between "build a request" and "parse a response" was up to me.

03What I built

There's no vendor library in the kiosk's build, only usb-serial-for-android for the port itself. The rest is written against the protocol document:

  • Framing. Each request is built field by field into a fixed-width message, then framed with start and end markers, a length prefix, and an LRC checksum, which is an XOR over the frame's bytes.
  • The exchange. Write the request, wait for the terminal to acknowledge it, then poll every half second while the customer is at the terminal. Each response is checksum-verified, parsed field by field, and acknowledged before the port is closed.
  • A transport seam. The protocol code only sees a terminal that can write, read and close. USB serial is one implementation of that. When a LAN-connected terminal came along, it became a second implementation over a socket, and the protocol code didn't change.

The shape of the exchange, simplified:

// Simplified sketch: field layout and message codes omitted.
suspend fun pay(amount: Long): Response =
    withTimeout(paymentTimeout) { exchange(amount) }   // timeout is a setting

private suspend fun exchange(amount: Long): Response {
    terminal.write(frame(saleMessage(amount)))
    awaitAck()                                         // give up after a few polls

    while (true) {
        val raw = terminal.read()
        if (raw.isEmpty()) { delay(500); continue }    // customer still paying
        if (!lrcMatches(raw)) throw EdcException("Bad LRC")

        val response = parse(raw)
        if (response.amount <= 0) throw EdcException("No payment was made")
        if (!response.hasApprovalCode()) continue      // not final yet, keep polling

        terminal.write(ACK)
        return response
    }
}

// Start marker + length + message + end marker + checksum.
fun frame(message: ByteArray): ByteArray {
    val body = lengthOf(message) + message + ETX
    return byteArrayOf(STX) + body + lrc(body)         // lrc = XOR of every byte
}

04Making it hold up on a shop floor

Getting one transaction through was the easy part. Most of the work came after:

  • Trusting the right response. A response with a bad checksum is rejected outright. A zero amount means no payment was made. A card payment only counts once the response carries an approval code.
  • QRIS is two steps. A QRIS payment request is followed by a separate inquiry that confirms whether it was paid. A setting decides whether that inquiry runs automatically.
  • Customers who walk away. The whole exchange runs under a configurable timeout, so an abandoned payment closes the port and frees the kiosk instead of leaving it stuck.
  • Cables and power. A connection check, handled connectivity errors, and a persisted USB device configuration so the kiosk finds the same terminal after a restart.
  • Visibility. Every frame written and read is logged to a file, so a failed payment in a store can be examined afterwards. A configurable testing account is available for testing and hidden in production.

05Result

The kiosk takes QRIS and BCA card payments through the terminal, built from the protocol document alone.

It's the piece of work I'd point to first. It's specific and unusual, and nothing was there to lean on. Every failure mode had to be found, understood and handled by hand.