The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
display SignInView
Kiran Ka96b7bf682dd
diff --git a/packages/stripe-app/src/icon.svg b/packages/stripe-app/src/icon.svgnew file mode 100644index 0000000000..c980d7e75d--- /dev/null+++ b/packages/stripe-app/src/icon.svg@@ -0,0 +1,3 @@+<svg width="65" height="64" viewBox="0 0 65 64" fill="none" xmlns="http://www.w3.org/2000/svg">+<path fill-rule="evenodd" clip-rule="evenodd" d="M32.5 64C50.1731 64 64.5 49.6731 64.5 32C64.5 20.1555 58.0648 9.81393 48.5 4.28099V31.9999V47.9998H40.5V45.8594C38.1466 47.2207 35.4143 47.9999 32.5 47.9999C23.6634 47.9999 16.5 40.8364 16.5 31.9999C16.5 23.1633 23.6634 15.9999 32.5 15.9999C35.4143 15.9999 38.1466 16.779 40.5 18.1404V1.00812C37.943 0.350018 35.2624 0 32.5 0C14.8269 0 0.500038 14.3269 0.500038 32C0.500038 49.6731 14.8269 64 32.5 64Z" fill="black"/>+</svg>\ No newline at end of filediff --git a/packages/stripe-app/src/utils/secrets.ts b/packages/stripe-app/src/utils/secrets.tsnew file mode 100644index 0000000000..614bfa095a--- /dev/null+++ b/packages/stripe-app/src/utils/secrets.ts@@ -0,0 +1,42 @@+import Stripe from "stripe";++type SecretName = "token" | "workspace";++// Secrets are stored on account level+const scope: Stripe.Apps.SecretCreateParams.Scope = {+ type: "account",+};++// Set a secret for the account+export async function setSecret({+ stripe,+ name,+ payload,+}: {+ stripe: Stripe;+ name: SecretName;+ payload: string;+}) {+ return await stripe.apps.secrets.create({+ name,+ payload,+ scope,+ });+}++// Get a secret for the account+export async function getSecret<T>({+ stripe,+ name,+}: {+ stripe: Stripe;+ name: SecretName;+}) {+ const secret = await stripe.apps.secrets.find({+ name,+ scope,+ expand: ["payload"],+ });++ return secret as T;+}diff --git a/packages/stripe-app/src/utils/types.ts b/packages/stripe-app/src/utils/types.tsnew file mode 100644index 0000000000..46d289fabe--- /dev/null+++ b/packages/stripe-app/src/utils/types.ts@@ -0,0 +1,13 @@+export interface Token {+ access_token: string;+ refresh_token: string;+ token_type: string;+ expires_in: number;+ scope: string;+}++export interface Workspace {+ id: string;+ name: string;+ logo: string;+}diff --git a/packages/stripe-app/src/views/AppSettings.tsx b/packages/stripe-app/src/views/AppSettings.tsxindex 66e12d4cd4..ae4f4e9048 100644--- a/packages/stripe-app/src/views/AppSettings.tsx+++ b/packages/stripe-app/src/views/AppSettings.tsx@@ -1,11 +1,21 @@import type { ExtensionContextValue } from "@stripe/ui-extension-sdk/context";import {- Box,- Icon,- Inline,- Link,- SettingsView,-} from "@stripe/ui-extension-sdk/ui";+ createHttpClient,+ STRIPE_API_KEY,+} from "@stripe/ui-extension-sdk/http_client";+import { Link, SignInView } from "@stripe/ui-extension-sdk/ui";+import { useEffect } from "react";+import Stripe from "stripe";+import appIcon from "../icon.svg";+import { getSecret } from "../utils/secrets";+import { Token } from "../utils/types";++// You don't need an API Key here, because the app uses the+// dashboard credentials to make requests.+const stripe: Stripe = new Stripe(STRIPE_API_KEY, {+ httpClient: createHttpClient() as Stripe.HttpClient,+ apiVersion: "2023-08-16",+});const AppSettings = ({userContext,@@ -20,36 +30,73 @@ const AppSettings = ({oauthContext,});+ useEffect(() => {+ // setSecret({+ // stripe,+ // name: "token",+ // payload: JSON.stringify({+ // access_token: "123",+ // refresh_token: "456",+ // token_type: "Bearer",+ // expires_in: 3600,+ // scope: "read_write",+ // }),+ // });++ getSecret<Token>({+ stripe,+ name: "token",+ });+ }, []);+return (- <SettingsView onSave={() => {}}>- <Box- css={{- background: "container",- borderRadius: "medium",- padding: "large",- }}- >- <Box css={{ marginBottom: "small" }}>- <Icon name="settings" size="medium" />- </Box>- Hello there- <Inline css={{ fontFamily: "monospace" }}>- src/views/AppSettings.tsx- </Inline>{" "}- and save to reload this view.- <Link- target="_blank"- href={- "https://stripe.com/docs/stripe-apps/build-test-views#add-application-settings"- }- >- <Box css={{ marginTop: "medium" }}>- Adding application settings <Icon name="arrowRight" size="xsmall" />- </Box>- </Link>- </Box>- </SettingsView>+ <SignInView+ description="Connect your Dub workspace with Stripe to start tracking the conversions."+ primaryAction={{+ label: "Connect workspace",+ href: "https://example.com",+ }}+ footerContent={+ <>+ Don't have an Dub account?{" "}+ <Link href="https://app.dub.co/register">Sign up</Link>+ </>+ }+ brandColor="#000000"+ brandIcon={appIcon}+ />);++ // return (+ // <SettingsView onSave={() => {}}>+ // <Box+ // css={{+ // background: "container",+ // borderRadius: "medium",+ // padding: "large",+ // }}+ // >+ // <Box css={{ marginBottom: "small" }}>+ // <Icon name="settings" size="medium" />+ // </Box>+ // Hello there+ // <Inline css={{ fontFamily: "monospace" }}>+ // src/views/AppSettings.tsx+ // </Inline>{" "}+ // and save to reload this view.+ // <Link+ // target="_blank"+ // href={+ // "https://stripe.com/docs/stripe-apps/build-test-views#add-application-settings"+ // }+ // >+ // <Box css={{ marginTop: "medium" }}>+ // Adding application settings <Icon name="arrowRight" size="xsmall" />+ // </Box>+ // </Link>+ // </Box>+ // </SettingsView>+ // );};export default AppSettings;diff --git a/packages/stripe-app/stripe-app.json b/packages/stripe-app/stripe-app.jsonindex 27e272b82c..416e93efd4 100644--- a/packages/stripe-app/stripe-app.json+++ b/packages/stripe-app/stripe-app.json@@ -35,6 +35,10 @@{"permission": "event_read","purpose": "Allows Dub to read event information."+ },+ {+ "permission": "secret_write",+ "purpose": "Allows storing Dub access tokens in Stripe for an account."}],"ui_extension": {