diff --git a/handlers/orders.go b/handlers/orders.go index 4e0e3c4..fe07e83 100644 --- a/handlers/orders.go +++ b/handlers/orders.go @@ -159,17 +159,9 @@ 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: ip, + IPAddress: getOrderIp(body.Ip), ItemId: lineItem.Id, Quantity: lineItem.Quantity, Description: orderItem.Name, @@ -264,3 +256,11 @@ func getDonatorPrice(months int, isSteam bool) (float32, error) { return 0, errors.New("invalid donator months provided") } + +func getOrderIp(bodyIp string) string { + if bodyIp != "" { + return bodyIp + } + + return "1.1.1.1" +} diff --git a/handlers/orders_steam.go b/handlers/orders_steam.go index f8ad280..ee14c85 100644 --- a/handlers/orders_steam.go +++ b/handlers/orders_steam.go @@ -42,18 +42,10 @@ 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: ip, + IPAddress: getOrderIp(body.Ip), ItemId: db.OrderItemDonator, Quantity: body.Months, Amount: price, diff --git a/handlers/orders_stripe.go b/handlers/orders_stripe.go index f212d50..b044c1f 100644 --- a/handlers/orders_stripe.go +++ b/handlers/orders_stripe.go @@ -77,7 +77,7 @@ func InitiateStripeDonatorCheckoutSession(c *gin.Context) *APIError { UserId: user.Id, OrderId: -1, TransactionId: s.ID, - IPAddress: getIpFromRequest(c), + IPAddress: getOrderIp(body.Ip), ItemId: db.OrderItemDonator, Quantity: body.Months, Amount: price,