Skip to content

Commit

Permalink
remove confusing vsdc example, add correct icc field spec
Browse files Browse the repository at this point in the history
  • Loading branch information
alovak committed Aug 19, 2024
1 parent dfac6bd commit 446a89b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 155 deletions.
155 changes: 0 additions & 155 deletions examples/VSDCChipData/main.go

This file was deleted.

83 changes: 83 additions & 0 deletions examples/icc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package examples

import (
"fmt"
"testing"

"github.com/moov-io/iso8583/encoding"
"github.com/moov-io/iso8583/field"
"github.com/moov-io/iso8583/prefix"
"github.com/moov-io/iso8583/sort"
"github.com/stretchr/testify/require"
)

// The sample is for VSDC chip data usage

// This field 55 VSDC chip data usage contains three subfields after the length subfield.
// Positions:
// 1 2 3 4 ... 255
// Fields
// - Subfield 1: length Byte, a one-byte binary subfield that contains the number of bytes in this field after the length subfield
// - Subfield 2: dataset ID, a one-byte binary identifier
// - Subfield 3: dataset length, 2-byte binary subfield that contains the total length of all TLV elements that follow.
// - Subfield 4:
// Chip Card TLV data elements
// Tag Length Value Tag Length Value
func TestICCField55(t *testing.T) {
field55Spec := &field.Spec{
Length: 255,
Description: "Integrated Circuit Card (ICC) Data",
Pref: prefix.Binary.L,
Tag: &field.TagSpec{
Length: 1,
Enc: encoding.ASCIIHexToBytes,
Sort: sort.StringsByHex,
},
Subfields: map[string]field.Field{
"01": field.NewComposite(&field.Spec{
Length: 252,
Description: "VSDC Data",
Pref: prefix.Binary.LL,
Tag: &field.TagSpec{
Enc: encoding.BerTLVTag,
Sort: sort.StringsByHex,
},
Subfields: map[string]field.Field{
"9A": field.NewString(&field.Spec{
Description: "Transaction Date",
Enc: encoding.Binary,
Pref: prefix.BerTLV,
}),
"9F02": field.NewString(&field.Spec{
Description: "Amount, Authorized (Numeric)",
Enc: encoding.Binary,
Pref: prefix.BerTLV,
}),
},
}),
},
}

type VSDCData struct {
TransactionDate string `iso8583:"9A"`
Amount string `iso8583:"9F02"`
}

type ICCData struct {
VSDCData *VSDCData `iso8583:"01"`
}

filed55 := field.NewComposite(field55Spec)
err := filed55.Marshal(&ICCData{
VSDCData: &VSDCData{
TransactionDate: "210720",
Amount: "000000000501",
},
})
require.NoError(t, err)

packed, err := filed55.Pack()
require.NoError(t, err)

require.Equal(t, "1A0100179A063231303732309F020C303030303030303030353031", fmt.Sprintf("%X", packed))
}

0 comments on commit 446a89b

Please sign in to comment.