00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef PAY_FORM_HPP
00010 #define PAY_FORM_HPP
00011
00012 #include "read_write_base.hpp"
00013 #include "forms_base.hpp"
00014
00015
00016 #include "PaymentServices.hpp"
00017 #include "Customer.hpp"
00018 #include "lookup.hpp"
00019
00020
00021
00022
00023 class Payment_Form: public forms_base, public Payment_Service
00024 {
00025 bool hasBeenInAddVerification;
00026 public:
00027 long long Customer_Id;
00028
00029
00030 Payment_Form(cgiScript & in)
00031 :forms_base(in),Payment_Service(),Customer_Id(0LL),hasBeenInAddVerification(false)
00032 {setKey(*this);}
00033 ~Payment_Form(){;}
00034
00035
00036 void form_id_transfer( void )
00037 {
00038 llongFXfer( "Payment_Service_Id", Id );
00039 }
00040
00041
00042 void form_data_transfer( void )
00043 {
00044 llongFXfer( "Customer_Id", Customer_Id );
00045 }
00046
00047 bool dbf_action( string mode, changeMap & changes )
00048 {
00049
00050 bool bret = false;
00051 bret = db_action( mode, changes );
00052 return bret;
00053 }
00054
00055
00056 bool form_display( void )
00057 {
00058 bool breturn = true;
00059
00060 script << makeHiddenBox("Customer_Id",Customer_Id);
00061
00062
00063 ocString sql = "select Id, Name from Payment_Service where Id = ";
00064 sql.append(Id);
00065
00066 script << makeComboBox( "Payment Type", "Payment_Service_Id", Id,
00067 sql );
00068
00069 return paymentSetupForm();
00070
00071 return breturn;
00072 }
00073
00074 bool paymentSetupForm( void )
00075 {
00076 bool breturn = true;
00077 getPaymentServiceParameters();
00078
00079
00080 if( usr_params.size() )
00081 {
00082 Customer_Obj customer;
00083 customer.key(Customer_Id);
00084 customer.get_data();
00085
00086 const avs_map & avs = customer.getAvsMap();
00087
00088
00089 for( Payment_Type_Parameters::iterator pos = usr_params.begin();
00090 pos != usr_params.end();
00091 ++pos )
00092 {
00093 paymentSetupElement( pos->second, const_cast<avs_map &>(avs) );
00094 }
00095
00096 }
00097 return breturn;
00098 }
00099
00100
00101 void paymentSetupElement( Payment_Type_Parameter & parm, avs_map & avs )
00102 {
00103 string size, length;
00104 string value;
00105
00106 if( parm.Interface_Type == ui_cc_number )
00107 {
00108 size="16";
00109 length="16";
00110 }
00111 else if( parm.Interface_Type == ui_cc_exp )
00112 {
00113 size="4";
00114 length="4";
00115 }
00116 else if(parm.Interface_Type == ui_cvs )
00117 {
00118 size="4";
00119 length="4";
00120 }
00121 else if( parm.Interface_Type == ui_addr_verification )
00122 {
00123 if( hasBeenInAddVerification == false )
00124 {
00125 script << titledSep("Billing Address:",
00126 "You can leave these as-is if they are the same as your shipping address.");
00127
00128 }
00129 value=avs[parm.Machine_Name];
00130 hasBeenInAddVerification = true;
00131 }
00132 else
00133 {
00134 length="30";
00135 size="80";
00136 }
00137
00138 string label = parm.Name;
00139
00140 ocString ret = formTemplate.getParagraph("control_group");
00141
00142 ocString parmName = "parm";
00143 parmName.append(parm.Id);
00144 ocTextbox * pText = textEntry( parmName, size, length );
00145
00146 if( pText )
00147 {
00148
00149 pText->setContent(value);
00150 getUserParm( pText, parm );
00151 string ctrl = "<div class='instructions'>";
00152 ctrl += parm.Instructions;
00153 ctrl += "</div>";
00154 ctrl += pText->getHtml();
00155 ret = ret.replace("$label$",label.c_str())
00156 .replace("$control$", ctrl.c_str());
00157
00158 delete pText;
00159 }
00160 script << ret << endl;
00161 }
00162
00163
00164
00165
00166
00167 bool getUserParm( ocBase * oc, Payment_Type_Parameter & parm )
00168 {
00169 bool bret = false;
00170 if( oc && Customer_Id )
00171 {
00172 ocString sql = "select Id from Customer_Payment_Service where Customer_Id = ";
00173 sql.append(Customer_Id);
00174
00175 string val = tableLookup ( sql );
00176 if( val.length() )
00177 {
00178
00179
00180 sql = "select Value from Customer_Payment_Parameter "
00181 "where Customer_Pmt_Service_Id = ";
00182 sql += val;
00183 sql +=" and Pmt_Type_Param_Id = ";
00184 sql.append( parm.Id );
00185
00186 val = tableLookup ( sql );
00187 if( val.length() )
00188 {
00189 oc->setContent(val);
00190 bret=true;
00191 }
00192 }
00193 }
00194 return bret;
00195 }
00196
00197 string makeButtonedBottom( string action )
00198 {
00199 ocString ret = formTemplate.getParagraph("form_end");
00200 return ret.replaceAll("$ACTION",action);
00201 }
00202
00203 string makeTop(string uri, string name )
00204 {
00205 ocString ret = formTemplate.getParagraph("form_begin");
00206 return ret.replace("$step_title$","Check Out Step 3 : Payment Setup")
00207 .replace("$action$",uri.c_str())
00208 .replace("$name$",name.c_str())
00209 .replace("$instructions$","Please fill out all of the payment information below.");
00210 }
00211 string titledSep(string title, string instruction )
00212 {
00213 ocString ret = formTemplate.getParagraph("form_titler");
00214 return ret.replace("$name$",title.c_str())
00215 .replace("$instructions$",instruction.c_str());
00216 }
00217 };
00218
00219 class Payment_Form_Complete: public forms_base, public Customer_Payment_Service
00220 {
00221
00222 public:
00223 Customer_Payment_Parameters uparms;
00224
00225
00226 Payment_Form_Complete(cgiScript &in):
00227 forms_base(in),Customer_Payment_Service(){setKey(*this);}
00228 ~Payment_Form_Complete(){;}
00229
00230
00231 void form_id_transfer( void )
00232 {
00233 llongFXfer( "Id", Id );
00234 }
00235
00236
00237 void form_data_transfer( void )
00238 {
00239
00240 llongFXfer( "Customer_Id", Customer_Id );
00241 llongFXfer( "Payment_Service_Id", Payment_Service_Id );
00242 }
00243
00244 bool dbf_action( string mode, changeMap & changes )
00245 {
00246 bool bret = false;
00247 bret = db_action( mode, changes );
00248
00249 if ( bret )
00250 {
00251 if( mode == "i" || mode == "u" )
00252 { deleteOldUserParameters();
00253 bret = createUserParameters();
00254 }
00255 }
00256 else
00257 {
00258 if( mode =="u" && changes.size()==0 )
00259 { bret = true;
00260 }
00261 else
00262 { m_result += "Payment Form Completion object, failure on transaction request - mode: " + mode;
00263
00264 }
00265 }
00266 return bret;
00267 }
00268
00269 bool deleteOldUserParameters( void )
00270 {
00271 ocString sqlcmd = "delete from Customer_Payment_Parameter where Customer_Pmt_Service_Id = ";
00272 sqlcmd.append(Id);
00273
00274 return cmd.execute(sqlcmd);
00275
00276
00277 }
00278 bool createUserParameters( void )
00279 {
00280 bool bret = false;
00281 Payment_Service pmt_svc;
00282 ocString where = " Id = ";
00283 where.append(Payment_Service_Id);
00284
00285 if(pmt_svc.get_data(where))
00286 {
00287 if( pmt_svc.getPaymentServiceParameters() &&
00288 pmt_svc.usr_params.size() )
00289 {
00290
00291 for( Payment_Type_Parameters::iterator pos = pmt_svc.usr_params.begin();
00292 pos != pmt_svc.usr_params.end();
00293 ++pos )
00294 {
00295 addUserElement( pos->second );
00296 }
00297 bret=true;
00298 }
00299 }
00300 else
00301 {
00302 m_result = "Couldn't get payment service data for: " + where;
00303
00304 }
00305 return bret;
00306 }
00307 void addUserElement( Payment_Type_Parameter & parm )
00308 {
00309 cgiInput & args = script.ClientArguments();
00310 ocString parmKey = "parm";
00311 parmKey.append(parm.Id);
00312 if( args.count(parmKey.c_str()) )
00313 {
00314
00315 Customer_Payment_Parameter CustomerPayParm;
00316 CustomerPayParm.Customer_Pmt_Service_Id=Id;
00317 CustomerPayParm.Pmt_Type_Param_Id=parm.Id;
00318 CustomerPayParm.Name=parm.Name;
00319 CustomerPayParm.Machine_Name=parm.Machine_Name;
00320 CustomerPayParm.Value=args[parmKey.c_str()].c_str();
00321 if( CustomerPayParm.db_insert() == false)
00322 {
00323 m_result += "Couldn't Insert ";
00324 m_result += CustomerPayParm.last_result();
00325 }
00326 else
00327 {
00328 uparms.push_back(CustomerPayParm);
00329 }
00330 }
00331 }
00332
00333
00334 bool form_display( void )
00335 {
00336 bool breturn = true;
00337
00338
00339 return breturn;
00340 }
00341
00342
00343 };
00344
00345 #endif
00346
00347