package paymentapiimp

import (
	"net"
	"strings"

	"github.com/tech/sendico/server/interface/api/srequest"
)

func applyCustomerIP(intent *srequest.PaymentIntent, remoteAddr string) {
	if intent == nil {
		return
	}
	ip := strings.TrimSpace(remoteAddr)
	if ip == "" {
		return
	}
	if host, _, err := net.SplitHostPort(ip); err == nil && host != "" {
		ip = host
	}
	if intent.Customer == nil {
		intent.Customer = &srequest.Customer{}
	}
	intent.Customer.IP = strings.TrimSpace(ip)
}
