2019-11-05 13:16:02 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2023-04-06 12:41:14 +01:00
|
|
|
package stripe
|
2019-11-05 13:16:02 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2020-03-30 10:08:50 +01:00
|
|
|
"storj.io/common/uuid"
|
2019-11-05 13:16:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ErrProjectRecordExists is error class defining that such project record already exists.
|
|
|
|
var ErrProjectRecordExists = Error.New("invoice project record already exists")
|
|
|
|
|
|
|
|
// ProjectRecordsDB is interface for working with invoice project records.
|
|
|
|
//
|
|
|
|
// architecture: Database
|
|
|
|
type ProjectRecordsDB interface {
|
2021-08-27 01:51:26 +01:00
|
|
|
// Create creates new invoice project record with credits spendings in the DB.
|
|
|
|
Create(ctx context.Context, records []CreateProjectRecord, start, end time.Time) error
|
2019-11-05 13:16:02 +00:00
|
|
|
// 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
|
2020-01-07 10:41:19 +00:00
|
|
|
// Get returns record for specified project and billing period.
|
|
|
|
Get(ctx context.Context, projectID uuid.UUID, start, end time.Time) (*ProjectRecord, error)
|
2019-11-05 13:16:02 +00:00
|
|
|
// Consume consumes invoice project record.
|
|
|
|
Consume(ctx context.Context, id uuid.UUID) error
|
|
|
|
// ListUnapplied returns project records page with unapplied project records.
|
2020-05-12 09:46:48 +01:00
|
|
|
ListUnapplied(ctx context.Context, offset int64, limit int, start, end time.Time) (ProjectRecordsPage, error)
|
2019-11-05 13:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateProjectRecord holds info needed for creation new invoice
|
|
|
|
// project record.
|
|
|
|
type CreateProjectRecord struct {
|
|
|
|
ProjectID uuid.UUID
|
|
|
|
Storage float64
|
|
|
|
Egress int64
|
2021-10-20 23:54:34 +01:00
|
|
|
Segments float64
|
2019-11-05 13:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ProjectRecord holds project usage particular for billing period.
|
|
|
|
type ProjectRecord struct {
|
|
|
|
ID uuid.UUID
|
|
|
|
ProjectID uuid.UUID
|
|
|
|
Storage float64
|
|
|
|
Egress int64
|
2021-10-20 23:54:34 +01:00
|
|
|
Segments float64
|
2019-11-05 13:16:02 +00:00
|
|
|
PeriodStart time.Time
|
|
|
|
PeriodEnd time.Time
|
2020-07-06 21:15:55 +01:00
|
|
|
State int
|
2019-11-05 13:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ProjectRecordsPage holds project records and
|
|
|
|
// indicates if there is more data available
|
|
|
|
// and provides next offset.
|
|
|
|
type ProjectRecordsPage struct {
|
|
|
|
Records []ProjectRecord
|
|
|
|
Next bool
|
|
|
|
NextOffset int64
|
|
|
|
}
|