2019-10-10 18:12:23 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2023-04-06 12:41:14 +01:00
|
|
|
package stripe
|
2019-10-10 18:12:23 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-11-05 13:16:02 +00:00
|
|
|
"time"
|
2019-10-10 18:12:23 +01:00
|
|
|
|
2020-03-30 10:08:50 +01:00
|
|
|
"storj.io/common/uuid"
|
2021-03-04 22:55:48 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/dbx"
|
2019-10-10 18:12:23 +01:00
|
|
|
)
|
|
|
|
|
2019-11-05 13:16:02 +00:00
|
|
|
// ErrNoCustomer is error class defining that there is no customer for user.
|
|
|
|
var ErrNoCustomer = Error.New("customer doesn't exist")
|
|
|
|
|
2019-10-11 16:00:35 +01:00
|
|
|
// CustomersDB is interface for working with stripe customers table.
|
2019-11-04 12:30:07 +00:00
|
|
|
//
|
|
|
|
// architecture: Database
|
2019-10-11 16:00:35 +01:00
|
|
|
type CustomersDB interface {
|
2019-10-10 18:12:23 +01:00
|
|
|
// Insert inserts a stripe customer into the database.
|
|
|
|
Insert(ctx context.Context, userID uuid.UUID, customerID string) error
|
2019-10-11 16:00:35 +01:00
|
|
|
// GetCustomerID return stripe customers id.
|
|
|
|
GetCustomerID(ctx context.Context, userID uuid.UUID) (string, error)
|
2023-02-13 17:32:39 +00:00
|
|
|
// GetUserID return userID given stripe customer id.
|
|
|
|
GetUserID(ctx context.Context, customerID string) (uuid.UUID, error)
|
2019-11-05 13:16:02 +00:00
|
|
|
// List returns page with customers ids created before specified date.
|
|
|
|
List(ctx context.Context, offset int64, limit int, before time.Time) (CustomersPage, error)
|
2023-03-22 20:23:44 +00:00
|
|
|
// UpdatePackage updates the customer's package plan and purchase time.
|
|
|
|
UpdatePackage(ctx context.Context, userID uuid.UUID, packagePlan *string, timestamp *time.Time) (*Customer, error)
|
|
|
|
// GetPackageInfo returns the package plan and time of purchase for a user.
|
|
|
|
GetPackageInfo(ctx context.Context, userID uuid.UUID) (packagePlan *string, purchaseTime *time.Time, err error)
|
2021-03-04 22:55:48 +00:00
|
|
|
|
|
|
|
// TODO: get rid of this.
|
|
|
|
Raw() *dbx.DB
|
2019-11-05 13:16:02 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 20:23:44 +00:00
|
|
|
// Customer holds customer id, user id, and package information.
|
2019-11-05 13:16:02 +00:00
|
|
|
type Customer struct {
|
2023-03-22 20:23:44 +00:00
|
|
|
ID string
|
|
|
|
UserID uuid.UUID
|
|
|
|
PackagePlan *string
|
|
|
|
PackagePurchasedAt *time.Time
|
2019-11-05 13:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CustomersPage holds customers and
|
|
|
|
// indicates if there is more data available
|
|
|
|
// and provides next offset.
|
|
|
|
type CustomersPage struct {
|
|
|
|
Customers []Customer
|
|
|
|
Next bool
|
|
|
|
NextOffset int64
|
2019-10-10 18:12:23 +01:00
|
|
|
}
|