Refactor
This commit is contained in:
parent
b0b5027ee9
commit
5ac140d3c2
11
config.go
11
config.go
@ -18,15 +18,16 @@ type ConfigAccount struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ConfigTransactionTypes struct {
|
type ConfigTransactionTypes struct {
|
||||||
Names []string `json:"names"`
|
Names []string `json:"names,omitempty"`
|
||||||
Firefly3 ConfigTransactionTypeFirefly3 `json:"firefly3,omitempty"`
|
|
||||||
MccCodes []int `json:"mcc_codes,omitempty"`
|
MccCodes []int `json:"mcc_codes,omitempty"`
|
||||||
|
Firefly3 ConfigTransactionTypeFirefly3 `json:"firefly3,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigTransactionTypeFirefly3 struct {
|
type ConfigTransactionTypeFirefly3 struct {
|
||||||
Description string `json:"description"`
|
Type string `json:"type,omitempty"`
|
||||||
Destination string `json:"destination"`
|
Destination string `json:"destination,omitempty"`
|
||||||
Category string `json:"category"`
|
Description string `json:"description,omitempty"`
|
||||||
|
Category string `json:"category,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadConfig(path string) (Config, error) {
|
func ReadConfig(path string) (Config, error) {
|
||||||
|
143
config.json
143
config.json
@ -1,143 +0,0 @@
|
|||||||
{
|
|
||||||
"accounts": [
|
|
||||||
{
|
|
||||||
"name": "Mono Black",
|
|
||||||
"firefly3_id": "1",
|
|
||||||
"monobank_id": "4723djMLsLOCzhoeYjxqRw"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Mono White",
|
|
||||||
"firefly3_id": "1",
|
|
||||||
"monobank_id": "jJPAm0cfwAJv3C0I-kYpTA"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Wallet cash (UAH)",
|
|
||||||
"firefly3_id": "4"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"transaction_types": [
|
|
||||||
{
|
|
||||||
"names": ["Hetzner"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Hetzner: vps2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["YouTube"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "YouTube membership: Latte ASMR"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Київстар +380672463500"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Kyivstar: +380672463500"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Lifecell +380732463500"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Lifecell: +380732463500"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["JetBrains"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "JetBrains: GoLand"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Telegram"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Telegram premium"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Платіж Tefal Initial+"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Credit payment: TEFAL OptiGrill+ Initial GC706D34",
|
|
||||||
"destination": "Credit: TEFAL OptiGrill+ Initial GC706D34"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Платіж Dyson"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Credit payment: Dyson Supersonic HD07 Nickel/Copper",
|
|
||||||
"destination": "Credit: Dyson Supersonic HD07 Nickel/Copper"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Платіж Pixel Watch 2"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Credit payment: Google Pixel Watch 2 Wi-Fi",
|
|
||||||
"destination": "Credit: Google Pixel Watch 2 Wi-Fi"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Платіж Apple Watch 9"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Credit payment: Apple Watch Series 9",
|
|
||||||
"destination": "Credit: Apple Watch Series 9"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Олена А."],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Doctor visit: Елена Ахрипова (психотерапевт)"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Ілля Ш."],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Legal services: Alva Privacy Law Firm",
|
|
||||||
"destination": "Legal: Alva Privacy Law Firm",
|
|
||||||
"category": "Legal services"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["АТБ", "Велмарт", "Novus", "Glovo", "zakaz.ua", "Мегамаркет", "Сільпо", "Фора", "METRO"],
|
|
||||||
"mcc_codes": [5411, 5499, 5451, 5422, 5412, 5921],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Groceries"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Аптека Доброго Дня", "Аптека оптових цін", "Аптека Копійка", "Аптека Гала", "Аптека АНЦ", "APTEKA 7", "Біла ромашка", "vidshkod ekv apt12", "Будемо Здорові Разом", "Apteka Ants", "Аптека Шар@"],
|
|
||||||
"mcc_codes": [5411, 5499, 5451, 5422, 5412, 5921],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Medications"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Київ Цифровий", "Київпастранс"],
|
|
||||||
"mcc_codes": [4131, 4111, 4112],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Public transport"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["McDonald’s"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "McDonalds"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["LeoCafe"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Cafe"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Bolt food", "Glovo", "Menya Musashi", "Mafia"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Restaurant"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": ["Lumberjack Barberhouse"],
|
|
||||||
"firefly3": {
|
|
||||||
"description": "Lumberjack: haircut"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -43,6 +43,14 @@
|
|||||||
"firefly3": {
|
"firefly3": {
|
||||||
"description": "Groceries"
|
"description": "Groceries"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"names": ["З чорної картки"],
|
||||||
|
"firefly3": {
|
||||||
|
"type": "transfer",
|
||||||
|
"description": "Transfer between accounts",
|
||||||
|
"destination": "Mono White"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
39
main.go
39
main.go
@ -35,7 +35,7 @@ func readResponseBody(r *http.Request) (monobank.Transaction, error) {
|
|||||||
//w.WriteHeader(http.StatusOK)
|
//w.WriteHeader(http.StatusOK)
|
||||||
//return
|
//return
|
||||||
|
|
||||||
//body = []byte("{\"type\":\"StatementItem\",\"data\":{\"account\":\"4723djMLsLOCzhoeYjxqRw\",\"statementItem\":{\"id\":\"5_NQ0arGAmp2pyNzvA\",\"time\":1711544958,\"description\":\"Ілля Ш.\",\"mcc\":4829,\"originalMcc\":4829,\"amount\":-572000,\"operationAmount\":-572000,\"currencyCode\":980,\"commissionRate\":22000,\"cashbackAmount\":0,\"balance\":8101246,\"hold\":true,\"receiptId\":\"EMXC-P266-90PC-EB8C\"}}}")
|
body = []byte("{\"type\":\"StatementItem\",\"data\":{\"account\":\"4723djMLsLOCzhoeYjxqRw\",\"statementItem\":{\"id\":\"5_NQ0arGAmp2pyNzvA\",\"time\":1711544958,\"description\":\"З чорної картки\",\"mcc\":4829,\"originalMcc\":4829,\"amount\":-572000,\"operationAmount\":-572000,\"currencyCode\":980,\"commissionRate\":22000,\"cashbackAmount\":0,\"balance\":8101246,\"hold\":true,\"receiptId\":\"EMXC-P266-90PC-EB8C\"}}}")
|
||||||
LogString(string(body))
|
LogString(string(body))
|
||||||
|
|
||||||
// check empty body
|
// check empty body
|
||||||
@ -105,7 +105,6 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
|||||||
var firefly3Transactions []firefly3.TransactionSplitStore
|
var firefly3Transactions []firefly3.TransactionSplitStore
|
||||||
|
|
||||||
firefly3Transaction := firefly3.TransactionSplitStore{
|
firefly3Transaction := firefly3.TransactionSplitStore{
|
||||||
Type_: &firefly3TransactionTypeWithdrawal,
|
|
||||||
Date: time.Unix(int64(monobankTransaction.Data.StatementItem.Time), 0).Add(time.Hour * 2),
|
Date: time.Unix(int64(monobankTransaction.Data.StatementItem.Time), 0).Add(time.Hour * 2),
|
||||||
Notes: string(monobankTransactionJson),
|
Notes: string(monobankTransactionJson),
|
||||||
Amount: strconv.Itoa(int(math.Abs(math.Round(float64(monobankTransaction.Data.StatementItem.Amount/100)))) - int(math.Abs(math.Round(float64(monobankTransaction.Data.StatementItem.CommissionRate/100))))),
|
Amount: strconv.Itoa(int(math.Abs(math.Round(float64(monobankTransaction.Data.StatementItem.Amount/100)))) - int(math.Abs(math.Round(float64(monobankTransaction.Data.StatementItem.CommissionRate/100))))),
|
||||||
@ -113,36 +112,26 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Special transaction cases
|
// Special transaction cases
|
||||||
if slices.Contains([]string{"З чорної картки"}, monobankTransaction.Data.StatementItem.Description) {
|
if slices.Contains([]string{"Термінал EasyPay", "City24", "Термінал City24"}, monobankTransaction.Data.StatementItem.Description) {
|
||||||
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
||||||
firefly3Transaction.Description = "Transfer between accounts"
|
firefly3Transaction.Description = "Transfer between accounts"
|
||||||
firefly3Transaction.DestinationId = ConfigGetAccountByName(config, "Mono White").Firefly3Id
|
firefly3Transaction.SourceName = "Wallet cash (UAH)" // test
|
||||||
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
|
||||||
} else if slices.Contains([]string{"З білої картки"}, monobankTransaction.Data.StatementItem.Description) {
|
|
||||||
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
|
||||||
firefly3Transaction.Description = "Transfer between accounts"
|
|
||||||
firefly3Transaction.DestinationId = ConfigGetAccountByName(config, "Mono Black").Firefly3Id
|
|
||||||
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
|
||||||
} else if slices.Contains([]string{"Термінал City24"}, monobankTransaction.Data.StatementItem.Description) {
|
|
||||||
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
|
||||||
firefly3Transaction.Description = "Transfer between accounts"
|
|
||||||
firefly3Transaction.SourceId = ConfigGetAccountByName(config, "Wallet cash (UAH)").Firefly3Id
|
|
||||||
firefly3Transaction.DestinationId = firefly3Transaction.SourceId
|
|
||||||
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
|
||||||
} else if slices.Contains([]string{"Термінал EasyPay", "City24", "Термінал City24"}, monobankTransaction.Data.StatementItem.Description) {
|
|
||||||
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
|
||||||
firefly3Transaction.Description = "Transfer between accounts"
|
|
||||||
firefly3Transaction.SourceId = ConfigGetAccountByName(config, "Wallet cash (UAH)").Firefly3Id // test
|
|
||||||
firefly3Transaction.DestinationId = account.Firefly3Id // test
|
firefly3Transaction.DestinationId = account.Firefly3Id // test
|
||||||
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
||||||
} else if slices.Contains([]string{"Банкомат DN00"}, monobankTransaction.Data.StatementItem.Description) {
|
|
||||||
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
|
||||||
firefly3Transaction.Description = "Transfer between accounts"
|
|
||||||
firefly3Transaction.DestinationId = ConfigGetAccountByName(config, "Wallet cash (UAH)").Firefly3Id // test
|
|
||||||
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
|
||||||
} 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) {
|
||||||
|
switch row.Firefly3.Type {
|
||||||
|
case "withdrawal":
|
||||||
|
firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal
|
||||||
|
break
|
||||||
|
case "transfer":
|
||||||
|
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal
|
||||||
|
}
|
||||||
|
|
||||||
firefly3Transaction.Description = row.Firefly3.Description
|
firefly3Transaction.Description = row.Firefly3.Description
|
||||||
firefly3Transaction.DestinationName = row.Firefly3.Destination
|
firefly3Transaction.DestinationName = row.Firefly3.Destination
|
||||||
firefly3Transaction.CategoryName = row.Firefly3.Category
|
firefly3Transaction.CategoryName = row.Firefly3.Category
|
||||||
|
Loading…
x
Reference in New Issue
Block a user