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.

662 B
Raw Blame
import { stripeAppClient } from "@/lib/stripe";
import { StripeMode } from "@/lib/types";

export async function getConnectedCustomer({
  stripeCustomerId,
  stripeAccountId,
  mode,
}: {
  stripeCustomerId?: string | null;
  stripeAccountId?: string | null;
  mode: StripeMode;
}) {
  // if stripeCustomerId or stripeAccountId is not provided, return null
  if (!stripeCustomerId || !stripeAccountId) {
    return null;
  }

  const connectedCustomer = await stripeAppClient({
    mode,
  }).customers.retrieve(stripeCustomerId, {
    stripeAccount: stripeAccountId,
  });

  if (connectedCustomer.deleted) {
    return null;
  }

  return connectedCustomer;
}