billing

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadAmount error = errors.New("billing: bad amount input")
)

Functions

func AddProduct

func AddProduct(product Product) error

Add entry to database

func Setup

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

func TerminateProduct

func TerminateProduct(ProductID uint64) error

Terminates the product

func UpdateProduct

func UpdateProduct(productID uint64, product Product) error

UpdateProduct() effectively updates OwnerID, ServerType, InstanceID, WalletID for the product specified by ProductID

Types

type BillingCycle

type BillingCycle uint8
const (
	PayAsYouGo BillingCycle = iota
	PerMonth
	PerQuarter
	PerYear
)

type Product

type Product struct {
	ProductID uint64

	// Ownership
	OwnerID uint64

	// Server-Account binding
	ServerType string
	InstanceID string

	// billing/payment
	DateCreation    time.Time // Accurate to DAY only
	DateTermination time.Time // Accurate to DAY only
	BillingCycle    BillingCycle
	WalletID        uint64
}

func ListActiveProductsByBillingCycle

func ListActiveProductsByBillingCycle(billingCycle BillingCycle) ([]Product, error)

For billing purposes

func ListAllProducts

func ListAllProducts() ([]Product, error)

For admin viewing. Caller should do local pagination

func ListUserProducts

func ListUserProducts(ownerID uint64) ([]Product, error)

For user viewing. Caller should do local pagination

func SelectProduct

func SelectProduct(productID uint64) (Product, error)

type Wallet

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

func UserWallet

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

func WalletByID

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

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

func (*Wallet) AvailableFund

func (w *Wallet) AvailableFund() (float64, error)

func (*Wallet) Balance

func (w *Wallet) Balance() (float64, error)

func (*Wallet) Charge

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

Charge() is unsafe version of Spend(). It doesn't fail when user can't afford it. USE ONLY FOR POST-USE BILLING

func (*Wallet) Deposit

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

func (*Wallet) SecureFund

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

func (*Wallet) Secured

func (w *Wallet) Secured() (float64, error)

func (*Wallet) Spend

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

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

func (*Wallet) SpendSecured

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

func (*Wallet) UndoSecureFund

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

func (*Wallet) UploadPubkey

func (w *Wallet) UploadPubkey(pubkey []byte, signature string) error

Use Ed25519 TODO: Upload to Database

func (*Wallet) VerifySignature

func (w *Wallet) VerifySignature(signature, data string) error

TODO: VerifySignature()

Jump to

Keyboard shortcuts

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