Skip to content

Instantly share code, notes, and snippets.

@alovak
Created June 2, 2021 15:22
Show Gist options
  • Save alovak/a1637a12c5e1c06ad89595effe284408 to your computer and use it in GitHub Desktop.
Save alovak/a1637a12c5e1c06ad89595effe284408 to your computer and use it in GitHub Desktop.
moov-io/iso8583 example
package main
import (
"github.com/moov-io/iso8583"
"github.com/moov-io/iso8583/encoding"
"github.com/moov-io/iso8583/field"
"github.com/moov-io/iso8583/prefix"
)
func NewSpec() *iso8583.MessageSpec {
return &iso8583.MessageSpec{
Fields: map[int]field.Field{
0: field.NewString(&field.Spec{
Length: 4,
Description: "Message Type Indicator",
Enc: encoding.ASCII,
Pref: prefix.ASCII.Fixed,
}),
1: field.NewBitmap(&field.Spec{
Description: "Bitmap",
Enc: encoding.Binary,
Pref: prefix.Binary.Fixed,
}),
2: field.NewString(&field.Spec{
Length: 19,
Description: "Primary Account Number",
Enc: encoding.BCD,
Pref: prefix.BCD.LL,
}),
//3: field.NewNumeric(&field.Spec{
// Length: 6,
// Description: "Processing Code",
// Enc: encoding.BCD,
// Pref: prefix.BCD.Fixed,
//}),
//4: field.NewNumeric(&field.Spec{
// Length: 12,
// Description: "Amount, Transaction",
// Enc: encoding.BCD,
// Pref: prefix.BCD.Fixed,
// //Pad: padding.Left('0'),
//}),
//6: field.NewNumeric(&field.Spec{
// Length: 12,
// Description: "Amount, Cardholder Billing",
// Enc: encoding.BCD,
// Pref: prefix.BCD.Fixed,
// Pad: padding.Left('0'),
//}),
//7: field.NewNumeric(&field.Spec{
// Length: 10,
// Description: "Transmission Date and Time",
// Enc: encoding.BCD,
// Pref: prefix.BCD.Fixed,
// Pad: padding.Left('0'),
//}),
// and so on
//
},
}
}
func main() {
spec := NewSpec()
message := iso8583.NewMessage(spec)
message.MTI("0100")
message.Field(2, "4242424242424242")
message.Field(3, "123456")
message.Field(4, "100")
// set your values
packed, err := message.Pack()
if err != nil {
panic(err)
}
// send packed via the network
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment