Integrating Cambodia's National QR Standard

Cambodia's Bakong KHQR system, launched by the National Bank of Cambodia, has completely unified digital payments across the country. For local developers, integrating KHQR is a standard requirement for rental platforms, booking engines, and e-commerce platforms.

Here is a step-by-step walkthrough of integrating Bakong KHQR into a backend built with NestJS.

---

1. Generating the KHQR String

The KHQR code is built on the EMVCo merchant QR standard. To generate it, you combine the merchant ID, acquirer bank ID, transaction currency (USD/KHR), amount, and order ID into a payload, then append a CRC16 checksum.

The official Bakong SDK makes this simple:

// typescript
import { Injectable } from '@nestjs/common';

@Injectable() export class PaymentService { async generateQR(orderId: string, amount: number, isUsd: boolean) { const info = new IndividualInfo(); info.accountId = 'merchant_account_id@acleda'; info.merchantName = 'Thoeun Lothin Shop'; info.merchantCity = 'Phnom Penh'; info.amount = amount; info.currency = isUsd ? 'USD' : 'KHR'; info.billNumber = orderId; info.storeLabel = 'Main Branch';

const qrResult = BakongKHQR.generateIndividual(info); return { qrString: qrResult.data.qrString, md5: qrResult.data.md5, }; } } ```

---

2. Creating Webhooks for Payment Status

Because KHQR payments happen peer-to-peer on the Bakong blockchain, the merchant server must verify that the transaction has successfully settled. The most reliable way is setting up a Webhook endpoint that Bakong or the acquiring bank pings once they confirm settlement:

// typescript
@Controller('api/payments') export class PaymentController {

@Post('webhook') async handleWebhook(@Body() payload: any, @Headers('x-signature') signature: string) { // 1. Verify acquirer certificate signature const isValid = this.paymentService.verifySignature(payload, signature); if (!isValid) { throw new UnauthorizedException('Invalid transaction signature'); }

// 2. Process transaction state await this.paymentService.settleOrder(payload.billNumber, payload.amount); return { status: 'SUCCESS' }; } } ```

---

3. Polling Fallback

If webhooks fail due to network instability, you should implement a short polling controller in NestJS using RxJS intervals or standard cron timers to verify status against the bank's transaction lookup API.

Integrating Bakong KHQR simplifies user checkouts, enabling Cambodian customers to scan and pay in seconds.