Skip to content

Commit 6a2acf8

Browse files
fix: greptile comment
1 parent 5857b22 commit 6a2acf8

6 files changed

Lines changed: 27 additions & 16 deletions

File tree

openmeter/billing/worker/subscriptionsync/service/reconciler/patchcharge_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func newChargePatchTestExistingIntent(target targetstate.StateItem) chargesusage
269269
Intent: chargesmeta.Intent{
270270
ManagedBy: billing.SubscriptionManagedLine,
271271
CustomerID: target.Subscription.CustomerId,
272-
Currency: target.CurrencyCalculator.Currency,
272+
Currency: target.CurrencyCalculator.CurrencyCode(),
273273
UniqueReferenceID: ptr("existing-charge"),
274274
Subscription: &chargesmeta.SubscriptionReference{
275275
SubscriptionID: target.Subscription.ID,

openmeter/billing/worker/subscriptionsync/service/reconciler/patchchargeflatfee.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func newFlatFeeChargeIntent(target targetstate.StateItem) (charges.ChargeIntent,
118118
ManagedBy: billing.SubscriptionManagedLine,
119119
CustomerID: target.Subscription.CustomerId,
120120
Annotations: annotations,
121-
Currency: target.CurrencyCalculator.Currency,
121+
Currency: target.CurrencyCalculator.CurrencyCode(),
122122
UniqueReferenceID: &target.UniqueID,
123123
Subscription: &chargesmeta.SubscriptionReference{
124124
SubscriptionID: target.Subscription.ID,

openmeter/billing/worker/subscriptionsync/service/reconciler/patchchargeusagebased.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func newUsageBasedChargeIntent(target targetstate.StateItem) (charges.ChargeInte
113113
ManagedBy: billing.SubscriptionManagedLine,
114114
CustomerID: target.Subscription.CustomerId,
115115
Annotations: annotations,
116-
Currency: target.CurrencyCalculator.Currency,
116+
Currency: target.CurrencyCalculator.CurrencyCode(),
117117
UniqueReferenceID: &target.UniqueID,
118118
Subscription: &chargesmeta.SubscriptionReference{
119119
SubscriptionID: target.Subscription.ID,

openmeter/billing/worker/subscriptionsync/service/targetstate/targetstateitem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (r StateItem) GetExpectedLine() (*billing.GatheringLine, error) {
5858
Description: r.Spec.RateCard.AsMeta().Description,
5959
}),
6060
ManagedBy: billing.SubscriptionManagedLine,
61-
Currency: r.CurrencyCalculator.Currency,
61+
Currency: r.CurrencyCalculator.CurrencyCode(),
6262
ChildUniqueReferenceID: &r.UniqueID,
6363
TaxConfig: r.Spec.RateCard.AsMeta().TaxConfig,
6464
ServicePeriod: r.GetServicePeriod(),

pkg/currencyx/currency_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ func TestCalculatorUsesCurrencyInterface(t *testing.T) {
103103
fiatCalculator, err := currencyx.NewCalculator(currencyx.Code("USD"))
104104
require.NoError(t, err)
105105
require.Equal(t, currencyx.CurrencyTypeFiat, fiatCalculator.CurrencyType())
106+
require.Equal(t, currencyx.Code("USD"), fiatCalculator.CurrencyCode())
106107
require.Equal(t, int32(2), fiatCalculator.CurrencyPrecision())
107108
require.Equal(t, currencyx.RoundingModeHalfAwayFromZero, fiatCalculator.RoundingMode())
108-
require.NotNil(t, fiatCalculator.Def)
109+
require.NotNil(t, fiatCalculator.Definition())
110+
require.Equal(t, "0.01", fiatCalculator.Unit().String())
109111
require.Equal(t, float64(1.24), fiatCalculator.RoundToPrecision(alpacadecimal.NewFromFloat(1.235)).InexactFloat64())
110112

111113
custom, err := currencyx.NewCustomCurrency(currencyx.Code("CREDITS"), 6)
@@ -114,9 +116,10 @@ func TestCalculatorUsesCurrencyInterface(t *testing.T) {
114116
customCalculator, err := currencyx.NewCalculator(custom)
115117
require.NoError(t, err)
116118
require.Equal(t, currencyx.CurrencyTypeCustom, customCalculator.CurrencyType())
119+
require.Equal(t, currencyx.Code("CREDITS"), customCalculator.CurrencyCode())
117120
require.Equal(t, int32(6), customCalculator.CurrencyPrecision())
118121
require.Equal(t, currencyx.RoundingModeBankers, customCalculator.RoundingMode())
119-
require.Nil(t, customCalculator.Def)
122+
require.Nil(t, customCalculator.Definition())
120123
require.Equal(t, float64(1.234568), customCalculator.RoundToPrecision(alpacadecimal.NewFromFloat(1.2345678)).InexactFloat64())
121124
}
122125

pkg/currencyx/fiat.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func (c Code) Calculator() (Calculator, error) {
3131
}
3232

3333
type Calculator struct {
34-
Currency Code
35-
Def *currency.Def
34+
currency Code
35+
def *currency.Def
3636
currencyType CurrencyType
3737
precision int32
3838
roundingMode RoundingMode
@@ -60,8 +60,8 @@ func NewCalculator(cur Currency) (Calculator, error) {
6060
}
6161

6262
return Calculator{
63-
Currency: code,
64-
Def: def,
63+
currency: code,
64+
def: def,
6565
currencyType: CurrencyTypeFiat,
6666
precision: int32(def.Subunits),
6767
roundingMode: RoundingModeHalfAwayFromZero,
@@ -80,7 +80,7 @@ func NewCalculator(cur Currency) (Calculator, error) {
8080
}
8181

8282
return Calculator{
83-
Currency: code,
83+
currency: code,
8484
currencyType: CurrencyTypeCustom,
8585
precision: precision,
8686
roundingMode: roundingMode,
@@ -90,6 +90,14 @@ func NewCalculator(cur Currency) (Calculator, error) {
9090
}
9191
}
9292

93+
func (c Calculator) CurrencyCode() Code {
94+
return c.currency
95+
}
96+
97+
func (c Calculator) Definition() *currency.Def {
98+
return c.def
99+
}
100+
93101
func (c Calculator) CurrencyType() CurrencyType {
94102
return c.currencyType
95103
}
@@ -126,17 +134,17 @@ func (c Calculator) Validate() error {
126134

127135
switch c.currencyType {
128136
case CurrencyTypeFiat:
129-
if err := c.Currency.Validate(); err != nil {
137+
if err := c.currency.Validate(); err != nil {
130138
errs = append(errs, err)
131139
}
132-
if c.Def == nil {
140+
if c.def == nil {
133141
errs = append(errs, errors.New("fiat currency definition is required"))
134142
}
135-
if c.Def != nil && c.precision != int32(c.Def.Subunits) {
143+
if c.def != nil && c.precision != int32(c.def.Subunits) {
136144
errs = append(errs, errors.New("fiat currency precision must match currency definition"))
137145
}
138146
case CurrencyTypeCustom:
139-
if err := c.Currency.ValidateCustom(); err != nil {
147+
if err := c.currency.ValidateCustom(); err != nil {
140148
errs = append(errs, err)
141149
}
142150
if err := validatePrecision(c.precision); err != nil {
@@ -146,7 +154,7 @@ func (c Calculator) Validate() error {
146154
errs = append(errs, err)
147155
}
148156
default:
149-
if c.Currency == "" {
157+
if c.currency == "" {
150158
errs = append(errs, errors.New("currency code is required"))
151159
}
152160
errs = append(errs, c.currencyType.Validate())

0 commit comments

Comments
 (0)