Giter Club home page Giter Club logo

libiso's Introduction

libiso - A library of utilities related to payments, crypto, ISO8583 etc

GitHub release (latest SemVer) CircleCI Go Report Card codecov GitHub go.mod Go version (branch & subfolder of monorepo)

Creating ISO8583 messages

First, create a yaml file containing the spec definition (for example, see this) and then list that under a file called specs.yaml (ignore the .spec files - they're an older way of defining specs)

  1. Read all the specs defined (the path should contain the file specs.yaml)
if err := iso8583.ReadSpecs(filepath.Join(".", "testdata")); err != nil {
		log.Fatal(err)
		return
}
  1. Once initialized you can construct ISO8583 messages like below (from https://github.com/rkbalgi/libiso/blob/master/v2/iso8583/iso_test.go#L20) -
	specName := "ISO8583-Test"
	spec := iso8583.SpecByName(specName)
	if spec == nil {
		t.Fatal("Unable to find spec - " + specName)
	}

	// Parse a message using an existing hex-dump

	msgData, _ := hex.DecodeString("3131303070386000000080003136343736363937373635343332373737373030343030303030303030303030313039303636363535313230313333353035323239333131333336383236")

	msg := spec.FindTargetMsg(msgData) // if you know the kind of message you are parsing, you can do this - Example: spec.MessageByName("1100 - Authorization")
	if msg != nil {
		parsedMsg, err := msg.Parse(msgData)
		if err != nil {
			t.Fatal(err)
		} else {
			iso := iso8583.FromParsedMsg(parsedMsg)
			assert.Equal(t, "000000001090", iso.Bitmap().Get(4).Value())
			assert.Equal(t, "666551", iso.Bitmap().Get(11).Value())
		}
	} else {
		t.Fatal("Unable to derive the type of message the data represents")
	}

	// OR
	// build a message from scratch

	msg = spec.MessageByName("1100 - Authorization")
	iso := msg.NewIso()
	iso.Set("Message Type", "1100")
	iso.Bitmap().Set(3, "004000")
	iso.Bitmap().Set(4, "4766977654327777") // or iso.Set("PAN","4766977654327777")
	iso.Bitmap().Set(3, "004000")

	iso.Bitmap().Set(49, "336")
	iso.Bitmap().Set(50, "826")

	msgData, _, err := iso.Assemble()
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, "31313030300000000000c00030303430303034373636393737363534333237373737333336383236", hex.EncodeToString(msgData))

Please checkout https://github.com/rkbalgi/isosim project which uses this library.

Benchmarks

With v2.0.1 you can turn off logging (and hence gain some speed and lower allocations) using the new parser API

        parser := iso8583.NewParser(&iso8583.ParserConfig{LogEnabled: false})

        log.SetLevel(log.ErrorLevel)

	specName := "ISO8583-Test"
	spec := iso8583.SpecByName(specName)
	if spec == nil {
		b.Fatal("Unable to find spec - " + specName)
	}
	msgData, _ := hex.DecodeString("3131303070386000000080003136343736363937373635343332373737373030343030303030303030303030313039303636363535313230313333353035323239333131333336383236")

	msg := spec.FindTargetMsg(msgData) // if you know the kind of message you are parse, you can do this - Example: spec.MessageByName("1100 - Authorization")
	parsedMsg, err := parser.Parse(msg,msgData)
	iso := iso8583.FromParsedMsg(parsedMsg)
	assert.Equal(t, "000000001090", iso.Bitmap().Get(4).Value())
PS C:\Users\rkbal\IdeaProjects\libiso\v2\iso8583> go test -bench . -run Benchmark_Parse
time="2020-10-11T09:56:02+05:30" level=debug msg="Available spec files -  [isoSpecs.spec iso_specs.yaml sample_spec.yaml]"
time="2020-10-11T09:56:02+05:30" level=debug msg="Reading file .. isoSpecs.spec"
time="2020-10-11T09:56:02+05:30" level=debug msg="Reading file .. iso_specs.yaml"
time="2020-10-11T09:56:02+05:30" level=debug msg="Reading file .. sample_spec.yaml"
goos: windows
goarch: amd64
pkg: github.com/rkbalgi/libiso/v2/iso8583
Benchmark_ParseWithParserAPI-8            327625              3692 ns/op            4016 B/op         27 allocs/op
Benchmark_ParseWithMsg-8                   85014             14037 ns/op           12121 B/op        154 allocs/op
PASS
ok      github.com/rkbalgi/libiso/v2/iso8583    4.600s
PS C:\Users\rkbal\IdeaProjects\libiso\v2\iso8583>

Just to see the impact of logging , with log level turned to TRACE -

Benchmark_ParseWithMsg-8                   502           2355728 ns/op           24749 B/op        409 allocs/op

Also, a new API for assembling

			asm:=iso8583.NewAssembler(&iso8583.AssemblerConfig{
			  LogEnabled: false,
		    })

			iso := msg.NewIso()
			iso.Set("Message Type", "1100")
			iso.Bitmap().Set(3, "004000")
			iso.Bitmap().Set(4, "4766977654327777")
			iso.Bitmap().Set(3, "004000")

			iso.Bitmap().Set(49, "336")
			iso.Bitmap().Set(50, "826")

			_, _, err := asm.Assemble(iso)

Note:

  • Message Type and Bitmap are reserved keywords within this library (i.e you cannot call the Bitmap as Primary Bitmap or Bmp etc)
  • This library has not yet been subjected to any kind of targeted tests (performance or otherwise), so use this with a bit of caution - It's at the moment perhaps best suited for simulators

Paysim

Paysim is an old application that uses this library. You can read more about paysim here - https://github.com/rkbalgi/go/wiki/Paysim

libiso's People

Contributors

josephu avatar rkbalgi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

libiso's Issues

misc_test.go does not work

first i run the test case, use
github.com/rkbalgi/go/iso8583 (master)
$ go test
An error came out that the "Handle" cannot be recognized.
then i omited the last few lines, then run again:
$ go test
exit status 3221225785
FAIL github.com/rkbalgi/go/iso8583 0.014s

Another issue is that

i have build iso_host.exe from github.com/rkbalgi/go/execs/iso_host, but after runing it, it turns out the same result.
i have a lot of research:

  1. put a log message in the first line in main() of iso_host.go, but nothing cameout.
  2. put a log message in every init() call, but nothing cameout.
  3. omited pkgs from iso_host.go
  • if i omited iso8583 pkg, that message cameout from main().

please tell me ,anything im doing wrong ?

How to run Paysim Please?

Hi, could you write instructions in how to tun Paysim?

I tried to run on my ubutun the simulator in Go+Web, and I got this error:
go run isosim.go -httpPort 7777 -specDefFile specs\isoSpecs.spec -htmlDir .\html isosim.go:5:2: cannot find package "github.com/rkbalgi/isosim/data" in any of: /usr/lib/go-1.6/src/github.com/rkbalgi/isosim/data (from $GOROOT) /home/edgar/go/src/github.com/rkbalgi/isosim/data (from $GOPATH) isosim.go:6:2: cannot find package "github.com/rkbalgi/isosim/web/http_handlers" in any of: /usr/lib/go-1.6/src/github.com/rkbalgi/isosim/web/http_handlers (from $GOROOT) /home/edgar/go/src/github.com/rkbalgi/isosim/web/http_handlers (from $GOPATH) isosim.go:7:2: cannot find package "github.com/rkbalgi/isosim/web/spec" in any of: /usr/lib/go-1.6/src/github.com/rkbalgi/isosim/web/spec (from $GOROOT) /home/edgar/go/src/github.com/rkbalgi/isosim/web/spec (from $GOPATH)

Build issues

I'm really new to Go and when I try to build go/iso_host, the following exceptions are raised:
..\paysim\ui\paysim_mac_dialog.go:25: cannot use gtk.BUTTONS_OK (type gtk.ButtonsType) as type gtk.ResponseType in argument to dialog.AddButton ..\paysim\ui\paysim_mac_dialog.go:26: cannot use gtk.BUTTONS_CANCEL (type gtk.ButtonsType) as type gtk.ResponseType in argument to dialog.AddButton ..\paysim\ui\paysim_pin_dialog.go:28: cannot use gtk.BUTTONS_OK (type gtk.ButtonsType) as type gtk.ResponseType in argument to dialog.AddButton ..\paysim\ui\paysim_pin_dialog.go:29: cannot use gtk.BUTTONS_CANCEL (type gtk.ButtonsType) as type gtk.ResponseType in argument to dialog.AddButton

Please your help

Compile issue + killed signal

Hi,
I tried compiling this today and had a couple of issues:

  1. error with MATTN package

github.com/rkbalgi/go/paysim/ui

../../paysim/ui/paysim_mac_dialog.go:25: cannot use gtk.BUTTONS_OK (type gtk.ButtonsType) as type gtk.ResponseType in argument to dialog.AddButton

I managed to get the code to compile by making the following changes

ok_btn := dialog.AddButton("Generate", gtk.RESPONSE_OK)
cancel_btn := dialog.AddButton("Cancel", gtk.RESPONSE_CANCEL)

// ok_btn := dialog.AddButton("Generate", gtk.BUTTONS_OK)
// cancel_btn := dialog.AddButton("Cancel", gtk.BUTTONS_CANCEL)

  1. It compiles with the following warning messages:

github.com/mattn/go-gtk/pango

ld: warning: /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation, ignoring unexpected dylib file

github.com/mattn/go-gtk/glib

ld: warning: /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation, ignoring unexpected dylib file

github.com/mattn/go-gtk/gdkpixbuf

ld: warning: /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation, ignoring unexpected dylib file

github.com/mattn/go-gtk/gdk

ld: warning: /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation, ignoring unexpected dylib file

github.com/mattn/go-gtk/gtk

ld: warning: /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation, ignoring unexpected dylib file

  1. If I run using GO RUN PAYSIM.GO after ignoring the warning messages I get:

signal: killed

This is on Mac OSX Sierra 10.12.5

Thanks
James

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.