thai_promptpay 0.1.0
thai_promptpay: ^0.1.0 copied to clipboard
Pure-Dart PromptPay (Thai EMVCo QR) toolkit: build and parse the QR payload for mobile, National ID / Tax ID and e-Wallet, with amount and CRC validation.
thai_promptpay #
ชุดเครื่องมือ PromptPay (Thai EMVCo QR) แบบ pure Dart — สร้างและถอดรหัส payload ของ QR สำหรับเบอร์มือถือ / เลขบัตรประชาชน-ภาษี / e-Wallet พร้อมจำนวนเงินและตรวจ CRC
A pure-Dart PromptPay (Thai EMVCo QR) toolkit — build and parse the QR payload string for a mobile number, National ID / Tax ID or e-Wallet, with amount and CRC validation.
- Pure Dart, no Flutter, one dependency (
thainum, for phone normalization + National-ID MOD-11 validation). Works in back-end / CLI (generate a QR for an invoice server-side) and Flutter. - Encode and decode. Most PromptPay libraries only generate — this one also parses a payload back into structured data and verifies the CRC.
- It returns the payload string, not an image. Render it with any QR package
you like (
qr_flutter,qr,barcode, …). - Exact money. Amounts are integer satang (1 baht = 100 satang) — no
double, no rounding surprises.
The output is verified byte-for-byte against the canonical PromptPay references
(dtinth/promptpay-qr and the
promptpay Python library).
dart pub add thai_promptpay
Encode #
import 'package:thai_promptpay/thai_promptpay.dart';
// To a mobile number (accepts 0812345678, 081-234-5678, +66812345678, …):
promptPayMobile('0812345678');
// 00020101021129370016A0000006770101110113006681234567853037645802TH6304823E
// With an amount (100.00 baht = 10000 satang) → a one-time "dynamic" QR:
promptPayMobile('0812345678', amountSatang: 10000);
// To a 13-digit National ID / personal Tax ID (validated with a MOD-11 checksum):
promptPayNationalId('1101700230708', amountSatang: 25075); // 250.75 baht
// To a 15-digit e-Wallet ID:
promptPayEWallet('004999000000001');
Then render the returned string as a QR with any package, e.g. qr_flutter:
QrImageView(data: promptPayMobile('0812345678', amountSatang: 10000));
Decode #
final p = decodePromptPay(
'00020101021229370016A0000006770101110113006681234567853037645406100.005802TH6304F142',
);
p.target.type; // PromptPayType.mobile
p.target.value; // '0812345678'
p.amountSatang; // 10000 (100.00 baht)
p.isDynamic; // true (one-time QR)
// Non-throwing variant — returns null on a bad payload / CRC mismatch:
tryDecodePromptPay('not a promptpay qr'); // null
decodePromptPay verifies the CRC and throws a PromptPayException (which
implements FormatException) on any malformed payload, CRC mismatch, or unknown
proxy. tryDecodePromptPay returns null instead.
Notes #
- Money is handled in integer satang end to end (
amountSatang). Pair it withthainumif you want the baht text. - Validation: mobile numbers are normalized/validated, National IDs are checked with the 13-digit MOD-11 checksum, e-Wallet IDs are length-checked.
- Scope: personal PromptPay (EMVCo tag 29) — mobile / National ID / e-Wallet. Bill-Payment (tag 30) is not included yet.
crc16ccitt(String)(CRC-16/CCITT-FALSE) is exported for convenience.
License #
MIT © 2026 MaIII (ultramcu)