interledger / rafiki

An open-source, comprehensive Interledger service for wallet providers, enabling them to provide Interledger functionality to their users.
https://rafiki.dev/
Apache License 2.0
233 stars 83 forks source link

Return amount spent on the outgoing payment grant during outgoing payment creation #2678

Closed mkurapov closed 3 months ago

mkurapov commented 5 months ago

Context

For the web monetization extension (and very likely other use cases), we should know how much has already been spent on the outgoing payment grant.

Whenever we create an outgoing payment, we determine whether the amount for the payment fits within the limits of the issued outgoing payment grant (by summing up all of the other payment that have been created under that said grant). If not, we reject the payment, otherwise, we create it. This accounting is done in the Open Payment resource server (the backend package), because that is where all of the outgoing payments are stored. In the auth server, we only know what the limit for the grant is, but not how much has been spent on it already.

This concerns the Open Payments outgoing payment, meaning there will be no changes in the Admin GraphQL API.

Todos

BlairCurrey commented 4 months ago

We talked about the reason for only returning on outgoing payment create, and that is because that is where the accounting is happening. We don't want to repeat that logic in a GET (especially for an entire page). We also concluded that returning in the create is sufficient for the webmon use-case.

Out of scope for this task but I wonder if there would ever be a use case for looking it up later. In that case I guess we could store it in the db on create. Although I imagine that could be stale by the time it's looked up.