Several type fixes (#855)

* Several type fixes

* Update ee/lib/stripe/client.ts

Co-authored-by: Alex Johansson <[email protected]>

* Typo

* Refactors createPaymentLink

* Simplify calendarClietn type

Co-authored-by: Alex Johansson <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
authored and GitHub committed 2021-10-05 16:46:48 -06:00
1 parent 4474e9dd74
commit 95b49a5995
6 files changed
+37 -24

No files matched your search

+8 -1
View File
@@ -1,4 +1,5 @@
import { loadStripe, Stripe } from "@stripe/stripe-js";
import { Maybe } from "@trpc/server";
import { stringify } from "querystring";
const stripePublicKey = process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY!;
@@ -18,7 +19,13 @@ const getStripe = (userPublicKey?: string) => {
return stripePromise;
};
export function createPaymentLink(paymentUid: string, name?: string, date?: string, absolute = true): string {
export function createPaymentLink(opts: {
paymentUid: string;
name?: Maybe<string>;
date?: Maybe<string>;
absolute?: boolean;
}): string {
const { paymentUid, name, date, absolute = true } = opts;
let link = "";
if (absolute) link = process.env.NEXT_PUBLIC_APP_URL!;
const query = stringify({ date, name });
+8 -9
View File
@@ -3,7 +3,7 @@ import Stripe from "stripe";
import { JsonValue } from "type-fest";
import { v4 as uuidv4 } from "uuid";
import { CalendarEvent, Person } from "@lib/calendarClient";
import { CalendarEvent } from "@lib/calendarClient";
import EventOrganizerRefundFailedMail from "@lib/emails/EventOrganizerRefundFailedMail";
import EventPaymentMail from "@lib/emails/EventPaymentMail";
import prisma from "@lib/prisma";
@@ -35,19 +35,14 @@ export async function handlePayment(
},
stripeCredential: { key: JsonValue },
booking: {
user: { email: string; name: string; timeZone: string };
user: { email: string | null; name: string | null; timeZone: string } | null;
id: number;
title: string;
description: string;
startTime: { toISOString: () => string };
endTime: { toISOString: () => string };
attendees: Person[];
location?: string;
uid: string;
}
) {
const paymentFee = Math.round(
selectedEventType.price * parseFloat(paymentFeePercentage || "0") + parseInt(paymentFeeFixed || "0")
selectedEventType.price * parseFloat(`${paymentFeePercentage}`) + parseInt(`${paymentFeeFixed}`)
);
const { stripe_user_id, stripe_publishable_key } = stripeCredential.key as Stripe.OAuthToken;
@@ -79,7 +74,11 @@ export async function handlePayment(
});
const mail = new EventPaymentMail(
createPaymentLink(payment.uid, booking.user.name, booking.startTime.toISOString()),
createPaymentLink({
paymentUid: payment.uid,
name: booking.user?.name,
date: booking.startTime.toISOString(),
}),
evt,
booking.uid
);