Documentation ¶
Index ¶
- Constants
- Variables
- func AddBillingRecord(record BillingRecord) (uint64, error)
- func AddProduct(product *Product) (uint64, error)
- func AddProductListing(pl *ProductListing) (uint64, error)
- func BeginningOfDay(t time.Time) time.Time
- func BillingOptionsToJSON(billingOptions []BillingOption) (string, error)
- func CollectRecurringPayment(product *Product) error
- func CollectUsageBasedPayment(product *Product, total float64) error
- func DailyRecurringBilling() []error
- func DeleteProductListingByID(productID uint64) error
- func DeleteProductListingGroupByID(id uint64) error
- func ForceCollectRecurringPayment(product *Product) error
- func ForceCollectUsageBasedPayment(product *Product, total float64) error
- func HourlyProductTermination() []error
- func HourlyUsageBilling() []error
- func ListProductListingGroupIDs() ([]uint64, error)
- func NewProductListingGroup(plg ProductListingGroup) (uint64, error)
- func Setup(d *sql.DB, sqlTblPrefix string)
- func TerminateProductBySerialNumber(serialNumber uint64) error
- func ToTerminateProductOn(product *Product, terminationDate time.Time) error
- func UpdateProduct(product *Product) error
- func UpdateProductListing(pl *ProductListing) error
- type BillingOption
- type BillingRecord
- type Product
- func GetProductBySerialNumber(serialNumber uint64) (*Product, error)
- func ListActiveProductsByBillingCycle(billingCycle uint8) ([]*Product, error)
- func ListAffiliationProducts(ownerAffiliationID uint64) ([]*Product, error)
- func ListAllProducts() ([]*Product, error)
- func ListProductsByProductID(productID uint64) ([]*Product, error)
- func ListProductsToTerminate() ([]*Product, error)
- func ListSystemProducts() ([]*Product, error)
- func ListUserProducts(ownerUserID uint64) ([]*Product, error)
- func (p *Product) Add() (uint64, error)
- func (p *Product) CollectPayment(v ...interface{}) error
- func (p *Product) DateCreation() time.Time
- func (p *Product) DateLastBill() time.Time
- func (p *Product) DateTermination() time.Time
- func (p *Product) ForceCollectPayment(v ...interface{}) error
- func (p *Product) Save() error
- func (p *Product) SerialNumber() uint64
- func (p *Product) Terminate() error
- func (p *Product) Terminated() bool
- func (p *Product) ToTerminateOn(terminationDate time.Time) error
- type ProductListing
- func GetProductListingByID(productID uint64) (*ProductListing, error)
- func ListProductListingsByGroupID(productGroupID uint64) ([]*ProductListing, error)
- func SudoGetProductListingByID(productID uint64) (*ProductListing, error)
- func SudoListProductListingsByGroupID(productGroupID uint64) ([]*ProductListing, error)
- func (pl *ProductListing) Add() (uint64, error)
- func (pl *ProductListing) CreateProduct(ownerUserID, ownerAffiliationID uint64, billingCycle uint8, walletID uint64) (*Product, error)
- func (pl *ProductListing) Delete() error
- func (pl *ProductListing) Discontinue() error
- func (pl *ProductListing) Discontinued() bool
- func (pl *ProductListing) Hidden() bool
- func (pl *ProductListing) Hide() error
- func (pl *ProductListing) ProductID() uint64
- func (pl *ProductListing) Reactivate() error
- func (pl *ProductListing) Save() error
- func (pl *ProductListing) Unhide() error
- type ProductListingGroup
- type UsageBillingFactor
- type UsageBillingFactors
- type Wallet
- func (w *Wallet) Balance() float64
- func (w *Wallet) Deposit(amount float64) error
- func (w *Wallet) Disable() error
- func (w *Wallet) Disabled() bool
- func (w *Wallet) Enable() error
- func (w *Wallet) ID() uint64
- func (w *Wallet) OwnerUserID() uint64
- func (w *Wallet) Secured() float64
- func (w *Wallet) Spend(amount float64) error
- func (w *Wallet) TrySpend(amount float64) error
Constants ¶
const ( USAGE_BASED uint8 = iota + 1 MONTHLY QUARTERLY ANNUALLY )
BillingCycle ENUMS
const ( PRICE_SUM uint8 = iota + 1 PRICE_MAX PRICE_MIN )
PricingPolicy ENUMS
Variables ¶
var ( ErrBadAmount error = errors.New("billing: bad amount input") ErrInsufficientFunds error = errors.New("billing: insufficient funds") // I can hear it... )
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") )
var (
ErrProductListingNotFound = errors.New("billing: product listing not found")
)
Functions ¶
func AddBillingRecord ¶ added in v0.1.0
func AddBillingRecord(record BillingRecord) (uint64, error)
func AddProductListing ¶ added in v0.1.0
func AddProductListing(pl *ProductListing) (uint64, error)
func BillingOptionsToJSON ¶ added in v0.1.0
func BillingOptionsToJSON(billingOptions []BillingOption) (string, error)
func CollectRecurringPayment ¶ added in v0.1.0
func CollectUsageBasedPayment ¶ added in v0.1.0
func DailyRecurringBilling ¶ added in v0.1.0
func DailyRecurringBilling() []error
DailyRecurringBilling() should be called at (at least) a daily basis. It will bill all active recurring billing products that is due.
func DeleteProductListingByID ¶ added in v0.1.0
func DeleteProductListingGroupByID ¶ added in v0.1.0
func ForceCollectRecurringPayment ¶ added in v0.1.0
THIS FUNCTION IS NOT EXPECTED TO BE USED IN ANYWHERE FOR Pre-V2 builds. IT DOES NOT CHECK IF IT IS DUE OR NOT.
func ForceCollectUsageBasedPayment ¶ added in v0.1.0
Be sure to terminate this product after this.
func HourlyProductTermination ¶ added in v0.1.0
func HourlyProductTermination() []error
HourlyProductTermination() should be called at an hourly basis. It will pickup all products that is due to be terminated: - If usage-based, charge the final amount - Terminate Account - Terminate Product
func HourlyUsageBilling ¶ added in v0.1.0
func HourlyUsageBilling() []error
HourlyUsageBilling() should be called at an hourly basis. It will bill all active usage-based billing products.
func ListProductListingGroupIDs ¶ added in v0.1.10
func NewProductListingGroup ¶ added in v0.1.0
func NewProductListingGroup(plg ProductListingGroup) (uint64, error)
func Setup ¶
Setup() of billing package requires: - Previous Setup() of auth package - *sql.DB's dsn has `parseTime=true`
func TerminateProductBySerialNumber ¶ added in v0.0.17
func ToTerminateProductOn ¶ added in v0.1.0
func UpdateProduct ¶
func UpdateProductListing ¶ added in v0.1.0
func UpdateProductListing(pl *ProductListing) error
Types ¶
type BillingOption ¶ added in v0.1.0
type BillingOption struct { BillingCycle uint8 `json:"billing_cycle"` // As defined in billing.go Price float64 `json:"price"` MonthlySpendingCap float64 `json:"monthly_spending_cap"` // Only for Usage-based billing CurrentMonthSpending float64 `json:"current_month_spending"` // Only for Usage-based billing AccountConfiguration map[string]interface{} `json:"account_configuration"` }
func BillingOptionsFromJSON ¶ added in v0.1.0
func BillingOptionsFromJSON(jsonStr string) ([]BillingOption, error)
type BillingRecord ¶ added in v0.1.0
type BillingRecord struct { SerialNumber uint64 WalletID uint64 UserID uint64 ProductID uint64 ProductSerialNumber uint64 BillingCycle uint8 BilledAmount float64 BilledAt time.Time }
func ListAllBillingRecords ¶ added in v0.1.0
func ListAllBillingRecords() ([]BillingRecord, error)
func ListBillingRecordsByWalletID ¶ added in v0.1.0
func ListBillingRecordsByWalletID(walletID uint64) ([]BillingRecord, error)
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. productID is actually the Serial Number of Product Listing WalletID uint64 BillingOption BillingOption // contains filtered or unexported fields }
func GetProductBySerialNumber ¶ added in v0.0.17
func ListActiveProductsByBillingCycle ¶
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
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 ¶
For admin viewing. Client should implement local-pagination
func ListProductsByProductID ¶ added in v0.0.17
For admin viewing.
func ListProductsToTerminate ¶ added in v0.1.0
For auto-billing.
func ListSystemProducts ¶ added in v0.1.10
func ListUserProducts ¶
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) CollectPayment ¶ added in v0.1.0
CollectPayment() expects
func (*Product) DateCreation ¶
func (*Product) DateLastBill ¶ added in v0.1.0
func (*Product) DateTermination ¶
func (*Product) ForceCollectPayment ¶ added in v0.1.0
func (*Product) SerialNumber ¶ added in v0.0.17
func (*Product) Terminated ¶ added in v0.1.0
type ProductListing ¶ added in v0.1.0
type ProductListing struct { ProductGroupID uint64 `json:"product_group_id"` ProductName string `json:"product_name"` ProductDescription string `json:"product_description"` // Internal BizLogic Related ServerType string `json:"server_type"` ServerInstanceID string `json:"server_instance_id"` ServerConfiguration map[string]interface{} `json:"server_configuration"` // a big chunk of JSON BillingOptions []BillingOption `json:"billing_options"` // Stored as JSON Arr UsageBillingFactors UsageBillingFactors `json:"usage_billing_factors"` // Store as JSON Obj // contains filtered or unexported fields }
func GetProductListingByID ¶ added in v0.1.0
func GetProductListingByID(productID uint64) (*ProductListing, error)
For Customer Purchasing. Throwing error for discontinued product
func ListProductListingsByGroupID ¶ added in v0.1.10
func ListProductListingsByGroupID(productGroupID uint64) ([]*ProductListing, error)
For Customer. Not showing hidden/disconiued products
func SudoGetProductListingByID ¶ added in v0.1.0
func SudoGetProductListingByID(productID uint64) (*ProductListing, error)
For Admin Editing/Customer Viewing Existing. Will show discontinued correctly
func SudoListProductListingsByGroupID ¶ added in v0.1.10
func SudoListProductListingsByGroupID(productGroupID uint64) ([]*ProductListing, error)
For Admin. Include hidden/discontinued products
func (*ProductListing) Add ¶ added in v0.1.0
func (pl *ProductListing) Add() (uint64, error)
func (*ProductListing) CreateProduct ¶ added in v0.1.0
func (*ProductListing) Delete ¶ added in v0.1.0
func (pl *ProductListing) Delete() error
func (*ProductListing) Discontinue ¶ added in v0.1.0
func (pl *ProductListing) Discontinue() error
Discontinue() prevents the product from being purchased
func (*ProductListing) Discontinued ¶ added in v0.1.0
func (pl *ProductListing) Discontinued() bool
func (*ProductListing) Hidden ¶ added in v0.1.0
func (pl *ProductListing) Hidden() bool
func (*ProductListing) Hide ¶ added in v0.1.0
func (pl *ProductListing) Hide() error
Hide() prevents the product from being shown by listing
func (*ProductListing) ProductID ¶ added in v0.1.0
func (pl *ProductListing) ProductID() uint64
func (*ProductListing) Reactivate ¶ added in v0.1.0
func (pl *ProductListing) Reactivate() error
Reactivate() undo the Discontinue()
func (*ProductListing) Save ¶ added in v0.1.0
func (pl *ProductListing) Save() error
func (*ProductListing) Unhide ¶ added in v0.1.0
func (pl *ProductListing) Unhide() error
Unhide() undo the Hide()
type ProductListingGroup ¶ added in v0.1.0
type ProductListingGroup struct { ProductGroupID uint64 `json:"product_group_id"` ProductGroupName string `json:"product_group_name"` ProductGroupDescription string `json:"product_group_description"` Hidden bool `json:"hidden"` }
func GetProductListingGroupByID ¶ added in v0.1.0
func GetProductListingGroupByID(id uint64) (ProductListingGroup, error)
func (ProductListingGroup) Delete ¶ added in v0.1.0
func (plg ProductListingGroup) Delete() error
func (ProductListingGroup) Save ¶ added in v0.1.0
func (plg ProductListingGroup) Save() error
type UsageBillingFactor ¶ added in v0.1.0
type UsageBillingFactor struct { BillingGroupID uint8 `json:"billing_group_id"` ResourceID uint64 `json:"resource_id"` // see: Ulysses.Lib/server/resource.go UnitPrice float64 `json:"unit_price"` // UnitPrice * Used = Price }
func (*UsageBillingFactor) CalculatePrice ¶ added in v0.1.0
func (ubf *UsageBillingFactor) CalculatePrice(used float64) float64
type UsageBillingFactors ¶ added in v0.1.0
type UsageBillingFactors struct { PricingPolicy uint8 `json:"pricing_policy"` // 0 - SUM(GroupPrice...), 1 - MAX(GroupPrice...), 2 - MIN(GroupPrice...) Factors map[uint8][]*UsageBillingFactor `json:"factors"` // key: BillingGroupID }
func UsageBillingFactorsFromJSON ¶ added in v0.1.0
func UsageBillingFactorsFromJSON(jsonStr string) (*UsageBillingFactors, error)
func (*UsageBillingFactors) CalculateTotalPrice ¶ added in v0.1.0
func (ubfs *UsageBillingFactors) CalculateTotalPrice(resUsageMap map[uint64]float64) (float64, error)
for resUsageMap, uint64 is the ResourceID, float64 is the usage
func (*UsageBillingFactors) ToJSON ¶ added in v0.1.0
func (ubfs *UsageBillingFactors) ToJSON() (string, error)
type Wallet ¶
type Wallet struct {
// contains filtered or unexported fields
}
func GetWalletByID ¶ added in v0.0.17
GetWalletByID() build a Wallet struct reflecting an entry in the database.