Esempio n. 1
0
// FetchAccounts returns all accounts registered for a given aqbanking instance
func (u *User) FetchAccounts(aq *AQBanking) error {
	ctx := C.AB_ImExporterContext_new()

	pro := C.AB_Banking_GetProvider(aq.ptr, C.CString("aqhbci"))
	if err := C.AH_Provider_GetAccounts(pro, u.ptr, ctx, 1, 0, 1); err != 0 {
		return fmt.Errorf("Error getting accounts (%d)", err)
	}

	C.AB_ImExporterContext_free(ctx)
	return nil
}
Esempio n. 2
0
// Transactions implements AB_JobGetTransactions_new from aqbanking, listing
// all transactions from a given aqbanking instance
func (ab *AQBanking) Transactions(acc *Account, from *time.Time, to *time.Time) ([]Transaction, error) {
	abJob := C.AB_JobGetTransactions_new(acc.ptr)

	if abJob == nil {
		return nil, errors.New("Unable to load transactions.")
	}

	if err := C.AB_Job_CheckAvailability(abJob); err != 0 {
		return nil, fmt.Errorf("Transactions is not supported by backend: %d", err)
	}

	if from != nil && to != nil {
		C.AB_JobGetTransactions_SetFromTime(abJob, (*C.GWEN_TIME)(newGwenTime(*from)))
		C.AB_JobGetTransactions_SetToTime(abJob, (*C.GWEN_TIME)(newGwenTime(*to)))
	}

	abJobList := C.AB_Job_List2_new()
	C.AB_Job_List2_PushBack(abJobList, abJob)
	abContext := C.AB_ImExporterContext_new()

	if err := C.AB_Banking_ExecuteJobs(ab.ptr, abJobList, abContext); err != 0 {
		return nil, fmt.Errorf("Unable to execute Transactions: %d", err)
	}

	if C.AB_Job_GetStatus(abJob) == C.AB_Job_StatusError {
		return nil, errors.New(C.GoString(C.AB_Job_GetResultText(abJob)))
	}

	abInfo := C.AB_ImExporterContext_GetFirstAccountInfo(abContext)
	var transactions = make([]Transaction, 0)

	for abInfo != nil {
		abTransaction := C.AB_ImExporterAccountInfo_GetFirstTransaction(abInfo)

		for abTransaction != nil {
			transaction, ok := newTransaction(abTransaction)

			if ok {
				transactions = append(transactions, transaction)
			}

			abTransaction = C.AB_ImExporterAccountInfo_GetNextTransaction(abInfo)
		}
		abInfo = C.AB_ImExporterContext_GetNextAccountInfo(abContext)
	}

	C.AB_Job_free(abJob)

	return transactions, nil
}