Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

small updates

Steven Teybe722a7ca12b
diff --git a/apps/web/.env.example b/apps/web/.env.example
index 9057687c70..4f0040e952 100644
--- a/apps/web/.env.example
+++ b/apps/web/.env.example
@@ -55,7 +55,6 @@ STRIPE_WEBHOOK_SECRET=
# Stripe App
STRIPE_APP_CLIENT_ID=
-STRIPE_APP_REDIRECT_URI=
STRIPE_APP_WEBHOOK_SECRET=
# Used for Google Login
diff --git a/apps/web/app/api/campaigns/connect-stripe/route.ts b/apps/web/app/api/campaigns/connect-stripe/route.ts
index 6cbf527c31..b893d88286 100644
--- a/apps/web/app/api/campaigns/connect-stripe/route.ts
+++ b/apps/web/app/api/campaigns/connect-stripe/route.ts
@@ -2,13 +2,12 @@ import { DubApiError } from "@/lib/api/errors";
import { withWorkspace } from "@/lib/auth";
import { redis } from "@/lib/upstash";
import z from "@/lib/zod";
-import { nanoid } from "@dub/utils";
+import { APP_DOMAIN_WITH_NGROK, nanoid } from "@dub/utils";
import { NextResponse } from "next/server";
const envSchema = z.object({
STRIPE_APP_INSTALL_URL: z.string(),
STRIPE_APP_CLIENT_ID: z.string(),
- STRIPE_APP_REDIRECT_URI: z.string(),
STRIPE_APP_WEBHOOK_SECRET: z.string(),
});
@@ -27,15 +26,14 @@ export const POST = withWorkspace(async ({ workspace }) => {
});
}
- const {
- STRIPE_APP_INSTALL_URL,
- STRIPE_APP_CLIENT_ID,
- STRIPE_APP_REDIRECT_URI,
- } = env.data;
+ const { STRIPE_APP_INSTALL_URL, STRIPE_APP_CLIENT_ID } = env.data;
const url = new URL(STRIPE_APP_INSTALL_URL);
url.searchParams.set("client_id", STRIPE_APP_CLIENT_ID);
- url.searchParams.set("redirect_uri", STRIPE_APP_REDIRECT_URI);
+ url.searchParams.set(
+ "redirect_uri",
+ `${APP_DOMAIN_WITH_NGROK}/api/campaigns/callback/stripe`,
+ );
url.searchParams.set("state", state);
console.log("Redirecting to", url.toString());
diff --git a/apps/web/app/api/campaigns/webhooks/stripe/customer-created.ts b/apps/web/app/api/campaigns/webhooks/stripe/customer-created.ts
index e506cf1c2d..da668abdb2 100644
--- a/apps/web/app/api/campaigns/webhooks/stripe/customer-created.ts
+++ b/apps/web/app/api/campaigns/webhooks/stripe/customer-created.ts
@@ -23,6 +23,7 @@ export async function customerCreated(event: Stripe.Event) {
}
// Check the customer is not already created
+ // Find customer using projectConnectId and externalId (the customer's ID in the client app)
const customerFound = await prisma.customer.findFirst({
where: {
projectConnectId: stripeAccountId,
diff --git a/apps/web/app/api/campaigns/webhooks/stripe/invoice-paid.ts b/apps/web/app/api/campaigns/webhooks/stripe/invoice-paid.ts
index 9d3e481918..0ca2ecb928 100644
--- a/apps/web/app/api/campaigns/webhooks/stripe/invoice-paid.ts
+++ b/apps/web/app/api/campaigns/webhooks/stripe/invoice-paid.ts
@@ -11,7 +11,7 @@ export async function invoicePaid(event: Stripe.Event) {
const stripeCustomerId = invoice.customer as string;
const invoiceId = invoice.id;
- // Find customer
+ // Find customer using projectConnectId and stripeCustomerId
const customer = await prisma.customer.findFirst({
where: {
projectConnectId: stripeAccountId,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx
index fb176a2938..07a4f6d916 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx
@@ -5,7 +5,9 @@ import DeleteWorkspace from "@/ui/workspaces/delete-workspace";
import UploadLogo from "@/ui/workspaces/upload-logo";
import WorkspaceId from "@/ui/workspaces/workspace-id";
import { Form } from "@dub/ui";
+import { Button } from "@dub/ui/src/button";
import { useRouter } from "next/navigation";
+import { useEffect, useState } from "react";
import { toast } from "sonner";
import { mutate } from "swr";
@@ -13,7 +15,10 @@ export default function WorkspaceSettingsClient() {
const router = useRouter();
const { id, name, slug, isOwner } = useWorkspace();
+ const [redirecting, setRedirecting] = useState(false);
+
const redirectToStripe = async () => {
+ setRedirecting(true);
const response = await fetch(
`/api/campaigns/connect-stripe?workspaceId=${id}`,
{
@@ -29,15 +34,22 @@ export default function WorkspaceSettingsClient() {
window.location.href = url;
};
+ useEffect(() => {
+ // when leave page, reset state
+ return () => {
+ setRedirecting(false);
+ };
+ }, []);
+
return (
<>
{/* TODO: Move the button to proper place */}
- <button
+ <Button
+ text="Connect to Stripe"
+ loading={redirecting}
onClick={redirectToStripe}
- className="group flex h-10 w-44 items-center justify-center space-x-2 rounded-md border border-black bg-black px-4 text-sm text-white"
- >
- Connect to Stripe
- </button>
+ className="max-w-xs"
+ />
<Form
title="Workspace Name"
description={`This is the name of your workspace on ${process.env.NEXT_PUBLIC_APP_NAME}.`}
diff --git a/packages/stripe-app/stripe-app.json b/packages/stripe-app/stripe-app.json
index 4675dcf8c2..19a04c75ca 100644
--- a/packages/stripe-app/stripe-app.json
+++ b/packages/stripe-app/stripe-app.json
@@ -45,8 +45,9 @@
}
},
"allowed_redirect_uris": [
- "https://6dc0-103-70-36-143.ngrok-free.app/api/campaigns/callback/stripe"
+ "https://6dc0-103-70-36-143.ngrok-free.app/api/campaigns/callback/stripe",
+ "https://rich-easily-kingfish.ngrok-free.app/api/campaigns/callback/stripe"
],
"stripe_api_access_type": "oauth",
"distribution_type": "public"
-}
\ No newline at end of file
+}