notifications

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package notifications provides base notification primitives and loan lifecycle notifiers. Consumers depend on the Notifier interface for transport and on contracts.LoanNotifier for loan-specific messaging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatPhoneNumber

func FormatPhoneNumber(phoneNumber, countryCode string) string

FormatPhoneNumber cleans a phone number string and prepends a country code when one is not already present.

Types

type AccountTemplates

type AccountTemplates struct {
	// RegistrationSuccess formats the welcome message after successful
	// registration. Args: (FullName string).
	RegistrationSuccess string

	// RegistrationFailed formats the message when registration cannot be
	// completed. Args: (Reason string).
	RegistrationFailed string

	// WrongAttempt formats the alert sent when an incorrect PIN is entered.
	// Args: (RemainingAttempts int).
	WrongAttempt string

	// AccountLocked formats the security alert sent when the account is
	// locked due to repeated failed PIN attempts. Args: (LockedUntil string).
	AccountLocked string

	// PINChanged formats the confirmation sent after a successful PIN change.
	// No format args.
	PINChanged string

	// PINChangeFailed formats the alert sent when a PIN change attempt fails.
	// Args: (Reason string).
	PINChangeFailed string

	// PINReset formats the confirmation sent after a successful PIN reset via
	// the recovery flow. No format args.
	PINReset string

	// PINResetFailed formats the alert sent when a PIN reset attempt fails.
	// Args: (Reason string).
	PINResetFailed string
}

AccountTemplates contains fmt.Sprintf-style format strings for account and PIN lifecycle notification messages. Each field documents its expected arguments.

func DefaultAccountTemplates

func DefaultAccountTemplates() *AccountTemplates

DefaultAccountTemplates returns sensible default templates for all account and PIN notification messages. Pass nil to NewSMSAccountNotifier to use these defaults.

type LoanTemplates

type LoanTemplates struct {
	// Approved: args = (DisplayCurrency, DisplayAmount, LoanNumber)
	Approved string
	// Rejected: args = (DisplayCurrency, DisplayAmount, Reason)
	Rejected string
	// Disbursed: args = (DisplayCurrency, DisplayAmount, LoanNumber)
	Disbursed string
	// Failed: args = (LoanNumber)
	Failed string
	// RepaymentReceived: args = (DisplayCurrency, DisplayAmount, LoanNumber, DisplayCurrency, RemainingBalance)
	RepaymentReceived string
	// RepaymentOverdue: args = (DisplayCurrency, DisplayAmount, LoanNumber)
	RepaymentOverdue string
	// RepaymentSoon: args = (DisplayCurrency, DisplayAmount, daysUntilDue, LoanNumber)
	RepaymentSoon string
	// RepaymentUpcoming: args = (DisplayCurrency, DisplayAmount, dueDateFormatted, LoanNumber)
	RepaymentUpcoming string
}

LoanTemplates contains format strings for each loan lifecycle notification. Each template uses fmt.Sprintf-style verbs; the exact arguments are documented per-field.

func DefaultLoanTemplates

func DefaultLoanTemplates() *LoanTemplates

DefaultLoanTemplates returns templates matching the current microvault-credit messages but parameterized for any currency.

type NoOpAccountNotifier

type NoOpAccountNotifier struct{}

NoOpAccountNotifier silently discards all account notifications. It is useful for testing and environments where SMS delivery is not configured.

func (*NoOpAccountNotifier) NotifyAccountLocked

func (*NoOpAccountNotifier) NotifyPINChangeFailed

func (*NoOpAccountNotifier) NotifyPINChanged

func (*NoOpAccountNotifier) NotifyPINReset

func (*NoOpAccountNotifier) NotifyPINResetFailed

func (*NoOpAccountNotifier) NotifyPINWrongAttempt

func (*NoOpAccountNotifier) NotifyRegistrationFailed

func (*NoOpAccountNotifier) NotifyRegistrationSuccess

type NoOpLoanNotifier

type NoOpLoanNotifier struct{}

NoOpLoanNotifier discards all loan notifications silently.

func (*NoOpLoanNotifier) NotifyLoanApproved

func (*NoOpLoanNotifier) NotifyLoanDisbursed

func (*NoOpLoanNotifier) NotifyLoanFailed

func (*NoOpLoanNotifier) NotifyLoanRejected

func (*NoOpLoanNotifier) NotifyRepaymentReceived

func (*NoOpLoanNotifier) NotifyRepaymentReceived(context.Context, contracts.LoanNotification) error

func (*NoOpLoanNotifier) NotifyRepaymentReminder

func (*NoOpLoanNotifier) NotifyRepaymentReminder(context.Context, contracts.LoanNotification) error

type NoOpNotifier

type NoOpNotifier struct{}

NoOpNotifier silently discards all messages. Useful for testing and environments where notifications are not configured.

func (*NoOpNotifier) Send

Send is a no-op.

type Notifier

type Notifier interface {
	Send(ctx context.Context, to string, message string) error
}

Notifier is a thin send-only interface that decouples notification logic from the underlying transport (SMS, push, email, etc.).

type SMSAccountNotifier

type SMSAccountNotifier struct {
	// contains filtered or unexported fields
}

SMSAccountNotifier implements contracts.AccountNotifier by formatting notification messages from AccountTemplates and delivering them through a Notifier transport (typically SMS).

func NewSMSAccountNotifier

func NewSMSAccountNotifier(notifier Notifier, templates *AccountTemplates) *SMSAccountNotifier

NewSMSAccountNotifier creates a new SMSAccountNotifier. If templates is nil, DefaultAccountTemplates is used.

func (*SMSAccountNotifier) NotifyAccountLocked

func (s *SMSAccountNotifier) NotifyAccountLocked(ctx context.Context, n contracts.AccountNotification) error

NotifyAccountLocked sends a security alert when the account is locked.

func (*SMSAccountNotifier) NotifyPINChangeFailed

func (s *SMSAccountNotifier) NotifyPINChangeFailed(ctx context.Context, n contracts.AccountNotification) error

NotifyPINChangeFailed sends an alert when a PIN change attempt is unsuccessful.

func (*SMSAccountNotifier) NotifyPINChanged

NotifyPINChanged sends a confirmation after a successful PIN change.

func (*SMSAccountNotifier) NotifyPINReset

NotifyPINReset sends a confirmation after a successful PIN reset.

func (*SMSAccountNotifier) NotifyPINResetFailed

func (s *SMSAccountNotifier) NotifyPINResetFailed(ctx context.Context, n contracts.AccountNotification) error

NotifyPINResetFailed sends an alert when a PIN reset attempt fails.

func (*SMSAccountNotifier) NotifyPINWrongAttempt

func (s *SMSAccountNotifier) NotifyPINWrongAttempt(ctx context.Context, n contracts.AccountNotification) error

NotifyPINWrongAttempt sends a warning after an incorrect PIN entry.

func (*SMSAccountNotifier) NotifyRegistrationFailed

func (s *SMSAccountNotifier) NotifyRegistrationFailed(ctx context.Context, n contracts.AccountNotification) error

NotifyRegistrationFailed sends an alert when registration cannot be completed.

func (*SMSAccountNotifier) NotifyRegistrationSuccess

func (s *SMSAccountNotifier) NotifyRegistrationSuccess(ctx context.Context, n contracts.AccountNotification) error

NotifyRegistrationSuccess sends a welcome message after successful registration.

type SMSLoanNotifier

type SMSLoanNotifier struct {
	// contains filtered or unexported fields
}

SMSLoanNotifier implements contracts.LoanNotifier using a Notifier transport and configurable LoanTemplates.

func NewSMSLoanNotifier

func NewSMSLoanNotifier(notifier Notifier, templates *LoanTemplates) *SMSLoanNotifier

NewSMSLoanNotifier creates a new SMSLoanNotifier. Pass nil for templates to use DefaultLoanTemplates().

func (*SMSLoanNotifier) NotifyLoanApproved

func (s *SMSLoanNotifier) NotifyLoanApproved(ctx context.Context, n contracts.LoanNotification) error

func (*SMSLoanNotifier) NotifyLoanDisbursed

func (s *SMSLoanNotifier) NotifyLoanDisbursed(ctx context.Context, n contracts.LoanNotification) error

func (*SMSLoanNotifier) NotifyLoanFailed

func (s *SMSLoanNotifier) NotifyLoanFailed(ctx context.Context, n contracts.LoanNotification) error

func (*SMSLoanNotifier) NotifyLoanRejected

func (s *SMSLoanNotifier) NotifyLoanRejected(ctx context.Context, n contracts.LoanNotification) error

func (*SMSLoanNotifier) NotifyRepaymentReceived

func (s *SMSLoanNotifier) NotifyRepaymentReceived(ctx context.Context, n contracts.LoanNotification) error

func (*SMSLoanNotifier) NotifyRepaymentReminder

func (s *SMSLoanNotifier) NotifyRepaymentReminder(ctx context.Context, n contracts.LoanNotification) error

type SMSNotifier

type SMSNotifier struct {
	// contains filtered or unexported fields
}

SMSNotifier implements Notifier by delegating to an sms.SMSProvider.

func NewSMSNotifier

func NewSMSNotifier(provider sms.SMSProvider, from string) *SMSNotifier

NewSMSNotifier creates a new SMSNotifier.

func (*SMSNotifier) Send

func (n *SMSNotifier) Send(ctx context.Context, to string, message string) error

Send sends a single SMS message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL