ING-139 feat(payments): Filter payments by currency#5517
Merged
Conversation
domenicofalco
approved these changes
May 19, 2026
The payments GraphQL query exposed filters by invoice, external customer, and search term, but not by currency. The frontend payments listing needs to narrow results by currency, so the resolver and the underlying query both need the new filter. Add a `currency` argument to `Resolvers::PaymentsResolver` and a matching `:currency` filter to `PaymentsQuery`. When set, the filter scopes the query to `where(amount_currency: filters.currency)`; when absent, it is a no-op and existing behavior is preserved. The generated `schema.graphql` and `schema.json` are regenerated to expose the new argument. Cover the new filter at both layers: a `PaymentsQuery` context creating a USD payment alongside the existing EUR set and asserting only the USD row comes back (plus a complementary "no matches" context for a currency with no payments), and a `PaymentsResolver` context exercising the GraphQL query with `currency: "USD"`.
## Context The `payments` GraphQL query exposes a `currency` filter that landed on this branch as a free-form `String`. Currencies in Lago come from the fixed list in `Currencies::ACCEPTED_CURRENCIES`, and the rest of the schema already surfaces them through `Types::CurrencyEnum`. Leaving the filter as a string let callers pass any value, deferring validation to the database lookup and producing an empty collection instead of a clear GraphQL error. ## Description Switch the `currency` argument on `Resolvers::PaymentsResolver` from `String` to `Types::CurrencyEnum`, regenerate `schema.graphql` and `schema.json` to reflect the new contract, and update the resolver spec so the query variable declaration matches the new type. The resolver internals stay the same: `PaymentsQuery` still receives a currency code string from GraphQL, and existing valid queries (`"USD"`, `"EUR"`, …) continue to work. The only user-visible change is that unknown currencies are now rejected by the GraphQL layer before the resolver runs.
1d7cfb2 to
29b2893
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The payments listing in the front-end needs to be filterable by currency, but the GraphQL
paymentsquery and the underlyingPaymentsQueryhad no such filter. This PR adds it at both layers.The change is mechanical: a
currencyargument onResolvers::PaymentsResolver, acurrencyentry inPaymentsQuery::Filters, and afilter_by_currencyhelper that scopes the query towhere(amount_currency: filters.currency). The resolver'sresolvemethod defaultscurrency:tonilso existing callers that don't pass it continue to work unchanged. The generatedschema.graphqlandschema.jsonare regenerated to reflect the new argument.Before and after
payments(currency: "USD") { ... }PaymentsQuery::Filtersshape[:invoice_id, :external_customer_id][:invoice_id, :external_customer_id, :currency]Test plan
bundle exec rspec spec/queries/payments_query_spec.rbbundle exec rspec spec/graphql/resolvers/payments_resolver_spec.rbpayments(currency: "USD") { collection { id } }returns only payments whoseamount_currency = "USD".Migration
None. The new argument is optional and not gated — existing callers see no change.
Follow-up worth opening
app/contracts/queries/payments_query_filters_contract.rblistsinvoice_idandexternal_customer_idbut notcurrency. Addingoptional(:currency).maybe(:string)would reject malformed currency strings at the validation layer instead of silently returning empty results. Skipped here to keep the PR focused.