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"
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 )
54  else if ( account.account_type == account.OFX_INVESTMENT )
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 
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 
An abstraction of an account.
Definition: inc/libofx.h:271
OfxPaymentRequest(const OfxFiLogin &fi, const OfxAccountData &account, const OfxPayee &payee, const OfxPayment &payment)
char * libofx_request_statement(const struct OfxFiLogin *fi, const struct OfxAccountData *account, time_t date_from)
Creates an OFX statement request in string form.
OfxStatementRequest(const OfxFiLogin &fi, const OfxAccountData &account, time_t from)
OfxAggregate InvestmentStatementRequest(void) const
A generic request.
Definition: ofx_request.hh:36
A single aggregate as described in the OFX 1.02 specification.
OfxAggregate RequestMessage(const string &msgtype, const string &trntype, const OfxAggregate &aggregate) const
char bank_id[OFX_BANKID_LENGTH]
Definition: inc/libofx.h:318
Various simple functions for type conversion & al.
void Add(const string &tag, const string &data)
string Output(void) const
A statement request.
OfxAggregate BankStatementRequest(void) const
OfxAggregate CreditCardStatementRequest(void) const
char account_number[OFX_ACCTID_LENGTH]
Definition: inc/libofx.h:314
OfxAggregate SignOnRequest(void) const
Definition: ofx_request.cpp:84
Declaration of libofx_request_statement to create an OFX file containing a request for a statement...
Information sufficient to log into an financial institution.
Definition: inc/libofx.h:806