Skip to content

Commit

Permalink
Fixed small bugs and corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
HirbodBehnam committed Dec 28, 2023
1 parent 9943153 commit be8d850
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions payment/api/idpay.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ func (api *API) CreateTransaction(c *gin.Context) {
return
}
logger := log.WithField("body", body)
// If buying goods is zero, something's up...
if len(body.BuyingGoods) == 0 {
logger.Warn("empty buying_goods")
c.JSON(http.StatusBadRequest, "empty buying_goods")
return
}
// Try to get the list of goods from database. This will fail if user has bought something
// from its BuyingGoods before
goods, err := api.Database.GetGoodsFromName(body.BuyingGoods)
Expand Down
4 changes: 2 additions & 2 deletions payment/pkg/util/rng.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package util

import (
"crypto/rand"
"encoding/base64"
"encoding/base32"
)

// RandomID generates a random ID based on 8 bytes in base 64
func RandomID() string {
buffer := make([]byte, 8)
_, _ = rand.Read(buffer)
return base64.StdEncoding.EncodeToString(buffer)
return base32.StdEncoding.EncodeToString(buffer)
}

0 comments on commit be8d850

Please sign in to comment.