TIP Base Models

class q2_sdk.models.tip.schemas.base.TIPModel[source]

TIPModel()

DesiredTipType = ~DesiredTipType
ParserType = ~ParserType
static try_getattr_from_elem(obj_elem, attr)[source]

Safely get an attribute from an etree Element, raising TIPModelParsingException if not found.

Parameters:
  • obj_elem (Element) – The etree Element to get the attribute from

  • attr (str) – The attribute name to retrieve

Returns:

The attribute value

Raises:

TIPModelParsingException – If the attribute is not found

static parse_optional(elem, parser_func)[source]

Generic method to parse optional fields with any parser function.

Return type:

Optional[TypeVar(ParserType)]

static parse_datetime(elem)[source]

Convert a date string from elem.text that should be in iso format to datetime object.

Parameters:

elem (Union[str, datetime, StringElement, ObjectifiedElement]) – The date string

Return type:

datetime

Returns:

Parsed datetime object

Raises:

TIPModelParsingException – If the date string cannot be parsed

static parse_datetime_optional(elem)[source]

Parse optional datetime field.

Parameters:

elem (Union[str, datetime, StringElement, ObjectifiedElement, None]) – The date string

Return type:

Optional[datetime]

Returns:

Parsed Optional[datetime]

static parse_str(elem)[source]

Ensure that a str from elem.text is a str and not empty.

Parameters:

elem (Optional[str]) – The The Optional[str] from elem.text

Return type:

str

Returns:

Parsed str

Raises:

TIPModelParsingException – If elem_text is None or empty string

static parse_str_optional(elem)[source]

Parse optional str field.

Parameters:

elem (Optional[str]) – The Optional[str] from elem.text

Return type:

Optional[str]

Returns:

Parsed Optional[str]

static parse_int(elem)[source]

Convert the value coming from element to an integer type.

Parameters:

elem (Union[str, int, IntElement, ObjectifiedElement]) – One element inside an objectify.ObjectifiedElement

Return type:

int

Returns:

Parsed int

Raises:

TIPModelParsingException – If the elem cannot be converted to an int

static parse_int_optional(elem)[source]

Parse optional int field.

Parameters:

elem (Union[str, int, IntElement, ObjectifiedElement, None]) – One element inside an objectify.ObjectifiedElement

Return type:

Optional[int]

Returns:

Parsed Optional[int]

static parse_int_id_optional(elem)[source]

Parse optional int id field. In TIP Models, we have some ID fields which are optional. In our stored procedures, if a field is NULL, its xml node is not included in the xml request body. To make the NULL more explicit, we set this value to -1. But here we want to set this -1 to None to be more clear to users of TIP that the value is missing.

Parameters:

elem (Union[str, int, IntElement, ObjectifiedElement, None]) – One element inside an objectify.ObjectifiedElement

Return type:

Optional[int]

Returns:

Parsed Optional[int]

static parse_bool(elem)[source]

Convert the value coming from element to a bool type

Parameters:

elem (Union[bool, str, int, IntElement, ObjectifiedElement]) – One element inside an objectify.ObjectifiedElement

Return type:

bool

Returns:

Parsed bool

Raises:

TIPModelParsingException – If the elem cannot be converted to an bool

static parse_bool_optional(elem)[source]

Parse optional bool field.

Parameters:

elem (Union[bool, str, int, IntElement, ObjectifiedElement, None]) – One element inside an objectify.ObjectifiedElement

Return type:

Optional[bool]

Returns:

Parsed Optional[int]

static parse_float(elem)[source]

Convert the value coming from element to a float type

Parameters:

elem (Union[str, int, float, IntElement, FloatElement, ObjectifiedElement]) – One element inside an objectify.ObjectifiedElement

Return type:

float

Returns:

Parsed float

Raises:

TIPModelParsingException – If the elem cannot be converted to an float

static parse_float_optional(elem)[source]

Parse optional float field.

Parameters:

elem (Union[str, FloatElement, float, None]) – One element inside an objectify.ObjectifiedElement

Return type:

Optional[float]

Returns:

Parsed Optional[float]

validate()[source]

registers all validation checks, ensures all succeed

Return type:

None

Returns:

None

Raises:

TIPModelValidationException – If any validation checks fail.

validate_type(f, field_val, field_types, is_optional, validation_errors, parent_field_str)[source]

Validate a single field’s type against expected types.

Parameters:
  • f (Field) – The dataclass field being validated

  • field_val (Any) – The value of the field

  • field_types (Set[type]) – Set of expected types for the field

  • is_optional (bool) – Whether the field is optional (can be None)

  • validation_errors (List[str]) – List to append validation errors to

  • parent_field_str (str) – String prefix for nested field names

Return type:

None

Returns:

None

validate_types(validation_errors=None, parent_field='')[source]

Validate all field types in this model.

Parameters:
  • validation_errors (Optional[List]) – Optional list to append errors to

  • parent_field (str) – Parent field name for nested validation

Return type:

List[str]

Returns:

List of validation error messages

Raises:

TIPModelValidationException – If any field type is a dict

to_kwargs()[source]

Convert this model to a dictionary of field names and values.

Return type:

Dict[str, Any]

Returns:

Dictionary mapping field names to their values

abstract classmethod model_validate_from_elem(data)[source]

Abstract method for converting lxml objectify data to TIPModel

Return type:

TIPModel

classmethod data_dictionary()[source]

Generates a data dictionary as a dict type.

Return type:

Dict[str, Any]

Returns:

dict containing all fields with their data types and descriptions

classmethod data_dictionary_json()[source]

Generates a data dictionary as a JSON string.

Return type:

str

Returns:

JSON string containing all fields with their data types and descriptions

class q2_sdk.models.tip.schemas.base.TIPRequest(customer_key, event_user_id, session_id, ui_source, transaction_id, audit_id, event_date_time, customer_id, group_id, transaction_type, gt_type_short_name, transaction_type_version, create_date, transaction_amount, login_audit_id, user_logon_id, created_user_id, authorized_user_id, modified_user_id)[source]

Data class that contains fields that are shared across transaction types and should be included in all TIP requests.

customer_key: str
event_user_id: int
session_id: str
ui_source: str
transaction_id: int
audit_id: int
event_date_time: datetime
customer_id: int
group_id: int
transaction_type: TransactionTypeEnum
gt_type_short_name: str
transaction_type_version: str
create_date: datetime
transaction_amount: float
login_audit_id: int
user_logon_id: int
created_user_id: Optional[int]
authorized_user_id: Optional[int]
modified_user_id: Optional[int]
classmethod model_validate_from_elem(data)[source]

Converts lxml objectify data to a TIPRequest model.

Parameters:

data (Element) – Input data as etree.Element

Return type:

TIPRequest

to_dict()[source]
Return type:

Dict[str, Any]

class q2_sdk.models.tip.schemas.base.TIPResponse(status, version=TIPResponseVersion.V0, tracking_id=None, transaction_id=None, error_type='Success', error_code='0', error_description='')[source]

Data class used to build the TIP response XML returned to HQ

status: TIPStatus
version: TIPResponseVersion = '0'
tracking_id: Optional[str] = None
transaction_id: Optional[int] = None
error_type: str = 'Success'
error_code: str = '0'
error_description: str = ''
to_audit_details()[source]
Return type:

Dict[str, str]

to_xml()[source]

Convert this TIPResponse to XML formatted string.

Return type:

str

Returns:

XML string representation of the response

classmethod from_exception(error_description, version=TIPResponseVersion.V0, tracking_id=None, transaction_id=None)[source]

Converts an error description along with other optional parameters to a TIPResponse

Parameters:
  • cls – Description

  • error_description (str) – Description

  • version (TIPResponseVersion) – Description

  • tracking_id (Optional[str]) – Description

  • transaction_id (Optional[int]) – Description

Return type:

TIPResponse

classmethod model_validate_from_elem(data)[source]

We don’t need this method implemented but we still want to inherit from TIPModel so that we can get type validation

Return type:

TIPResponse

validate_no_optional()[source]

This is the same method as super().validate() except we temporarily set self._allow_optional to False so that we force all the fields in this class to be required.

q2_sdk.models.tip.schemas.base.get_execute_request_as_xml_response_from_tip_response(root_node, xml_str, attrs)[source]

Builds a soap envelope to respond to an “ExecuteRequestAsXML” request from HQ

Parameters:
  • root_node (str) – Request nodename provided by HQ

  • form_data – Response data

  • attrs (dict) – Attributes to add to the interior Data node, passed through to HQ

  • hq_commands – (Optional) Instance of HqCommands to send additional commands with the response

Return type:

str