Transaction Interdiction Protocol Request Handler

The Transaction Interdiction Protocol (TIP) request handler should be sub-classed in order to create a TIP SDK extension. The easiest way to create a TIP SDK extension is with the q2 cli tool:

q2 create_extension -t tip

This will prompt you for the name of your extension. After you provide your extension name, it will create all of the necessary template files required to build a TIP extension.

extension.py will contain the core logic for your TIP request handler. This file builds a request handler that sub-classes the TIPRequestHandler (documented below) and provides example implementations for the two required methods:

  • decision_transaction

  • generate_tracking_id

After you have implemented these two methods, you can test your TIP request handler with q2 run.

Note

TIP is a paid feature and requires HQ and Q2DB configuration updates for your TIP request handler to be called from HQ and actually interdict transactions. Please contact your client success manager for more information.

More details on the TIP request data shapes that can be sent to your TIP request handler can be found in the TIP Data Dictionary.

class q2_sdk.core.http_handlers.tip_handler.TIPRequestHandler(application, request, **kwargs)[source]

Bases: Q2HqRequestHandler

TIP (Transaction Interdiction Protocol)

This class is a request handler that can respond to Authorize Transaction requests from HQ with a decision for how to handle the transaction.

Responses are defined in q2_sdk.models.tip.schemas.base.TIPResponse

set_audit_params()[source]

Sets the audit_params attribute to reasonable and best-guess default values. This is necessary because if the request is invalid, we may not be able to determine all of the audit parameters.

Return type:

None

set_tracking_params()[source]

Sets the tracking_params attribute to reasonable default values. This is necessary because if the request is invalid we may not be able to determine all of the tracking parameters.

Return type:

None

wrap_soap_response(custom_response)[source]

If the incoming request is wrapped in a soap envelope, this prepares it for return back to HQ.

This overrides the Q2HqRequestHandler version of this method to provide an ErrorDescription and set the ErrorCode in the response.

Parameters:

custom_response (str) – Response to wrap in an appropriate soap envelope

Return type:

str

Returns:

SOAP wrapped XML body to be sent to HQ

async q2_post(*args, **kwargs)[source]

Core logic for responding to TIP POST requests. This method does the following:

  1. Validates request from HQ and converts the XML to a data class

  2. Logs an audit event to indicate whether or not the decision has started

    • TIPDecisionStarted if validation succeeded

    • TIPRequestValidationFailed if validation failed

    • TIPDecisionFailed if some other error occurred prior to decision_transaction being called

  3. Calls decision_transaction (abstract method)

  4. Logs an audit event

    • TIPDecisionSucceeded if the decision succeeded

    • TIPDecisionFailed if the decision failed

  5. Validates returned value from decision_transaction and forms the XML to send back to HQ

Return type:

str

Returns:

TIPResponse formatted as an XML string

abstract generate_tracking_id(tip_request)[source]

Using a TIPRequest as input, generates a tracking id. This will be used to set the attribute self.tracking_params.tracking_id that will ultimately be included the the TIPResponse sent back to HQ.

Parameters:

tip_request (TIPRequest) – TIPRequest

Return type:

str

Returns:

string containing the generated tracking id

abstract async decision_transaction(tip_request)[source]

Using a TIPRequest as input, determines what the status of a transaction should be and returns it as a TIPResponse.

Parameters:

tip_request (TIPRequest) – TIPRequest

Return type:

TIPResponse

Returns:

TIPResponse containing the decision for transaction being authorized