billing

package
v1.67.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TransactionStatusPending indicates that status of this transaction is pending.
	TransactionStatusPending = "pending"
	// TransactionStatusCancelled indicates that status of this transaction is cancelled.
	TransactionStatusCancelled = "cancelled"
	// TransactionStatusCompleted indicates that status of this transaction is complete.
	TransactionStatusCompleted = "complete"
)
View Source
const (
	// TransactionTypeCredit indicates that type of this transaction is credit.
	TransactionTypeCredit = "credit"
	// TransactionTypeDebit indicates that type of this transaction is debit.
	TransactionTypeDebit = "debit"
	// TransactionTypeUnknown indicates that type of this transaction is unknown.
	TransactionTypeUnknown = "unknown"
)

Variables

View Source
var ChoreErr = errs.Class("billing chore")

ChoreErr is billing chore err class.

View Source
var ErrInsufficientFunds = errs.New("Insufficient funds for this transaction")

ErrInsufficientFunds represents err when a user balance is too low for some transaction.

View Source
var ErrNoTransactions = errs.New("no transactions in the database")

ErrNoTransactions represents err when there is no billing transactions in the DB.

View Source
var ErrNoWallet = errs.New("no wallet in the database")

ErrNoWallet represents err when there is no wallet in the DB.

Functions

This section is empty.

Types

type Chore added in v1.62.1

type Chore struct {
	TransactionCycle *sync2.Cycle
	// contains filtered or unexported fields
}

Chore periodically queries for new billing transactions from payment type.

architecture: Chore

func NewChore added in v1.62.1

func NewChore(log *zap.Logger, paymentTypes []PaymentType, transactionsDB TransactionsDB, interval time.Duration, disableLoop bool) *Chore

NewChore creates new chore.

func (*Chore) Close added in v1.62.1

func (chore *Chore) Close() (err error)

Close closes all underlying resources.

func (*Chore) Run added in v1.62.1

func (chore *Chore) Run(ctx context.Context) (err error)

Run runs billing transaction loop.

type Config added in v1.62.1

type Config struct {
	Interval    time.Duration `help:"billing chore interval to query for new transactions from all payment types" default:"15s"`
	DisableLoop bool          `help:"flag to disable querying for new billing transactions by billing chore" default:"true"`
}

Config stores needed information for billing service initialization.

type PaymentType added in v1.62.1

type PaymentType interface {
	// Source the source of the payment
	Source() string
	// Type the type of the payment
	Type() TransactionType
	// GetNewTransactions returns new transactions that occurred after the provided last transaction received.
	GetNewTransactions(ctx context.Context, lastTransactionTime time.Time, metadata []byte) ([]Transaction, error)
}

PaymentType is an interface which defines functionality required for all billing payment types. Payment types can include but are not limited to Bitcoin, Ether, credit or debit card, ACH transfer, or even physical transfer of live goats. In each case, a source, type, and method to get new transactions must be defined by the service, though metadata specific to each payment type is also supported (i.e. goat hair type).

type Transaction

type Transaction struct {
	ID          int64
	UserID      uuid.UUID
	Amount      currency.Amount
	Description string
	Source      string
	Status      TransactionStatus
	Type        TransactionType
	Metadata    []byte
	Timestamp   time.Time
	CreatedAt   time.Time
}

Transaction defines billing related transaction info that is stored in the DB.

type TransactionStatus added in v1.62.1

type TransactionStatus string

TransactionStatus indicates transaction status.

type TransactionType added in v1.62.1

type TransactionType string

TransactionType indicates transaction type.

type TransactionsDB

type TransactionsDB interface {
	// Insert inserts the provided transaction.
	Insert(ctx context.Context, tx Transaction) (txID int64, err error)
	// UpdateStatus updates the status of the transaction.
	UpdateStatus(ctx context.Context, txID int64, status TransactionStatus) error
	// UpdateMetadata updates the metadata of the transaction.
	UpdateMetadata(ctx context.Context, txID int64, metadata []byte) error
	// LastTransaction returns the timestamp and metadata of the last known transaction for given source and type.
	LastTransaction(ctx context.Context, txSource string, txType TransactionType) (time.Time, []byte, error)
	// List returns all transactions for the specified user.
	List(ctx context.Context, userID uuid.UUID) ([]Transaction, error)
	// GetBalance returns the current usable balance for the specified user.
	GetBalance(ctx context.Context, userID uuid.UUID) (currency.Amount, error)
}

TransactionsDB is an interface which defines functionality of DB which stores billing transactions.

architecture: Database

Jump to

Keyboard shortcuts

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