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

from ..core.unchecked_base_model import UncheckedBaseModel
import typing
import pydantic
from .tender import Tender
from .refund import Refund
from .transaction_product import TransactionProduct
from .address import Address
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class Transaction(UncheckedBaseModel):
    """
    Represents a transaction processed with Square, either with the
    Connect API or with Square Point of Sale.

    The `tenders` field of this object lists all methods of payment used to pay in
    the transaction.
    """

    id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The transaction's unique ID, issued by Square payments servers.
    """

    location_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The ID of the transaction's associated location.
    """

    created_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The timestamp for when the transaction was created, in RFC 3339 format.
    """

    tenders: typing.Optional[typing.List[Tender]] = pydantic.Field(default=None)
    """
    The tenders used to pay in the transaction.
    """

    refunds: typing.Optional[typing.List[Refund]] = pydantic.Field(default=None)
    """
    Refunds that have been applied to any tender in the transaction.
    """

    reference_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    If the transaction was created with the [Charge](api-endpoint:Transactions-Charge)
    endpoint, this value is the same as the value provided for the `reference_id`
    parameter in the request to that endpoint. Otherwise, it is not set.
    """

    product: typing.Optional[TransactionProduct] = pydantic.Field(default=None)
    """
    The Square product that processed the transaction.
    See [TransactionProduct](#type-transactionproduct) for possible values
    """

    client_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    If the transaction was created in the Square Point of Sale app, this value
    is the ID generated for the transaction by Square Point of Sale.
    
    This ID has no relationship to the transaction's canonical `id`, which is
    generated by Square's backend servers. This value is generated for bookkeeping
    purposes, in case the transaction cannot immediately be completed (for example,
    if the transaction is processed in offline mode).
    
    It is not currently possible with the Connect API to perform a transaction
    lookup by this value.
    """

    shipping_address: typing.Optional[Address] = pydantic.Field(default=None)
    """
    The shipping address provided in the request, if any.
    """

    order_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The order_id is an identifier for the order associated with this transaction, if any.
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
