From fdcc6191540a743f48dffc905ae63078bc2fe01f Mon Sep 17 00:00:00 2001 From: Swan Date: Tue, 13 Aug 2024 10:02:08 -0400 Subject: [PATCH] Add ip field for steam transactions --- handlers/orders.go | 20 +++++++++++++++----- handlers/orders_steam.go | 19 +++++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/handlers/orders.go b/handlers/orders.go index f096cef..4e0e3c4 100644 --- a/handlers/orders.go +++ b/handlers/orders.go @@ -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 @@ -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 { @@ -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, @@ -253,4 +263,4 @@ func getDonatorPrice(months int, isSteam bool) (float32, error) { } return 0, errors.New("invalid donator months provided") -} \ No newline at end of file +} diff --git a/handlers/orders_steam.go b/handlers/orders_steam.go index 0d5c075..f8ad280 100644 --- a/handlers/orders_steam.go +++ b/handlers/orders_steam.go @@ -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, @@ -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" -}