Skip to content
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

fix(current usage): fix current usage taxes #3115

Merged
merged 3 commits into from
Jan 29, 2025
Merged

Conversation

lovrocolic
Copy link
Collaborator

Initially, when fetching taxes from Anrok we used fee.item_id (add_on_id, billable_metric_id, subscription_id) as main identifier that helps us map received taxes with certain fee on Lago side.

First version worked well for real invoices, but also for current usage where we don't have ID persisted on fee.

However, there was a case where multiple charges are related to the same billable_metric (especially when one fee amount is zero and another is positive) and we were not able to perform mapping correctly: #2842

However, one regression bug was produced with latest changes. Since fee.id is nil for current usage, taxes are not applied correctly in some scenarios.

This PR fixes described case

@lovrocolic lovrocolic requested a review from nudded January 29, 2025 12:56
@lovrocolic lovrocolic merged commit 6897439 into main Jan 29, 2025
6 checks passed
@lovrocolic lovrocolic deleted the fix-current-usage-taxes branch January 29, 2025 13:22
julienbourdeau added a commit that referenced this pull request Feb 6, 2025
## Context

When calling `GET
/customers/:cust_id/current_usage?external_subscription_id=:sub_id` Lago
computes the current usage

## Description

The taxes are computed by a thrid party (Anrok through Nango). We
originally implemented a cache to avoir http calls to third party but it
comes with drawbacks. We recently [tried to improve
this](#3115).
After investigation we believe it's best to remove the cache.

- [x] Remove Anrok cache
- [x] Introduce new `item_key` to reconcile fees when they are not
persisted
- [x] Add new `apply_taxes` params to the API
- If you get an error due to third party, you can call again without
taxes
- In case you only need pre-tax amounts (like for b2b), passing
`apply_taxes: false` will be more performant
  - getlago/lago-openapi#332

---------

Co-authored-by: Miguel Pinto <[email protected]>
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.

2 participants