satellite/payments: coupon addition removed

Change-Id: I92781d9133603fdefd58b19a6f0ac6b1c6df3ac6
This commit is contained in:
crawter 2020-01-14 18:01:29 +02:00 committed by Yehor Butko
parent cd4ff0722e
commit 41d5e86306
7 changed files with 6 additions and 101 deletions

View File

@ -95,11 +95,6 @@ var (
Short: "Creates stripe invoice line items for not consumed project records",
RunE: createInvoiceItems,
}
prepareInvoiceCouponsCmd = &cobra.Command{
Use: "prepare-invoice-coupons",
Short: "Creates coupon usage for all satellite projects",
RunE: prepareInvoiceCoupons,
}
createInvoiceCouponsCmd = &cobra.Command{
Use: "create-invoice-coupons",
Short: "Creates stripe invoice line items for not consumed coupons",
@ -501,26 +496,6 @@ func createInvoiceItems(cmd *cobra.Command, args []string) error {
return nil
}
func prepareInvoiceCoupons(cmd *cobra.Command, args []string) error {
ctx, _ := process.Ctx(cmd)
i, err := NewInspector(*Addr, *IdentityPath)
if err != nil {
return ErrInspectorDial.Wrap(err)
}
defer func() { err = errs.Combine(err, i.Close()) }()
_, err = i.paymentsClient.PrepareInvoiceCoupons(ctx,
&pb.PrepareInvoiceCouponsRequest{},
)
if err != nil {
return err
}
fmt.Println("successfully created invoice coupons")
return nil
}
func createInvoiceCoupons(cmd *cobra.Command, args []string) error {
ctx, _ := process.Ctx(cmd)
i, err := NewInspector(*Addr, *IdentityPath)
@ -592,7 +567,6 @@ func init() {
paymentsCmd.AddCommand(prepareInvoiceRecordsCmd)
paymentsCmd.AddCommand(createInvoiceItemsCmd)
paymentsCmd.AddCommand(prepareInvoiceCouponsCmd)
paymentsCmd.AddCommand(createInvoiceCouponsCmd)
paymentsCmd.AddCommand(createInvoicesCmd)

2
go.mod
View File

@ -111,7 +111,7 @@ require (
gopkg.in/olivere/elastic.v5 v5.0.76 // indirect
gopkg.in/spacemonkeygo/monkit.v2 v2.0.0-20190612171030-cf5a9e6f8fd2
gopkg.in/yaml.v2 v2.2.2
storj.io/common v0.0.0-20200110234232-05a83300869e
storj.io/common v0.0.0-20200114152414-8dcdd4c9d250
storj.io/drpc v0.0.7-0.20191115031725-2171c57838d2
storj.io/uplink v0.0.0-20200109100422-69086b6ee4a8
)

9
go.sum
View File

@ -588,15 +588,12 @@ gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
storj.io/common v0.0.0-20200108114547-1c62e5708bce h1:0okFmuEp38BNSKXQ72PXMTouSYMKMfC6H+GlNRfthbA=
storj.io/common v0.0.0-20200108114547-1c62e5708bce/go.mod h1:mDnchZF+e7g7u630Wwgu/X/zCmqpU0lvy5kQ3jQgs5k=
storj.io/common v0.0.0-20200109103211-f95ce3581da7 h1:vGQ7fEcRpCQG7HqH6/HDaJpnlsn46LvZEvqN/XreHJQ=
storj.io/common v0.0.0-20200109103211-f95ce3581da7/go.mod h1:mDnchZF+e7g7u630Wwgu/X/zCmqpU0lvy5kQ3jQgs5k=
storj.io/common v0.0.0-20200110234232-05a83300869e h1:yY/MrmWD445YKTZ1dEM27+D5aYQtM7b27uJYRzMwXEI=
storj.io/common v0.0.0-20200110234232-05a83300869e/go.mod h1:0yn1ANoDXETNBREGQHq8d7m1Kq0vWMu6Ul7C2YPZo/E=
storj.io/common v0.0.0-20200114152414-8dcdd4c9d250 h1:JDScdUShGqfHyiSWtfXhYEK1OkSVD40SHR7fO01k5Xk=
storj.io/common v0.0.0-20200114152414-8dcdd4c9d250/go.mod h1:0yn1ANoDXETNBREGQHq8d7m1Kq0vWMu6Ul7C2YPZo/E=
storj.io/drpc v0.0.7-0.20191115031725-2171c57838d2 h1:8SgLYEhe99R8QlAD1EAOBPRyIR+cn2hqkXtWlAUPf/c=
storj.io/drpc v0.0.7-0.20191115031725-2171c57838d2/go.mod h1:/ascUDbzNAv0A3Jj7wUIKFBH2JdJ2uJIBO/b9+2yHgQ=
storj.io/uplink v0.0.0-20200108132132-c2c5e0d46c1a h1:w/588H+U5IfTXCHA2GTFVLzpUbworS0DtoB4sR9h/8M=
storj.io/uplink v0.0.0-20200108132132-c2c5e0d46c1a/go.mod h1:3498FK1ewiOxrVTbPwGJmE/kwIWA3q9ULtAU/WAreys=
storj.io/uplink v0.0.0-20200109100422-69086b6ee4a8 h1:WG1rX2uc815ZkUz1xrebuZA+JWFBF9Y2n64gvVKZFko=
storj.io/uplink v0.0.0-20200109100422-69086b6ee4a8/go.mod h1:3498FK1ewiOxrVTbPwGJmE/kwIWA3q9ULtAU/WAreys=
storj.io/uplink v0.0.0-20200109100422-69086b6ee4a8/go.mod h1:3498FK1ewiOxrVTbPwGJmE/kwIWA3q9ULtAU/WAreys=

View File

@ -17,7 +17,6 @@ import (
"gopkg.in/spacemonkeygo/monkit.v2"
"storj.io/common/macaroon"
"storj.io/common/memory"
"storj.io/storj/pkg/auth"
"storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/console/consoleauth"
@ -153,17 +152,7 @@ func (payments PaymentsService) AddCreditCard(ctx context.Context, creditCardTok
return Error.Wrap(err)
}
err = payments.service.accounts.CreditCards().Add(ctx, auth.User.ID, creditCardToken)
if err != nil {
return Error.Wrap(err)
}
err = payments.AddPromotionCoupon(ctx, auth.User.ID)
if err != nil {
payments.service.log.Error(fmt.Sprintf("can not add promotional coupon to user %s", auth.User.Email), zap.Error(err))
}
return nil
return Error.Wrap(payments.service.accounts.CreditCards().Add(ctx, auth.User.ID, creditCardToken))
}
// MakeCreditCardDefault makes a credit card default payment method.
@ -320,40 +309,6 @@ func (payments PaymentsService) TokenDeposit(ctx context.Context, amount int64)
return tx, errs.Wrap(err)
}
// AddPromotionCoupon creates new coupon for specified user.
func (payments PaymentsService) AddPromotionCoupon(ctx context.Context, userID uuid.UUID) (err error) {
defer mon.Task()(&ctx)(&err)
projects, err := payments.service.store.Projects().GetByUserID(ctx, userID)
if err != nil {
return Error.Wrap(err)
}
creditCards, err := payments.service.accounts.CreditCards().List(ctx, userID)
if err != nil {
return Error.Wrap(err)
}
if len(creditCards) == 0 {
return Error.Wrap(errs.New("user don't have credit cards"))
}
coupons, err := payments.service.accounts.Coupons(ctx, userID)
if err != nil {
return Error.Wrap(err)
}
if len(coupons) > 0 {
return Error.Wrap(errs.New("user already have a coupon"))
}
err = payments.service.accounts.AddCoupon(ctx, userID, projects[0].ID, 50, 2, "promotional coupon", 0)
if err != nil {
return Error.Wrap(err)
}
// TODO: delete coupon if limits can't be updated?
return Error.Wrap(payments.service.projectUsage.UpdateProjectLimits(ctx, projects[0].ID, memory.TB))
}
// CreateUser gets password hash value and creates new inactive User
func (s *Service) CreateUser(ctx context.Context, user CreateUser, tokenSecret RegistrationSecret, refUserID string) (u *User, err error) {
defer mon.Task()(&ctx)(&err)
@ -865,11 +820,6 @@ func (s *Service) CreateProject(ctx context.Context, projectInfo ProjectInfo) (p
return nil, err
}
err = s.Payments().AddPromotionCoupon(ctx, auth.User.ID)
if err != nil {
s.log.Error(fmt.Sprintf("can not add promotional coupon to user %s", auth.User.Email), zap.Error(err))
}
return p, nil
}

View File

@ -5,6 +5,7 @@ package payments
import (
"context"
"github.com/skyrings/skyring-common/tools/uuid"
"github.com/zeebo/errs"
)
@ -21,9 +22,6 @@ type Accounts interface {
// Balance returns an integer amount in cents that represents the current balance of payment account.
Balance(ctx context.Context, userID uuid.UUID) (int64, error)
// AddCoupon creates new coupon for specified user and project.
AddCoupon(ctx context.Context, userID, projectID uuid.UUID, amount int64, duration int, description string, couponType CouponType) (err error)
// ProjectCharges returns how much money current user will be charged for each project.
ProjectCharges(ctx context.Context, userID uuid.UUID) ([]ProjectCharge, error)

View File

@ -75,13 +75,6 @@ func (accounts *accounts) Balance(ctx context.Context, userID uuid.UUID) (_ int6
return 0, nil
}
// AddCoupon creates new coupon for specified user and project.
func (accounts *accounts) AddCoupon(ctx context.Context, userID, projectID uuid.UUID, amount int64, duration int, description string, couponType payments.CouponType) (err error) {
defer mon.Task()(&ctx, userID, projectID, amount, duration, couponType)(&err)
return nil
}
// ProjectCharges returns how much money current user will be charged for each project.
func (accounts *accounts) ProjectCharges(ctx context.Context, userID uuid.UUID) (charges []payments.ProjectCharge, err error) {
defer mon.Task()(&ctx, userID)(&err)

View File

@ -44,13 +44,6 @@ func (endpoint *Endpoint) ApplyInvoiceRecords(ctx context.Context, req *pb.Apply
return &pb.ApplyInvoiceRecordsResponse{}, nil
}
// PrepareInvoiceCoupons creates coupon usage for all satellite projects.
func (endpoint *Endpoint) PrepareInvoiceCoupons(ctx context.Context, req *pb.PrepareInvoiceCouponsRequest) (_ *pb.PrepareInvoiceCouponsResponse, err error) {
defer mon.Task()(&ctx)(&err)
return &pb.PrepareInvoiceCouponsResponse{}, rpcstatus.Error(rpcstatus.Unimplemented, "not implemented")
}
// ApplyInvoiceCoupons creates stripe line items for all unapplied coupons.
func (endpoint *Endpoint) ApplyInvoiceCoupons(ctx context.Context, req *pb.ApplyInvoiceCouponsRequest) (_ *pb.ApplyInvoiceCouponsResponse, err error) {
defer mon.Task()(&ctx)(&err)