Skip to content

Commit

Permalink
fix: testing
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagozs committed Apr 2, 2024
1 parent 5b4d5d7 commit 16d6b77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 78 deletions.
84 changes: 7 additions & 77 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,17 @@ package main

import (
"fmt"
"iso8583/iso8583"
"strings"
"iso8583"
)

func main() {

dataTcp := "08002038000000200002810000000001084909052253415630305A303537363331202020205341564E47583130303131303032303030302020202020200011010008B9F3F723CA3CD2F8"

i := iso8583.New()

fmt.Println("Data TCP =", dataTcp)

_, err := i.Parse(dataTcp)
if err != nil {
fmt.Printf("Error Parse: %v\n", err)
return
}

i.LogFields()

fmt.Println()
fmt.Println("Testing ISO8583 Builder")
fmt.Printf("%s\n", strings.Repeat("-", 80))

index := `MTI: 0200
Field 2 (Primary Account Number): 4000001234567890
Field 3 (Processing Code): 000000 (Assuming purchase)
Field 4 (Amount, Transaction): 000000006000 (60 USD, 12 digits, no decimal point)
Field 7 (Transmission Date & Time): 0209123456 (Assuming February 9th, 12:34:56)
Field 11 (Systems Trace Audit Number): 000001
Field 12 (Time, Local Transaction): 123456 (12:34:56)
Field 13 (Date, Local Transaction): 0209 (February 9th)
Field 14 (Date, Expiration): 2402 (February 2024)
Field 22 (Point of Service Entry Mode): 022 (Magnetic stripe, including PIN capability)
Field 32 (Acquiring Institution Identification Code): 123456
Field 35 (Track 2 Data): 4000001234567890=240212345
Field 37 (Retrieval Reference Number): 123456789012
Field 41 (Card Acceptor Terminal ID): TERM1234
Field 42 (Card Acceptor ID Code): 123456789012345
Field 49 (Currency Code, Transaction): 840 (USD)
Field 54 (Additional Amounts): 0400600D000000000000 (4 installments of 60 USD)
`
fmt.Println(index)
// Adding fields with example values that correspond to
// typical ISO 8583 usage

msg := i.CreateISO("0200")
msg.AddField(2, "4000001234567890")
msg.AddField(3, "000000")
msg.AddField(4, "000000006000")
msg.AddField(7, "0209123456")
msg.AddField(11, "000001")
msg.AddField(12, "123456")
msg.AddField(13, "0209")
msg.AddField(14, "2402")
msg.AddField(22, "022")
msg.AddField(32, "123456")
msg.AddField(35, "4000001234567890=240212345")
msg.AddField(37, "123456789012")
msg.AddField(41, "TERM1234")
msg.AddField(42, "123456789012345")
msg.AddField(49, "840")
msg.AddField(54, "0400600D000000000000")

iso, err := msg.Build()
if err != nil {
fmt.Printf("Error Build: %v\n", err)
return
}

fmt.Println("ISO Generated =", iso)

_, err = i.Parse(iso)
if err != nil {
fmt.Printf("Error Parse: %v\n", err)
return
}

i.LogFields()

fmt.Println()
fmt.Printf("Testing2 ISO8583 Builder, adding fields with example \nvalues that correspond to typical ISO 8583 usage\n")
fmt.Printf("%s\n", strings.Repeat("-", 80))

// Adding fields with example values that correspond to
// typical ISO 8583 usage
msg = i.CreateISO("0200")
msg.AddField(2, "1234567890123456") // Primary Account Number
msg.AddField(3, "000000") // Processing Code
msg.AddField(4, "000000010000") // Amount, Transaction
Expand Down Expand Up @@ -119,6 +45,10 @@ Field 54 (Additional Amounts): 0400600D000000000000 (4 installments of 60 USD)
msg.AddField(59, "XXXXXXYYYYYYYYYZ") // Echo Data
msg.AddField(64, "IFFFXPTO") // Network Management Information Code

msg.AddField(65, "IFFFXPTO") // Network Management Information Code
msg.AddField(66, "IFFFXPTO") // Network Management Information Code
msg.AddField(67, "IFFFXPTO") // Network Management Information Code

isoMessage, err := msg.Build()
if err != nil {
fmt.Printf("Error building ISO message: %v\n", err)
Expand Down
5 changes: 4 additions & 1 deletion message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func TestCreateISO(t *testing.T) {
msg.AddField(42, "123456789012345")
msg.AddField(49, "840")
msg.AddField(54, "0400600D000000000000")
msg.AddField(65, "0400600D000000000000")
msg.AddField(66, "0400600D000000000000")
msg.AddField(67, "0400600D000000000000")

// Build the ISO message
isoMessage, err := msg.Build()
Expand All @@ -72,7 +75,7 @@ func TestCreateISO(t *testing.T) {
}

// Expected ISO message
expectedISO := "0200723C040128C0840016400000123456789000000000000000600002091234560000011234560209240202206123456264000001234567890=240212345123456789012TERM12341234567890123458400200400600D000000000000"
expectedISO := "0200F23C040128C08400E00000000000000016400000123456789000000000000000600002091234560000011234560209240202206123456264000001234567890=240212345123456789012TERM12341234567890123458400200400600D0000000000000004"

if isoMessage != expectedISO {
t.Errorf("Expected ISO message = %s, got %s", expectedISO, isoMessage)
Expand Down

0 comments on commit 16d6b77

Please sign in to comment.