Skip to content

feat: credit realization#3886

Closed
turip wants to merge 1 commit intofeat/charges-billing-apisfrom
feat/charges-credit-realizations
Closed

feat: credit realization#3886
turip wants to merge 1 commit intofeat/charges-billing-apisfrom
feat/charges-credit-realizations

Conversation

@turip
Copy link
Copy Markdown
Member

@turip turip commented Feb 20, 2026

Overview

Fixes #(issue)

Notes for reviewer

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 20, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/charges-credit-realizations

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@turip turip force-pushed the feat/charges-billing-apis branch from 82cf8f2 to d5146d4 Compare February 20, 2026 15:19
@turip turip force-pushed the feat/charges-credit-realizations branch 2 times, most recently from 48376bb to de35fd3 Compare February 20, 2026 16:08
Comment on lines +447 to +469
// Let's find out the service period for the credit realization
servicePeriod := timeutil.ClosedPeriod{
From: input.Charge.Intent.ServicePeriod.From,
To: input.AsOf,
}

lastRealizedPeriod := input.Charge.Realizations.Credit.LastRealizedPeriod()
if lastRealizedPeriod != nil {
servicePeriod.From = lastRealizedPeriod.To
}

h.customerAccountBalance -= amountToRealize.InexactFloat64()

// Note: we are also realizing the 0 value to make sure that we signify that in that period there was no usage
// in this setup the ledger transaction should not be created.

return []charges.CreditRealizationCreateInput{
{
Amount: amountToRealize,
ServicePeriod: servicePeriod,
},
}, nil
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: store the realization state inside the charge object and pass it to the handler as an already calculated value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also allows us to not to create 0 amount credit realizations, which will be good for the db schema as we can mandate the transaction group id

@turip turip force-pushed the feat/charges-credit-realizations branch from de35fd3 to 784fba4 Compare February 21, 2026 07:53
@turip turip force-pushed the feat/charges-credit-realizations branch from 784fba4 to 69b0f76 Compare February 22, 2026 04:31
@turip turip closed this Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant