00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef OC_TRUST_COMMERCE
00013 #define OC_TRUST_COMMERCE
00014 #include <string>
00015 #include "tcInfo.h"
00016
00017 extern "C" {
00018 #include "tclink.h"
00019 }
00020
00021 using namespace std;
00022
00023 class ocTCLink
00024 {
00025 private:
00026 TCLinkHandle handle;
00027 string transaction_status;
00028 string transaction_id;
00029 string transaction_info;
00030 bool isGood;
00031 void setTransactionInfo( void )
00032 {
00033 const size_t bigBufSize = 1024;
00034 char * bigBuf = new char[bigBufSize];
00035 if( bigBuf && TCLinkGetEntireResponse(handle, bigBuf, bigBufSize) )
00036 {
00037 transaction_info = bigBuf;
00038 }
00039 delete [] bigBuf;
00040 }
00041 public:
00042 ocTCLink():handle(NULL),isGood(true)
00043 {
00044 handle = TCLinkCreate();
00045 if( !handle )
00046 {
00047 isGood=false;
00048 return;
00049 }
00050 PushParam( "custid", tccid);
00051 PushParam( "password", tcpwd);
00052 }
00053
00054 ~ocTCLink()
00055 {
00056 Close();
00057 }
00058
00059 ocTCLink & PushParam(string name, string value)
00060 {
00061 if( handle ) TCLinkPushParam(handle, name.c_str(), value.c_str());
00062 return *this;
00063 }
00064
00065 ocTCLink & Send( void )
00066 {
00067 TCLinkSend(handle);
00068 char responseBuf[PARAM_MAX_LEN];
00069 char * ptrStat = NULL;
00070 if( handle ) ptrStat = TCLinkGetResponse(handle, "status", responseBuf);
00071 if( ptrStat )
00072 {
00073 transaction_status = responseBuf;
00074 if( transaction_status == "accepted" || transaction_status == "approved" )
00075 {
00076 if( TCLinkGetResponse(handle, "transid", responseBuf) )
00077 {
00078 transaction_id = responseBuf;
00079 }
00080 }
00081 else
00082 {
00083 isGood=false;
00084 }
00085 setTransactionInfo();
00086 }
00087 else
00088 {
00089 isGood=false;
00090 }
00091 return *this;
00092 }
00093
00094 ocTCLink & Close()
00095 {
00096 if( handle )
00097 {
00098 TCLinkDestroy(handle);
00099 handle = NULL;
00100 }
00101 }
00102 bool IsGood( void ) { return isGood; }
00103 const string & TransactionStatus( void ) { return transaction_status; }
00104 const string & TransactionId( void ) { return transaction_id; }
00105 const string & TransactionInfo( void ) { return transaction_info; }
00106
00107 };
00108 #endif
00109
00110 #ifdef IN_T2_TESTHARNESS
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 ocTCLink tcLink;
00123 tcLink.PushParam("action","preauth")
00124 .PushParam("media", "cc")
00125 .PushParam("demo", "y")
00126 .PushParam("name", "George George Jr.")
00127 .PushParam("ticket","product-14")
00128
00129
00130 .PushParam("cc","5411111111111115")
00131 .PushParam("exp","0404")
00132 .PushParam("amount","42137");
00133 if( tcLink.Send().IsGood() )
00134 {
00135 cout << "Good cc preauth - TransactionId: " << tcLink.TransactionId() << endl;
00136 cout << "TransactionStatus: " << tcLink.TransactionStatus() << endl;
00137 cout << "TransactionInfo: " << tcLink.TransactionInfo() << endl;
00138
00139
00140 tcLink.Close();
00141 ocTCLink tcLink2;
00142 tcLink2.PushParam("action","postauth")
00143 .PushParam("transid", tcLink.TransactionId().c_str() )
00144 .PushParam("demo", "y");
00145
00146 if( tcLink2.Send().IsGood() )
00147 {
00148 cout << "Good cc postauth - TransactionId: " << tcLink2.TransactionId() << endl;
00149 cout << "TransactionStatus: " << tcLink2.TransactionStatus() << endl;
00150 cout << "TransactionInfo: " << tcLink2.TransactionInfo() << endl;
00151 }
00152 else
00153 {
00154 cout << "Transaction Failed: " << endl
00155 << tcLink2.TransactionInfo() << endl;
00156 }
00157 }
00158 else
00159 {
00160 cout << "Transaction Failed: " << endl
00161 << tcLink.TransactionInfo() << endl;
00162 }
00163
00164 #endif