build/libofx-0.10.0/lib/ofx_request_statement.cpp
Go to the documentation of this file.
/***************************************************************************
ofx_request_statement.cpp
-------------------
copyright : (C) 2005 by Ace Jones
email : acejones@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <cstdlib>
#include <string>
#include "libofx.h"
#include "ofx_utilities.hh"
#include "ofx_request_statement.hh"
using namespace std;
char* libofx_request_statement( const OfxFiLogin* login, const OfxAccountData* account, time_t date_from )
{
OfxStatementRequest strq( *login, *account, date_from );
string request = OfxHeader(login->header_version) + strq.Output();
unsigned size = request.size();
char* result = (char*)malloc(size + 1);
request.copy(result, size);
result[size] = 0;
return result;
}
OfxStatementRequest::OfxStatementRequest( const OfxFiLogin& fi, const OfxAccountData& account, time_t from ):
OfxRequest(fi),
m_account(account),
m_date_from(from)
{
Add( SignOnRequest() );
if ( account.account_type == account.OFX_CREDITCARD )
Add(CreditCardStatementRequest());
else if ( account.account_type == account.OFX_INVESTMENT || account.account_type == account.OFX_401K)
Add(InvestmentStatementRequest());
else
Add(BankStatementRequest());
}
OfxAggregate OfxStatementRequest::BankStatementRequest(void) const
{
OfxAggregate bankacctfromTag("BANKACCTFROM");
bankacctfromTag.Add( "BANKID", m_account.bank_id );
bankacctfromTag.Add( "ACCTID", m_account.account_number );
if ( m_account.account_type == m_account.OFX_CHECKING )
bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
else if ( m_account.account_type == m_account.OFX_SAVINGS )
bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
else if ( m_account.account_type == m_account.OFX_MONEYMRKT )
bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
else if ( m_account.account_type == m_account.OFX_CREDITLINE )
bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
else if ( m_account.account_type == m_account.OFX_CMA )
bankacctfromTag.Add( "ACCTTYPE", "CMA" );
OfxAggregate inctranTag("INCTRAN");
inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
inctranTag.Add( "INCLUDE", "Y" );
OfxAggregate stmtrqTag("STMTRQ");
stmtrqTag.Add( bankacctfromTag );
stmtrqTag.Add( inctranTag );
return RequestMessage("BANK", "STMT", stmtrqTag);
}
OfxAggregate OfxStatementRequest::CreditCardStatementRequest(void) const
{
/*
QString dtstart_string = _dtstart.toString(Qt::ISODate).remove(QRegExp("[^0-9]"));
return message("CREDITCARD","CCSTMT",Tag("CCSTMTRQ")
.subtag(Tag("CCACCTFROM").element("ACCTID",accountnum()))
.subtag(Tag("INCTRAN").element("DTSTART",dtstart_string).element("INCLUDE","Y")));
}
*/
OfxAggregate ccacctfromTag("CCACCTFROM");
ccacctfromTag.Add( "ACCTID", m_account.account_number );
OfxAggregate inctranTag("INCTRAN");
inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
inctranTag.Add( "INCLUDE", "Y" );
OfxAggregate ccstmtrqTag("CCSTMTRQ");
ccstmtrqTag.Add( ccacctfromTag );
ccstmtrqTag.Add( inctranTag );
return RequestMessage("CREDITCARD", "CCSTMT", ccstmtrqTag);
}
OfxAggregate OfxStatementRequest::InvestmentStatementRequest(void) const
{
OfxAggregate invacctfromTag("INVACCTFROM");
invacctfromTag.Add( "BROKERID", m_account.broker_id );
invacctfromTag.Add( "ACCTID", m_account.account_number );
OfxAggregate inctranTag("INCTRAN");
inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
inctranTag.Add( "INCLUDE", "Y" );
OfxAggregate incposTag("INCPOS");
incposTag.Add( "DTASOF", time_t_to_ofxdatetime( time(NULL) ) );
incposTag.Add( "INCLUDE", "Y" );
OfxAggregate invstmtrqTag("INVSTMTRQ");
invstmtrqTag.Add( invacctfromTag );
invstmtrqTag.Add( inctranTag );
invstmtrqTag.Add( "INCOO", "Y" );
invstmtrqTag.Add( incposTag );
invstmtrqTag.Add( "INCBAL", "Y" );
if (m_account.account_type == OfxAccountData::OFX_401K)
{
invstmtrqTag.AddXml( "INC401K", "Y" );
invstmtrqTag.AddXml( "INC401KBAL", "Y" );
}
return RequestMessage("INVSTMT", "INVSTMT", invstmtrqTag);
}
char* libofx_request_payment( const OfxFiLogin* login, const OfxAccountData* account, const OfxPayee* payee, const OfxPayment* payment )
{
OfxPaymentRequest strq( *login, *account, *payee, *payment );
string request = OfxHeader(login->header_version) + strq.Output();
unsigned size = request.size();
char* result = (char*)malloc(size + 1);
request.copy(result, size);
result[size] = 0;
return result;
}
OfxPaymentRequest::OfxPaymentRequest( const OfxFiLogin& fi, const OfxAccountData& account, const OfxPayee& payee, const OfxPayment& payment ):
OfxRequest(fi),
m_account(account),
m_payee(payee),
m_payment(payment)
{
Add( SignOnRequest() );
OfxAggregate bankacctfromTag("BANKACCTFROM");
bankacctfromTag.Add( "BANKID", m_account.bank_id );
bankacctfromTag.Add( "ACCTID", m_account.account_number );
if ( m_account.account_type == m_account.OFX_CHECKING)
bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
else if ( m_account.account_type == m_account.OFX_SAVINGS )
bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
else if ( m_account.account_type == m_account.OFX_MONEYMRKT )
bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
else if ( m_account.account_type == m_account.OFX_CREDITLINE )
bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
else if ( m_account.account_type == m_account.OFX_CMA )
bankacctfromTag.Add( "ACCTTYPE", "CMA" );
OfxAggregate payeeTag("PAYEE");
payeeTag.Add( "NAME", m_payee.name );
payeeTag.Add( "ADDR1", m_payee.address1 );
payeeTag.Add( "CITY", m_payee.city );
payeeTag.Add( "STATE", m_payee.state );
payeeTag.Add( "POSTALCODE", m_payee.postalcode );
payeeTag.Add( "PHONE", m_payee.phone );
OfxAggregate pmtinfoTag("PMTINFO");
pmtinfoTag.Add( bankacctfromTag );
pmtinfoTag.Add( "TRNAMT", m_payment.amount );
pmtinfoTag.Add( payeeTag );
pmtinfoTag.Add( "PAYACCT", m_payment.account );
pmtinfoTag.Add( "DTDUE", m_payment.datedue );
pmtinfoTag.Add( "MEMO", m_payment.memo );
OfxAggregate pmtrqTag("PMTRQ");
pmtrqTag.Add( pmtinfoTag );
Add( RequestMessage("BILLPAY", "PMT", pmtrqTag) );
}
char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid )
{
#if 0
OfxAggregate pmtinqrqTag( "PMTINQRQ" );
pmtinqrqTag.Add( "SRVRTID", transactionid );
OfxRequest ofx(*login);
ofx.Add( ofx.SignOnRequest() );
ofx.Add( ofx.RequestMessage("BILLPAY", "PMTINQ", pmtinqrqTag) );
string request = OfxHeader() + ofx.Output();
unsigned size = request.size();
char* result = (char*)malloc(size + 1);
request.copy(result, size);
result[size] = 0;
#else
OfxAggregate payeesyncrq( "PAYEESYNCRQ" );
payeesyncrq.Add( "TOKEN", "0" );
payeesyncrq.Add( "TOKENONLY", "N" );
payeesyncrq.Add( "REFRESH", "Y" );
payeesyncrq.Add( "REJECTIFMISSING", "N" );
OfxAggregate message( "BILLPAYMSGSRQV1" );
message.Add( payeesyncrq );
OfxRequest ofx(*login);
ofx.Add( ofx.SignOnRequest() );
ofx.Add( message );
string request = OfxHeader(login->header_version) + ofx.Output();
unsigned size = request.size();
char* result = (char*)malloc(size + 1);
request.copy(result, size);
result[size] = 0;
#endif
return result;
}
// vim:cin:si:ai:et:ts=2:sw=2:
OfxPaymentRequest
Definition: build/libofx-0.10.0/lib/ofx_request_statement.hh:84
OfxAccountData
An abstraction of an account.
Definition: inc/libofx.h:276
OfxPayee
Definition: inc/libofx.h:1398
OfxPaymentRequest::OfxPaymentRequest
OfxPaymentRequest(const OfxFiLogin &fi, const OfxAccountData &account, const OfxPayee &payee, const OfxPayment &payment)
Definition: build/libofx-0.10.0/lib/ofx_request_statement.cpp:154
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.
ofx_utilities.hh
Various simple functions for type conversion & al.
OfxAccountData::OFX_SAVINGS
Definition: inc/libofx.h:305
OfxAccountData::OFX_CREDITCARD
Definition: inc/libofx.h:309
std
ofx_request_statement.hh
Declaration of libofx_request_statement to create an OFX file containing a request for a statement...
OfxStatementRequest::OfxStatementRequest
OfxStatementRequest(const OfxFiLogin &fi, const OfxAccountData &account, time_t from)
Definition: build/libofx-0.10.0/lib/ofx_request_statement.cpp:45
OfxPayment
Definition: inc/libofx.h:1390
OfxStatementRequest::InvestmentStatementRequest
OfxAggregate InvestmentStatementRequest(void) const
Definition: build/libofx-0.10.0/lib/ofx_request_statement.cpp:111
OfxRequest
A generic request.
Definition: build/libofx-0.10.0/lib/ofx_request.hh:36
OfxAggregate
A single aggregate as described in the OFX 1.02 specification.
Definition: build/libofx-0.10.0/lib/ofx_aggregate.hh:42
OfxAccountData::OFX_401K
Definition: inc/libofx.h:311
OfxAccountData::OFX_MONEYMRKT
Definition: inc/libofx.h:306
OfxRequest::RequestMessage
OfxAggregate RequestMessage(const string &msgtype, const string &trntype, const OfxAggregate &aggregate) const
Definition: build/libofx-0.10.0/lib/ofx_request.cpp:115
OfxAccountData::bank_id
char bank_id[OFX_BANKID_LENGTH]
Definition: inc/libofx.h:324
OfxAggregate::Add
void Add(const string &tag, const string &data)
Definition: build/libofx-0.10.0/lib/ofx_aggregate.hh:59
OfxAggregate::Output
string Output(void) const
Definition: build/libofx-0.10.0/lib/ofx_aggregate.hh:90
OfxStatementRequest
A statement request.
Definition: build/libofx-0.10.0/lib/ofx_request_statement.hh:37
OfxStatementRequest::BankStatementRequest
OfxAggregate BankStatementRequest(void) const
Definition: build/libofx-0.10.0/lib/ofx_request_statement.cpp:60
OfxStatementRequest::CreditCardStatementRequest
OfxAggregate CreditCardStatementRequest(void) const
Definition: build/libofx-0.10.0/lib/ofx_request_statement.cpp:87
OfxAccountData::OFX_CMA
Definition: inc/libofx.h:308
OfxAccountData::account_number
char account_number[OFX_ACCTID_LENGTH]
Definition: inc/libofx.h:320
OfxRequest::SignOnRequest
OfxAggregate SignOnRequest(void) const
Definition: build/libofx-0.10.0/lib/ofx_request.cpp:84
OfxAccountData::OFX_CREDITLINE
Definition: inc/libofx.h:307
OfxAccountData::OFX_INVESTMENT
Definition: inc/libofx.h:310
OfxAggregate::AddXml
void AddXml(const string &tag, const string &data)
Definition: build/libofx-0.10.0/lib/ofx_aggregate.hh:70
OfxAccountData::OFX_CHECKING
Definition: inc/libofx.h:304
OfxFiLogin
Information sufficient to log into an financial institution.
Definition: inc/libofx.h:1372