Skip to content

Commit 436ea2f

Browse files
committed
feat(customcurrencies): support resolving costbases
1 parent 39c670b commit 436ea2f

21 files changed

Lines changed: 1182 additions & 50 deletions

app/common/charges.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func NewChargesUsageBasedService(
257257
billingService billing.Service,
258258
featureService feature.FeatureConnector,
259259
ratingService rating.Service,
260+
currenciesService currencies.Service,
260261
streamingConnector streaming.Connector,
261262
) (usagebased.Service, error) {
262263
usageBasedSvc, err := usagebasedservice.New(usagebasedservice.Config{
@@ -269,6 +270,7 @@ func NewChargesUsageBasedService(
269270
CustomerOverrideService: billingService,
270271
FeatureService: featureService,
271272
RatingService: ratingService,
273+
Currencies: currenciesService,
272274
StreamingConnector: streamingConnector,
273275
})
274276
if err != nil {
@@ -505,6 +507,7 @@ func newChargesRegistry(
505507
billingService,
506508
featureService,
507509
ratingService,
510+
currenciesService,
508511
streamingConnector,
509512
)
510513
if err != nil {

openmeter/billing/charges/flatfee/service/creditheninvoice.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,16 @@ func (s *CreditThenInvoiceStateMachine) UnsupportedShrinkOperation(_ context.Con
391391
)
392392
}
393393

394-
// ResolveDynamicCostBasis persists the dynamic cost basis effective at the
395-
// charge's service-period start. A persisted resolution is authoritative and
396-
// is returned unchanged on subsequent lifecycle attempts.
394+
// ResolveDynamicCostBasis idempotently persists the dynamic cost basis
395+
// effective at the charge's service-period start. Once resolved, the persisted
396+
// value is authoritative and must never be overwritten by lifecycle retries.
397397
func (s *CreditThenInvoiceStateMachine) ResolveDynamicCostBasis(ctx context.Context) error {
398398
intent := s.Charge.Intent.GetCostBasisIntent()
399-
if intent == nil || intent.Kind() != costbasis.ModeDynamic || s.Charge.State.ResolvedCostBasis != nil {
399+
if intent == nil || intent.Kind() != costbasis.ModeDynamic {
400+
return nil
401+
}
402+
403+
if s.Charge.State.ResolvedCostBasis != nil {
400404
return nil
401405
}
402406

openmeter/billing/charges/service/base_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func (s *BaseSuite) SetupSuite() {
157157
CustomerOverrideService: s.BillingService,
158158
FeatureService: s.FeatureService,
159159
RatingService: billingratingservice.New(billingratingservice.Config{UnitConfigEnabled: s.UnitConfigEnabled}),
160+
Currencies: currencyService,
160161
StreamingConnector: s.MockStreamingConnector,
161162
})
162163
s.NoError(err)

openmeter/billing/charges/service/invoicable_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,6 +3166,7 @@ func (s *InvoicableChargesTestSuite) TestUsageBasedCreditOnlyWithCustomCurrency(
31663166
CustomerOverrideService: s.BillingService,
31673167
FeatureService: s.FeatureService,
31683168
RatingService: billingratingservice.New(billingratingservice.Config{UnitConfigEnabled: s.UnitConfigEnabled}),
3169+
Currencies: s.CurrencyService,
31693170
StreamingConnector: s.MockStreamingConnector,
31703171
})
31713172
s.Require().NoError(err)

0 commit comments

Comments
 (0)