import "github.com/bitnob/statement-generator-sdk/pkg/statements"Represents a single financial transaction.
type Transaction struct {
ID string `json:"id"`
Date time.Time `json:"date"`
Description string `json:"description"`
Amount decimal.Decimal `json:"amount"`
Type TransactionType `json:"type"`
Reference string `json:"reference,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
}ID(string, required): Unique identifier for the transactionDate(time.Time, required): Transaction date and timeDescription(string, required): Human-readable descriptionAmount(decimal.Decimal, required): Transaction amount (positive for credits, negative for debits)Type(TransactionType, required): EitherCreditorDebitReference(string, optional): External reference numberMetadata(interface{}, optional): Additional data for custom use
type TransactionType string
const (
Credit TransactionType = "credit"
Debit TransactionType = "debit"
)Represents a financial account with optional address for proof-of-address.
type Account struct {
Number string `json:"number"`
HolderName string `json:"holder_name"`
Currency string `json:"currency"`
Type string `json:"type,omitempty"`
Address *Address `json:"address,omitempty"`
}Number(string, required): Account number (can be masked, e.g., "****1234")HolderName(string, required): Full name of account holderCurrency(string, required): ISO 4217 currency code (e.g., "USD", "EUR", "NGN")Type(string, optional): Account type (e.g., "Checking", "Savings", "Investment")Address(*Address, optional): Physical address for proof-of-address
Physical address information for proof-of-address documentation.
type Address struct {
Line1 string `json:"line1"`
Line2 string `json:"line2,omitempty"`
City string `json:"city"`
State string `json:"state,omitempty"`
PostalCode string `json:"postal_code,omitempty"`
Country string `json:"country"`
}Line1(string, required): Primary address lineLine2(string, optional): Secondary address line (apartment, suite, etc.)City(string, required): City nameState(string, optional): State or provincePostalCode(string, optional): Postal or ZIP codeCountry(string, required): Country name
Represents the financial institution issuing the statement.
type Institution struct {
Name string `json:"name"`
Logo []byte `json:"logo,omitempty"`
LogoSVG string `json:"logo_svg,omitempty"`
Address *Address `json:"address,omitempty"`
RegNumber string `json:"reg_number,omitempty"`
TaxID string `json:"tax_id,omitempty"`
ContactPhone string `json:"contact_phone,omitempty"`
ContactEmail string `json:"contact_email,omitempty"`
Website string `json:"website,omitempty"`
FooterText string `json:"footer_text,omitempty"`
}Name(string, required): Institution nameLogo([]byte, optional): Logo image data in PNG or JPEG formatLogoSVG(string, optional): Logo in SVG format (preferred for scalability)Address(*Address, optional): Institution's physical addressRegNumber(string, optional): Registration or license number (e.g., "Member FDIC")TaxID(string, optional): Tax identification numberContactPhone(string, optional): Customer service phone numberContactEmail(string, optional): Customer support email addressWebsite(string, optional): Institution website URLFooterText(string, optional): Custom footer message for statements
Input data for generating a statement.
type StatementInput struct {
Account Account `json:"account"`
Transactions []Transaction `json:"transactions"`
PeriodStart time.Time `json:"period_start"`
PeriodEnd time.Time `json:"period_end"`
OpeningBalance decimal.Decimal `json:"opening_balance"`
Institution *Institution `json:"institution,omitempty"`
}Account(Account, required): Account informationTransactions([]Transaction, required): List of transactionsPeriodStart(time.Time, required): Statement period startPeriodEnd(time.Time, required): Statement period endOpeningBalance(decimal.Decimal, required): Balance at period startInstitution(*Institution, optional): Issuing institution
Generated statement with calculated balances and summaries.
type Statement struct {
Account Account `json:"account"`
Transactions []Transaction `json:"transactions"`
PeriodStart time.Time `json:"period_start"`
PeriodEnd time.Time `json:"period_end"`
OpeningBalance decimal.Decimal `json:"opening_balance"`
ClosingBalance decimal.Decimal `json:"closing_balance"`
TotalCredits decimal.Decimal `json:"total_credits"`
TotalDebits decimal.Decimal `json:"total_debits"`
TransactionCount int `json:"transaction_count"`
Institution *Institution `json:"institution,omitempty"`
GeneratedAt time.Time `json:"generated_at"`
Locale string `json:"locale"`
}Creates a new StatementGenerator with optional configuration.
func New(options ...GeneratorOption) *StatementGeneratoroptions(variadic GeneratorOption): Configuration options
*StatementGenerator: Configured generator instance
generator := statements.New(
statements.WithLocale("en-US"),
statements.WithInstitution(institution),
)Generates a PDF statement with minimal configuration.
func QuickPDF(transactions []Transaction, openingBalance decimal.Decimal) ([]byte, error)transactions([]Transaction): List of transactionsopeningBalance(decimal.Decimal): Opening balance
[]byte: PDF document byteserror: Error if generation fails
Generates a CSV statement with minimal configuration.
func QuickCSV(transactions []Transaction, openingBalance decimal.Decimal) (string, error)transactions([]Transaction): List of transactionsopeningBalance(decimal.Decimal): Opening balance
string: CSV contenterror: Error if generation fails
Creates a new statement builder for fluent API usage.
func NewBuilder() *StatementBuilder*StatementBuilder: New builder instance
Creates a new validator instance.
func NewValidator() *Validator*Validator: New validator instance
Creates a new balance calculator.
func NewCalculator() *Calculator*Calculator: New calculator instance
Creates a locale-aware currency formatter.
func NewCurrencyFormatter(locale string) *CurrencyFormatterlocale(string): Locale code (e.g., "en-US", "fr-FR")
*CurrencyFormatter: Configured formatter
Creates a locale-aware date formatter.
func NewDateFormatter(locale string) *DateFormatterlocale(string): Locale code
*DateFormatter: Configured formatter
Generates a statement from input data.
func (g *StatementGenerator) Generate(input StatementInput) (*Statement, error)input(StatementInput): Statement input data
*Statement: Generated statementerror: Validation or generation error
Exports statement as PDF.
func (s *Statement) ToPDF() ([]byte, error)[]byte: PDF document byteserror: Export error
Exports statement as CSV.
func (s *Statement) ToCSV() stringstring: CSV content
Exports statement as HTML.
func (s *Statement) ToHTML() stringstring: HTML content
Exports statement as JSON.
func (s *Statement) ToJSON() ([]byte, error)[]byte: JSON byteserror: Marshaling error
func (b *StatementBuilder) SetAccount(account Account) *StatementBuilderfunc (b *StatementBuilder) SetPeriodStart(start time.Time) *StatementBuilderfunc (b *StatementBuilder) SetPeriodEnd(end time.Time) *StatementBuilderfunc (b *StatementBuilder) SetOpeningBalance(balance decimal.Decimal) *StatementBuilderfunc (b *StatementBuilder) AddTransaction(transaction Transaction) *StatementBuilderfunc (b *StatementBuilder) SetInstitution(institution *Institution) *StatementBuilderfunc (b *StatementBuilder) Build() (*Statement, error)Validates statement input data.
func (v *Validator) ValidateStatementInput(input StatementInput) errorValidates a single transaction.
func (v *Validator) ValidateTransaction(tx Transaction) errorValidates account information.
func (v *Validator) ValidateAccount(account Account) errorValidates ISO 4217 currency code.
func (v *Validator) ValidateCurrency(currency string) errorCalculates running balances and totals.
func (c *Calculator) CalculateBalances(
transactions []Transaction,
openingBalance decimal.Decimal,
) (*BalanceResult, error)transactions([]Transaction): Sorted transactionsopeningBalance(decimal.Decimal): Opening balance
*BalanceResult: Calculated balances and totalserror: Calculation error
Formats amount with currency symbol and separators.
func (f *CurrencyFormatter) FormatAmount(
amount decimal.Decimal,
currency string,
) stringFormats balance with sign indicator.
func (f *CurrencyFormatter) FormatBalance(
balance decimal.Decimal,
currency string,
) stringFormats date according to locale.
func (f *DateFormatter) Format(date time.Time) stringFormats date range.
func (f *DateFormatter) FormatRange(start, end time.Time) stringOptions for configuring StatementGenerator.
Sets the locale for formatting.
func WithLocale(locale string) GeneratorOptionSets default institution.
func WithInstitution(institution *Institution) GeneratorOptionOverrides default date format.
func WithDateFormat(format string) GeneratorOptionOverrides currency symbol.
func WithCurrencySymbol(symbol string) GeneratorOptionSets decimal places for amounts.
func WithDecimalPlaces(places int) GeneratorOptionReturned when validation fails.
type ValidationError struct {
Field string
Message string
}
func (e *ValidationError) Error() stringReturned when formatting fails.
type FormatError struct {
Type string
Message string
}
func (e *FormatError) Error() stringReturned when statement generation fails.
type GenerationError struct {
Step string
Message string
Cause error
}
func (e *GenerationError) Error() stringThe SDK supports all ISO 4217 currency codes. Common ones include:
const (
USD = "USD" // US Dollar
EUR = "EUR" // Euro
GBP = "GBP" // British Pound
NGN = "NGN" // Nigerian Naira
JPY = "JPY" // Japanese Yen
CNY = "CNY" // Chinese Yuan
// ... 200+ more
)const (
LocaleEnUS = "en-US" // English (United States)
LocaleEnGB = "en-GB" // English (United Kingdom)
LocaleFrFR = "fr-FR" // French (France)
LocaleDeDE = "de-DE" // German (Germany)
LocaleEsES = "es-ES" // Spanish (Spain)
LocalePtBR = "pt-BR" // Portuguese (Brazil)
LocaleZhCN = "zh-CN" // Chinese (Simplified)
LocaleJaJP = "ja-JP" // Japanese (Japan)
)All public methods in the SDK are thread-safe and can be called concurrently. The StatementGenerator can be shared across goroutines.
generator := statements.New()
// Safe to use concurrently
go func() {
statement, _ := generator.Generate(input1)
}()
go func() {
statement, _ := generator.Generate(input2)
}()- For large datasets (>10,000 transactions), consider streaming or pagination
- PDF generation is the most resource-intensive operation
- CSV generation is the fastest export format
- Use builder pattern for complex statements to avoid intermediate allocations
institution := &statements.Institution{
Name: "Community Bank",
ContactPhone: "1-800-555-1234",
ContactEmail: "help@communitybank.com",
}
generator := statements.New(
statements.WithInstitution(institution),
)
// Statement will include contact info in footerinstitution := &statements.Institution{
Name: "International Bank Corp",
Address: &statements.Address{
Line1: "100 Wall Street",
City: "New York",
State: "NY",
Country: "USA",
},
RegNumber: "FDIC #12345 | SWIFT: IBCUUS33",
ContactPhone: "+1-212-555-0100",
ContactEmail: "support@intlbank.com",
Website: "www.intlbank.com",
FooterText: "Thank you for choosing International Bank. For immediate assistance with your account, please call our 24/7 hotline or visit our website. Always have your account number ready when contacting us.",
LogoSVG: svgLogoData, // Your SVG logo as string
}
generator := statements.New(
statements.WithInstitution(institution),
statements.WithLocale("en-US"),
)institution := &statements.Institution{
Name: "NeoBank",
ContactEmail: "support@neobank.app",
Website: "app.neobank.io",
FooterText: "Questions? Open the NeoBank app and tap 'Support' for instant help, or email us with your account number.",
}
// Minimal contact info for digital-first bankinstitution := &statements.Institution{
Name: "Global Bank",
ContactPhone: "1-800-GLOBAL1",
FooterText: "For assistance in English, press 1. Para español, oprima 2. Pour le français, appuyez sur 3.",
}The generated statements will automatically include:
-
Contact Section (if provided):
Customer Service Phone: 1-800-555-1234 Email: support@bank.com Website: www.bank.com -
Custom Footer Text with account reference:
[Your custom message]. Please reference your account number (****1234) when contacting us. -
Page Footer (on every page):
Page 1 of 3 Generated: Mar 8, 2026 at 2:30 PM EST © Your Bank Name. All rights reserved.
Logos appear at the top of the statement:
- SVG logos are preferred for scalability
- PNG/JPEG logos are supported via byte array
- Maximum recommended height: 15mm (PDF)
- v1.0.0 - Initial release with PDF, CSV, HTML support
- v1.1.0 - Added address support for proof-of-address
- v1.2.0 - Added multi-currency support with 200+ ISO codes
- v1.3.0 - Added customizable footer, contact info, and logo support