diff --git a/cmd/cart/checkout_builder.go b/cmd/cart/checkout_builder.go index 405c353..0e9e59c 100644 --- a/cmd/cart/checkout_builder.go +++ b/cmd/cart/checkout_builder.go @@ -17,6 +17,7 @@ type CheckoutMeta struct { // Terms string // Checkout string // Confirmation string + ClientIp string Country string Currency string // optional override (defaults to "SEK" if empty) Locale string // optional override (defaults to "sv-se" if empty) diff --git a/cmd/cart/pool-server.go b/cmd/cart/pool-server.go index dd44355..f32940f 100644 --- a/cmd/cart/pool-server.go +++ b/cmd/cart/pool-server.go @@ -366,10 +366,19 @@ func getOriginalHost(r *http.Request) string { return r.Host } +func getClientIp(r *http.Request) string { + ip := r.Header.Get("X-Forwarded-For") + if ip == "" { + ip = r.RemoteAddr + } + return ip +} + func (s *PoolServer) CreateOrUpdateCheckout(r *http.Request, id cart.CartId) (*CheckoutOrder, error) { host := getOriginalHost(r) country := getCountryFromHost(host) meta := &CheckoutMeta{ + ClientIp: getClientIp(r), SiteUrl: fmt.Sprintf("https://%s", host), Country: country, Currency: getCurrency(country), @@ -729,6 +738,7 @@ func (s *PoolServer) AdyenSessionHandler(w http.ResponseWriter, r *http.Request, host := getOriginalHost(r) country := getCountryFromHost(host) meta := &CheckoutMeta{ + ClientIp: getClientIp(r), SiteUrl: fmt.Sprintf("https://%s", host), Country: country, Currency: getCurrency(country),