openfun / joanie

👛 A headless ERP for education to manage course enrollment/subscription, payment and certificates delivery.
MIT License
22 stars 2 forks source link

Order validate - Prevent enrollment failure on post transition callback to revert the state transition #711

Closed jbpenrath closed 6 months ago

jbpenrath commented 6 months ago

Bug Report

Problematic behavior

Currently, when an order is validated we try to enroll the user to single open course run and we sync existing enrollment (to update enrollment mode for OpenEdX course run). But if this logic fails, currently we do not catch errors properly. As consequences, as the post transition callback raise an error, the transition state is reverted that is weird. Indeed, as this stage, the user is purchasing a product and this failure lets believe that something went wrong about the payment. Furthermore the only option for the user is to try to cancel the payment but this action also failed as this one cannot be aborted as it has succeeded.

Expected behavior/code

When a payment succeed and the automatic enrollment logic is triggered, if this one failed, the state transition should not be reverted.

Additional context/Screenshots https://github.com/openfun/joanie/blob/78b5135504530899fb4383085126a94c9dda5c93/src/backend/joanie/core/models/products.py#L1054-L1096