LibOFX

fx-0.9.14/lib/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"
28 #include "ofx_request_statement.hh"
29
30 using namespace std;
31
32 char* 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
45 OfxStatementRequest::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 )
53 Add(CreditCardStatementRequest());
54 else if ( account.account_type == account.OFX_INVESTMENT )
55 Add(InvestmentStatementRequest());
56 else
57 Add(BankStatementRequest());
58 }
59
60 OfxAggregate OfxStatementRequest::BankStatementRequest(void) const
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
87 OfxAggregate OfxStatementRequest::CreditCardStatementRequest(void) const
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
111 OfxAggregate OfxStatementRequest::InvestmentStatementRequest(void) const
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
133 return RequestMessage("INVSTMT", "INVSTMT", invstmtrqTag);
134 }
135
136 char* libofx_request_payment( const OfxFiLogin* login, const OfxAccountData* account, const OfxPayee* payee, const OfxPayment* payment )
137 {
138 OfxPaymentRequest strq( *login, *account, *payee, *payment );
139 string request = OfxHeader(login->header_version) + strq.Output();
140
141 unsigned size = request.size();
142 char* result = (char*)malloc(size + 1);
143 request.copy(result, size);
144 result[size] = 0;
145
146 return result;
147 }
148
149 OfxPaymentRequest::OfxPaymentRequest( const OfxFiLogin& fi, const OfxAccountData& account, const OfxPayee& payee, const OfxPayment& payment ):
150 OfxRequest(fi),
151 m_account(account),
152 m_payee(payee),
153 m_payment(payment)
154 {
155 Add( SignOnRequest() );
156
157 OfxAggregate bankacctfromTag("BANKACCTFROM");
158 bankacctfromTag.Add( "BANKID", m_account.bank_id );
159 bankacctfromTag.Add( "ACCTID", m_account.account_number );
160 if ( m_account.account_type == m_account.OFX_CHECKING)
161 bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
162 else if ( m_account.account_type == m_account.OFX_SAVINGS )
163 bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
164 else if ( m_account.account_type == m_account.OFX_MONEYMRKT )
165 bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
166 else if ( m_account.account_type == m_account.OFX_CREDITLINE )
167 bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
168 else if ( m_account.account_type == m_account.OFX_CMA )
169 bankacctfromTag.Add( "ACCTTYPE", "CMA" );
170
171 OfxAggregate payeeTag("PAYEE");
172 payeeTag.Add( "NAME", m_payee.name );
173 payeeTag.Add( "ADDR1", m_payee.address1 );
174 payeeTag.Add( "CITY", m_payee.city );
175 payeeTag.Add( "STATE", m_payee.state );
176 payeeTag.Add( "POSTALCODE", m_payee.postalcode );
177 payeeTag.Add( "PHONE", m_payee.phone );
178
179 OfxAggregate pmtinfoTag("PMTINFO");
180 pmtinfoTag.Add( bankacctfromTag );
181 pmtinfoTag.Add( "TRNAMT", m_payment.amount );
182 pmtinfoTag.Add( payeeTag );
183 pmtinfoTag.Add( "PAYACCT", m_payment.account );
184 pmtinfoTag.Add( "DTDUE", m_payment.datedue );
185 pmtinfoTag.Add( "MEMO", m_payment.memo );
186
187 OfxAggregate pmtrqTag("PMTRQ");
188 pmtrqTag.Add( pmtinfoTag );
189
190 Add( RequestMessage("BILLPAY", "PMT", pmtrqTag) );
191 }
192
193 char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid )
194 {
195 #if 0
196 OfxAggregate pmtinqrqTag( "PMTINQRQ" );
197 pmtinqrqTag.Add( "SRVRTID", transactionid );
198
199 OfxRequest ofx(*login);
200 ofx.Add( ofx.SignOnRequest() );
201 ofx.Add( ofx.RequestMessage("BILLPAY", "PMTINQ", pmtinqrqTag) );
202
203 string request = OfxHeader() + ofx.Output();
204
205 unsigned size = request.size();
206 char* result = (char*)malloc(size + 1);
207 request.copy(result, size);
208 result[size] = 0;
209 #else
210 OfxAggregate payeesyncrq( "PAYEESYNCRQ" );
211 payeesyncrq.Add( "TOKEN", "0" );
212 payeesyncrq.Add( "TOKENONLY", "N" );
213 payeesyncrq.Add( "REFRESH", "Y" );
214 payeesyncrq.Add( "REJECTIFMISSING", "N" );
215
216 OfxAggregate message( "BILLPAYMSGSRQV1" );
217 message.Add( payeesyncrq );
218
219 OfxRequest ofx(*login);
220 ofx.Add( ofx.SignOnRequest() );
221 ofx.Add( message );
222
223 string request = OfxHeader(login->header_version) + ofx.Output();
224
225 unsigned size = request.size();
226 char* result = (char*)malloc(size + 1);
227 request.copy(result, size);
228 result[size] = 0;
229
230 #endif
231 return result;
232 }
233
234 // vim:cin:si:ai:et:ts=2:sw=2:
235
OfxPaymentRequest
Definition: ofx_request_statement.hh:84
OfxAccountData
An abstraction of an account.
Definition: inc/libofx.h:271
OfxPayee
Definition: inc/libofx.h:832
ofx_utilities.hh
Various simple functions for type conversion & al.
OfxPaymentRequest::OfxPaymentRequest
OfxPaymentRequest(const OfxFiLogin &fi, const OfxAccountData &account, const OfxPayee &payee, const OfxPayment &payment)
Definition: ofx_request_statement.cpp:149
libofx_request_statement
char * libofx_request_statement(const struct OfxFiLogin *fi, const struct OfxAccountData *account, time_t date_from)
Creates an OFX statement request in string form.
OfxAccountData::OFX_SAVINGS
Definition: inc/libofx.h:300
OfxAccountData::OFX_CREDITCARD
Definition: inc/libofx.h:304
std
OfxStatementRequest::OfxStatementRequest
OfxStatementRequest(const OfxFiLogin &fi, const OfxAccountData &account, time_t from)
Definition: ofx_request_statement.cpp:45
OfxPayment
Definition: inc/libofx.h:824
ofx_request_statement.hh
Declaration of libofx_request_statement to create an OFX file containing a request for a statement...
OfxStatementRequest::InvestmentStatementRequest
OfxAggregate InvestmentStatementRequest(void) const
Definition: ofx_request_statement.cpp:111
OfxRequest
A generic request.
Definition: ofx_request.hh:36
OfxAggregate
A single aggregate as described in the OFX 1.02 specification.
Definition: ofx_aggregate.hh:42
OfxAccountData::OFX_MONEYMRKT
Definition: inc/libofx.h:301
OfxRequest::RequestMessage
OfxAggregate RequestMessage(const string &msgtype, const string &trntype, const OfxAggregate &aggregate) const
Definition: ofx_request.cpp:115
OfxAccountData::bank_id
char bank_id[OFX_BANKID_LENGTH]
Definition: inc/libofx.h:318
OfxAggregate::Add
void Add(const string &tag, const string &data)
Definition: ofx_aggregate.hh:59
OfxStatementRequest
A statement request.
Definition: ofx_request_statement.hh:37
OfxStatementRequest::BankStatementRequest
OfxAggregate BankStatementRequest(void) const
Definition: ofx_request_statement.cpp:60
OfxStatementRequest::CreditCardStatementRequest
OfxAggregate CreditCardStatementRequest(void) const
Definition: ofx_request_statement.cpp:87
OfxAccountData::OFX_CMA
Definition: inc/libofx.h:303
OfxAccountData::account_number
char account_number[OFX_ACCTID_LENGTH]
Definition: inc/libofx.h:314
OfxRequest::SignOnRequest
OfxAggregate SignOnRequest(void) const
Definition: ofx_request.cpp:84
OfxAccountData::OFX_CREDITLINE
Definition: inc/libofx.h:302
OfxAccountData::OFX_INVESTMENT
Definition: inc/libofx.h:305
OfxAccountData::OFX_CHECKING
Definition: inc/libofx.h:299
OfxFiLogin
Information sufficient to log into an financial institution.
Definition: inc/libofx.h:806