Add support for swap source&destination
This commit is contained in:
parent
b5d81243e0
commit
de4369997d
@ -29,6 +29,7 @@ type ConfigTransactionTypeFirefly3 struct {
|
||||
Destination string `json:"destination,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
IsUseDestinationAsSource bool `json:"is_use_destination_as_source,omitempty"`
|
||||
}
|
||||
|
||||
func ReadConfig(path string) (Config, error) {
|
||||
|
@ -52,6 +52,15 @@
|
||||
"destination": "Mono White"
|
||||
}
|
||||
},
|
||||
{
|
||||
"names": ["Термінал EasyPay", "City24", "Термінал City24"],
|
||||
"firefly3": {
|
||||
"type": "transfer",
|
||||
"description": "Transfer between accounts",
|
||||
"destination": "Wallet cash (UAH)",
|
||||
"is_use_destination_as_source": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"names": ["Novapay"],
|
||||
"firefly3": {
|
||||
|
15
webhook.go
15
webhook.go
@ -72,14 +72,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
||||
SourceId: account.Firefly3Id,
|
||||
}
|
||||
|
||||
// Special transaction cases
|
||||
if slices.Contains([]string{"Термінал EasyPay", "City24", "Термінал City24"}, monobankTransaction.Data.StatementItem.Description) {
|
||||
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
||||
firefly3Transaction.Description = "Transfer between accounts"
|
||||
firefly3Transaction.SourceName = "Wallet cash (UAH)" // test
|
||||
firefly3Transaction.DestinationId = account.Firefly3Id // test
|
||||
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
||||
} else {
|
||||
// match transaction with config
|
||||
for _, row := range config.TransactionTypes {
|
||||
// check name & mcc
|
||||
if !(slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, monobankTransaction.Data.StatementItem.Mcc)) {
|
||||
@ -111,8 +104,12 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
||||
firefly3Transaction.DestinationName = row.Firefly3.Destination
|
||||
firefly3Transaction.CategoryName = row.Firefly3.Category
|
||||
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
||||
break
|
||||
|
||||
// swap source and destination
|
||||
if row.Firefly3.IsUseDestinationAsSource {
|
||||
firefly3Transaction.SourceName, firefly3Transaction.DestinationName = firefly3Transaction.DestinationName, firefly3Transaction.SourceName
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// record transfer fee
|
||||
|
Loading…
x
Reference in New Issue
Block a user