diff --git a/openmeter/app/stripe/calculator.go b/openmeter/app/stripe/calculator.go index 5a13bc5747..c2e4ecc357 100644 --- a/openmeter/app/stripe/calculator.go +++ b/openmeter/app/stripe/calculator.go @@ -12,10 +12,8 @@ import ( ) // NewStripeCalculator creates a new StripeCalculator. -func NewStripeCalculator(currencyCode currencyx.Code) (StripeCalculator, error) { - currency, err := currencyx.NewCurrencyBuilder(currencyx.CurrencyTypeFiat). - WithCode(currencyCode). - Build() +func NewStripeCalculator(currencyCode currencyx.FiatCode) (StripeCalculator, error) { + currency, err := currencyCode.AsFiatCurrency() if err != nil { return StripeCalculator{}, fmt.Errorf("failed to get stripe calculator: %w", err) } diff --git a/openmeter/app/stripe/client/invoice.go b/openmeter/app/stripe/client/invoice.go index fa4b7584e6..f7814020da 100644 --- a/openmeter/app/stripe/client/invoice.go +++ b/openmeter/app/stripe/client/invoice.go @@ -144,7 +144,7 @@ type CreateInvoiceInput struct { InvoiceID string AutomaticTaxEnabled bool CollectionMethod billing.CollectionMethod - Currency currencyx.Code + Currency currencyx.FiatCode DaysUntilDue *int64 StatementDescriptor *string StripeCustomerID string diff --git a/openmeter/billing/charges/creditpurchase/service/create.go b/openmeter/billing/charges/creditpurchase/service/create.go index e4a06d5bec..c83c48d590 100644 --- a/openmeter/billing/charges/creditpurchase/service/create.go +++ b/openmeter/billing/charges/creditpurchase/service/create.go @@ -95,9 +95,8 @@ func (s *service) buildInvoiceCreditPurchaseGatheringLine(charge creditpurchase. // Total cost = credit amount * cost basis (e.g., 100 credits * $0.5 = $50) totalCost := intent.CreditAmount.Mul(invoiceSettlement.CostBasis) - calc, err := currencyx.NewCurrencyBuilder(currencyx.CurrencyTypeFiat). - WithCode(invoiceSettlement.Currency). - Build() + invoiceCurrency := currencyx.FiatCode(invoiceSettlement.Currency) + calc, err := invoiceCurrency.AsFiatCurrency() if err != nil { return billing.GatheringLine{}, fmt.Errorf("creating currency calculator: %w", err) } @@ -134,7 +133,7 @@ func (s *service) buildInvoiceCreditPurchaseGatheringLine(charge creditpurchase. }, ), ), - Currency: invoiceSettlement.Currency, + Currency: invoiceCurrency, ServicePeriod: intent.ServicePeriod, InvoiceAt: intent.CalculateEffectiveAt(), TaxConfig: lo.ToPtr(intent.TaxConfig.ToTaxConfig()), diff --git a/openmeter/billing/charges/flatfee/charge.go b/openmeter/billing/charges/flatfee/charge.go index 63b0649191..46ef6dc887 100644 --- a/openmeter/billing/charges/flatfee/charge.go +++ b/openmeter/billing/charges/flatfee/charge.go @@ -15,6 +15,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/currencies" "github.com/openmeterio/openmeter/openmeter/customer" "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/currencyx" "github.com/openmeterio/openmeter/pkg/models" "github.com/openmeterio/openmeter/pkg/timeutil" ) @@ -81,6 +82,25 @@ func (c ChargeBase) GetCurrency() currencies.Currency { return c.Intent.GetCurrency() } +func (c ChargeBase) GetInvoiceCurrency() (currencyx.FiatCode, error) { + currency := c.GetCurrency() + if currency.IsFiat() { + return currencyx.FiatCode(currency.GetCode()), nil + } + + costBasisIntent := c.Intent.GetCostBasisIntent() + if costBasisIntent == nil { + return "", errors.New("cost basis intent is required for a custom-currency invoice") + } + + fiatCurrency, err := costBasisIntent.GetFiatCurrency() + if err != nil { + return "", fmt.Errorf("getting cost basis fiat currency: %w", err) + } + + return fiatCurrency.GetFiatCode(), nil +} + func (c ChargeBase) ErrorAttributes() models.Attributes { return models.Attributes{ "charge_id": c.ID, diff --git a/openmeter/billing/charges/flatfee/service/create.go b/openmeter/billing/charges/flatfee/service/create.go index 37584dc0d1..087f5e0c06 100644 --- a/openmeter/billing/charges/flatfee/service/create.go +++ b/openmeter/billing/charges/flatfee/service/create.go @@ -195,6 +195,11 @@ func buildFlatFeeGatheringLine(input buildFlatFeeGatheringLineInput) (billing.Ga managedBy = billing.ManuallyManagedLine } + invoiceCurrency, err := flatFee.GetInvoiceCurrency() + if err != nil { + return billing.GatheringLine{}, fmt.Errorf("getting invoice currency: %w", err) + } + gatheringLine := billing.GatheringLine{ GatheringLineBase: billing.GatheringLineBase{ ManagedResource: models.NewManagedResource(models.ManagedResourceInput{ @@ -217,7 +222,7 @@ func buildFlatFeeGatheringLine(input buildFlatFeeGatheringLineInput) (billing.Ga ), FeatureKey: lo.FromPtr(lineIntent.FeatureKey), - Currency: lineIntent.Currency.GetCode(), + Currency: invoiceCurrency, ServicePeriod: lineIntent.ServicePeriod, InvoiceAt: lineIntent.InvoiceAt, diff --git a/openmeter/billing/charges/flatfee/service/linemapper.go b/openmeter/billing/charges/flatfee/service/linemapper.go index d1bd014783..62eceb4ecb 100644 --- a/openmeter/billing/charges/flatfee/service/linemapper.go +++ b/openmeter/billing/charges/flatfee/service/linemapper.go @@ -8,13 +8,10 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/flatfee" - "github.com/openmeterio/openmeter/pkg/currencyx" ) func populateFlatFeeStandardLineFromRun(stdLine *billing.StandardLine, run flatfee.RealizationRun) error { - currency, err := currencyx.NewCurrencyBuilder(currencyx.CurrencyTypeFiat). - WithCode(stdLine.Currency). - Build() + currency, err := stdLine.Currency.AsFiatCurrency() if err != nil { return fmt.Errorf("creating currency calculator: %w", err) } diff --git a/openmeter/billing/charges/flatfee/service/manualedit.go b/openmeter/billing/charges/flatfee/service/manualedit.go index b6523b4d55..3c006c1d6c 100644 --- a/openmeter/billing/charges/flatfee/service/manualedit.go +++ b/openmeter/billing/charges/flatfee/service/manualedit.go @@ -78,10 +78,11 @@ func intentFromManualCreatedLine( return flatfee.Intent{}, fmt.Errorf("line id is required") } - currency, err := currencies.NewFiatCurrency(line.GetCurrency()) + fiatCurrency, err := line.GetCurrency().AsFiatCurrency() if err != nil { return flatfee.Intent{}, fmt.Errorf("resolving fiat currency %q: %w", line.GetCurrency(), err) } + currency := currencies.Currency{Currency: fiatCurrency} if chargeID := line.GetChargeID(); chargeID != nil && *chargeID != "" { return flatfee.Intent{}, fmt.Errorf("line[%s]: charge id must be empty for manual create", line.GetID()) diff --git a/openmeter/billing/charges/invoiceupdater/invoiceupdate.go b/openmeter/billing/charges/invoiceupdater/invoiceupdate.go index 9ab26e2f00..e42485a4d9 100644 --- a/openmeter/billing/charges/invoiceupdater/invoiceupdate.go +++ b/openmeter/billing/charges/invoiceupdater/invoiceupdate.go @@ -320,7 +320,7 @@ func (u *updater) provisionUpcomingLines(ctx context.Context, customerID custome return nil } - linesByCurrency := lo.GroupBy(lines, func(l billing.GatheringLine) currencyx.Code { + linesByCurrency := lo.GroupBy(lines, func(l billing.GatheringLine) currencyx.FiatCode { return l.Currency }) diff --git a/openmeter/billing/charges/models/costbasis/intent.go b/openmeter/billing/charges/models/costbasis/intent.go index 0bcd9100fb..df22434eb8 100644 --- a/openmeter/billing/charges/models/costbasis/intent.go +++ b/openmeter/billing/charges/models/costbasis/intent.go @@ -130,6 +130,36 @@ func (i Intent) AsDynamic() (DynamicIntent, error) { return *i.dynamic, nil } +// GetFiatCurrency returns the fiat currency in which the custom-currency cost +// basis is expressed, regardless of the selected resolution mode. +func (i Intent) GetFiatCurrency() (*currencyx.FiatCurrency, error) { + switch i.kind { + case ModeDynamic: + intent, err := i.AsDynamic() + if err != nil { + return nil, err + } + + return intent.FiatCurrency, nil + case ModePinned: + intent, err := i.AsPinned() + if err != nil { + return nil, err + } + + return intent.FiatCurrency, nil + case ModeManual: + intent, err := i.AsManual() + if err != nil { + return nil, err + } + + return intent.FiatCurrency, nil + default: + return nil, models.NewGenericValidationError(fmt.Errorf("invalid intent kind: %s", i.kind)) + } +} + type DynamicIntent struct { FiatCurrency *currencyx.FiatCurrency } diff --git a/openmeter/billing/charges/service/create.go b/openmeter/billing/charges/service/create.go index ba2aabd13c..8fa994a177 100644 --- a/openmeter/billing/charges/service/create.go +++ b/openmeter/billing/charges/service/create.go @@ -394,7 +394,7 @@ type currencyAndCustomerID struct { } type currencyCodeAndCustomerID struct { - currency currencyx.Code + currency currencyx.FiatCode customerID customer.CustomerID } diff --git a/openmeter/billing/charges/service/creditpurchase_test.go b/openmeter/billing/charges/service/creditpurchase_test.go index a647e0e63a..901697b5a5 100644 --- a/openmeter/billing/charges/service/creditpurchase_test.go +++ b/openmeter/billing/charges/service/creditpurchase_test.go @@ -826,7 +826,7 @@ func (s *CreditPurchaseTestSuite) TestStandardInvoiceCreditPurchase() { s.Require().Len(lines, 1) line := lines[0] - s.Equal(USD, line.Currency) + s.Equal(currencyx.FiatCode(USD), line.Currency) s.Equal(timeutil.ClosedPeriod{ From: datetime.MustParseTimeInLocation(s.T(), "2026-01-01T00:00:00Z", time.UTC).AsTime(), To: datetime.MustParseTimeInLocation(s.T(), "2026-02-01T00:00:00Z", time.UTC).AsTime(), diff --git a/openmeter/billing/charges/service/flatfee_costbasis_test.go b/openmeter/billing/charges/service/flatfee_costbasis_test.go index 3e82186d4c..eaffb789d2 100644 --- a/openmeter/billing/charges/service/flatfee_costbasis_test.go +++ b/openmeter/billing/charges/service/flatfee_costbasis_test.go @@ -140,6 +140,8 @@ func (s *FlatFeeCostBasisCreateSuite) TestCreatePersistsManualPinnedAndDynamicCo seenCostBasisIDs := map[string]struct{}{} for idx, result := range created { + s.Require().NotNil(result.GatheringLineToCreate, "charge index %d", idx) + s.Require().Equal(currencyx.FiatCode("USD"), result.GatheringLineToCreate.Currency, "charge index %d", idx) s.Require().NotNil(result.Charge.State.CostBasisID, "charge index %d", idx) reloaded, err := s.mustGetChargeByID(result.Charge.GetChargeID()).AsFlatFeeCharge() diff --git a/openmeter/billing/charges/service/invoicable_test.go b/openmeter/billing/charges/service/invoicable_test.go index dffeb4c9bd..938f97f73f 100644 --- a/openmeter/billing/charges/service/invoicable_test.go +++ b/openmeter/billing/charges/service/invoicable_test.go @@ -498,7 +498,7 @@ func (s *InvoicableChargesTestSuite) TestFlatFeePartialCreditRealizations() { gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{currencyx.Code(currency.USD)}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(currency.USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) @@ -1363,7 +1363,7 @@ func (s *InvoicableChargesTestSuite) TestUsageBasedCreditOnlyLifecycle() { gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{currencyx.Code(currency.USD)}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(currency.USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) @@ -2759,7 +2759,7 @@ func (s *InvoicableChargesTestSuite) TestFlatFeeCreditOnlyLifecycle() { gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{currencyx.Code(currency.USD)}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(currency.USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) diff --git a/openmeter/billing/charges/service/invoice.go b/openmeter/billing/charges/service/invoice.go index 4250a605ce..5d7b96efee 100644 --- a/openmeter/billing/charges/service/invoice.go +++ b/openmeter/billing/charges/service/invoice.go @@ -88,10 +88,11 @@ func (s *service) handleStandardInvoiceUpdate(ctx context.Context, invoice billi return err } - currency, err := currencies.NewFiatCurrency(invoice.Currency) + fiatCurrency, err := invoice.Currency.AsFiatCurrency() if err != nil { return fmt.Errorf("resolving fiat invoice currency %q: %w", invoice.Currency, err) } + currency := currencies.Currency{Currency: fiatCurrency} return s.recognizeCustomerEarnings(ctx, invoice.CustomerID(), currency) } diff --git a/openmeter/billing/charges/service/pendinglines.go b/openmeter/billing/charges/service/pendinglines.go index a2c1a84e3a..051d7eba04 100644 --- a/openmeter/billing/charges/service/pendinglines.go +++ b/openmeter/billing/charges/service/pendinglines.go @@ -15,7 +15,6 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" "github.com/openmeterio/openmeter/openmeter/currencies" "github.com/openmeterio/openmeter/openmeter/productcatalog" - "github.com/openmeterio/openmeter/pkg/currencyx" "github.com/openmeterio/openmeter/pkg/framework/transaction" "github.com/openmeterio/openmeter/pkg/slicesx" ) @@ -112,9 +111,7 @@ func validateChargePendingInvoiceLinesInput(input charges.CreatePendingInvoiceLi } func mapPendingInvoiceLinesToChargeIntents(input charges.CreatePendingInvoiceLinesInput) (charges.ChargeIntents, error) { - currency, err := currencyx.NewCurrencyBuilder(currencyx.CurrencyTypeFiat). - WithCode(input.Currency). - Build() + currency, err := input.Currency.AsFiatCurrency() if err != nil { return nil, fmt.Errorf("resolving fiat currency %q: %w", input.Currency, err) } diff --git a/openmeter/billing/charges/service/pendinglines_test.go b/openmeter/billing/charges/service/pendinglines_test.go index 70376916c8..36615bb3c3 100644 --- a/openmeter/billing/charges/service/pendinglines_test.go +++ b/openmeter/billing/charges/service/pendinglines_test.go @@ -10,6 +10,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/currencyx" "github.com/openmeterio/openmeter/pkg/datetime" "github.com/openmeterio/openmeter/pkg/models" "github.com/openmeterio/openmeter/pkg/timeutil" @@ -46,7 +47,7 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesCreatesChargeB }), ManagedBy: billing.ManuallyManagedLine, Engine: billing.LineEngineTypeInvoice, - Currency: USD, + Currency: currencyx.FiatCode(USD), ServicePeriod: servicePeriod, InvoiceAt: servicePeriod.To, Price: lo.FromPtr(productcatalog.NewPriceFrom(productcatalog.UnitPrice{ @@ -70,7 +71,7 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesCreatesChargeB InvoiceAt: servicePeriod.From, ManagedBy: billing.ManuallyManagedLine, Name: "manual flat", - Currency: USD, + Currency: currencyx.FiatCode(USD), PerUnitAmount: alpacadecimal.NewFromInt(10), PaymentTerm: productcatalog.InAdvancePaymentTerm, RateCardDiscounts: billing.Discounts{ @@ -86,7 +87,7 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesCreatesChargeB result, err := s.Charges.CreatePendingInvoiceLines(ctx, charges.CreatePendingInvoiceLinesInput{ Customer: cust.GetID(), - Currency: USD, + Currency: currencyx.FiatCode(USD), Lines: []billing.GatheringLine{ usageLine, flatLine, @@ -154,7 +155,7 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesRollsBackCreat InvoiceAt: servicePeriod.From, ManagedBy: billing.ManuallyManagedLine, Name: "manual zero flat", - Currency: USD, + Currency: currencyx.FiatCode(USD), PerUnitAmount: alpacadecimal.Zero, PaymentTerm: productcatalog.InAdvancePaymentTerm, }) @@ -163,7 +164,7 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesRollsBackCreat result, err := s.Charges.CreatePendingInvoiceLines(ctx, charges.CreatePendingInvoiceLinesInput{ Customer: cust.GetID(), - Currency: USD, + Currency: currencyx.FiatCode(USD), Lines: []billing.GatheringLine{ zeroFlatLine, }, @@ -198,14 +199,14 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesRejectsNonManu InvoiceAt: servicePeriod.From, ManagedBy: billing.SystemManagedLine, Name: "system flat", - Currency: USD, + Currency: currencyx.FiatCode(USD), PerUnitAmount: alpacadecimal.NewFromInt(10), PaymentTerm: productcatalog.InAdvancePaymentTerm, }) _, err := s.Charges.CreatePendingInvoiceLines(ctx, charges.CreatePendingInvoiceLinesInput{ Customer: cust.GetID(), - Currency: USD, + Currency: currencyx.FiatCode(USD), Lines: []billing.GatheringLine{ systemLine, }, @@ -219,7 +220,7 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesRejectsNonManu InvoiceAt: servicePeriod.From, ManagedBy: billing.ManuallyManagedLine, Name: "subscription flat", - Currency: USD, + Currency: currencyx.FiatCode(USD), PerUnitAmount: alpacadecimal.NewFromInt(10), PaymentTerm: productcatalog.InAdvancePaymentTerm, }) @@ -232,7 +233,7 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesRejectsNonManu _, err = s.Charges.CreatePendingInvoiceLines(ctx, charges.CreatePendingInvoiceLinesInput{ Customer: cust.GetID(), - Currency: USD, + Currency: currencyx.FiatCode(USD), Lines: []billing.GatheringLine{ subscriptionLine, }, @@ -270,7 +271,7 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesRollsBackParti }), ManagedBy: billing.ManuallyManagedLine, Engine: billing.LineEngineTypeInvoice, - Currency: USD, + Currency: currencyx.FiatCode(USD), ServicePeriod: servicePeriod, InvoiceAt: servicePeriod.To, Price: lo.FromPtr(productcatalog.NewPriceFrom(productcatalog.UnitPrice{ @@ -286,7 +287,7 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesRollsBackParti InvoiceAt: servicePeriod.From, ManagedBy: billing.ManuallyManagedLine, Name: "manual zero flat", - Currency: USD, + Currency: currencyx.FiatCode(USD), PerUnitAmount: alpacadecimal.Zero, PaymentTerm: productcatalog.InAdvancePaymentTerm, }) @@ -294,7 +295,7 @@ func (s *InvoicableChargesTestSuite) TestCreatePendingInvoiceLinesRollsBackParti result, err := s.Charges.CreatePendingInvoiceLines(ctx, charges.CreatePendingInvoiceLinesInput{ Customer: cust.GetID(), - Currency: USD, + Currency: currencyx.FiatCode(USD), Lines: []billing.GatheringLine{ usageLine, zeroFlatLine, diff --git a/openmeter/billing/charges/service/taxcode_test.go b/openmeter/billing/charges/service/taxcode_test.go index 88bec931f6..675c65bc7c 100644 --- a/openmeter/billing/charges/service/taxcode_test.go +++ b/openmeter/billing/charges/service/taxcode_test.go @@ -410,7 +410,7 @@ func (s *TaxCodePersistenceTestSuite) TestCreditPurchaseInvoiceSettlementPropaga gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{USD}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) @@ -529,7 +529,7 @@ func (s *TaxCodePersistenceTestSuite) TestCreditPurchaseInvoiceSettlementNilTaxC gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{USD}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) @@ -980,7 +980,7 @@ func (s *TaxCodePersistenceTestSuite) TestFlatFeeInvoiceSettlementPropagatesTaxC gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{USD}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) @@ -1040,7 +1040,7 @@ func (s *TaxCodePersistenceTestSuite) TestFlatFeeInvoiceSettlementNilTaxConfigGe gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{USD}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) @@ -1111,7 +1111,7 @@ func (s *TaxCodePersistenceTestSuite) TestUsageBasedCreditThenInvoicePropagatesT gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{USD}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) @@ -1295,7 +1295,7 @@ func (s *TaxCodePersistenceTestSuite) TestFlatFeeBehaviorOnlyTaxConfigGetsDefaul gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{USD}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) @@ -1371,7 +1371,7 @@ func (s *TaxCodePersistenceTestSuite) TestUsageBasedBehaviorOnlyTaxConfigGetsDef gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{USD}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) diff --git a/openmeter/billing/charges/service/usagebased_costbasis_test.go b/openmeter/billing/charges/service/usagebased_costbasis_test.go index 748e0d2893..f8d659dd2c 100644 --- a/openmeter/billing/charges/service/usagebased_costbasis_test.go +++ b/openmeter/billing/charges/service/usagebased_costbasis_test.go @@ -140,6 +140,8 @@ func (s *UsageBasedCostBasisCreateSuite) TestCreatePersistsManualPinnedAndDynami seenCostBasisIDs := map[string]struct{}{} for idx, result := range created { + s.Require().NotNil(result.GatheringLineToCreate, "charge index %d", idx) + s.Require().Equal(currencyx.FiatCode("USD"), result.GatheringLineToCreate.Currency, "charge index %d", idx) s.Require().NotNil(result.Charge.State.CostBasisID, "charge index %d", idx) reloaded, err := s.mustGetChargeByID(result.Charge.GetChargeID()).AsUsageBasedCharge() diff --git a/openmeter/billing/charges/usagebased/charge.go b/openmeter/billing/charges/usagebased/charge.go index ca886df010..1d066ca0a6 100644 --- a/openmeter/billing/charges/usagebased/charge.go +++ b/openmeter/billing/charges/usagebased/charge.go @@ -15,6 +15,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/customer" "github.com/openmeterio/openmeter/openmeter/productcatalog" "github.com/openmeterio/openmeter/openmeter/productcatalog/feature" + "github.com/openmeterio/openmeter/pkg/currencyx" "github.com/openmeterio/openmeter/pkg/models" "github.com/openmeterio/openmeter/pkg/ref" "github.com/openmeterio/openmeter/pkg/timeutil" @@ -84,6 +85,25 @@ func (c ChargeBase) GetCurrency() currencies.Currency { return c.Intent.GetCurrency() } +func (c ChargeBase) GetInvoiceCurrency() (currencyx.FiatCode, error) { + currency := c.GetCurrency() + if currency.IsFiat() { + return currencyx.FiatCode(currency.GetCode()), nil + } + + costBasisIntent := c.Intent.GetCostBasisIntent() + if costBasisIntent == nil { + return "", errors.New("cost basis intent is required for a custom-currency invoice") + } + + fiatCurrency, err := costBasisIntent.GetFiatCurrency() + if err != nil { + return "", fmt.Errorf("getting cost basis fiat currency: %w", err) + } + + return fiatCurrency.GetFiatCode(), nil +} + // GetIntentDeletedAt returns the effective intent deletion timestamp. // If an override is present, the override intent owns deletion; otherwise the base intent does. func (c ChargeBase) GetIntentDeletedAt() *time.Time { diff --git a/openmeter/billing/charges/usagebased/service/create.go b/openmeter/billing/charges/usagebased/service/create.go index f9426e9ba2..266da4992f 100644 --- a/openmeter/billing/charges/usagebased/service/create.go +++ b/openmeter/billing/charges/usagebased/service/create.go @@ -118,6 +118,11 @@ func gatheringLineFromUsageBasedChargeForPeriod(charge usagebased.Charge, servic unitConfig = lo.ToPtr(intent.UnitConfig.Clone()) } + invoiceCurrency, err := charge.GetInvoiceCurrency() + if err != nil { + return usagebased.ChargeWithGatheringLine{}, fmt.Errorf("getting invoice currency: %w", err) + } + gatheringLine := billing.GatheringLine{ GatheringLineBase: billing.GatheringLineBase{ ManagedResource: models.NewManagedResource(models.ManagedResourceInput{ @@ -134,7 +139,7 @@ func gatheringLineFromUsageBasedChargeForPeriod(charge usagebased.Charge, servic FeatureKey: intent.FeatureKey, UnitConfig: unitConfig, - Currency: intent.Currency.GetCode(), + Currency: invoiceCurrency, ServicePeriod: servicePeriod, InvoiceAt: invoiceAt, diff --git a/openmeter/billing/charges/usagebased/service/lineengine_test.go b/openmeter/billing/charges/usagebased/service/lineengine_test.go index eebcd48f66..ab10187b3f 100644 --- a/openmeter/billing/charges/usagebased/service/lineengine_test.go +++ b/openmeter/billing/charges/usagebased/service/lineengine_test.go @@ -59,7 +59,7 @@ func TestLineEngineSplitGatheringLineKeepsChargeGroupingWithoutChildReferences(t }), ManagedBy: billing.SystemManagedLine, Engine: billing.LineEngineTypeChargeUsageBased, - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), ServicePeriod: servicePeriod, InvoiceAt: servicePeriod.To, Price: lo.FromPtr(price), diff --git a/openmeter/billing/charges/usagebased/service/linemapper.go b/openmeter/billing/charges/usagebased/service/linemapper.go index ef6164f473..82265a7c55 100644 --- a/openmeter/billing/charges/usagebased/service/linemapper.go +++ b/openmeter/billing/charges/usagebased/service/linemapper.go @@ -35,9 +35,7 @@ func intentFromManualCreatedLine( return usagebased.Intent{}, fmt.Errorf("line id is required") } - currency, err := currencyx.NewCurrencyBuilder(currencyx.CurrencyTypeFiat). - WithCode(line.GetCurrency()). - Build() + currency, err := line.GetCurrency().AsFiatCurrency() if err != nil { return usagebased.Intent{}, fmt.Errorf("resolving fiat currency %q: %w", line.GetCurrency(), err) } @@ -133,9 +131,7 @@ func populateStandardLineFromRun(stdLine *billing.StandardLine, input populateSt stdLine.UsageBased = &billing.UsageBasedLine{} } - cur, err := currencyx.NewCurrencyBuilder(currencyx.CurrencyTypeFiat). - WithCode(stdLine.Currency). - Build() + cur, err := stdLine.Currency.AsFiatCurrency() if err != nil { return fmt.Errorf("creating currency calculator: %w", err) } diff --git a/openmeter/billing/charges/usagebased/service/linemapper_test.go b/openmeter/billing/charges/usagebased/service/linemapper_test.go index 2cf92137b9..e864458f3f 100644 --- a/openmeter/billing/charges/usagebased/service/linemapper_test.go +++ b/openmeter/billing/charges/usagebased/service/linemapper_test.go @@ -234,7 +234,7 @@ func newUsageBasedStandardLineForTest(period timeutil.ClosedPeriod) *billing.Sta ManagedBy: billing.SystemManagedLine, Engine: billing.LineEngineTypeChargeUsageBased, InvoiceID: "invoice-id", - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), Period: period, InvoiceAt: period.To, ChargeID: lo.ToPtr("charge-id"), diff --git a/openmeter/billing/charges/usagebased/service/run/payment_test.go b/openmeter/billing/charges/usagebased/service/run/payment_test.go index 62b2c344a5..8f1740d005 100644 --- a/openmeter/billing/charges/usagebased/service/run/payment_test.go +++ b/openmeter/billing/charges/usagebased/service/run/payment_test.go @@ -117,7 +117,7 @@ func newBookPaymentAuthorizedInput(t testing.TB) BookInvoicedPaymentAuthorizedIn Name: "line-1", }, ManagedBy: billing.SystemManagedLine, - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), InvoiceID: "invoice-1", InvoiceAt: now, Period: timeutil.ClosedPeriod{ diff --git a/openmeter/billing/gatheringinvoice.go b/openmeter/billing/gatheringinvoice.go index 33acdb00da..55ce5e0898 100644 --- a/openmeter/billing/gatheringinvoice.go +++ b/openmeter/billing/gatheringinvoice.go @@ -30,7 +30,7 @@ type GatheringInvoiceBase struct { Number string `json:"number"` CustomerID string `json:"customerID"` - Currency currencyx.Code `json:"currency"` + Currency currencyx.FiatCode `json:"currency"` ServicePeriod timeutil.ClosedPeriod `json:"servicePeriod"` NextCollectionAt *time.Time `json:"nextCollectionAt,omitempty"` @@ -414,7 +414,7 @@ type GatheringLineBase struct { Engine LineEngineType `json:"engine,omitempty"` InvoiceID string `json:"invoiceID"` - Currency currencyx.Code `json:"currency"` + Currency currencyx.FiatCode `json:"currency"` ServicePeriod timeutil.ClosedPeriod `json:"period"` InvoiceAt time.Time `json:"invoiceAt"` Price productcatalog.Price `json:"price"` @@ -453,7 +453,7 @@ func (i GatheringLineBase) GetTaxConfig() *TaxConfig { return FromProductCatalog(i.TaxConfig) } -func (i GatheringLineBase) GetCurrency() currencyx.Code { +func (i GatheringLineBase) GetCurrency() currencyx.FiatCode { return i.Currency } @@ -883,7 +883,7 @@ func (g GatheringLine) AsNewStandardLine(invoiceID string) (*StandardLine, error type CreatePendingInvoiceLinesInput struct { Customer customer.CustomerID `json:"customer"` - Currency currencyx.Code `json:"currency"` + Currency currencyx.FiatCode `json:"currency"` Lines []GatheringLine `json:"lines"` } @@ -928,7 +928,7 @@ type CreatePendingInvoiceLinesResult struct { type CreateGatheringInvoiceAdapterInput struct { Namespace string Number string - Currency currencyx.Code + Currency currencyx.FiatCode Metadata map[string]string Description *string @@ -976,7 +976,7 @@ type ListGatheringInvoicesInput struct { ExcludedNamespaces []string IDs []string Customers []string - Currencies []currencyx.Code + Currencies []currencyx.FiatCode OrderBy api.InvoiceOrderBy Order sortx.Order IncludeDeleted bool @@ -1094,5 +1094,5 @@ func (i UpdateGatheringInvoiceInput) Validate() error { type PrepareBillableLinesInput = InvoicePendingLinesInput type PrepareBillableLinesResult struct { - LinesByCurrency map[currencyx.Code]GatheringLines + LinesByCurrency map[currencyx.FiatCode]GatheringLines } diff --git a/openmeter/billing/httpdriver/invoice.go b/openmeter/billing/httpdriver/invoice.go index fba33cebb1..4fe0097e94 100644 --- a/openmeter/billing/httpdriver/invoice.go +++ b/openmeter/billing/httpdriver/invoice.go @@ -463,7 +463,7 @@ func (h *handler) SimulateInvoice() SimulateInvoiceHandler { CustomerID: ¶ms.CustomerID, Number: body.Number, - Currency: currencyx.Code(body.Currency), + Currency: currencyx.FiatCode(body.Currency), Lines: billing.NewStandardInvoiceLines(lines), }, nil }, diff --git a/openmeter/billing/httpdriver/invoice_test.go b/openmeter/billing/httpdriver/invoice_test.go index 0fdfeb1b6d..49b4a011d1 100644 --- a/openmeter/billing/httpdriver/invoice_test.go +++ b/openmeter/billing/httpdriver/invoice_test.go @@ -218,7 +218,7 @@ func (s *InvoicingTestSuite) TestGatheringInvoiceSerialization() { // Let's provision a gathering invoice with a single flat fee line res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: cust.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine( billing.NewFlatFeeLineInput{ diff --git a/openmeter/billing/httpdriver/invoiceline.go b/openmeter/billing/httpdriver/invoiceline.go index 4df1ab90cb..00944df1b5 100644 --- a/openmeter/billing/httpdriver/invoiceline.go +++ b/openmeter/billing/httpdriver/invoiceline.go @@ -79,7 +79,7 @@ func (h *handler) CreatePendingLine() CreatePendingLineHandler { Namespace: ns, ID: params.CustomerID, }, - Currency: currencyx.Code(req.Currency), + Currency: currencyx.FiatCode(req.Currency), Lines: lineEntities, }, nil }, @@ -259,7 +259,7 @@ func mapTaxConfigToAPI(to *productcatalog.TaxConfig) *api.TaxConfig { return lo.ToPtr(productcataloghttp.FromTaxConfig(*to)) } -func mapDetailedLinesToAPI(lines billing.DetailedLines, currency currencyx.Code, invoiceAt time.Time, taxConfig *productcatalog.TaxConfig) (*[]api.InvoiceDetailedLine, error) { +func mapDetailedLinesToAPI(lines billing.DetailedLines, currency currencyx.FiatCode, invoiceAt time.Time, taxConfig *productcatalog.TaxConfig) (*[]api.InvoiceDetailedLine, error) { mappedLines, err := slicesx.MapWithErr(lines, func(line billing.DetailedLine) (api.InvoiceDetailedLine, error) { return mapDetailedLineToAPI(line, currency, invoiceAt, taxConfig) }) @@ -270,7 +270,7 @@ func mapDetailedLinesToAPI(lines billing.DetailedLines, currency currencyx.Code, return lo.ToPtr(mappedLines), nil } -func mapDetailedLineToAPI(line billing.DetailedLine, currency currencyx.Code, invoiceAt time.Time, taxConfig *productcatalog.TaxConfig) (api.InvoiceDetailedLine, error) { +func mapDetailedLineToAPI(line billing.DetailedLine, currency currencyx.FiatCode, invoiceAt time.Time, taxConfig *productcatalog.TaxConfig) (api.InvoiceDetailedLine, error) { amountDiscountsAPI, err := mapInvoiceLineAmountDiscountsToAPI(line.AmountDiscounts) if err != nil { return api.InvoiceDetailedLine{}, fmt.Errorf("failed to map amount discounts: %w", err) diff --git a/openmeter/billing/invoiceline.go b/openmeter/billing/invoiceline.go index 95dc569164..2d8f5f1be1 100644 --- a/openmeter/billing/invoiceline.go +++ b/openmeter/billing/invoiceline.go @@ -103,7 +103,7 @@ type GenericInvoiceLineReader interface { GetInvoiceID() string GetEngine() LineEngineType GetLineEngineType() LineEngineType - GetCurrency() currencyx.Code + GetCurrency() currencyx.FiatCode GetPrice() *productcatalog.Price GetUnitConfig() *productcatalog.UnitConfig GetTaxConfig() *TaxConfig diff --git a/openmeter/billing/invoicelinesplitgroup.go b/openmeter/billing/invoicelinesplitgroup.go index 028eb452f0..c60b95bdb7 100644 --- a/openmeter/billing/invoicelinesplitgroup.go +++ b/openmeter/billing/invoicelinesplitgroup.go @@ -59,7 +59,7 @@ type SplitLineGroupCreate struct { Price *productcatalog.Price `json:"price"` FeatureKey *string `json:"featureKey,omitempty"` Subscription *SubscriptionReference `json:"subscription,omitempty"` - Currency currencyx.Code `json:"currency"` + Currency currencyx.FiatCode `json:"currency"` UniqueReferenceID *string `json:"childUniqueReferenceId,omitempty"` } @@ -127,7 +127,7 @@ type SplitLineGroup struct { Price *productcatalog.Price `json:"price"` FeatureKey *string `json:"featureKey,omitempty"` Subscription *SubscriptionReference `json:"subscription,omitempty"` - Currency currencyx.Code `json:"currency"` + Currency currencyx.FiatCode `json:"currency"` UniqueReferenceID *string `json:"childUniqueReferenceId,omitempty"` } diff --git a/openmeter/billing/sequence/sequence.go b/openmeter/billing/sequence/sequence.go index d94e02d6b0..bfc258075b 100644 --- a/openmeter/billing/sequence/sequence.go +++ b/openmeter/billing/sequence/sequence.go @@ -98,7 +98,7 @@ var ( type GenerationInput struct { Namespace string CustomerName string - Currency currencyx.Code + Currency currencyx.FiatCode } func (i GenerationInput) Validate() error { diff --git a/openmeter/billing/sequence/service/service.go b/openmeter/billing/sequence/service/service.go index 764906ff01..0c7e514f06 100644 --- a/openmeter/billing/sequence/service/service.go +++ b/openmeter/billing/sequence/service/service.go @@ -68,7 +68,7 @@ func New(config Config) (*Service, error) { type sequenceInput struct { CustomerPrefix string - Currency currencyx.Code + Currency currencyx.FiatCode NextSequenceNumber string } diff --git a/openmeter/billing/sequence/service/service_test.go b/openmeter/billing/sequence/service/service_test.go index 382f18466f..67d94eb1eb 100644 --- a/openmeter/billing/sequence/service/service_test.go +++ b/openmeter/billing/sequence/service/service_test.go @@ -222,7 +222,7 @@ func (s *SequenceServiceSuite) generateInvoiceNumber(ctx context.Context, namesp return s.service.GenerateInvoiceSequenceNumber(ctx, sequence.GenerationInput{ Namespace: namespace, CustomerName: "Acme Inc", - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), }, sequence.Definition{ Prefix: "INV", SuffixTemplate: "{{.CustomerPrefix}}-{{.NextSequenceNumber}}", diff --git a/openmeter/billing/service/gatheringinvoicependinglines.go b/openmeter/billing/service/gatheringinvoicependinglines.go index 9f2f76246a..ef66d16f79 100644 --- a/openmeter/billing/service/gatheringinvoicependinglines.go +++ b/openmeter/billing/service/gatheringinvoicependinglines.go @@ -167,7 +167,7 @@ func (s *Service) prepareBillableLines(ctx context.Context, input billing.Prepar } } - invoicesByCurrency := lo.SliceToMap(existingGatheringInvoices.Items, func(i billing.GatheringInvoice) (currencyx.Code, gatheringInvoiceWithFeatureMeters) { + invoicesByCurrency := lo.SliceToMap(existingGatheringInvoices.Items, func(i billing.GatheringInvoice) (currencyx.FiatCode, gatheringInvoiceWithFeatureMeters) { return i.Currency, gatheringInvoiceWithFeatureMeters{ Invoice: i, } @@ -199,7 +199,7 @@ func (s *Service) prepareBillableLines(ctx context.Context, input billing.Prepar return nil, err } - linesToBeBilledByCurrency := make(map[currencyx.Code]billing.GatheringLines) + linesToBeBilledByCurrency := make(map[currencyx.FiatCode]billing.GatheringLines) for currency, inScopeLines := range inScopeLinesByCurrency { // Let's first make sure we have properly split the progressively billed @@ -311,7 +311,7 @@ type gatheringInvoiceWithFeatureMeters struct { } type gatherInScopeLineInput struct { - GatheringInvoicesByCurrency map[currencyx.Code]gatheringInvoiceWithFeatureMeters + GatheringInvoicesByCurrency map[currencyx.FiatCode]gatheringInvoiceWithFeatureMeters // If set restricts the lines to be included to these IDs, otherwise the AsOf is used // to determine the lines to be included. LinesToInclude mo.Option[[]string] @@ -319,7 +319,7 @@ type gatherInScopeLineInput struct { ProgressiveBilling bool } -type gatherInScopeLinesResult map[currencyx.Code][]gatheringLineWithBillablePeriod +type gatherInScopeLinesResult map[currencyx.FiatCode][]gatheringLineWithBillablePeriod func (s *Service) gatherInScopeLines(ctx context.Context, in gatherInScopeLineInput) (gatherInScopeLinesResult, error) { res := make(gatherInScopeLinesResult) @@ -496,7 +496,7 @@ func (s *Service) hasInvoicableLines(ctx context.Context, in hasInvoicableLinesI } inScopeLines, err := s.gatherInScopeLines(ctx, gatherInScopeLineInput{ - GatheringInvoicesByCurrency: map[currencyx.Code]gatheringInvoiceWithFeatureMeters{ + GatheringInvoicesByCurrency: map[currencyx.FiatCode]gatheringInvoiceWithFeatureMeters{ in.Invoice.Currency: { Invoice: in.Invoice, FeatureMeters: in.FeatureMeters, diff --git a/openmeter/billing/service/invoicecalc/collectionat_test.go b/openmeter/billing/service/invoicecalc/collectionat_test.go index 7141142e0d..0d9f8785da 100644 --- a/openmeter/billing/service/invoicecalc/collectionat_test.go +++ b/openmeter/billing/service/invoicecalc/collectionat_test.go @@ -379,7 +379,7 @@ func newStandardLine(t *testing.T, invoiceAt string) *billing.StandardLine { return &billing.StandardLine{ StandardLineBase: billing.StandardLineBase{ ManagedResource: billing.GatheringLineBase{}.ManagedResource, - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), ManagedBy: billing.ManuallyManagedLine, InvoiceAt: at, Period: timeutil.ClosedPeriod{ @@ -427,7 +427,7 @@ func newFlatFeeStandardLine(t *testing.T, invoiceAt string) *billing.StandardLin To: at, }, Name: "Flat fee", - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), ManagedBy: billing.ManuallyManagedLine, PerUnitAmount: alpacadecimal.NewFromFloat(10), diff --git a/openmeter/billing/service/invoiceupdate.go b/openmeter/billing/service/invoiceupdate.go index 3b3a327e30..9c53590c78 100644 --- a/openmeter/billing/service/invoiceupdate.go +++ b/openmeter/billing/service/invoiceupdate.go @@ -746,7 +746,7 @@ func (s *Service) taxCodeIDWithBackfill(ctx context.Context, namespace string, t type preallocatedCreatedStandardLinesInput struct { Invoice billing.InvoiceID - Currency currencyx.Code + Currency currencyx.FiatCode SchemaLevel int CreatedLines []billing.GenericInvoiceLine } diff --git a/openmeter/billing/service/invoiceupdate_test.go b/openmeter/billing/service/invoiceupdate_test.go index a0e7f129ce..63116a48cf 100644 --- a/openmeter/billing/service/invoiceupdate_test.go +++ b/openmeter/billing/service/invoiceupdate_test.go @@ -765,7 +765,7 @@ func TestApplyManualInvoiceLineOverridesMarksGatheringManualChanges(t *testing.T ID: "invoice-1", Name: "invoice-1", }, - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), ServicePeriod: originalLine.ServicePeriod, SchemaLevel: 1, }, @@ -815,7 +815,7 @@ func newStandardLineForLineEngineTest(id string, engine billing.LineEngineType, }, Engine: engine, InvoiceID: "invoice-1", - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), ManagedBy: billing.ManuallyManagedLine, Period: timeutil.ClosedPeriod{ From: now, @@ -855,7 +855,7 @@ func newGatheringLineForLineEngineTest(id string, engine billing.LineEngineType, }, Engine: engine, InvoiceID: "invoice-1", - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), ManagedBy: billing.ManuallyManagedLine, ServicePeriod: timeutil.ClosedPeriod{ From: now, diff --git a/openmeter/billing/service/stdinvoiceline.go b/openmeter/billing/service/stdinvoiceline.go index 2c68cb5ca4..487b804430 100644 --- a/openmeter/billing/service/stdinvoiceline.go +++ b/openmeter/billing/service/stdinvoiceline.go @@ -173,7 +173,7 @@ type upsertGatheringInvoiceForCurrencyResponse struct { IsInvoiceNew bool } -func (s *Service) upsertGatheringInvoiceForCurrency(ctx context.Context, currency currencyx.Code, customerProfile billing.CustomerOverrideWithDetails) (*upsertGatheringInvoiceForCurrencyResponse, error) { +func (s *Service) upsertGatheringInvoiceForCurrency(ctx context.Context, currency currencyx.FiatCode, customerProfile billing.CustomerOverrideWithDetails) (*upsertGatheringInvoiceForCurrencyResponse, error) { // We would want to stage a pending invoice Line pendingInvoiceList, err := s.adapter.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Page: pagination.Page{ @@ -182,7 +182,7 @@ func (s *Service) upsertGatheringInvoiceForCurrency(ctx context.Context, currenc }, Customers: []string{customerProfile.Customer.ID}, Namespaces: []string{customerProfile.Customer.Namespace}, - Currencies: []currencyx.Code{currency}, + Currencies: []currencyx.FiatCode{currency}, OrderBy: api.InvoiceOrderByCreatedAt, Order: sortx.OrderAsc, IncludeDeleted: true, diff --git a/openmeter/billing/stdinvoice.go b/openmeter/billing/stdinvoice.go index 148e3417b7..ed3826d56e 100644 --- a/openmeter/billing/stdinvoice.go +++ b/openmeter/billing/stdinvoice.go @@ -248,7 +248,7 @@ type StandardInvoiceBase struct { Metadata map[string]string `json:"metadata"` - Currency currencyx.Code `json:"currency,omitempty"` + Currency currencyx.FiatCode `json:"currency,omitempty"` Status StandardInvoiceStatus `json:"status"` StatusDetails StandardInvoiceStatusDetails `json:"statusDetail,omitempty"` @@ -743,7 +743,7 @@ type CreateInvoiceAdapterInput struct { Customer customer.Customer Profile Profile Number string - Currency currencyx.Code + Currency currencyx.FiatCode Status StandardInvoiceStatus Metadata map[string]string IssuedAt time.Time @@ -927,7 +927,7 @@ type SimulateInvoiceInput struct { Customer *customer.Customer Number *string - Currency currencyx.Code + Currency currencyx.FiatCode Lines StandardInvoiceLines } @@ -1208,7 +1208,7 @@ type ListStandardInvoicesResponse = pagination.Result[StandardInvoice] type CreateStandardInvoiceFromGatheringLinesInput struct { Customer customer.CustomerID - Currency currencyx.Code + Currency currencyx.FiatCode Description *string Lines GatheringLines diff --git a/openmeter/billing/stdinvoiceline.go b/openmeter/billing/stdinvoiceline.go index 348c3b080c..686d94fa05 100644 --- a/openmeter/billing/stdinvoiceline.go +++ b/openmeter/billing/stdinvoiceline.go @@ -30,8 +30,8 @@ type StandardLineBase struct { ManagedBy InvoiceLineManagedBy `json:"managedBy"` Engine LineEngineType `json:"engine,omitempty"` - InvoiceID string `json:"invoiceID,omitempty"` - Currency currencyx.Code `json:"currency"` + InvoiceID string `json:"invoiceID,omitempty"` + Currency currencyx.FiatCode `json:"currency"` // Lifecycle Period timeutil.ClosedPeriod `json:"period"` @@ -184,16 +184,14 @@ func (i StandardLineBase) GetCreditsApplied() CreditsApplied { return i.CreditsApplied } -func (i StandardLineBase) GetCurrency() currencyx.Code { +func (i StandardLineBase) GetCurrency() currencyx.FiatCode { return i.Currency } func (i StandardLineBase) GetCurrencyCalculator() (currencyx.Currency, error) { - currency, err := currencyx.NewCurrencyBuilder(currencyx.CurrencyTypeFiat). - WithCode(i.Currency). - Build() + currency, err := i.Currency.AsFiatCurrency() if err != nil { - return nil, fmt.Errorf("building fiat currency calculator: %w", err) + return nil, fmt.Errorf("resolving fiat currency calculator: %w", err) } return currency, nil @@ -852,7 +850,7 @@ type NewFlatFeeLineInput struct { Annotations models.Annotations Description *string - Currency currencyx.Code + Currency currencyx.FiatCode ManagedBy InvoiceLineManagedBy diff --git a/openmeter/billing/stdinvoiceline_test.go b/openmeter/billing/stdinvoiceline_test.go index 15c63ead02..4bdb6d8251 100644 --- a/openmeter/billing/stdinvoiceline_test.go +++ b/openmeter/billing/stdinvoiceline_test.go @@ -114,7 +114,7 @@ func validStandardLineForValidation() StandardLine { }, ManagedBy: SystemManagedLine, InvoiceID: "inv_123", - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), Period: timeutil.ClosedPeriod{ From: start, To: start.Add(time.Hour), diff --git a/openmeter/billing/worker/subscriptionsync/service/reconciler/invoiceupdater/invoiceupdate.go b/openmeter/billing/worker/subscriptionsync/service/reconciler/invoiceupdater/invoiceupdate.go index cc4aa82fcb..db4176d1d6 100644 --- a/openmeter/billing/worker/subscriptionsync/service/reconciler/invoiceupdater/invoiceupdate.go +++ b/openmeter/billing/worker/subscriptionsync/service/reconciler/invoiceupdater/invoiceupdate.go @@ -276,7 +276,7 @@ func (u *Updater) provisionUpcomingLines(ctx context.Context, customerID custome return nil } - linesByCurrency := lo.GroupBy(lines, func(l billing.GatheringLine) currencyx.Code { + linesByCurrency := lo.GroupBy(lines, func(l billing.GatheringLine) currencyx.FiatCode { return l.Currency }) diff --git a/openmeter/billing/worker/subscriptionsync/service/targetstate/targetstateitem.go b/openmeter/billing/worker/subscriptionsync/service/targetstate/targetstateitem.go index 522a2b866b..6f7d42fb37 100644 --- a/openmeter/billing/worker/subscriptionsync/service/targetstate/targetstateitem.go +++ b/openmeter/billing/worker/subscriptionsync/service/targetstate/targetstateitem.go @@ -11,6 +11,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/currencies" "github.com/openmeterio/openmeter/openmeter/productcatalog" "github.com/openmeterio/openmeter/openmeter/subscription" + "github.com/openmeterio/openmeter/pkg/currencyx" "github.com/openmeterio/openmeter/pkg/models" "github.com/openmeterio/openmeter/pkg/timeutil" ) @@ -50,6 +51,10 @@ func (r StateItem) GetServicePeriod() timeutil.ClosedPeriod { } func (r StateItem) GetExpectedLine() (*billing.GatheringLine, error) { + if !r.Currency.IsFiat() { + return nil, fmt.Errorf("billing line currency must be fiat: %s", r.Currency.GetCode()) + } + line := billing.GatheringLine{ GatheringLineBase: billing.GatheringLineBase{ ManagedResource: models.NewManagedResource(models.ManagedResourceInput{ @@ -58,7 +63,7 @@ func (r StateItem) GetExpectedLine() (*billing.GatheringLine, error) { Description: r.Spec.RateCard.AsMeta().Description, }), ManagedBy: billing.SubscriptionManagedLine, - Currency: r.Currency.GetCode(), + Currency: currencyx.FiatCode(r.Currency.GetCode()), ChildUniqueReferenceID: &r.UniqueID, TaxConfig: r.Spec.RateCard.AsMeta().TaxConfig, ServicePeriod: r.GetServicePeriod(), diff --git a/openmeter/ent/db/billinggatheringinvoiceline.go b/openmeter/ent/db/billinggatheringinvoiceline.go index d165ecd7de..c60c9cf60e 100644 --- a/openmeter/ent/db/billinggatheringinvoiceline.go +++ b/openmeter/ent/db/billinggatheringinvoiceline.go @@ -46,7 +46,7 @@ type BillingGatheringInvoiceLine struct { // Description holds the value of the "description" field. Description *string `json:"description,omitempty"` // Currency holds the value of the "currency" field. - Currency currencyx.Code `json:"currency,omitempty"` + Currency currencyx.FiatCode `json:"currency,omitempty"` // ServicePeriodStart holds the value of the "service_period_start" field. ServicePeriodStart time.Time `json:"service_period_start,omitempty"` // ServicePeriodEnd holds the value of the "service_period_end" field. @@ -291,7 +291,7 @@ func (_m *BillingGatheringInvoiceLine) assignValues(columns []string, values []a if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field currency", values[i]) } else if value.Valid { - _m.Currency = currencyx.Code(value.String) + _m.Currency = currencyx.FiatCode(value.String) } case billinggatheringinvoiceline.FieldServicePeriodStart: if value, ok := values[i].(*sql.NullTime); !ok { diff --git a/openmeter/ent/db/billinggatheringinvoiceline/where.go b/openmeter/ent/db/billinggatheringinvoiceline/where.go index 241e525f89..44c32ed9e6 100644 --- a/openmeter/ent/db/billinggatheringinvoiceline/where.go +++ b/openmeter/ent/db/billinggatheringinvoiceline/where.go @@ -99,7 +99,7 @@ func Description(v string) predicate.BillingGatheringInvoiceLine { } // Currency applies equality check predicate on the "currency" field. It's identical to CurrencyEQ. -func Currency(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func Currency(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldCurrency, vc)) } @@ -530,19 +530,19 @@ func DescriptionContainsFold(v string) predicate.BillingGatheringInvoiceLine { } // CurrencyEQ applies the EQ predicate on the "currency" field. -func CurrencyEQ(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyEQ(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldCurrency, vc)) } // CurrencyNEQ applies the NEQ predicate on the "currency" field. -func CurrencyNEQ(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyNEQ(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldCurrency, vc)) } // CurrencyIn applies the In predicate on the "currency" field. -func CurrencyIn(vs ...currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyIn(vs ...currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { v := make([]any, len(vs)) for i := range v { v[i] = string(vs[i]) @@ -551,7 +551,7 @@ func CurrencyIn(vs ...currencyx.Code) predicate.BillingGatheringInvoiceLine { } // CurrencyNotIn applies the NotIn predicate on the "currency" field. -func CurrencyNotIn(vs ...currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyNotIn(vs ...currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { v := make([]any, len(vs)) for i := range v { v[i] = string(vs[i]) @@ -560,55 +560,55 @@ func CurrencyNotIn(vs ...currencyx.Code) predicate.BillingGatheringInvoiceLine { } // CurrencyGT applies the GT predicate on the "currency" field. -func CurrencyGT(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyGT(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldCurrency, vc)) } // CurrencyGTE applies the GTE predicate on the "currency" field. -func CurrencyGTE(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyGTE(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldCurrency, vc)) } // CurrencyLT applies the LT predicate on the "currency" field. -func CurrencyLT(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyLT(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldCurrency, vc)) } // CurrencyLTE applies the LTE predicate on the "currency" field. -func CurrencyLTE(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyLTE(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldCurrency, vc)) } // CurrencyContains applies the Contains predicate on the "currency" field. -func CurrencyContains(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyContains(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldCurrency, vc)) } // CurrencyHasPrefix applies the HasPrefix predicate on the "currency" field. -func CurrencyHasPrefix(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyHasPrefix(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldCurrency, vc)) } // CurrencyHasSuffix applies the HasSuffix predicate on the "currency" field. -func CurrencyHasSuffix(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyHasSuffix(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldCurrency, vc)) } // CurrencyEqualFold applies the EqualFold predicate on the "currency" field. -func CurrencyEqualFold(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyEqualFold(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldCurrency, vc)) } // CurrencyContainsFold applies the ContainsFold predicate on the "currency" field. -func CurrencyContainsFold(v currencyx.Code) predicate.BillingGatheringInvoiceLine { +func CurrencyContainsFold(v currencyx.FiatCode) predicate.BillingGatheringInvoiceLine { vc := string(v) return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldCurrency, vc)) } diff --git a/openmeter/ent/db/billinggatheringinvoiceline_create.go b/openmeter/ent/db/billinggatheringinvoiceline_create.go index 64435f6812..e263476464 100644 --- a/openmeter/ent/db/billinggatheringinvoiceline_create.go +++ b/openmeter/ent/db/billinggatheringinvoiceline_create.go @@ -115,7 +115,7 @@ func (_c *BillingGatheringInvoiceLineCreate) SetNillableDescription(v *string) * } // SetCurrency sets the "currency" field. -func (_c *BillingGatheringInvoiceLineCreate) SetCurrency(v currencyx.Code) *BillingGatheringInvoiceLineCreate { +func (_c *BillingGatheringInvoiceLineCreate) SetCurrency(v currencyx.FiatCode) *BillingGatheringInvoiceLineCreate { _c.mutation.SetCurrency(v) return _c } diff --git a/openmeter/ent/db/billinginvoice.go b/openmeter/ent/db/billinginvoice.go index 4f8433abd5..0cc7715b27 100644 --- a/openmeter/ent/db/billinginvoice.go +++ b/openmeter/ent/db/billinginvoice.go @@ -119,7 +119,7 @@ type BillingInvoice struct { // DeletionSource holds the value of the "deletion_source" field. DeletionSource *billing.ChangeSource `json:"deletion_source,omitempty"` // Currency holds the value of the "currency" field. - Currency currencyx.Code `json:"currency,omitempty"` + Currency currencyx.FiatCode `json:"currency,omitempty"` // DueAt holds the value of the "due_at" field. DueAt *time.Time `json:"due_at,omitempty"` // Status holds the value of the "status" field. @@ -648,7 +648,7 @@ func (_m *BillingInvoice) assignValues(columns []string, values []any) error { if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field currency", values[i]) } else if value.Valid { - _m.Currency = currencyx.Code(value.String) + _m.Currency = currencyx.FiatCode(value.String) } case billinginvoice.FieldDueAt: if value, ok := values[i].(*sql.NullTime); !ok { diff --git a/openmeter/ent/db/billinginvoice/where.go b/openmeter/ent/db/billinginvoice/where.go index caf01aa5c9..b1b50065fc 100644 --- a/openmeter/ent/db/billinginvoice/where.go +++ b/openmeter/ent/db/billinginvoice/where.go @@ -282,7 +282,7 @@ func QuantitySnapshotedAt(v time.Time) predicate.BillingInvoice { } // Currency applies equality check predicate on the "currency" field. It's identical to CurrencyEQ. -func Currency(v currencyx.Code) predicate.BillingInvoice { +func Currency(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldEQ(FieldCurrency, vc)) } @@ -3056,19 +3056,19 @@ func DeletionSourceNotNil() predicate.BillingInvoice { } // CurrencyEQ applies the EQ predicate on the "currency" field. -func CurrencyEQ(v currencyx.Code) predicate.BillingInvoice { +func CurrencyEQ(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldEQ(FieldCurrency, vc)) } // CurrencyNEQ applies the NEQ predicate on the "currency" field. -func CurrencyNEQ(v currencyx.Code) predicate.BillingInvoice { +func CurrencyNEQ(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldNEQ(FieldCurrency, vc)) } // CurrencyIn applies the In predicate on the "currency" field. -func CurrencyIn(vs ...currencyx.Code) predicate.BillingInvoice { +func CurrencyIn(vs ...currencyx.FiatCode) predicate.BillingInvoice { v := make([]any, len(vs)) for i := range v { v[i] = string(vs[i]) @@ -3077,7 +3077,7 @@ func CurrencyIn(vs ...currencyx.Code) predicate.BillingInvoice { } // CurrencyNotIn applies the NotIn predicate on the "currency" field. -func CurrencyNotIn(vs ...currencyx.Code) predicate.BillingInvoice { +func CurrencyNotIn(vs ...currencyx.FiatCode) predicate.BillingInvoice { v := make([]any, len(vs)) for i := range v { v[i] = string(vs[i]) @@ -3086,55 +3086,55 @@ func CurrencyNotIn(vs ...currencyx.Code) predicate.BillingInvoice { } // CurrencyGT applies the GT predicate on the "currency" field. -func CurrencyGT(v currencyx.Code) predicate.BillingInvoice { +func CurrencyGT(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldGT(FieldCurrency, vc)) } // CurrencyGTE applies the GTE predicate on the "currency" field. -func CurrencyGTE(v currencyx.Code) predicate.BillingInvoice { +func CurrencyGTE(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldGTE(FieldCurrency, vc)) } // CurrencyLT applies the LT predicate on the "currency" field. -func CurrencyLT(v currencyx.Code) predicate.BillingInvoice { +func CurrencyLT(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldLT(FieldCurrency, vc)) } // CurrencyLTE applies the LTE predicate on the "currency" field. -func CurrencyLTE(v currencyx.Code) predicate.BillingInvoice { +func CurrencyLTE(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldLTE(FieldCurrency, vc)) } // CurrencyContains applies the Contains predicate on the "currency" field. -func CurrencyContains(v currencyx.Code) predicate.BillingInvoice { +func CurrencyContains(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldContains(FieldCurrency, vc)) } // CurrencyHasPrefix applies the HasPrefix predicate on the "currency" field. -func CurrencyHasPrefix(v currencyx.Code) predicate.BillingInvoice { +func CurrencyHasPrefix(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldHasPrefix(FieldCurrency, vc)) } // CurrencyHasSuffix applies the HasSuffix predicate on the "currency" field. -func CurrencyHasSuffix(v currencyx.Code) predicate.BillingInvoice { +func CurrencyHasSuffix(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldHasSuffix(FieldCurrency, vc)) } // CurrencyEqualFold applies the EqualFold predicate on the "currency" field. -func CurrencyEqualFold(v currencyx.Code) predicate.BillingInvoice { +func CurrencyEqualFold(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldEqualFold(FieldCurrency, vc)) } // CurrencyContainsFold applies the ContainsFold predicate on the "currency" field. -func CurrencyContainsFold(v currencyx.Code) predicate.BillingInvoice { +func CurrencyContainsFold(v currencyx.FiatCode) predicate.BillingInvoice { vc := string(v) return predicate.BillingInvoice(sql.FieldContainsFold(FieldCurrency, vc)) } diff --git a/openmeter/ent/db/billinginvoice_create.go b/openmeter/ent/db/billinginvoice_create.go index 257f44a82d..6a33745727 100644 --- a/openmeter/ent/db/billinginvoice_create.go +++ b/openmeter/ent/db/billinginvoice_create.go @@ -546,7 +546,7 @@ func (_c *BillingInvoiceCreate) SetNillableDeletionSource(v *billing.ChangeSourc } // SetCurrency sets the "currency" field. -func (_c *BillingInvoiceCreate) SetCurrency(v currencyx.Code) *BillingInvoiceCreate { +func (_c *BillingInvoiceCreate) SetCurrency(v currencyx.FiatCode) *BillingInvoiceCreate { _c.mutation.SetCurrency(v) return _c } diff --git a/openmeter/ent/db/billinginvoiceline.go b/openmeter/ent/db/billinginvoiceline.go index 7c25f85850..c56ce3c91f 100644 --- a/openmeter/ent/db/billinginvoiceline.go +++ b/openmeter/ent/db/billinginvoiceline.go @@ -54,7 +54,7 @@ type BillingInvoiceLine struct { // Description holds the value of the "description" field. Description *string `json:"description,omitempty"` // Currency holds the value of the "currency" field. - Currency currencyx.Code `json:"currency,omitempty"` + Currency currencyx.FiatCode `json:"currency,omitempty"` // TaxConfig holds the value of the "tax_config" field. TaxConfig billing.TaxConfig `json:"tax_config,omitempty"` // TaxCodeID holds the value of the "tax_code_id" field. @@ -475,7 +475,7 @@ func (_m *BillingInvoiceLine) assignValues(columns []string, values []any) error if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field currency", values[i]) } else if value.Valid { - _m.Currency = currencyx.Code(value.String) + _m.Currency = currencyx.FiatCode(value.String) } case billinginvoiceline.FieldTaxConfig: if value, ok := values[i].(*[]byte); !ok { diff --git a/openmeter/ent/db/billinginvoiceline/where.go b/openmeter/ent/db/billinginvoiceline/where.go index fa998b8cca..80f267179a 100644 --- a/openmeter/ent/db/billinginvoiceline/where.go +++ b/openmeter/ent/db/billinginvoiceline/where.go @@ -100,7 +100,7 @@ func Description(v string) predicate.BillingInvoiceLine { } // Currency applies equality check predicate on the "currency" field. It's identical to CurrencyEQ. -func Currency(v currencyx.Code) predicate.BillingInvoiceLine { +func Currency(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldEQ(FieldCurrency, vc)) } @@ -586,19 +586,19 @@ func DescriptionContainsFold(v string) predicate.BillingInvoiceLine { } // CurrencyEQ applies the EQ predicate on the "currency" field. -func CurrencyEQ(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyEQ(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldEQ(FieldCurrency, vc)) } // CurrencyNEQ applies the NEQ predicate on the "currency" field. -func CurrencyNEQ(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyNEQ(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldNEQ(FieldCurrency, vc)) } // CurrencyIn applies the In predicate on the "currency" field. -func CurrencyIn(vs ...currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyIn(vs ...currencyx.FiatCode) predicate.BillingInvoiceLine { v := make([]any, len(vs)) for i := range v { v[i] = string(vs[i]) @@ -607,7 +607,7 @@ func CurrencyIn(vs ...currencyx.Code) predicate.BillingInvoiceLine { } // CurrencyNotIn applies the NotIn predicate on the "currency" field. -func CurrencyNotIn(vs ...currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyNotIn(vs ...currencyx.FiatCode) predicate.BillingInvoiceLine { v := make([]any, len(vs)) for i := range v { v[i] = string(vs[i]) @@ -616,55 +616,55 @@ func CurrencyNotIn(vs ...currencyx.Code) predicate.BillingInvoiceLine { } // CurrencyGT applies the GT predicate on the "currency" field. -func CurrencyGT(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyGT(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldGT(FieldCurrency, vc)) } // CurrencyGTE applies the GTE predicate on the "currency" field. -func CurrencyGTE(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyGTE(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldGTE(FieldCurrency, vc)) } // CurrencyLT applies the LT predicate on the "currency" field. -func CurrencyLT(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyLT(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldLT(FieldCurrency, vc)) } // CurrencyLTE applies the LTE predicate on the "currency" field. -func CurrencyLTE(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyLTE(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldLTE(FieldCurrency, vc)) } // CurrencyContains applies the Contains predicate on the "currency" field. -func CurrencyContains(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyContains(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldContains(FieldCurrency, vc)) } // CurrencyHasPrefix applies the HasPrefix predicate on the "currency" field. -func CurrencyHasPrefix(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyHasPrefix(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldHasPrefix(FieldCurrency, vc)) } // CurrencyHasSuffix applies the HasSuffix predicate on the "currency" field. -func CurrencyHasSuffix(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyHasSuffix(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldHasSuffix(FieldCurrency, vc)) } // CurrencyEqualFold applies the EqualFold predicate on the "currency" field. -func CurrencyEqualFold(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyEqualFold(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldEqualFold(FieldCurrency, vc)) } // CurrencyContainsFold applies the ContainsFold predicate on the "currency" field. -func CurrencyContainsFold(v currencyx.Code) predicate.BillingInvoiceLine { +func CurrencyContainsFold(v currencyx.FiatCode) predicate.BillingInvoiceLine { vc := string(v) return predicate.BillingInvoiceLine(sql.FieldContainsFold(FieldCurrency, vc)) } diff --git a/openmeter/ent/db/billinginvoiceline_create.go b/openmeter/ent/db/billinginvoiceline_create.go index c61e088024..738311ded5 100644 --- a/openmeter/ent/db/billinginvoiceline_create.go +++ b/openmeter/ent/db/billinginvoiceline_create.go @@ -127,7 +127,7 @@ func (_c *BillingInvoiceLineCreate) SetNillableDescription(v *string) *BillingIn } // SetCurrency sets the "currency" field. -func (_c *BillingInvoiceLineCreate) SetCurrency(v currencyx.Code) *BillingInvoiceLineCreate { +func (_c *BillingInvoiceLineCreate) SetCurrency(v currencyx.FiatCode) *BillingInvoiceLineCreate { _c.mutation.SetCurrency(v) return _c } diff --git a/openmeter/ent/db/billinginvoicesplitlinegroup.go b/openmeter/ent/db/billinginvoicesplitlinegroup.go index 13c41fa499..b8e20f794e 100644 --- a/openmeter/ent/db/billinginvoicesplitlinegroup.go +++ b/openmeter/ent/db/billinginvoicesplitlinegroup.go @@ -40,7 +40,7 @@ type BillingInvoiceSplitLineGroup struct { // Description holds the value of the "description" field. Description *string `json:"description,omitempty"` // Currency holds the value of the "currency" field. - Currency currencyx.Code `json:"currency,omitempty"` + Currency currencyx.FiatCode `json:"currency,omitempty"` // ServicePeriodStart holds the value of the "service_period_start" field. ServicePeriodStart time.Time `json:"service_period_start,omitempty"` // ServicePeriodEnd holds the value of the "service_period_end" field. @@ -238,7 +238,7 @@ func (_m *BillingInvoiceSplitLineGroup) assignValues(columns []string, values [] if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field currency", values[i]) } else if value.Valid { - _m.Currency = currencyx.Code(value.String) + _m.Currency = currencyx.FiatCode(value.String) } case billinginvoicesplitlinegroup.FieldServicePeriodStart: if value, ok := values[i].(*sql.NullTime); !ok { diff --git a/openmeter/ent/db/billinginvoicesplitlinegroup/where.go b/openmeter/ent/db/billinginvoicesplitlinegroup/where.go index a02dc27b27..08ba26c2ac 100644 --- a/openmeter/ent/db/billinginvoicesplitlinegroup/where.go +++ b/openmeter/ent/db/billinginvoicesplitlinegroup/where.go @@ -97,7 +97,7 @@ func Description(v string) predicate.BillingInvoiceSplitLineGroup { } // Currency applies equality check predicate on the "currency" field. It's identical to CurrencyEQ. -func Currency(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func Currency(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldEQ(FieldCurrency, vc)) } @@ -498,19 +498,19 @@ func DescriptionContainsFold(v string) predicate.BillingInvoiceSplitLineGroup { } // CurrencyEQ applies the EQ predicate on the "currency" field. -func CurrencyEQ(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyEQ(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldEQ(FieldCurrency, vc)) } // CurrencyNEQ applies the NEQ predicate on the "currency" field. -func CurrencyNEQ(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyNEQ(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldNEQ(FieldCurrency, vc)) } // CurrencyIn applies the In predicate on the "currency" field. -func CurrencyIn(vs ...currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyIn(vs ...currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { v := make([]any, len(vs)) for i := range v { v[i] = string(vs[i]) @@ -519,7 +519,7 @@ func CurrencyIn(vs ...currencyx.Code) predicate.BillingInvoiceSplitLineGroup { } // CurrencyNotIn applies the NotIn predicate on the "currency" field. -func CurrencyNotIn(vs ...currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyNotIn(vs ...currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { v := make([]any, len(vs)) for i := range v { v[i] = string(vs[i]) @@ -528,55 +528,55 @@ func CurrencyNotIn(vs ...currencyx.Code) predicate.BillingInvoiceSplitLineGroup } // CurrencyGT applies the GT predicate on the "currency" field. -func CurrencyGT(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyGT(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldGT(FieldCurrency, vc)) } // CurrencyGTE applies the GTE predicate on the "currency" field. -func CurrencyGTE(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyGTE(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldGTE(FieldCurrency, vc)) } // CurrencyLT applies the LT predicate on the "currency" field. -func CurrencyLT(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyLT(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldLT(FieldCurrency, vc)) } // CurrencyLTE applies the LTE predicate on the "currency" field. -func CurrencyLTE(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyLTE(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldLTE(FieldCurrency, vc)) } // CurrencyContains applies the Contains predicate on the "currency" field. -func CurrencyContains(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyContains(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldContains(FieldCurrency, vc)) } // CurrencyHasPrefix applies the HasPrefix predicate on the "currency" field. -func CurrencyHasPrefix(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyHasPrefix(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldHasPrefix(FieldCurrency, vc)) } // CurrencyHasSuffix applies the HasSuffix predicate on the "currency" field. -func CurrencyHasSuffix(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyHasSuffix(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldHasSuffix(FieldCurrency, vc)) } // CurrencyEqualFold applies the EqualFold predicate on the "currency" field. -func CurrencyEqualFold(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyEqualFold(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldEqualFold(FieldCurrency, vc)) } // CurrencyContainsFold applies the ContainsFold predicate on the "currency" field. -func CurrencyContainsFold(v currencyx.Code) predicate.BillingInvoiceSplitLineGroup { +func CurrencyContainsFold(v currencyx.FiatCode) predicate.BillingInvoiceSplitLineGroup { vc := string(v) return predicate.BillingInvoiceSplitLineGroup(sql.FieldContainsFold(FieldCurrency, vc)) } diff --git a/openmeter/ent/db/billinginvoicesplitlinegroup_create.go b/openmeter/ent/db/billinginvoicesplitlinegroup_create.go index 6a3bbdcbe3..c11435b51a 100644 --- a/openmeter/ent/db/billinginvoicesplitlinegroup_create.go +++ b/openmeter/ent/db/billinginvoicesplitlinegroup_create.go @@ -107,7 +107,7 @@ func (_c *BillingInvoiceSplitLineGroupCreate) SetNillableDescription(v *string) } // SetCurrency sets the "currency" field. -func (_c *BillingInvoiceSplitLineGroupCreate) SetCurrency(v currencyx.Code) *BillingInvoiceSplitLineGroupCreate { +func (_c *BillingInvoiceSplitLineGroupCreate) SetCurrency(v currencyx.FiatCode) *BillingInvoiceSplitLineGroupCreate { _c.mutation.SetCurrency(v) return _c } diff --git a/openmeter/ent/db/entmixinaccessor.go b/openmeter/ent/db/entmixinaccessor.go index 98635780eb..6bee7e2c0b 100644 --- a/openmeter/ent/db/entmixinaccessor.go +++ b/openmeter/ent/db/entmixinaccessor.go @@ -310,7 +310,7 @@ func (e *BillingGatheringInvoiceLine) GetDescription() *string { return e.Description } -func (e *BillingGatheringInvoiceLine) GetCurrency() currencyx.Code { +func (e *BillingGatheringInvoiceLine) GetCurrency() currencyx.FiatCode { return e.Currency } @@ -546,7 +546,7 @@ func (e *BillingInvoiceLine) GetDescription() *string { return e.Description } -func (e *BillingInvoiceLine) GetCurrency() currencyx.Code { +func (e *BillingInvoiceLine) GetCurrency() currencyx.FiatCode { return e.Currency } diff --git a/openmeter/ent/db/mutation.go b/openmeter/ent/db/mutation.go index 71c1518831..96dc233295 100644 --- a/openmeter/ent/db/mutation.go +++ b/openmeter/ent/db/mutation.go @@ -11980,7 +11980,7 @@ type BillingGatheringInvoiceLineMutation struct { deleted_at *time.Time name *string description *string - currency *currencyx.Code + currency *currencyx.FiatCode service_period_start *time.Time service_period_end *time.Time tax_config *billing.TaxConfig @@ -12461,12 +12461,12 @@ func (m *BillingGatheringInvoiceLineMutation) ResetDescription() { } // SetCurrency sets the "currency" field. -func (m *BillingGatheringInvoiceLineMutation) SetCurrency(c currencyx.Code) { - m.currency = &c +func (m *BillingGatheringInvoiceLineMutation) SetCurrency(cc currencyx.FiatCode) { + m.currency = &cc } // Currency returns the value of the "currency" field in the mutation. -func (m *BillingGatheringInvoiceLineMutation) Currency() (r currencyx.Code, exists bool) { +func (m *BillingGatheringInvoiceLineMutation) Currency() (r currencyx.FiatCode, exists bool) { v := m.currency if v == nil { return @@ -12477,7 +12477,7 @@ func (m *BillingGatheringInvoiceLineMutation) Currency() (r currencyx.Code, exis // OldCurrency returns the old "currency" field's value of the BillingGatheringInvoiceLine entity. // If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *BillingGatheringInvoiceLineMutation) OldCurrency(ctx context.Context) (v currencyx.Code, err error) { +func (m *BillingGatheringInvoiceLineMutation) OldCurrency(ctx context.Context) (v currencyx.FiatCode, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCurrency is only allowed on UpdateOne operations") } @@ -14007,7 +14007,7 @@ func (m *BillingGatheringInvoiceLineMutation) SetField(name string, value ent.Va m.SetDescription(v) return nil case billinggatheringinvoiceline.FieldCurrency: - v, ok := value.(currencyx.Code) + v, ok := value.(currencyx.FiatCode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -14656,7 +14656,7 @@ type BillingInvoiceMutation struct { draft_until *time.Time quantity_snapshoted_at *time.Time deletion_source *billing.ChangeSource - currency *currencyx.Code + currency *currencyx.FiatCode due_at *time.Time status *billing.StandardInvoiceStatus status_details_cache *billing.StandardInvoiceStatusDetails @@ -16840,12 +16840,12 @@ func (m *BillingInvoiceMutation) ResetDeletionSource() { } // SetCurrency sets the "currency" field. -func (m *BillingInvoiceMutation) SetCurrency(c currencyx.Code) { - m.currency = &c +func (m *BillingInvoiceMutation) SetCurrency(cc currencyx.FiatCode) { + m.currency = &cc } // Currency returns the value of the "currency" field in the mutation. -func (m *BillingInvoiceMutation) Currency() (r currencyx.Code, exists bool) { +func (m *BillingInvoiceMutation) Currency() (r currencyx.FiatCode, exists bool) { v := m.currency if v == nil { return @@ -16856,7 +16856,7 @@ func (m *BillingInvoiceMutation) Currency() (r currencyx.Code, exists bool) { // OldCurrency returns the old "currency" field's value of the BillingInvoice entity. // If the BillingInvoice object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *BillingInvoiceMutation) OldCurrency(ctx context.Context) (v currencyx.Code, err error) { +func (m *BillingInvoiceMutation) OldCurrency(ctx context.Context) (v currencyx.FiatCode, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCurrency is only allowed on UpdateOne operations") } @@ -18714,7 +18714,7 @@ func (m *BillingInvoiceMutation) SetField(name string, value ent.Value) error { m.SetDeletionSource(v) return nil case billinginvoice.FieldCurrency: - v, ok := value.(currencyx.Code) + v, ok := value.(currencyx.FiatCode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -20205,7 +20205,7 @@ type BillingInvoiceLineMutation struct { deleted_at *time.Time name *string description *string - currency *currencyx.Code + currency *currencyx.FiatCode tax_config *billing.TaxConfig tax_behavior *productcatalog.TaxBehavior amount *alpacadecimal.Decimal @@ -20725,12 +20725,12 @@ func (m *BillingInvoiceLineMutation) ResetDescription() { } // SetCurrency sets the "currency" field. -func (m *BillingInvoiceLineMutation) SetCurrency(c currencyx.Code) { - m.currency = &c +func (m *BillingInvoiceLineMutation) SetCurrency(cc currencyx.FiatCode) { + m.currency = &cc } // Currency returns the value of the "currency" field in the mutation. -func (m *BillingInvoiceLineMutation) Currency() (r currencyx.Code, exists bool) { +func (m *BillingInvoiceLineMutation) Currency() (r currencyx.FiatCode, exists bool) { v := m.currency if v == nil { return @@ -20741,7 +20741,7 @@ func (m *BillingInvoiceLineMutation) Currency() (r currencyx.Code, exists bool) // OldCurrency returns the old "currency" field's value of the BillingInvoiceLine entity. // If the BillingInvoiceLine object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *BillingInvoiceLineMutation) OldCurrency(ctx context.Context) (v currencyx.Code, err error) { +func (m *BillingInvoiceLineMutation) OldCurrency(ctx context.Context) (v currencyx.FiatCode, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCurrency is only allowed on UpdateOne operations") } @@ -23314,7 +23314,7 @@ func (m *BillingInvoiceLineMutation) SetField(name string, value ent.Value) erro m.SetDescription(v) return nil case billinginvoiceline.FieldCurrency: - v, ok := value.(currencyx.Code) + v, ok := value.(currencyx.FiatCode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -26532,7 +26532,7 @@ type BillingInvoiceSplitLineGroupMutation struct { deleted_at *time.Time name *string description *string - currency *currencyx.Code + currency *currencyx.FiatCode service_period_start *time.Time service_period_end *time.Time unique_reference_id *string @@ -26957,12 +26957,12 @@ func (m *BillingInvoiceSplitLineGroupMutation) ResetDescription() { } // SetCurrency sets the "currency" field. -func (m *BillingInvoiceSplitLineGroupMutation) SetCurrency(c currencyx.Code) { - m.currency = &c +func (m *BillingInvoiceSplitLineGroupMutation) SetCurrency(cc currencyx.FiatCode) { + m.currency = &cc } // Currency returns the value of the "currency" field in the mutation. -func (m *BillingInvoiceSplitLineGroupMutation) Currency() (r currencyx.Code, exists bool) { +func (m *BillingInvoiceSplitLineGroupMutation) Currency() (r currencyx.FiatCode, exists bool) { v := m.currency if v == nil { return @@ -26973,7 +26973,7 @@ func (m *BillingInvoiceSplitLineGroupMutation) Currency() (r currencyx.Code, exi // OldCurrency returns the old "currency" field's value of the BillingInvoiceSplitLineGroup entity. // If the BillingInvoiceSplitLineGroup object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *BillingInvoiceSplitLineGroupMutation) OldCurrency(ctx context.Context) (v currencyx.Code, err error) { +func (m *BillingInvoiceSplitLineGroupMutation) OldCurrency(ctx context.Context) (v currencyx.FiatCode, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCurrency is only allowed on UpdateOne operations") } @@ -28008,7 +28008,7 @@ func (m *BillingInvoiceSplitLineGroupMutation) SetField(name string, value ent.V m.SetDescription(v) return nil case billinginvoicesplitlinegroup.FieldCurrency: - v, ok := value.(currencyx.Code) + v, ok := value.(currencyx.FiatCode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } diff --git a/openmeter/ent/schema/billing.go b/openmeter/ent/schema/billing.go index 6f4bb2d3c2..6a42e47c1d 100644 --- a/openmeter/ent/schema/billing.go +++ b/openmeter/ent/schema/billing.go @@ -290,7 +290,7 @@ type InvoiceLineBaseMixin struct { func (InvoiceLineBaseMixin) Fields() []ent.Field { return []ent.Field{ field.String("currency"). - GoType(currencyx.Code("")). + GoType(currencyx.FiatCode("")). NotEmpty(). Immutable(). SchemaType(map[string]string{ @@ -326,7 +326,7 @@ func (StandardInvoiceLineIntentMixin) Annotations() []schema.Annotation { func (StandardInvoiceLineIntentMixin) Fields() []ent.Field { return []ent.Field{ field.String("currency"). - GoType(currencyx.Code("")). + GoType(currencyx.FiatCode("")). NotEmpty(). Immutable(). SchemaType(map[string]string{ @@ -810,7 +810,7 @@ func (BillingInvoiceSplitLineGroup) Mixin() []ent.Mixin { func (BillingInvoiceSplitLineGroup) Fields() []ent.Field { return []ent.Field{ field.String("currency"). - GoType(currencyx.Code("")). + GoType(currencyx.FiatCode("")). NotEmpty(). Immutable(). SchemaType(map[string]string{ @@ -1244,7 +1244,7 @@ func (BillingInvoice) Fields() []ent.Field { Nillable(), field.String("currency"). - GoType(currencyx.Code("")). + GoType(currencyx.FiatCode("")). NotEmpty(). Immutable(). SchemaType(map[string]string{ diff --git a/openmeter/notification/internal/rule.go b/openmeter/notification/internal/rule.go index 83fa89f12d..3cc3530f34 100644 --- a/openmeter/notification/internal/rule.go +++ b/openmeter/notification/internal/rule.go @@ -202,7 +202,7 @@ func (t *TestEventGenerator) newTestInvoicePayload(ctx context.Context, namespac }, Number: lo.ToPtr("TEST-INV-1"), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: billing.NewStandardInvoiceLines([]*billing.StandardLine{ billing.NewFlatFeeLine(billing.NewFlatFeeLineInput{ Namespace: namespace, diff --git a/test/app/custominvoicing/invocing_test.go b/test/app/custominvoicing/invocing_test.go index 6eee125ec0..257ee5aea1 100644 --- a/test/app/custominvoicing/invocing_test.go +++ b/test/app/custominvoicing/invocing_test.go @@ -133,7 +133,7 @@ func (s *CustomInvoicingTestSuite) TestInvoicingFlowHooksEnabled() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.HUF), + Currency: currencyx.FiatCode(currency.HUF), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Period: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, @@ -298,7 +298,7 @@ func (s *CustomInvoicingTestSuite) TestInvoicingFlowPaymentStatusOnly() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.HUF), + Currency: currencyx.FiatCode(currency.HUF), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Period: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, diff --git a/test/app/stripe/invoice_credits_test.go b/test/app/stripe/invoice_credits_test.go index c5c9d1eae0..f498874396 100644 --- a/test/app/stripe/invoice_credits_test.go +++ b/test/app/stripe/invoice_credits_test.go @@ -305,7 +305,7 @@ func (s *StripeInvoiceTestSuite) expectStripeInvoiceCreate(appID app.AppID, cust InvoiceID: invoiceID, AutomaticTaxEnabled: true, CollectionMethod: billing.CollectionMethodChargeAutomatically, - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), StripeCustomerID: stripeCustomerID, }). Once(). diff --git a/test/app/stripe/invoice_test.go b/test/app/stripe/invoice_test.go index 6e398d280c..96f5fd8679 100644 --- a/test/app/stripe/invoice_test.go +++ b/test/app/stripe/invoice_test.go @@ -393,7 +393,7 @@ func (s *StripeInvoiceTestSuite) TestComplexInvoice() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { // Covered case: Discount caused by maximum amount @@ -1241,7 +1241,7 @@ func (s *StripeInvoiceTestSuite) TestEmptyInvoiceGenerationZeroUsage() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -1424,7 +1424,7 @@ func (s *StripeInvoiceTestSuite) TestSendInvoice() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Period: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, diff --git a/test/billing/adapter_test.go b/test/billing/adapter_test.go index 2babf8c5c0..56bbfd61f3 100644 --- a/test/billing/adapter_test.go +++ b/test/billing/adapter_test.go @@ -69,7 +69,7 @@ func (s *BillingAdapterTestSuite) setupInvoice(ctx context.Context, ns string) * Customer: *customerEntity, Number: "INV-123", - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Status: billing.StandardInvoiceStatusGathering, Profile: *profile, @@ -863,7 +863,7 @@ func (s *BillingAdapterTestSuite) TestHardDeleteGatheringInvoiceLines() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -874,7 +874,7 @@ func (s *BillingAdapterTestSuite) TestHardDeleteGatheringInvoiceLines() { ServicePeriod: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, InvoiceAt: periodEnd, ManagedBy: billing.ManuallyManagedLine, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), RateCardDiscounts: billing.Discounts{ Percentage: &billing.PercentageDiscount{ PercentageDiscount: productcatalog.PercentageDiscount{ @@ -897,7 +897,7 @@ func (s *BillingAdapterTestSuite) TestHardDeleteGatheringInvoiceLines() { ServicePeriod: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, InvoiceAt: periodEnd, ManagedBy: billing.ManuallyManagedLine, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), RateCardDiscounts: billing.Discounts{ Percentage: &billing.PercentageDiscount{ PercentageDiscount: productcatalog.PercentageDiscount{ @@ -991,7 +991,7 @@ func (s *BillingAdapterTestSuite) TestHardDeleteGatheringInvoiceLinesNegative() createdPendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -1002,7 +1002,7 @@ func (s *BillingAdapterTestSuite) TestHardDeleteGatheringInvoiceLinesNegative() ServicePeriod: timeutil.ClosedPeriod{From: line1PeriodStart, To: line1PeriodEnd}, InvoiceAt: line1PeriodStart, ManagedBy: billing.ManuallyManagedLine, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), RateCardDiscounts: billing.Discounts{ Percentage: &billing.PercentageDiscount{ PercentageDiscount: productcatalog.PercentageDiscount{ @@ -1026,7 +1026,7 @@ func (s *BillingAdapterTestSuite) TestHardDeleteGatheringInvoiceLinesNegative() ServicePeriod: timeutil.ClosedPeriod{From: line2PeriodStart, To: line2PeriodEnd}, InvoiceAt: line2PeriodStart, ManagedBy: billing.ManuallyManagedLine, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), RateCardDiscounts: billing.Discounts{ Percentage: &billing.PercentageDiscount{ PercentageDiscount: productcatalog.PercentageDiscount{ diff --git a/test/billing/collection_test.go b/test/billing/collection_test.go index 4e492c22da..0e7df670e0 100644 --- a/test/billing/collection_test.go +++ b/test/billing/collection_test.go @@ -99,7 +99,7 @@ func (s *CollectionTestSuite) TestUncollectableCollection() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -163,7 +163,7 @@ func (s *CollectionTestSuite) TestGatheringLineUnitConfigSnapshotRoundTrip() { created, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: res.customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -229,7 +229,7 @@ func (s *CollectionTestSuite) TestCollectionFlow() { s.Run("validate collection_at calculation", func() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -428,7 +428,7 @@ func (s *CollectionTestSuite) TestCollectionFlowWithFlatFeeOnly() { // Given pendingLineResult, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{tc.line}, }) s.NoError(err) @@ -482,7 +482,7 @@ func (s *CollectionTestSuite) TestCollectionFlowWithFlatFeeEditing() { pendingLineResult, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -531,7 +531,7 @@ func (s *CollectionTestSuite) TestCollectionFlowWithFlatFeeEditing() { invoice.Lines.Append( billing.NewFlatFeeLine(billing.NewFlatFeeLineInput{ Namespace: namespace, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), InvoiceID: invoice.ID, Period: linePeriod, InvoiceAt: linePeriod.To, @@ -598,7 +598,7 @@ func (s *CollectionTestSuite) TestAnchoredAlignment_StandardInvoiceUsesLateEvent periodEnd := now.Add(12 * time.Hour) _, err = s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -697,7 +697,7 @@ func (s *CollectionTestSuite) TestAnchoredAlignment_AutomaticCollectionWaitsForA periodEnd := now.Add(12 * time.Hour) _, err = s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -760,7 +760,7 @@ func (s *CollectionTestSuite) TestAnchoredAlignment_StandardInvoiceWaitsForLateE periodEnd := lo.Must(time.Parse(time.RFC3339, "2025-06-15T12:00:00Z")) _, err = s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -800,7 +800,7 @@ func (s *CollectionTestSuite) TestAnchoredAlignment_StandardInvoiceWaitsForLateE inv, err := s.BillingService.CreateStandardInvoiceFromGatheringLines(ctx, billing.CreateStandardInvoiceFromGatheringLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: invoices.Items[0].Lines.OrEmpty(), }) s.NoError(err) @@ -839,7 +839,7 @@ func (s *CollectionTestSuite) TestCollectionFlowWithUBPEditingExtendingCollectio pendingLineResult, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -887,7 +887,7 @@ func (s *CollectionTestSuite) TestCollectionFlowWithUBPEditingExtendingCollectio Namespace: namespace, Name: "UBP - unit - new", }), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), InvoiceID: invoice.ID, Period: newLinePeriod, InvoiceAt: newLinePeriod.To, diff --git a/test/billing/discount_test.go b/test/billing/discount_test.go index 6b4d7dff1d..cdf7a13f3d 100644 --- a/test/billing/discount_test.go +++ b/test/billing/discount_test.go @@ -91,7 +91,7 @@ func (s *DiscountsTestSuite) TestCorrelationIDHandling() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -105,7 +105,7 @@ func (s *DiscountsTestSuite) TestCorrelationIDHandling() { ManagedBy: billing.ManuallyManagedLine, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), RateCardDiscounts: billing.Discounts{ Percentage: &billing.PercentageDiscount{ PercentageDiscount: productcatalog.PercentageDiscount{ @@ -221,7 +221,7 @@ func (s *DiscountsTestSuite) TestFlatPriceUsageDiscountIsNotPersisted() { // - the pending line is created _, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -344,7 +344,7 @@ func (s *DiscountsTestSuite) TestUnitDiscountProgressiveBilling() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -358,7 +358,7 @@ func (s *DiscountsTestSuite) TestUnitDiscountProgressiveBilling() { ManagedBy: billing.ManuallyManagedLine, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), RateCardDiscounts: billing.Discounts{ Usage: &billing.UsageDiscount{ UsageDiscount: productcatalog.UsageDiscount{ diff --git a/test/billing/invoice_test.go b/test/billing/invoice_test.go index e0f23fe6ce..a417ed9f45 100644 --- a/test/billing/invoice_test.go +++ b/test/billing/invoice_test.go @@ -134,7 +134,7 @@ func (s *InvoicingTestSuite) TestPendingLineCreation() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Namespace: namespace, @@ -168,7 +168,7 @@ func (s *InvoicingTestSuite) TestPendingLineCreation() { res, err = s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.HUF), + Currency: currencyx.FiatCode(currency.HUF), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Period: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, @@ -226,7 +226,7 @@ func (s *InvoicingTestSuite) TestPendingLineCreation() { Namespaces: []string{namespace}, Customers: []string{customerEntity.ID}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, - Currencies: []currencyx.Code{currencyx.Code(currency.USD)}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(currency.USD)}, }) require.NoError(s.T(), err) require.Len(s.T(), usdInvoices.Items, 1) @@ -250,7 +250,7 @@ func (s *InvoicingTestSuite) TestPendingLineCreation() { ManagedBy: billing.ManuallyManagedLine, Engine: billing.LineEngineTypeInvoice, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Metadata: map[string]string{ "key": "value", @@ -278,7 +278,7 @@ func (s *InvoicingTestSuite) TestPendingLineCreation() { }), Number: "GATHER-TECU-USD-1", - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), ServicePeriod: timeutil.ClosedPeriod{From: periodStart.Truncate(time.Second), To: periodEnd.Truncate(time.Second)}, // The customer snapshot @@ -322,7 +322,7 @@ func (s *InvoicingTestSuite) TestPendingLineCreation() { Namespaces: []string{namespace}, Customers: []string{customerEntity.ID}, Expand: billing.GatheringInvoiceExpandAll, - Currencies: []currencyx.Code{currencyx.Code(currency.HUF)}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(currency.HUF)}, }) require.NoError(s.T(), err) require.Len(s.T(), hufInvoices.Items, 1) @@ -376,7 +376,7 @@ func (s *InvoicingTestSuite) TestPendingLineCreation() { invoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{namespace}, Customers: []string{customerEntity.ID}, - Currencies: []currencyx.Code{currencyx.Code(currency.USD)}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(currency.USD)}, }) require.NoError(s.T(), err) require.Len(s.T(), invoices.Items, 1) @@ -423,7 +423,7 @@ func (s *InvoicingTestSuite) TestCreateInvoice() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Namespace: namespace, @@ -603,7 +603,7 @@ func (s *InvoicingTestSuite) TestCreateInvoice() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Name: "Test item1", @@ -660,7 +660,7 @@ func (s *InvoicingTestSuite) TestListGatheringInvoices_CollectionAtFilterExclude now := time.Now().UTC().Truncate(time.Second) res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine( billing.NewFlatFeeLineInput{ @@ -1588,7 +1588,7 @@ func (s *InvoicingTestSuite) TestUBPProgressiveInvoicing() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -2459,7 +2459,7 @@ func (s *InvoicingTestSuite) TestUBPGraduatingFlatFeeTier1() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -2775,7 +2775,7 @@ func (s *InvoicingTestSuite) TestUBPNonProgressiveInvoicing() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -3275,7 +3275,7 @@ func (s *InvoicingTestSuite) TestGatheringInvoiceRecalculation() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -3442,7 +3442,7 @@ func (s *InvoicingTestSuite) TestEmptyInvoiceGenerationZeroUsage() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -3561,7 +3561,7 @@ func (s *InvoicingTestSuite) TestEmptyInvoiceGenerationZeroPrice() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -3743,7 +3743,7 @@ func (s *InvoicingTestSuite) TestProgressiveBillLate() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -3835,7 +3835,7 @@ func (s *InvoicingTestSuite) TestPartialInvoiceLinesOptions() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -3942,7 +3942,7 @@ func (s *InvoicingTestSuite) TestSortLines() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -4068,7 +4068,7 @@ func (s *InvoicingTestSuite) TestGatheringInvoicePeriodPersisting() { // When pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Period: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, @@ -4100,7 +4100,7 @@ func (s *InvoicingTestSuite) TestGatheringInvoicePeriodPersisting() { pendingLines, err = s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Period: timeutil.ClosedPeriod{From: newPeriodStart, To: newPeriodEnd}, @@ -4167,7 +4167,7 @@ func (s *InvoicingTestSuite) TestDeleteGatheringInvoiceViaService() { // - a gathering invoice with two active flat-fee lines pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Namespace: namespace, @@ -4256,7 +4256,7 @@ func (s *InvoicingTestSuite) TestCreatePendingInvoiceLinesForDeletedCustomers() pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Period: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, @@ -4292,7 +4292,7 @@ func (s *InvoicingTestSuite) TestCreatePendingInvoiceLinesForDeletedCustomers() pendingLines, err = s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Period: timeutil.ClosedPeriod{From: clock.Now(), To: clock.Now().Add(time.Hour * 24)}, @@ -4397,7 +4397,7 @@ func (s *InvoicingTestSuite) TestSnapshotQuantityInvalidDatabaseState() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -4490,7 +4490,7 @@ func (s *InvoicingTestSuite) TestGatheringInvoiceEmulation() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Namespace: namespace, @@ -4575,7 +4575,7 @@ func (s *InvoicingTestSuite) TestUpdateInvoice() { s.Run("given a gathering invoice with a line and a deleted line", func() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: testLines, }) require.NoError(s.T(), err) @@ -4670,7 +4670,7 @@ func (s *InvoicingTestSuite) TestUpdateInvoice() { s.Run("given a draft invoice with a line and a deleted line", func() { pendingLines, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: testLines, }) require.NoError(s.T(), err) diff --git a/test/billing/lineengine_test.go b/test/billing/lineengine_test.go index 3648f591e0..c016133d2d 100644 --- a/test/billing/lineengine_test.go +++ b/test/billing/lineengine_test.go @@ -242,7 +242,7 @@ func (s *LineEngineTestSuite) createMeteredDraftInvoiceWaitingForCollectionForAp Namespace: customerEntity.Namespace, ID: customerEntity.ID, }, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []ombilling.GatheringLine{{ GatheringLineBase: ombilling.GatheringLineBase{ ManagedResource: models.ManagedResource{ @@ -397,7 +397,7 @@ func (s *LineEngineTestSuite) TestGatheringPreviewUsesPreviewLineEngineCallback( Namespace: customerEntity.Namespace, ID: customerEntity.ID, }, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []ombilling.GatheringLine{{ GatheringLineBase: ombilling.GatheringLineBase{ ManagedResource: models.ManagedResource{ diff --git a/test/billing/schemamigration_test.go b/test/billing/schemamigration_test.go index 3b9e521fe7..313309d2b3 100644 --- a/test/billing/schemamigration_test.go +++ b/test/billing/schemamigration_test.go @@ -115,7 +115,7 @@ func (s *SchemaMigrationTestSuite) TestSchemaLevel1Migration() { _, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -126,7 +126,7 @@ func (s *SchemaMigrationTestSuite) TestSchemaLevel1Migration() { ServicePeriod: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, InvoiceAt: periodEnd, ManagedBy: billing.ManuallyManagedLine, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), RateCardDiscounts: billing.Discounts{ Percentage: &billing.PercentageDiscount{ PercentageDiscount: productcatalog.PercentageDiscount{ @@ -149,7 +149,7 @@ func (s *SchemaMigrationTestSuite) TestSchemaLevel1Migration() { ServicePeriod: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, InvoiceAt: periodEnd, ManagedBy: billing.ManuallyManagedLine, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), RateCardDiscounts: billing.Discounts{ Percentage: &billing.PercentageDiscount{ PercentageDiscount: productcatalog.PercentageDiscount{ @@ -217,7 +217,7 @@ func (s *SchemaMigrationTestSuite) TestSchemaLevel1Migration() { result, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customerEntity.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -228,7 +228,7 @@ func (s *SchemaMigrationTestSuite) TestSchemaLevel1Migration() { ServicePeriod: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, InvoiceAt: periodEnd, ManagedBy: billing.ManuallyManagedLine, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), FeatureKey: featureFlatPerUnit.Key, Price: lo.FromPtr(productcatalog.NewPriceFrom(productcatalog.FlatPrice{ Amount: alpacadecimal.NewFromFloat(100), diff --git a/test/billing/suite.go b/test/billing/suite.go index 60cdf2aff1..2522f64f9f 100644 --- a/test/billing/suite.go +++ b/test/billing/suite.go @@ -466,7 +466,7 @@ func (s *BaseSuite) CreateGatheringInvoice(t *testing.T, ctx context.Context, in res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: in.Customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine( billing.NewFlatFeeLineInput{ @@ -476,7 +476,7 @@ func (s *BaseSuite) CreateGatheringInvoice(t *testing.T, ctx context.Context, in ManagedBy: billing.ManuallyManagedLine, Name: "Test item1", PerUnitAmount: alpacadecimal.NewFromFloat(100), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Metadata: map[string]string{ "key": "value", }, @@ -491,7 +491,7 @@ func (s *BaseSuite) CreateGatheringInvoice(t *testing.T, ctx context.Context, in ManagedBy: billing.ManuallyManagedLine, Name: "Test item2", PerUnitAmount: alpacadecimal.NewFromFloat(200), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Metadata: map[string]string{ "key": "value", }, diff --git a/test/billing/tax_test.go b/test/billing/tax_test.go index 24e15dbe6e..5709b42bff 100644 --- a/test/billing/tax_test.go +++ b/test/billing/tax_test.go @@ -209,7 +209,7 @@ func (s *InvoicingTaxTestSuite) TestLineSplittingRetainsTaxConfig() { res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -296,7 +296,7 @@ func (s *InvoicingTaxTestSuite) generateDraftInvoice(ctx context.Context, custom res, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: customer.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Period: timeutil.ClosedPeriod{From: now, To: now.Add(time.Hour * 24)}, diff --git a/test/billing/taxcode_dual_write_test.go b/test/billing/taxcode_dual_write_test.go index 9731fc2189..6a118eb6b7 100644 --- a/test/billing/taxcode_dual_write_test.go +++ b/test/billing/taxcode_dual_write_test.go @@ -524,7 +524,7 @@ func (s *TaxCodeDualWriteTestSuite) TestSnapshotTaxCodeIntoLinesOnAdvance() { _, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: cust.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ billing.NewFlatFeeGatheringLine(billing.NewFlatFeeLineInput{ Namespace: ns, @@ -570,7 +570,7 @@ func (s *TaxCodeDualWriteTestSuite) TestSnapshotLineOwnCodeTakesPrecedence() { _, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: cust.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -628,7 +628,7 @@ func (s *TaxCodeDualWriteTestSuite) TestSnapshotPreservesExistingTaxCodeID() { // Create a pending line with the TaxCodeID already stamped (as subscription sync would do). _, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: cust.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ @@ -696,7 +696,7 @@ func (s *TaxCodeDualWriteTestSuite) TestSimulateInvoiceReadOnly() { result, err := s.BillingService.SimulateInvoice(ctx, billing.SimulateInvoiceInput{ Namespace: ns, CustomerID: &cust.ID, - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: billing.NewStandardInvoiceLines([]*billing.StandardLine{line}), }) s.NoError(err) diff --git a/test/billing/unitconfig_legacy_test.go b/test/billing/unitconfig_legacy_test.go index e7d5539b89..528e6e03c3 100644 --- a/test/billing/unitconfig_legacy_test.go +++ b/test/billing/unitconfig_legacy_test.go @@ -67,7 +67,7 @@ func (s *legacyUnitConfigRatingSuite) TestRatesConvertedQuantity() { _, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ Customer: cust.GetID(), - Currency: currencyx.Code(currency.USD), + Currency: currencyx.FiatCode(currency.USD), Lines: []billing.GatheringLine{ { GatheringLineBase: billing.GatheringLineBase{ diff --git a/test/credits/credit_then_invoice_test.go b/test/credits/credit_then_invoice_test.go index d469b74bea..7a0f141413 100644 --- a/test/credits/credit_then_invoice_test.go +++ b/test/credits/credit_then_invoice_test.go @@ -5314,7 +5314,7 @@ func (s *CreditThenInvoiceTestSuite) mustGatheringLinesForCharge(namespace, cust gatheringInvoices, err := s.BillingService.ListGatheringInvoices(s.T().Context(), billing.ListGatheringInvoicesInput{ Namespaces: []string{namespace}, Customers: []string{customerID}, - Currencies: []currencyx.Code{USD}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(USD)}, IncludeDeleted: includeDeletedLines, Expand: expand, }) diff --git a/test/credits/sanity_test.go b/test/credits/sanity_test.go index 6811658974..b36aedaf9f 100644 --- a/test/credits/sanity_test.go +++ b/test/credits/sanity_test.go @@ -3298,7 +3298,7 @@ func (s *SanitySuite) TestFlatFeeCreditOnlySanity() { gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{USD}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) @@ -3341,7 +3341,7 @@ func (s *SanitySuite) TestFlatFeeCreditOnlySanity() { gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{ Namespaces: []string{ns}, Customers: []string{cust.ID}, - Currencies: []currencyx.Code{USD}, + Currencies: []currencyx.FiatCode{currencyx.FiatCode(USD)}, Expand: []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines}, }) s.NoError(err) diff --git a/test/customer/subject.go b/test/customer/subject.go index b0ffdf673f..11713b0c65 100644 --- a/test/customer/subject.go +++ b/test/customer/subject.go @@ -393,7 +393,7 @@ func (s *CustomerHandlerTestSuite) TestMultiSubjectIntegrationFlow(ctx context.C Namespace: s.namespace, ID: createdCustomer.ID, }, - Currency: currencyx.Code("USD"), + Currency: currencyx.FiatCode("USD"), Lines: []billing.GatheringLine{pendingLine}, }) require.NoError(t, err, "creating pending invoice lines should succeed")