Compare commits

..

10 Commits

Author SHA1 Message Date
a5c9403576 Add transaction adjustment on cancellation (when amount differs)
All checks were successful
build docker image / docker-build (push) Successful in 2m16s
2025-06-06 16:54:36 +03:00
ebb213a3cc Add transaction adjustment on cancellation (when amount differs)
Some checks failed
build docker image / docker-build (push) Has been cancelled
2025-06-06 16:54:16 +03:00
f947606131 Update .gitea/workflows/build-docker-image.yaml
All checks were successful
build docker image / docker-build (push) Successful in 1m4s
2025-01-04 21:47:29 +02:00
464093e5bd Add docker deploy
All checks were successful
build docker image / docker-build (push) Successful in 53s
2024-11-15 13:29:14 +02:00
f96f88d16e Add docker deploy
Some checks failed
build docker image / docker-build (push) Has been cancelled
2024-11-15 13:28:44 +02:00
686c46bf78 Add docker deploy
All checks were successful
build docker image / docker-build (push) Successful in 1m32s
2024-11-04 21:58:44 +02:00
38b4e89a02 Add docker deploy
All checks were successful
build docker image / docker-build (push) Successful in 1m32s
2024-11-04 20:39:15 +02:00
3986e1c9de Add docker deploy
All checks were successful
build docker image / docker-build (push) Successful in 49s
2024-11-04 20:18:28 +02:00
f0e26a0cd2 Add docker deploy
Some checks failed
build docker image / docker-build (push) Has been cancelled
2024-11-04 20:18:18 +02:00
00657a8660 Add docker deploy
Some checks failed
build docker image / docker-build (push) Has been cancelled
2024-11-04 20:18:07 +02:00
4 changed files with 60 additions and 24 deletions

View File

@ -29,8 +29,6 @@ jobs:
with:
platforms: linux/amd64
push: true
build-args: |
APP_URL="${{ vars.APP_URL }}"
tags: gitea.stuzer.link/stuzer05/monobank-firefly3-bot:latest
cache-from: type=registry,ref=gitea.stuzer.link/stuzer05/monobank-firefly3-bot:latest
cache-to: type=inline

View File

@ -1,8 +1,11 @@
FROM golang:1.23.2 AS builder
# Install certificates
RUN apt-get update && apt-get install -y ca-certificates
WORKDIR /app
COPY go.mod go.sum ./
COPY go.mod go.sum .
RUN go mod download && go mod verify
@ -14,7 +17,6 @@ RUN make
FROM scratch
COPY --from=builder /etc/ssl/* /etc/ssl
COPY --from=builder /app/monobank-firefly3-bot /app
ENTRYPOINT ["/app"]

View File

@ -55,7 +55,7 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
return err
}
// find matching transaction to delete
// find matching transaction to adjust/delete
isDeleted := false
for _, tRows := range oldTransactions.Data {
if isDeleted {
@ -70,24 +70,54 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
}
// read monobank transaction
var monobankTransaction monobank.WebHookResponse
err = json.Unmarshal(notesBytes, &monobankTransaction)
var monobankTransactionOld monobank.WebHookResponse
err = json.Unmarshal(notesBytes, &monobankTransactionOld)
if err != nil {
continue
}
// Parse amounts
sumNew := int64(math.Abs(math.Round(monobankTransaction.Data.StatementItem.Amount/100))) - int64(math.Abs(math.Round(monobankTransaction.Data.StatementItem.CommissionRate/100)))
sumOldFloat, _ := strconv.ParseFloat(tRow.Amount, 64)
sumOld := int64(sumOldFloat)
// find transaction
sum := int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.Amount/100))) - int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.CommissionRate/100)))
sum2, _ := strconv.ParseFloat(tRow.Amount, 64)
if slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) && sum == int(sum2) {
if slices.Contains(row.Names, monobankTransactionOld.Data.StatementItem.Description) {
if sumNew == sumOld {
// delete transaction
opts := firefly3.TransactionsApiDeleteTransactionOpts{}
_, err := App().Firefly3Client.TransactionsApi.DeleteTransaction(context.Background(), tRows.Id, &opts)
if err != nil {
return err
}
} else {
// adjust transaction
opts := firefly3.TransactionsApiUpdateTransactionOpts{}
body := firefly3.TransactionUpdate{
Transactions: []firefly3.TransactionSplitUpdate{
{
Description: tRow.Description,
CategoryId: tRow.CategoryId,
DestinationId: tRow.DestinationId,
SourceId: tRow.SourceId,
CurrencyId: tRow.CurrencyId,
ExternalUrl: tRow.ExternalUrl,
Date: tRow.Date,
DueDate: tRow.DueDate,
Tags: tRow.Tags,
Notes: tRow.Notes,
// Notes: string(monobankTransactionJson),
Amount: strconv.FormatInt(sumOld-sumNew, 10),
},
},
}
_, _, err := App().Firefly3Client.TransactionsApi.UpdateTransaction(context.Background(), body, tRows.Id, &opts)
if err != nil {
return err
}
}
isDeleted = true
isDeleted = true // break 2
}
}
}

View File

@ -9,6 +9,10 @@ import (
)
func handleWebhook(w http.ResponseWriter, r *http.Request) {
// Parse URL query parameters
queryParams := r.URL.Query()
isRetry := queryParams.Get("retry") == "true"
// read request body bytes
body, err := io.ReadAll(r.Body)
if err != nil {
@ -36,7 +40,8 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
return
}
// check if transaction hs been logged
// only check for logged transaction if not a retry
if !isRetry {
isTransactionAlreadyLogged, err := app.LogContainsTransactionID(monobankTransaction.Data.StatementItem.Id)
if err != nil {
app.LogString(err.Error())
@ -45,6 +50,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
if isTransactionAlreadyLogged {
return
}
}
err = app.ImportTransaction(monobankTransaction)
if err != nil {