# This file was auto-generated by Fern from our API Definition.

from ...core.client_wrapper import SyncClientWrapper
from .raw_client import RawTransactionsClient
import typing
from ...types.sort_order import SortOrder
from ...core.request_options import RequestOptions
from ...types.list_transactions_response import ListTransactionsResponse
from ...types.get_transaction_response import GetTransactionResponse
from ...types.capture_transaction_response import CaptureTransactionResponse
from ...types.void_transaction_response import VoidTransactionResponse
from ...core.client_wrapper import AsyncClientWrapper
from .raw_client import AsyncRawTransactionsClient


class TransactionsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTransactionsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawTransactionsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawTransactionsClient
        """
        return self._raw_client

    def list(
        self,
        location_id: str,
        *,
        begin_time: typing.Optional[str] = None,
        end_time: typing.Optional[str] = None,
        sort_order: typing.Optional[SortOrder] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListTransactionsResponse:
        """
        Lists transactions for a particular location.

        Transactions include payment information from sales and exchanges and refund
        information from returns and exchanges.

        Max results per [page](https://developer.squareup.com/docs/working-with-apis/pagination): 50

        Parameters
        ----------
        location_id : str
            The ID of the location to list transactions for.

        begin_time : typing.Optional[str]
            The beginning of the requested reporting period, in RFC 3339 format.

            See [Date ranges](https://developer.squareup.com/docs/build-basics/working-with-dates) for details on date inclusivity/exclusivity.

            Default value: The current time minus one year.

        end_time : typing.Optional[str]
            The end of the requested reporting period, in RFC 3339 format.

            See [Date ranges](https://developer.squareup.com/docs/build-basics/working-with-dates) for details on date inclusivity/exclusivity.

            Default value: The current time.

        sort_order : typing.Optional[SortOrder]
            The order in which results are listed in the response (`ASC` for
            oldest first, `DESC` for newest first).

            Default value: `DESC`

        cursor : typing.Optional[str]
            A pagination cursor returned by a previous call to this endpoint.
            Provide this to retrieve the next set of results for your original query.

            See [Paginating results](https://developer.squareup.com/docs/working-with-apis/pagination) for more information.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ListTransactionsResponse
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        client.locations.transactions.list(
            location_id="location_id",
        )
        """
        response = self._raw_client.list(
            location_id,
            begin_time=begin_time,
            end_time=end_time,
            sort_order=sort_order,
            cursor=cursor,
            request_options=request_options,
        )
        return response.data

    def get(
        self, location_id: str, transaction_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetTransactionResponse:
        """
        Retrieves details for a single transaction.

        Parameters
        ----------
        location_id : str
            The ID of the transaction's associated location.

        transaction_id : str
            The ID of the transaction to retrieve.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        GetTransactionResponse
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        client.locations.transactions.get(
            location_id="location_id",
            transaction_id="transaction_id",
        )
        """
        response = self._raw_client.get(location_id, transaction_id, request_options=request_options)
        return response.data

    def capture(
        self, location_id: str, transaction_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CaptureTransactionResponse:
        """
        Captures a transaction that was created with the [Charge](api-endpoint:Transactions-Charge)
        endpoint with a `delay_capture` value of `true`.


        See [Delayed capture transactions](https://developer.squareup.com/docs/payments/transactions/overview#delayed-capture)
        for more information.

        Parameters
        ----------
        location_id : str


        transaction_id : str


        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CaptureTransactionResponse
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        client.locations.transactions.capture(
            location_id="location_id",
            transaction_id="transaction_id",
        )
        """
        response = self._raw_client.capture(location_id, transaction_id, request_options=request_options)
        return response.data

    def void(
        self, location_id: str, transaction_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> VoidTransactionResponse:
        """
        Cancels a transaction that was created with the [Charge](api-endpoint:Transactions-Charge)
        endpoint with a `delay_capture` value of `true`.


        See [Delayed capture transactions](https://developer.squareup.com/docs/payments/transactions/overview#delayed-capture)
        for more information.

        Parameters
        ----------
        location_id : str


        transaction_id : str


        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        VoidTransactionResponse
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        client.locations.transactions.void(
            location_id="location_id",
            transaction_id="transaction_id",
        )
        """
        response = self._raw_client.void(location_id, transaction_id, request_options=request_options)
        return response.data


class AsyncTransactionsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTransactionsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawTransactionsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawTransactionsClient
        """
        return self._raw_client

    async def list(
        self,
        location_id: str,
        *,
        begin_time: typing.Optional[str] = None,
        end_time: typing.Optional[str] = None,
        sort_order: typing.Optional[SortOrder] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListTransactionsResponse:
        """
        Lists transactions for a particular location.

        Transactions include payment information from sales and exchanges and refund
        information from returns and exchanges.

        Max results per [page](https://developer.squareup.com/docs/working-with-apis/pagination): 50

        Parameters
        ----------
        location_id : str
            The ID of the location to list transactions for.

        begin_time : typing.Optional[str]
            The beginning of the requested reporting period, in RFC 3339 format.

            See [Date ranges](https://developer.squareup.com/docs/build-basics/working-with-dates) for details on date inclusivity/exclusivity.

            Default value: The current time minus one year.

        end_time : typing.Optional[str]
            The end of the requested reporting period, in RFC 3339 format.

            See [Date ranges](https://developer.squareup.com/docs/build-basics/working-with-dates) for details on date inclusivity/exclusivity.

            Default value: The current time.

        sort_order : typing.Optional[SortOrder]
            The order in which results are listed in the response (`ASC` for
            oldest first, `DESC` for newest first).

            Default value: `DESC`

        cursor : typing.Optional[str]
            A pagination cursor returned by a previous call to this endpoint.
            Provide this to retrieve the next set of results for your original query.

            See [Paginating results](https://developer.squareup.com/docs/working-with-apis/pagination) for more information.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ListTransactionsResponse
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.locations.transactions.list(
                location_id="location_id",
            )


        asyncio.run(main())
        """
        response = await self._raw_client.list(
            location_id,
            begin_time=begin_time,
            end_time=end_time,
            sort_order=sort_order,
            cursor=cursor,
            request_options=request_options,
        )
        return response.data

    async def get(
        self, location_id: str, transaction_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetTransactionResponse:
        """
        Retrieves details for a single transaction.

        Parameters
        ----------
        location_id : str
            The ID of the transaction's associated location.

        transaction_id : str
            The ID of the transaction to retrieve.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        GetTransactionResponse
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.locations.transactions.get(
                location_id="location_id",
                transaction_id="transaction_id",
            )


        asyncio.run(main())
        """
        response = await self._raw_client.get(location_id, transaction_id, request_options=request_options)
        return response.data

    async def capture(
        self, location_id: str, transaction_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CaptureTransactionResponse:
        """
        Captures a transaction that was created with the [Charge](api-endpoint:Transactions-Charge)
        endpoint with a `delay_capture` value of `true`.


        See [Delayed capture transactions](https://developer.squareup.com/docs/payments/transactions/overview#delayed-capture)
        for more information.

        Parameters
        ----------
        location_id : str


        transaction_id : str


        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CaptureTransactionResponse
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.locations.transactions.capture(
                location_id="location_id",
                transaction_id="transaction_id",
            )


        asyncio.run(main())
        """
        response = await self._raw_client.capture(location_id, transaction_id, request_options=request_options)
        return response.data

    async def void(
        self, location_id: str, transaction_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> VoidTransactionResponse:
        """
        Cancels a transaction that was created with the [Charge](api-endpoint:Transactions-Charge)
        endpoint with a `delay_capture` value of `true`.


        See [Delayed capture transactions](https://developer.squareup.com/docs/payments/transactions/overview#delayed-capture)
        for more information.

        Parameters
        ----------
        location_id : str


        transaction_id : str


        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        VoidTransactionResponse
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.locations.transactions.void(
                location_id="location_id",
                transaction_id="transaction_id",
            )


        asyncio.run(main())
        """
        response = await self._raw_client.void(location_id, transaction_id, request_options=request_options)
        return response.data
