Skip to content

Commit

Permalink
Merge pull request #8 from starkbank/feature/boleto-credit-search
Browse files Browse the repository at this point in the history
Added boleto event search tab, for credited, canceled and overdue events
  • Loading branch information
matheuscferraz authored Jun 1, 2020
2 parents 285f2f5 + f767109 commit ef9bb5f
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 59 deletions.
32 changes: 16 additions & 16 deletions src.vba/BigIntMath.bas
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ End Function
Public Function Divide(ByVal a As String, ByVal b As String) As String
Dim an, bn, rn As Boolean
Dim c As Integer
Dim s As String
Dim S As String
Dim d As PartialDivideInfo
an = (Left(a, 1) = "-")
bn = (Left(b, 1) = "-")
Expand Down Expand Up @@ -258,20 +258,20 @@ Public Function Divide(ByVal a As String, ByVal b As String) As String
Exit Function
End If
Divide = ""
s = ""
S = ""
For c = 1 To Len(a)
s = s + Mid(a, c, 1)
d = PartialDivide(s, b)
S = S + Mid(a, c, 1)
d = PartialDivide(S, b)
Divide = Divide + CStr(d.Quotient)
s = d.Remainder
S = d.Remainder
Next c
Do While Len(Divide) > 1 And Left(Divide, 1) = "0"
Divide = Mid(Divide, 2)
Loop
If Divide <> "0" And rn Then
Divide = "-" + Divide
End If
LastRemainder = s
LastRemainder = S
End Function

Public Function LastModulus() As String
Expand All @@ -291,20 +291,20 @@ Public Function Modulus(ByVal a As String, ByVal b As String) As String
End If
End Function

Public Function BigIntFromString(ByVal s As String, ByVal base As Integer) As String
Public Function BigIntFromString(ByVal S As String, ByVal base As Integer) As String
Dim rn As Boolean
Dim bs As String
Dim i, v As Integer
If Left(s, 1) = "-" Then
If Left(S, 1) = "-" Then
rn = True
s = Mid(s, 2)
S = Mid(S, 2)
Else
rn = False
End If
bs = CStr(base)
BigIntFromString = "0"
For i = 1 To Len(s)
v = InStr(Alphabet, UCase(Mid(s, i, 1)))
For i = 1 To Len(S)
v = InStr(Alphabet, UCase(Mid(S, i, 1)))
If v > 0 Then
BigIntFromString = multiply(BigIntFromString, bs)
BigIntFromString = Add(BigIntFromString, CStr(v - 1))
Expand All @@ -315,20 +315,20 @@ Public Function BigIntFromString(ByVal s As String, ByVal base As Integer) As St
End If
End Function

Public Function BigIntToString(ByVal s As String, ByVal base As Integer) As String
Public Function BigIntToString(ByVal S As String, ByVal base As Integer) As String
Dim rn As Boolean
Dim bs As String
Dim v As Integer
If Left(s, 1) = "-" Then
If Left(S, 1) = "-" Then
rn = True
s = Mid(s, 2)
S = Mid(S, 2)
Else
rn = False
End If
bs = CStr(base)
BigIntToString = ""
Do While Compare(s, "0") > 0
s = Divide(s, bs)
Do While Compare(S, "0") > 0
S = Divide(S, bs)
v = CInt(LastModulus())
BigIntToString = Mid(Alphabet, v + 1, 1) + BigIntToString
Loop
Expand Down
12 changes: 6 additions & 6 deletions src.vba/CSHA256.cls
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ End Function
' DESCRIPTION:
' SHA-256 function (rotate right)
'*******************************************************************************
Private Function s(ByVal x As Long, _
Private Function S(ByVal x As Long, _
ByVal n As Long) As Long
s = (RShift(x, (n And m_lOnBits(4))) Or LShift(x, (32 - (n And m_lOnBits(4)))))
S = (RShift(x, (n And m_lOnBits(4))) Or LShift(x, (32 - (n And m_lOnBits(4)))))
End Function


Expand All @@ -425,7 +425,7 @@ End Function
' SHA-256 function
'*******************************************************************************
Private Function Sigma0(ByVal x As Long) As Long
Sigma0 = (s(x, 2) Xor s(x, 13) Xor s(x, 22))
Sigma0 = (S(x, 2) Xor S(x, 13) Xor S(x, 22))
End Function


Expand All @@ -436,7 +436,7 @@ End Function
' SHA-256 function
'*******************************************************************************
Private Function Sigma1(ByVal x As Long) As Long
Sigma1 = (s(x, 6) Xor s(x, 11) Xor s(x, 25))
Sigma1 = (S(x, 6) Xor S(x, 11) Xor S(x, 25))
End Function


Expand All @@ -447,7 +447,7 @@ End Function
' SHA-256 function
'*******************************************************************************
Private Function Gamma0(ByVal x As Long) As Long
Gamma0 = (s(x, 7) Xor s(x, 18) Xor r(x, 3))
Gamma0 = (S(x, 7) Xor S(x, 18) Xor r(x, 3))
End Function


Expand All @@ -458,7 +458,7 @@ End Function
' SHA-256 function
'*******************************************************************************
Private Function Gamma1(ByVal x As Long) As Long
Gamma1 = (s(x, 17) Xor s(x, 19) Xor r(x, 10))
Gamma1 = (S(x, 17) Xor S(x, 19) Xor r(x, 10))
End Function


Expand Down
19 changes: 17 additions & 2 deletions src.vba/ChargeGateway.bas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ Public Function getStatusInPt(Status As String)
End Select
End Function

Public Function getEventInPt(Status As String)
Select Case Status
Case "paid": getEventInPt = "pago"
Case "bank": getEventInPt = "creditado"
Case "register": getEventInPt = "criado (pendente de registro)"
Case "registered": getEventInPt = "registrado"
Case "overdue": getEventInPt = "vencido"
Case "cancel": getEventInPt = "em cancelamento"
Case "canceled": getEventInPt = "cancelado"
Case "failed": getEventInPt = "falha"
Case "unknown": getEventInPt = "desconhecido"
Case Else: getEventInPt = Status
End Select
End Function

Public Function getStatusFromId(id As String)
Select Case id
Case "00": getStatusFromId = "register"
Expand Down Expand Up @@ -260,14 +275,14 @@ Public Function createCharges(charges As Collection)

End Function

Public Function getEventLog(chargeId As String, logevent As String, optionalParam As Dictionary)
Public Function getEventLog(chargeId As String, logEvent As String, optionalParam As Dictionary)
Dim query As String
Dim resp As response
Dim elem As Variant

query = ""
If chargeId <> "" Then
query = "?events=" + logevent + "&chargeIds=" + chargeId
query = "?events=" + logEvent + "&chargeIds=" + chargeId
End If
If optionalParam.Count > 0 Then
For Each key In optionalParam
Expand Down
22 changes: 11 additions & 11 deletions src.vba/Cnab400.bas
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ Public Function getTaxIdType(taxId As String) As String
getTaxIdType = idType
End Function

Public Function ZeroPad(s As Variant, n As Integer) As String
ZeroPad = Format(CStr(s), String(n, "0"))
Public Function ZeroPad(S As Variant, n As Integer) As String
ZeroPad = Format(CStr(S), String(n, "0"))
End Function

Private Sub DebugDict()
Expand All @@ -123,20 +123,20 @@ End Function

Private Function getLogOccurrenceDate(statusCode As String, chargeId As String) As String
Dim respMessage As Variant
Dim logevent As String
Dim logEvent As String
Set respMessage = ChargeGateway.getChargeLog(chargeId, New Dictionary)

For Each elem In respMessage("logs")
logevent = elem("event")
If (statusCode = ChargeGateway.getStatusInPt(logevent)) Then
logEvent = elem("event")
If (statusCode = ChargeGateway.getStatusInPt(logEvent)) Then
getLogOccurrenceDate = elem("created")
Exit Function
End If
Next

End Function

Private Sub getLogOccurrenceDates(lastRow As Integer, logevent As String)
Private Sub getLogOccurrenceDates(lastRow As Integer, logEvent As String)
Dim chunk As String
Dim respMessage As Dictionary
Dim i As Integer
Expand All @@ -153,23 +153,23 @@ Private Sub getLogOccurrenceDates(lastRow As Integer, logevent As String)
chargeId = CStr(Cells(i, "M").Value)

occurrenceId = ChargeGateway.getOccurrenceId(statusCode)
If ChargeGateway.getStatusFromId(occurrenceId) = logevent Then
If ChargeGateway.getStatusFromId(occurrenceId) = logEvent Then
j = j + 1
chunk = chunk & chargeId & ","
If j >= 100 Then
insertOccurrenceDict chunk, logevent
insertOccurrenceDict chunk, logEvent
chunk = ""
j = 0
End If
End If
Next
If chunk <> "" Then
insertOccurrenceDict chunk, logevent
insertOccurrenceDict chunk, logEvent
End If
End Sub

Private Sub insertOccurrenceDict(chunk As String, logevent As String)
Set respMessage = ChargeGateway.getEventLog(chunk, logevent, New Dictionary)
Private Sub insertOccurrenceDict(chunk As String, logEvent As String)
Set respMessage = ChargeGateway.getEventLog(chunk, logEvent, New Dictionary)

For Each elem In respMessage("logs")
occurrenceDateDict.Add CStr(elem("charge")("id")), elem("created")
Expand Down
5 changes: 5 additions & 0 deletions src.vba/Cover.bas
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ Public Sub BotaoConsultaEmitidos()
ThisWorkbook.Sheets(name).Activate
End Sub

Public Sub BotaoEventosBoletos()
name = "Histórico de Boletos Emitidos"
ThisWorkbook.Sheets(name).Activate
End Sub

Public Sub BotaoEmissaoBoletos()
name = "Emissão de Boletos"
ThisWorkbook.Sheets(name).Activate
Expand Down
6 changes: 3 additions & 3 deletions src.vba/EllipticCurve_Der.bas
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ Public Function readLength(strHexa As String) As String
readLength = respArray
End Function

Public Function encodeSequence(r() As Byte, s() As Byte) As Byte()
Public Function encodeSequence(r() As Byte, S() As Byte) As Byte()
rLen = UBound(r, 1) - LBound(r, 1) + 1
sLen = UBound(s, 1) - LBound(s, 1) + 1
sLen = UBound(S, 1) - LBound(S, 1) + 1
Dim totalLen As Integer: totalLen = rLen + sLen

Dim encodedLength() As Byte: encodedLength = encodeLength(totalLen)
encodedLengthInHexa = BytesToHex(encodedLength)

encodeSequence = HexToBytes("30" & encodedLengthInHexa & BytesToHex(r) & BytesToHex(s))
encodeSequence = HexToBytes("30" & encodedLengthInHexa & BytesToHex(r) & BytesToHex(S))

End Function

Expand Down
4 changes: 2 additions & 2 deletions src.vba/EllipticCurve_Ecdsa.bas
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Public Function sign(message As String, PrivateKey As PrivateKey) As signature

Dim s1 As String: s1 = BigIntMath.Add(numberMessage, BigIntMath.multiply(r, PrivateKey.secret))
Dim s2 As String: s2 = EllipticCurve_Math.inv(randNum, PrivateKey.curve.n)
Dim s As String: s = BigIntMath.Modulus(BigIntMath.multiply(s1, s2), PrivateKey.curve.n)
Dim S As String: S = BigIntMath.Modulus(BigIntMath.multiply(s1, s2), PrivateKey.curve.n)

Dim sig As signature: Set sig = New signature
Call sig.setProperties(r, s)
Call sig.setProperties(r, S)
Set sign = sig
End Function
8 changes: 4 additions & 4 deletions src.vba/EllipticCurve_Math.bas
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ Public Function jacobianDouble(Point As Point, a As String, P As String) As Poin
Set jacobianDouble = pp
Else
Dim ysq As String: ysq = BigIntMath.Modulus(BigIntMath.multiply(Point.y, Point.y), P)
Dim s As String: s = BigIntMath.Modulus(BigIntMath.multiply("4", BigIntMath.multiply(Point.x, ysq)), P)
Dim S As String: S = BigIntMath.Modulus(BigIntMath.multiply("4", BigIntMath.multiply(Point.x, ysq)), P)
Dim z4 As String: z4 = BigIntMath.multiply(Point.z, BigIntMath.multiply(Point.z, BigIntMath.multiply(Point.z, Point.z)))
Dim M As String: M = BigIntMath.Modulus(BigIntMath.Add(BigIntMath.multiply("3", BigIntMath.multiply(Point.x, Point.x)), BigIntMath.multiply(a, z4)), P)
Dim nx As String: nx = BigIntMath.Modulus(BigIntMath.Subtract(BigIntMath.multiply(M, M), BigIntMath.multiply("2", s)), P)
Dim nx As String: nx = BigIntMath.Modulus(BigIntMath.Subtract(BigIntMath.multiply(M, M), BigIntMath.multiply("2", S)), P)

Dim part1 As String: part1 = BigIntMath.multiply(M, BigIntMath.Subtract(s, nx))
Dim part1 As String: part1 = BigIntMath.multiply(M, BigIntMath.Subtract(S, nx))
Dim part2 As String: part2 = BigIntMath.multiply("8", BigIntMath.multiply(ysq, ysq))
Dim part3 As String: part3 = BigIntMath.Subtract(part1, part2)
Dim part4 As String: part4 = BigIntMath.Modulus(part3, P)
Dim ny As String: ny = BigIntMath.Modulus(BigIntMath.Subtract(BigIntMath.multiply(M, BigIntMath.Subtract(s, nx)), BigIntMath.multiply("8", BigIntMath.multiply(ysq, ysq))), P)
Dim ny As String: ny = BigIntMath.Modulus(BigIntMath.Subtract(BigIntMath.multiply(M, BigIntMath.Subtract(S, nx)), BigIntMath.multiply("8", BigIntMath.multiply(ysq, ysq))), P)
Dim nz As String: nz = BigIntMath.Modulus(BigIntMath.multiply("2", BigIntMath.multiply(Point.y, Point.z)), P)

Call pp.setCoordinates(nx, ny, nz)
Expand Down
4 changes: 4 additions & 0 deletions src.vba/Main.bas
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ Public Sub searchCharges()
ViewChargeForm.Show
End Sub

Public Sub searchChargeEvents()
ViewChargeEventsForm.Show
End Sub

Public Sub searchTransfers()
ViewTransferForm.Show
End Sub
Expand Down
2 changes: 1 addition & 1 deletion src.vba/Request.bas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Public Function fetch(url As String, method As String, headers As Dictionary, pa
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open method, url, False

' Debug.Print url
Debug.Print url
For Each key In headers.keys()
objHTTP.setRequestHeader key, headers(key)
Next
Expand Down
6 changes: 3 additions & 3 deletions src.vba/Utils.bas
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,13 @@ Public Function ShellRun(sCmd As String) As String
Set oOutput = oExec.StdOut

'handle the results as they are written to and read from the StdOut object
Dim s As String
Dim S As String
Dim sLine As String
While Not oOutput.AtEndOfStream
sLine = oOutput.ReadLine
If sLine <> "" Then s = s & sLine & vbCrLf
If sLine <> "" Then S = S & sLine & vbCrLf
Wend

ShellRun = s
ShellRun = S

End Function
Loading

0 comments on commit ef9bb5f

Please sign in to comment.