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
18 changes: 9 additions & 9 deletions openmeter/app/custominvoicing/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ func (a App) GetEventAppData() (app.EventAppData, error) {
// InvoicingApp
// These are no-ops as whatever is meaningful, is handled via the http driver of the custominvoicing app.

// ValidateInvoice is a no-op as any validation issues are published via the draft.syncing and finalizations syncing
// ValidateStandardInvoice is a no-op as any validation issues are published via the draft.syncing and finalizations syncing
// flow.
func (a App) ValidateInvoice(ctx context.Context, invoice billing.Invoice) error {
func (a App) ValidateStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) error {
return nil
}

func (a App) UpsertInvoice(ctx context.Context, invoice billing.Invoice) (*billing.UpsertInvoiceResult, error) {
func (a App) UpsertStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.UpsertStandardInvoiceResult, error) {
return nil, nil
}

func (a App) FinalizeInvoice(ctx context.Context, invoice billing.Invoice) (*billing.FinalizeInvoiceResult, error) {
func (a App) FinalizeStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.FinalizeStandardInvoiceResult, error) {
canAdvance, err := a.CanIssuingSyncAdvance(invoice)
if err != nil {
return nil, err
}

res := billing.NewFinalizeInvoiceResult()
res := billing.NewFinalizeStandardInvoiceResult()

// If we are done with the hook work, let's make sure that the invoice has a non-draft invoice number
if canAdvance {
Expand All @@ -128,14 +128,14 @@ func (a App) FinalizeInvoice(ctx context.Context, invoice billing.Invoice) (*bil
return res, nil
}

// DeleteInvoice is a no-op as this should happen via the notifications webhook
func (a App) DeleteInvoice(ctx context.Context, invoice billing.Invoice) error {
// DeleteStandardInvoice is a no-op as this should happen via the notifications webhook
func (a App) DeleteStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) error {
return nil
}

// InvoicingAppAsyncSyncer

func (a App) CanDraftSyncAdvance(invoice billing.Invoice) (bool, error) {
func (a App) CanDraftSyncAdvance(invoice billing.StandardInvoice) (bool, error) {
if !a.Configuration.EnableDraftSyncHook {
return true, nil
}
Expand All @@ -151,7 +151,7 @@ func (a App) CanDraftSyncAdvance(invoice billing.Invoice) (bool, error) {
return false, nil
}

func (a App) CanIssuingSyncAdvance(invoice billing.Invoice) (bool, error) {
func (a App) CanIssuingSyncAdvance(invoice billing.StandardInvoice) (bool, error) {
if !a.Configuration.EnableIssuingSyncHook {
return true, nil
}
Expand Down
4 changes: 2 additions & 2 deletions openmeter/app/custominvoicing/httpdriver/custominvoicing.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (h *handler) DraftSyncronized() DraftSyncronizedHandler {
ID: params.InvoiceID,
Namespace: namespace,
},
UpsertInvoiceResults: mapUpsertInvoiceResultFromAPI(body.Invoicing),
UpsertInvoiceResults: mapUpsertStandardInvoiceResultFromAPI(body.Invoicing),
}, nil
},
func(ctx context.Context, request DraftSyncronizedRequest) (DraftSyncronizedResponse, error) {
Expand Down Expand Up @@ -91,7 +91,7 @@ func (h *handler) IssuingSyncronized() IssuingSyncronizedHandler {
ID: params.InvoiceID,
Namespace: namespace,
},
FinalizeInvoiceResult: mapFinalizeInvoiceResultFromAPI(body),
FinalizeInvoiceResult: mapFinalizeStandardInvoiceResultFromAPI(body),
}, nil
},
func(ctx context.Context, request IssuingSyncronizedRequest) (IssuingSyncronizedResponse, error) {
Expand Down
8 changes: 4 additions & 4 deletions openmeter/app/custominvoicing/httpdriver/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"github.com/openmeterio/openmeter/pkg/models"
)

func mapUpsertInvoiceResultFromAPI(in *api.CustomInvoicingSyncResult) *billing.UpsertInvoiceResult {
func mapUpsertStandardInvoiceResultFromAPI(in *api.CustomInvoicingSyncResult) *billing.UpsertStandardInvoiceResult {
if in == nil {
return nil
}

res := billing.NewUpsertInvoiceResult()
res := billing.NewUpsertStandardInvoiceResult()

if in.InvoiceNumber != nil {
res.SetInvoiceNumber(*in.InvoiceNumber)
Expand All @@ -38,8 +38,8 @@ func mapUpsertInvoiceResultFromAPI(in *api.CustomInvoicingSyncResult) *billing.U
return res
}

func mapFinalizeInvoiceResultFromAPI(in api.CustomInvoicingFinalizedRequest) *billing.FinalizeInvoiceResult {
res := billing.NewFinalizeInvoiceResult()
func mapFinalizeStandardInvoiceResultFromAPI(in api.CustomInvoicingFinalizedRequest) *billing.FinalizeStandardInvoiceResult {
res := billing.NewFinalizeStandardInvoiceResult()

if in.Invoicing != nil {
if in.Invoicing.InvoiceNumber != nil {
Expand Down
6 changes: 3 additions & 3 deletions openmeter/app/custominvoicing/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type FactoryService interface {
}

type SyncService interface {
SyncDraftInvoice(ctx context.Context, input SyncDraftInvoiceInput) (billing.Invoice, error)
SyncIssuingInvoice(ctx context.Context, input SyncIssuingInvoiceInput) (billing.Invoice, error)
SyncDraftInvoice(ctx context.Context, input SyncDraftInvoiceInput) (billing.StandardInvoice, error)
SyncIssuingInvoice(ctx context.Context, input SyncIssuingInvoiceInput) (billing.StandardInvoice, error)

HandlePaymentTrigger(ctx context.Context, input HandlePaymentTriggerInput) (billing.Invoice, error)
HandlePaymentTrigger(ctx context.Context, input HandlePaymentTriggerInput) (billing.StandardInvoice, error)
}
32 changes: 16 additions & 16 deletions openmeter/app/custominvoicing/service/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (

var _ appcustominvoicing.SyncService = (*Service)(nil)

func (s *Service) SyncDraftInvoice(ctx context.Context, input appcustominvoicing.SyncDraftInvoiceInput) (billing.Invoice, error) {
func (s *Service) SyncDraftInvoice(ctx context.Context, input appcustominvoicing.SyncDraftInvoiceInput) (billing.StandardInvoice, error) {
if err := input.Validate(); err != nil {
return billing.Invoice{}, err
return billing.StandardInvoice{}, err
}

return s.billingService.SyncDraftInvoice(ctx, billing.SyncDraftInvoiceInput{
return s.billingService.SyncDraftInvoice(ctx, billing.SyncDraftStandardInvoiceInput{
InvoiceID: input.InvoiceID,
UpsertInvoiceResults: input.UpsertInvoiceResults,
AdditionalMetadata: map[string]string{
Expand All @@ -32,12 +32,12 @@ func (s *Service) SyncDraftInvoice(ctx context.Context, input appcustominvoicing
})
}

func (s *Service) SyncIssuingInvoice(ctx context.Context, input appcustominvoicing.SyncIssuingInvoiceInput) (billing.Invoice, error) {
func (s *Service) SyncIssuingInvoice(ctx context.Context, input appcustominvoicing.SyncIssuingInvoiceInput) (billing.StandardInvoice, error) {
if err := input.Validate(); err != nil {
return billing.Invoice{}, err
return billing.StandardInvoice{}, err
}

return s.billingService.SyncIssuingInvoice(ctx, billing.SyncIssuingInvoiceInput{
return s.billingService.SyncIssuingInvoice(ctx, billing.SyncIssuingStandardInvoiceInput{
InvoiceID: input.InvoiceID,
FinalizeInvoiceResult: input.FinalizeInvoiceResult,
AdditionalMetadata: map[string]string{
Expand All @@ -47,9 +47,9 @@ func (s *Service) SyncIssuingInvoice(ctx context.Context, input appcustominvoici
})
}

func (s *Service) ValidateInvoiceApp(invoice billing.Invoice) error {
func (s *Service) ValidateInvoiceApp(invoice billing.StandardInvoice) error {
if invoice.Workflow.Apps == nil {
return models.NewGenericValidationError(fmt.Errorf("invoice %s has no apps", invoice.ID))
return models.NewGenericValidationError(fmt.Errorf("standard invoice %s has no apps", invoice.ID))
}

if invoice.Workflow.Apps.Invoicing == nil {
Expand All @@ -63,21 +63,21 @@ func (s *Service) ValidateInvoiceApp(invoice billing.Invoice) error {
return nil
}

func (s *Service) HandlePaymentTrigger(ctx context.Context, input appcustominvoicing.HandlePaymentTriggerInput) (billing.Invoice, error) {
func (s *Service) HandlePaymentTrigger(ctx context.Context, input appcustominvoicing.HandlePaymentTriggerInput) (billing.StandardInvoice, error) {
if err := input.Validate(); err != nil {
return billing.Invoice{}, err
return billing.StandardInvoice{}, err
}

return transaction.Run(ctx, s.adapter, func(ctx context.Context) (billing.Invoice, error) {
return transaction.Run(ctx, s.adapter, func(ctx context.Context) (billing.StandardInvoice, error) {
invoice, err := s.billingService.GetInvoiceByID(ctx, billing.GetInvoiceByIdInput{
Invoice: input.InvoiceID,
})
if err != nil {
return billing.Invoice{}, err
return billing.StandardInvoice{}, err
}

if err := s.ValidateInvoiceApp(invoice); err != nil {
return billing.Invoice{}, err
return billing.StandardInvoice{}, err
}

err = s.billingService.TriggerInvoice(ctx, billing.InvoiceTriggerServiceInput{
Expand All @@ -89,14 +89,14 @@ func (s *Service) HandlePaymentTrigger(ctx context.Context, input appcustominvoi
Capability: app.CapabilityTypeCollectPayments,
})
if err != nil {
return billing.Invoice{}, err
return billing.StandardInvoice{}, err
}

invoice, err = s.billingService.GetInvoiceByID(ctx, billing.GetInvoiceByIdInput{
Invoice: input.InvoiceID,
})
if err != nil {
return billing.Invoice{}, err
return billing.StandardInvoice{}, err
}

if len(invoice.ValidationIssues) > 0 {
Expand All @@ -106,7 +106,7 @@ func (s *Service) HandlePaymentTrigger(ctx context.Context, input appcustominvoi

if len(criticalIssues) > 0 {
// Warning: This causes a rollback of the transaction
return billing.Invoice{}, billing.ValidationError{
return billing.StandardInvoice{}, billing.ValidationError{
Err: criticalIssues.AsError(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions openmeter/app/custominvoicing/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type SyncDraftInvoiceInput struct {
InvoiceID billing.InvoiceID
UpsertInvoiceResults *billing.UpsertInvoiceResult
UpsertInvoiceResults *billing.UpsertStandardInvoiceResult
}

func (i *SyncDraftInvoiceInput) Validate() error {
Expand All @@ -29,7 +29,7 @@ func (i *SyncDraftInvoiceInput) Validate() error {

type SyncIssuingInvoiceInput struct {
InvoiceID billing.InvoiceID
FinalizeInvoiceResult *billing.FinalizeInvoiceResult
FinalizeInvoiceResult *billing.FinalizeStandardInvoiceResult
}

func (i *SyncIssuingInvoiceInput) Validate() error {
Expand Down
18 changes: 9 additions & 9 deletions openmeter/app/sandbox/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ func (a App) DeleteCustomerData(ctx context.Context, input app.DeleteAppInstance
return nil
}

func (a App) ValidateInvoice(ctx context.Context, invoice billing.Invoice) error {
func (a App) ValidateStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) error {
return nil
}

func (a App) UpdateAppConfig(ctx context.Context, input app.AppConfigUpdate) error {
return nil
}

func (a App) UpsertInvoice(ctx context.Context, invoice billing.Invoice) (*billing.UpsertInvoiceResult, error) {
return billing.NewUpsertInvoiceResult(), nil
func (a App) UpsertStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.UpsertStandardInvoiceResult, error) {
return billing.NewUpsertStandardInvoiceResult(), nil
}

func (a App) FinalizeInvoice(ctx context.Context, invoice billing.Invoice) (*billing.FinalizeInvoiceResult, error) {
func (a App) FinalizeStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.FinalizeStandardInvoiceResult, error) {
invoiceNumber, err := a.billingService.GenerateInvoiceSequenceNumber(
ctx,
billing.SequenceGenerationInput{
Expand All @@ -97,17 +97,17 @@ func (a App) FinalizeInvoice(ctx context.Context, invoice billing.Invoice) (*bil
return nil, fmt.Errorf("failed to generate invoice sequence number: %w", err)
}

return billing.NewFinalizeInvoiceResult().
return billing.NewFinalizeStandardInvoiceResult().
SetInvoiceNumber(invoiceNumber).
SetSentToCustomerAt(clock.Now()), nil
}

func (a App) DeleteInvoice(ctx context.Context, invoice billing.Invoice) error {
func (a App) DeleteStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) error {
return nil
}

func (a App) PostAdvanceInvoiceHook(ctx context.Context, invoice billing.Invoice) (*billing.PostAdvanceHookResult, error) {
if invoice.Status != billing.InvoiceStatusPaymentProcessingPending {
func (a App) PostAdvanceStandardInvoiceHook(ctx context.Context, invoice billing.StandardInvoice) (*billing.PostAdvanceHookResult, error) {
if invoice.Status != billing.StandardInvoiceStatusPaymentProcessingPending {
return nil, nil
}

Expand All @@ -127,7 +127,7 @@ func (a App) PostAdvanceInvoiceHook(ctx context.Context, invoice billing.Invoice
Invoice: invoice.InvoiceID(),
Trigger: billing.TriggerFailed,
ValidationErrors: &billing.InvoiceTriggerValidationInput{
Operation: billing.InvoiceOpInitiatePayment,
Operation: billing.StandardInvoiceOpInitiatePayment,
Errors: []error{ErrSimulatedPaymentFailure},
},
}), nil
Expand Down
40 changes: 20 additions & 20 deletions openmeter/app/sandbox/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type AppFactory interface {
NewApp(ctx context.Context, appBase app.AppBase) (app.App, error)
}

type InvoiceUpsertCallback func(billing.Invoice) (*billing.UpsertInvoiceResult, error)
type InvoiceUpsertCallback func(billing.StandardInvoice) (*billing.UpsertStandardInvoiceResult, error)

type MockApp struct {
validateCustomerResponse mo.Option[error]
Expand All @@ -29,7 +29,7 @@ type MockApp struct {
upsertInvoiceCallback mo.Option[InvoiceUpsertCallback]
upsertInvoiceCalled bool

finalizeInvoiceResponse mo.Option[*billing.FinalizeInvoiceResult]
finalizeInvoiceResponse mo.Option[*billing.FinalizeStandardInvoiceResult]
finalizeInvoiceCalled bool

deleteInvoiceResponse mo.Option[error]
Expand Down Expand Up @@ -67,44 +67,44 @@ func (m *MockApp) OnValidateCustomer(err error) {

// InvoicingApp

func (m *MockApp) ValidateInvoice(appID string, invoice billing.Invoice) error {
func (m *MockApp) ValidateStandardInvoice(appID string, invoice billing.StandardInvoice) error {
m.validateInvoiceResponseCalled = true
return m.validateInvoiceResponse.MustGet()
}

func (m *MockApp) OnValidateInvoice(err error) {
func (m *MockApp) OnValidateStandardInvoice(err error) {
m.validateInvoiceResponse = mo.Some(err)
}

func (m *MockApp) UpsertInvoice(ctx context.Context, invoice billing.Invoice) (*billing.UpsertInvoiceResult, error) {
func (m *MockApp) UpsertStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.UpsertStandardInvoiceResult, error) {
m.upsertInvoiceCalled = true

if m.upsertInvoiceCallback.IsPresent() && m.upsertInvoiceCallback.MustGet() != nil {
return m.upsertInvoiceCallback.MustGet()(invoice)
}

return billing.NewUpsertInvoiceResult(), nil
return billing.NewUpsertStandardInvoiceResult(), nil
}

func (m *MockApp) OnUpsertInvoice(cb InvoiceUpsertCallback) {
func (m *MockApp) OnUpsertStandardInvoice(cb InvoiceUpsertCallback) {
m.upsertInvoiceCallback = mo.Some(cb)
}

func (m *MockApp) FinalizeInvoice(ctx context.Context, invoice billing.Invoice) (*billing.FinalizeInvoiceResult, error) {
func (m *MockApp) FinalizeStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.FinalizeStandardInvoiceResult, error) {
m.finalizeInvoiceCalled = true
return m.finalizeInvoiceResponse.MustGet(), nil
}

func (m *MockApp) OnFinalizeInvoice(result *billing.FinalizeInvoiceResult) {
func (m *MockApp) OnFinalizeStandardInvoice(result *billing.FinalizeStandardInvoiceResult) {
m.finalizeInvoiceResponse = mo.Some(result)
}

func (m *MockApp) DeleteInvoice(ctx context.Context, invoice billing.Invoice) error {
func (m *MockApp) DeleteStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) error {
m.deleteInvoiceCalled = true
return m.deleteInvoiceResponse.MustGet()
}

func (m *MockApp) OnDeleteInvoice(err error) {
func (m *MockApp) OnDeleteStandardInvoice(err error) {
m.deleteInvoiceResponse = mo.Some(err)
}

Expand All @@ -122,7 +122,7 @@ func (m *MockApp) Reset(t *testing.T) {
m.upsertInvoiceCallback = mo.None[InvoiceUpsertCallback]()
m.upsertInvoiceCalled = false

m.finalizeInvoiceResponse = mo.None[*billing.FinalizeInvoiceResult]()
m.finalizeInvoiceResponse = mo.None[*billing.FinalizeStandardInvoiceResult]()
m.finalizeInvoiceCalled = false

m.deleteInvoiceResponse = mo.None[error]()
Expand Down Expand Up @@ -191,20 +191,20 @@ func (m *mockAppInstance) ValidateCustomer(ctx context.Context, customer *custom
return m.parent.ValidateCustomer(m.GetID().ID, customer, capabilities)
}

func (m *mockAppInstance) ValidateInvoice(ctx context.Context, invoice billing.Invoice) error {
return m.parent.ValidateInvoice(m.GetID().ID, invoice)
func (m *mockAppInstance) ValidateStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) error {
return m.parent.ValidateStandardInvoice(m.GetID().ID, invoice)
}

func (m *mockAppInstance) UpsertInvoice(ctx context.Context, invoice billing.Invoice) (*billing.UpsertInvoiceResult, error) {
return m.parent.UpsertInvoice(ctx, invoice)
func (m *mockAppInstance) UpsertStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.UpsertStandardInvoiceResult, error) {
return m.parent.UpsertStandardInvoice(ctx, invoice)
}

func (m *mockAppInstance) FinalizeInvoice(ctx context.Context, invoice billing.Invoice) (*billing.FinalizeInvoiceResult, error) {
return m.parent.FinalizeInvoice(ctx, invoice)
func (m *mockAppInstance) FinalizeStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.FinalizeStandardInvoiceResult, error) {
return m.parent.FinalizeStandardInvoice(ctx, invoice)
}

func (m *mockAppInstance) DeleteInvoice(ctx context.Context, invoice billing.Invoice) error {
return m.parent.DeleteInvoice(ctx, invoice)
func (m *mockAppInstance) DeleteStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) error {
return m.parent.DeleteStandardInvoice(ctx, invoice)
}

func (m *mockAppInstance) GetEventAppData() (app.EventAppData, error) {
Expand Down
Loading
Loading