fix: checkout
This commit is contained in:
@@ -27,7 +27,6 @@ const paramsSchema = z.object({
|
|||||||
|
|
||||||
const metadataSchema = z.object({
|
const metadataSchema = z.object({
|
||||||
organizationId: z.string(),
|
organizationId: z.string(),
|
||||||
projectId: z.string(),
|
|
||||||
integrationId: z.string(),
|
integrationId: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -89,7 +88,7 @@ export async function slackWebhook(
|
|||||||
'👋 Hello. You have successfully connected OpenPanel.dev to your Slack workspace.',
|
'👋 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({
|
await db.integration.update({
|
||||||
where: {
|
where: {
|
||||||
@@ -105,7 +104,7 @@ export async function slackWebhook(
|
|||||||
});
|
});
|
||||||
|
|
||||||
return reply.redirect(
|
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) {
|
} catch (err) {
|
||||||
request.log.error(err);
|
request.log.error(err);
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function Billing({ organization }: Props) {
|
export default function Billing({ organization }: Props) {
|
||||||
const { projectId } = useAppParams();
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const trpc = useTRPC();
|
const trpc = useTRPC();
|
||||||
const [customerSessionToken, setCustomerSessionToken] = useQueryState(
|
const [customerSessionToken, setCustomerSessionToken] = useQueryState(
|
||||||
@@ -271,7 +270,6 @@ export default function Billing({ organization }: Props) {
|
|||||||
key={selectedProduct.prices[0].id}
|
key={selectedProduct.prices[0].id}
|
||||||
price={selectedProduct.prices[0]}
|
price={selectedProduct.prices[0]}
|
||||||
organization={organization}
|
organization={organization}
|
||||||
projectId={projectId}
|
|
||||||
buttonText={
|
buttonText={
|
||||||
isUpgrade
|
isUpgrade
|
||||||
? 'Upgrade'
|
? 'Upgrade'
|
||||||
@@ -350,13 +348,11 @@ export default function Billing({ organization }: Props) {
|
|||||||
function CheckoutButton({
|
function CheckoutButton({
|
||||||
price,
|
price,
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
|
||||||
disabled,
|
disabled,
|
||||||
buttonText,
|
buttonText,
|
||||||
}: {
|
}: {
|
||||||
price: IPolarPrice;
|
price: IPolarPrice;
|
||||||
organization: IServiceOrganization;
|
organization: IServiceOrganization;
|
||||||
projectId: string;
|
|
||||||
disabled?: string | null;
|
disabled?: string | null;
|
||||||
buttonText?: string;
|
buttonText?: string;
|
||||||
}) {
|
}) {
|
||||||
@@ -396,7 +392,6 @@ function CheckoutButton({
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
const createCheckout = () =>
|
const createCheckout = () =>
|
||||||
checkout.mutate({
|
checkout.mutate({
|
||||||
projectId,
|
|
||||||
organizationId: organization.id,
|
organizationId: organization.id,
|
||||||
productPriceId: price!.id,
|
productPriceId: price!.id,
|
||||||
productId: price.productId,
|
productId: price.productId,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export async function getProjectById(id: string) {
|
|||||||
export const getProjectByIdCached = cacheable(getProjectById, 60 * 60 * 24);
|
export const getProjectByIdCached = cacheable(getProjectById, 60 * 60 * 24);
|
||||||
|
|
||||||
export async function getProjectWithClients(id: string) {
|
export async function getProjectWithClients(id: string) {
|
||||||
const res = await db.project.findUnique({
|
const res = await db.$primary().project.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13,14 +13,8 @@ export const polar = new Polar({
|
|||||||
server: process.env.NODE_ENV === 'production' ? 'production' : 'sandbox',
|
server: process.env.NODE_ENV === 'production' ? 'production' : 'sandbox',
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getSuccessUrl = (
|
export const getSuccessUrl = (baseUrl: string, organizationId: string) =>
|
||||||
baseUrl: string,
|
`${baseUrl}/${organizationId}/billing`;
|
||||||
organizationId: string,
|
|
||||||
projectId?: string,
|
|
||||||
) =>
|
|
||||||
projectId
|
|
||||||
? `${baseUrl}/${organizationId}/${projectId}/settings?tab=billing`
|
|
||||||
: `${baseUrl}/${organizationId}`;
|
|
||||||
|
|
||||||
export async function getProducts() {
|
export async function getProducts() {
|
||||||
const products = await polar.products.list({
|
const products = await polar.products.list({
|
||||||
@@ -52,13 +46,11 @@ export async function createPortal({
|
|||||||
export async function createCheckout({
|
export async function createCheckout({
|
||||||
productId,
|
productId,
|
||||||
organizationId,
|
organizationId,
|
||||||
projectId,
|
|
||||||
user,
|
user,
|
||||||
ipAddress,
|
ipAddress,
|
||||||
}: {
|
}: {
|
||||||
productId: string;
|
productId: string;
|
||||||
organizationId: string;
|
organizationId: string;
|
||||||
projectId?: string;
|
|
||||||
user: {
|
user: {
|
||||||
id: string;
|
id: string;
|
||||||
firstName: string | null;
|
firstName: string | null;
|
||||||
@@ -73,7 +65,6 @@ export async function createCheckout({
|
|||||||
successUrl: getSuccessUrl(
|
successUrl: getSuccessUrl(
|
||||||
process.env.DASHBOARD_URL || process.env.NEXT_PUBLIC_DASHBOARD_URL!,
|
process.env.DASHBOARD_URL || process.env.NEXT_PUBLIC_DASHBOARD_URL!,
|
||||||
organizationId,
|
organizationId,
|
||||||
projectId,
|
|
||||||
),
|
),
|
||||||
customerEmail: user.email,
|
customerEmail: user.email,
|
||||||
customerName: [user.firstName, user.lastName].filter(Boolean).join(' '),
|
customerName: [user.firstName, user.lastName].filter(Boolean).join(' '),
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ export const subscriptionRouter = createTRPCRouter({
|
|||||||
const checkout = await createCheckout({
|
const checkout = await createCheckout({
|
||||||
productId: input.productId,
|
productId: input.productId,
|
||||||
organizationId: input.organizationId,
|
organizationId: input.organizationId,
|
||||||
projectId: input.projectId ?? undefined,
|
|
||||||
user,
|
user,
|
||||||
ipAddress: ctx.req.ip,
|
ipAddress: ctx.req.ip,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user