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

import typing_extensions
import typing_extensions
from .money import MoneyParams
import typing
from .processing_fee import ProcessingFeeParams
from .card_payment_details import CardPaymentDetailsParams
from .cash_payment_details import CashPaymentDetailsParams
from .bank_account_payment_details import BankAccountPaymentDetailsParams
from .external_payment_details import ExternalPaymentDetailsParams
from .digital_wallet_details import DigitalWalletDetailsParams
from .buy_now_pay_later_details import BuyNowPayLaterDetailsParams
from .square_account_details import SquareAccountDetailsParams
from .risk_evaluation import RiskEvaluationParams
from .address import AddressParams
from .device_details import DeviceDetailsParams
from .application_details import ApplicationDetailsParams
from .offline_payment_details import OfflinePaymentDetailsParams


class PaymentParams(typing_extensions.TypedDict):
    """
    Represents a payment processed by the Square API.
    """

    id: typing_extensions.NotRequired[str]
    """
    A unique ID for the payment.
    """

    created_at: typing_extensions.NotRequired[str]
    """
    The timestamp of when the payment was created, in RFC 3339 format.
    """

    updated_at: typing_extensions.NotRequired[str]
    """
    The timestamp of when the payment was last updated, in RFC 3339 format.
    """

    amount_money: typing_extensions.NotRequired[MoneyParams]
    """
    The amount processed for this payment, not including `tip_money`.
    
    The amount is specified in the smallest denomination of the applicable currency (for example,
    US dollar amounts are specified in cents). For more information, see
    [Working with Monetary Amounts](https://developer.squareup.com/docs/build-basics/working-with-monetary-amounts).
    """

    tip_money: typing_extensions.NotRequired[MoneyParams]
    """
    The amount designated as a tip. 
    
    This amount is specified in the smallest denomination of the applicable currency (for example,
    US dollar amounts are specified in cents). For more information, see
    [Working with Monetary Amounts](https://developer.squareup.com/docs/build-basics/working-with-monetary-amounts).
    """

    total_money: typing_extensions.NotRequired[MoneyParams]
    """
    The total amount for the payment, including `amount_money` and `tip_money`.
    This amount is specified in the smallest denomination of the applicable currency (for example,
    US dollar amounts are specified in cents). For more information, see
    [Working with Monetary Amounts](https://developer.squareup.com/docs/build-basics/working-with-monetary-amounts).
    """

    app_fee_money: typing_extensions.NotRequired[MoneyParams]
    """
    The amount the developer is taking as a fee for facilitating the payment on behalf
    of the seller. This amount is specified in the smallest denomination of the applicable currency
    (for example, US dollar amounts are specified in cents). For more information,
    see [Take Payments and Collect Fees](https://developer.squareup.com/docs/payments-api/take-payments-and-collect-fees).
    
    The amount cannot be more than 90% of the `total_money` value.
    
    To set this field, `PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS` OAuth permission is required.
    For more information, see [Permissions](https://developer.squareup.com/docs/payments-api/take-payments-and-collect-fees#permissions).
    """

    approved_money: typing_extensions.NotRequired[MoneyParams]
    """
    The amount of money approved for this payment. This value may change if Square chooses to
    obtain reauthorization as part of a call to [UpdatePayment](api-endpoint:Payments-UpdatePayment).
    """

    processing_fee: typing_extensions.NotRequired[typing.Sequence[ProcessingFeeParams]]
    """
    The processing fees and fee adjustments assessed by Square for this payment.
    """

    refunded_money: typing_extensions.NotRequired[MoneyParams]
    """
    The total amount of the payment refunded to date. 
    
    This amount is specified in the smallest denomination of the applicable currency (for example,
    US dollar amounts are specified in cents).
    """

    status: typing_extensions.NotRequired[str]
    """
    Indicates whether the payment is APPROVED, PENDING, COMPLETED, CANCELED, or FAILED.
    """

    delay_duration: typing_extensions.NotRequired[str]
    """
    The duration of time after the payment's creation when Square automatically applies the
    `delay_action` to the payment. This automatic `delay_action` applies only to payments that
    do not reach a terminal state (COMPLETED, CANCELED, or FAILED) before the `delay_duration`
    time period.
    
    This field is specified as a time duration, in RFC 3339 format.
    
    Notes:
    This feature is only supported for card payments.
    
    Default:
    
    - Card-present payments: "PT36H" (36 hours) from the creation time.
    - Card-not-present payments: "P7D" (7 days) from the creation time.
    """

    delay_action: typing_extensions.NotRequired[typing.Optional[str]]
    """
    The action to be applied to the payment when the `delay_duration` has elapsed.
    
    Current values include `CANCEL` and `COMPLETE`.
    """

    delayed_until: typing_extensions.NotRequired[str]
    """
    The read-only timestamp of when the `delay_action` is automatically applied,
    in RFC 3339 format.
    
    Note that this field is calculated by summing the payment's `delay_duration` and `created_at`
    fields. The `created_at` field is generated by Square and might not exactly match the
    time on your local machine.
    """

    source_type: typing_extensions.NotRequired[str]
    """
    The source type for this payment.
    
    Current values include `CARD`, `BANK_ACCOUNT`, `WALLET`, `BUY_NOW_PAY_LATER`, `SQUARE_ACCOUNT`,
    `CASH` and `EXTERNAL`. For information about these payment source types,
    see [Take Payments](https://developer.squareup.com/docs/payments-api/take-payments).
    """

    card_details: typing_extensions.NotRequired[CardPaymentDetailsParams]
    """
    Details about a card payment. These details are only populated if the source_type is `CARD`.
    """

    cash_details: typing_extensions.NotRequired[CashPaymentDetailsParams]
    """
    Details about a cash payment. These details are only populated if the source_type is `CASH`.
    """

    bank_account_details: typing_extensions.NotRequired[BankAccountPaymentDetailsParams]
    """
    Details about a bank account payment. These details are only populated if the source_type is `BANK_ACCOUNT`.
    """

    external_details: typing_extensions.NotRequired[ExternalPaymentDetailsParams]
    """
    Details about an external payment. The details are only populated 
    if the `source_type` is `EXTERNAL`.
    """

    wallet_details: typing_extensions.NotRequired[DigitalWalletDetailsParams]
    """
    Details about an wallet payment. The details are only populated 
    if the `source_type` is `WALLET`.
    """

    buy_now_pay_later_details: typing_extensions.NotRequired[BuyNowPayLaterDetailsParams]
    """
    Details about a Buy Now Pay Later payment. The details are only populated
    if the `source_type` is `BUY_NOW_PAY_LATER`. For more information, see 
    [Afterpay Payments](https://developer.squareup.com/docs/payments-api/take-payments/afterpay-payments).
    """

    square_account_details: typing_extensions.NotRequired[SquareAccountDetailsParams]
    """
    Details about a Square Account payment. The details are only populated
    if the `source_type` is `SQUARE_ACCOUNT`.
    """

    location_id: typing_extensions.NotRequired[str]
    """
    The ID of the location associated with the payment.
    """

    order_id: typing_extensions.NotRequired[str]
    """
    The ID of the order associated with the payment.
    """

    reference_id: typing_extensions.NotRequired[str]
    """
    An optional ID that associates the payment with an entity in
    another system.
    """

    customer_id: typing_extensions.NotRequired[str]
    """
    The ID of the customer associated with the payment. If the ID is 
    not provided in the `CreatePayment` request that was used to create the `Payment`, 
    Square may use information in the request 
    (such as the billing and shipping address, email address, and payment source) 
    to identify a matching customer profile in the Customer Directory. 
    If found, the profile ID is used. If a profile is not found, the 
    API attempts to create an 
    [instant profile](https://developer.squareup.com/docs/customers-api/what-it-does#instant-profiles). 
    If the API cannot create an 
    instant profile (either because the seller has disabled it or the 
    seller's region prevents creating it), this field remains unset. Note that 
    this process is asynchronous and it may take some time before a 
    customer ID is added to the payment.
    """

    employee_id: typing_extensions.NotRequired[str]
    """
    __Deprecated__: Use `Payment.team_member_id` instead.
    
    An optional ID of the employee associated with taking the payment.
    """

    team_member_id: typing_extensions.NotRequired[typing.Optional[str]]
    """
    An optional ID of the [TeamMember](entity:TeamMember) associated with taking the payment.
    """

    refund_ids: typing_extensions.NotRequired[typing.Sequence[str]]
    """
    A list of `refund_id`s identifying refunds for the payment.
    """

    risk_evaluation: typing_extensions.NotRequired[RiskEvaluationParams]
    """
    Provides information about the risk associated with the payment, as determined by Square.
    This field is present for payments to sellers that have opted in to receive risk
    evaluations.
    """

    terminal_checkout_id: typing_extensions.NotRequired[str]
    """
    An optional ID for a Terminal checkout that is associated with the payment.
    """

    buyer_email_address: typing_extensions.NotRequired[str]
    """
    The buyer's email address.
    """

    billing_address: typing_extensions.NotRequired[AddressParams]
    """
    The buyer's billing address.
    """

    shipping_address: typing_extensions.NotRequired[AddressParams]
    """
    The buyer's shipping address.
    """

    note: typing_extensions.NotRequired[str]
    """
    An optional note to include when creating a payment.
    """

    statement_description_identifier: typing_extensions.NotRequired[str]
    """
    Additional payment information that gets added to the customer's card statement
    as part of the statement description.
    
    Note that the `statement_description_identifier` might get truncated on the statement description
    to fit the required information including the Square identifier (SQ *) and the name of the
    seller taking the payment.
    """

    capabilities: typing_extensions.NotRequired[typing.Sequence[str]]
    """
    Actions that can be performed on this payment:
    - `EDIT_AMOUNT_UP` - The payment amount can be edited up.
    - `EDIT_AMOUNT_DOWN` - The payment amount can be edited down.
    - `EDIT_TIP_AMOUNT_UP` - The tip amount can be edited up.
    - `EDIT_TIP_AMOUNT_DOWN` - The tip amount can be edited down.
    - `EDIT_DELAY_ACTION` - The delay_action can be edited.
    """

    receipt_number: typing_extensions.NotRequired[str]
    """
    The payment's receipt number.
    The field is missing if a payment is canceled.
    """

    receipt_url: typing_extensions.NotRequired[str]
    """
    The URL for the payment's receipt.
    The field is only populated for COMPLETED payments.
    """

    device_details: typing_extensions.NotRequired[DeviceDetailsParams]
    """
    Details about the device that took the payment.
    """

    application_details: typing_extensions.NotRequired[ApplicationDetailsParams]
    """
    Details about the application that took the payment.
    """

    is_offline_payment: typing_extensions.NotRequired[bool]
    """
    Whether or not this payment was taken offline.
    """

    offline_payment_details: typing_extensions.NotRequired[OfflinePaymentDetailsParams]
    """
    Additional information about the payment if it was taken offline.
    """

    version_token: typing_extensions.NotRequired[typing.Optional[str]]
    """
    Used for optimistic concurrency. This opaque token identifies a specific version of the
    `Payment` object.
    """
