Library for generating QR Code and Barcode from BOT Barcode input. Supports both file output and blob/data URL format.
npm install thai-bot-barcode-generatorไลบรารีสำหรับสร้าง QR Code และ Barcode จาก BOT Barcode input สำหรับระบบ PromptPay ของประเทศไทย รองรับทั้งการบันทึกเป็นไฟล์และส่งออกเป็น blob/data URL format
ไลบรารีนี้ถูกออกแบบมาเพื่อ:
- แปลง BOT Barcode จากรูปแบบดิบ (raw format) เป็น QR Code และ Barcode ที่ใช้งานได้
- รองรับเฉพาะ BOT Barcode format ตามมาตรฐานธนาคารแห่งประเทศไทย
- สร้างภาพ QR Code และ Barcode ในรูปแบบ PNG
- รองรับการใช้งานในระบบ PromptPay ของทุกธนาคารในประเทศไทย
- รองรับเฉพาะ BOT Barcode format เท่านั้น (ไม่รองรับ QR Code format อื่นๆ)
- รองรับเฉพาะ Bill Payment (ไม่รองรับรูปแบบอื่นๆ เช่น Dynamic QR)
- ต้องใช้ BOT Barcode input ที่ถูกต้อง ตามรูปแบบ: |[billerId] [ref1] [ref2] [amount]
- Barcode ต้องไม่เกิน 62 หลัก (ไม่รวม Carriage Return) ตามมาตรฐาน BOT
1. แปลง BOT Barcode เป็น QR Code (EMVCo Standard)
- สร้าง QR Code ตามมาตรฐาน EMVCo
- รองรับทุกธนาคารในประเทศไทย (KBank, SCB, BBL, KTB, TMB, และอื่นๆ)
- Error Correction Level: M (Medium)
- ขนาดภาพ: 500x500 pixels (ปรับแต่งได้)
2. แปลง BOT Barcode เป็น Barcode (Code 128)
- สร้าง Barcode ตามมาตรฐาน BOT
- ใช้ Code 128 format (auto-select A/B/C)
- รองรับ Carriage Return (\r) ตามมาตรฐาน BOT
- ขนาดภาพ: 1600x250 pixels
- ความสูง: 120 pixels (มากกว่า 1 cm ตามมาตรฐาน)
3. รองรับการส่งออกหลายรูปแบบ
- ✅ บันทึกเป็นไฟล์ PNG (เลือก path ได้)
- ✅ ส่งออกเป็น blob/data URL (data:image/png;base64,...)
- ✅ รองรับทั้ง Promise และ Callback
4. รองรับ TypeScript
- มี TypeScript definitions ครบถ้วน
- Type-safe API
- รองรับทั้ง ES modules และ CommonJS
5. รองรับทุกธนาคาร
- KBank (กสิกรไทย)
- SCB (ไทยพาณิชย์)
- BBL (กรุงเทพ)
- KTB (กรุงไทย)
- TMB (ทหารไทย)
- และธนาคารอื่นๆ ที่รองรับ PromptPay
- QR Code: 500x500 pixels, PNG format, ~50-100 KB
- Barcode: 1600x250 pixels, PNG format, ~10-20 KB
- Data URL: Base64 encoded, พร้อมใช้งานใน HTML/Web
- ความเร็ว: สร้าง QR Code/Barcode ได้ในเวลา < 100ms
``bash`
npm install thai-bot-barcode-generator
`javascript
const {
generateFromBarcode,
generateQRCodeBlobFromBarcode,
generateBarcodeBlobFromBarcode,
saveFromBarcode
} = require('thai-bot-barcode-generator');
// BOT Barcode input
const inputBarcode = '|123456789012345 ABC123456789012 12345678901234567890 10000';
`
`typescript
import {
generateFromBarcode,
generateQRCodeBlobFromBarcode,
generateBarcodeBlobFromBarcode,
saveFromBarcode,
GenerateOptions
} from 'thai-bot-barcode-generator';
const inputBarcode = '|123456789012345 ABC123456789012 12345678901234567890 10000';
`
`javascript
// สร้างทั้ง QR Code และ Barcode เป็น blob
const result = await generateFromBarcode(inputBarcode, {
returnBlob: true
});
console.log('QR Code:', result.qrCode); // data:image/png;base64,...
console.log('Barcode:', result.barcode); // data:image/png;base64,...
console.log('Parsed Data:', result.parsedData);
// {
// billerId: '123456789012345',
// ref1: 'ABC123456789012',
// ref2: '12345678901234567890',
// amount: 100
// }
`
`javascript
// บันทึก QR Code และ Barcode เป็นไฟล์
const result = await saveFromBarcode(
inputBarcode,
'./output/qrcode.png', // path สำหรับ QR Code
'./output/barcode.png' // path สำหรับ Barcode
);
console.log('QR Code saved to:', result.qrCodePath);
console.log('Barcode saved to:', result.barcodePath);
`
`javascript`
// สร้างเฉพาะ QR Code เป็น blob
const qrBlob = await generateQRCodeBlobFromBarcode(inputBarcode);
console.log('QR Code Data URL:', qrBlob);
// data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...
`javascript`
// สร้างเฉพาะ Barcode เป็น blob
const barcodeBlob = await generateBarcodeBlobFromBarcode(inputBarcode);
console.log('Barcode Data URL:', barcodeBlob);
// data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...
`javascript
// สร้าง blob และบันทึกไฟล์พร้อมกัน
const blobResult = await generateFromBarcode(inputBarcode, {
returnBlob: true
});
const fileResult = await saveFromBarcode(
inputBarcode,
'./output/qrcode.png',
'./output/barcode.png'
);
`
แปลง BOT Barcode input เป็นข้อมูลที่ใช้ได้
Parameters:
- inputBarcode - BOT Barcode string (เช่น: "|123456789012345 ABC123456789012 12345678901234567890 10000")
Returns:
`typescript`
{
billerId: string;
ref1: string;
ref2: string;
amount: number;
}
สร้าง QR Code และ Barcode จาก inputBarcode
Parameters:
- inputBarcode - BOT Barcode stringoptions
- - ตัวเลือกการสร้างqrOutputPath?: string
- - path สำหรับบันทึก QR CodebarcodeOutputPath?: string
- - path สำหรับบันทึก BarcodereturnBlob?: boolean
- - ถ้าเป็น true จะคืนค่าเป็น blob/data URL
Returns:
- ถ้า returnBlob = true: { qrCode: string, barcode: string, parsedData, qrPayload, barcodeData }{ qrCodePath?: string, barcodePath?: string, parsedData, qrPayload, barcodeData }
- ถ้าบันทึกไฟล์:
สร้าง QR Code เป็น blob/data URL
Returns: Data URL string (data:image/png;base64,...)
สร้าง Barcode เป็น blob/data URL
Returns: Data URL string (data:image/png;base64,...)
บันทึก QR Code และ Barcode เป็นไฟล์
Returns: Object ที่มี qrCodePath และ barcodePath
BOT Barcode format: |[billerId] [ref1] [ref2] [amount]
- billerId - รหัสผู้รับเงิน (15 หลัก)ref1
- - Reference 1 (15 หลัก)ref2
- - Reference 2 (20 หลัก)amount
- - จำนวนเงิน (หน่วย: สตางค์)
ตัวอย่าง:
``
|123456789012345 ABC123456789012 12345678901234567890 10000
หมายเหตุ: จำนวนเงิน 10000 = 100.00 บาท (10000 สตางค์)
- ความยาว: ไม่เกิน 62 หลัก (ไม่รวม Carriage Return)
- Format: ต้องมี Carriage Return (\r) ระหว่างฟิลด์
- Prefix: ต้องขึ้นต้นด้วย |
- Encoding: Code 128 (auto-select A/B/C)
ไลบรารีนี้รองรับ TypeScript โดยมี type definitions ครบถ้วน
`typescript
import {
generateFromBarcode,
GenerateOptions,
GenerateBlobResult,
GenerateFileResult
} from 'thai-bot-barcode-generator';
const options: GenerateOptions = {
returnBlob: true
};
const result: GenerateBlobResult = await generateFromBarcode(inputBarcode, options);
`
- canvas - สำหรับสร้าง Barcode imagejsbarcode
- - สำหรับสร้าง Code 128 Barcodepromptparse
- - สำหรับสร้าง EMVCo QR Code payloadqrcode` - สำหรับสร้าง QR Code image
-
ไลบรารีนี้รองรับทุกธนาคารในประเทศไทยที่รองรับ PromptPay:
- ✅ ธนาคารกสิกรไทย (KBank)
- ✅ ธนาคารไทยพาณิชย์ (SCB)
- ✅ ธนาคารกรุงเทพ (BBL)
- ✅ ธนาคารกรุงไทย (KTB)
- ✅ ธนาคารทหารไทยธนชาต (TMB)
- ✅ ธนาคารอื่นๆ ที่รองรับ PromptPay
ISC
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.