stripecoinpayments

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChore = errs.Class("stripecoinpayments chore error")

ErrChore is stripecoinpayments clearing loop chore error class.

View Source
var ErrNoCustomer = Error.New("customer doesn't exist")

ErrNoCustomer is error class defining that there is no customer for user.

View Source
var ErrProjectRecordExists = Error.New("invoice project record already exists")

ErrProjectRecordExists is error class defining that such project record already exists.

View Source
var ErrVersion = errs.Class("version service error")

ErrVersion defines version service error.

View Source
var (
	// Error defines stripecoinpayments service error.
	Error = errs.Class("stripecoinpayments service error")
)

Functions

This section is empty.

Types

type Chore added in v0.25.0

type Chore struct {
	TransactionCycle    sync2.Cycle
	AccountBalanceCycle sync2.Cycle
	// contains filtered or unexported fields
}

Chore runs clearing process of reconciling transactions deposits, customer balance, invoices and usages.

architecture: Chore

func NewChore added in v0.25.0

func NewChore(log *zap.Logger, service *Service, txInterval time.Duration, accBalanceInterval time.Duration) *Chore

NewChore creates new clearing loop chore.

func (*Chore) Close added in v0.25.0

func (chore *Chore) Close() (err error)

Close closes all underlying resources.

func (*Chore) Run added in v0.25.0

func (chore *Chore) Run(ctx context.Context) (err error)

Run runs all clearing related cycles.

type Config

type Config struct {
	StripeSecretKey              string        `help:"stripe API secret key" default:""`
	StripePublicKey              string        `help:"stripe API public key" default:""`
	CoinpaymentsPublicKey        string        `help:"coinpayments API public key" default:""`
	CoinpaymentsPrivateKey       string        `help:"coinpayments API private key key" default:""`
	TransactionUpdateInterval    time.Duration `help:"amount of time we wait before running next transaction update loop" devDefault:"1m" releaseDefault:"30m"`
	AccountBalanceUpdateInterval time.Duration `help:"amount of time we wait before running next account balance update loop" devDefault:"3m" releaseDefault:"1h30m"`
	ConversionRatesCycleInterval time.Duration `help:"amount of time we wait before running next conversion rates update loop" devDefault:"1m" releaseDefault:"10m"`
}

Config stores needed information for payment service initialization.

type CreateProjectRecord added in v0.25.0

type CreateProjectRecord struct {
	ProjectID uuid.UUID
	Storage   float64
	Egress    int64
	Objects   int64
}

CreateProjectRecord holds info needed for creation new invoice project record.

type Customer added in v0.25.0

type Customer struct {
	ID     string
	UserID uuid.UUID
}

Customer holds customer id and user id.

type CustomersDB

type CustomersDB interface {
	// Insert inserts a stripe customer into the database.
	Insert(ctx context.Context, userID uuid.UUID, customerID string) error
	// GetCustomerID return stripe customers id.
	GetCustomerID(ctx context.Context, userID uuid.UUID) (string, error)
	// List returns page with customers ids created before specified date.
	List(ctx context.Context, offset int64, limit int, before time.Time) (CustomersPage, error)
}

CustomersDB is interface for working with stripe customers table.

architecture: Database

type CustomersPage added in v0.25.0

type CustomersPage struct {
	Customers  []Customer
	Next       bool
	NextOffset int64
}

CustomersPage holds customers and indicates if there is more data available and provides next offset.

type DB added in v0.25.0

type DB interface {
	// Customers is getter for customers db.
	Customers() CustomersDB
	// Transactions is getter for transactions db.
	Transactions() TransactionsDB
	// ProjectRecords is getter for invoice project records db.
	ProjectRecords() ProjectRecordsDB
}

DB is stripecoinpayments DB interface.

architecture: Database

type Endpoint added in v0.25.0

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

Endpoint is stripecoinpayments private RPC server payments endpoint.

func NewEndpoint added in v0.25.0

func NewEndpoint(service *Service) *Endpoint

NewEndpoint creates new endpoint.

func (*Endpoint) ApplyInvoiceRecords added in v0.25.0

func (endpoint *Endpoint) ApplyInvoiceRecords(ctx context.Context, req *pb.ApplyInvoiceRecordsRequest) (_ *pb.ApplyInvoiceRecordsResponse, err error)

ApplyInvoiceRecords creates stripe line items for all unapplied invoice project records.

func (*Endpoint) CreateInvoices added in v0.25.0

func (endpoint *Endpoint) CreateInvoices(ctx context.Context, req *pb.CreateInvoicesRequest) (_ *pb.CreateInvoicesResponse, err error)

CreateInvoices creates invoice for all user accounts on the satellite.

func (*Endpoint) PrepareInvoiceRecords added in v0.25.0

func (endpoint *Endpoint) PrepareInvoiceRecords(ctx context.Context, req *pb.PrepareInvoiceRecordsRequest) (_ *pb.PrepareInvoiceRecordsResponse, err error)

PrepareInvoiceRecords creates project invoice records for all satellite projects.

type ProjectRecord added in v0.25.0

type ProjectRecord struct {
	ID          uuid.UUID
	ProjectID   uuid.UUID
	Storage     float64
	Egress      int64
	Objects     int64
	PeriodStart time.Time
	PeriodEnd   time.Time
}

ProjectRecord holds project usage particular for billing period.

type ProjectRecordsDB added in v0.25.0

type ProjectRecordsDB interface {
	// Create creates new invoice project record in the DB.
	Create(ctx context.Context, records []CreateProjectRecord, start, end time.Time) error
	// Check checks if invoice project record for specified project and billing period exists.
	Check(ctx context.Context, projectID uuid.UUID, start, end time.Time) error
	// Consume consumes invoice project record.
	Consume(ctx context.Context, id uuid.UUID) error
	// ListUnapplied returns project records page with unapplied project records.
	ListUnapplied(ctx context.Context, offset int64, limit int, before time.Time) (ProjectRecordsPage, error)
}

ProjectRecordsDB is interface for working with invoice project records.

architecture: Database

type ProjectRecordsPage added in v0.25.0

type ProjectRecordsPage struct {
	Records    []ProjectRecord
	Next       bool
	NextOffset int64
}

ProjectRecordsPage holds project records and indicates if there is more data available and provides next offset.

type Service

type Service struct {
	PerObjectPrice int64
	EgressPrice    int64
	TBhPrice       int64
	// contains filtered or unexported fields
}

Service is an implementation for payment service via Stripe and Coinpayments.

architecture: Service

func NewService

func NewService(log *zap.Logger, config Config, db DB, projectsDB console.Projects, usageDB accounting.ProjectAccounting, perObjectPrice, egressPrice, tbhPrice int64) *Service

NewService creates a Service instance.

func (*Service) Accounts

func (service *Service) Accounts() payments.Accounts

Accounts exposes all needed functionality to manage payment accounts.

func (*Service) CreateInvoices added in v0.25.0

func (service *Service) CreateInvoices(ctx context.Context) (err error)

CreateInvoices lists through all customers and creates invoices.

func (*Service) GetRate added in v0.26.0

func (service *Service) GetRate(ctx context.Context, curr1, curr2 coinpayments.Currency) (_ *big.Float, err error)

GetRate returns conversion rate for specified currencies.

func (*Service) InvoiceApplyProjectRecords added in v0.25.0

func (service *Service) InvoiceApplyProjectRecords(ctx context.Context) (err error)

InvoiceApplyProjectRecords iterates through unapplied invoice project records and creates invoice line items for stripe customer.

func (*Service) PrepareInvoiceProjectRecords added in v0.25.0

func (service *Service) PrepareInvoiceProjectRecords(ctx context.Context, period time.Time) (err error)

PrepareInvoiceProjectRecords iterates through all projects and creates invoice records if none exists.

func (*Service) UpdateRates added in v0.26.0

func (service *Service) UpdateRates(ctx context.Context) (err error)

UpdateRates fetches new rates and updates service rate cache.

type Transaction

type Transaction struct {
	ID        coinpayments.TransactionID
	AccountID uuid.UUID
	Address   string
	Amount    big.Float
	Received  big.Float
	Status    coinpayments.Status
	Key       string
	Timeout   time.Duration
	CreatedAt time.Time
}

Transaction defines coinpayments transaction info that is stored in the DB.

type TransactionUpdate

type TransactionUpdate struct {
	TransactionID coinpayments.TransactionID
	Status        coinpayments.Status
	Received      big.Float
}

TransactionUpdate holds transaction update info.

type TransactionsDB

type TransactionsDB interface {
	// Insert inserts new coinpayments transaction into DB.
	Insert(ctx context.Context, tx Transaction) (*Transaction, error)
	// Update updates status and received for set of transactions.
	Update(ctx context.Context, updates []TransactionUpdate, applies coinpayments.TransactionIDList) error
	// Consume marks transaction as consumed, so it won't participate in apply account balance loop.
	Consume(ctx context.Context, id coinpayments.TransactionID) error
	// LockRate locks conversion rate for transaction.
	LockRate(ctx context.Context, id coinpayments.TransactionID, rate *big.Float) error
	// GetLockedRate returns locked conversion rate for transaction or error if non exists.
	GetLockedRate(ctx context.Context, id coinpayments.TransactionID) (*big.Float, error)
	// ListAccount returns all transaction for specific user.
	ListAccount(ctx context.Context, userID uuid.UUID) ([]Transaction, error)
	// ListPending returns TransactionsPage with pending transactions.
	ListPending(ctx context.Context, offset int64, limit int, before time.Time) (TransactionsPage, error)
	// List Unapplied returns TransactionsPage with completed transaction that should be applied to account balance.
	ListUnapplied(ctx context.Context, offset int64, limit int, before time.Time) (TransactionsPage, error)
}

TransactionsDB is an interface which defines functionality of DB which stores coinpayments transactions.

architecture: Database

type TransactionsPage

type TransactionsPage struct {
	Transactions []Transaction
	Next         bool
	NextOffset   int64
}

TransactionsPage holds set of transaction and indicates if there are more transactions to fetch.

func (*TransactionsPage) IDList

IDList returns transaction id list of page's transactions.

type VersionService added in v0.26.0

type VersionService struct {
	Cycle sync2.Cycle
	// contains filtered or unexported fields
}

VersionService updates conversion rates in a loop.

architecture: Service

func NewVersionService added in v0.26.0

func NewVersionService(log *zap.Logger, service *Service, interval time.Duration) *VersionService

NewVersionService creates new instance of VersionService.

func (*VersionService) Close added in v0.26.0

func (version *VersionService) Close() (err error)

Close closes underlying cycle.

func (*VersionService) Run added in v0.26.0

func (version *VersionService) Run(ctx context.Context) (err error)

Run runs loop which updates conversion rates for service.

Jump to

Keyboard shortcuts

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