Skip to content

Commit

Permalink
Add ip field for steam transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Swan committed Aug 13, 2024
1 parent a477075 commit fdcc619
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
20 changes: 15 additions & 5 deletions handlers/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ var (

// Common request body when initiating a donator transaction
type donationRequestBody struct {
Months int `form:"months" json:"months" binding:"required"`
GiftUserId int `form:"gift_user_id" json:"gift_user_id"`
Recurring bool `form:"recurring" json:"recurring"`
Months int `form:"months" json:"months" binding:"required"`
GiftUserId int `form:"gift_user_id" json:"gift_user_id"`
Recurring bool `form:"recurring" json:"recurring"`
Ip string `form:"ip" json:"ip"`
}

// GetDonatorPrices Returns the current donator prices
Expand Down Expand Up @@ -117,6 +118,7 @@ func CreateOrderCheckoutSession(c *gin.Context) *APIError {
Quantity int `json:"quantity"`
GiftUserId int `json:"gift_user_id"`
} `json:"line_items"`
Ip string `json:"ip"`
}{}

if err := c.ShouldBindJSON(&body); err != nil {
Expand Down Expand Up @@ -157,9 +159,17 @@ func CreateOrderCheckoutSession(c *gin.Context) *APIError {
return APIErrorBadRequest(fmt.Sprintf("You cannot gift item %v", lineItem.Id))
}

var ip string

if body.Ip != "" {
ip = body.Ip
} else {
ip = "1.1.1.1"
}

order := &db.Order{
UserId: user.Id,
IPAddress: getSteamTransactionIp(c),
IPAddress: ip,
ItemId: lineItem.Id,
Quantity: lineItem.Quantity,
Description: orderItem.Name,
Expand Down Expand Up @@ -253,4 +263,4 @@ func getDonatorPrice(months int, isSteam bool) (float32, error) {
}

return 0, errors.New("invalid donator months provided")
}
}
19 changes: 9 additions & 10 deletions handlers/orders_steam.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ func InitiateSteamDonatorTransaction(c *gin.Context) *APIError {
return APIErrorBadRequest("You have provided an invalid amount of months.")
}

var ip string

if body.Ip != "" {
ip = body.Ip
} else {
ip = "1.1.1.1"
}

order := &db.Order{
UserId: user.Id,
OrderId: generateSteamOrderId(),
IPAddress: getSteamTransactionIp(c),
IPAddress: ip,
ItemId: db.OrderItemDonator,
Quantity: body.Months,
Amount: price,
Expand Down Expand Up @@ -359,12 +367,3 @@ func generateSteamOrderId() int {

return rand.Intn(maximum-minimum+1) + minimum
}

// Returns the transaction ip address for steam
func getSteamTransactionIp(c *gin.Context) string {
if config.Instance.IsProduction {
return getIpFromRequest(c)
}

return "1.1.1.1"
}

0 comments on commit fdcc619

Please sign in to comment.