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 
31 char* libofx_request_statement( const OfxFiLogin* login, const OfxAccountData* account, time_t date_from )
32 {
33  OfxStatementRequest strq( *login, *account, date_from );
34  std::string request = OfxHeader(login->header_version) + strq.Output();
35 
36  unsigned size = request.size();
37  char* result = (char*)malloc(size + 1);
38  request.copy(result, size);
39  result[size] = 0;
40 
41  return result;
42 }
43 
44 OfxStatementRequest::OfxStatementRequest( const OfxFiLogin& fi, const OfxAccountData& account, time_t from ):
45  OfxRequest(fi),
46  m_account(account),
47  m_date_from(from)
48 {
49  Add( SignOnRequest() );
50 
51  if ( account.account_type == account.OFX_CREDITCARD )
53  else if ( account.account_type == account.OFX_INVESTMENT || account.account_type == account.OFX_401K)
55  else
57 }
58 
60 {
61  OfxAggregate bankacctfromTag("BANKACCTFROM");
62  bankacctfromTag.Add( "BANKID", m_account.bank_id );
63  bankacctfromTag.Add( "ACCTID", m_account.account_number );
64  if ( m_account.account_type == m_account.OFX_CHECKING )
65  bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
66  else if ( m_account.account_type == m_account.OFX_SAVINGS )
67  bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
68  else if ( m_account.account_type == m_account.OFX_MONEYMRKT )
69  bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
70  else if ( m_account.account_type == m_account.OFX_CREDITLINE )
71  bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
72  else if ( m_account.account_type == m_account.OFX_CMA )
73  bankacctfromTag.Add( "ACCTTYPE", "CMA" );
74 
75  OfxAggregate inctranTag("INCTRAN");
76  inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
77  inctranTag.Add( "INCLUDE", "Y" );
78 
79  OfxAggregate stmtrqTag("STMTRQ");
80  stmtrqTag.Add( bankacctfromTag );
81  stmtrqTag.Add( inctranTag );
82 
83  return RequestMessage("BANK", "STMT", stmtrqTag);
84 }
85 
87 {
88  /*
89  QString dtstart_string = _dtstart.toString(Qt::ISODate).remove(QRegExp("[^0-9]"));
90 
91  return message("CREDITCARD","CCSTMT",Tag("CCSTMTRQ")
92  .subtag(Tag("CCACCTFROM").element("ACCTID",accountnum()))
93  .subtag(Tag("INCTRAN").element("DTSTART",dtstart_string).element("INCLUDE","Y")));
94  }
95  */
96  OfxAggregate ccacctfromTag("CCACCTFROM");
97  ccacctfromTag.Add( "ACCTID", m_account.account_number );
98 
99  OfxAggregate inctranTag("INCTRAN");
100  inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
101  inctranTag.Add( "INCLUDE", "Y" );
102 
103  OfxAggregate ccstmtrqTag("CCSTMTRQ");
104  ccstmtrqTag.Add( ccacctfromTag );
105  ccstmtrqTag.Add( inctranTag );
106 
107  return RequestMessage("CREDITCARD", "CCSTMT", ccstmtrqTag);
108 }
109 
111 {
112  OfxAggregate invacctfromTag("INVACCTFROM");
113 
114  invacctfromTag.Add( "BROKERID", m_account.broker_id );
115  invacctfromTag.Add( "ACCTID", m_account.account_number );
116 
117  OfxAggregate inctranTag("INCTRAN");
118  inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
119  inctranTag.Add( "INCLUDE", "Y" );
120 
121  OfxAggregate incposTag("INCPOS");
122  incposTag.Add( "DTASOF", time_t_to_ofxdatetime( time(NULL) ) );
123  incposTag.Add( "INCLUDE", "Y" );
124 
125  OfxAggregate invstmtrqTag("INVSTMTRQ");
126  invstmtrqTag.Add( invacctfromTag );
127  invstmtrqTag.Add( inctranTag );
128  invstmtrqTag.Add( "INCOO", "Y" );
129  invstmtrqTag.Add( incposTag );
130  invstmtrqTag.Add( "INCBAL", "Y" );
131  if (m_account.account_type == OfxAccountData::OFX_401K)
132  {
133  invstmtrqTag.AddXml( "INC401K", "Y" );
134  invstmtrqTag.AddXml( "INC401KBAL", "Y" );
135  }
136 
137  return RequestMessage("INVSTMT", "INVSTMT", invstmtrqTag);
138 }
139 
140 char* libofx_request_payment( const OfxFiLogin* login, const OfxAccountData* account, const OfxPayee* payee, const OfxPayment* payment )
141 {
142  OfxPaymentRequest strq( *login, *account, *payee, *payment );
143  std::string request = OfxHeader(login->header_version) + strq.Output();
144 
145  unsigned size = request.size();
146  char* result = (char*)malloc(size + 1);
147  request.copy(result, size);
148  result[size] = 0;
149 
150  return result;
151 }
152 
153 OfxPaymentRequest::OfxPaymentRequest( const OfxFiLogin& fi, const OfxAccountData& account, const OfxPayee& payee, const OfxPayment& payment ):
154  OfxRequest(fi),
155  m_account(account),
156  m_payee(payee),
157  m_payment(payment)
158 {
159  Add( SignOnRequest() );
160 
161  OfxAggregate bankacctfromTag("BANKACCTFROM");
162  bankacctfromTag.Add( "BANKID", m_account.bank_id );
163  bankacctfromTag.Add( "ACCTID", m_account.account_number );
164  if ( m_account.account_type == m_account.OFX_CHECKING)
165  bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
166  else if ( m_account.account_type == m_account.OFX_SAVINGS )
167  bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
168  else if ( m_account.account_type == m_account.OFX_MONEYMRKT )
169  bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
170  else if ( m_account.account_type == m_account.OFX_CREDITLINE )
171  bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
172  else if ( m_account.account_type == m_account.OFX_CMA )
173  bankacctfromTag.Add( "ACCTTYPE", "CMA" );
174 
175  OfxAggregate payeeTag("PAYEE");
176  payeeTag.Add( "NAME", m_payee.name );
177  payeeTag.Add( "ADDR1", m_payee.address1 );
178  payeeTag.Add( "CITY", m_payee.city );
179  payeeTag.Add( "STATE", m_payee.state );
180  payeeTag.Add( "POSTALCODE", m_payee.postalcode );
181  payeeTag.Add( "PHONE", m_payee.phone );
182 
183  OfxAggregate pmtinfoTag("PMTINFO");
184  pmtinfoTag.Add( bankacctfromTag );
185  pmtinfoTag.Add( "TRNAMT", m_payment.amount );
186  pmtinfoTag.Add( payeeTag );
187  pmtinfoTag.Add( "PAYACCT", m_payment.account );
188  pmtinfoTag.Add( "DTDUE", m_payment.datedue );
189  pmtinfoTag.Add( "MEMO", m_payment.memo );
190 
191  OfxAggregate pmtrqTag("PMTRQ");
192  pmtrqTag.Add( pmtinfoTag );
193 
194  Add( RequestMessage("BILLPAY", "PMT", pmtrqTag) );
195 }
196 
197 char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid )
198 {
199 #if 0
200  OfxAggregate pmtinqrqTag( "PMTINQRQ" );
201  pmtinqrqTag.Add( "SRVRTID", transactionid );
202 
203  OfxRequest ofx(*login);
204  ofx.Add( ofx.SignOnRequest() );
205  ofx.Add( ofx.RequestMessage("BILLPAY", "PMTINQ", pmtinqrqTag) );
206 
207  std::string request = OfxHeader() + ofx.Output();
208 
209  unsigned size = request.size();
210  char* result = (char*)malloc(size + 1);
211  request.copy(result, size);
212  result[size] = 0;
213 #else
214  OfxAggregate payeesyncrq( "PAYEESYNCRQ" );
215  payeesyncrq.Add( "TOKEN", "0" );
216  payeesyncrq.Add( "TOKENONLY", "N" );
217  payeesyncrq.Add( "REFRESH", "Y" );
218  payeesyncrq.Add( "REJECTIFMISSING", "N" );
219 
220  OfxAggregate message( "BILLPAYMSGSRQV1" );
221  message.Add( payeesyncrq );
222 
223  OfxRequest ofx(*login);
224  ofx.Add( ofx.SignOnRequest() );
225  ofx.Add( message );
226 
227  std::string request = OfxHeader(login->header_version) + ofx.Output();
228 
229  unsigned size = request.size();
230  char* result = (char*)malloc(size + 1);
231  request.copy(result, size);
232  result[size] = 0;
233 
234 #endif
235  return result;
236 }
237 
238 // vim:cin:si:ai:et:ts=2:sw=2:
239 
OfxStatementRequest::OfxStatementRequest
OfxStatementRequest(const OfxFiLogin &fi, const OfxAccountData &account, time_t from)
Definition: ofx_request_statement.cpp:44
OfxAccountData::OFX_CREDITCARD
@ OFX_CREDITCARD
Definition: inc/libofx.h:320
OfxAggregate::Add
void Add(const std::string &tag, const std::string &data)
Definition: ofx_aggregate.hh:64
OfxStatementRequest::BankStatementRequest
OfxAggregate BankStatementRequest(void) const
Definition: ofx_request_statement.cpp:59
OfxAccountData
An abstraction of an account.
Definition: inc/libofx.h:287
OfxPayee
Definition: inc/libofx.h:1409
OfxStatementRequest::InvestmentStatementRequest
OfxAggregate InvestmentStatementRequest(void) const
Definition: ofx_request_statement.cpp:110
OfxAccountData::OFX_INVESTMENT
@ OFX_INVESTMENT
Definition: inc/libofx.h:321
OfxPayment
Definition: inc/libofx.h:1401
OfxAccountData::OFX_SAVINGS
@ OFX_SAVINGS
Definition: inc/libofx.h:316
OfxRequest::RequestMessage
OfxAggregate RequestMessage(const std::string &msgtype, const std::string &trntype, const OfxAggregate &aggregate) const
Definition: ofx_request.cpp:113
OfxRequest::SignOnRequest
OfxAggregate SignOnRequest(void) const
Definition: ofx_request.cpp:82
OfxFiLogin
Information sufficient to log into an financial institution.
Definition: inc/libofx.h:1383
OfxAggregate
A single aggregate as described in the OFX 1.02 specification.
Definition: ofx_aggregate.hh:40
ofx_utilities.hh
Various simple functions for type conversion & al.
OfxAccountData::account_number
char account_number[OFX_ACCTID_LENGTH]
Definition: inc/libofx.h:331
OfxRequest
A generic request.
Definition: ofx_request.hh:34
OfxAccountData::OFX_401K
@ OFX_401K
Definition: inc/libofx.h:322
OfxAggregate::AddXml
void AddXml(const std::string &tag, const std::string &data)
Definition: ofx_aggregate.hh:75
OfxAccountData::bank_id
char bank_id[OFX_BANKID_LENGTH]
Definition: inc/libofx.h:335
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.
OfxStatementRequest::CreditCardStatementRequest
OfxAggregate CreditCardStatementRequest(void) const
Definition: ofx_request_statement.cpp:86
OfxAccountData::OFX_MONEYMRKT
@ OFX_MONEYMRKT
Definition: inc/libofx.h:317
OfxStatementRequest
A statement request.
Definition: ofx_request_statement.hh:34
ofx_request_statement.hh
Declaration of libofx_request_statement to create an OFX file containing a request for a statement.
OfxPaymentRequest
Definition: ofx_request_statement.hh:81
OfxAccountData::OFX_CHECKING
@ OFX_CHECKING
Definition: inc/libofx.h:315
OfxAccountData::OFX_CREDITLINE
@ OFX_CREDITLINE
Definition: inc/libofx.h:318
OfxAccountData::OFX_CMA
@ OFX_CMA
Definition: inc/libofx.h:319
OfxPaymentRequest::OfxPaymentRequest
OfxPaymentRequest(const OfxFiLogin &fi, const OfxAccountData &account, const OfxPayee &payee, const OfxPayment &payment)
Definition: ofx_request_statement.cpp:153