Skip to content

Commit

Permalink
Refactor order ip & use for stripe
Browse files Browse the repository at this point in the history
  • Loading branch information
Swan committed Aug 13, 2024
1 parent fdcc619 commit 60315b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
18 changes: 9 additions & 9 deletions handlers/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
}
10 changes: 1 addition & 9 deletions handlers/orders_steam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion handlers/orders_stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 60315b7

Please sign in to comment.