2020-05-12 18:16:04 +01:00
|
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
|
|
package payments
|
|
|
|
|
|
2022-11-30 16:24:09 +00:00
|
|
|
|
import (
|
2023-03-24 22:25:36 +00:00
|
|
|
|
"context"
|
|
|
|
|
|
2022-11-30 16:24:09 +00:00
|
|
|
|
"github.com/shopspring/decimal"
|
2023-03-24 22:25:36 +00:00
|
|
|
|
|
|
|
|
|
"storj.io/common/uuid"
|
2022-11-30 16:24:09 +00:00
|
|
|
|
)
|
|
|
|
|
|
2023-03-24 22:25:36 +00:00
|
|
|
|
// 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)
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 18:16:04 +01:00
|
|
|
|
// 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 {
|
2022-11-30 16:24:09 +00:00
|
|
|
|
FreeCredits int64 `json:"freeCredits"`
|
2023-03-05 18:49:32 +00:00
|
|
|
|
Coins decimal.Decimal `json:"coins"` // STORJ token balance from storjscan.
|
|
|
|
|
Credits decimal.Decimal `json:"credits"`
|
2023-03-17 14:37:28 +00:00
|
|
|
|
// Credits is the balance (in cents) from stripe. This may include the following.
|
2023-03-05 18:49:32 +00:00
|
|
|
|
// 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.
|
2020-05-12 18:16:04 +01:00
|
|
|
|
}
|
2023-03-24 22:25:36 +00:00
|
|
|
|
|
|
|
|
|
// BalanceTransaction represents a single transaction affecting a customer balance.
|
|
|
|
|
type BalanceTransaction struct {
|
|
|
|
|
ID string
|
|
|
|
|
Amount int64
|
|
|
|
|
Description string
|
|
|
|
|
}
|
2023-03-22 15:28:52 +00:00
|
|
|
|
|
|
|
|
|
// PackagePlan is an amount to charge a user one time in exchange for credit of greater value.
|
|
|
|
|
// Price and Credit are in cents USD.
|
|
|
|
|
type PackagePlan struct {
|
|
|
|
|
Price int64
|
|
|
|
|
Credit int64
|
|
|
|
|
}
|