Skip to content

Commit

Permalink
Merge pull request #134 from SocialGouv/fix/obiz-create-order-accompte
Browse files Browse the repository at this point in the history
fix: add total_amount_to_pay for acompte in CREATION_COMMANDE obiz
  • Loading branch information
ClementNumericite authored Nov 15, 2024
2 parents c002c03 + a975972 commit abde615
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 20 additions & 1 deletion webapp/src/server/api/routers/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/utils/obiz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ""
Expand Down Expand Up @@ -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,
"",
"",
"",
Expand Down

0 comments on commit abde615

Please sign in to comment.