Skip to content

Commit

Permalink
fix: Header size definition (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinkrustev committed Apr 20, 2018
1 parent b06d9c5 commit 501eb2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 0 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<a name="6.4.0"></a>
# [6.4.0](https://github.com/softwaregroup-bg/ut-codec-payshield/compare/v6.2.2...v6.4.0) (2018-04-17)


### Bug Fixes

* better error handling ([f61494e](https://github.com/softwaregroup-bg/ut-codec-payshield/commit/f61494e))



<a name="6.2.7"></a>
## [6.2.7](https://github.com/softwaregroup-bg/ut-codec-payshield/compare/v6.2.6...v6.2.7) (2018-03-28)

Expand Down
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ PayshieldCodec.prototype.init = function(config) {
if (this.headerPattern === false) {
throw this.errors.parserHeader();
}

this.headerNoSize = this.headerPattern.filter(function(value) {
return value.name === 'headerNo';
}).pop().size;
this.maxTrace = parseInt('9'.repeat(this.headerNoSize));

for (var property in commandsObj) {
if (commandsObj.hasOwnProperty(property)) {
if (commandsObj[property].requestPattern) {
Expand Down Expand Up @@ -126,9 +132,9 @@ PayshieldCodec.prototype.encode = function(data, $meta, context) {

var headerNo = $meta.trace;
if (headerNo === undefined || headerNo === null) {
headerNo = $meta.trace = ('000000' + context.trace).substr(-6);
headerNo = $meta.trace = ('0'.repeat(this.headerNoSize) + context.trace).substr(-this.headerNoSize);
context.trace += 1;
if (context.trace > 999999) {
if (context.trace > this.maxTrace) {
context.trace = 0;
}
}
Expand Down

0 comments on commit 501eb2f

Please sign in to comment.