MTI Response Builder

easy · iso8583, payments

MTI Response Builder

You're implementing a payment switch that receives authorization requests and needs to build responses. When you receive an 0100 (authorization request), you need to respond with an 0110 (authorization response). When you receive an 0400 (reversal request), you respond with 0410.

The pattern is consistent: for request MTIs, the response MTI increments the function digit from 0 to 1 (request → response) or from 2 to 3 (advice → advice response).

Your task: given a request or advice MTI, build the corresponding response MTI.

The Pattern

Request:           0100  →  Response:        0110
                   │││└─ Origin (preserved)
                   ││└── Function: 0→1
                   │└─── Class (preserved)
                   └──── Version (preserved)

Advice:            0120  →  Advice Response: 0130
                   │││└─ Origin (preserved)
                   ││└── Function: 2→3
                   │└─── Class (preserved)
                   └──── Version (preserved)

The rules:

  • Function 0 (request) → Function 1 (response)
  • Function 2 (advice) → Function 3 (advice response)
  • Function 4 (notification) → Function 5 (notification ack)
  • All other parts of the MTI remain unchanged
  • If the input is already a response (function 1, 3, or 5), return an error

What You're Building

func BuildResponseMTI(requestMTI string) (string, error)

Behavior

  1. Validate the input MTI (exactly 4 ASCII digits)
  2. Check that it's a request/advice/notification (function digit 0, 2, or 4)
  3. Increment the function digit by 1
  4. Return the response MTI

Examples

// Authorization flow
BuildResponseMTI("0100") // → "0110", nil  (auth request → auth response)
BuildResponseMTI("0110") // → "", error    (already a response!)

// Reversal flow
BuildResponseMTI("0400") // → "0410", nil  (reversal request → reversal response)
BuildResponseMTI("0420") // → "0430", nil  (reversal advice → reversal advice response)

// Network management
BuildResponseMTI("0800") // → "0810", nil  (network mgmt request → response)

// 2003 spec
BuildResponseMTI("2100") // → "2110", nil  (2003-spec auth request → response)

// Errors
BuildResponseMTI("0110") // → "", error    (already a response)
BuildResponseMTI("0130") // → "", error    (already an advice response)
BuildResponseMTI("010")  // → "", error    (invalid MTI - too short)
BuildResponseMTI("01X0") // → "", error    (invalid MTI - non-digit)

Edge Cases to Handle

  • Already a response: If function digit is 1, 3, or 5, return an error
  • Reserved function values: For function digits 6-9, return an error (no defined response)
  • Repeat indicators: The origin digit should be preserved (a repeat request gets a repeat response)
BuildResponseMTI("0101") // → "0111", nil  (acquirer repeat request → repeat response)
BuildResponseMTI("0403") // → "0413", nil  (issuer repeat reversal → response)

Why This Matters

When building a payment switch or gateway, you'll constantly transform MTIs:

  1. Receive request, build response
  2. Log both with matched MTIs
  3. Handle timeouts by converting requests to reversals

Understanding MTI transformation is fundamental to message flow handling. This function is a building block you'll use repeatedly.

Hints (only if stuck)

<details> <summary>Hint 1: String manipulation</summary> You can convert a string to a byte slice, modify one byte, and convert back:

bytes := []byte(mti)
bytes[2] = bytes[2] + 1  // Increment function digit
return string(bytes), nil

</details>

<details> <summary>Hint 2: Checking request vs response</summary> A message is a request/advice/notification if the function digit (position 2) is even (0, 2, 4). A message is a response if the function digit is odd (1, 3, 5). </details>

<details> <summary>Hint 3: Reserved values</summary> Function digits 6-9 don't have a defined request/response pattern. Return an error for these. </details>

Run tests to see results
No issues detected
    Join Discord