notifications

package
v1.0.3 Latest Latest
Warning

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

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

Documentation

Overview

Package notifications delivers user-facing messages — loan lifecycle and account/PIN events — and is the concrete implementation of the notifier ports declared in the contracts package. It separates three concerns: what to say, how it reads, and how it is delivered.

Transport

Notifier is a thin send-only interface — Send a message to a recipient — that decouples the rest of the package from any particular channel. SMSNotifier implements it over an SMS provider; NoOpNotifier discards everything, for tests and for environments where notifications are switched off. Phone numbers are redacted in logs via the shared pkg/phone helper.

Composition

SMSLoanNotifier and SMSAccountNotifier satisfy contracts.LoanNotifier and contracts.AccountNotifier. Each takes a Notifier plus a set of templates, picks the template for the event it was asked to send, fills it from the notification's fields, and hands the result to the transport. Callers depend on the contracts interface, so the transport and wording can change without touching them.

Templates

LoanTemplates and AccountTemplates are structs of fmt.Sprintf format strings, one per event, each documenting the arguments it expects. DefaultLoanTemplates and DefaultAccountTemplates supply ready copy, parameterized for any currency; pass a custom struct to either constructor to override the wording without changing the sending logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 LanguageResolver added in v1.0.0

type LanguageResolver func(ctx context.Context, phoneNumber string) string

LanguageResolver returns the preferred SMS language (ISO code en/sw/fr) for a recipient phone number. Used by notifiers when a notification doesn't pin its own Language.

type LoanTemplates

type LoanTemplates struct {
	// Approved: args = (DisplayCurrency, DisplayAmount, LoanReference)
	Approved string
	// Rejected: args = (DisplayCurrency, DisplayAmount, Reason)
	Rejected string
	// Disbursed: args = (DisplayCurrency, DisplayAmount, LoanReference)
	Disbursed string
	// Failed: args = (LoanReference)
	Failed string
	// OffRampFailed: args = (DisplayCurrency, DisplayAmount, LoanReference).
	// Sent when vault borrow succeeded but the off-ramp could not be
	// initiated/completed and the USDC has been returned to the vault. The
	// borrower owes nothing — distinct from the credit-default "Failed".
	OffRampFailed string
	// CashPickupApproved: args = (DisplayCurrency, DisplayAmount, LoanReference).
	// Sent when a cash-pickup loan is approved, in place of "Approved" — the
	// generic copy implies a push disbursement, which is misleading here. A
	// second SMS with the MoneyGram interactive URL follows once the off-ramp
	// is initiated (see CashPickupInitiated).
	CashPickupApproved string
	// RepaymentReceived: args = (DisplayCurrency, DisplayAmount, LoanReference, DisplayCurrency, RemainingBalance)
	RepaymentReceived string
	// RepaymentOverdue: args = (DisplayCurrency, DisplayAmount, LoanReference)
	RepaymentOverdue string
	// RepaymentSoon: args = (DisplayCurrency, DisplayAmount, daysUntilDue, LoanReference)
	RepaymentSoon string
	// RepaymentUpcoming: args = (DisplayCurrency, DisplayAmount, dueDateFormatted, LoanReference)
	RepaymentUpcoming string
	// CashPickupInitiated: args = (LoanReference, InteractiveURL)
	CashPickupInitiated string
	// CashPickupReady: args = (DisplayCurrency, DisplayAmount, CashPickupRef, LoanReference, CashPickupInfoURL)
	// Runs to two SMS segments; the support link is worth the second.
	CashPickupReady string
	// CashPickupCancelled: args = (LoanReference)
	//
	// Sent when MoneyGram refunds a cash-pickup loan, which usually means the
	// borrower cancelled in MoneyGram's own app — sometimes by mistake. The
	// wording has to reassure rather than alarm: nothing is owed and they can
	// simply request again.
	CashPickupCancelled 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 ready-to-use loan templates, 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) NotifyLoanCashPickupApproved added in v1.0.0

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

func (*NoOpLoanNotifier) NotifyLoanCashPickupCancelled added in v1.0.0

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

func (*NoOpLoanNotifier) NotifyLoanCashPickupInitiated added in v1.0.0

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

func (*NoOpLoanNotifier) NotifyLoanCashPickupReady added in v1.0.0

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

func (*NoOpLoanNotifier) NotifyLoanDisbursed

func (*NoOpLoanNotifier) NotifyLoanFailed

func (*NoOpLoanNotifier) NotifyLoanOffRampFailed added in v1.0.0

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

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, the built-in localized templates (en/sw/fr) are used. A non-nil templates value is used for every language (single-language override).

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.

func (*SMSAccountNotifier) SetLanguageResolver added in v1.0.0

func (s *SMSAccountNotifier) SetLanguageResolver(r LanguageResolver)

SetLanguageResolver injects a resolver consulted when a notification leaves Language empty. Pass nil to fall back to English.

type SMSLoanNotifier

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

SMSLoanNotifier implements contracts.LoanNotifier using a Notifier transport and per-language LoanTemplates.

func NewSMSLoanNotifier

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

NewSMSLoanNotifier creates a new SMSLoanNotifier. Pass nil for templates to use the built-in localized templates (en/sw/fr). A non-nil templates value is used for every language (single-language override).

func (*SMSLoanNotifier) NotifyLoanApproved

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

func (*SMSLoanNotifier) NotifyLoanCashPickupApproved added in v1.0.0

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

func (*SMSLoanNotifier) NotifyLoanCashPickupCancelled added in v1.0.0

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

func (*SMSLoanNotifier) NotifyLoanCashPickupInitiated added in v1.0.0

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

func (*SMSLoanNotifier) NotifyLoanCashPickupReady added in v1.0.0

func (s *SMSLoanNotifier) NotifyLoanCashPickupReady(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) NotifyLoanOffRampFailed added in v1.0.0

func (s *SMSLoanNotifier) NotifyLoanOffRampFailed(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

func (*SMSLoanNotifier) SetLanguageResolver added in v1.0.0

func (s *SMSLoanNotifier) SetLanguageResolver(r LanguageResolver)

SetLanguageResolver injects a resolver consulted when a notification leaves Language empty. Pass nil to fall back to English.

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