Skip to content
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
11 changes: 4 additions & 7 deletions app/common/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"go.opentelemetry.io/otel/trace"

"github.com/openmeterio/openmeter/app/config"
"github.com/openmeterio/openmeter/openmeter/billing"
"github.com/openmeterio/openmeter/openmeter/customer"
customeradapter "github.com/openmeterio/openmeter/openmeter/customer/adapter"
customerservice "github.com/openmeterio/openmeter/openmeter/customer/service"
Expand Down Expand Up @@ -65,19 +64,17 @@ func NewCustomerSubjectServiceHook(
tracer trace.Tracer,
subjectService subject.Service,
customerService customer.Service,
customerOverrideService billing.CustomerOverrideService,
) (CustomerSubjectHook, error) {
if !config.EnableSubjectHook {
return new(customerservicehooks.NoopSubjectCustomerHook), nil
}

// Initialize the subject customer hook and register it for Subject service
h, err := customerservicehooks.NewSubjectCustomerHook(customerservicehooks.SubjectCustomerHookConfig{
Customer: customerService,
CustomerOverride: customerOverrideService,
Logger: logger,
Tracer: tracer,
IgnoreErrors: config.IgnoreErrors,
Customer: customerService,
Logger: logger,
Tracer: tracer,
IgnoreErrors: config.IgnoreErrors,
})
if err != nil {
return nil, fmt.Errorf("failed to create customer subject hook: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/brianvoe/gofakeit/v6 v6.28.0
github.com/cloudevents/sdk-go/v2 v2.16.1
github.com/confluentinc/confluent-kafka-go/v2 v2.11.1
github.com/forscht/namegen v1.0.1
github.com/getkin/kin-openapi v0.133.0
github.com/go-chi/chi/v5 v5.2.3
github.com/go-chi/cors v1.2.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@ github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/forscht/namegen v1.0.1 h1:HipCEuyIKECsb1Yt68xaX7XTCDDrd+aDdEROoayY52I=
github.com/forscht/namegen v1.0.1/go.mod h1:Vnu8EC4fPGwaP7ogYi7kTPvRQHAUZUe1i1wN1RlgzII=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
Expand Down
9 changes: 8 additions & 1 deletion openmeter/app/stripe/adapter/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,19 @@ func (a *adapter) UpsertStripeCustomerData(ctx context.Context, input appstripee
SetStripeCustomerID(input.StripeCustomerID).
SetNillableStripeDefaultPaymentMethodID(input.StripeDefaultPaymentMethodID).
// Upsert
OnConflictColumns(appstripecustomerdb.FieldNamespace, appstripecustomerdb.FieldAppID, appstripecustomerdb.FieldCustomerID, appstripecustomerdb.FieldStripeCustomerID).
OnConflictColumns(appstripecustomerdb.FieldNamespace, appstripecustomerdb.FieldAppID, appstripecustomerdb.FieldCustomerID).
UpdateStripeCustomerID().
UpdateStripeDefaultPaymentMethodID().
Exec(ctx)
if err != nil {
if entdb.IsConstraintError(err) {
a.logger.WarnContext(ctx, "failed to upsert app stripe customer data",
"error", err,
"app_id", input.AppID.ID,
"customer_id", input.CustomerID.ID,
"stripe_customer_id", input.StripeCustomerID,
)

return nil, app.NewAppCustomerPreConditionError(
input.AppID,
app.AppTypeStripe,
Expand Down
5 changes: 0 additions & 5 deletions openmeter/billing/adapter/invoicelinediff.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,6 @@ func diffInvoiceLines(lines []*billing.Line) (*invoiceLineDiff, error) {

// Let's figure out what we need to do about child lines
for _, childUpdate := range childUpdates {
// If the children are not present, we don't need to do anything (a.k.a. do not touch)
if len(childUpdate.Children) == 0 {
continue
}

if err := getChildrenActions(
childUpdate.DBState.Children,
childUpdate.Children,
Expand Down
3 changes: 1 addition & 2 deletions openmeter/billing/worker/subscription/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4500,13 +4500,12 @@ func (s *SubscriptionHandlerTestSuite) TestSyncronizeSubscriptionPeriodAlgorithm
},
{
Start: s.mustParseTime("2025-03-02T00:00:00Z"),
End: s.mustParseTime("2025-03-28T00:00:00Z"), // TODO: once we implement sticky recurrence (sticking to end of month) this should be 03-31
End: s.mustParseTime("2025-03-31T00:00:00Z"),
},
},

InvoiceAt: mo.Some([]time.Time{
s.mustParseTime("2025-01-31T00:00:00Z"),
// TODO: Once the period fix is there, this should be 03-31
s.mustParseTime("2025-03-02T00:00:00Z"),
}),
},
Expand Down
2 changes: 1 addition & 1 deletion openmeter/credit/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (m *connector) GetLastValidSnapshotAt(ctx context.Context, owner models.Nam

bal, err := m.BalanceSnapshotService.GetLatestValidAt(ctx, owner, at)
if err != nil {
if _, ok := err.(*balance.NoSavedBalanceForOwnerError); ok {
if _, ok := lo.ErrorsAs[*balance.NoSavedBalanceForOwnerError](err); ok {
// if no snapshot is found we have to calculate from start of time on all grants and usage
m.Logger.Debug(fmt.Sprintf("no saved balance found for owner %s before %s, calculating from start of time", owner.ID, at))

Expand Down
1 change: 1 addition & 0 deletions openmeter/entitlement/adapter/entitlement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ func TestEntitlementLoadsSubjectAndCustomerAndPreservesAcrossTypedMapping(t *tes
Interval: timeutil.RecurrencePeriodMonth,
Anchor: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),
})),
IsSoftLimit: lo.ToPtr(true),
})
require.NoError(t, err)

Expand Down
Loading
Loading