raast
v0.1.0
Published
Generate Raast payment QR codes compliant with Pakistani banking standards
Maintainers
Readme
Raast QR Code Generator
A JavaScript library for generating Raast payment QR codes compliant with Pakistani banking standards.
Installation
npm install raastUsage
This library uses neverthrow for type-safe error handling. All functions return ResultAsync objects instead of throwing errors.
Generating a Static QR Code
Static QR codes are reusable and don't contain payment amounts:
import { generatePaymentQrCode } from 'raast';
const result = await generatePaymentQrCode({
"qr-code-type": "static",
iban: "PK36SCBL0000001123456702"
});
if (result.isOk()) {
console.log(result.value.dataUri); // Data URI containing the QR code image
} else {
console.error(`Error ${result.error.code}: ${result.error.message}`);
if (result.error.hint) {
console.log(`Hint: ${result.error.hint}`);
}
}Generating a Dynamic QR Code
Dynamic QR codes include amount, description, and expiration:
import { generatePaymentQrCode } from 'raast';
const result = await generatePaymentQrCode({
"qr-code-type": "dynamic",
iban: "PK36SCBL0000001123456702",
amount: "1000.00",
description: "Payment for services",
expiration: "2024-12-31T23:59:59"
});
// Using the match pattern for clean error handling
result.match(
(qrCode) => console.log(qrCode.dataUri),
(error) => console.error(`${error.code}: ${error.message}`)
);API
generatePaymentQrCode(data)
Generates a Raast payment QR code.
Parameters
data(Object): QR code configurationqr-code-type(string): Either"static"or"dynamic"iban(string): IBAN account number (required)amount(string): Payment amount (required for dynamic QR codes)description(string): Payment description (optional)expiration(string): ISO 8601 date/time string (required for dynamic QR codes)
Returns
Promise<ResultAsync<QrCodeResult, QrCodeError>>
Success value (QrCodeResult):
dataUri(string): Data URI containing the QR code image
Error value (QrCodeError):
code(string): Error code for programmatic handling (e.g.,MISSING_IBAN,INVALID_AMOUNT_TYPE)message(string): Human-readable error messagefield(string): Field that caused the errorhint(string): Helpful suggestion to fix the error- Additional context-specific fields (e.g.,
value,length,maxLength)
Error Codes
MISSING_IBAN: IBAN is requiredINVALID_IBAN_TYPE: IBAN must be a stringIBAN_TOO_LONG: IBAN exceeds 99 charactersMISSING_AMOUNT: Amount required for dynamic QR codesINVALID_AMOUNT_TYPE: Amount must be a stringAMOUNT_TOO_LONG: Amount exceeds 99 charactersMISSING_EXPIRATION: Expiration required for dynamic QR codesINVALID_DESCRIPTION_TYPE: Description must be a stringDESCRIPTION_TOO_LONG: Description exceeds 99 charactersINVALID_CHARACTER: Invalid character in payloadQR_GENERATION_FAILED: QR code library error
TypeScript Support
This package includes TypeScript type definitions. Types are automatically available when using TypeScript:
import { generatePaymentQrCode, QrCodeData, QrCodeResult } from 'raast';
const data: QrCodeData = {
"qr-code-type": "static",
iban: "PK36SCBL0000001123456702"
};
const result: QrCodeResult = await generatePaymentQrCode(data);Compatibility
This package supports Raast QR codes for Pakistani mobile banking applications. For a compatibility matrix showing which banking apps support different QR code features, see compatibility.json.
License
MIT
