openmeter / billing /charges /testutils /linerouter.go
Leon4gr45's picture
Upload folder using huggingface_hub (part 2)
5a22efd verified
Raw
History Blame Contribute Delete
823 Bytes
package testutils
import (
"fmt"
"testing"
"github.com/openmeterio/openmeter/openmeter/billing"
"github.com/openmeterio/openmeter/openmeter/productcatalog"
)
func NewChargesEnabledLineRouter(t testing.TB) billing.CreateLineRouter {
t.Helper()
return chargesEnabledLineRouter{}
}
type chargesEnabledLineRouter struct{}
func (chargesEnabledLineRouter) GetLineEngineForCreateLine(line billing.GenericInvoiceLineReader) (billing.LineEngineType, error) {
if line == nil {
return "", fmt.Errorf("line is required")
}
price := line.GetPrice()
if price == nil {
return "", fmt.Errorf("line[%s]: price is required", line.GetID())
}
switch price.Type() {
case productcatalog.FlatPriceType:
return billing.LineEngineTypeChargeFlatFee, nil
default:
return billing.LineEngineTypeChargeUsageBased, nil
}
}