ofx_request_statement.cpp
Go to the documentation of this file.

    00001 /***************************************************************************
    00002          ofx_request_statement.cpp
    00003                              -------------------
    00004     copyright            : (C) 2005 by Ace Jones
    00005     email                : acejones@users.sourceforge.net
    00006 ***************************************************************************/
    00011 /***************************************************************************
    00012  *                                                                         *
    00013  *   This program is free software; you can redistribute it and/or modify  *
    00014  *   it under the terms of the GNU General Public License as published by  *
    00015  *   the Free Software Foundation; either version 2 of the License, or     *
    00016  *   (at your option) any later version.                                   *
    00017  *                                                                         *
    00018  ***************************************************************************/
    00019
    00020 #ifdef HAVE_CONFIG_H
    00021 #include <config.h>
    00022 #endif
    00023
    00024 #include <cstdlib>
    00025 #include <string>
    00026 #include "libofx.h"
    00027 #include "ofx_utilities.hh"
    00028 #include "ofx_request_statement.hh"
    00029
    00030 using namespace std;
    00031
    00032 char* libofx_request_statement( const OfxFiLogin* login, const OfxAccountData* account, time_t date_from )
    00033 {
    00034   OfxStatementRequest strq( *login, *account, date_from );
    00035   string request = OfxHeader(login->header_version) + strq.Output();
    00036
    00037   unsigned size = request.size();
    00038   char* result = (char*)malloc(size + 1);
    00039   request.copy(result, size);
    00040   result[size] = 0;
    00041
    00042   return result;
    00043 }
    00044
    00045 OfxStatementRequest::OfxStatementRequest( const OfxFiLogin& fi, const OfxAccountData& account, time_t from ):
    00046   OfxRequest(fi),
    00047   m_account(account),
    00048   m_date_from(from)
    00049 {
    00050   Add( SignOnRequest() );
    00051
    00052   if ( account.account_type == account.OFX_CREDITCARD )
    00053     Add(CreditCardStatementRequest());
    00054   else if ( account.account_type == account.OFX_INVESTMENT )
    00055     Add(InvestmentStatementRequest());
    00056   else
    00057     Add(BankStatementRequest());
    00058 }
    00059
    00060 OfxAggregate OfxStatementRequest::BankStatementRequest(void) const
    00061 {
    00062   OfxAggregate bankacctfromTag("BANKACCTFROM");
    00063   bankacctfromTag.Add( "BANKID", m_account.bank_id );
    00064   bankacctfromTag.Add( "ACCTID", m_account.account_number );
    00065   if ( m_account.account_type ==  m_account.OFX_CHECKING )
    00066     bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
    00067   else if  ( m_account.account_type == m_account.OFX_SAVINGS )
    00068     bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
    00069   else if  ( m_account.account_type == m_account.OFX_MONEYMRKT )
    00070     bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
    00071   else if  ( m_account.account_type == m_account.OFX_CREDITLINE )
    00072     bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
    00073   else if  ( m_account.account_type == m_account.OFX_CMA )
    00074     bankacctfromTag.Add( "ACCTTYPE", "CMA" );
    00075
    00076   OfxAggregate inctranTag("INCTRAN");
    00077   inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
    00078   inctranTag.Add( "INCLUDE", "Y" );
    00079
    00080   OfxAggregate stmtrqTag("STMTRQ");
    00081   stmtrqTag.Add( bankacctfromTag );
    00082   stmtrqTag.Add( inctranTag );
    00083
    00084   return RequestMessage("BANK", "STMT", stmtrqTag);
    00085 }
    00086
    00087 OfxAggregate OfxStatementRequest::CreditCardStatementRequest(void) const
    00088 {
    00089   /*
    00090    QString dtstart_string = _dtstart.toString(Qt::ISODate).remove(QRegExp("[^0-9]"));
    00091
    00092    return message("CREDITCARD","CCSTMT",Tag("CCSTMTRQ")
    00093      .subtag(Tag("CCACCTFROM").element("ACCTID",accountnum()))
    00094      .subtag(Tag("INCTRAN").element("DTSTART",dtstart_string).element("INCLUDE","Y")));
    00095   }
    00096   */
    00097   OfxAggregate ccacctfromTag("CCACCTFROM");
    00098   ccacctfromTag.Add( "ACCTID", m_account.account_number );
    00099
    00100   OfxAggregate inctranTag("INCTRAN");
    00101   inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
    00102   inctranTag.Add( "INCLUDE", "Y" );
    00103
    00104   OfxAggregate ccstmtrqTag("CCSTMTRQ");
    00105   ccstmtrqTag.Add( ccacctfromTag );
    00106   ccstmtrqTag.Add( inctranTag );
    00107
    00108   return RequestMessage("CREDITCARD", "CCSTMT", ccstmtrqTag);
    00109 }
    00110
    00111 OfxAggregate OfxStatementRequest::InvestmentStatementRequest(void) const
    00112 {
    00113   OfxAggregate invacctfromTag("INVACCTFROM");
    00114
    00115   invacctfromTag.Add( "BROKERID", m_account.broker_id );
    00116   invacctfromTag.Add( "ACCTID", m_account.account_number );
    00117
    00118   OfxAggregate inctranTag("INCTRAN");
    00119   inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
    00120   inctranTag.Add( "INCLUDE", "Y" );
    00121
    00122   OfxAggregate incposTag("INCPOS");
    00123   incposTag.Add( "DTASOF", time_t_to_ofxdatetime( time(NULL) ) );
    00124   incposTag.Add( "INCLUDE", "Y" );
    00125
    00126   OfxAggregate invstmtrqTag("INVSTMTRQ");
    00127   invstmtrqTag.Add( invacctfromTag );
    00128   invstmtrqTag.Add( inctranTag );
    00129   invstmtrqTag.Add( "INCOO", "Y" );
    00130   invstmtrqTag.Add( incposTag );
    00131   invstmtrqTag.Add( "INCBAL", "Y" );
    00132
    00133   return RequestMessage("INVSTMT", "INVSTMT", invstmtrqTag);
    00134 }
    00135
    00136 char* libofx_request_payment( const OfxFiLogin* login, const OfxAccountData* account, const OfxPayee* payee, const OfxPayment* payment )
    00137 {
    00138   OfxPaymentRequest strq( *login, *account, *payee, *payment );
    00139   string request = OfxHeader(login->header_version) + strq.Output();
    00140
    00141   unsigned size = request.size();
    00142   char* result = (char*)malloc(size + 1);
    00143   request.copy(result, size);
    00144   result[size] = 0;
    00145
    00146   return result;
    00147 }
    00148
    00149 OfxPaymentRequest::OfxPaymentRequest( const OfxFiLogin& fi, const OfxAccountData& account, const OfxPayee& payee, const OfxPayment& payment ):
    00150   OfxRequest(fi),
    00151   m_account(account),
    00152   m_payee(payee),
    00153   m_payment(payment)
    00154 {
    00155   Add( SignOnRequest() );
    00156
    00157   OfxAggregate bankacctfromTag("BANKACCTFROM");
    00158   bankacctfromTag.Add( "BANKID", m_account.bank_id );
    00159   bankacctfromTag.Add( "ACCTID", m_account.account_number );
    00160   if ( m_account.account_type == m_account.OFX_CHECKING)
    00161     bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
    00162   else if  ( m_account.account_type == m_account.OFX_SAVINGS )
    00163     bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
    00164   else if  ( m_account.account_type == m_account.OFX_MONEYMRKT )
    00165     bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
    00166   else if  ( m_account.account_type ==  m_account.OFX_CREDITLINE )
    00167     bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
    00168   else if  ( m_account.account_type == m_account.OFX_CMA )
    00169     bankacctfromTag.Add( "ACCTTYPE", "CMA" );
    00170
    00171   OfxAggregate payeeTag("PAYEE");
    00172   payeeTag.Add( "NAME", m_payee.name );
    00173   payeeTag.Add( "ADDR1", m_payee.address1 );
    00174   payeeTag.Add( "CITY", m_payee.city );
    00175   payeeTag.Add( "STATE", m_payee.state );
    00176   payeeTag.Add( "POSTALCODE", m_payee.postalcode );
    00177   payeeTag.Add( "PHONE", m_payee.phone );
    00178
    00179   OfxAggregate pmtinfoTag("PMTINFO");
    00180   pmtinfoTag.Add( bankacctfromTag );
    00181   pmtinfoTag.Add( "TRNAMT", m_payment.amount );
    00182   pmtinfoTag.Add( payeeTag );
    00183   pmtinfoTag.Add( "PAYACCT", m_payment.account );
    00184   pmtinfoTag.Add( "DTDUE", m_payment.datedue );
    00185   pmtinfoTag.Add( "MEMO", m_payment.memo );
    00186
    00187   OfxAggregate pmtrqTag("PMTRQ");
    00188   pmtrqTag.Add( pmtinfoTag );
    00189
    00190   Add( RequestMessage("BILLPAY", "PMT", pmtrqTag) );
    00191 }
    00192
    00193 char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid )
    00194 {
    00195 #if 0
    00196   OfxAggregate pmtinqrqTag( "PMTINQRQ" );
    00197   pmtinqrqTag.Add( "SRVRTID", transactionid );
    00198
    00199   OfxRequest ofx(*login);
    00200   ofx.Add( ofx.SignOnRequest() );
    00201   ofx.Add( ofx.RequestMessage("BILLPAY", "PMTINQ", pmtinqrqTag) );
    00202
    00203   string request = OfxHeader() + ofx.Output();
    00204
    00205   unsigned size = request.size();
    00206   char* result = (char*)malloc(size + 1);
    00207   request.copy(result, size);
    00208   result[size] = 0;
    00209 #else
    00210   OfxAggregate payeesyncrq( "PAYEESYNCRQ" );
    00211   payeesyncrq.Add( "TOKEN", "0" );
    00212   payeesyncrq.Add( "TOKENONLY", "N" );
    00213   payeesyncrq.Add( "REFRESH", "Y" );
    00214   payeesyncrq.Add( "REJECTIFMISSING", "N" );
    00215
    00216   OfxAggregate message( "BILLPAYMSGSRQV1" );
    00217   message.Add( payeesyncrq );
    00218
    00219   OfxRequest ofx(*login);
    00220   ofx.Add( ofx.SignOnRequest() );
    00221   ofx.Add( message );
    00222
    00223   string request = OfxHeader(login->header_version) + ofx.Output();
    00224
    00225   unsigned size = request.size();
    00226   char* result = (char*)malloc(size + 1);
    00227   request.copy(result, size);
    00228   result[size] = 0;
    00229
    00230 #endif
    00231   return result;
    00232 }
    00233
    00234 // vim:cin:si:ai:et:ts=2:sw=2:
    00235