mirror of
https://github.com/ae-utbm/sith.git
synced 2025-04-29 21:06:45 +00:00
Fix etransaction_data endpoint
This commit is contained in:
parent
bc99390b25
commit
2ae9baa82f
@ -1,22 +1,20 @@
|
|||||||
from ninja_extra import ControllerBase, api_controller, route
|
from ninja_extra import ControllerBase, api_controller, route
|
||||||
from ninja_extra.exceptions import NotFound
|
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 counter.models import BillingInfo
|
||||||
from eboutic.models import Basket
|
from eboutic.models import Basket
|
||||||
|
|
||||||
|
|
||||||
@api_controller("/etransaction", permissions=[IsAuthenticated])
|
@api_controller("/etransaction", permissions=[CanView])
|
||||||
class EtransactionInfoController(ControllerBase):
|
class EtransactionInfoController(ControllerBase):
|
||||||
@route.get("/data", url_name="etransaction_data")
|
@route.get("/data/{basket_id}", url_name="etransaction_data")
|
||||||
def fetch_etransaction_data(self):
|
def fetch_etransaction_data(self, basket_id: int):
|
||||||
"""Generate the data to pay an eboutic command with paybox.
|
"""Generate the data to pay an eboutic command with paybox.
|
||||||
|
|
||||||
The data is generated with the basket that is used by the current session.
|
The data is generated with the basket that is used by the current session.
|
||||||
"""
|
"""
|
||||||
basket = Basket.from_session(self.context.request.session)
|
basket: Basket = self.get_object_or_exception(Basket, pk=basket_id)
|
||||||
if basket is None:
|
|
||||||
raise NotFound
|
|
||||||
try:
|
try:
|
||||||
return dict(basket.get_e_transaction_data())
|
return dict(basket.get_e_transaction_data())
|
||||||
except BillingInfo.DoesNotExist as e:
|
except BillingInfo.DoesNotExist as e:
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
import { etransactioninfoFetchEtransactionData } from "#openapi";
|
import { etransactioninfoFetchEtransactionData } from "#openapi";
|
||||||
|
|
||||||
document.addEventListener("alpine:init", () => {
|
document.addEventListener("alpine:init", () => {
|
||||||
Alpine.data("etransaction", (initialData) => ({
|
Alpine.data("etransaction", (initialData, basketId: number) => ({
|
||||||
data: initialData,
|
data: initialData,
|
||||||
isCbAvailable: Object.keys(initialData).length > 0,
|
isCbAvailable: Object.keys(initialData).length > 0,
|
||||||
|
|
||||||
async fill() {
|
async fill() {
|
||||||
this.isCbAvailable = false;
|
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) {
|
if (res.response.ok) {
|
||||||
this.data = res.data;
|
this.data = res.data;
|
||||||
this.isCbAvailable = true;
|
this.isCbAvailable = true;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
let billingInfos = {{ billing_infos|safe }};
|
let billingInfos = {{ billing_infos|safe }};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div x-data="etransaction(billingInfos)">
|
<div x-data="etransaction(billingInfos, {{ basket.id }})">
|
||||||
<p>{% trans %}Basket: {% endtrans %}</p>
|
<p>{% trans %}Basket: {% endtrans %}</p>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user