Skip to content

Commit 276d2d4

Browse files
author
Rafael Castro
committed
Add bank authentication to Payment Parser Response
1 parent 9bd035b commit 276d2d4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

febraban/cnab240/v83/result/parser.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ class PaymentResponseStatus:
1111

1212
class PaymentResponse:
1313

14-
def __init__(self, identifier=None, occurrences=None, content=None):
14+
def __init__(self, identifier=None, occurrences=None, content=None, authentication=None):
1515
self.identifier = identifier
1616
self.occurrences = occurrences
1717
self.content = content or []
18+
self.authentication = authentication
1819

1920
def occurrencesText(self):
2021
return [occurrences[occurrenceId] for occurrenceId in self.occurrences]
@@ -56,10 +57,13 @@ def _parseLines(cls, lines):
5657
continue
5758
elif line[7] == "1":
5859
currentResponse = PaymentResponse(content=[line])
59-
elif line[7] == "3":
60+
elif line[7] == "3" and line[13] == "A":
6061
currentResponse.content.append(line)
6162
currentResponse.identifier = cls._getIdentifier(line)
6263
currentResponse.occurrences = cls._getOccurrences(line)
64+
elif line[7] == "3" and line[13] == "Z":
65+
currentResponse.content.append(line)
66+
currentResponse.authentication = cls._getAuthentication(line)
6367
elif line[7] == "5":
6468
currentResponse.content.append(line)
6569
result.append(currentResponse)
@@ -77,4 +81,8 @@ def _splitString(cls, string):
7781

7882
@classmethod
7983
def _getIdentifier(self, line):
80-
return line[73:93].strip()
84+
return line[73:93].strip()
85+
86+
@classmethod
87+
def _getAuthentication(cls, line):
88+
return line[14:78].strip()

sample-payment-parser.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from febraban.cnab240.v83.result.parser import PaymentParser
22

3-
file = open("output.REM", "r")
3+
file = open("SB25058A.RET", "r")
44

55
responses = PaymentParser.parseFile(file)
66

77
for response in responses:
88
print response.identifier
9+
print response.authentication
910
print response.status()
1011
print response.content
1112
print response.contentText()

0 commit comments

Comments
 (0)