From 2ae9baa82f47d770338f052ed7cd2ee0b58b035f Mon Sep 17 00:00:00 2001 From: Sli Date: Tue, 15 Apr 2025 18:50:25 +0200 Subject: [PATCH] Fix etransaction_data endpoint --- eboutic/api.py | 12 +++++------- eboutic/static/bundled/eboutic/checkout-index.ts | 9 +++++++-- eboutic/templates/eboutic/eboutic_checkout.jinja | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/eboutic/api.py b/eboutic/api.py index 3c2a1dc2..2041fb87 100644 --- a/eboutic/api.py +++ b/eboutic/api.py @@ -1,22 +1,20 @@ from ninja_extra import ControllerBase, api_controller, route from ninja_extra.exceptions import NotFound -from ninja_extra.permissions import IsAuthenticated +from core.auth.api_permissions import CanView from counter.models import BillingInfo from eboutic.models import Basket -@api_controller("/etransaction", permissions=[IsAuthenticated]) +@api_controller("/etransaction", permissions=[CanView]) class EtransactionInfoController(ControllerBase): - @route.get("/data", url_name="etransaction_data") - def fetch_etransaction_data(self): + @route.get("/data/{basket_id}", url_name="etransaction_data") + def fetch_etransaction_data(self, basket_id: int): """Generate the data to pay an eboutic command with paybox. The data is generated with the basket that is used by the current session. """ - basket = Basket.from_session(self.context.request.session) - if basket is None: - raise NotFound + basket: Basket = self.get_object_or_exception(Basket, pk=basket_id) try: return dict(basket.get_e_transaction_data()) except BillingInfo.DoesNotExist as e: diff --git a/eboutic/static/bundled/eboutic/checkout-index.ts b/eboutic/static/bundled/eboutic/checkout-index.ts index 47e81cb6..cb4be7f0 100644 --- a/eboutic/static/bundled/eboutic/checkout-index.ts +++ b/eboutic/static/bundled/eboutic/checkout-index.ts @@ -1,13 +1,18 @@ import { etransactioninfoFetchEtransactionData } from "#openapi"; document.addEventListener("alpine:init", () => { - Alpine.data("etransaction", (initialData) => ({ + Alpine.data("etransaction", (initialData, basketId: number) => ({ data: initialData, isCbAvailable: Object.keys(initialData).length > 0, async fill() { this.isCbAvailable = false; - const res = await etransactioninfoFetchEtransactionData(); + const res = await etransactioninfoFetchEtransactionData({ + path: { + // biome-ignore lint/style/useNamingConvention: api is in snake_case + basket_id: basketId, + }, + }); if (res.response.ok) { this.data = res.data; this.isCbAvailable = true; diff --git a/eboutic/templates/eboutic/eboutic_checkout.jinja b/eboutic/templates/eboutic/eboutic_checkout.jinja index 50fbd2fa..5ceeafc2 100644 --- a/eboutic/templates/eboutic/eboutic_checkout.jinja +++ b/eboutic/templates/eboutic/eboutic_checkout.jinja @@ -19,7 +19,7 @@ let billingInfos = {{ billing_infos|safe }}; -
+

{% trans %}Basket: {% endtrans %}