00001
00002
00003
00004
00005
00006
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023
00024 #include <string>
00025 #include "libofx.h"
00026 #include "ofx_utilities.hh"
00027 #include "ofx_request_statement.hh"
00028
00029 using namespace std;
00030
00031 char* libofx_request_statement( const OfxFiLogin* login, const OfxAccountInfo* account, time_t date_from )
00032 {
00033 OfxStatementRequest strq( *login, *account, date_from );
00034 string request = OfxHeader() + strq.Output();
00035
00036 unsigned size = request.size();
00037 char* result = (char*)malloc(size + 1);
00038 request.copy(result,size);
00039 result[size] = 0;
00040
00041 return result;
00042 }
00043
00044 OfxStatementRequest::OfxStatementRequest( const OfxFiLogin& fi, const OfxAccountInfo& account, time_t from ):
00045 OfxRequest(fi),
00046 m_account(account),
00047 m_date_from(from)
00048 {
00049 Add( SignOnRequest() );
00050
00051 if ( account.type == OFX_CREDITCARD_ACCOUNT )
00052 Add(CreditCardStatementRequest());
00053 else if ( account.type == OFX_INVEST_ACCOUNT )
00054 Add(InvestmentStatementRequest());
00055 else
00056 Add(BankStatementRequest());
00057 }
00058
00059 OfxAggregate OfxStatementRequest::BankStatementRequest(void) const
00060 {
00061 OfxAggregate bankacctfromTag("BANKACCTFROM");
00062 bankacctfromTag.Add( "BANKID", m_account.bankid );
00063 bankacctfromTag.Add( "ACCTID", m_account.accountid );
00064 bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
00065
00066
00067 OfxAggregate inctranTag("INCTRAN");
00068 inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
00069 inctranTag.Add( "INCLUDE","Y" );
00070
00071 OfxAggregate stmtrqTag("STMTRQ");
00072 stmtrqTag.Add( bankacctfromTag );
00073 stmtrqTag.Add( inctranTag );
00074
00075 return RequestMessage("BANK","STMT", stmtrqTag);
00076 }
00077
00078 OfxAggregate OfxStatementRequest::CreditCardStatementRequest(void) const
00079 {
00080
00081
00082
00083
00084
00085
00086
00087 OfxAggregate ccacctfromTag("CCACCTFROM");
00088 ccacctfromTag.Add( "ACCTID", m_account.accountid );
00089
00090 OfxAggregate inctranTag("INCTRAN");
00091 inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
00092 inctranTag.Add( "INCLUDE","Y" );
00093
00094 OfxAggregate ccstmtrqTag("CCSTMTRQ");
00095 ccstmtrqTag.Add( ccacctfromTag );
00096 ccstmtrqTag.Add( inctranTag );
00097
00098 return RequestMessage("CREDITCARD","CCSTMT", ccstmtrqTag);
00099 }
00100
00101 OfxAggregate OfxStatementRequest::InvestmentStatementRequest(void) const
00102 {
00103 OfxAggregate invacctfromTag("INVACCTFROM");
00104
00105 invacctfromTag.Add( "BROKERID", m_account.brokerid );
00106 invacctfromTag.Add( "ACCTID", m_account.accountid );
00107
00108 OfxAggregate inctranTag("INCTRAN");
00109 inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
00110 inctranTag.Add( "INCLUDE","Y" );
00111
00112 OfxAggregate incposTag("INCPOS");
00113 incposTag.Add( "DTASOF", time_t_to_ofxdatetime( time(NULL) ) );
00114 incposTag.Add( "INCLUDE","Y" );
00115
00116 OfxAggregate invstmtrqTag("INVSTMTRQ");
00117 invstmtrqTag.Add( invacctfromTag );
00118 invstmtrqTag.Add( inctranTag );
00119 invstmtrqTag.Add( "INCOO","Y" );
00120 invstmtrqTag.Add( incposTag );
00121 invstmtrqTag.Add( "INCBAL","Y" );
00122
00123 return RequestMessage("INVSTMT","INVSTMT", invstmtrqTag);
00124 }
00125
00126 char* libofx_request_payment( const OfxFiLogin* login, const OfxAccountInfo* account, const OfxPayee* payee, const OfxPayment* payment )
00127 {
00128 OfxPaymentRequest strq( *login, *account, *payee, *payment );
00129 string request = OfxHeader() + strq.Output();
00130
00131 unsigned size = request.size();
00132 char* result = (char*)malloc(size + 1);
00133 request.copy(result,size);
00134 result[size] = 0;
00135
00136 return result;
00137 }
00138
00139 OfxPaymentRequest::OfxPaymentRequest( const OfxFiLogin& fi, const OfxAccountInfo& account, const OfxPayee& payee, const OfxPayment& payment ):
00140 OfxRequest(fi),
00141 m_account(account),
00142 m_payee(payee),
00143 m_payment(payment)
00144 {
00145 Add( SignOnRequest() );
00146
00147 OfxAggregate bankacctfromTag("BANKACCTFROM");
00148 bankacctfromTag.Add( "BANKID", m_account.bankid );
00149 bankacctfromTag.Add( "ACCTID", m_account.accountid );
00150 bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
00151
00152
00153 OfxAggregate payeeTag("PAYEE");
00154 payeeTag.Add( "NAME", m_payee.name );
00155 payeeTag.Add( "ADDR1", m_payee.address1 );
00156 payeeTag.Add( "CITY", m_payee.city );
00157 payeeTag.Add( "STATE", m_payee.state );
00158 payeeTag.Add( "POSTALCODE", m_payee.postalcode );
00159 payeeTag.Add( "PHONE", m_payee.phone );
00160
00161 OfxAggregate pmtinfoTag("PMTINFO");
00162 pmtinfoTag.Add( bankacctfromTag );
00163 pmtinfoTag.Add( "TRNAMT", m_payment.amount );
00164 pmtinfoTag.Add( payeeTag );
00165 pmtinfoTag.Add( "PAYACCT", m_payment.account );
00166 pmtinfoTag.Add( "DTDUE", m_payment.datedue );
00167 pmtinfoTag.Add( "MEMO", m_payment.memo );
00168
00169 OfxAggregate pmtrqTag("PMTRQ");
00170 pmtrqTag.Add( pmtinfoTag );
00171
00172 Add( RequestMessage("BILLPAY","PMT", pmtrqTag) );
00173 }
00174
00175 CFCT char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid )
00176 {
00177 #if 0
00178 OfxAggregate pmtinqrqTag( "PMTINQRQ" );
00179 pmtinqrqTag.Add( "SRVRTID", transactionid );
00180
00181 OfxRequest ofx(*login);
00182 ofx.Add( ofx.SignOnRequest() );
00183 ofx.Add( ofx.RequestMessage("BILLPAY","PMTINQ", pmtinqrqTag) );
00184
00185 string request = OfxHeader() + ofx.Output();
00186
00187 unsigned size = request.size();
00188 char* result = (char*)malloc(size + 1);
00189 request.copy(result,size);
00190 result[size] = 0;
00191 #else
00192 OfxAggregate payeesyncrq( "PAYEESYNCRQ" );
00193 payeesyncrq.Add( "TOKEN", "0" );
00194 payeesyncrq.Add( "TOKENONLY", "N" );
00195 payeesyncrq.Add( "REFRESH", "Y" );
00196 payeesyncrq.Add( "REJECTIFMISSING", "N" );
00197
00198 OfxAggregate message( "BILLPAYMSGSRQV1" );
00199 message.Add( payeesyncrq );
00200
00201 OfxRequest ofx(*login);
00202 ofx.Add( ofx.SignOnRequest() );
00203 ofx.Add( message );
00204
00205 string request = OfxHeader() + ofx.Output();
00206
00207 unsigned size = request.size();
00208 char* result = (char*)malloc(size + 1);
00209 request.copy(result,size);
00210 result[size] = 0;
00211
00212 #endif
00213 return result;
00214 }
00215
00216
00217