Coder Social home page Coder Social logo

getlago / lago-api Goto Github PK

View Code? Open in Web Editor NEW
308.0 308.0 86.0 10.06 MB

Open Source Metering and Usage Based Billing

Home Page: https://www.getlago.com/

License: GNU Affero General Public License v3.0

Ruby 94.33% JavaScript 0.01% Shell 0.03% Dockerfile 0.02% Makefile 0.01% Slim 5.62%

lago-api's People

Contributors

ansmonjol avatar binc0 avatar ccfiel avatar dependabot[bot] avatar dorianmariecom avatar dsinghvi avatar edwardmp avatar inventionlabssydney avatar ivannovosad avatar jcrapuchettes avatar jdenquin avatar josemoyab avatar julienbourdeau avatar lovrocolic avatar mathieu-lago avatar morganelecurieux avatar namehorn avatar odnobit avatar omeraplak avatar porter-deployment-app[bot] avatar prognostikos avatar rsempe avatar sarkissianraffi avatar stephentgrammer avatar vincent-pochet avatar zeeshanmuhammad avatar zobione avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lago-api's Issues

LoadError: cannot load such file -- factory_bot_rails

Sentry Issue: API-3

LoadError: cannot load such file -- factory_bot_rails
  bootsnap (1.10.3) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:27:in `require'
  zeitwerk (2.5.4) lib/zeitwerk/kernel.rb:35:in `require'
  db/seeds.rb:3:in `<main>'
    require 'factory_bot_rails'
  bootsnap (1.10.3) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in `load'
  bootsnap (1.10.3) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in `load'
...
(46 additional frame(s) were not displayed)

Improve model validation error for GraphQL

For GraphQL mutation, we should improve the way validation errors are sent to the front.

It will allow the front end to properly handle translations and field errors

In order to do to so, in case of unprocessable_entity error, an extension property of the GraphQL error will give the full detail of what went wrong when processing the mutation on the model.

Example of payload:

{
  "customer_id": ["already_taken"],
  "country": ["invalid"]
}

Add Customer create logic for GraphQL

Today we use the same service method for creating a customer with the API and the GraphQL endpoints.
We must create a dedicated method for GraphQL since the logic is a bit different :

  • We must return an error if the customer already exists

Graphql schemas consistency organization.vatRate

image

Today the organization.vatRate can be undefined or null. In the spec it's specified that it can only be a number between 0 and 100.
For consistency (and also because it avoids a lot of useless check in the front), can we update the grapqhl schema to "number, not optional" please ?

[QA]: Upgrade/Downgrade a plan

  • When downgrading plan, we should have the futur start date of the new plan (currently null) :
    query Customer.subscriptions.startDate

Add error codes for vat_rate numerical validation

We recently introduce numerical validations on the vat_rate attribute of organizations and customers.

Since this validations have an impact on the graphQL API, we need to add error codes to allow the front end to properly handle and translate them.

Handle trial period on plan

On each subscription fee creation:

end_of_trial = subscription_date + plan.trial_period

if to_date of invoice < end_of_trial
  amount = 0
elsif from_date < end_of_trial && to_date > end_of_trial 
 amount = pro-rata on days to bill
else # from_date > end_of_trial
  amoun = full amount
end

Add a property to the invoices table to store the number of free days to prevent recomputing it each time

Prevent hard destroy on DB resources

DB resources should not be hard deleted, instead, we should add a deleted_at.
Soft deleted resources should not be exposed in GraphQL or API but remain present in DB for tracking purpose.

Warning: this will impact all DB indexes based on unique constraint, the deleted_at field should be part of the index

Error handling for events and aggregation

Possible problems:

  • For MAX and SUM aggregation, field value is expected to be an integer.
    • If field is not an integer or cannot be casted as an integer, an ActiveRecord::StatementInvalid is raised by rails. Today it is handled at aggregation time but it fails for all the billing period
  • For MAX, SUM and COUNT UNIQUE, a property is expected in the event payload.
    • If the property is not present, it is ignored, or count as a 0 value.

In both cases, we should detect it, filter invalid events from the aggregation and let the user/developer know there is an issuer with the event.

The proper solution to let the user know still as to be discussed with the product team

Plan price comparison for upgrade/downgrade

Today, when checking for upgrade/downgrade of plan, we compare plan amount_cents no mater if the plan is yearly or monthly.
To have a proper base of comparison, we should divide multiply the amount by 12 when the plan is monhtly

[BUG] - Filter only on active subscriptions to (i) edit plan and (ii) plan list view

Describe the bug
When no customer is linked to a plan, we should be able to edit the plan (infos, model and charges). We have to be able to:

  • Filter assigned plan only for active subscriptions
  • Filter (image below) #of customers only for active subscriptions

Capture d’écran 2022-05-12 à 15 59 43

To Reproduce

  1. Create a plan
  2. Create a customer
  3. Link a plan to a customer
  4. Terminate the subscription
  5. It's now impossble to edit the plan, even if no customer has active subscription for it

Expected behavior
We shoud be able to edit a plan if no active subscription is assigned for this plan

:lady_beetle: Do not try to send webhook when organization does not have a webhook url

Sentry Issue: API-2

ArgumentError: bad argument (expected URI object or URI string)
  lib/lago_http_client/lago_http_client/client.rb:8:in `initialize'
    @uri = URI(url)
  app/services/webhooks/base_service.rb:16:in `new'
    http_client = LagoHttpClient::Client.new(current_organization.webhook_url)
  app/services/webhooks/base_service.rb:16:in `call'
    http_client = LagoHttpClient::Client.new(current_organization.webhook_url)
  app/jobs/send_webhook_job.rb:13:in `perform'
    Webhooks::InvoicesService.new(object).call
...
(74 additional frame(s) were not displayed)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.