diff --git a/src.vba/BigIntMath.bas b/src.vba/BigIntMath.bas index c873404..18c99f5 100644 --- a/src.vba/BigIntMath.bas +++ b/src.vba/BigIntMath.bas @@ -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) = "-") @@ -258,12 +258,12 @@ 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) @@ -271,7 +271,7 @@ Public Function Divide(ByVal a As String, ByVal b As String) As String If Divide <> "0" And rn Then Divide = "-" + Divide End If - LastRemainder = s + LastRemainder = S End Function Public Function LastModulus() As String @@ -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)) @@ -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 diff --git a/src.vba/CSHA256.cls b/src.vba/CSHA256.cls index df795a8..e813165 100644 --- a/src.vba/CSHA256.cls +++ b/src.vba/CSHA256.cls @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src.vba/ChargeGateway.bas b/src.vba/ChargeGateway.bas index 7d2f382..239058f 100644 --- a/src.vba/ChargeGateway.bas +++ b/src.vba/ChargeGateway.bas @@ -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" @@ -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 diff --git a/src.vba/Cnab400.bas b/src.vba/Cnab400.bas index ede6593..49c09e7 100644 --- a/src.vba/Cnab400.bas +++ b/src.vba/Cnab400.bas @@ -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() @@ -123,12 +123,12 @@ 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 @@ -136,7 +136,7 @@ Private Function getLogOccurrenceDate(statusCode As String, chargeId As String) 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 @@ -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") diff --git a/src.vba/Cover.bas b/src.vba/Cover.bas index 249f6cd..6b4d437 100644 --- a/src.vba/Cover.bas +++ b/src.vba/Cover.bas @@ -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 diff --git a/src.vba/EllipticCurve_Der.bas b/src.vba/EllipticCurve_Der.bas index af8db40..6d78ba4 100644 --- a/src.vba/EllipticCurve_Der.bas +++ b/src.vba/EllipticCurve_Der.bas @@ -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 diff --git a/src.vba/EllipticCurve_Ecdsa.bas b/src.vba/EllipticCurve_Ecdsa.bas index 2e618d6..da39798 100644 --- a/src.vba/EllipticCurve_Ecdsa.bas +++ b/src.vba/EllipticCurve_Ecdsa.bas @@ -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 \ No newline at end of file diff --git a/src.vba/EllipticCurve_Math.bas b/src.vba/EllipticCurve_Math.bas index 1cb0c8a..fd76020 100644 --- a/src.vba/EllipticCurve_Math.bas +++ b/src.vba/EllipticCurve_Math.bas @@ -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) diff --git a/src.vba/Main.bas b/src.vba/Main.bas index df287e1..4b229b3 100644 --- a/src.vba/Main.bas +++ b/src.vba/Main.bas @@ -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 diff --git a/src.vba/Request.bas b/src.vba/Request.bas index e5be7ba..351ec71 100644 --- a/src.vba/Request.bas +++ b/src.vba/Request.bas @@ -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 diff --git a/src.vba/Utils.bas b/src.vba/Utils.bas index 6131641..7bddf50 100644 --- a/src.vba/Utils.bas +++ b/src.vba/Utils.bas @@ -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 \ No newline at end of file diff --git a/src.vba/ViewChargeEventsForm.frm b/src.vba/ViewChargeEventsForm.frm new file mode 100644 index 0000000..94ce063 --- /dev/null +++ b/src.vba/ViewChargeEventsForm.frm @@ -0,0 +1,306 @@ + +Private Sub AfterTextBox_Change() + Static reentry As Boolean + If reentry Then Exit Sub + + reentry = True + AfterTextBox.text = Utils.formatDateInUserForm(AfterTextBox.text) + reentry = False +End Sub + +Private Sub BeforeTextBox_Change() + Static reentry As Boolean + If reentry Then Exit Sub + + reentry = True + BeforeTextBox.text = Utils.formatDateInUserForm(BeforeTextBox.text) + reentry = False +End Sub + +Private Sub UserForm_Initialize() + Me.OptionButtonEventCredited.Enabled = True + + Me.AfterTextBox.Value = InputLogGateway.getAfterDate() + Me.BeforeTextBox.Value = InputLogGateway.getBeforeDate() +End Sub + +Private Sub SearchButton_Click() + ' On Error Resume Next + Dim afterInput As String: afterInput = AfterTextBox.Value + Dim beforeInput As String: beforeInput = BeforeTextBox.Value + + Dim after As String: after = Utils.DateToSendingFormat(afterInput) + Dim before As String: before = Utils.DateToSendingFormat(beforeInput) + + Dim id As String + Dim amount As Double + Dim fee As Double + Dim issueDate As String + Dim eventDate As String + Dim chargeStatus As String + Dim logEvent As String + Dim dueDate As String + Dim tags As Collection + + Dim cursor As String + Dim charge As Object + Dim chargeLog As Object + Dim charges As Collection + Dim chargeLogs As Collection + Dim row As Long + Dim logRow As Long + Dim optionalParam As Dictionary: Set optionalParam = New Dictionary + Dim rng As Range + + Dim logsPaidByCharge As Dictionary: Set logsPaidByCharge = New Dictionary + Dim logsRegisteredByCharge As Dictionary: Set logsRegisteredByCharge = New Dictionary + + Call InputLogGateway.saveDates(afterInput, beforeInput) + + 'Table layout + Utils.applyStandardLayout ("V") + ActiveSheet.Hyperlinks.Delete + Range("A" & CStr(TableFormat.HeaderRow() + 1) & ":V" & Rows.Count).ClearContents + + 'Headers definition + + ActiveSheet.Cells(TableFormat.HeaderRow(), 1).Value = "Data do Evento" + ActiveSheet.Cells(TableFormat.HeaderRow(), 2).Value = "Evento" + ActiveSheet.Cells(TableFormat.HeaderRow(), 3).Value = "Nome" + ActiveSheet.Cells(TableFormat.HeaderRow(), 4).Value = "CPF/CNPJ" + ActiveSheet.Cells(TableFormat.HeaderRow(), 5).Value = "Valor" + ActiveSheet.Cells(TableFormat.HeaderRow(), 6).Value = "Valor de Emissão" + ActiveSheet.Cells(TableFormat.HeaderRow(), 7).Value = "Desconto" + ActiveSheet.Cells(TableFormat.HeaderRow(), 8).Value = "Multa" + ActiveSheet.Cells(TableFormat.HeaderRow(), 9).Value = "Juros" + ActiveSheet.Cells(TableFormat.HeaderRow(), 10).Value = "Data de Emissão" + ActiveSheet.Cells(TableFormat.HeaderRow(), 11).Value = "Vencimento" + ActiveSheet.Cells(TableFormat.HeaderRow(), 12).Value = "Linha Digitável" + ActiveSheet.Cells(TableFormat.HeaderRow(), 13).Value = "Id do Boleto" + ActiveSheet.Cells(TableFormat.HeaderRow(), 14).Value = "Tarifa" + ActiveSheet.Cells(TableFormat.HeaderRow(), 15).Value = "Tags" + ActiveSheet.Cells(TableFormat.HeaderRow(), 16).Value = "Link PDF" + ActiveSheet.Cells(TableFormat.HeaderRow(), 17).Value = "Logradouro" + ActiveSheet.Cells(TableFormat.HeaderRow(), 18).Value = "Complemento" + ActiveSheet.Cells(TableFormat.HeaderRow(), 19).Value = "Bairro" + ActiveSheet.Cells(TableFormat.HeaderRow(), 20).Value = "Cidade" + ActiveSheet.Cells(TableFormat.HeaderRow(), 21).Value = "Estado" + ActiveSheet.Cells(TableFormat.HeaderRow(), 22).Value = "CEP" + + Call FreezeHeader + + 'Optional parameters + + If after <> "--" Then + optionalParam.Add "after", after + End If + If before <> "--" Then + optionalParam.Add "before", before + End If + + Dim Events As String: Events = "" +' If OptionButtonEventCreated.Value Then +' Events = Events + "register," +' End If +' If OptionButtonEventRegistered.Value Then +' Events = Events + "registered," +' End If + If OptionButtonEventCanceled.Value Then + Events = Events + "canceled," + End If + If OptionButtonEventOverdue.Value Then + Events = Events + "overdue," + End If + If OptionButtonEventCredited.Value Then + Events = Events + "bank," + End If + + row = TableFormat.HeaderRow() + 1 + If Events <> "bank," Then + optionalParam.Add "events", Events + Do + Set respJson = getChargeLogs(cursor, optionalParam) + cursor = "" + If respJson("cursor") <> "" Then + cursor = respJson("cursor") + End If + + Set logs = respJson("logs") + + For Each chargeLog In logs + + Set charge = chargeLog("charge") + + logEvent = chargeLog("event") + id = charge("id") + amount = charge("amount") / 100 + fee = charge("fee") / 100 + eventDate = chargeLog("created") + issueDate = charge("issueDate") + chargeStatus = charge("status") + dueDate = charge("dueDate") + Set tags = charge("tags") + + ActiveSheet.Cells(row, 1).Value = Utils.ISODATEZ(eventDate) + ActiveSheet.Cells(row, 2).Value = ChargeGateway.getEventInPt(logEvent) + ActiveSheet.Cells(row, 3).Value = charge("name") + ActiveSheet.Cells(row, 4).Value = charge("taxId") + ActiveSheet.Cells(row, 5).Value = amount + + ActiveSheet.Cells(row, 10).Value = Utils.ISODATEZ(issueDate) + ActiveSheet.Cells(row, 11).Value = Utils.ISODATEZ(dueDate) + ActiveSheet.Cells(row, 12).Value = charge("line") + ActiveSheet.Cells(row, 13).Value = id + ActiveSheet.Cells(row, 14).Value = fee + ActiveSheet.Cells(row, 15).Value = CollectionToString(tags, ",") + + ActiveSheet.Cells(row, 16).Value = "PDF" + Set rng = ActiveSheet.Range("P" + CStr(row)) + rng.Parent.Hyperlinks.Add Anchor:=rng, address:=StarkBankApi.baseUrl() + "/v1/charge/" + charge("id") + "/pdf", SubAddress:="", TextToDisplay:="PDF" + row = row + 1 + Next + Loop While cursor <> "" + Unload Me + Exit Sub + End If + optionalParam.Add "events", Events + Do + logRow = row + Set respJson = getChargeLogs(cursor, optionalParam) + If respJson.Exists("error") Then + Unload Me + Exit Sub + End If + + cursor = "" + If respJson("cursor") <> "" Then + cursor = respJson("cursor") + End If + + Set logs = respJson("logs") + + For Each chargeLog In logs + Set charge = chargeLog("charge") + + eventDate = chargeLog("created") + logEvent = chargeLog("event") + id = charge("id") + amount = charge("amount") / 100 + fee = charge("fee") / 100 + issueDate = charge("issueDate") + chargeStatus = charge("status") + dueDate = charge("dueDate") + Set tags = charge("tags") + + ActiveSheet.Cells(row, 1).Value = Utils.ISODATEZ(eventDate) + ActiveSheet.Cells(row, 2).Value = ChargeGateway.getEventInPt(logEvent) + ActiveSheet.Cells(row, 3).Value = charge("name") + ActiveSheet.Cells(row, 4).Value = charge("taxId") + + ActiveSheet.Cells(row, 5).Value = amount + + ActiveSheet.Cells(row, 10).Value = Utils.ISODATEZ(issueDate) + ActiveSheet.Cells(row, 11).Value = Utils.ISODATEZ(dueDate) + ActiveSheet.Cells(row, 12).Value = charge("line") + ActiveSheet.Cells(row, 13).Value = id + ActiveSheet.Cells(row, 14).Value = fee + ActiveSheet.Cells(row, 15).Value = CollectionToString(tags, ",") + + ActiveSheet.Cells(row, 16).Value = "PDF" + Set rng = ActiveSheet.Range("P" + CStr(row)) + rng.Parent.Hyperlinks.Add Anchor:=rng, address:=StarkBankApi.baseUrl() + "/v1/charge/" + charge("id") + "/pdf", SubAddress:="", TextToDisplay:="PDF" + + ActiveSheet.Cells(row, 17).Value = charge("streetLine1") + ActiveSheet.Cells(row, 18).Value = charge("streetLine2") + ActiveSheet.Cells(row, 19).Value = charge("district") + ActiveSheet.Cells(row, 20).Value = charge("city") + ActiveSheet.Cells(row, 21).Value = charge("stateCode") + ActiveSheet.Cells(row, 22).Value = charge("zipCode") + + If chargeStatus = "paid" Then + logsPaidByCharge.Add id, chargeLog + logsRegisteredByCharge.Add id, New Dictionary + End If + + row = row + 1 + Next + + Dim logsParam As Dictionary + Dim keys As String + Dim sep As String + Dim registeredCursor As String: registeredCursor = "" + keys = "" + sep = "" + Set logsParam = New Dictionary + + For Each chargeId In logsPaidByCharge.keys() + keys = keys + sep + chargeId + sep = "," + Next + logsParam.Add "chargeIds", keys + + Do + logsParam("events") = "register" + logsParam("cursor") = registeredCursor + Set respJson = getChargeLogs("", logsParam) + If respJson.Exists("error") Then + MsgBox "Erro ao obter dados detalhados de boletos registrados!" + Exit Sub + End If + If respJson("cursor") <> "" Then + registeredCursor = respJson("cursor") + End If + Set registeredLogs = respJson("logs") + For Each registeredLog In registeredLogs + Set logsRegisteredByCharge(registeredLog("charge")("id")) = registeredLog + Next + Loop While registeredCursor <> "" + + For Each chargeLog In logs + Set charge = chargeLog("charge") + If charge("status") = "paid" Then + Call setChargeEventInfo(charge, logsPaidByCharge(charge("id")), logsRegisteredByCharge(charge("id")), logRow) + End If + logRow = logRow + 1 + Next + + Set logsPaidByCharge = New Dictionary + Set logsRegisteredByCharge = New Dictionary + + Loop While cursor <> "" + + Unload Me +End Sub + +Public Sub setChargeEventInfo(ByVal charge As Object, ByVal paidLog As Dictionary, ByVal createdLog As Dictionary, row As Long) + Dim nominalAmount As Double + Dim fine As Double + Dim amount As Double + Dim interest As Double + Dim discount As Double + Dim deltaAmount As Double + Dim logs As Collection + Dim id As String: id = charge("id") + + amount = charge("amount") / 100 + + nominalAmount = createdLog("charge")("amount") / 100 + deltaAmount = amount - nominalAmount + + ActiveSheet.Cells(row, 6).Value = nominalAmount + If deltaAmount < 0 Then + discount = deltaAmount + ActiveSheet.Cells(row, 7).Value = discount + ActiveSheet.Cells(row, 7).Font.Color = RGB(180, 0, 0) + End If + If deltaAmount > 0 Then + fine = charge("fine") / 100 * nominalAmount + interest = amount - fine - nominalAmount + ActiveSheet.Cells(row, 8).Value = fine + ActiveSheet.Cells(row, 9).Value = interest + ActiveSheet.Cells(row, 8).Font.Color = RGB(0, 140, 0) + ActiveSheet.Cells(row, 9).Font.Color = RGB(0, 140, 0) + End If +End Sub + + diff --git a/src.vba/privateKey.cls b/src.vba/privateKey.cls index e296f65..52a64ca 100644 --- a/src.vba/privateKey.cls +++ b/src.vba/privateKey.cls @@ -18,29 +18,29 @@ End Function Public Function fromDer(strByte() As Byte) Dim strs() As String: strs = Split(EllipticCurve_Der.removeSequence(strByte), ",") - Dim s As String: s = strs(0) + Dim S As String: S = strs(0) Dim emptyStr As String: emptyStr = strs(1) If Len(emptyStr) <> 0 Then Err.Raise number:=vbObjectError + 513, description:="trailing junk after DER privkey: " & emptyStr End If - strs = Split(EllipticCurve_Der.removeInteger(s), ",") + strs = Split(EllipticCurve_Der.removeInteger(S), ",") Dim one As String: one = strs(0) - s = strs(1) + S = strs(1) If one <> "1" Then Err.Raise number:=vbObjectError + 513, description:="expected '1' at start of DER privkey, got " & one End If - strs = Split(EllipticCurve_Der.removeOctetString(s), ",") + strs = Split(EllipticCurve_Der.removeOctetString(S), ",") Dim privkeyStr As String: privkeyStr = strs(0) - s = strs(1) + S = strs(1) - strs = Split(EllipticCurve_Der.removeConstructed(s), ",") + strs = Split(EllipticCurve_Der.removeConstructed(S), ",") Dim tag As String: tag = strs(0) Dim curveOidStr As String: curveOidStr = strs(1) - s = strs(2) + S = strs(2) If tag <> "0" Then Err.Raise number:=vbObjectError + 513, description:="expected tag 0 in DER privkey, got " & tag diff --git a/src.vba/signature.cls b/src.vba/signature.cls index 279ca9d..f6e87c2 100644 --- a/src.vba/signature.cls +++ b/src.vba/signature.cls @@ -1,19 +1,19 @@ Public r As String -Public s As String +Public S As String Private Sub Class_Initialize() r = vbNullString - s = vbNullString + S = vbNullString End Sub Public Function setProperties(p1 As String, p2 As String) r = p1 - s = p2 + S = p2 End Function Public Function toDer() As Byte() Dim rEncoded() As Byte: rEncoded = EllipticCurve_Der.encodeInteger(r) - Dim sEncoded() As Byte: sEncoded = EllipticCurve_Der.encodeInteger(s) + Dim sEncoded() As Byte: sEncoded = EllipticCurve_Der.encodeInteger(S) toDer = EllipticCurve_Der.encodeSequence(rEncoded, sEncoded) End Function diff --git a/starkbank-sdk.xlsm b/starkbank-sdk.xlsm index 42f126c..b60fd02 100644 Binary files a/starkbank-sdk.xlsm and b/starkbank-sdk.xlsm differ