Documentation ¶
Index ¶
Constants ¶
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" )
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" )
const ( StripeSource = "stripe" StorjScanSource = "storjscan" StorjScanBonusSource = "storjscanbonus" )
Well-known PaymentType sources.
Variables ¶
var ChoreErr = errs.Class("billing chore")
ChoreErr is billing chore err class.
var ErrInsufficientFunds = errs.New("Insufficient funds for this transaction")
ErrInsufficientFunds represents err when a user balance is too low for some transaction.
var ErrNoTransactions = errs.New("no transactions in the database")
ErrNoTransactions represents err when there is no billing transactions in the DB.
var ErrNoWallet = errs.New("wallet does not exists")
ErrNoWallet represents err when there is no wallet in the DB.
Functions ¶
Types ¶
type Chore ¶ added in v1.62.1
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, bonusRate int64, observers ChoreObservers) *Chore
NewChore creates new chore.
func (*Chore) TestSetPaymentTypes ¶ added in v1.87.2
func (chore *Chore) TestSetPaymentTypes(types []PaymentType)
TestSetPaymentTypes is used in tests to change the payment types this chore tracks.
type ChoreObservers ¶ added in v1.85.1
ChoreObservers holds functionality to process confirmed transactions using different types of observers.
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 Observer ¶ added in v1.84.1
type Observer interface { // Process is called repeatedly for each transaction. Process(context.Context, Transaction) error }
Observer processes a billing transaction.
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 primary transaction along with zero or more // supplemental transactions that. This is NOT intended for bulk insertion, // but rather to provide an atomic commit of one or more _related_ // transactions. Insert(ctx context.Context, primaryTx Transaction, supplementalTx ...Transaction) (txIDs []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) // ListSource returns all transactions for the specified user and source. ListSource(ctx context.Context, userID uuid.UUID, txSource string) ([]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