payout

package
v1.801.307 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package payout is the ONE attributed-credit money seam shared by the credit programs — referrals, affiliates, authors: read an org's metered spend (the qualify / accrual base) and grant a promo credit to its wallet (a payout made in credits, landing in commerce's Credit/trial bucket). It was three byte-identical commerce.go copies (their own doc-comments said so); extracted here so the S2S commerce binding — the HTTP deposit + usage-rollup path — lives exactly ONCE.

Every payout lands via the SAME COMMERCE_SERVICE_TOKEN S2S path, the same X-Org-Id=<org> namespace + bare-org `user` subject that admin.grantCredit uses, so it is indistinguishable from an admin grant except by its ledger tag (grant:referral / grant:affiliate / grant:author, all → the commerce Credit/trial bucket per DepositKind's grant:* rule). The tag is supplied BY THE CALLER, so payout carries zero program domain logic — it is the money seam, nothing else.

Commerce is an INTERFACE so each program's store/handler logic stays testable with a fake ledger; Client is the ONE production binding. A program keeps its own narrow (unexported-method) seam and a thin adapter delegating to Client — Go package-scoped interface methods can't cross packages, and the adapter is where a program still names its own grant tag.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnconfigured = errors.New("payout: commerce endpoint not configured")

ErrUnconfigured is returned by a Deposit against an unwired commerce so the caller records an honest failure rather than reporting a phantom grant.

Functions

This section is empty.

Types

type Client

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

Client is the production commerce binding (COMMERCE_SERVICE_TOKEN S2S).

func NewClient

func NewClient(base, token string) *Client

NewClient builds the production binding. base is the commerce HTTP URL (via transport.BaseURL at the call site); token is COMMERCE_SERVICE_TOKEN.

func (*Client) Configured

func (c *Client) Configured() bool

func (*Client) Deposit

func (c *Client) Deposit(ctx context.Context, org, user string, amountCents int64, currency, notes, tags string) (string, error)

Deposit posts POST /v1/billing/deposit — the ONE money-in primitive (identical to admin.grantCredit's deposit). Commerce's EdgeAuth pins the body `user` to the X-Org-Id subject, so a payout can never be mis-targeted to another wallet.

func (*Client) SpendCents

func (c *Client) SpendCents(ctx context.Context, org, user string) (int64, error)

SpendCents reads GET /v1/billing/usage-rollup and returns consumedCents. Zero (not an error) when commerce is unconfigured so a partial deploy degrades to "no spend to accrue yet" rather than a 5xx.

type Commerce

type Commerce interface {
	Configured() bool
	// Deposit grants amountCents to org's wallet (Credit/trial bucket via the
	// caller-supplied grant:* tag) and returns the ledger transaction id.
	Deposit(ctx context.Context, org, user string, amountCents int64, currency, notes, tags string) (txnID string, err error)
	// SpendCents is the org's month-to-date metered consumption — the qualify
	// signal / commission accrual base (spend × the program's rate).
	SpendCents(ctx context.Context, org, user string) (int64, error)
}

Commerce is the narrow money seam an attributed-credit program needs: read a referred/deploying org's metered spend and grant a credit to a wallet. The HTTP impl (Client) below is the ONE production binding.

Jump to

Keyboard shortcuts

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