diff --git a/bun.lock b/bun.lock index 5c4f4c22..801d86d2 100644 --- a/bun.lock +++ b/bun.lock @@ -11,7 +11,7 @@ "@ibcornelsen/api": "link:@ibcornelsen/api", "@ibcornelsen/database": "link:@ibcornelsen/database", "@ibcornelsen/ui": "^0.0.2", - "@mollie/api-client": "^3.7.0", + "@mollie/api-client": "^4.1.0", "@pdfme/common": "^5.2.16", "@pdfme/generator": "^5.2.16", "@pdfme/ui": "^5.2.16", @@ -315,7 +315,7 @@ "@mdx-js/mdx": ["@mdx-js/mdx@3.1.0", "", { "dependencies": { "@types/estree": "^1.0.0", "@types/estree-jsx": "^1.0.0", "@types/hast": "^3.0.0", "@types/mdx": "^2.0.0", "collapse-white-space": "^2.0.0", "devlop": "^1.0.0", "estree-util-is-identifier-name": "^3.0.0", "estree-util-scope": "^1.0.0", "estree-walker": "^3.0.0", "hast-util-to-jsx-runtime": "^2.0.0", "markdown-extensions": "^2.0.0", "recma-build-jsx": "^1.0.0", "recma-jsx": "^1.0.0", "recma-stringify": "^1.0.0", "rehype-recma": "^1.0.0", "remark-mdx": "^3.0.0", "remark-parse": "^11.0.0", "remark-rehype": "^11.0.0", "source-map": "^0.7.0", "unified": "^11.0.0", "unist-util-position-from-estree": "^2.0.0", "unist-util-stringify-position": "^4.0.0", "unist-util-visit": "^5.0.0", "vfile": "^6.0.0" } }, "sha512-/QxEhPAvGwbQmy1Px8F899L5Uc2KZ6JtXwlCgJmjSTBedwOZkByYcBG4GceIGPXRDsmfxhHazuS+hlOShRLeDw=="], - "@mollie/api-client": ["@mollie/api-client@3.7.0", "", { "dependencies": { "axios": "^0.27.2" } }, "sha512-8pYq08xwv7VJIQvOJU+3nThZbXuNLhtD8iJQQ4UYW67kxHw4eC6cVE9SNVtUuHRfxTwcKLv5wrZd9jFb3BFqiA=="], + "@mollie/api-client": ["@mollie/api-client@4.1.0", "", { "dependencies": { "@types/node-fetch": "^2.6.11", "node-fetch": "^2.7.0", "ruply": "^1.0.1" } }, "sha512-cSPigdR7cK9k6YgW2QuX0Jk++TLNxZwi5QR1Nmuq2wrSBcQOswZHaGmCP1nSZgdIJtzfXpZxg4qptzGe1VkYZw=="], "@nodelib/fs.scandir": ["@nodelib/fs.scandir@2.1.5", "", { "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" } }, "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g=="], @@ -549,6 +549,8 @@ "@types/node": ["@types/node@22.13.0", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-ClIbNe36lawluuvq3+YYhnIN2CELi+6q8NpnM7PYp4hBn/TatfboPgVSm2rwKRfnV2M+Ty9GWDFI64KEe+kysA=="], + "@types/node-fetch": ["@types/node-fetch@2.6.12", "", { "dependencies": { "@types/node": "*", "form-data": "^4.0.0" } }, "sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA=="], + "@types/nodemailer": ["@types/nodemailer@6.4.17", "", { "dependencies": { "@types/node": "*" } }, "sha512-I9CCaIp6DTldEg7vyUTZi8+9Vo0hi1/T8gv3C89yk1rSAAzoKQ8H8ki/jBYJSFoH/BisgLP8tkZMlQ91CIquww=="], "@types/pug": ["@types/pug@2.0.10", "", {}, "sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA=="], @@ -675,8 +677,6 @@ "aws4": ["aws4@1.13.2", "", {}, "sha512-lHe62zvbTB5eEABUVi/AwVh0ZKY9rMMDhmm+eeyuuUQbQ3+J+fONVQOZyj+DdrvD4BY33uYniyRJ4UJIaSKAfw=="], - "axios": ["axios@0.27.2", "", { "dependencies": { "follow-redirects": "^1.14.9", "form-data": "^4.0.0" } }, "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ=="], - "axobject-query": ["axobject-query@4.1.0", "", {}, "sha512-qIj0G9wZbMGNLjLmg1PT6v2mE9AH2zlnADJD/2tC6E00hgmhUOfEB6greHPAfLRSufHqROIUTkw6E+M3lH0PTQ=="], "babel-runtime": ["babel-runtime@6.26.0", "", { "dependencies": { "core-js": "^2.4.0", "regenerator-runtime": "^0.11.0" } }, "sha512-ITKNuq2wKlW1fJg9sSW52eepoYgZBggvOAHC0u/CYu/qxQ9EVzThCgR69BnSXLHjy2f7SY5zaQ4yt7H9ZVxY2g=="], @@ -1073,8 +1073,6 @@ "flattie": ["flattie@1.1.1", "", {}, "sha512-9UbaD6XdAL97+k/n+N7JwX46K/M6Zc6KcFYskrYL8wbBV/Uyk0CTAMY0VT+qiK5PM7AIc9aTWYtq65U7T+aCNQ=="], - "follow-redirects": ["follow-redirects@1.15.9", "", {}, "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ=="], - "fontkit": ["fontkit@2.0.4", "", { "dependencies": { "@swc/helpers": "^0.5.12", "brotli": "^1.3.2", "clone": "^2.1.2", "dfa": "^1.2.0", "fast-deep-equal": "^3.1.3", "restructure": "^3.0.0", "tiny-inflate": "^1.0.3", "unicode-properties": "^1.4.0", "unicode-trie": "^2.0.0" } }, "sha512-syetQadaUEDNdxdugga9CpEYVaQIxOwk7GlwZWWZ19//qW4zE5bknOKeMBDYAASwnpaSHKJITRLMF9m1fp3s6g=="], "foreground-child": ["foreground-child@3.3.0", "", { "dependencies": { "cross-spawn": "^7.0.0", "signal-exit": "^4.0.1" } }, "sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg=="], @@ -1915,6 +1913,8 @@ "run-parallel": ["run-parallel@1.2.0", "", { "dependencies": { "queue-microtask": "^1.2.2" } }, "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA=="], + "ruply": ["ruply@1.0.1", "", {}, "sha512-p39LnaaJyuucPGlgaB0KiyifpcuOkn24+Hq5y0ejAD/LlH+mRAbkHn2tckCLgHir+S+nis1WYG+TYEC4zHX0WQ=="], + "rw": ["rw@1.3.3", "", {}, "sha512-PdhdWy89SiZogBLaw42zdeqtRJ//zFd2PgQavcICDUgJT5oW10QCRKbJ6bg4r0/UY2M6BWd5tkxuGFRvCkgfHQ=="], "rxjs": ["rxjs@7.8.1", "", { "dependencies": { "tslib": "^2.1.0" } }, "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg=="], diff --git a/src/cypress/fixtures/example.json b/cypress/fixtures/example.json similarity index 100% rename from src/cypress/fixtures/example.json rename to cypress/fixtures/example.json diff --git a/src/cypress/fixtures/images/daemmung/1.jpeg b/cypress/fixtures/images/daemmung/1.jpeg similarity index 100% rename from src/cypress/fixtures/images/daemmung/1.jpeg rename to cypress/fixtures/images/daemmung/1.jpeg diff --git a/src/cypress/fixtures/images/daemmung/2.jpeg b/cypress/fixtures/images/daemmung/2.jpeg similarity index 100% rename from src/cypress/fixtures/images/daemmung/2.jpeg rename to cypress/fixtures/images/daemmung/2.jpeg diff --git a/src/cypress/fixtures/images/fenster/1.jpeg b/cypress/fixtures/images/fenster/1.jpeg similarity index 100% rename from src/cypress/fixtures/images/fenster/1.jpeg rename to cypress/fixtures/images/fenster/1.jpeg diff --git a/src/cypress/fixtures/images/fenster/2.jpeg b/cypress/fixtures/images/fenster/2.jpeg similarity index 100% rename from src/cypress/fixtures/images/fenster/2.jpeg rename to cypress/fixtures/images/fenster/2.jpeg diff --git a/src/cypress/fixtures/images/gebaeude/1.jpeg b/cypress/fixtures/images/gebaeude/1.jpeg similarity index 100% rename from src/cypress/fixtures/images/gebaeude/1.jpeg rename to cypress/fixtures/images/gebaeude/1.jpeg diff --git a/src/cypress/fixtures/images/heizungsanlage/1.jpeg b/cypress/fixtures/images/heizungsanlage/1.jpeg similarity index 100% rename from src/cypress/fixtures/images/heizungsanlage/1.jpeg rename to cypress/fixtures/images/heizungsanlage/1.jpeg diff --git a/src/cypress/fixtures/images/heizungsanlage/2.jpeg b/cypress/fixtures/images/heizungsanlage/2.jpeg similarity index 100% rename from src/cypress/fixtures/images/heizungsanlage/2.jpeg rename to cypress/fixtures/images/heizungsanlage/2.jpeg diff --git a/cypress/screenshots/erstellen.cy.ts/Verbrauchsausweis erstellen Schritt 1 -- erstellt einen neuen Verbrauchsausweis Wohngebäude (failed).png b/cypress/screenshots/erstellen.cy.ts/Verbrauchsausweis erstellen Schritt 1 -- erstellt einen neuen Verbrauchsausweis Wohngebäude (failed).png new file mode 100644 index 00000000..2d8d12c7 Binary files /dev/null and b/cypress/screenshots/erstellen.cy.ts/Verbrauchsausweis erstellen Schritt 1 -- erstellt einen neuen Verbrauchsausweis Wohngebäude (failed).png differ diff --git a/package.json b/package.json index 5874e3d4..993d6443 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@ibcornelsen/api": "link:@ibcornelsen/api", "@ibcornelsen/database": "link:@ibcornelsen/database", "@ibcornelsen/ui": "^0.0.2", - "@mollie/api-client": "^3.7.0", + "@mollie/api-client": "^4.1.0", "@pdfme/common": "^5.2.16", "@pdfme/generator": "^5.2.16", "@pdfme/ui": "^5.2.16", diff --git a/persistent/images/img-1017697d-6806-431f-8cb0-083be6851402.webp b/persistent/images/img-1017697d-6806-431f-8cb0-083be6851402.webp new file mode 100644 index 00000000..683d630f Binary files /dev/null and b/persistent/images/img-1017697d-6806-431f-8cb0-083be6851402.webp differ diff --git a/persistent/images/img-1fc02565-7612-431a-aa6c-59911f5c7a73.webp b/persistent/images/img-1fc02565-7612-431a-aa6c-59911f5c7a73.webp new file mode 100644 index 00000000..ad48e7a2 Binary files /dev/null and b/persistent/images/img-1fc02565-7612-431a-aa6c-59911f5c7a73.webp differ diff --git a/persistent/images/img-425b7b43-c12f-43eb-b20b-5ea23bae2712.webp b/persistent/images/img-425b7b43-c12f-43eb-b20b-5ea23bae2712.webp new file mode 100644 index 00000000..52f45313 Binary files /dev/null and b/persistent/images/img-425b7b43-c12f-43eb-b20b-5ea23bae2712.webp differ diff --git a/persistent/images/img-8be88072-7bdd-43e2-a5b4-1a716f934762.webp b/persistent/images/img-8be88072-7bdd-43e2-a5b4-1a716f934762.webp new file mode 100644 index 00000000..daa1baab Binary files /dev/null and b/persistent/images/img-8be88072-7bdd-43e2-a5b4-1a716f934762.webp differ diff --git a/persistent/images/img-ea69cea0-813a-469e-b603-2ae68086001a.webp b/persistent/images/img-ea69cea0-813a-469e-b603-2ae68086001a.webp new file mode 100644 index 00000000..311095e4 Binary files /dev/null and b/persistent/images/img-ea69cea0-813a-469e-b603-2ae68086001a.webp differ diff --git a/src/astro-typesafe-api-caller.ts b/src/astro-typesafe-api-caller.ts index 489fcfa3..c12f37e9 100644 --- a/src/astro-typesafe-api-caller.ts +++ b/src/astro-typesafe-api-caller.ts @@ -11,6 +11,7 @@ export const createCaller = createCallerFactory({ "auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"), "bilder/[uid]": await import("../src/pages/api/bilder/[uid].ts"), "objekt": await import("../src/pages/api/objekt/index.ts"), + "rechnung": await import("../src/pages/api/rechnung/index.ts"), "ticket": await import("../src/pages/api/ticket/index.ts"), "user": await import("../src/pages/api/user/index.ts"), "user/self": await import("../src/pages/api/user/self.ts"), diff --git a/src/client/lib/verbrauchsausweisWohnenSpeichern.ts b/src/client/lib/verbrauchsausweisWohnenSpeichern.ts index 73967fcb..657fc9a5 100644 --- a/src/client/lib/verbrauchsausweisWohnenSpeichern.ts +++ b/src/client/lib/verbrauchsausweisWohnenSpeichern.ts @@ -5,7 +5,6 @@ import { exclude } from "#lib/exclude.js"; import Cookies from "js-cookie"; import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js"; import { AufnahmeClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient, } from "#components/Ausweis/types.js"; -// import { addNotification } from "@ibcornelsen/ui"; export async function verbrauchsausweisWohnenSpeichern( ausweis: VerbrauchsausweisWohnenClient, @@ -74,7 +73,7 @@ export async function verbrauchsausweisWohnenSpeichern( } }) } else { - await api["verbrauchsausweis-wohnen"].PUT.fetch({ + const { uid } = await api["verbrauchsausweis-wohnen"].PUT.fetch({ ausweis, uid_aufnahme: aufnahme.uid }, { @@ -82,6 +81,8 @@ export async function verbrauchsausweisWohnenSpeichern( "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` } }) + + ausweis.uid = uid; } for (const bild of bilder) { diff --git a/src/components/Ausweis/Ausweisart.svelte b/src/components/Ausweis/Ausweisart.svelte index 7c840974..25092d90 100644 --- a/src/components/Ausweis/Ausweisart.svelte +++ b/src/components/Ausweis/Ausweisart.svelte @@ -44,6 +44,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 placeholder="Anlass" bind:value={ausweis.ausstellgrund} required + data-cy="ausstellgrund" > {#each Object.entries(Enums.Ausstellgrund) as [name, ausstellgrund]} diff --git a/src/components/Ausweis/ButtonWeiterHilfe.svelte b/src/components/Ausweis/ButtonWeiterHilfe.svelte index b0698fb3..d1172743 100644 --- a/src/components/Ausweis/ButtonWeiterHilfe.svelte +++ b/src/components/Ausweis/ButtonWeiterHilfe.svelte @@ -1,8 +1,14 @@ - -
- +
- + - -
- -
- - -
\ No newline at end of file +
+ +
+
diff --git a/src/components/Ausweis/ButtonZurueckSpeichernKaufabschluss.svelte b/src/components/Ausweis/ButtonZurueckSpeichernKaufabschluss.svelte index 7a6349e2..4271e054 100644 --- a/src/components/Ausweis/ButtonZurueckSpeichernKaufabschluss.svelte +++ b/src/components/Ausweis/ButtonZurueckSpeichernKaufabschluss.svelte @@ -1,28 +1,14 @@ - -
- +
- + - - - -
\ No newline at end of file + +
diff --git a/src/components/Ausweis/LueftungundLeerstand.svelte b/src/components/Ausweis/LueftungundLeerstand.svelte index 7e532edc..1264f679 100644 --- a/src/components/Ausweis/LueftungundLeerstand.svelte +++ b/src/components/Ausweis/LueftungundLeerstand.svelte @@ -80,12 +80,12 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 bind:value={aufnahme.lueftung} > - - - + + - diff --git a/src/components/Ausweis/SanierungsOption.svelte b/src/components/Ausweis/SanierungsOption.svelte index ae360252..8f5098d7 100644 --- a/src/components/Ausweis/SanierungsOption.svelte +++ b/src/components/Ausweis/SanierungsOption.svelte @@ -4,31 +4,24 @@ export let checked: boolean | null | undefined; export let name: string; export let label: string; + export let help: string; export let value: string; -function clickCheckbox(e){ -e.target.firstChild.click(); -}; - - -
+
clickCheckbox(event)} on:keydown={() => clickCheckbox(event)} > - diff --git a/src/components/Ausweis/Verbrauch.svelte b/src/components/Ausweis/Verbrauch.svelte index abd8b18e..0ba316a8 100644 --- a/src/components/Ausweis/Verbrauch.svelte +++ b/src/components/Ausweis/Verbrauch.svelte @@ -138,6 +138,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 class="checkbox" name="zusaetzliche_heizquelle_1" bind:checked={ausweis.zusaetzliche_heizquelle} + data-cy="zusaetzliche_heizquelle" />
diff --git a/src/modules/VerbrauchsausweisWohnen/AusweisWeiter.svelte b/src/modules/VerbrauchsausweisWohnen/AusweisWeiter.svelte index 3945e5f9..a3e45ac9 100644 --- a/src/modules/VerbrauchsausweisWohnen/AusweisWeiter.svelte +++ b/src/modules/VerbrauchsausweisWohnen/AusweisWeiter.svelte @@ -88,4 +88,4 @@
- \ No newline at end of file + \ No newline at end of file diff --git a/src/modules/VerbrauchsausweisWohnen/VerbrauchsausweisWohnenModule.svelte b/src/modules/VerbrauchsausweisWohnen/VerbrauchsausweisWohnenModule.svelte index 2990e24a..bfa2a078 100644 --- a/src/modules/VerbrauchsausweisWohnen/VerbrauchsausweisWohnenModule.svelte +++ b/src/modules/VerbrauchsausweisWohnen/VerbrauchsausweisWohnenModule.svelte @@ -137,7 +137,7 @@ "", `${location.pathname}?uid=${result.uid_ausweis}` ); - window.location.href = `/kundendaten?uid=${result.uid_ausweis}`; + // window.location.href = `/kundendaten?uid=${result.uid_ausweis}`; } } diff --git a/src/pages/api/auth/forgot-password.ts b/src/pages/api/auth/forgot-password.ts index d9252123..9a7e73f3 100644 --- a/src/pages/api/auth/forgot-password.ts +++ b/src/pages/api/auth/forgot-password.ts @@ -61,7 +61,7 @@ Viele Grüße, IBCornelsen` }) - if (info.rejected) { + if (info.rejected.length > 0) { throw new APIError({ code: "INTERNAL_SERVER_ERROR", message: "Etwas ist schiefgelaufen, bitte versuchen sie es erneut." diff --git a/src/pages/api/rechnung/index.ts b/src/pages/api/rechnung/index.ts new file mode 100644 index 00000000..0d24ea9f --- /dev/null +++ b/src/pages/api/rechnung/index.ts @@ -0,0 +1,142 @@ +import { z } from "zod"; +import { Enums, RechnungSchema, prisma } from "@ibcornelsen/database/server"; +import { TRPCError } from "@trpc/server"; +import { mollieClient } from "#lib/mollie.js"; +import { PaymentMethod } from "@mollie/api-client"; +import { defineApiRoute } from "astro-typesafe-api/server"; +import { + authorizationHeaders, + authorizationMiddleware, +} from "#lib/middleware/authorization.js"; + +export const PUT = defineApiRoute({ + meta: { + contentTypes: ["application/json"], + description: + "Erstellt eine neue Rechnung mit der ein Energieausweis bezahlt werden kann. Gibt eine Checkout URL zurück, welche der Nutzer folgen muss, um zum Kaufabschluss zu gelangen.", + summary: "Erstellt eine neue Rechnung zu einem Energieausweis Vorgang.", + tags: ["Rechnungen"], + }, + input: z + .object({ + ausweisart: z.nativeEnum(Enums.Ausweisart), + uid: z.string().uuid(), + }) + .merge( + RechnungSchema.omit({ + benutzer_id: true, + bezahlt_am: true, + erstellt_am: true, + id: true, + status: true, + uid: true, + betrag: true, + storniert_am: true, + transaktions_referenz: true, + }) + ), + output: z.object({ + checkout_url: z.string(), + uid: z.string().uuid(), + }), + headers: authorizationHeaders, + middleware: authorizationMiddleware, + async fetch(input, ctx, user) { + // Wir erstellen eine Mollie Payment Referenz und eine neue Rechnung in unserer Datenbank, daraufhin geben + // wir eine Checkout URL zurück auf die der Nutzer weitergeleitet werden kann. + + const { uid, ausweisart, bezahlmethode, services } = input; + + // TODO: Services Implementieren + + if (ausweisart === Enums.Ausweisart.BedarfsausweisWohnen) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: "Bedarfsausweis Wohnen wird noch nicht unterstützt.", + }); + } else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: + "Verbrauchsausweis Gewerbe wird noch nicht unterstützt.", + }); + } else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) { + // Wir müssen überprüfen, ob dem Nutzer der Ausweis tatsächlich gehört. + const ausweis = await prisma.verbrauchsausweisWohnen.findUnique({ + where: { + uid, + }, + }); + + if (!ausweis) { + throw new TRPCError({ + code: "NOT_FOUND", + message: "Ausweis nicht gefunden.", + }); + } + + if (ausweis.benutzer_id !== user.id) { + throw new TRPCError({ + code: "UNAUTHORIZED", + message: "Ausweis gehört nicht dem Nutzer.", + }); + } + + // Wir erstellen eine neue Rechnung in unserer Datenbank. + const rechnung = await prisma.rechnung.create({ + data: { + benutzer_id: user.id, + betrag: 0, + bezahlmethode: bezahlmethode, + status: Enums.Rechnungsstatus.open, + aufnahme_id: ausweis.aufnahme_id, + }, + select: { + uid: true, + betrag: true, + }, + }); + + if (!rechnung) { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "Rechnung konnte nicht erstellt werden.", + }); + } + + // Wir erstellen eine Mollie Payment Referenz. + const payment = await mollieClient.payments.create({ + amount: { + value: "45.00", + currency: "EUR", + }, + metadata: { + rechnung_uid: rechnung.uid, + }, + method: input.bezahlmethode as PaymentMethod, + description: "Verbrauchsausweis Wohnen 2016", + redirectUrl: "https://ibcornelsen.de/payment/success", + webhookUrl: "http://api.ibcornelsen.de/v1/webhooks/mollie", + }); + + const checkoutUrl = payment.getCheckoutUrl(); + + if (!checkoutUrl) { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "Checkout URL konnte nicht erstellt werden.", + }); + } + + return { + uid: rechnung.uid, + checkout_url: checkoutUrl, + }; + } else { + throw new TRPCError({ + code: "BAD_REQUEST", + message: "Ausweisart nicht unterstützt.", + }); + } + }, +}); diff --git a/src/trpc.ts b/src/trpc.ts deleted file mode 100644 index 963d6f71..00000000 --- a/src/trpc.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { createTRPCProxyClient, httpBatchLink } from '@trpc/client'; -import cookies from 'js-cookie'; -import type { AppRouter } from '@ibcornelsen/api'; -import { Buffer } from 'buffer'; - -let url: string = 'http://localhost:3001/'; - -if (typeof window !== "undefined" && window.location.hostname !== "localhost") { - url = "http://rpc.ibcornelsen.de/" -} - - -export const client = createTRPCProxyClient({ - links: [ - httpBatchLink({ - url, - headers() { - const accessToken = cookies.get('accessToken'); - if (!accessToken) return {}; - - const buffer = Buffer.from(accessToken, 'utf-8'); - const base64 = buffer.toString('base64') - - return { - 'Authorization': `Bearer ${base64}`, - }; - }, - }), - ], -}); \ No newline at end of file