rafiki icon indicating copy to clipboard operation
rafiki copied to clipboard

Add `cancelOutgoingPayment` GraphQL API

Open mkurapov opened this issue 1 year ago • 2 comments

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

  • [ ] Create cancelOutgoingPayment mutation
  • [ ] Update the OutgoingPaymentState enum in the GraphQL API
  • [ ] Update the mock ASE to call this mutation when a user does not have enough balance.
  • [ ] Make sure to add description to the mutation

mkurapov avatar Apr 30 '24 13:04 mkurapov

@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?

golobitch avatar Apr 30 '24 23:04 golobitch

@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

mkurapov avatar May 01 '24 13:05 mkurapov