Skip to content
Open
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
6 changes: 3 additions & 3 deletions openmeter/app/custominvoicing/httpdriver/custominvoicing.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (h *handler) DraftSyncronized() DraftSyncronizedHandler {
return DraftSyncronizedResponse{}, err
}

return billinghttpdriver.MapInvoiceToAPI(invoice)
return billinghttpdriver.MapStandardInvoiceToAPI(invoice)
},
commonhttp.JSONResponseEncoderWithStatus[DraftSyncronizedResponse](http.StatusOK),
httptransport.AppendOptions(
Expand Down Expand Up @@ -104,7 +104,7 @@ func (h *handler) IssuingSyncronized() IssuingSyncronizedHandler {
return IssuingSyncronizedResponse{}, err
}

return billinghttpdriver.MapInvoiceToAPI(invoice)
return billinghttpdriver.MapStandardInvoiceToAPI(invoice)
},
commonhttp.JSONResponseEncoderWithStatus[IssuingSyncronizedResponse](http.StatusOK),
httptransport.AppendOptions(
Expand Down Expand Up @@ -160,7 +160,7 @@ func (h *handler) UpdatePaymentStatus() UpdatePaymentStatusHandler {
return UpdatePaymentStatusResponse{}, err
}

return billinghttpdriver.MapInvoiceToAPI(invoice)
return billinghttpdriver.MapStandardInvoiceToAPI(invoice)
},
commonhttp.JSONResponseEncoderWithStatus[UpdatePaymentStatusResponse](http.StatusOK),
httptransport.AppendOptions(
Expand Down
2 changes: 2 additions & 0 deletions openmeter/billing/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type InvoiceAdapter interface {
UpdateInvoice(ctx context.Context, input UpdateInvoiceAdapterInput) (StandardInvoice, error)

GetInvoiceOwnership(ctx context.Context, input GetInvoiceOwnershipAdapterInput) (GetOwnershipAdapterResponse, error)

GetInvoiceType(ctx context.Context, input GetInvoiceTypeAdapterInput) (InvoiceType, error)
}

type GatheringInvoiceAdapter interface {
Expand Down
28 changes: 28 additions & 0 deletions openmeter/billing/adapter/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,31 @@ func (a *adapter) IsAppUsed(ctx context.Context, appID app.AppID) error {

return nil
}

func (a *adapter) GetInvoiceType(ctx context.Context, input billing.GetInvoiceTypeAdapterInput) (billing.InvoiceType, error) {
if err := input.Validate(); err != nil {
return "", err
}

return entutils.TransactingRepo(ctx, a, func(ctx context.Context, tx *adapter) (billing.InvoiceType, error) {
invoice, err := tx.db.BillingInvoice.Query().
Where(billinginvoice.ID(input.ID)).
Where(billinginvoice.Namespace(input.Namespace)).
Only(ctx)
if err != nil {
if db.IsNotFound(err) {
return "", billing.NotFoundError{
Err: fmt.Errorf("invoice not found: %w", err),
}
}

return "", err
}

if invoice.Status == billing.StandardInvoiceStatusGathering {
return billing.InvoiceTypeGathering, nil
}

return billing.InvoiceTypeStandard, nil
})
}
72 changes: 47 additions & 25 deletions openmeter/billing/derived.gen.go

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

50 changes: 46 additions & 4 deletions openmeter/billing/gatheringinvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ func (g GatheringInvoice) Clone() (GatheringInvoice, error) {
return clone, nil
}

func (g GatheringInvoice) GetGenericLines() mo.Option[[]GenericInvoiceLine] {
if !g.Lines.IsPresent() {
return mo.None[[]GenericInvoiceLine]()
}

return mo.Some(lo.Map(g.Lines.OrEmpty(), func(l GatheringLine, _ int) GenericInvoiceLine {
return &gatheringInvoiceLineGenericWrapper{GatheringLine: l}
}))
}

func (g *GatheringInvoice) SetLines(lines []GenericInvoiceLine) error {
mappedLines, err := slicesx.MapWithErr(lines, func(l GenericInvoiceLine) (GatheringLine, error) {
return l.AsInvoiceLine().AsGatheringLine()
})
if err != nil {
return fmt.Errorf("mapping lines: %w", err)
}

g.Lines = NewGatheringInvoiceLines(mappedLines)
return nil
}

type GatheringInvoiceExpand string

func (e GatheringInvoiceExpand) Validate() error {
Expand Down Expand Up @@ -487,6 +509,10 @@ func (i GatheringLineBase) GetChildUniqueReferenceID() *string {
return i.ChildUniqueReferenceID
}

func (i *GatheringLineBase) SetChildUniqueReferenceID(id *string) {
i.ChildUniqueReferenceID = id
}

func (i GatheringLineBase) GetSplitLineGroupID() *string {
return i.SplitLineGroupID
}
Expand Down Expand Up @@ -522,6 +548,18 @@ func (g GatheringLineBase) GetRateCardDiscounts() Discounts {
return g.RateCardDiscounts
}

func (g GatheringLineBase) Equal(other GatheringLineBase) bool {
return deriveEqualGatheringLineBase(&g, &other)
}

func (g GatheringLineBase) GetSubscriptionReference() *SubscriptionReference {
if g.Subscription == nil {
return nil
}

return g.Subscription.Clone()
}

var (
_ GenericInvoiceLine = (*gatheringInvoiceLineGenericWrapper)(nil)
_ InvoiceAtAccessor = (*gatheringInvoiceLineGenericWrapper)(nil)
Expand Down Expand Up @@ -615,6 +653,14 @@ func (g GatheringLine) AsInvoiceLine() InvoiceLine {
}
}

func (g GatheringLine) Equal(other GatheringLine) bool {
return g.GatheringLineBase.Equal(other.GatheringLineBase)
}

func (g GatheringLine) RemoveMetaForCompare() (GatheringLine, error) {
return g.WithoutDBState()
}

type CreatePendingInvoiceLinesInput struct {
Customer customer.CustomerID `json:"customer"`
Currency currencyx.Code `json:"currency"`
Expand Down Expand Up @@ -724,10 +770,6 @@ func (i ListGatheringInvoicesInput) Validate() error {
}
}

if len(i.Namespaces) == 0 {
errs = append(errs, errors.New("namespaces is required"))
}

for _, expand := range i.Expand {
if err := expand.Validate(); err != nil {
errs = append(errs, fmt.Errorf("expand: %w", err))
Expand Down
Loading
Loading