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.
example/example.dart
// A tour of thai_promptpay. Run with: dart run example/example.dart
import 'package:thai_promptpay/thai_promptpay.dart';
void main() {
// ── Encode ────────────────────────────────────────────────────────────────
// Mobile, static (no amount):
print(promptPayMobile('0812345678'));
// Mobile (formatted input is fine), 100.00 baht = 10000 satang → dynamic QR:
print(promptPayMobile('081-234-5678', amountSatang: 10000));
// 13-digit National ID / personal Tax ID (MOD-11 validated), 250.75 baht:
print(promptPayNationalId('1101700230708', amountSatang: 25075));
// 15-digit e-Wallet ID:
print(promptPayEWallet('004999000000001'));
// Render the returned string as a QR with any package (qr_flutter, qr, ...).
// ── Decode (verifies the CRC) ────────────────────────────────────────────
final p = decodePromptPay(promptPayMobile('0812345678', amountSatang: 5000));
print('${p.target.type.name} ${p.target.value} '
'${p.amountSatang} satang dynamic=${p.isDynamic}');
// mobile 0812345678 5000 satang dynamic=true
// Non-throwing: returns null on a bad payload / CRC mismatch.
print(tryDecodePromptPay('not a promptpay qr')); // null
// CRC-16/CCITT-FALSE is exported too.
print(crc16ccitt('123456789').toRadixString(16)); // 29b1
}