import {z} from 'zod' export type CreateApiV1AccountsAccountPersonsArgs = {account: string, body: {additional_tos_acceptances?: ({account?: ({date?: number | undefined, ip?: string | undefined, user_agent?: (string | '') | undefined}) | undefined}) | undefined, address?: ({city?: string | undefined, country?: string | undefined, line1?: string | undefined, line2?: string | undefined, postal_code?: string | undefined, state?: string | undefined}) | undefined, address_kana?: ({city?: string | undefined, country?: string | undefined, line1?: string | undefined, line2?: string | undefined, postal_code?: string | undefined, state?: string | undefined, town?: string | undefined}) | undefined, address_kanji?: ({city?: string | undefined, country?: string | undefined, line1?: string | undefined, line2?: string | undefined, postal_code?: string | undefined, state?: string | undefined, town?: string | undefined}) | undefined, dob?: ({day: number, month: number, year: number} | '') | undefined, documents?: ({company_authorization?: ({files?: (Array) | undefined}) | undefined, passport?: ({files?: (Array) | undefined}) | undefined, visa?: ({files?: (Array) | undefined}) | undefined}) | undefined, email?: string | undefined, expand?: Array | undefined, first_name?: string | undefined, first_name_kana?: string | undefined, first_name_kanji?: string | undefined, full_name_aliases?: (Array | '') | undefined, gender?: string | undefined, id_number?: string | undefined, id_number_secondary?: string | undefined, last_name?: string | undefined, last_name_kana?: string | undefined, last_name_kanji?: string | undefined, maiden_name?: string | undefined, metadata?: ({[key: string]: string} | '') | undefined, nationality?: string | undefined, person_token?: string | undefined, phone?: string | undefined, political_exposure?: ('existing' | 'none') | undefined, registered_address?: ({city?: string | undefined, country?: string | undefined, line1?: string | undefined, line2?: string | undefined, postal_code?: string | undefined, state?: string | undefined}) | undefined, relationship?: ({authorizer?: boolean | undefined, director?: boolean | undefined, executive?: boolean | undefined, legal_guardian?: boolean | undefined, owner?: boolean | undefined, percent_ownership?: (number | '') | undefined, representative?: boolean | undefined, title?: string | undefined}) | undefined, ssn_last_4?: string | undefined, us_cfpb_data?: ({ethnicity_details?: ({ethnicity?: (Array<'cuban' | 'hispanic_or_latino' | 'mexican' | 'not_hispanic_or_latino' | 'other_hispanic_or_latino' | 'prefer_not_to_answer' | 'puerto_rican'>) | undefined, ethnicity_other?: string | undefined}) | undefined, race_details?: ({race?: (Array<'african_american' | 'american_indian_or_alaska_native' | 'asian' | 'asian_indian' | 'black_or_african_american' | 'chinese' | 'ethiopian' | 'filipino' | 'guamanian_or_chamorro' | 'haitian' | 'jamaican' | 'japanese' | 'korean' | 'native_hawaiian' | 'native_hawaiian_or_other_pacific_islander' | 'nigerian' | 'other_asian' | 'other_black_or_african_american' | 'other_pacific_islander' | 'prefer_not_to_answer' | 'samoan' | 'somali' | 'vietnamese' | 'white'>) | undefined, race_other?: string | undefined}) | undefined, self_identified_gender?: string | undefined}) | undefined, verification?: ({additional_document?: ({back?: string | undefined, front?: string | undefined}) | undefined, document?: ({back?: string | undefined, front?: string | undefined}) | undefined}) | undefined}}; export type CreateApiV1AccountsAccountPersonsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const personAdditionalTosAcceptance = z.object({date: z.number().int().nullable().optional(), ip: z.string().max(5000).nullable().optional(), user_agent: z.string().max(5000).nullable().optional()}); export const personAdditionalTosAcceptances = z.object({account: personAdditionalTosAcceptance.nullable().optional()}); export const address = z.object({city: z.string().max(5000).nullable().optional(), country: z.string().max(5000).nullable().optional(), line1: z.string().max(5000).nullable().optional(), line2: z.string().max(5000).nullable().optional(), postal_code: z.string().max(5000).nullable().optional(), state: z.string().max(5000).nullable().optional()}); export const legalEntityJapanAddress = z.object({city: z.string().max(5000).nullable().optional(), country: z.string().max(5000).nullable().optional(), line1: z.string().max(5000).nullable().optional(), line2: z.string().max(5000).nullable().optional(), postal_code: z.string().max(5000).nullable().optional(), state: z.string().max(5000).nullable().optional(), town: z.string().max(5000).nullable().optional()}); export const legalEntityDob = z.object({day: z.number().int().nullable().optional(), month: z.number().int().nullable().optional(), year: z.number().int().nullable().optional()}); export const accountRequirementsAlternative = z.object({alternative_fields_due: z.array(z.string().max(5000)), original_fields_due: z.array(z.string().max(5000))}); export const accountRequirementsError = z.object({code: z.enum(["external_request", "information_missing", "invalid_address_city_state_postal_code", "invalid_address_cmra_address", "invalid_address_highway_contract_box", "invalid_address_private_mailbox", "invalid_address_registered_agent_address", "invalid_business_profile_name", "invalid_business_profile_name_denylisted", "invalid_company_name_denylisted", "invalid_dob_age_over_maximum", "invalid_dob_age_under_18", "invalid_dob_age_under_minimum", "invalid_product_description_length", "invalid_product_description_url_match", "invalid_representative_country", "invalid_signator", "invalid_statement_descriptor_business_mismatch", "invalid_statement_descriptor_denylisted", "invalid_statement_descriptor_length", "invalid_statement_descriptor_prefix_denylisted", "invalid_statement_descriptor_prefix_mismatch", "invalid_street_address", "invalid_tax_id", "invalid_tax_id_format", "invalid_tos_acceptance", "invalid_url_denylisted", "invalid_url_format", "invalid_url_web_presence_detected", "invalid_url_website_business_information_mismatch", "invalid_url_website_empty", "invalid_url_website_inaccessible", "invalid_url_website_inaccessible_geoblocked", "invalid_url_website_inaccessible_password_protected", "invalid_url_website_incomplete", "invalid_url_website_incomplete_cancellation_policy", "invalid_url_website_incomplete_customer_service_details", "invalid_url_website_incomplete_legal_restrictions", "invalid_url_website_incomplete_refund_policy", "invalid_url_website_incomplete_return_policy", "invalid_url_website_incomplete_terms_and_conditions", "invalid_url_website_incomplete_under_construction", "invalid_url_website_other", "invalid_value_other", "unsupported_business_type", "verification_directors_mismatch", "verification_document_address_mismatch", "verification_document_address_missing", "verification_document_corrupt", "verification_document_country_not_supported", "verification_document_directors_mismatch", "verification_document_dob_mismatch", "verification_document_duplicate_type", "verification_document_expired", "verification_document_failed_copy", "verification_document_failed_greyscale", "verification_document_failed_other", "verification_document_failed_test_mode", "verification_document_fraudulent", "verification_document_id_number_mismatch", "verification_document_id_number_missing", "verification_document_incomplete", "verification_document_invalid", "verification_document_issue_or_expiry_date_missing", "verification_document_manipulated", "verification_document_missing_back", "verification_document_missing_front", "verification_document_name_mismatch", "verification_document_name_missing", "verification_document_nationality_mismatch", "verification_document_not_readable", "verification_document_not_signed", "verification_document_not_uploaded", "verification_document_photo_mismatch", "verification_document_too_large", "verification_document_type_not_supported", "verification_extraneous_directors", "verification_failed_address_match", "verification_failed_authorizer_authority", "verification_failed_business_iec_number", "verification_failed_document_match", "verification_failed_id_number_match", "verification_failed_keyed_identity", "verification_failed_keyed_match", "verification_failed_name_match", "verification_failed_other", "verification_failed_representative_authority", "verification_failed_residential_address", "verification_failed_tax_id_match", "verification_failed_tax_id_not_issued", "verification_legal_entity_structure_mismatch", "verification_missing_directors", "verification_missing_executives", "verification_missing_owners", "verification_rejected_ownership_exemption_reason", "verification_requires_additional_memorandum_of_associations", "verification_requires_additional_proof_of_registration", "verification_supportability"]), reason: z.string().max(5000), requirement: z.string().max(5000)}); export const personFutureRequirements = z.object({alternatives: z.array(accountRequirementsAlternative).nullable().optional(), currently_due: z.array(z.string().max(5000)), errors: z.array(accountRequirementsError), eventually_due: z.array(z.string().max(5000)), past_due: z.array(z.string().max(5000)), pending_verification: z.array(z.string().max(5000))}); export const personRelationship = z.object({authorizer: z.boolean().nullable().optional(), director: z.boolean().nullable().optional(), executive: z.boolean().nullable().optional(), legal_guardian: z.boolean().nullable().optional(), owner: z.boolean().nullable().optional(), percent_ownership: z.number().nullable().optional(), representative: z.boolean().nullable().optional(), title: z.string().max(5000).nullable().optional()}); export const personRequirements = z.object({alternatives: z.array(accountRequirementsAlternative).nullable().optional(), currently_due: z.array(z.string().max(5000)), errors: z.array(accountRequirementsError), eventually_due: z.array(z.string().max(5000)), past_due: z.array(z.string().max(5000)), pending_verification: z.array(z.string().max(5000))}); export const personEthnicityDetails = z.object({ethnicity: z.array(z.enum(["cuban", "hispanic_or_latino", "mexican", "not_hispanic_or_latino", "other_hispanic_or_latino", "prefer_not_to_answer", "puerto_rican"])).nullable().optional(), ethnicity_other: z.string().max(5000).nullable().optional()}); export const personRaceDetails = z.object({race: z.array(z.enum(["african_american", "american_indian_or_alaska_native", "asian", "asian_indian", "black_or_african_american", "chinese", "ethiopian", "filipino", "guamanian_or_chamorro", "haitian", "jamaican", "japanese", "korean", "native_hawaiian", "native_hawaiian_or_other_pacific_islander", "nigerian", "other_asian", "other_black_or_african_american", "other_pacific_islander", "prefer_not_to_answer", "samoan", "somali", "vietnamese", "white"])).nullable().optional(), race_other: z.string().max(5000).nullable().optional()}); export const personUsCfpbData = z.object({ethnicity_details: personEthnicityDetails.nullable().optional(), race_details: personRaceDetails.nullable().optional(), self_identified_gender: z.string().max(5000).nullable().optional()}); export const fileLink = z.object({created: z.number().int(), expired: z.boolean(), expires_at: z.number().int().nullable().optional(), file: z.union([z.string().max(5000), z.lazy(() => file)]), id: z.string().max(5000), livemode: z.boolean(), metadata: z.record(z.string(), z.string().max(500)), object: z.literal("file_link"), url: z.string().max(5000).nullable().optional()}); export const file: z.ZodType = z.object({created: z.number().int(), expires_at: z.number().int().nullable().optional(), filename: z.string().max(5000).nullable().optional(), id: z.string().max(5000), links: z.object({data: z.array(fileLink), has_more: z.boolean(), object: z.literal("list"), url: z.string().max(5000)}).nullable().optional(), object: z.literal("file"), purpose: z.enum(["account_requirement", "additional_verification", "business_icon", "business_logo", "customer_signature", "dispute_evidence", "document_provider_identity_document", "finance_report_run", "financial_account_statement", "identity_document", "identity_document_downloadable", "issuing_regulatory_reporting", "pci_document", "platform_terms_of_service", "selfie", "sigma_scheduled_query", "tax_document_user_upload", "terminal_android_apk", "terminal_reader_splashscreen", "terminal_wifi_certificate", "terminal_wifi_private_key"]), size: z.number().int(), title: z.string().max(5000).nullable().optional(), type: z.string().max(5000).nullable().optional(), url: z.string().max(5000).nullable().optional()}); export const legalEntityPersonVerificationDocument = z.object({back: z.union([z.string().max(5000), file]).nullable().optional(), details: z.string().max(5000).nullable().optional(), details_code: z.string().max(5000).nullable().optional(), front: z.union([z.string().max(5000), file]).nullable().optional()}); export const legalEntityPersonVerification = z.object({additional_document: legalEntityPersonVerificationDocument.nullable().optional(), details: z.string().max(5000).nullable().optional(), details_code: z.string().max(5000).nullable().optional(), document: legalEntityPersonVerificationDocument.optional(), status: z.string().max(5000)}); export const person = z.object({account: z.string().max(5000), additional_tos_acceptances: personAdditionalTosAcceptances.optional(), address: address.optional(), address_kana: legalEntityJapanAddress.nullable().optional(), address_kanji: legalEntityJapanAddress.nullable().optional(), created: z.number().int(), dob: legalEntityDob.optional(), email: z.string().max(5000).nullable().optional(), first_name: z.string().max(5000).nullable().optional(), first_name_kana: z.string().max(5000).nullable().optional(), first_name_kanji: z.string().max(5000).nullable().optional(), full_name_aliases: z.array(z.string().max(5000)).optional(), future_requirements: personFutureRequirements.nullable().optional(), gender: z.string().nullable().optional(), id: z.string().max(5000), id_number_provided: z.boolean().optional(), id_number_secondary_provided: z.boolean().optional(), last_name: z.string().max(5000).nullable().optional(), last_name_kana: z.string().max(5000).nullable().optional(), last_name_kanji: z.string().max(5000).nullable().optional(), maiden_name: z.string().max(5000).nullable().optional(), metadata: z.record(z.string(), z.string().max(500)).optional(), nationality: z.string().max(5000).nullable().optional(), object: z.literal("person"), phone: z.string().max(5000).nullable().optional(), political_exposure: z.enum(["existing", "none"]).optional(), registered_address: address.optional(), relationship: personRelationship.optional(), requirements: personRequirements.nullable().optional(), ssn_last_4_provided: z.boolean().optional(), us_cfpb_data: personUsCfpbData.nullable().optional(), verification: legalEntityPersonVerification.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create a person * * POST /v1/accounts/{account}/persons * * Also accepts auth: bearerAuth */ export const createApiV1AccountsAccountPersons = async (args: CreateApiV1AccountsAccountPersonsArgs, options?: CreateApiV1AccountsAccountPersonsOptions) => { const {baseUrl = "https://api.stripe.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account))}/persons${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(person, await res.json()) };