npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

payway-kh

v1.0.5

Published

Unofficial ABA PayWay API wrapper for JavaScript and TypeScript - Free & Open Source

Readme

payway-kh

npm version npm downloads License: MIT

Unofficial ABA PayWay API wrapper for JavaScript, TypeScript, and Python. Works everywhere: Node.js, React, Next.js, Vue, Nuxt, Svelte, SvelteKit, Astro, Remix, Bun, Deno, and plain browser <script> tags.

Installation

npm install payway-kh
# or
yarn add payway-kh
# or
pnpm add payway-kh

Framework Compatibility

| Environment | Supported | Import style | |-------------|-----------|--------------| | Node.js 18+ | ✅ | require() or import | | Next.js (server) | ✅ | import | | React (via API route) | ✅ | use server-side only | | Vue 3 / Nuxt | ✅ | import | | Svelte / SvelteKit | ✅ | import | | Astro | ✅ | import in .astro server | | Remix | ✅ | import in loader/action | | Bun | ✅ | import | | Deno | ✅ | import from npm:payway-kh | | Browser CDN | ✅ | <script> UMD + PayWayKH.* | | TypeScript | ✅ | full types included | | Plain JS (no TS) | ✅ | JSDoc IntelliSense via .d.ts |

Quick Start

Just provide a payment link and amount - the package handles everything else!

const { PayWayClient } = require('payway-kh')
// or: import { PayWayClient } from 'payway-kh'

const client = new PayWayClient()

// Step 1: Create QR with just link and amount
const qr = await client.createQR({
  url: 'https://link.payway.com.kh/ABAPAYr1436868d',
  amount: 0.01
})

// Step 2: Wait for payment (auto-polls until paid)
const result = await client.waitForPayment({
  interval: 3000, // check every 3 seconds
  timeout: 300000, // 5 minute timeout
  onUpdate: (status) => {
    if (status.meta.qr_scanned) console.log('QR scanned!')
    if (status.meta.payment_approved) console.log('Payment approved!')
  }
})

console.log('Payment complete!', result)

API

new PayWayClient(options?)

Creates a new PayWay client.

const client = new PayWayClient({
  baseUrl: 'https://2008.site/payway' // optional, this is the default
})

client.createQR(request)

Creates a payment QR code. Transaction details are automatically stored for easy status checking.

const qr = await client.createQR({
  url: string,    // PayWay payment link
  amount: number  // Amount in currency units
})

// Returns:
// {
//   qr_string: string,
//   expire_in_sec: string,
//   download_qr: string,
//   transaction_summary: { merchant: MerchantInfo, order_details: OrderDetails },
//   status: PayWayStatus,
//   client_id: string
// }

client.checkStatus(request?)

Checks payment status. Uses stored transaction details from createQR() if no arguments provided.

// Simplified - uses stored transaction details
const status = await client.checkStatus()

// Or provide explicitly:
const status = await client.checkStatus({
  tran_id: string,
  client_id: string
})

// Returns:
// {
//   status: PayWayStatus,
//   data: Record<string, unknown>,
//   meta: {
//     tran_id: string,
//     client_id: string,
//     qr_scanned: boolean,      // true when customer scans QR
//     payment_approved: boolean, // true when payment is approved
//     finished: boolean         // true when transaction is complete
//   }
// }

client.waitForPayment(options?)

Polls checkStatus() until payment is complete. Payment is ONLY successful when ALL three conditions are true:

  • qr_scanned = true (customer scanned QR)
  • payment_approved = true (payment approved)
  • finished = true (transaction complete)

⚠️ QR scanned alone ≠ success! Payment approved alone ≠ success! ALL 3 must be true!

const result = await client.waitForPayment({
  interval: 3000,   // poll interval in ms (default: 3000)
  timeout: 300000,  // max wait time in ms (default: 300000 = 5 min)
  onUpdate: (status) => console.log(status) // callback on each check
})

client.health()

Checks API health.

const health = await client.health()
// { status: 'ok', upstream: { status: string, timestamp: string } }

Error Handling

const { PayWayClient, PayWayError } = require('payway-kh')

try {
  await client.createQR({ url: '...', amount: 0.01 })
} catch (err) {
  if (err instanceof PayWayError) {
    // err.code: 'INVALID_INPUT' | 'UPSTREAM_ERROR' | 'NETWORK_ERROR'
    // err.message: human-readable error
    // err.statusCode: HTTP status code (if applicable)
    console.error(`[${err.code}] ${err.message}`)
  }
}

Examples

See the examples/ folder:

Browser CDN Usage

<script src="https://unpkg.com/payway-kh/dist/index.umd.js"></script>
<script>
  const client = new PayWayKH.PayWayClient()
  client.health().then(console.log)
</script>

⚠️ Security Note

Never call PayWay directly from React/Vue client components - always proxy through your own backend API route. The client should only be used server-side.

Node.js 16 Support

This package uses native fetch (Node 18+). For Node 16, add a polyfill:

import fetch from 'node-fetch'
global.fetch = fetch

GitHub Repository

git clone https://github.com/blaxkmiradev/payway-kh.git
cd payway-kh
npm install
npm run build

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Issues

Found a bug or have a feature request? Please file an issue at GitHub Issues.

License

MIT

Author

rikixz - GitHub


⭐ Star this repo if you find it useful! Unofficial ABA PayWay wrapper - Free & Open Source for everyone.