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.

554 B
Raw Blame
/**
 * Resolve Dub customer.externalId from Stripe object metadata.
 * Precedence:
 * 1. dubCustomerExternalId
 * 2. dubCustomerId
 * 3. user_id (Lemon Squeezy customer id after LS → Stripe migration)
 */
export function getDubCustomerExternalIdFromMetadata(
  metadata?: Record<string, string> | null,
): string | undefined {
  if (!metadata) return undefined;

  const value =
    metadata.dubCustomerExternalId ||
    metadata.dubCustomerId ||
    metadata.user_id;

  if (value == null || value === "") return undefined;

  return String(value);
}