XRPL-Labs / Nop.Plugin.Payments.Xumm

Accept cryptocurrency payments on the XRP Ledger with Xumm.
MIT License
2 stars 1 forks source link

Refund (partially) #4

Closed DominiqueBlomsma closed 2 years ago

DominiqueBlomsma commented 2 years ago

Paid orders will show refund buttons by default at the order detail page to (partially) refund offline. This means that the shop owner has to make sure he refunded the consumer himself.

Refund offline

The Xumm plugin could implement refunding and this will show 2 extra buttons, as shown below.

Refund plugin

Clicking on either Refund or Partial refund triggers the Xumm plugin implementation and has 2 outcomes:

  1. Success (No errors) and NewPaymentStatus (Pending, Authorized, Paid, PartiallyRefunded, Refunded, Voided)
  2. Errors[].

It is possible to create a payload with refund values but no way to user-friendly integrate this in nopCommerce.

Possible flow: nopCommercel

  1. Shop owner clicks [Refund].
  2. nopCommerce magic happens and triggers Xumm Plugin.
  3. Payment payload is created with user_token to send a Xumm Event on the shop owners phone.
  4. Save payload's refund attempt in the order to be able to generate unique custom identifiers (multiple partial refunds / cancelled / failed).
  5. Return a useful error message in Errors[] to indicate that there is a Xumm Event and not update the order as refunded.

NOTE: Step 5 will add a note to the order Unable to partially refund order. {error}

Webhook

  1. Extract order GUID from custom identifier.
  2. Validate XRPL transaction and save some indication to the order that the next Refund will be succeeded/failed to prevent a newly created refund payload.
  3. Call the nopCommerce implementation of the [Refund] button which triggers the Xumm plugin again and does a lot of other necessary things.
  4. Return PaymentStatus.PartiallyRefunded or PaymentStatus.Refunded if succeeded or any error in Errors[] to prevent nopCommerce to update the order as refunded.

Example of the error message Error message

Is this an acceptable and user-friendly flow or should we reconsider how we're going to handle refunds?

DominiqueBlomsma commented 2 years ago

Another solution might be creating a Widget and render it in OrderPartiallyRefundButtons.

We could disable Refunds in the Xumm Plugin and create a refund widget with a button that uses a redirect flow. This does mean that we have to copy/implement logic to refund and requires shop owners to install 2 extensions (plugin & widget).

DominiqueBlomsma commented 2 years ago

Decided flow:

nopCommerce

  1. Shop owner clicks [Refund].
  2. Payment Payload is created and an email will be send to the logged in admin.
  3. Save the count of the refund for unique custom identifiers (multiple partial refunds).
  4. An error will be returned to prevent the order to be updated as refunded with a message description about the mail being send.

Sign Payload

  1. User will sign the payload and is being redirected to the order detail page.
  2. Order will be updated with the received webhook or the redirected admin by calling the original [Refund] button functionality.
  3. Custom code will now return PaymentStatus.PartiallyRefunded or PaymentStatus.Refunded if the transaction was a success or any error in Errors[] if the payload was not signed.