{"_id":"@byteindev/bank-slip-verifier","name":"@byteindev/bank-slip-verifier","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@byteindev/bank-slip-verifier","version":"1.0.0","description":"Zero-dependency client for the OIIO Service Slip Verify API — verify Thai bank transfer slips by image (OCR) or QR code data from npm, pnpm, bun, yarn or the browser","license":"MIT","author":{"name":"ByteInDev"},"homepage":"https://github.com/ByteInDev/bank-slip-verifier-npm","repository":{"type":"git","url":"git+https://github.com/ByteInDev/bank-slip-verifier-npm.git"},"type":"module","publishConfig":{"access":"public"},"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":{"import":"./dist/index.d.ts","require":"./dist/index.d.cts"},"import":"./dist/index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"build":"tsup","test":"vitest run","test:live":"cross-env LIVE=1 vitest run test/live.test.ts","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"keywords":["bank-slip","slip","verify","verification","thailand","promptpay","qrcode","ocr","api-client","bangkok-bank","kbank","scb"],"devDependencies":{"@types/node":"^24.13.3","cross-env":"^7.0.3","tsup":"^8.5.0","typescript":"^5.9.3","vitest":"^3.2.7"},"allowScripts":{"esbuild@0.27.2":true},"overrides":{"esbuild":"0.27.2"},"_id":"@byteindev/bank-slip-verifier@1.0.0","bugs":{"url":"https://github.com/ByteInDev/bank-slip-verifier-npm/issues"},"_nodeVersion":"24.18.0","_npmVersion":"12.0.2","dist":{"integrity":"sha512-0nJSDFOBRpIZnKdB8bkNjIbPLrA+CFG5G5gqKGf2lx0qXTZLhYM7gq8kbhL9RrjE0L2azWvUY0x3dmwOXn7iFg==","shasum":"dd7c06f48d60d7aa0773d7da5d1569a3201f5772","tarball":"https://registry.npmjs.org/@byteindev/bank-slip-verifier/-/bank-slip-verifier-1.0.0.tgz","fileCount":10,"unpackedSize":89842,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDmYxaDN46c2hRmZov7u8E9CQm5aGeF8JXfHN5DwH9TogIhANmmmcL0T2bKF6bxXfwM6rgToDr/Jpn9DVyKlkWRtvRi"}]},"_npmUser":{"name":"byteindev","email":"zelthr.premium@gmail.com"},"directories":{},"maintainers":[{"name":"byteindev","email":"zelthr.premium@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bank-slip-verifier_1.0.0_1786504422509_0.1875269325950395"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-12T03:13:42.269Z","1.0.0":"2026-08-12T03:13:42.666Z","modified":"2026-08-12T03:13:42.875Z"},"maintainers":[{"name":"byteindev","email":"zelthr.premium@gmail.com"}],"description":"Zero-dependency client for the OIIO Service Slip Verify API — verify Thai bank transfer slips by image (OCR) or QR code data from npm, pnpm, bun, yarn or the browser","homepage":"https://github.com/ByteInDev/bank-slip-verifier-npm","keywords":["bank-slip","slip","verify","verification","thailand","promptpay","qrcode","ocr","api-client","bangkok-bank","kbank","scb"],"repository":{"type":"git","url":"git+https://github.com/ByteInDev/bank-slip-verifier-npm.git"},"author":{"name":"ByteInDev"},"bugs":{"url":"https://github.com/ByteInDev/bank-slip-verifier-npm/issues"},"license":"MIT","readme":"<br>\n\n<div align=\"center\">\n\n# Bank-Slip-Verifier (npm)\n\n**ไลบรารีตรวจสอบสลิปโอนเงิน (Zero-dependency) สำหรับ OIIO Service Slip Verify API** — ใช้ได้กับ npm, pnpm, bun, yarn หรือเบราว์เซอร์\n\n![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)\n![TypeScript](https://img.shields.io/badge/TypeScript-5.9-3178C6?logo=typescript&logoColor=white)\n![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18-339933?logo=nodedotjs&logoColor=white)\n![Zero dependencies](https://img.shields.io/badge/dependencies-0-6DA55F)\n![ESM + CJS](https://img.shields.io/badge/ESM%20%2B%20CJS-both-8A2BE2)\n\n**ภาษาไทย** - [English](README.md)\n\n</div>\n\n---\n\nโหมดตรวจสอบ 3 แบบใน client เดียว — ยืนยันว่าสลิปที่ลูกค้าส่งมาว่า \"โอนจริง\" ในระบบธนาคารหรือไม่:\n\n| โหมด | Endpoint | ความเร็ว |\n| --- | --- | --- |\n| `detectAmount({ img })` | `POST /api/slip` | ช้าที่สุด — อ่านจำนวนเงินจากรูปด้วย OCR แล้วตรวจสอบ |\n| `verifyAmount({ img, amount })` | `POST /api/slip/:amount` | เร็วกว่า — ระบุยอดที่คาดหวัง ข้ามขั้นตอน OCR |\n| `verifyQrCode({ qrCodeData, amount })` | `POST /api/slip/:amount/no_slip` | เร็วที่สุด — ใช้ข้อมูล QR โดยไม่ต้องใช้รูป |\n\n## คุณสมบัติ\n\n| ความสามารถ | รายละเอียด |\n| ------- | ------- |\n| ครบ 3 endpoints | ตรวจจับยอดด้วย OCR, รูป + ยอดที่ระบุ, และตรวจสอบด้วย QR ล้วนๆ — ผลลัพธ์ type เดียวกันทั้งหมด |\n| Static API | `import { Client }` — ไม่ต้องสร้าง instance, `await Client.verifyAmount(...)` ใช้ได้ทันทีกับเซิร์ฟเวอร์ hosted |\n| Zero dependencies | ไม่มี install scripts, ไม่มี native binaries, ไม่มี runtime deps — ESM + CJS + TypeScript types |\n| ใช้ได้ทุกที่ | Node.js >= 18, Bun, Deno, เบราว์เซอร์ — อะไรก็ได้ที่มี global `fetch` |\n| Errors ที่ typed | `SlipApiError` พร้อม HTTP status และ error slug ตามเอกสาร (`amount-not-verified`, `slip-not-found`, ...) รวมถึง `SlipTimeoutError` และ `SlipError` |\n| กัน timeout | ค่าเริ่มต้น 35 วินาที — เพราะการตรวจสอบอาจใช้เวลาสูงสุด 25 วินาที (OCR) |\n\n## เริ่มต้นใช้งาน\n\nติดตั้งด้วย package manager ตัวใดก็ได้:\n\n```bash\nnpm install @byteindev/bank-slip-verifier\n# หรือ\npnpm add @byteindev/bank-slip-verifier\n# หรือ\nyarn add @byteindev/bank-slip-verifier\n# หรือ\nbun add @byteindev/bank-slip-verifier\n```\n\n`Client` เป็น static wrapper พร้อมใช้ เชื่อมกับเซิร์ฟเวอร์ hosted ให้อัตโนมัติ:\n\n```ts\nimport { Client } from '@byteindev/bank-slip-verifier';\n\n// 1. รู้ยอดที่ลูกค้าควรโอน (แนะนำ — เร็วกว่า):\nconst { data, fromCache } = await Client.verifyAmount({\n  img: 'data:image/jpeg;base64,...',\n  amount: 100,\n});\nconsole.log(data.amount === 100); // true — ธนาคารยืนยันว่ามีการโอนจริง\n\n// 2. ไม่รู้ยอด — ให้ OCR อ่านจากรูป (ช้าที่สุด):\nconst detected = await Client.detectAmount({ img: 'data:image/jpeg;base64,...' });\nconsole.log(detected.data.amount); // ยอดที่ OCR อ่านได้ แล้วตรวจสอบกับธนาคาร\n\n// 3. ใช้ข้อมูล QR อย่างเดียว ไม่ใช้รูป (เร็วที่สุด):\nconst qr = await Client.verifyQrCode({ qrCodeData: '004...', amount: 100 });\nconsole.log(qr.data.ref); // เลขอ้างอิงรายการโอน\n```\n\nผลลัพธ์ทุกโหมดมีโครงสร้างเดียวกัน:\n\n```ts\n{\n  message: 'Slip processed successfully.',\n  fromCache: false, // true เมื่อตอบจากแคชของเซิร์ฟเวอร์\n  data: {\n    ref: '202602032204376094',\n    date: '2026-03-17T10:00:00.000Z',\n    amount: 100,\n    sender_bank: '004',\n    sender_name: 'John Doe',\n    sender_id: 'xxx-x-xxxxx-x',\n    receiver_bank: '014',\n    receiver_name: 'Jane Doe',\n    receiver_id: 'xxx-x-xxxxx-x',\n  },\n}\n```\n\n### ใช้เซิร์ฟเวอร์ของตัวเอง (หรือปรับแต่ง)\n\n```ts\nimport { createClient } from '@byteindev/bank-slip-verifier';\n\nconst client = createClient(); // hosted: https://slip-c.oiio.download\n// หรือ\nconst custom = createClient({ baseUrl: 'https://your-deployment.example.com' });\n// หรือตั้งค่า static client:\nClient.configure({ baseUrl: 'https://your-deployment.example.com' });\n\nconst result = await client.verifyAmount({ img: 'data:image/jpeg;base64,...', amount: 100 });\n```\n\nลำดับการหา Base URL: option `baseUrl` > environment variable\n`BANK_SLIP_VERIFIER_BASE_URL` > เซิร์ฟเวอร์ hosted:\n\n```bash\nBANK_SLIP_VERIFIER_BASE_URL=https://staging.example.com node app.js\n```\n\n## เรื่อง Timeout\n\nการตรวจสอบอาจใช้เวลา**สูงสุด 25 วินาที** (endpoint OCR) เอกสาร API แนะนำให้ตั้ง HTTP\ntimeout **30 วินาทีขึ้นไป** — ไลบรารีนี้ตั้งค่าเริ่มต้นไว้ที่ 35 วินาที และจะ throw\n`SlipTimeoutError` เมื่อไม่ได้รับคำตอบภายในเวลา:\n\n```ts\nconst client = createClient({ timeoutMs: 60_000 }); // หรือลดลงได้ แต่ไม่ควรต่ำกว่า 30_000\n```\n\n## ข้อกำหนดการใช้งาน (Terms of Service)\n\nAPI ปฏิเสธทุกคำขอถ้าไม่ยอมรับ TOS, Privacy และ EULA โดยไลบรารีจะส่ง\n`{ tos: true, privacy: true, eula: true }` เป็นค่าเริ่มต้น (การใช้บริการถือว่ายอมรับข้อกำหนด)\nสามารถ override ได้ทั้งระดับ client และระดับการเรียก:\n\n```ts\ncreateClient({ consent: { tos: true, privacy: false, eula: true } }); // ระดับ client\nclient.detectAmount({ img, consent: { tos: false } });                 // ระดับการเรียก (มีผลกว่า)\n```\n\n## จัดการ Errors\n\nError ทั้งหมดสืบทอดจาก `SlipError` ข้อผิดพลาดจาก API จะมาเป็น `SlipApiError` พร้อม HTTP\nstatus และ error slug ตามเอกสาร:\n\n```ts\nimport { SlipApiError, SlipTimeoutError, SlipError } from '@byteindev/bank-slip-verifier';\n\ntry {\n  const { data } = await Client.verifyAmount({ img, amount: 100 });\n} catch (err) {\n  if (err instanceof SlipApiError) {\n    console.log(err.status, err.slug, err.message);\n    // 422 'amount-not-verified' 'Amount not verified'\n    if (err.slug === 'amount-not-verified') {\n      // แจ้งลูกค้าให้ตรวจสอบยอดอีกครั้ง — สลิปไม่ตรงกับยอดจริง\n    }\n  } else if (err instanceof SlipTimeoutError) {\n    // ตรวจสอบนานเกิน timeoutMs — ให้ลองใหม่ภายหลัง\n  }\n}\n```\n\n| HTTP | slug | สาเหตุ |\n| --- | --- | --- |\n| 400 | `bad-request` | body ไม่ถูกต้อง / ขาด field |\n| 400 | `terms-not-accepted` | ไม่ได้ยอมรับ TOS/Privacy/EULA |\n| 400 | `invalid-image` | base64 image ไม่ถูกต้อง |\n| 422 | `qr-not-found` | หา QR ในรูปไม่เจอ |\n| 422 | `invalid-qr` | QR format ไม่ถูกต้อง |\n| 422 | `amount-not-found` | OCR อ่านจำนวนเงินไม่ได้ |\n| 422 | `amount-not-verified` | OCR อ่านยอดได้ แต่ยอดนั้นตรวจสอบกับธนาคารไม่ผ่าน |\n| 422 | `invalid-slip-data` | ข้อมูลสลิปไม่สมบูรณ์ |\n| 404 | `slip-not-found` | ไม่พบสลิปในระบบธนาคาร |\n\n`SlipApiError.slug` เป็น type ตรงกับค่าเหล่านี้ (`SLIP_ERROR_SLUGS` และ `isSlipErrorSlug`\nexport ไว้สำหรับเช็คตอน runtime)\n\n> **หมายเหตุจาก API จริง (ตรวจสอบกับบริการจริงด้วยสลิปจริง):** เอกสารระบุว่า ยอดไม่ตรง\n> จะได้ `422 amount-not-verified` แต่ API จริงตอบ `404 slip-not-found`\n> (\"ไม่พบข้อมูลสลิป...\") เมื่อยอดที่ส่งไม่ตรงกับสลิป — ในโค้ดธุรกิจควรจัดการ\n> **ทั้งสอง slug** ว่าเป็นกรณี \"ยอดไม่ตรงกัน\"\n\n## การใช้งานในเบราว์เซอร์ / Edge\n\nแพ็กเกจนี้ไม่มี dependency เฉพาะ Node — ใช้ได้ทุกที่ที่มี `fetch` ระดับ global\nใช้ bundler ตัวโปรดรวมไฟล์แล้วเรียกจาก client-side ได้เลย:\n\n```ts\nimport { Client } from '@byteindev/bank-slip-verifier';\n// const Client = window.ByteInDevBankSlipVerifier.Client; // CDN build\n\nconst file = fileInput.files[0];\nconst reader = new FileReader();\nreader.onload = async () => {\n  const { data } = await Client.verifyAmount({ img: reader.result, amount: 100 });\n};\nreader.readAsDataURL(file);\n```\n\n> หมายเหตุ: การตรวจสอบอาจใช้เวลาหลายวินาที — ควรรักษา `timeoutMs` ไว้ที่ 30 วินาทีขึ้นไป\n\n## Live smoke tests\n\nแพ็กเกจมาพร้อม live smoke test ต่อเซิร์ฟเวอร์จริง (ข้ามโดยค่าเริ่มต้น):\n\n```bash\nBANK_SLIP_VERIFIER_BASE_URL=https://slip-c.oiio.download npm run test:live\n```\n\nการเช็คยอดไม่ตรงกับ**สลิปจริง** เป็นแบบ opt-in (ไม่ commit สลิปจริงขึ้น repo):\n\n```bash\nBANK_SLIP_VERIFIER_LIVE_IMAGE=C:\\path\\to\\slip.jpg npm run test:live\n```\n\n## API Reference\n\n| Export | คำอธิบาย |\n| --- | --- |\n| `Client` | static wrapper รอบ instance ร่วม (ชี้ไปที่เซิร์ฟเวอร์ hosted โดยค่าเริ่มต้น) |\n| `createClient(options?)` | สร้าง `SlipClient` ใหม่ ชี้ไปที่ hosted หรือ `baseUrl` ที่กำหนด |\n| `SlipClient` | คลาส client; `detectAmount`, `verifyAmount`, `verifyQrCode` |\n| `DEFAULT_BASE_URL` | `https://slip-c.oiio.download` |\n| `ENV_BASE_URL` | `BANK_SLIP_VERIFIER_BASE_URL` — env-var fallback สำหรับ base URL |\n| `SlipError` / `SlipApiError` / `SlipTimeoutError` | คลาส error แบบ typed |\n| `SLIP_ERROR_SLUGS`, `isSlipErrorSlug` | ค่าคงที่ error slug + type guard |\n| `VERSION` | เวอร์ชันของแพ็กเกจ |\n\n## Credits\n\nPowered by [OIIO Service Slip Verify API](https://slip-c.oiio.download).\n\n## License\n\nMIT © ByteInDev","readmeFilename":"README.th.md","_rev":"1-4fb9f7c889fdb0b2dc06008982c79a36"}