Skip to content

Payments flow adaptation for lazy payments - #37

Open
Tiago-Salles wants to merge 1 commit into
nau/teak.masterfrom
Tiago-Salles/issues/767-lazy-payments-flow
Open

Payments flow adaptation for lazy payments#37
Tiago-Salles wants to merge 1 commit into
nau/teak.masterfrom
Tiago-Salles/issues/767-lazy-payments-flow

Conversation

@Tiago-Salles

@Tiago-Salles Tiago-Salles commented May 17, 2026

Copy link
Copy Markdown
Contributor

Context

The payment flow on our Open edX ecommerce instance currently checks asynchronous payments (MB references and MBWAY) synchronously, right after the user clicks Continuar on PayGate. Because the upstream payment is not yet confirmed at that point, handle_processor_response raises GatewayError ("PayGate couldn't double check if basket has been payed") and the user is shown the misleading message "You have not been charged." — even when, in many cases, the payment will be successfully confirmed by PayGate a few seconds/minutes later.

We do not want to introduce a background queue. The chosen solution is to defer the payment confirmation to the moment the user opens the Order History page, where each row will lazily consult the payment processor and update its status (and create the Order in place if the payment was confirmed).

This PR introduces the backend pieces of that lazy resolution in nau_extensions. The MFE (frontend-app-ecommerce) consumes these endpoints and the ecommerce-plugin-paygate redirects the user to the new Thank-You page; those changes ship in their own PRs.

What this PR adds

  • BasketPaymentStatusViewGET /payment/nau_extensions/basket-payment-status/?order_number=…
    • Returns the current payment status of a single basket: paid, pending or failed.
    • If an Order already exists for the basket → returns paid immediately, without hitting PayGate.
    • If the basket has no PayGate PaymentProcessorResponse yet → returns pending without hitting PayGate (nothing to confirm).
    • Otherwise loads the PayGate processor via get_processor_class_by_name("paygate") and calls handle_payment + create_order + handle_post_order using a tiny EdxOrderPlacementMixin adapter (_LazyOrderPlacement). On GatewayError the response is pending. On other PaymentError or order-creation failures the response is failed.
    • Restricted to the basket owner (or staff users).
  • PendingBasketsListViewGET /payment/nau_extensions/pending-baskets/
    • Lists the authenticated user's baskets that have at least one PayGate attempt but no Order yet, so the Order History page can show in-flight asynchronous payments alongside the standard /api/v2/orders/ results.
  • Internal helpers _serialize_basket and _build_course_url to produce the JSON payload consumed by the MFE (including a best-effort LMS course URL used by the new "Go to course" action button).

What this PR changes

  • views.py — new imports (GatewayError, PaymentError, Response, EdxOrderPlacementMixin, get_processor_class_by_name, PaymentProcessorResponse, OrderNumberGenerator, django_settings) and the two new API views described above.
  • urls.py — registered two new routes:
    • basket-payment-status/basket_payment_status
    • pending-baskets/pending_baskets

Related PRs

Related to: https://github.com/fccn/nau-technical/issues/923

@Tiago-Salles
Tiago-Salles force-pushed the Tiago-Salles/issues/767-lazy-payments-flow branch from 4d19c74 to 54991a3 Compare May 17, 2026 17:48
@Tiago-Salles
Tiago-Salles marked this pull request as ready for review May 19, 2026 09:15
@Tiago-Salles
Tiago-Salles force-pushed the Tiago-Salles/issues/767-lazy-payments-flow branch 2 times, most recently from 93c6fa4 to dc399cf Compare May 30, 2026 20:59
@Tiago-Salles
Tiago-Salles force-pushed the Tiago-Salles/issues/767-lazy-payments-flow branch from dc399cf to ee4f27f Compare August 7, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant