Skip to main content

Appendix 5

Generate Message

Step 1 : Sample Data Fields

Construct the data fields for the message.

Please refer to Notification Parameters for details of each field.

  • Ensure itemGivenId and mrn are padded with spaces or 0 to meet the required fixed length.
    String mti = "0025";
String resultCode = "00000";
String amount = "000000000200";
String itemGivenId = " ABCXYZ123"; // padded
String mid = "000010000012345";
String mrn = " 20251124014201000123456"; // padded
String paymentType = "PRE";
String paymentMethod = "01";
String approvalCode = "123456";

Step 2 : Combine Fields

Combine all the fields into a single variable as the data.

    String data
= mti
+ resultCode
+ amount
+ itemGivenId
+ mid
+ mrn
+ paymentType
+ paymentMethod
+ approvalCode;

Step 3 : Generate Checksum

Pass the data created into a Checksum function to verify for errors.

    public static String calculateXorChecksum(String input) {
int xor = 0;
for (int i = 0; i < input.length(); i++) {
xor ^= input.charAt(i); // XOR ASCII values
}
return String.format("%02X", xor & 0xFF); // 2-digit HEX
}

Step 4 : Build Message

The message should be constructed as:

  • STX + DATA + CHECKSUM + ETX

STX (Start of Text) and ETX (End of Text) are special characters used to mark:

  • STX: the start of the message
  • ETX: the end of the message
    String checksum = calculateXorChecksum(data);
String message = "\u0002" + data + checksum + "\u0003";