payments

package
v0.28.3 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: AGPL-3.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const STORJTokenPrecision = 32

STORJTokenPrecision defines STORJ token precision.

Variables

View Source
var ErrAccountNotSetup = errs.Class("payment account is not set up")

ErrAccountNotSetup is an error type which indicates that payment account is not created.

Functions

This section is empty.

Types

type Accounts added in v0.24.0

type Accounts interface {
	// Setup creates a payment account for the user.
	// If account is already set up it will return nil.
	Setup(ctx context.Context, userID uuid.UUID, email string) error

	// Balance returns an integer amount in cents that represents the current balance of payment account.
	Balance(ctx context.Context, userID uuid.UUID) (int64, error)

	// ProjectCharges returns how much money current user will be charged for each project.
	ProjectCharges(ctx context.Context, userID uuid.UUID) ([]ProjectCharge, error)

	// Coupons return list of all coupons of specified payment account.
	Coupons(ctx context.Context, userID uuid.UUID) ([]Coupon, error)

	// CreditCards exposes all needed functionality to manage account credit cards.
	CreditCards() CreditCards

	// StorjTokens exposes all storj token related functionality.
	StorjTokens() StorjTokens

	// Invoices exposes all needed functionality to manage account invoices.
	Invoices() Invoices
}

Accounts exposes all needed functionality to manage payment accounts.

type Coupon added in v0.27.0

type Coupon struct {
	ID          uuid.UUID     `json:"id"`
	UserID      uuid.UUID     `json:"userId"`
	ProjectID   uuid.UUID     `json:"projectId"`
	Amount      int64         `json:"amount"`   // Amount is stored in cents.
	Duration    time.Duration `json:"duration"` // Duration is stored in days.
	Description string        `json:"description"`
	Status      CouponStatus  `json:"status"`
	Created     time.Time     `json:"created"`
}

Coupon is an entity that adds some funds to Accounts balance for some fixed period. Coupon is attached to the project. At the end of the period, the entire remaining coupon amount will be returned from the account balance.

type CouponStatus added in v0.27.0

type CouponStatus int

CouponStatus indicates the state of the coupon.

const (
	// CouponActive is a default coupon state.
	CouponActive CouponStatus = 0
	// CouponUsed status indicates that coupon was used.
	CouponUsed CouponStatus = 1
	// CouponExpired status indicates that coupon is expired and unavailable.
	CouponExpired CouponStatus = 2
)

type CouponsPage added in v0.27.0

type CouponsPage struct {
	Coupons    []Coupon
	Next       bool
	NextOffset int64
}

CouponsPage holds set of coupon and indicates if there are more coupons to fetch.

type CreditCard added in v0.24.0

type CreditCard struct {
	ID        string `json:"id"`
	ExpMonth  int    `json:"expMonth"`
	ExpYear   int    `json:"expYear"`
	Brand     string `json:"brand"`
	Last4     string `json:"last4"`
	IsDefault bool   `json:"isDefault"`
}

CreditCard holds all public information about credit card.

type CreditCards added in v0.24.0

type CreditCards interface {
	// List returns a list of credit cards for a given payment account.
	List(ctx context.Context, userID uuid.UUID) ([]CreditCard, error)

	// Add is used to save new credit card and attach it to payment account.
	Add(ctx context.Context, userID uuid.UUID, cardToken string) error

	// Remove is used to detach a credit card from payment account.
	Remove(ctx context.Context, userID uuid.UUID, cardID string) error

	// MakeDefault makes a credit card default payment method.
	// this credit card should be attached to account before make it default.
	MakeDefault(ctx context.Context, userID uuid.UUID, cardID string) error
}

CreditCards exposes all needed functionality to manage account credit cards.

type Invoice

type Invoice struct {
	ID          string    `json:"id"`
	Description string    `json:"description"`
	Amount      int64     `json:"amount"`
	Status      string    `json:"status"`
	Link        string    `json:"link"`
	Start       time.Time `json:"start"`
	End         time.Time `json:"end"`
}

Invoice holds all public information about invoice.

type Invoices added in v0.25.0

type Invoices interface {
	// List returns a list of invoices for a given payment account.
	List(ctx context.Context, userID uuid.UUID) ([]Invoice, error)
}

Invoices exposes all needed functionality to manage account invoices.

type ProjectCharge added in v0.26.0

type ProjectCharge struct {
	ProjectID uuid.UUID `json:"projectId"`
	// StorageGbHrs shows how much cents we should pay for storing GB*Hrs.
	StorageGbHrs int64 `json:"storage"`
	// Egress shows how many cents we should pay for Egress.
	Egress int64 `json:"egress"`
	// ObjectCount shows how many cents we should pay for objects count.
	ObjectCount int64 `json:"objectCount"`
}

ProjectCharge shows how much money current project will charge in the end of the month.

type StorjTokens added in v0.24.0

type StorjTokens interface {
	// Deposit creates deposit transaction for specified amount in cents.
	Deposit(ctx context.Context, userID uuid.UUID, amount int64) (*Transaction, error)
	// ListTransactionInfos returns all transaction associated with user.
	ListTransactionInfos(ctx context.Context, userID uuid.UUID) ([]TransactionInfo, error)
}

StorjTokens defines all payments STORJ token related functionality.

type TokenAmount added in v0.26.0

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

TokenAmount is a wrapper type for STORJ token amount. Uses big.Float as inner representation. Precision is set to 32 so it can properly handle 8 digits after point which is STORJ token decimal set.

func NewTokenAmount added in v0.26.0

func NewTokenAmount() *TokenAmount

NewTokenAmount creates new zeroed TokenAmount with fixed precision.

func ParseTokenAmount added in v0.26.0

func ParseTokenAmount(s string) (*TokenAmount, error)

ParseTokenAmount parses string representing floating point and returns TokenAmount.

func TokenAmountFromBigFloat added in v0.26.0

func TokenAmountFromBigFloat(f *big.Float) *TokenAmount

TokenAmountFromBigFloat converts big.Float to TokenAmount.

func (*TokenAmount) BigFloat added in v0.26.0

func (amount *TokenAmount) BigFloat() *big.Float

BigFloat returns inner representation of TokenAmount.

func (*TokenAmount) String added in v0.26.0

func (amount *TokenAmount) String() string

String representation of TokenValue.

type Transaction added in v0.24.0

type Transaction struct {
	ID        TransactionID
	Amount    TokenAmount
	Rate      big.Float
	Address   string
	Status    TransactionStatus
	Timeout   time.Duration
	Link      string
	CreatedAt time.Time
}

Transaction defines deposit transaction which accepts user funds on a specific wallet address.

type TransactionID added in v0.24.0

type TransactionID []byte

TransactionID is a transaction ID type.

func (TransactionID) String added in v0.26.0

func (id TransactionID) String() string

String returns string representation of transaction id.

type TransactionInfo added in v0.26.0

type TransactionInfo struct {
	ID            TransactionID
	Amount        TokenAmount
	Received      TokenAmount
	AmountCents   int64
	ReceivedCents int64
	Address       string
	Status        TransactionStatus
	Link          string
	ExpiresAt     time.Time
	CreatedAt     time.Time
}

TransactionInfo holds transaction data with additional information such as links and expiration time.

type TransactionStatus added in v0.24.0

type TransactionStatus string

TransactionStatus defines allowed statuses for deposit transactions.

const (
	// TransactionStatusPaid is a transaction which successfully received required funds.
	TransactionStatusPaid TransactionStatus = "paid"
	// TransactionStatusPending is a transaction which accepts funds.
	TransactionStatusPending TransactionStatus = "pending"
	// TransactionStatusCancelled is a transaction that is cancelled and no longer accepting new funds.
	TransactionStatusCancelled TransactionStatus = "cancelled"
)

func (TransactionStatus) String added in v0.26.0

func (status TransactionStatus) String() string

String returns string representation of transaction status.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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