Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ip field for steam transactions #57

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
Loading