storj/satellite/payments/balance.go
Cameron a2e3247471 satellite/payments: add Balances interface
Add and implement interface to manage customer balances. Adds ability to
add credit to a user's balance, list balance transactions, and get the
balance.

Change-Id: I7fd65d07868bb2b7489d1141a5e9049514d6984e
2023-03-31 21:51:37 +00:00

43 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package payments
import (
"context"
"github.com/shopspring/decimal"
"storj.io/common/uuid"
)
// Balances exposes needed functionality for managing customer balances.
type Balances interface {
// ApplyCredit applies a credit of `amount` to the user's stripe balance with a description of `desc`.
ApplyCredit(ctx context.Context, userID uuid.UUID, amount int64, desc string) (*Balance, error)
// Get returns the customer balance.
Get(ctx context.Context, userID uuid.UUID) (Balance, error)
// ListTransactions returns a list of transactions on the customer's balance.
ListTransactions(ctx context.Context, userID uuid.UUID) ([]BalanceTransaction, error)
}
// Balance is an entity that holds free credits and coins balance of user.
// Earned by applying of promotional coupon and coins depositing, respectively.
type Balance struct {
FreeCredits int64 `json:"freeCredits"`
Coins decimal.Decimal `json:"coins"` // STORJ token balance from storjscan.
Credits decimal.Decimal `json:"credits"`
// Credits is the balance (in cents) from stripe. This may include the following.
// 1. legacy Coinpayments deposit.
// 2. legacy credit for a manual STORJ deposit.
// 4. bonus manually credited for a storjscan payment once a month before invoicing.
// 5. any other adjustment we may have to make from time to time manually to the customer´s STORJ balance.
}
// BalanceTransaction represents a single transaction affecting a customer balance.
type BalanceTransaction struct {
ID string
Amount int64
Description string
}