-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: generate invoice for overdraft credits #796
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Pull Request Test Coverage Report for Build 11772280490Details
💛 - Coveralls |
d87e971
to
288c700
Compare
288c700
to
fe89ad2
Compare
fe89ad2
to
f2911fd
Compare
f2911fd
to
b5c6f8b
Compare
b5c6f8b
to
0ab130a
Compare
0ab130a
to
1a4e969
Compare
1a4e969
to
5e3baf7
Compare
5e3baf7
to
2192e76
Compare
2192e76
to
1551444
Compare
1551444
to
129b56e
Compare
129b56e
to
1330151
Compare
It's necessary to configure the product name to calculate per unit price before the overdraft credits can be invoiced in `billing.customer.credit_overdraft_product`. If not set, invoice reconcilation and creation is skipped. If there is already an invoice for overdraft credits for same time range, no new invoice will be created for that customer. Currently the system generates them on the first day of the month. When the overdraft invoice is created for the first time, it accounts for transactions from the start of customer life but then moving forward only accounts from the last month time range. Reconcilation of these invoice happens on same cadence as invoices gets synced from the billing provider. Signed-off-by: Kush Sharma <[email protected]>
1330151
to
e754cff
Compare
@@ -388,9 +422,28 @@ func (r BillingTransactionRepository) getBalanceInTx(ctx context.Context, tx *sq | |||
// in transaction table till now. | |||
func (r BillingTransactionRepository) GetBalance(ctx context.Context, accountID string) (int64, error) { | |||
var amount int64 | |||
if err := r.dbc.WithTxn(ctx, sql.TxOptions{}, func(tx *sqlx.Tx) error { | |||
if err := r.dbc.WithTxn(ctx, sql.TxOptions{ | |||
Isolation: sql.LevelSerializable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this done to prevent race condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it will make system slow once we start to have good amount of transactions. Also we calculate balance by summing over all rows instead which may also get performance issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this done to prevent race condition?
Yes, this is to prevent race conditions. What other way do you propose here to prevent it?
I feel it will make system slow once we start to have good amount of transactions. Also we calculate balance by summing over all rows instead which may also get performance issues.
Yes, one way I was thinking was to maintain a monthly statement in system and only accumulate records since last statement. But this introduces complexity quite a lot and was postponing it until we hit the performance degradation. I want to know what part of it is the bottleneck before going ahead with this approach. Do you have anything else in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is to prevent race conditions. What other way do you propose here to prevent it?
We actually did analysis for the same. Shared a document with you. With current setup where we don't have an aggregated balance, we can use redis. If instead we can move to having an aggregated balance which each transactions update, then we can use pessimistic locks.
It's necessary to configure the product name to calculate per unit price before the overdraft credits can be invoiced in
billing.customer.credit_overdraft_product
. If not set, invoice reconcilation and creation is skipped.If there is already an invoice for overdraft credits for same time range, no new invoice will be created for that customer. Currently the system generates them on the first day of the month.
Reconciliation of these invoice happens on same cadence as invoices gets synced from the billing provider.