2019-10-10 18:12:23 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellitedb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
|
|
|
|
dbx "storj.io/storj/satellite/satellitedb/dbx"
|
|
|
|
)
|
|
|
|
|
2019-10-11 16:00:35 +01:00
|
|
|
// customers is an implementation of stripecoinpayments.CustomersDB.
|
2019-10-10 18:12:23 +01:00
|
|
|
type customers struct {
|
|
|
|
db *dbx.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert inserts a stripe customer into the database.
|
|
|
|
func (customers *customers) Insert(ctx context.Context, userID uuid.UUID, customerID string) (err error) {
|
|
|
|
defer mon.Task()(&ctx, userID, customerID)(&err)
|
|
|
|
|
2019-10-15 19:05:45 +01:00
|
|
|
_, err = customers.db.Create_StripeCustomer(
|
2019-10-10 18:12:23 +01:00
|
|
|
ctx,
|
2019-10-15 19:05:45 +01:00
|
|
|
dbx.StripeCustomer_UserId(userID[:]),
|
|
|
|
dbx.StripeCustomer_CustomerId(customerID),
|
2019-10-10 18:12:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
2019-10-11 16:00:35 +01:00
|
|
|
|
|
|
|
// GetCustomerID return stripe customers id.
|
|
|
|
func (customers *customers) GetCustomerID(ctx context.Context, userID uuid.UUID) (customerID string, err error) {
|
|
|
|
defer mon.Task()(&ctx, userID)(&err)
|
|
|
|
|
2019-10-15 19:05:45 +01:00
|
|
|
idRow, err := customers.db.Get_StripeCustomer_CustomerId_By_UserId(ctx, dbx.StripeCustomer_UserId(userID[:]))
|
2019-10-11 16:00:35 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return idRow.CustomerId, nil
|
|
|
|
}
|