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.

create link and redirect

Kiran K08e2f74237a5
diff --git a/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/compliance-button.tsx b/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/compliance-button.tsx
index 1a5e039d92..5ca37c7bb8 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/compliance-button.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/compliance-button.tsx
@@ -1,27 +1,17 @@
-import { createDotsFlowAction } from "@/lib/actions/partners/create-dots-flow";
-import { dotsFlowConfigurations } from "@/lib/dots/styles";
-import useDotsUser from "@/lib/swr/use-dots-user";
+import { createAccountLinkAction } from "@/lib/actions/partners/create-account-link";
import { Button } from "@dub/ui";
import { useAction } from "next-safe-action/hooks";
import { toast } from "sonner";
-export const ComplianceButton = ({
- setModalState,
-}: {
- setModalState: (state: { show: boolean; iframeSrc: string }) => void;
-}) => {
- const { dotsUser } = useDotsUser();
-
- const { executeAsync, isExecuting } = useAction(createDotsFlowAction, {
- async onSuccess({ data }) {
- if (!data?.link) {
- toast.error("No link found – contact support");
+export const ComplianceButton = () => {
+ const { executeAsync, isExecuting } = useAction(createAccountLinkAction, {
+ onSuccess({ data }) {
+ if (!data?.url) {
+ toast.error("Unable to create account link. Please contact support.");
return;
}
- setModalState({
- show: true,
- iframeSrc: `${data.link}?styles=${dotsFlowConfigurations}`,
- });
+
+ window.open(data.url, "_blank");
},
onError({ error }) {
toast.error(error.serverError);
@@ -30,9 +20,9 @@ export const ComplianceButton = ({
return (
<Button
- text={dotsUser?.compliance.submitted ? "Update" : "Submit"}
+ text="Submit"
variant="secondary"
- onClick={async () => await executeAsync({ flow: "compliance" })}
+ onClick={async () => await executeAsync()}
loading={isExecuting}
className="h-8 w-fit px-2"
/>
diff --git a/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/page-client.tsx b/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/page-client.tsx
index f499ddf301..114ff7479d 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/page-client.tsx
@@ -1,6 +1,5 @@
"use client";
-import { createDotsFlowAction } from "@/lib/actions/partners/create-dots-flow";
import useDotsUser from "@/lib/swr/use-dots-user";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import usePayoutMethods from "@/lib/swr/use-payout-methods";
@@ -9,15 +8,13 @@ import { usePayoutWithdrawSheet } from "@/ui/partners/payout-withdraw-sheet";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import { CheckCircleFill, X } from "@/ui/shared/icons";
import { Button, Modal, Note, SimpleTooltipContent, Tooltip } from "@dub/ui";
-import { GiftFill, GreekTemple, MobilePhone } from "@dub/ui/src/icons";
+import { GiftFill, GreekTemple } from "@dub/ui/src/icons";
import {
cn,
currencyFormatter,
FREE_WITHDRAWAL_MINIMUM_BALANCE,
} from "@dub/utils";
-import { useAction } from "next-safe-action/hooks";
import { useState } from "react";
-import { toast } from "sonner";
import { PartnerWithdrawalsActivity } from "./activity";
import { ComplianceButton } from "./compliance-button";
import PayoutMethodCard, {
@@ -26,27 +23,14 @@ import PayoutMethodCard, {
export function WalletSettingsPageClient() {
const { partner } = usePartnerProfile();
-
const { dotsUser, isLoading, mutate } = useDotsUser();
+
const {
payoutMethods,
isLoading: payoutMethodsLoading,
mutate: mutatePayoutMethods,
} = usePayoutMethods();
- const { executeAsync, isExecuting } = useAction(createDotsFlowAction, {
- onSuccess({ data }) {
- if (!data?.link) {
- toast.error("No link found – contact support");
- return;
- }
- setModalState({ show: true, iframeSrc: data.link });
- },
- onError({ error }) {
- toast.error(error.serverError);
- },
- });
-
const [modalState, setModalState] = useState<{
show: boolean;
iframeSrc: string;
@@ -59,212 +43,227 @@ export function WalletSettingsPageClient() {
usePayoutWithdrawSheet();
return (
- <>
- {payoutWithdrawSheet}
- {modalState.show && (
- <Modal
- showModal={modalState.show}
- setShowModal={() => setModalState({ show: false, iframeSrc: "" })}
- onClose={async () => {
- await Promise.all([mutate(), mutatePayoutMethods()]);
- }}
- className="h-full w-full bg-white p-4 sm:h-[80vh] sm:max-w-md"
- >
- <button
- onClick={() => setModalState({ show: false, iframeSrc: "" })}
- className="group absolute right-4 top-8 hidden rounded-full p-2 transition-colors hover:bg-neutral-100 sm:top-4 sm:block"
- >
- <X className="size-5 text-neutral-700 transition-all group-hover:scale-110 group-active:scale-90" />
- </button>
- <iframe
- src={modalState.iframeSrc}
- className="h-full w-full rounded-lg"
- />
- </Modal>
- )}
- <div className="min-h-screen">
- {partner?.dotsUserId && dotsUser?.verified ? (
- <div className="grid grid-cols-1 gap-4">
- <div className="grid gap-4 rounded-lg border border-neutral-300 bg-white p-5">
- {dotsUser?.wallet && (
- <div className="grid divide-neutral-200 rounded-lg border border-neutral-200 bg-neutral-50 max-sm:divide-y sm:grid-cols-[repeat(2,minmax(0,1fr))] sm:divide-x">
- <div className="flex flex-col p-4">
- <div className="flex flex-wrap justify-between gap-x-5 gap-y-1">
- <div className="whitespace-nowrap p-1 text-sm text-neutral-500">
- Withdrawable balance
- </div>
- <div>
- {dotsUser ? (
- <Button
- text="Withdraw funds"
- onClick={() => setShowPayoutWithdrawSheet(true)}
- className="h-7 w-fit px-2"
- disabledTooltip={
- payoutMethods.length === 0
- ? "You need to connect a payout method first"
- : !dotsUser.compliance.submitted
- ? "You need to verify your identity first"
- : !dotsUser.wallet.withdrawable_amount
- ? "You need a positive balance to withdraw funds"
- : undefined
- }
- />
- ) : (
- <div className="h-7 w-24 animate-pulse rounded-md bg-neutral-200" />
- )}
- </div>
- </div>
- <div className="mt-6 flex grow flex-col justify-end p-1">
- <div className="flex flex-wrap items-end justify-between gap-x-4 gap-y-3">
- <div className="whitespace-nowrap text-2xl text-neutral-800">
- {currencyFormatter(
- dotsUser.wallet.withdrawable_amount / 100,
- {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- },
- )}{" "}
- USD
- </div>
- {partner.country === "US" &&
- dotsUser.wallet.withdrawable_amount > 0 && (
- <FreeWithdrawalProgress
- balance={dotsUser.wallet.withdrawable_amount}
- />
- )}
- </div>
- </div>
- </div>
- <div className="flex flex-col p-4">
- <div className="flex justify-between gap-5">
- <div className="p-1 text-sm text-neutral-500">
- Pending balance
- </div>
- </div>
- <div className="mt-6 flex grow flex-col justify-end p-1">
- {dotsUser ? (
- <div className="text-2xl text-neutral-800">
- {currencyFormatter(
- dotsUser?.wallet.pending_amount / 100,
- {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- },
- )}{" "}
- USD
- </div>
- ) : (
- <div className="h-8 w-32 animate-pulse rounded bg-neutral-200" />
- )}
- </div>
- </div>
- </div>
- )}
- {!payoutMethodsLoading && payoutMethods.length === 0 ? (
- <AnimatedEmptyState
- title="No payout methods connected"
- description="Connect a payout method to start withdrawing funds"
- cardContent={() => (
- <>
- <GreekTemple className="size-4 text-neutral-700" />
- <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
- </>
- )}
- addButton={
- <Button
- text="Connect payout method"
- onClick={() => executeAsync({ flow: "manage-payouts" })}
- loading={isExecuting}
- />
- }
- />
- ) : (
- <div className="flex flex-col gap-4">
- <div className="flex items-center justify-between">
- <p className="font-medium text-neutral-900">
- Payout methods
- </p>
- <Button
- text="Manage"
- variant="secondary"
- onClick={() => executeAsync({ flow: "manage-payouts" })}
- loading={isExecuting}
- className="h-8 w-fit px-2"
- />
- </div>
- <div className="grid gap-4">
- {payoutMethodsLoading
- ? Array.from({ length: 3 }).map((_, i) => (
- <PayoutMethodCardSkeleton key={i} />
- ))
- : payoutMethods.map(
- ({ platform, default: isDefault }) => (
- <PayoutMethodCard
- key={platform}
- platform={platform}
- isDefault={isDefault}
- />
- ),
- )}
- </div>
- </div>
- )}
- </div>
- <div className="flex items-center justify-between rounded-lg border border-neutral-200 bg-white p-4">
- <div className="flex items-center gap-3">
- <div className="flex size-12 items-center justify-center rounded-full border border-neutral-200">
- <Note className="size-5 text-neutral-700" />
- </div>
- <div>
- <p className="font-medium text-neutral-900">
- Compliance documents
- </p>
- {dotsUser.compliance.submitted ? (
- <div className="flex items-center gap-1">
- <CheckCircleFill className="size-4 text-green-600" />
- <p className="text-sm text-neutral-500">
- {partner.country === "US"
- ? "W-9 submitted"
- : "W8-BEN submitted"}
- </p>
- </div>
- ) : (
- <p className="text-sm text-neutral-500">
- W8-BEN (non-US) / W-9 (US) Required to withdraw payouts
- </p>
- )}
- </div>
- </div>
- <ComplianceButton setModalState={setModalState} />
- </div>
- <div className="my-8">
- <PartnerWithdrawalsActivity />
+ <div className="flex items-center justify-between rounded-lg border border-neutral-200 bg-white p-4">
+ <div className="flex items-center gap-3">
+ <div className="flex size-12 items-center justify-center rounded-full border border-neutral-200">
+ <Note className="size-5 text-neutral-700" />
+ </div>
+ <div>
+ <p className="font-medium text-neutral-900">Compliance documents</p>
+ {/* {dotsUser.compliance.submitted ? (
+ <div className="flex items-center gap-1">
+ <CheckCircleFill className="size-4 text-green-600" />
+ <p className="text-sm text-neutral-500">
+ {partner.country === "US"
+ ? "W-9 submitted"
+ : "W8-BEN submitted"}
+ </p>
</div>
- </div>
- ) : !isLoading ? (
- <AnimatedEmptyState
- title="Verify your phone number"
- description="Verify your phone number to set up your wallet"
- cardContent={() => (
- <>
- <MobilePhone className="size-4 text-neutral-700" />
- <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
- </>
- )}
- addButton={
- <Button
- text="Verify phone number"
- onClick={() => executeAsync({ flow: "manage-payouts" })}
- loading={isExecuting}
- />
- }
- />
- ) : (
- <LayoutLoader />
- )}
+ ) : (
+ <p className="text-sm text-neutral-500">
+ W8-BEN (non-US) / W-9 (US) Required to withdraw payouts
+ </p>
+ )} */}
+ </div>
</div>
- </>
+ <ComplianceButton />
+ </div>
);
+
+ // return (
+ // <>
+ // {payoutWithdrawSheet}
+ // {modalState.show && (
+ // <Modal
+ // showModal={modalState.show}
+ // setShowModal={() => setModalState({ show: false, iframeSrc: "" })}
+ // onClose={async () => {
+ // await Promise.all([mutate(), mutatePayoutMethods()]);
+ // }}
+ // className="h-full w-full bg-white p-4 sm:h-[80vh] sm:max-w-md"
+ // >
+ // <button
+ // onClick={() => setModalState({ show: false, iframeSrc: "" })}
+ // className="group absolute right-4 top-8 hidden rounded-full p-2 transition-colors hover:bg-neutral-100 sm:top-4 sm:block"
+ // >
+ // <X className="size-5 text-neutral-700 transition-all group-hover:scale-110 group-active:scale-90" />
+ // </button>
+ // <iframe
+ // src={modalState.iframeSrc}
+ // className="h-full w-full rounded-lg"
+ // />
+ // </Modal>
+ // )}
+
+ // <div className="min-h-screen">
+ // {partner?.dotsUserId && dotsUser?.verified ? (
+ // <div className="grid grid-cols-1 gap-4">
+ // <div className="grid gap-4 rounded-lg border border-neutral-300 bg-white p-5">
+ // {dotsUser?.wallet && (
+ // <div className="grid divide-neutral-200 rounded-lg border border-neutral-200 bg-neutral-50 max-sm:divide-y sm:grid-cols-[repeat(2,minmax(0,1fr))] sm:divide-x">
+ // <div className="flex flex-col p-4">
+ // <div className="flex flex-wrap justify-between gap-x-5 gap-y-1">
+ // <div className="whitespace-nowrap p-1 text-sm text-neutral-500">
+ // Withdrawable balance
+ // </div>
+ // <div>
+ // {dotsUser ? (
+ // <Button
+ // text="Withdraw funds"
+ // onClick={() => setShowPayoutWithdrawSheet(true)}
+ // className="h-7 w-fit px-2"
+ // disabledTooltip={
+ // payoutMethods.length === 0
+ // ? "You need to connect a payout method first"
+ // : !dotsUser.compliance.submitted
+ // ? "You need to verify your identity first"
+ // : !dotsUser.wallet.withdrawable_amount
+ // ? "You need a positive balance to withdraw funds"
+ // : undefined
+ // }
+ // />
+ // ) : (
+ // <div className="h-7 w-24 animate-pulse rounded-md bg-neutral-200" />
+ // )}
+ // </div>
+ // </div>
+ // <div className="mt-6 flex grow flex-col justify-end p-1">
+ // <div className="flex flex-wrap items-end justify-between gap-x-4 gap-y-3">
+ // <div className="whitespace-nowrap text-2xl text-neutral-800">
+ // {currencyFormatter(
+ // dotsUser.wallet.withdrawable_amount / 100,
+ // {
+ // minimumFractionDigits: 2,
+ // maximumFractionDigits: 2,
+ // },
+ // )}{" "}
+ // USD
+ // </div>
+ // {partner.country === "US" &&
+ // dotsUser.wallet.withdrawable_amount > 0 && (
+ // <FreeWithdrawalProgress
+ // balance={dotsUser.wallet.withdrawable_amount}
+ // />
+ // )}
+ // </div>
+ // </div>
+ // </div>
+ // <div className="flex flex-col p-4">
+ // <div className="flex justify-between gap-5">
+ // <div className="p-1 text-sm text-neutral-500">
+ // Pending balance
+ // </div>
+ // </div>
+ // <div className="mt-6 flex grow flex-col justify-end p-1">
+ // {dotsUser ? (
+ // <div className="text-2xl text-neutral-800">
+ // {currencyFormatter(
+ // dotsUser?.wallet.pending_amount / 100,
+ // {
+ // minimumFractionDigits: 2,
+ // maximumFractionDigits: 2,
+ // },
+ // )}{" "}
+ // USD
+ // </div>
+ // ) : (
+ // <div className="h-8 w-32 animate-pulse rounded bg-neutral-200" />
+ // )}
+ // </div>
+ // </div>
+ // </div>
+ // )}
+
+ // {!payoutMethodsLoading && payoutMethods.length === 0 ? (
+ // <AnimatedEmptyState
+ // title="No payout methods connected"
+ // description="Connect a payout method to start withdrawing funds"
+ // cardContent={() => (
+ // <>
+ // <GreekTemple className="size-4 text-neutral-700" />
+ // <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
+ // </>
+ // )}
+ // addButton={
+ // <Button
+ // text="Connect payout method"
+ // // onClick={() => executeAsync({ flow: "manage-payouts" })}
+ // loading={isExecuting}
+ // />
+ // }
+ // />
+ // ) : (
+ // <div className="flex flex-col gap-4">
+ // <div className="flex items-center justify-between">
+ // <p className="font-medium text-neutral-900">
+ // Payout methods
+ // </p>
+ // <Button
+ // text="Manage"
+ // variant="secondary"
+ // // onClick={() => executeAsync({ flow: "manage-payouts" })}
+ // loading={isExecuting}
+ // className="h-8 w-fit px-2"
+ // />
+ // </div>
+ // <div className="grid gap-4">
+ // {payoutMethodsLoading
+ // ? Array.from({ length: 3 }).map((_, i) => (
+ // <PayoutMethodCardSkeleton key={i} />
+ // ))
+ // : payoutMethods.map(
+ // ({ platform, default: isDefault }) => (
+ // <PayoutMethodCard
+ // key={platform}
+ // platform={platform}
+ // isDefault={isDefault}
+ // />
+ // ),
+ // )}
+ // </div>
+ // </div>
+ // )}
+ // </div>
+
+ // <div className="flex items-center justify-between rounded-lg border border-neutral-200 bg-white p-4">
+ // <div className="flex items-center gap-3">
+ // <div className="flex size-12 items-center justify-center rounded-full border border-neutral-200">
+ // <Note className="size-5 text-neutral-700" />
+ // </div>
+ // <div>
+ // <p className="font-medium text-neutral-900">
+ // Compliance documents
+ // </p>
+ // {dotsUser.compliance.submitted ? (
+ // <div className="flex items-center gap-1">
+ // <CheckCircleFill className="size-4 text-green-600" />
+ // <p className="text-sm text-neutral-500">
+ // {partner.country === "US"
+ // ? "W-9 submitted"
+ // : "W8-BEN submitted"}
+ // </p>
+ // </div>
+ // ) : (
+ // <p className="text-sm text-neutral-500">
+ // W8-BEN (non-US) / W-9 (US) Required to withdraw payouts
+ // </p>
+ // )}
+ // </div>
+ // </div>
+ // <ComplianceButton setModalState={setModalState} />
+ // </div>
+ // <div className="my-8">
+ // <PartnerWithdrawalsActivity />
+ // </div>
+ // </div>
+ // ) : !isLoading ? (
+ // <>Nothing here yet</>
+ // ) : (
+ // <LayoutLoader />
+ // )}
+ // </div>
+ // </>
+ // );
}
function FreeWithdrawalProgress({ balance }: { balance: number }) {
diff --git a/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/verify-phone-number.tsx b/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/verify-phone-number.tsx
deleted file mode 100644
index e001cb755f..0000000000
--- a/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/verify-phone-number.tsx
+++ /dev/null
@@ -1,104 +0,0 @@
-import usePartnerProfile from "@/lib/swr/use-partner-profile";
-import { Combobox, Input } from "@dub/ui";
-import { cn, COUNTRIES, COUNTRY_PHONE_CODES } from "@dub/utils";
-import { useMemo } from "react";
-import { useForm } from "react-hook-form";
-
-export function VerifyPhoneNumber() {
- const { partner } = usePartnerProfile();
-
- const { register, setValue, handleSubmit, watch } = useForm<{
- countryCode: string;
- phoneNumber: string;
- }>({
- defaultValues: {
- countryCode: partner?.country ?? "",
- },
- });
-
- return (
- <div>
- <p className="text-sm font-medium">
- Verify your phone number to receive payouts
- </p>
- <form
- onSubmit={handleSubmit(async (data) => {
- console.log(data);
- })}
- className="mt-2"
- >
- <div className="flex max-w-fit items-center gap-2">
- <CountryPhoneCodesCombobox
- value={watch("countryCode")}
- onChange={(value) => {
- console.log(value);
- setValue("countryCode", value);
- }}
- />
- <Input
- {...register("phoneNumber")}
- type="tel"
- className="w-60"
- placeholder="(888) 888-8888"
- />
- </div>
- </form>
- </div>
- );
-}
-
-function CountryPhoneCodesCombobox({
- value,
- onChange,
-}: {
- value: string;
- onChange: (value: string) => void;
-}) {
- const options = useMemo(
- () =>
- Object.entries(COUNTRY_PHONE_CODES).map(([key, value]) => ({
- icon: (
- <img
- alt={key}
- src={`https://flag.vercel.app/m/${key}.svg`}
- className="mr-1 h-2.5 w-4"
- />
- ),
- value: key,
- label: `${COUNTRIES[key]} +${value.toString()}`,
- })),
- [],
- );
-
- return (
- <Combobox
- selected={options.find((o) => o.value === value) ?? null}
- setSelected={(option) => {
- if (!option) return;
- onChange(option.value);
- }}
- options={options}
- icon={
- value ? (
- <img
- alt={value}
- src={`https://flag.vercel.app/m/${value}.svg`}
- className="h-2.5 w-4"
- />
- ) : undefined
- }
- caret={true}
- placeholder="Select country"
- searchPlaceholder="Search..."
- matchTriggerWidth
- buttonProps={{
- className: cn(
- "w-full justify-start border-gray-300 px-3",
- "data-[state=open]:ring-1 data-[state=open]:ring-gray-500 data-[state=open]:border-gray-500",
- "focus:ring-1 focus:ring-gray-500 focus:border-gray-500 transition-none",
- !value && "text-gray-400",
- ),
- }}
- />
- );
-}
diff --git a/apps/web/lib/actions/partners/create-account-link.ts b/apps/web/lib/actions/partners/create-account-link.ts
new file mode 100644
index 0000000000..5f67546c08
--- /dev/null
+++ b/apps/web/lib/actions/partners/create-account-link.ts
@@ -0,0 +1,22 @@
+"use server";
+
+import { createAccountLink } from "@/lib/stripe/create-account-link";
+import { authPartnerActionClient } from "../safe-action";
+
+export const createAccountLinkAction = authPartnerActionClient.action(
+ async ({ ctx }) => {
+ const { partner } = ctx;
+
+ if (!partner.stripeConnectId) {
+ throw new Error("Partner does not have a Stripe Connect account.");
+ }
+
+ const { url } = await createAccountLink({
+ stripeConnectId: partner.stripeConnectId,
+ });
+
+ return {
+ url,
+ };
+ },
+);
diff --git a/apps/web/lib/stripe/create-account-link.ts b/apps/web/lib/stripe/create-account-link.ts
new file mode 100644
index 0000000000..87837fbd0a
--- /dev/null
+++ b/apps/web/lib/stripe/create-account-link.ts
@@ -0,0 +1,20 @@
+import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";
+import { stripe } from ".";
+
+// TODO:
+// Handle the errors from the stripe API
+// refresh_url can also be a api path that generate new account link and redirect to it
+
+export const createAccountLink = async ({
+ stripeConnectId,
+}: {
+ stripeConnectId: string;
+}) => {
+ return await stripe.accountLinks.create({
+ account: stripeConnectId,
+ refresh_url: `${APP_DOMAIN_WITH_NGROK}/settings/payouts`,
+ return_url: `${APP_DOMAIN_WITH_NGROK}/settings/payouts`,
+ type: "account_onboarding",
+ collect: "eventually_due",
+ });
+};
diff --git a/apps/web/lib/stripe/create-connected-account.ts b/apps/web/lib/stripe/create-connected-account.ts
index e66887f504..fca5d84a34 100644
--- a/apps/web/lib/stripe/create-connected-account.ts
+++ b/apps/web/lib/stripe/create-connected-account.ts
@@ -2,6 +2,9 @@ import { z } from "zod";
import { stripe } from ".";
import { onboardPartnerSchema } from "../zod/schemas/partners";
+// TODO:
+// Handle the errors from the stripe API
+
export const createConnectedAccount = async ({
name,
email,
@@ -13,9 +16,6 @@ export const createConnectedAccount = async ({
>) => {
const [firstName, lastName] = name.split(" ");
- // TODO:
- // Handle the errors from the stripe API
-
return await stripe.accounts.create({
type: "express",
business_type: "individual",
diff --git a/apps/web/lib/stripe/retrieve-connected-account.ts b/apps/web/lib/stripe/retrieve-connected-account.ts
new file mode 100644
index 0000000000..501db7b406
--- /dev/null
+++ b/apps/web/lib/stripe/retrieve-connected-account.ts
@@ -0,0 +1,24 @@
+import { z } from "zod";
+import { stripe } from ".";
+
+// TODO:
+// Handle the errors from the stripe API
+
+const connectedAccountSchema = z.object({
+ id: z.string(),
+ charges_enabled: z.boolean(),
+ capabilities: z.object({
+ card_payments: z.enum(["inactive", "active"]),
+ transfers: z.enum(["inactive", "active"]),
+ }),
+});
+
+export const retrieveConnectedAccount = async ({
+ stripeConnectId,
+}: {
+ stripeConnectId: string;
+}) => {
+ const response = await stripe.accounts.retrieve(stripeConnectId);
+
+ return connectedAccountSchema.parse(response);
+};
diff --git a/apps/web/scripts/stripe-connect.ts b/apps/web/scripts/stripe-connect.ts
index c87b82bafb..4bcbbf28c5 100644
--- a/apps/web/scripts/stripe-connect.ts
+++ b/apps/web/scripts/stripe-connect.ts
@@ -34,7 +34,7 @@ async function main() {
// await createLoginLink();
// await createPayout();
- const account = await stripe.accounts.retrieve(affiliate.connectedAccountId);
+ const account = await stripe.accounts.retrieve("acct_1QVHHo2Z0L3O7iWp");
console.log("Account", account);
}