digitalocean

package
v1.799.2 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package do reads DigitalOcean's billing API for the finance dashboard's cost side. DO is our PRIMARY venue (a large promotional credit); this client turns the customer balance + billing history into money.Cents the finance aggregator folds into gross margin and runway.

Auth is a single personal-access token, DO_API_TOKEN, sourced from a KMSSecret on the cloud env — NEVER hard-coded. When the token is unset the client is not Ready and every read reports the honest not-configured state.

SIGN CONVENTION (from DO's public OpenAPI spec): GET /v2/customers/my/balance returns decimal-dollar strings; account_balance carries the accounts-receivable sign — POSITIVE = we OWE DO, NEGATIVE = we hold CREDIT. Our promo credit shows as a negative account balance, so credit-remaining = -Account. Dollars are converted to cents once at this edge; everything downstream is money.Cents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balance

type Balance struct {
	Account     money.Cents
	MonthToDate money.Cents
	Usage       money.Cents
	At          string
}

Balance is the decoded /v2/customers/my/balance, in cents. Account carries DO's accounts-receivable sign (positive = owed to DO, negative = credit we hold).

type Client

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

Client reads DigitalOcean billing with a personal-access token.

func New

func New(token string) *Client

New builds a DO client against the public API.

func NewWithBase

func NewWithBase(base, token string) *Client

NewWithBase builds a DO client against base (a test may point it at a stub).

func (*Client) Balance

func (c *Client) Balance(ctx context.Context) (Balance, error)

Balance fetches the customer balance, converting every dollar string to cents.

func (*Client) History

func (c *Client) History(ctx context.Context, perPage int) ([]Entry, error)

History fetches recent billing history. Used only for the burn-down series; a failure is non-fatal to the caller (it renders the balance tiles with no series).

func (*Client) Ready

func (c *Client) Ready() bool

Ready reports whether a DO token is present.

type Entry

type Entry struct {
	Description string
	Amount      money.Cents
	Date        string
	Kind        string
	InvoiceID   string
}

Entry is one billing-history row (used to build the credit burn-down series).

Jump to

Keyboard shortcuts

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