Commit 0f6fcca2 authored by Morbi's avatar Morbi

basic hbci fetch

parent f351e7c7
context.ctx
hbci
config.json
log
{
"API": {
"BaseURL": "http://localhost:9991",
"PathPrefix": "v1/",
"Bind": ":9991",
"SwaggerAPIPath": "/apidocs.json",
"SwaggerPath": "/apidocs/",
"SwaggerFilePath": "/home/ubuntu/swagger-ui/dist",
"ImageFilePath": "/home/ubuntu/sangha_images"
},
"Connections": {
"PostgreSQL": {
"Host": "localhost",
"DbName": "sangha",
"User": "user",
"Password": "password",
"Port": 5432,
"SslMode": "disable"
},
"AMQP": {
"Host": "localhost",
"User": "user",
"Password": "password",
"Port": 5672,
"Broker": "rabbit",
"Queue": "payments"
}
},
"PaymentProviders": {
"Hbci": {
"Name": "string",
"UserId": "AA00000000",
"BankCode": "11122233",
"Pin": "secret",
"Url": "https://example.com"
}
},
"Web": {
"BaseURL": "http://localhost:4200/"
}
}
package main
import (
"fmt"
_ "github.com/davecgh/go-spew/spew"
_ "github.com/kr/pretty"
"github.com/spf13/cobra"
"github.com/umsatz/go-aqbanking"
_ "gitlab.techcultivation.org/sangha/mq"
"gitlab.techcultivation.org/sangha/sangha/config"
)
var (
fetchCmd = &cobra.Command{
Use: "fetch",
Short: "fetch new payments",
Long: `The fetch command retrieves all new incoming payments from the bank via hbci`,
RunE: func(cmd *cobra.Command, args []string) error {
return executeFetch()
},
}
)
type Pin struct {
MyBankCode, MyUserID, MyPin string
}
func (p Pin) BankCode() string {
return p.MyBankCode
}
func (p Pin) UserID() string {
return p.MyUserID
}
func (p Pin) Pin() string {
return p.MyPin
}
func executeFetch() error {
// Create a client instance
aq, err := aqbanking.DefaultAQBanking()
if err != nil {
panic(err)
}
fmt.Printf("using aqbanking %d.%d.%d\n",
aq.Version.Major,
aq.Version.Minor,
aq.Version.Patchlevel,
)
user := aqbanking.User{
ID: 0,
Name: config.Settings.PaymentProviders.Hbci.Name,
UserID: config.Settings.PaymentProviders.Hbci.UserId,
CustomerID: config.Settings.PaymentProviders.Hbci.UserId,
BankCode: config.Settings.PaymentProviders.Hbci.BankCode,
ServerURI: config.Settings.PaymentProviders.Hbci.Url,
HbciVersion: 300,
}
userCollection, err := aq.Users()
if err != nil {
fmt.Printf("unable to list accounts: %v", err)
}
for _, u := range userCollection.Users {
if u.UserID == user.UserID {
user = u
break
}
}
fmt.Printf("user: %+v", user)
if user.ID == 0 {
if err = aq.AddPinTanUser(&user); err != nil {
fmt.Println(err)
}
}
p := Pin{
MyUserID: config.Settings.PaymentProviders.Hbci.UserId,
MyBankCode: config.Settings.PaymentProviders.Hbci.BankCode,
MyPin: config.Settings.PaymentProviders.Hbci.Pin,
}
aq.RegisterPin(p)
err = user.FetchAccounts(aq)
if err != nil {
fmt.Printf("unable to list accounts: %v", err)
}
accountCollection, err := aq.Accounts()
if err != nil {
fmt.Printf("unable to list accounts: %v", err)
}
for _, account := range accountCollection.Accounts {
fmt.Printf("%v", account)
transactions, err := aq.AllTransactions(&account)
if err != nil {
fmt.Printf("unable to list transactions: %v", err)
}
for _, transaction := range transactions {
fmt.Printf("transaction: %+v\n", transaction)
}
}
return nil
}
func init() {
RootCmd.AddCommand(fetchCmd)
}
package main
import (
"os"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gitlab.techcultivation.org/sangha/mq"
"gitlab.techcultivation.org/sangha/sangha/config"
"gitlab.techcultivation.org/sangha/sangha/db"
"gitlab.techcultivation.org/sangha/sangha/logger"
)
var (
// RootCmd is the core command used for cli-arg parsing
RootCmd = &cobra.Command{
Use: "hbci",
Short: "hbci processor",
Long: "hbci processor is the hbci processor of the sangha framework\n" +
"Complete documentation is available at https://gitlab.techcultivation.org/sangha/sangha",
SilenceErrors: false,
SilenceUsage: true,
}
)
func main() {
var configFile, logLevelStr string
RootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "config.json", "use this config file (JSON format)")
RootCmd.PersistentFlags().StringVarP(&logLevelStr, "loglevel", "l", "info", "log level")
logLevel, err := log.ParseLevel(logLevelStr)
if err != nil {
log.Fatal(err)
}
log.SetLevel(logLevel)
config.ParseSettings(configFile)
logger.SetupLogger(config.Settings.Connections.Logger.Protocol,
config.Settings.Connections.Logger.Address,
"hbci-processor")
log.Infoln("Starting payment hbci processor")
db.SetupPostgres(config.Settings.Connections.PostgreSQL)
mq.SetupAMQP(config.Settings.Connections.AMQP)
if err := RootCmd.Execute(); err != nil {
os.Exit(-1)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment