satellite/payments: remove Deposit from Tokens interface

Change-Id: Ie04c35410baf8bf2c74cca0b7df1236a80f00e1b
This commit is contained in:
Yaroslav Vorobiov 2022-10-06 15:37:33 +02:00
parent fa287b8206
commit e014e88cc7
6 changed files with 0 additions and 170 deletions

View File

@ -262,68 +262,6 @@ func (p *Payments) BillingHistory(w http.ResponseWriter, r *http.Request) {
}
}
// TokenDeposit creates new deposit transaction and info about address and amount of newly created tx.
func (p *Payments) TokenDeposit(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
defer mon.Task()(&ctx)(&err)
w.Header().Set("Content-Type", "application/json")
var requestData struct {
Amount int64 `json:"amount"`
}
if err = json.NewDecoder(r.Body).Decode(&requestData); err != nil {
p.serveJSONError(w, http.StatusBadRequest, err)
return
}
if requestData.Amount < 0 {
p.serveJSONError(w, http.StatusBadRequest, errs.New("amount can not be negative"))
return
}
if requestData.Amount == 0 {
p.serveJSONError(w, http.StatusBadRequest, errs.New("amount should be greater than zero"))
return
}
tx, err := p.service.Payments().TokenDeposit(ctx, requestData.Amount)
if err != nil {
if console.ErrUnauthorized.Has(err) {
p.serveJSONError(w, http.StatusUnauthorized, err)
return
}
p.serveJSONError(w, http.StatusInternalServerError, err)
return
}
var responseData struct {
Address string `json:"address"`
Amount float64 `json:"amount"`
TokenAmount string `json:"tokenAmount"`
Rate string `json:"rate"`
Status string `json:"status"`
Link string `json:"link"`
ExpiresAt time.Time `json:"expires"`
}
responseData.Address = tx.Address
responseData.Amount = float64(requestData.Amount) / 100
responseData.TokenAmount = tx.Amount.AsDecimal().String()
responseData.Rate = tx.Rate.StringFixed(8)
responseData.Status = tx.Status.String()
responseData.Link = tx.Link
responseData.ExpiresAt = tx.CreatedAt.Add(tx.Timeout)
err = json.NewEncoder(w).Encode(responseData)
if err != nil {
p.log.Error("failed to write json token deposit response", zap.Error(ErrPaymentsAPI.Wrap(err)))
}
}
// ApplyCouponCode applies a coupon code to the user's account.
func (p *Payments) ApplyCouponCode(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

View File

@ -306,7 +306,6 @@ func NewServer(logger *zap.Logger, config Config, service *console.Service, oidc
paymentsRouter.HandleFunc("/wallet", paymentController.ClaimWallet).Methods(http.MethodPost)
paymentsRouter.HandleFunc("/wallet/payments", paymentController.WalletPayments).Methods(http.MethodGet)
paymentsRouter.HandleFunc("/billing-history", paymentController.BillingHistory).Methods(http.MethodGet)
paymentsRouter.HandleFunc("/tokens/deposit", paymentController.TokenDeposit).Methods(http.MethodPost)
paymentsRouter.Handle("/coupon/apply", server.userIDRateLimiter.Limit(http.HandlerFunc(paymentController.ApplyCouponCode))).Methods(http.MethodPatch)
paymentsRouter.HandleFunc("/coupon", paymentController.GetCoupon).Methods(http.MethodGet)

View File

@ -532,25 +532,6 @@ func (payment Payments) BillingHistory(ctx context.Context) (billingHistory []*B
return billingHistory, nil
}
// TokenDeposit creates new deposit transaction for adding STORJ tokens to account balance.
func (payment Payments) TokenDeposit(ctx context.Context, amount int64) (_ *payments.Transaction, err error) {
defer mon.Task()(&ctx)(&err)
user, err := payment.service.getUserAndAuditLog(ctx, "token deposit")
if err != nil {
return nil, Error.Wrap(err)
}
tx, err := payment.service.accounts.StorjTokens().Deposit(ctx, user.ID, amount)
if err != nil {
return nil, Error.Wrap(err)
}
payment.service.analytics.TrackStorjTokenAdded(user.ID, user.Email)
return tx, nil
}
// checkOutstandingInvoice returns if the payment account has any unpaid/outstanding invoices or/and invoice items.
func (payment Payments) checkOutstandingInvoice(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)

View File

@ -23,13 +23,6 @@ func convertToCents(rate decimal.Decimal, amount currency.Amount) int64 {
return usdCents.Round(0).IntPart()
}
// convertFromCents convert amount in cents to a StorjTokenAmount with given rate.
func convertFromCents(rate decimal.Decimal, usdCents int64) currency.Amount {
usd := decimal.NewFromInt(usdCents).Shift(-2)
numStorj := usd.Div(rate)
return currency.AmountFromDecimal(numStorj, currency.USDollars)
}
// ErrConversion defines version service error.
var ErrConversion = errs.Class("conversion service")

View File

@ -13,7 +13,6 @@ import (
"github.com/stripe/stripe-go/v72"
"go.uber.org/zap"
"storj.io/common/currency"
"storj.io/common/uuid"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/coinpayments"
@ -27,11 +26,6 @@ const (
// StripeDepositBonusTransactionDescription is the description for Stripe
// balance transactions representing bonuses received for STORJ deposits.
StripeDepositBonusTransactionDescription = "STORJ deposit bonus"
// StripeMigratedDepositBonusTransactionDescription is the description for
// Stripe balance transactions representing bonuses migrated from the
// 'credits' table of the satellite DB.
StripeMigratedDepositBonusTransactionDescription = "Migrated STORJ deposit bonus"
)
// ensure that storjTokens implements payments.StorjTokens.
@ -44,79 +38,6 @@ type storjTokens struct {
service *Service
}
// Deposit creates new deposit transaction with the given amount returning
// ETH wallet address where funds should be sent. There is one
// hour limit to complete the transaction. Transaction is saved to DB with
// reference to the user who made the deposit.
func (tokens *storjTokens) Deposit(ctx context.Context, userID uuid.UUID, amount int64) (_ *payments.Transaction, err error) {
defer mon.Task()(&ctx, userID, amount)(&err)
customerID, err := tokens.service.db.Customers().GetCustomerID(ctx, userID)
if err != nil {
return nil, Error.Wrap(err)
}
c, err := tokens.service.stripeClient.Customers().Get(customerID, nil)
if err != nil {
return nil, Error.Wrap(err)
}
rate, err := tokens.service.GetRate(ctx, currency.StorjToken, currency.USDollars)
if err != nil {
return nil, Error.Wrap(err)
}
tokenAmount := convertFromCents(rate, amount)
tx, err := tokens.service.coinPayments.Transactions().Create(ctx,
&coinpayments.CreateTX{
Amount: tokenAmount.AsDecimal(),
CurrencyIn: currency.StorjToken,
CurrencyOut: currency.StorjToken,
BuyerEmail: c.Email,
},
)
if err != nil {
return nil, Error.Wrap(err)
}
key, err := coinpayments.GetTransactionKeyFromURL(tx.CheckoutURL)
if err != nil {
return nil, Error.Wrap(err)
}
if err = tokens.service.db.Transactions().LockRate(ctx, tx.ID, rate); err != nil {
return nil, Error.Wrap(err)
}
createTime, err := tokens.service.db.Transactions().Insert(ctx,
Transaction{
ID: tx.ID,
AccountID: userID,
Address: tx.Address,
Amount: tx.Amount,
Received: currency.AmountFromBaseUnits(0, tx.Amount.Currency()),
Status: coinpayments.StatusPending,
Key: key,
Timeout: tx.Timeout,
},
)
if err != nil {
return nil, Error.Wrap(err)
}
return &payments.Transaction{
ID: payments.TransactionID(tx.ID),
Amount: tx.Amount,
Rate: rate,
Address: tx.Address,
Status: payments.TransactionStatusPending,
Timeout: tx.Timeout,
Link: tx.CheckoutURL,
CreatedAt: createTime,
}, nil
}
// ListTransactionInfos fetches all transactions from the database for specified user, reconstructing checkout link.
func (tokens *storjTokens) ListTransactionInfos(ctx context.Context, userID uuid.UUID) (_ []payments.TransactionInfo, err error) {
defer mon.Task()(&ctx, userID)(&err)

View File

@ -18,8 +18,6 @@ import (
//
// architecture: Service
type StorjTokens interface {
// Deposit creates deposit transaction for specified amount in cents.
Deposit(ctx context.Context, userID uuid.UUID, amount int64) (*Transaction, error)
// ListTransactionInfos returns all transactions associated with user.
ListTransactionInfos(ctx context.Context, userID uuid.UUID) ([]TransactionInfo, error)
// ListDepositBonuses returns all deposit bonuses associated with user.