1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/***************************************************************************
begin : Tue May 03 2005
copyright : (C) 2018 by Martin Preuss
email : martin@libchipcard.de
***************************************************************************
* This file is part of the project "AqBanking". *
* Please see toplevel file COPYING of that project for license details. *
***************************************************************************/
/***************************************************************************
* This tutorial shows how to use jobs in AqBanking. *
* In this example we retrieve transaction statements for a given account. *
* *
* You must either choose a GUI implementation to be used with AqBanking *
* or create one yourself by implementing the user interface callbacks of *
* LibGwenhywfar. *
* *
* However, for simplicity reasons we use the console GUI implementation *
* which implements these callbacks for you. *
* *
* There are other GUI implementations, e.g. for GTK2, QT3, QT4 and FOX16. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <aqbanking/banking.h>
#include <gwenhywfar/cgui.h>
#include <aqbanking/types/transaction.h>
int main(int argc, char **argv)
{
AB_BANKING *ab;
int rv;
AB_ACCOUNT_SPEC_LIST *accs=NULL;
AB_ACCOUNT_SPEC *as;
GWEN_GUI *gui;
gui=GWEN_Gui_CGui_new();
GWEN_Gui_SetGui(gui);
ab=AB_Banking_new("tutorial4", 0, 0);
/* This is the basic init function. It only initializes the minimum (like
* setting up plugin and data paths). After this function successfully
* returns you may freely use any non-online function. To use online
* banking functions (like getting the list of managed accounts, users
* etc) you will have to call AB_Banking_OnlineInit().
*/
rv=AB_Banking_Init(ab);
if (rv) {
fprintf(stderr, "Error on init (%d)\n", rv);
return 2;
}
fprintf(stderr, "AqBanking successfully initialized.\n");
/* get the list of known accounts */
rv=AB_Banking_GetAccountSpecList(ab, &accs);
if (rv<0) {
fprintf(stderr, "Unable to get the list of accounts (%d: %s)\n", rv, GWEN_Error_SimpleToString(rv));
return 3;
}
/* find a matching account within the given list */
as=AB_AccountSpec_List_FindFirst(accs,
"aqhbci", /* backendName */
"de", /* country */
"28*", /* bankId bank */
"*", /* accountNumber */
"*", /* subAccountId */
"*", /* iban */
"*", /* currency */
AB_AccountType_Unknown); /* ty */
if (as==NULL) {
fprintf(stderr, "No matching account found.\n");
return 3;
} /* if (as==NULL) */
if (as) {
AB_TRANSACTION_LIST2 *cmdList;
AB_TRANSACTION *t;
AB_IMEXPORTER_CONTEXT *ctx;
/* create a list to which banking commands are added */
cmdList=AB_Transaction_List2_new();
/* create an online banking command */
t=AB_Transaction_new();
AB_Transaction_SetCommand(t, AB_Transaction_CommandGetTransactions);
AB_Transaction_SetUniqueAccountId(t, AB_AccountSpec_GetUniqueId(as));
/* add command to the list */
AB_Transaction_List2_PushBack(cmdList, t);
/* we could now add any number of commands here */
/* When sending a list of commands (as we will do below) all the
* data returned by the server will be stored within an ImExporter
* context.
*/
ctx=AB_ImExporterContext_new();
/* execute the jobs which are in the given list (well, for this tutorial
* there is only one job in the list, but the number is not limited).
* This effectivly sends all jobs to the respective backends/banks.
* It only returns an error code (!=0) if there has been a problem
* sending the jobs. */
rv=AB_Banking_SendCommands(ab, cmdList, ctx);
if (rv<0) {
fprintf(stderr, "Error on executeQueue (%d)\n", rv);
/* clean up */
AB_ImExporterContext_free(ctx);
AB_Banking_Fini(ab);
AB_Banking_free(ab);
return 2;
}
else {
AB_IMEXPORTER_ACCOUNTINFO *ai;
ai=AB_ImExporterContext_GetFirstAccountInfo(ctx);
while (ai) {
const AB_TRANSACTION *t;
t=AB_ImExporterAccountInfo_GetFirstTransaction(ai, 0, 0);
while (t) {
const AB_VALUE *v;
v=AB_Transaction_GetValue(t);
if (v) {
const char *purpose;
/* The purpose (memo field) might contain multiple lines. */
purpose=AB_Transaction_GetPurpose(t);
fprintf(stderr, " %-32s (%.2f %s)\n",
purpose,
AB_Value_GetValueAsDouble(v),
AB_Value_GetCurrency(v));
}
t=AB_Transaction_List_Next(t);
} /* while transactions */
ai=AB_ImExporterAccountInfo_List_Next(ai);
} /* while ai */
} /* if executeQueue successful */
/* free im-/exporter context */
AB_ImExporterContext_free(ctx);
} /* if (as) */
/* This function deinitializes AqBanking. It undoes the effects of
* AB_Banking_Init() and should be called before destroying an AB_BANKING
* object.
*/
rv=AB_Banking_Fini(ab);
if (rv) {
fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv);
return 3;
}
/* free AqBanking object */
AB_Banking_free(ab);
return 0;
}
|