LibOFX
ofx_request_statement.cpp
Go to the documentation of this file.
1/***************************************************************************
2 ofx_request_statement.cpp
3 -------------------
4 copyright : (C) 2005 by Ace Jones
5 email : acejones@users.sourceforge.net
6***************************************************************************/
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24#include <cstdlib>
25#include <string>
26#include "libofx.h"
27#include "ofx_utilities.hh"
29
30using namespace std;
31
32char* libofx_request_statement( const OfxFiLogin* login, const OfxAccountData* account, time_t date_from )
33{
34 OfxStatementRequest strq( *login, *account, date_from );
35 string request = OfxHeader(login->header_version) + strq.Output();
36
37 unsigned size = request.size();
38 char* result = (char*)malloc(size + 1);
39 request.copy(result, size);
40 result[size] = 0;
41
42 return result;
43}
44
45OfxStatementRequest::OfxStatementRequest( const OfxFiLogin& fi, const OfxAccountData& account, time_t from ):
46 OfxRequest(fi),
47 m_account(account),
48 m_date_from(from)
49{
50 Add( SignOnRequest() );
51
52 if ( account.account_type == account.OFX_CREDITCARD )
54 else if ( account.account_type == account.OFX_INVESTMENT || account.account_type == account.OFX_401K)
56 else
58}
59
61{
62 OfxAggregate bankacctfromTag("BANKACCTFROM");
63 bankacctfromTag.Add( "BANKID", m_account.bank_id );
64 bankacctfromTag.Add( "ACCTID", m_account.account_number );
65 if ( m_account.account_type == m_account.OFX_CHECKING )
66 bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
67 else if ( m_account.account_type == m_account.OFX_SAVINGS )
68 bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
69 else if ( m_account.account_type == m_account.OFX_MONEYMRKT )
70 bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
71 else if ( m_account.account_type == m_account.OFX_CREDITLINE )
72 bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
73 else if ( m_account.account_type == m_account.OFX_CMA )
74 bankacctfromTag.Add( "ACCTTYPE", "CMA" );
75
76 OfxAggregate inctranTag("INCTRAN");
77 inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
78 inctranTag.Add( "INCLUDE", "Y" );
79
80 OfxAggregate stmtrqTag("STMTRQ");
81 stmtrqTag.Add( bankacctfromTag );
82 stmtrqTag.Add( inctranTag );
83
84 return RequestMessage("BANK", "STMT", stmtrqTag);
85}
86
88{
89 /*
90 QString dtstart_string = _dtstart.toString(Qt::ISODate).remove(QRegExp("[^0-9]"));
91
92 return message("CREDITCARD","CCSTMT",Tag("CCSTMTRQ")
93 .subtag(Tag("CCACCTFROM").element("ACCTID",accountnum()))
94 .subtag(Tag("INCTRAN").element("DTSTART",dtstart_string).element("INCLUDE","Y")));
95 }
96 */
97 OfxAggregate ccacctfromTag("CCACCTFROM");
98 ccacctfromTag.Add( "ACCTID", m_account.account_number );
99
100 OfxAggregate inctranTag("INCTRAN");
101 inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
102 inctranTag.Add( "INCLUDE", "Y" );
103
104 OfxAggregate ccstmtrqTag("CCSTMTRQ");
105 ccstmtrqTag.Add( ccacctfromTag );
106 ccstmtrqTag.Add( inctranTag );
107
108 return RequestMessage("CREDITCARD", "CCSTMT", ccstmtrqTag);
109}
110
112{
113 OfxAggregate invacctfromTag("INVACCTFROM");
114
115 invacctfromTag.Add( "BROKERID", m_account.broker_id );
116 invacctfromTag.Add( "ACCTID", m_account.account_number );
117
118 OfxAggregate inctranTag("INCTRAN");
119 inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
120 inctranTag.Add( "INCLUDE", "Y" );
121
122 OfxAggregate incposTag("INCPOS");
123 incposTag.Add( "DTASOF", time_t_to_ofxdatetime( time(NULL) ) );
124 incposTag.Add( "INCLUDE", "Y" );
125
126 OfxAggregate invstmtrqTag("INVSTMTRQ");
127 invstmtrqTag.Add( invacctfromTag );
128 invstmtrqTag.Add( inctranTag );
129 invstmtrqTag.Add( "INCOO", "Y" );
130 invstmtrqTag.Add( incposTag );
131 invstmtrqTag.Add( "INCBAL", "Y" );
132 if (m_account.account_type == OfxAccountData::OFX_401K)
133 {
134 invstmtrqTag.AddXml( "INC401K", "Y" );
135 invstmtrqTag.AddXml( "INC401KBAL", "Y" );
136 }
137
138 return RequestMessage("INVSTMT", "INVSTMT", invstmtrqTag);
139}
140
141char* libofx_request_payment( const OfxFiLogin* login, const OfxAccountData* account, const OfxPayee* payee, const OfxPayment* payment )
142{
143 OfxPaymentRequest strq( *login, *account, *payee, *payment );
144 string request = OfxHeader(login->header_version) + strq.Output();
145
146 unsigned size = request.size();
147 char* result = (char*)malloc(size + 1);
148 request.copy(result, size);
149 result[size] = 0;
150
151 return result;
152}
153
154OfxPaymentRequest::OfxPaymentRequest( const OfxFiLogin& fi, const OfxAccountData& account, const OfxPayee& payee, const OfxPayment& payment ):
155 OfxRequest(fi),
156 m_account(account),
157 m_payee(payee),
158 m_payment(payment)
159{
160 Add( SignOnRequest() );
161
162 OfxAggregate bankacctfromTag("BANKACCTFROM");
163 bankacctfromTag.Add( "BANKID", m_account.bank_id );
164 bankacctfromTag.Add( "ACCTID", m_account.account_number );
165 if ( m_account.account_type == m_account.OFX_CHECKING)
166 bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
167 else if ( m_account.account_type == m_account.OFX_SAVINGS )
168 bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
169 else if ( m_account.account_type == m_account.OFX_MONEYMRKT )
170 bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
171 else if ( m_account.account_type == m_account.OFX_CREDITLINE )
172 bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
173 else if ( m_account.account_type == m_account.OFX_CMA )
174 bankacctfromTag.Add( "ACCTTYPE", "CMA" );
175
176 OfxAggregate payeeTag("PAYEE");
177 payeeTag.Add( "NAME", m_payee.name );
178 payeeTag.Add( "ADDR1", m_payee.address1 );
179 payeeTag.Add( "CITY", m_payee.city );
180 payeeTag.Add( "STATE", m_payee.state );
181 payeeTag.Add( "POSTALCODE", m_payee.postalcode );
182 payeeTag.Add( "PHONE", m_payee.phone );
183
184 OfxAggregate pmtinfoTag("PMTINFO");
185 pmtinfoTag.Add( bankacctfromTag );
186 pmtinfoTag.Add( "TRNAMT", m_payment.amount );
187 pmtinfoTag.Add( payeeTag );
188 pmtinfoTag.Add( "PAYACCT", m_payment.account );
189 pmtinfoTag.Add( "DTDUE", m_payment.datedue );
190 pmtinfoTag.Add( "MEMO", m_payment.memo );
191
192 OfxAggregate pmtrqTag("PMTRQ");
193 pmtrqTag.Add( pmtinfoTag );
194
195 Add( RequestMessage("BILLPAY", "PMT", pmtrqTag) );
196}
197
198char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid )
199{
200#if 0
201 OfxAggregate pmtinqrqTag( "PMTINQRQ" );
202 pmtinqrqTag.Add( "SRVRTID", transactionid );
203
204 OfxRequest ofx(*login);
205 ofx.Add( ofx.SignOnRequest() );
206 ofx.Add( ofx.RequestMessage("BILLPAY", "PMTINQ", pmtinqrqTag) );
207
208 string request = OfxHeader() + ofx.Output();
209
210 unsigned size = request.size();
211 char* result = (char*)malloc(size + 1);
212 request.copy(result, size);
213 result[size] = 0;
214#else
215 OfxAggregate payeesyncrq( "PAYEESYNCRQ" );
216 payeesyncrq.Add( "TOKEN", "0" );
217 payeesyncrq.Add( "TOKENONLY", "N" );
218 payeesyncrq.Add( "REFRESH", "Y" );
219 payeesyncrq.Add( "REJECTIFMISSING", "N" );
220
221 OfxAggregate message( "BILLPAYMSGSRQV1" );
222 message.Add( payeesyncrq );
223
224 OfxRequest ofx(*login);
225 ofx.Add( ofx.SignOnRequest() );
226 ofx.Add( message );
227
228 string request = OfxHeader(login->header_version) + ofx.Output();
229
230 unsigned size = request.size();
231 char* result = (char*)malloc(size + 1);
232 request.copy(result, size);
233 result[size] = 0;
234
235#endif
236 return result;
237}
238
239// vim:cin:si:ai:et:ts=2:sw=2:
240
A single aggregate as described in the OFX 1.02 specification.
void Add(const string &tag, const string &data)
void AddXml(const string &tag, const string &data)
OfxPaymentRequest(const OfxFiLogin &fi, const OfxAccountData &account, const OfxPayee &payee, const OfxPayment &payment)
A generic request.
OfxAggregate RequestMessage(const string &msgtype, const string &trntype, const OfxAggregate &aggregate) const
OfxAggregate SignOnRequest(void) const
A statement request.
OfxStatementRequest(const OfxFiLogin &fi, const OfxAccountData &account, time_t from)
OfxAggregate CreditCardStatementRequest(void) const
OfxAggregate InvestmentStatementRequest(void) const
OfxAggregate BankStatementRequest(void) const
Main header file containing the LibOfx API.
char * libofx_request_statement(const struct OfxFiLogin *fi, const struct OfxAccountData *account, time_t date_from)
Creates an OFX statement request in string form.
Declaration of libofx_request_statement to create an OFX file containing a request for a statement.
Various simple functions for type conversion & al.
An abstraction of an account.
Definition libofx.h:277
char bank_id[OFX_BANKID_LENGTH]
Definition libofx.h:324
char account_number[OFX_ACCTID_LENGTH]
Definition libofx.h:320
Information sufficient to log into an financial institution.
Definition libofx.h:1373