Skip to content

Commit 44ae1f4

Browse files
Create ChargePayment
1 parent c496ae2 commit 44ae1f4

9 files changed

+234
-17
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .result.parser import PaymentParser
22
from .payment.transfer import Transfer
3-
from .payment.segmentA import SegmentA
3+
from .payment.chargePayment import ChargePayment
44
from .file.file import File
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from ....libs.barCode import BarCode
2+
from .header import Header
3+
from .segmentJ import SegmentJ
4+
from .segmentJ52 import SegmentJ52
5+
from .trailer import Trailer
6+
7+
8+
class ChargePayment:
9+
10+
def __init__(self):
11+
self.header = Header()
12+
self.segmentJ = SegmentJ()
13+
self.segmentJ52 = SegmentJ52()
14+
self.trailer = Trailer()
15+
16+
def toString(self):
17+
# self.validate()
18+
return "\r\n".join((
19+
self.header.content,
20+
self.segmentJ.content,
21+
self.segmentJ52.content,
22+
self.trailer.content,
23+
))
24+
25+
def setSender(self, user):
26+
"""Sets the sender for the payment. The sender represents a users, its bank and its address."""
27+
self.header.setSender(user)
28+
self.header.setSenderBank(user.bank)
29+
self.header.setSenderAddress(user.address)
30+
self.segmentJ.setSenderBank(user.bank)
31+
self.segmentJ52.setSender(user)
32+
self.segmentJ52.setSenderBank(user.bank)
33+
self.trailer.setSenderBank(user.bank)
34+
35+
def setIdentifier(self, identifier):
36+
"""Sets the charge identifier that will be returned from the bank. Used for matching results."""
37+
self.segmentJ.setIdentifier(identifier)
38+
39+
def setScheduleDate(self, paymentDate):
40+
"""Sets the payment date to be sent to the bank. Defaults to today."""
41+
self.segmentJ.setScheduleDate(paymentDate)
42+
43+
def setBarCode(self, barCode):
44+
barCode = BarCode(barCode)
45+
self.segmentJ.setBarCode(barCode)
46+
self.trailer.setAmountInCents(barCode.amount)
47+
48+
def setPositionInLot(self, index):
49+
self.header.setPositionInLot(index)
50+
self.segmentJ.setPositionInLot(index)
51+
self.segmentJ52.setPositionInLot(index)
52+
self.trailer.setPositionInLot(index)
53+
54+
def setInfo(self, kind="20", method="31"):
55+
"""
56+
This method set config information in the payment
57+
58+
Args:
59+
kind: String - Kind of payment - 20 Fornecedores, read: NOTES 4
60+
method: String - Payment method - 30 Pagamento Boleto Itau, 31 Pagamento Boleto outros Bancos. read: NOTES 5
61+
"""
62+
self.header.setInfo(kind, method)
63+
64+
# def validate(self):
65+
# self.header.validate()
66+
# self.segmentJ.validate()
67+
# self.segmentJ52.validate()
68+
# self.trailer.validate()

febraban/cnab240/itau/sispag/payment/header.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def __init__(self):
1212

1313
def defaultValues(self):
1414
structs = [
15-
( 7, 8, 1, numeric, "1"),
16-
( 8, 9, 1, alphaNumeric, "C"),
15+
( 7, 8, 1, numeric, "1"),
16+
( 8, 9, 1, alphaNumeric, "C"),
1717
( 13, 16, 3, numeric, "040"),
1818
]
1919
self.content = Row.setStructs(structs=structs, content=self.content)
@@ -56,15 +56,3 @@ def setInfo(self, kind, method):
5656
(11, 13, 2, numeric, method)
5757
]
5858
self.content = Row.setStructs(structs=structs, content=self.content)
59-
60-
# def setPaymentMethod(self, method):
61-
# structure = [
62-
# (11, 13, 2, numeric, method),
63-
# ]
64-
# self.content = Row.setStructs(structs=structure, content=self.content)
65-
#
66-
# def setPaymentKind(self, kind):
67-
# structure = [
68-
# (9, 11, 2, numeric, kind),
69-
# ]
70-
# self.content = Row.setStructs(structs=structure, content=self.content)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# coding: utf-8
2+
3+
from datetime import date
4+
from ....row import Row
5+
from ....characterType import numeric, alphaNumeric
6+
7+
8+
class SegmentJ:
9+
10+
def __init__(self):
11+
self.content = " " * 240
12+
self.defaultValues()
13+
14+
def defaultValues(self):
15+
structs = [
16+
( 7, 8, 1, numeric, "3"), # TIPO DE REGISTRO
17+
( 8, 13, 5, numeric, 1), # INDEX DO REGISTRO
18+
( 13, 14, 1, alphaNumeric, "J"), # CÓDIGO DE SEGMENTO
19+
( 14, 17, 3, numeric, "000"), # TIPO DE MOVIMENTO
20+
(144, 152, 8, numeric, date.today().strftime("%d%m%Y")),
21+
(114, 144, 23, numeric, "0"),
22+
(167, 182, 15, numeric, "0"),
23+
]
24+
self.content = Row.setStructs(structs=structs, content=self.content)
25+
26+
def setSenderBank(self, bank):
27+
structs = [
28+
(0, 3, 3, numeric, bank.bankId),
29+
]
30+
self.content = Row.setStructs(structs=structs, content=self.content)
31+
32+
def setBarCode(self, barCode):
33+
structs = [
34+
( 17, 20, 3, numeric, barCode.bankId),
35+
( 20, 21, 1, numeric, barCode.currency),
36+
( 21, 22, 1, numeric, barCode.dac),
37+
( 22, 26, 4, numeric, barCode.dueFactor),
38+
( 26, 36, 10, numeric, barCode.amount),
39+
( 36, 61, 25, numeric, barCode.freeField),
40+
( 99, 114, 15, numeric, barCode.amount), # VALOR NOMINAL DO TÍTULO
41+
(152, 167, 15, numeric, barCode.amount), # VALOR DO PAGAMENTO
42+
( 91, 99, 8, numeric, barCode.dueDate.strftime("%d%m%Y")), # DATA DE VENCIMENTO
43+
]
44+
self.content = Row.setStructs(structs=structs, content=self.content)
45+
46+
def setScheduleDate(self, date):
47+
structs = [
48+
(144, 152, 8, numeric, date)
49+
]
50+
self.content = Row.setStructs(structs=structs, content=self.content)
51+
52+
def setIdentifier(self, identifier):
53+
structs = [
54+
(182, 202, 20, alphaNumeric, identifier),
55+
]
56+
self.content = Row.setStructs(structs=structs, content=self.content)
57+
58+
def setPositionInLot(self, index):
59+
structs = [
60+
(3, 7, 4, numeric, index)
61+
]
62+
self.content = Row.setStructs(structs=structs, content=self.content)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# coding: utf-8
2+
3+
from ....row import Row
4+
from ....characterType import numeric, alphaNumeric
5+
6+
7+
class SegmentJ52:
8+
9+
def __init__(self):
10+
self.content = " " * 240
11+
self.defaultValues()
12+
13+
def defaultValues(self):
14+
structs = [
15+
( 7, 8, 1, numeric, "3"), # TIPO DE REGISTRO
16+
( 8, 13, 5, numeric, "1"), # INDEX DO REGISTRO
17+
(13, 14, 1, alphaNumeric, "J"), # CÓDIGO DE SEGMENTO
18+
(14, 17, 3, numeric, "0"), # TIPO DE MOVIMENTO
19+
(17, 19, 2, numeric, "52"), # IDENTIFICAÇÃO DO REGISTRO OPCIONAL
20+
(75, 91, 16, numeric, "0"),
21+
(131, 147, 16, numeric, "0"),
22+
]
23+
self.content = Row.setStructs(structs=structs, content=self.content)
24+
25+
def setSenderBank(self, bank):
26+
structs = [
27+
( 0, 3, 3, numeric, bank.bankId),
28+
]
29+
self.content = Row.setStructs(structs=structs, content=self.content)
30+
31+
def setSender(self, user):
32+
structs = [
33+
(19, 20, 1, numeric, "1" if len(user.identifier) == 11 else "2"),
34+
(20, 35, 15, numeric, user.identifier),
35+
(35, 75, 40, alphaNumeric, user.name)
36+
]
37+
self.content = Row.setStructs(structs=structs, content=self.content)
38+
39+
def setPositionInLot(self, index):
40+
structs = [
41+
( 3, 7, 4, numeric, index),
42+
]
43+
self.content = Row.setStructs(structs=structs, content=self.content)

febraban/cnab240/itau/sispag/payment/transfer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ def setPositionInLot(self, index):
3636
def setScheduleDate(self, date):
3737
self.segmentA.setScheduleDate(date)
3838

39-
def setInfo(self, kind="98", method="41", reason="10"):
39+
def setInfo(self, kind="20", method="41", reason="10"):
4040
"""
4141
This method set config information in the payment
4242
4343
Args:
44-
kind: String - Kind of payment - 98 Diversos, read: NOTES 4
44+
kind: String - Kind of payment - 20 Fornecedores, read: NOTES 4
4545
method: String - Payment method - 41 TED Outro titular, 43 TED Mesmo titular, 01 ITAU account. read: NOTES 5
4646
reason: String - Payment reason - 10 Credito em Conta Corrente, read: NOTES 26
4747
"""

febraban/cnab240/libs/barCode.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from datetime import date, timedelta
2+
3+
4+
class BarCode:
5+
6+
def __init__(self, number):
7+
self.number = number
8+
self.bankId = self.number[0:3]
9+
self.currency = self.number[3:4]
10+
self.dac = self.number[4:5]
11+
self.dueFactor = self.number[5:9]
12+
self.amount = self.number[9:19]
13+
self.freeField = self.number[19:44]
14+
self.baseDate = date(year=1997, month=10, day=7)
15+
self.dueDate = self.baseDate + timedelta(days=int(self.dueFactor))

sample-charge-payment-parser.py

Whitespace-only changes.

sample-charge-payment.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
# coding: utf-8
3+
4+
from febraban.cnab240.itau.sispag import ChargePayment, File
5+
from febraban.cnab240.user import User, UserAddress, UserBank
6+
7+
8+
sender = User(
9+
name="YOUR COMPANY NAME HERE",
10+
identifier="12345678901234",
11+
bank=UserBank(
12+
bankId="341",
13+
branchCode="4321",
14+
accountNumber="12345678",
15+
accountVerifier="9"
16+
),
17+
address=UserAddress(
18+
streetLine1="AV PAULISTA 1000",
19+
city="SAO PAULO",
20+
stateCode="SP",
21+
zipCode="01310000"
22+
)
23+
)
24+
25+
file = File()
26+
file.setSender(sender)
27+
28+
payment = ChargePayment()
29+
payment.setSender(sender)
30+
payment.setBarCode("34192791100000020001090000229827307144464000")
31+
payment.setScheduleDate("08062019")
32+
payment.setIdentifier("ID1234567890")
33+
payment.setInfo(
34+
kind="98", # Tipo de pagamento - Diversos
35+
method="30", # Pagamento de Boleto mesmo banco
36+
)
37+
38+
file.add(lot=payment)
39+
40+
file.output(fileName="output3.REM", path="/../../")
41+

0 commit comments

Comments
 (0)