def METHOD_NAME(
    cls, transaction_item: payment_models.TransactionItem
) -> Union[checkout_models.Checkout, order_models.Order]:
    if transaction_item.checkout_id:
        checkout = cast(checkout_models.Checkout, transaction_item.checkout)
        return checkout
    if transaction_item.order_id:
        order = cast(order_models.Order, transaction_item.order)
        return order
    raise ValidationError(
        {
            "id": ValidationError(
                "Transaction doesn't have attached order or checkout.",
                code=TransactionProcessErrorCode.INVALID.value,
            )
        }
    )