Update library
This commit is contained in:
parent
29a5248974
commit
00968aee30
@ -43,7 +43,7 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
||||
for _, row := range App().Config.TransactionTypes {
|
||||
|
||||
// is refund
|
||||
if slices.Contains(row.NamesRefund, *monobankTransaction.Data.StatementItem.Description) {
|
||||
if slices.Contains(row.NamesRefund, monobankTransaction.Data.StatementItem.Description) {
|
||||
opts := firefly3.TransactionsApiListTransactionOpts{
|
||||
Limit: optional.NewInt32(999),
|
||||
Type_: optional.NewInterface("withdrawal"),
|
||||
@ -76,9 +76,9 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
||||
}
|
||||
|
||||
// find transaction
|
||||
sum := int(math.Abs(math.Round(float64(*monobankTransaction.Amount/100)))) - int(math.Abs(math.Round(float64(*monobankTransaction.CommissionRate/100))))
|
||||
sum := int(math.Abs(math.Round(monobankTransaction.Amount/100))) - int(math.Abs(math.Round(monobankTransaction.CommissionRate/100)))
|
||||
sum2, _ := strconv.ParseFloat(tRow.Amount, 64)
|
||||
if slices.Contains(row.Names, *monobankTransaction.Description) && sum == int(sum2) {
|
||||
if slices.Contains(row.Names, monobankTransaction.Description) && sum == int(sum2) {
|
||||
// delete transaction
|
||||
opts := firefly3.TransactionsApiDeleteTransactionOpts{}
|
||||
App().Firefly3Client.TransactionsApi.DeleteTransaction(context.Background(), tRows.Id, &opts)
|
||||
@ -90,15 +90,15 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
||||
break
|
||||
} else {
|
||||
// check name & mcc
|
||||
if !(slices.Contains(row.Names, *monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, int(*monobankTransaction.Data.StatementItem.Mcc))) {
|
||||
if !(slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, int(monobankTransaction.Data.StatementItem.Mcc))) {
|
||||
continue
|
||||
}
|
||||
|
||||
// create firefly3 transaction
|
||||
firefly3Transaction := firefly3.TransactionSplitStore{
|
||||
Date: time.Unix(int64(*monobankTransaction.Data.StatementItem.Time), 0).Add(time.Hour * time.Duration(timezoneHoursDiff)),
|
||||
Date: time.Unix(int64(monobankTransaction.Data.StatementItem.Time), 0).Add(time.Hour * time.Duration(timezoneHoursDiff)),
|
||||
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(monobankTransaction.Data.StatementItem.Amount/100))) - int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.CommissionRate/100)))),
|
||||
SourceName: account.Firefly3Name,
|
||||
}
|
||||
|
||||
@ -135,13 +135,13 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
||||
break
|
||||
}
|
||||
}
|
||||
if *monobankTransaction.Data.StatementItem.CommissionRate > 0 {
|
||||
if monobankTransaction.Data.StatementItem.CommissionRate > 0 {
|
||||
firefly3Transactions = append(firefly3Transactions, firefly3.TransactionSplitStore{
|
||||
Type_: &firefly3TransactionTypeWithdrawal,
|
||||
Date: time.Unix(int64(*monobankTransaction.Data.StatementItem.Time), 0).Add(time.Hour * time.Duration(timezoneHoursDiff)),
|
||||
Date: time.Unix(int64(monobankTransaction.Data.StatementItem.Time), 0).Add(time.Hour * time.Duration(timezoneHoursDiff)),
|
||||
Notes: string(monobankTransactionJson),
|
||||
Description: "Transfer fee",
|
||||
Amount: strconv.Itoa(int(math.Abs(math.Round(float64(*monobankTransaction.Data.StatementItem.CommissionRate / 100))))),
|
||||
Amount: strconv.Itoa(int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.CommissionRate / 100)))),
|
||||
SourceName: account.Firefly3Name,
|
||||
})
|
||||
}
|
||||
|
11
main.go
11
main.go
@ -35,16 +35,14 @@ func main() {
|
||||
// manual transaction
|
||||
if *flagMonobankListAccounts {
|
||||
// get monobank accounts
|
||||
req := monobank.ApiPersonalClientInfoGetRequest{}
|
||||
req = req.XToken(os.Getenv("MONOBANK_TOKEN"))
|
||||
res, _, err := app.App().MonobankClient.DefaultApi.PersonalClientInfoGetExecute(req)
|
||||
res, _, err := app.App().MonobankClient.Api.PersonalClientInfoGet(context.Background(), os.Getenv("MONOBANK_TOKEN"))
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
|
||||
// list accounts
|
||||
for _, row := range res.Accounts {
|
||||
fmt.Printf("%v\t%v\n", *row.Id, (*row.MaskedPan)[0])
|
||||
fmt.Printf("%v\t%v\n", row.Id, (*row.MaskedPan)[0])
|
||||
}
|
||||
} else if *flagFirefly3ListAccounts {
|
||||
// get firefly3 accounts
|
||||
@ -81,10 +79,7 @@ func main() {
|
||||
webhookUrl := fmt.Sprintf("https://%s/webhook/%s", os.Getenv("MONOBANK_WEBHOOK_DOMAIN"), os.Getenv("MONOBANK_WEBHOOK_SECRET"))
|
||||
|
||||
// register monobank webhook
|
||||
req := monobank.ApiPersonalWebhookPostRequest{}
|
||||
req = req.XToken(os.Getenv("MONOBANK_TOKEN"))
|
||||
req = req.SetWebHook(monobank.SetWebHook{WebHookUrl: &webhookUrl})
|
||||
_, err := app.App().MonobankClient.DefaultApi.PersonalWebhookPostExecute(req)
|
||||
_, err := app.App().MonobankClient.Api.PersonalWebhookPost(context.Background(), monobank.SetWebHook{WebHookUrl: webhookUrl}, os.Getenv("MONOBANK_TOKEN"))
|
||||
if err != nil {
|
||||
log.Fatalln("failed to register monobank webhook")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user