billing

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadAmount         error = errors.New("billing: bad amount input")
	ErrInsufficientFunds error = errors.New("billing: insufficient funds") // I can hear it...
)
View Source
var (
	ErrInvalidSerialNumber = errors.New("billing: invalid serial number")
	ErrInvalidOwnerID      = errors.New("billing: invalid owner ID, need OwnerUserID or OwnerAffiliationID")
	ErrInvalidProductID    = errors.New("billing: invalid product ID")
	ErrInvalidWalletID     = errors.New("billing: invalid wallet ID")
)

Functions

func AddProduct

func AddProduct(product *Product) error

Add entry to database

func Setup

func Setup(d *sql.DB, sqlTblPrefix string) error

func TerminateProductBySerialNumber added in v0.0.17

func TerminateProductBySerialNumber(serialNumber uint64) error

func UpdateProduct

func UpdateProduct(product *Product) error

Types

type Product

type Product struct {

	// Ownership. At least one must be set.
	// if both are set, the product is treated
	// as a private owned product.
	OwnerUserID        uint64
	OwnerAffiliationID uint64

	// billing/payment
	ProductID uint64 // identifier for product type, description, pricing, etc.

	BillingCycle uint8
	WalletID     uint64
	// contains filtered or unexported fields
}

func GetProductBySerialNumber added in v0.0.17

func GetProductBySerialNumber(serialNumber uint64) (*Product, error)

func ListActiveProductsByBillingCycle

func ListActiveProductsByBillingCycle(billingCycle uint8) ([]*Product, error)

For automated-billing purposes. Designed for Pay-As-You-Go billing. But may be used for other purposes later?

func ListAffiliationProducts added in v0.0.17

func ListAffiliationProducts(ownerAffiliationID uint64) ([]*Product, error)

For affliation user viewing. Lists all products owned by the affiliation, including both shared and private owned products. Client should implement local-pagination to reduce need of repeated query Client should mark private products (ownerUserID != 0) as private API Server should hide dateTermination in response, if dateTermination is earlier than dateCreation

func ListAllProducts

func ListAllProducts() ([]*Product, error)

For admin viewing. Client should implement local-pagination

func ListProductsByProductID added in v0.0.17

func ListProductsByProductID(productID uint64) ([]*Product, error)

For admin viewing.

func ListUserProducts

func ListUserProducts(ownerUserID uint64) ([]*Product, error)

For user viewing. Lists all products owned by the user. Client should implement local-pagination to reduce need of repeated query API Server should hide dateTermination in reponse, if dateTermination is earlier than dateCreation

func (*Product) Add added in v0.0.17

func (p *Product) Add() error

func (*Product) DateCreation

func (p *Product) DateCreation() time.Time

func (*Product) DateTermination

func (p *Product) DateTermination() time.Time

func (*Product) SerialNumber added in v0.0.17

func (p *Product) SerialNumber() uint64

func (*Product) Terminate added in v0.0.17

func (p *Product) Terminate() error

func (*Product) Update added in v0.0.17

func (p *Product) Update() error

type Wallet

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

func GetWalletByID added in v0.0.17

func GetWalletByID(walletID uint64) (*Wallet, error)

GetWalletByID() build a Wallet struct reflecting an entry in the database.

func UserWallet

func UserWallet(ownerID uint64) (*Wallet, error)

func (*Wallet) Balance

func (w *Wallet) Balance() float64

func (*Wallet) Deposit

func (w *Wallet) Deposit(amount float64) error

func (*Wallet) Disable added in v0.0.17

func (w *Wallet) Disable() error

func (*Wallet) Enabke added in v0.0.17

func (w *Wallet) Enabke() error

func (*Wallet) Secured

func (w *Wallet) Secured() float64

func (*Wallet) Spend

func (w *Wallet) Spend(amount float64) error

Spend() tries to consumes balance from the wallet, without throwing error even if balance is insufficient. May result in negative balance.

func (*Wallet) TrySpend added in v0.0.17

func (w *Wallet) TrySpend(amount float64) error

Spend() is safe. i.e., it does not leave a negative balance will return error if not enough balance to spend

Jump to

Keyboard shortcuts

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