1 package com.jcommercesql.gateway.authorizenet; 2 3 23 24 import java.util.Enumeration ; 25 import java.io.IOException ; 26 27 77 78 public final class AuthorizeNetCC extends AuthorizeNet { 79 80 83 92 protected String x_Card_Num=""; 94 protected String x_Exp_Date=""; 95 protected String x_Type=""; 96 97 101 public AuthorizeNetCC() {}; 102 103 108 public AuthorizeNetCC( String filename ) throws IOException , InvalidPropException { 109 this.properties=loadPropFile(filename); 110 this.propFileName=filename; 111 }; 112 113 137 138 143 public void setCardNum(String cardNum) { this.x_Card_Num=cardNum; } 144 145 150 public String getCardNum() { return x_Card_Num; } 151 152 159 public void setExpDate(String expDate) { this.x_Exp_Date=expDate; } 160 161 166 public String getExpDate() { return x_Exp_Date; } 167 168 178 public void setType(String transType) { this.x_Type=transType; } 179 180 185 public String getType() { return x_Type; } 186 187 200 public void setTransaction(String cardNum, String expDate, String amount, String transType) { 201 202 setCardNum(cardNum); 203 setExpDate(expDate); 204 setAmount(amount); 205 setType(transType); 206 } 207 208 213 private boolean verifyMinCCFieldsSet() { 214 215 boolean result=true; 216 if (x_Card_Num==null) result = false; 217 if (x_Exp_Date==null || x_Delim_Data.equals("") ) result = false; 218 if (x_Type==null || x_Type.equals("") ) result = false; 219 return result; 220 } 221 222 231 public String getPostData() { 232 return postData; 233 } 234 243 public void submit() throws RequiredFieldException,Exception { 244 245 String host=getHost(); 246 String path=getPath(); 247 int port=getPort(); 248 String postdata; 249 250 if (!verifyMinCCFieldsSet()) { 251 throw new RequiredFieldException("One of the following fields is not set: Card_Num,Exp_Date,Type"); 252 } 253 254 if (!verifyMinimumFieldsSet()) { 255 throw new RequiredFieldException("One of the following fields is not set: login, transaction key, amount"); 256 } 257 258 if ( host==null || host.equals("") ) { 259 throw new RequiredFieldException("Host Field Not Set"); 260 } 261 if ( path==null || path.equals("") ) { 262 throw new RequiredFieldException("URL Path Field Not Set"); 263 } 264 265 postdata=AuthorizeNetCodes.REQ_FIELD_VERSION+"="+getVersion(); 267 postdata+="&"+AuthorizeNetCodes.REQ_FIELD_LOGIN+"="+getLogin(); 268 postdata+="&"+AuthorizeNetCodes.REQ_FIELD_TRAN_KEY+"="+getTranKey(); 269 postdata+="&"+AuthorizeNetCodes.REQ_FIELD_AMOUNT+"="+getAmount(); 270 postdata+="&"+AuthorizeNetCodes.REQ_FIELD_CARD_NUM+"="+getCardNum(); 271 postdata+="&"+AuthorizeNetCodes.REQ_FIELD_EXP_DATE+"="+getExpDate(); 272 postdata+="&"+AuthorizeNetCodes.REQ_FIELD_TYPE+"="+getType(); 273 postdata+="&"+AuthorizeNetCodes.REQ_FIELD_DELIM_DATA+"="+getDelimData(); 274 postdata+="&"+AuthorizeNetCodes.REQ_FIELD_DELIM_CHAR+"="+getDelimChar(); 275 276 Enumeration e = optionalFields.keys(); 278 while (e.hasMoreElements()) { 279 String field = (String )e.nextElement(); 280 postdata+="&"+field+"="+(String )optionalFields.get(field); 281 } 282 283 int idx=0; 285 while (merchantDefinedFields.size() > idx) { 286 postdata+="&"+(String )merchantDefinedFields.get(idx)+"="+(String )merchantDefinedFields.get(idx+1); 287 idx+=2; 288 } 289 290 this.postData=postdata; 291 292 submitANetPost(host,port,path,postdata); 293 294 } } 296 | Popular Tags |