UNPKG

payseed

Version:

A comprehensive TypeScript library for payment processing utilities - format money, validate cards, calculate fees, and more.

75 lines (73 loc) 2.72 kB
type CurrencyCode = 'USD' | 'EUR' | 'GBP' | 'JPY' | 'CAD' | 'AUD' | 'CHF' | 'CNY'; interface Money { amount: number; currency: CurrencyCode; } interface PaymentCard { number: string; brand?: 'visa' | 'mastercard' | 'amex' | 'discover' | 'unknown'; } declare function formatMoney(money: Money): string; declare function calculateFee(amount: number, percentage: number): number; declare function seedId(prefix?: string): string; /** * Convert amount from major units to minor units (e.g., dollars to cents) */ declare function toMinorUnits(amount: number, decimals?: number): number; /** * Convert amount from minor units to major units (e.g., cents to dollars) */ declare function toMajorUnits(amount: number, decimals?: number): number; /** * Validate and identify credit card brand */ declare function identifyCardBrand(cardNumber: string): PaymentCard['brand']; /** * Mask credit card number for display (show only last 4 digits) */ declare function maskCardNumber(cardNumber: string): string; /** * Validate card number using Luhn algorithm */ declare function validateCardNumber(cardNumber: string): boolean; /** * Calculate payment processing fee with fixed and percentage components */ declare function calculateProcessingFee(amount: number, percentageFee: number, fixedFee?: number): number; /** * Format currency with locale support */ declare function formatCurrency(amount: number, currency: CurrencyCode, locale?: string): string; /** * Get number of decimals for a currency */ declare function getCurrencyDecimals(currency: CurrencyCode): number; /** * Parse money string to Money object */ declare function parseMoney(moneyString: string, currency: CurrencyCode): Money; /** * Add two money values (must be same currency) */ declare function addMoney(a: Money, b: Money): Money; /** * Subtract two money values (must be same currency) */ declare function subtractMoney(a: Money, b: Money): Money; /** * Multiply money by a factor */ declare function multiplyMoney(money: Money, factor: number): Money; /** * Check if money amount is zero */ declare function isZeroMoney(money: Money): boolean; /** * Check if money amount is negative */ declare function isNegativeMoney(money: Money): boolean; /** * Generate a payment reference ID */ declare function paymentReference(type?: 'invoice' | 'order' | 'payment'): string; export { type CurrencyCode, type Money, type PaymentCard, addMoney, calculateFee, calculateProcessingFee, formatCurrency, formatMoney, getCurrencyDecimals, identifyCardBrand, isNegativeMoney, isZeroMoney, maskCardNumber, multiplyMoney, parseMoney, paymentReference, seedId, subtractMoney, toMajorUnits, toMinorUnits, validateCardNumber };