diff --git a/webapp/src/server/api/routers/order.ts b/webapp/src/server/api/routers/order.ts index b338ce0c..f505cc2e 100644 --- a/webapp/src/server/api/routers/order.ts +++ b/webapp/src/server/api/routers/order.ts @@ -129,11 +129,30 @@ export const orderRouter = createTRPCRouter({ }); try { + const total_amount_to_pay = articles.reduce((acc, currentArticle) => { + const articleReference = article_references.find( + (ar) => ar.reference === currentArticle.reference + ); + + if (articleReference) { + if (currentArticle.kind === "fixed_price" && currentArticle.price) { + return acc + currentArticle.price * articleReference.quantity; + } else if ( + currentArticle.kind === "variable_price" && + input_value + ) { + return acc + input_value * articleReference.quantity; + } + } + return acc; + }, 0); + // CREATION DE LA COMMANDE const create_order_payload = createOrderPayload( user, initialOrder, - "CARTECADEAU" + "CARTECADEAU", + total_amount_to_pay ); const [resultOrder] = await ctx.soapObizClient.CREATION_COMMANDE_ARRAYAsync({ diff --git a/webapp/src/utils/obiz.ts b/webapp/src/utils/obiz.ts index d8b03222..7a34e490 100644 --- a/webapp/src/utils/obiz.ts +++ b/webapp/src/utils/obiz.ts @@ -17,7 +17,8 @@ export const obiz_signature = crypto export const createOrderPayload = ( user: User, order: Order, - kind: "CARTECADEAU" | "EBILLET" + kind: "CARTECADEAU" | "EBILLET", + total_amount_to_pay: number ) => { const { street_address, city, zip_code } = extractAddressInformations( user.address || "" @@ -91,7 +92,7 @@ export const createOrderPayload = ( "", `${baseUrl.includes("localhost") ? removeProtocolFromUrl(baseUrl) : baseUrl}/dashboard/order/${order.id}/success`, // url_retour_ok `${baseUrl.includes("localhost") ? removeProtocolFromUrl(baseUrl) : baseUrl}/dashboard/order/error`, // url_retour_ko - "", + total_amount_to_pay, "", "", "",