Add sum_max config property

This commit is contained in:
Illya Marchenko 2024-03-29 22:05:27 +02:00
parent 774ca114dd
commit 9a04c8deb2
Signed by: stuzer05
GPG Key ID: A6ABAAA9268F9F4F
3 changed files with 28 additions and 15 deletions

@ -21,6 +21,7 @@ type ConfigTransactionTypes struct {
Names []string `json:"names,omitempty"` Names []string `json:"names,omitempty"`
MccCodes []int `json:"mcc_codes,omitempty"` MccCodes []int `json:"mcc_codes,omitempty"`
Firefly3 ConfigTransactionTypeFirefly3 `json:"firefly3,omitempty"` Firefly3 ConfigTransactionTypeFirefly3 `json:"firefly3,omitempty"`
SumMax int `json:"sum_max,omitempty"`
} }
type ConfigTransactionTypeFirefly3 struct { type ConfigTransactionTypeFirefly3 struct {

@ -52,5 +52,12 @@
"destination": "Mono White" "destination": "Mono White"
} }
}, },
{
"names": ["Novapay"],
"firefly3": {
"description": "NovaPoshta: delivery"
},
"sum_max": 150
}
] ]
} }

@ -81,6 +81,10 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
} else { } else {
for _, row := range config.TransactionTypes { for _, row := range config.TransactionTypes {
if slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, monobankTransaction.Data.StatementItem.Mcc) { if slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, monobankTransaction.Data.StatementItem.Mcc) {
sum, _ := strconv.Atoi(firefly3Transaction.Amount)
// check max sum
if row.SumMax == 0 || sum <= row.SumMax {
switch row.Firefly3.Type { switch row.Firefly3.Type {
case "withdrawal": case "withdrawal":
firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal
@ -100,6 +104,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
} }
} }
} }
}
// record transfer fee // record transfer fee
if monobankTransaction.Data.StatementItem.CommissionRate > 0 { if monobankTransaction.Data.StatementItem.CommissionRate > 0 {