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.

Fix the Stripe redirect URL in test mode (#3656)

Kiran K376af6baf2d2
diff --git a/packages/stripe-app/src/utils/constants.ts b/packages/stripe-app/src/utils/constants.ts
index 9a57d3265b..8ddf525be3 100644
--- a/packages/stripe-app/src/utils/constants.ts
+++ b/packages/stripe-app/src/utils/constants.ts
@@ -1,11 +1,5 @@
-import { StripeMode } from "./types";
-
// Dub
export const DUB_CLIENT_ID =
"dub_app_517290377fe6b4dfcc8726a7061ba9b6da1c4d7d7d75f77a";
export const DUB_HOST = "https://app.dub.co";
export const DUB_API_HOST = "https://api.dub.co";
-
-// Stripe
-export const STRIPE_MODE: StripeMode = "live";
-export const STRIPE_REDIRECT_URL = `https://dashboard.stripe.com/${STRIPE_MODE === "live" ? "" : "test/"}apps-oauth/dub.co`;
diff --git a/packages/stripe-app/src/utils/oauth.ts b/packages/stripe-app/src/utils/oauth.ts
index 66d7f759e6..69e4847750 100644
--- a/packages/stripe-app/src/utils/oauth.ts
+++ b/packages/stripe-app/src/utils/oauth.ts
@@ -1,24 +1,25 @@
import Stripe from "stripe";
-import {
- DUB_API_HOST,
- DUB_CLIENT_ID,
- DUB_HOST,
- STRIPE_REDIRECT_URL,
-} from "./constants";
+import { DUB_API_HOST, DUB_CLIENT_ID, DUB_HOST } from "./constants";
import { getSecret, setSecret } from "./secrets";
-import { Token, Workspace } from "./types";
+import { StripeMode, Token, Workspace } from "./types";
+
+function getRedirectUrl(mode: StripeMode) {
+ return `https://dashboard.stripe.com/${mode === "live" ? "" : "test/"}apps-oauth/dub.co`;
+}
// Returns the authorization URL
export function getOAuthUrl({
state,
challenge,
+ mode,
}: {
state: string;
challenge: string;
+ mode: StripeMode;
}) {
const searchParams = {
client_id: DUB_CLIENT_ID,
- redirect_uri: STRIPE_REDIRECT_URL,
+ redirect_uri: getRedirectUrl(mode),
response_type: "code",
code_challenge: challenge,
code_challenge_method: "S256",
@@ -32,21 +33,21 @@ export function getOAuthUrl({
export async function getToken({
code,
verifier,
+ mode,
}: {
code: string;
verifier: string;
+ mode: StripeMode;
}) {
- const url = `${DUB_API_HOST}/oauth/token`;
-
try {
- const response = await fetch(url, {
+ const response = await fetch(`${DUB_API_HOST}/oauth/token`, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
client_id: DUB_CLIENT_ID,
- redirect_uri: STRIPE_REDIRECT_URL,
+ redirect_uri: getRedirectUrl(mode),
grant_type: "authorization_code",
code_verifier: verifier,
code,
diff --git a/packages/stripe-app/src/views/AppSettings.tsx b/packages/stripe-app/src/views/AppSettings.tsx
index b05771b092..3060f35165 100644
--- a/packages/stripe-app/src/views/AppSettings.tsx
+++ b/packages/stripe-app/src/views/AppSettings.tsx
@@ -21,7 +21,11 @@ import {
import { deleteSecret, setSecret } from "../utils/secrets";
import { stripe } from "../utils/stripe";
-const AppSettings = ({ userContext, oauthContext }: ExtensionContextValue) => {
+const AppSettings = ({
+ userContext,
+ oauthContext,
+ environment,
+}: ExtensionContextValue) => {
const credentialsUsed = useRef(false);
const [oauthState, setOAuthState] = useState("");
const [challenge, setChallenge] = useState("");
@@ -72,7 +76,11 @@ const AppSettings = ({ userContext, oauthContext }: ExtensionContextValue) => {
return;
}
- const token = await getToken({ code, verifier });
+ const token = await getToken({
+ code,
+ verifier,
+ mode: environment.mode,
+ });
if (!token) {
return;
@@ -163,7 +171,11 @@ const AppSettings = ({ userContext, oauthContext }: ExtensionContextValue) => {
: "Connect workspace",
href: connecting
? "#"
- : getOAuthUrl({ state: oauthState, challenge }),
+ : getOAuthUrl({
+ state: oauthState,
+ challenge,
+ mode: environment.mode,
+ }),
}}
footerContent={
<>