# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations from typing import Iterable, Optional from typing_extensions import Literal import httpx from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( to_raw_response_wrapper, to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) from ...types.dir import reference_create_params, reference_update_params from ..._base_client import make_request_options from ...types.dir.reference_list import ReferenceList from ...types.dir.reference_input_param import ReferenceInputParam from ...types.dir.reference_update_response import ReferenceUpdateResponse __all__ = ["ReferencesResource", "AsyncReferencesResource"] class ReferencesResource(SyncAPIResource): """ Submit and manage the two business references and one financial reference that vouch for a DIR. References are contacted to confirm the business identity during vetting. References (two business references and one financial reference) are needed only if the documents uploaded with the DIR don't already prove the business is legitimate and financially stable. Any one of these is enough proof: audited or certified financial statements (uploaded as `other`, with a description), a commercial credit report (uploaded as `business_credit_report`), or references. Telnyx reviewers decide during vetting whether your documents are enough. """ @cached_property def with_raw_response(self) -> ReferencesResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return ReferencesResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> ReferencesResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return ReferencesResourceWithStreamingResponse(self) def create( self, dir_id: str, *, business_references: Iterable[ReferenceInputParam], financial_reference: ReferenceInputParam, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ReferenceList: """ Submit the two business references and one financial reference for a DIR. References (two business references and one financial reference) are needed only if the documents uploaded with the DIR don't already prove the business is legitimate and financially stable. Any one of these is enough proof: audited or certified financial statements (uploaded as `other`, with a description), a commercial credit report (uploaded as `business_credit_report`), or references. Telnyx reviewers decide during vetting whether your documents are enough. References can't be changed while the DIR is `verified`. Update the DIR first, which returns it to draft. The request body carries exactly two business references plus one financial reference. The first submission stores them and returns `201`. Resubmitting returns `200`: identical values are simply confirmed and nothing is written, while changed values replace those references. A replaced reference's pending verification call is cancelled and its dial-in code stops working, and the replacement contact is emailed fresh scheduling details. References whose details did not change keep their existing call, code, and the notice already sent to them. The response always echoes the stored references in the same shape as the GET. Who qualifies: the two business references confirm the company's reputation and operations. Each should be a senior contact at an organization the business works with, such as a vendor, partner, or client: a C-suite executive (CEO, CFO, CTO, COO), an owner or founder as reflected in the company's corporate records, or a senior manager, director, or executive. The financial reference confirms the company pays its bills and should be a licensed certified public accountant (CPA) the company uses, a contact at a bank or financial institution that has a relationship with the company, or a reasonable alternative banking or financial reference. Args: business_references: Exactly two business references. Array order determines each one's slot: the first entry becomes slot 1 and the second becomes slot 2. Those slots are what you pass when updating a single reference later. Each should be a senior contact who can speak to your company's reputation and operations: a C-suite executive (CEO, CFO, CTO, COO), an owner or founder as reflected in your corporate records, or a senior manager, director, or executive at an organization you work with, such as a vendor, partner, or client. financial_reference: One reference supplied at submit. The reference type is implied by the field that carries it (business_references vs financial_reference). extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not dir_id: raise ValueError(f"Expected a non-empty value for `dir_id` but received {dir_id!r}") return self._post( path_template("/dir/{dir_id}/references", dir_id=dir_id), body=maybe_transform( { "business_references": business_references, "financial_reference": financial_reference, }, reference_create_params.ReferenceCreateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ReferenceList, ) def update( self, slot: int, *, dir_id: str, ref_type: Literal["business", "financial"], email: str | Omit = omit, full_name: str | Omit = omit, job_title: Optional[str] | Omit = omit, organization: Optional[str] | Omit = omit, phone_e164: str | Omit = omit, relationship_to_registrant: Optional[str] | Omit = omit, timezone: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ReferenceUpdateResponse: """ Partially update one reference, addressed by the DIR id plus the reference's type (business or financial) and slot. Cosmetic fields (full name, job title, organization, relationship, email) are always editable. The phone number and timezone may only be changed while a scheduled call has not yet been dialed; if a call is in progress or all attempts are complete, those fields are locked. Changing the timezone reschedules any pending call into the new local calling window. Args: email: The reference's email address. We email them scheduling and dial-in instructions before we call, so use an address they check. full_name: The full name of the person we should contact as your reference. job_title: The reference contact's job title, for example CFO or Owner. organization: The name of the organization the reference contact works for. phone_e164: The reference's phone number in E.164 format, for example +14155550123. We call this number during their local business hours. relationship_to_registrant: How the reference contact is related to the registering business. timezone: The reference's IANA time zone, for example America/New_York. We only call during their local 8am to 9pm hours, which is why we need it. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not dir_id: raise ValueError(f"Expected a non-empty value for `dir_id` but received {dir_id!r}") if not ref_type: raise ValueError(f"Expected a non-empty value for `ref_type` but received {ref_type!r}") return self._patch( path_template("/dir/{dir_id}/references/{ref_type}/{slot}", dir_id=dir_id, ref_type=ref_type, slot=slot), body=maybe_transform( { "email": email, "full_name": full_name, "job_title": job_title, "organization": organization, "phone_e164": phone_e164, "relationship_to_registrant": relationship_to_registrant, "timezone": timezone, }, reference_update_params.ReferenceUpdateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ReferenceUpdateResponse, ) def list( self, dir_id: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ReferenceList: """ List the business and financial references submitted for a DIR. Returns the two business references (slots 1 and 2) followed by the single financial reference. Each entry carries its `ref_type` and `slot`, which together address the reference when updating it, alongside the details supplied when it was submitted (name, title, organization, relationship, phone, email, timezone). No internal identifiers are exposed. Returns an empty list when no references were submitted. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not dir_id: raise ValueError(f"Expected a non-empty value for `dir_id` but received {dir_id!r}") return self._get( path_template("/dir/{dir_id}/references", dir_id=dir_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ReferenceList, ) class AsyncReferencesResource(AsyncAPIResource): """ Submit and manage the two business references and one financial reference that vouch for a DIR. References are contacted to confirm the business identity during vetting. References (two business references and one financial reference) are needed only if the documents uploaded with the DIR don't already prove the business is legitimate and financially stable. Any one of these is enough proof: audited or certified financial statements (uploaded as `other`, with a description), a commercial credit report (uploaded as `business_credit_report`), or references. Telnyx reviewers decide during vetting whether your documents are enough. """ @cached_property def with_raw_response(self) -> AsyncReferencesResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return AsyncReferencesResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncReferencesResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return AsyncReferencesResourceWithStreamingResponse(self) async def create( self, dir_id: str, *, business_references: Iterable[ReferenceInputParam], financial_reference: ReferenceInputParam, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ReferenceList: """ Submit the two business references and one financial reference for a DIR. References (two business references and one financial reference) are needed only if the documents uploaded with the DIR don't already prove the business is legitimate and financially stable. Any one of these is enough proof: audited or certified financial statements (uploaded as `other`, with a description), a commercial credit report (uploaded as `business_credit_report`), or references. Telnyx reviewers decide during vetting whether your documents are enough. References can't be changed while the DIR is `verified`. Update the DIR first, which returns it to draft. The request body carries exactly two business references plus one financial reference. The first submission stores them and returns `201`. Resubmitting returns `200`: identical values are simply confirmed and nothing is written, while changed values replace those references. A replaced reference's pending verification call is cancelled and its dial-in code stops working, and the replacement contact is emailed fresh scheduling details. References whose details did not change keep their existing call, code, and the notice already sent to them. The response always echoes the stored references in the same shape as the GET. Who qualifies: the two business references confirm the company's reputation and operations. Each should be a senior contact at an organization the business works with, such as a vendor, partner, or client: a C-suite executive (CEO, CFO, CTO, COO), an owner or founder as reflected in the company's corporate records, or a senior manager, director, or executive. The financial reference confirms the company pays its bills and should be a licensed certified public accountant (CPA) the company uses, a contact at a bank or financial institution that has a relationship with the company, or a reasonable alternative banking or financial reference. Args: business_references: Exactly two business references. Array order determines each one's slot: the first entry becomes slot 1 and the second becomes slot 2. Those slots are what you pass when updating a single reference later. Each should be a senior contact who can speak to your company's reputation and operations: a C-suite executive (CEO, CFO, CTO, COO), an owner or founder as reflected in your corporate records, or a senior manager, director, or executive at an organization you work with, such as a vendor, partner, or client. financial_reference: One reference supplied at submit. The reference type is implied by the field that carries it (business_references vs financial_reference). extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not dir_id: raise ValueError(f"Expected a non-empty value for `dir_id` but received {dir_id!r}") return await self._post( path_template("/dir/{dir_id}/references", dir_id=dir_id), body=await async_maybe_transform( { "business_references": business_references, "financial_reference": financial_reference, }, reference_create_params.ReferenceCreateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ReferenceList, ) async def update( self, slot: int, *, dir_id: str, ref_type: Literal["business", "financial"], email: str | Omit = omit, full_name: str | Omit = omit, job_title: Optional[str] | Omit = omit, organization: Optional[str] | Omit = omit, phone_e164: str | Omit = omit, relationship_to_registrant: Optional[str] | Omit = omit, timezone: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ReferenceUpdateResponse: """ Partially update one reference, addressed by the DIR id plus the reference's type (business or financial) and slot. Cosmetic fields (full name, job title, organization, relationship, email) are always editable. The phone number and timezone may only be changed while a scheduled call has not yet been dialed; if a call is in progress or all attempts are complete, those fields are locked. Changing the timezone reschedules any pending call into the new local calling window. Args: email: The reference's email address. We email them scheduling and dial-in instructions before we call, so use an address they check. full_name: The full name of the person we should contact as your reference. job_title: The reference contact's job title, for example CFO or Owner. organization: The name of the organization the reference contact works for. phone_e164: The reference's phone number in E.164 format, for example +14155550123. We call this number during their local business hours. relationship_to_registrant: How the reference contact is related to the registering business. timezone: The reference's IANA time zone, for example America/New_York. We only call during their local 8am to 9pm hours, which is why we need it. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not dir_id: raise ValueError(f"Expected a non-empty value for `dir_id` but received {dir_id!r}") if not ref_type: raise ValueError(f"Expected a non-empty value for `ref_type` but received {ref_type!r}") return await self._patch( path_template("/dir/{dir_id}/references/{ref_type}/{slot}", dir_id=dir_id, ref_type=ref_type, slot=slot), body=await async_maybe_transform( { "email": email, "full_name": full_name, "job_title": job_title, "organization": organization, "phone_e164": phone_e164, "relationship_to_registrant": relationship_to_registrant, "timezone": timezone, }, reference_update_params.ReferenceUpdateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ReferenceUpdateResponse, ) async def list( self, dir_id: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ReferenceList: """ List the business and financial references submitted for a DIR. Returns the two business references (slots 1 and 2) followed by the single financial reference. Each entry carries its `ref_type` and `slot`, which together address the reference when updating it, alongside the details supplied when it was submitted (name, title, organization, relationship, phone, email, timezone). No internal identifiers are exposed. Returns an empty list when no references were submitted. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not dir_id: raise ValueError(f"Expected a non-empty value for `dir_id` but received {dir_id!r}") return await self._get( path_template("/dir/{dir_id}/references", dir_id=dir_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ReferenceList, ) class ReferencesResourceWithRawResponse: def __init__(self, references: ReferencesResource) -> None: self._references = references self.create = to_raw_response_wrapper( references.create, ) self.update = to_raw_response_wrapper( references.update, ) self.list = to_raw_response_wrapper( references.list, ) class AsyncReferencesResourceWithRawResponse: def __init__(self, references: AsyncReferencesResource) -> None: self._references = references self.create = async_to_raw_response_wrapper( references.create, ) self.update = async_to_raw_response_wrapper( references.update, ) self.list = async_to_raw_response_wrapper( references.list, ) class ReferencesResourceWithStreamingResponse: def __init__(self, references: ReferencesResource) -> None: self._references = references self.create = to_streamed_response_wrapper( references.create, ) self.update = to_streamed_response_wrapper( references.update, ) self.list = to_streamed_response_wrapper( references.list, ) class AsyncReferencesResourceWithStreamingResponse: def __init__(self, references: AsyncReferencesResource) -> None: self._references = references self.create = async_to_streamed_response_wrapper( references.create, ) self.update = async_to_streamed_response_wrapper( references.update, ) self.list = async_to_streamed_response_wrapper( references.list, )