satellite/console: allow coupons to be a valid payment option

Currently a user is only able to create a project if either
a STORJ deposit or CC was added to his account. With this change, an existing
coupon is also valid to let the user proceed.

Change-Id: I7be8d2d9ec58a15c50755b3fe33af04d2fd64ea2
This commit is contained in:
Stefan Benten 2020-09-28 23:15:49 +02:00
parent 8786e55a78
commit 79eb682f9c

View File

@ -950,19 +950,25 @@ func (s *Service) CreateProject(ctx context.Context, projectInfo ProjectInfo) (p
if s.accounts.PaywallEnabled(auth.User.ID) {
cards, err := s.accounts.CreditCards().List(ctx, auth.User.ID)
if err != nil {
s.log.Debug(fmt.Sprintf("could not add promotional coupon for user %s", auth.User.ID.String()), zap.Error(Error.Wrap(err)))
s.log.Debug(fmt.Sprintf("could not list credit cards for user %s", auth.User.ID.String()), zap.Error(Error.Wrap(err)))
return nil, Error.Wrap(err)
}
balance, err := s.accounts.Balance(ctx, auth.User.ID)
if err != nil {
s.log.Debug(fmt.Sprintf("could not add promotional coupon for user %s", auth.User.ID.String()), zap.Error(Error.Wrap(err)))
s.log.Debug(fmt.Sprintf("could not get balance for user %s", auth.User.ID.String()), zap.Error(Error.Wrap(err)))
return nil, Error.Wrap(err)
}
if len(cards) == 0 && balance.Coins < s.minCoinPayment {
coupons, err := s.accounts.Coupons().ListByUserID(ctx, auth.User.ID)
if err != nil {
s.log.Debug(fmt.Sprintf("could not list coupons for user %s", auth.User.ID.String()), zap.Error(Error.Wrap(err)))
return nil, Error.Wrap(err)
}
if len(cards) == 0 && balance.Coins < s.minCoinPayment && len(coupons) == 0 {
err = errs.New("no valid payment methods found")
s.log.Debug(fmt.Sprintf("could not add promotional coupon for user %s", auth.User.ID.String()), zap.Error(Error.Wrap(err)))
s.log.Debug(fmt.Sprintf("could not create project for user %s", auth.User.ID.String()), zap.Error(Error.Wrap(err)))
return nil, Error.Wrap(err)
}
}