Preview
Try each outcome, or wait a minute for the code to expire. The code in this demo is not a real payment.
Sothearo Coffee
4.50 USD
Install
pnpx sothearo add khqr
It checks whether you use Vue, Nuxt or React, and adds only the files you need to your components folder, in khqr/. They're yours to change.
Usage
The card only shows a payment. Your server makes the KHQR payload, for example with the official bakong-khqr package, and tells the page when the payment lands. Pass the payload and the current status.
Checkout.vue
<script setup lang="ts">
import KhqrCard from "@/components/khqr/KhqrCard.vue";
const { payload, expiresAt } = await $fetch("/api/payments", { method: "POST" });
const status = ref("waiting");
</script>
<template>
<KhqrCard
:payload="payload"
merchant="Sothearo Coffee"
:amount="4.5"
currency="USD"
:status="status"
:expires-at="expiresAt"
@expire="status = 'expired'"
@refresh="createPayment"
/>
</template>
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
payload | string | The KHQR string from your server. | |
image | string | A code your server already drew, as a data URL or link. Use it in place of payload. | |
merchant | string | Name shown above the amount. | |
amount | number | Leave it out for a code that takes any amount. | |
currency | "USD" | "KHR" | "USD" | Sets the format and the sign in the middle of the code. |
status | "waiting" | "paid" | "expired" | "failed" | "waiting" | What the card shows. |
expires-at | Date | number | Shows a countdown and a bar that runs out. |
Events
| Name | When |
|---|---|
@expire | The countdown reaches zero while waiting. |
@refresh | The person asks for a new code after it expires. |
@retry | The person tries again after a failure. |
Customise
khqr.css
[data-khqr] {
--khqr-width: 320px;
--khqr-radius: 24px;
--khqr-success: #0f9d58;
}
The card carries data-status, so you can style each state.
Accessibility
- The code has a label naming who you pay.
- Paid and expired are announced as status, failed as an alert.
- The code stays black on white in dark mode, so it always scans.