fix: checkout

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-10-18 10:28:56 +02:00
parent 4b831204b7
commit 21fc076368
5 changed files with 5 additions and 21 deletions

View File

@@ -27,7 +27,6 @@ const paramsSchema = z.object({
const metadataSchema = z.object({
organizationId: z.string(),
projectId: z.string(),
integrationId: z.string(),
});
@@ -89,7 +88,7 @@ export async function slackWebhook(
'👋 Hello. You have successfully connected OpenPanel.dev to your Slack workspace.',
});
const { projectId, organizationId, integrationId } = parsedMetadata.data;
const { organizationId, integrationId } = parsedMetadata.data;
await db.integration.update({
where: {
@@ -105,7 +104,7 @@ export async function slackWebhook(
});
return reply.redirect(
`${process.env.DASHBOARD_URL || process.env.NEXT_PUBLIC_DASHBOARD_URL}/${organizationId}/${projectId}/settings/integrations?tab=installed`,
`${process.env.DASHBOARD_URL || process.env.NEXT_PUBLIC_DASHBOARD_URL}/${organizationId}/integrations/installed`,
);
} catch (err) {
request.log.error(err);

View File

@@ -29,7 +29,6 @@ type Props = {
};
export default function Billing({ organization }: Props) {
const { projectId } = useAppParams();
const queryClient = useQueryClient();
const trpc = useTRPC();
const [customerSessionToken, setCustomerSessionToken] = useQueryState(
@@ -271,7 +270,6 @@ export default function Billing({ organization }: Props) {
key={selectedProduct.prices[0].id}
price={selectedProduct.prices[0]}
organization={organization}
projectId={projectId}
buttonText={
isUpgrade
? 'Upgrade'
@@ -350,13 +348,11 @@ export default function Billing({ organization }: Props) {
function CheckoutButton({
price,
organization,
projectId,
disabled,
buttonText,
}: {
price: IPolarPrice;
organization: IServiceOrganization;
projectId: string;
disabled?: string | null;
buttonText?: string;
}) {
@@ -396,7 +392,6 @@ function CheckoutButton({
onClick={() => {
const createCheckout = () =>
checkout.mutate({
projectId,
organizationId: organization.id,
productPriceId: price!.id,
productId: price.productId,

View File

@@ -28,7 +28,7 @@ export async function getProjectById(id: string) {
export const getProjectByIdCached = cacheable(getProjectById, 60 * 60 * 24);
export async function getProjectWithClients(id: string) {
const res = await db.project.findUnique({
const res = await db.$primary().project.findUnique({
where: {
id,
},

View File

@@ -13,14 +13,8 @@ export const polar = new Polar({
server: process.env.NODE_ENV === 'production' ? 'production' : 'sandbox',
});
export const getSuccessUrl = (
baseUrl: string,
organizationId: string,
projectId?: string,
) =>
projectId
? `${baseUrl}/${organizationId}/${projectId}/settings?tab=billing`
: `${baseUrl}/${organizationId}`;
export const getSuccessUrl = (baseUrl: string, organizationId: string) =>
`${baseUrl}/${organizationId}/billing`;
export async function getProducts() {
const products = await polar.products.list({
@@ -52,13 +46,11 @@ export async function createPortal({
export async function createCheckout({
productId,
organizationId,
projectId,
user,
ipAddress,
}: {
productId: string;
organizationId: string;
projectId?: string;
user: {
id: string;
firstName: string | null;
@@ -73,7 +65,6 @@ export async function createCheckout({
successUrl: getSuccessUrl(
process.env.DASHBOARD_URL || process.env.NEXT_PUBLIC_DASHBOARD_URL!,
organizationId,
projectId,
),
customerEmail: user.email,
customerName: [user.firstName, user.lastName].filter(Boolean).join(' '),

View File

@@ -77,7 +77,6 @@ export const subscriptionRouter = createTRPCRouter({
const checkout = await createCheckout({
productId: input.productId,
organizationId: input.organizationId,
projectId: input.projectId ?? undefined,
user,
ipAddress: ctx.req.ip,
});