diff --git a/webapp/.env.example b/webapp/.env.example index 0df16bd4..68895321 100644 --- a/webapp/.env.example +++ b/webapp/.env.example @@ -38,4 +38,8 @@ WEB_PUSH_PRIVATE_KEY=web-push-private-key # Widget NEXT_PUBLIC_WIDGET_TOKEN_NAME=widget-token WIDGET_SECRET_JWT=secret1 -WIDGET_SECRET_DATA_ENCRYPTION=secret2 \ No newline at end of file +WIDGET_SECRET_DATA_ENCRYPTION=secret2 + +# Obiz API +OBIZ_PARTNER_ID=default +OBIZ_SECRET=default \ No newline at end of file diff --git a/webapp/src/components/obiz/DiscountAmountBlock.tsx b/webapp/src/components/obiz/DiscountAmountBlock.tsx new file mode 100644 index 00000000..e1b1bd61 --- /dev/null +++ b/webapp/src/components/obiz/DiscountAmountBlock.tsx @@ -0,0 +1,119 @@ +import { + Center, + Divider, + Flex, + FormControl, + FormLabel, + Input, + NumberInput, + NumberInputField, + Text, +} from "@chakra-ui/react"; +import { Dispatch, SetStateAction } from "react"; + +const DiscountAmountBlock = ({ + amount, + setAmount, + minAmount, + maxAmount, + discount, +}: { + amount: number; + setAmount: Dispatch>; + minAmount: number; + maxAmount: number; + discount: number; +}) => { + const isDisabled = amount === 0; + const isInvalid = + !isDisabled && + (amount < minAmount || amount > maxAmount || amount % 1 !== 0); + + return ( +
+ + + Choisissez le montant du bon + + + setAmount(e.target.value ? Number(e.target.value) : 0) + } + placeholder="0€" + min={minAmount} + max={maxAmount} + /> + + +
+ + Vous payez + + + {!isDisabled && ( + + {amount}€ + + )} + + {(amount - amount * (discount / 100)) + .toFixed(isDisabled ? 0 : 2) + .replace(".", ",")} + € + + +
+ +
+ + Vous économisez + + + {(amount * (discount / 100)) + .toFixed(isDisabled ? 0 : 2) + .replace(".", ",")} + € + +
+
+
+ ); +}; + +export default DiscountAmountBlock; diff --git a/webapp/src/pages/dashboard/obiz-offer-variable.tsx b/webapp/src/pages/dashboard/obiz-offer-variable.tsx new file mode 100644 index 00000000..1f42f1a2 --- /dev/null +++ b/webapp/src/pages/dashboard/obiz-offer-variable.tsx @@ -0,0 +1,26 @@ +import { Box, Button, Flex } from "@chakra-ui/react"; +import { useState } from "react"; +import DiscountAmountBlock from "~/components/obiz/DiscountAmountBlock"; +import BackButton from "~/components/ui/BackButton"; + +export default function ObizOfferVariable() { + const [amount, setAmount] = useState(0); + + return ( + + + + + + + + ); +} diff --git a/webapp/src/server/api/routers/order.ts b/webapp/src/server/api/routers/order.ts index 0f6ebe3b..7f0da46b 100644 --- a/webapp/src/server/api/routers/order.ts +++ b/webapp/src/server/api/routers/order.ts @@ -1,11 +1,15 @@ +import { z } from "zod"; import { createTRPCRouter, userProtectedProcedure } from "~/server/api/trpc"; +import { createOrderPayload } from "~/utils/obiz"; export const orderRouter = createTRPCRouter({ - createOrder: userProtectedProcedure.query(async ({ ctx }) => { - // const [test] = await ctx.soapObizClient.ETAT_SITEAsync(); + createOrder: userProtectedProcedure + .input(z.object({ user_id: z.number(), client_id: z.number() })) + .query(async ({ ctx, input }) => { + const order_payload = createOrderPayload(input); - // console.log(JSON.stringify(test, null, 2)); + const [] = await ctx.soapObizClient.CREATION_COMMANDE_ARRAYAsync(); - return { data: "Hello" }; - }), + return { data: "Hello" }; + }), }); diff --git a/webapp/src/utils/obiz.ts b/webapp/src/utils/obiz.ts new file mode 100644 index 00000000..a7de87e9 --- /dev/null +++ b/webapp/src/utils/obiz.ts @@ -0,0 +1,12 @@ +var crypto = require("crypto"); + +export const obiz_signature = crypto + .createHash("sha512") + .update(`${process.env.OBIZ_PARTNER_ID}+${process.env.OBIZ_PARTNER_SECRET}`) + .digest("hex") as string; + +export const createOrderPayload = async ({ user_id }: { user_id: number }) => { + return { + CE_ID: "", + }; +};