-
Notifications
You must be signed in to change notification settings - Fork 89
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
refactor(backend): handle grant lookup more gracefully in remote incoming payment service #2888
Conversation
…etOrCreate function
5a69214
to
4bff426
Compare
2e014e5
to
1b85b85
Compare
const resourceServerUrl = | ||
walletAddress.resourceServer ?? new URL(walletAddress.id).origin |
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.
We don't really need new URL(walletAddress.id).origin
at this point, but being defensive
return createIncomingPayment(deps, { | ||
createArgs, | ||
walletAddress, | ||
retryOnTokenError: false |
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.
we could make it such that we retry multiple times, but for our use case, we just want to retry with a new grant once
# Conflicts: # packages/backend/src/open_payments/grant/service.test.ts # packages/backend/src/open_payments/grant/service.ts
✅ Deploy Preview for brilliant-pasca-3e80ec canceled.
|
Changes proposed in this pull request
A new
grantService.getOrCreate
function was created in #2887, that, besides storing grant information, does all of the actual Open Payments grant requests with the OP client (as well as doing token rotation for those grant tokens as necessary).Previously, the logic for requesting grants and doing token rotation was repeated in the
remoteIncomingPaymentService
as well as thereceiverService
. Both services were doing the same thing: using the OP client to do grant requests and do token rotation. Now, since this logic is consolidated ingrantService.getOrCreate
, we are able to clean up those respective services:remoteIncomingPaymentService
callsgrantService.getOrCreate
in both of itscreate
andget
methods, which allows us to clean it up considerablyreceiverService
just has to callremoteIncomingPaymentService.get/create
to get & create remote incoming payments (which under the hood handles the grant management), which allows us to to clean up its logicAdditionally, in the
remoteIncomingPaymentService
, there is additional logic that is a bit more graceful in its incoming payment requests: if we fail to get or create an incoming payment with an existing grant (by checking for 401 or 403 errors), we delete the old grant, and try a request once more.Finally, we remove old external grantService methods which are no longer used after these changes.
Context
Fixes #2852
Checklist
fixes #number