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

Add `cancelOutgoingPayment` GraphQL API #2688

Closed mkurapov closed 4 months ago

mkurapov commented 5 months ago

Context

Currently, when we create an outgoing payment, we send a outgoing_payment.created webhook to the ASE such that the ASE can check the user account, place a hold on the account for the payment amount, and then call fundOutgoingPayment, to deposit liquidity into the payment. Then, the ILP payment starts sending into the incoming payment.

Sometimes, however, the sending user account may not have enough balance to fulfill the outgoing payment amount. Rafiki does not provide a way for the ASE to notify about this possibility, and as a result, the outgoing payment will indefinitely stay in a FUNDING state.

We should allow the ASE to notify Rafiki about this possibility through a new Admin API, cancelOutgoingPayment (name always up for discussion). cancelOutgoingPayment will take in the outgoingPaymentId and update the state of the outgoing payment to a new state CANCELLED.

The only time an outgoing payment can be marked CANCELLED is if it is in a FUNDING state. Make sure to also update the OutgoingPayment.failed getter in the model to include this state, so that we properly return failed: true when it is fetched via Open Payments. Also, there is no need to send a webhook when an outgoing payment has been cancelled.

Todos

golobitch commented 5 months ago

@mkurapov how do you imagine flow here? So when should ASE perform balance check and call cancelOutgoingPayment in case there is not enough balance?

I assume that this check needs to be performed when ASE receives outgoing_payment.created webhook right?

mkurapov commented 5 months ago

@golobitch exactly,

  1. Receive outgoing_payment.created webhook
  2. If enough balance on user account, call fundOutgoingPayment
  3. If not enough balance (or some other system error), call cancelOutgoingPayment
  4. Reply 200