1 16 17 21 package org.ofbiz.accounting.thirdparty.authorizedotnet; 22 23 import java.util.*; 24 25 public class AuthorizeResponse { 26 27 private String rawResp = null; 28 private Vector response = new Vector(); 29 private String respCode = ""; 30 private String reasonCode = ""; 31 private String reasonText = ""; 32 private String version = "3.0"; 33 private int maxPos = 39; 35 public static int RESPONSE_CODE = 1; 37 public static int RESPONSE_SUBCODE = 2; 38 public static int RESPONSE_REASON_CODE = 3; 39 public static int RESPONSE_REASON_TEXT = 4; 40 public static int APPROVAL_CODE = 5; 41 public static int AUTHORIZATION_CODE = 5; 42 public static int AVS_RESULT_CODE = 6; 43 public static int TRANSACTION_ID = 7; 44 45 public static int INVOICE_NUMBER = 8; 47 public static int DESCRIPTION = 9; 48 public static int AMOUNT = 10; 49 public static int METHOD = 11; 50 public static int TRANSACTION_TYPE = 12; 51 public static int CUSTOMER_ID = 13; 52 public static int CARDHOLDER_FIRST_NAME = 14; 53 public static int CARDHOLDER_LAST_NAME = 15; 54 public static int COMPANY = 16; 55 public static int BILLING_ADDRESS = 17; 56 public static int CITY = 18; 57 public static int STATE = 19; 58 public static int ZIP = 20; 59 public static int COUNTRY = 21; 60 public static int PHONE = 22; 61 public static int FAX = 23; 62 public static int EMAIL = 24; 63 public static int SHIP_TO_FIRST_NAME = 25; 64 public static int SHIP_TO_LAST_NAME = 26; 65 public static int SHIP_TO_COMPANY = 27; 66 public static int SHIP_TO_ADDRESS = 28; 67 public static int SHIP_TO_CITY = 29; 68 public static int SHIP_TO_STATE = 30; 69 public static int SHIP_TO_ZIP = 31; 70 public static int SHIP_TO_COUNTRY = 32; 71 public static int TAX_AMOUNT = 33; 72 public static int DUTY_AMOUNT = 34; 73 public static int FREIGHT_AMOUNT = 35; 74 public static int TAX_EXEMPT_FLAG = 36; 75 public static int PO_NUMBER = 37; 76 public static int MD5_HASH = 38; 77 public static int CID_RESPONSE_CODE = 39; 78 80 public static String APPROVED = "Approved"; 82 public static String DECLINED = "Declined"; 83 public static String ERROR = "Error"; 84 85 86 public AuthorizeResponse(String resp) { 87 this(resp, "|"); 88 } 89 90 public AuthorizeResponse(String resp, String delim) { 91 this.rawResp = resp; 92 this.response = splitResp(resp, delim); 93 setApproval(); 94 } 95 96 private void setApproval() { 97 String rc = (String )response.get(RESPONSE_CODE); 98 99 if(rc.equals("1")) { 100 this.respCode = APPROVED; 101 } 102 103 if(rc.equals("2")) { 104 this.respCode = DECLINED; 105 } 106 107 if(rc.equals("3")) { 108 this.respCode = ERROR; 109 } 110 111 this.reasonCode = (String )response.get(RESPONSE_REASON_CODE); 112 this.reasonText = (String )response.get(RESPONSE_REASON_TEXT); 113 114 } 115 116 public void setVersion(String version) 117 { 118 if (version != null && version.length() > 0) 119 { 120 if (version.equals("3.0") || version.equals("3.1")) 121 this.version = version; 122 } 123 124 } 125 126 public String getResponseCode() { 127 return this.respCode; 128 } 129 130 public String getReasonCode() { 131 return this.reasonCode; 132 } 133 134 public String getReasonText() { 135 return this.reasonText; 136 } 137 138 public String getResponseField(int posNum) { 139 140 if (this.version.equals("3.0")) 141 { 142 if (posNum == this.CID_RESPONSE_CODE) 143 return "M"; 144 } 145 if(posNum < 1 || posNum > maxPos) { 146 return "unknown_field"; 147 } 148 else { 149 return (String )response.get(posNum); 150 } 151 } 152 153 public String getRawResponse() { 154 return this.rawResp; 155 } 156 157 private Vector splitResp(String r, String delim) { 158 int s1=0, s2=-1; 159 Vector out = new Vector(40); 160 out.addElement("empty"); 161 while(true){ 162 s2 = r.indexOf(delim, s1); 163 if(s2 != -1){ 164 out.addElement(r.substring(s1, s2)); 165 }else{ 166 String _ = r.substring(s1); 168 if(_ != null && !_.equals("")){ 169 out.addElement(_); 170 } 171 break; 172 } 173 s1 = s2; 174 s1 += delim.length(); 175 } 176 return out; 177 } 178 179 public String toString() { 180 return response.toString(); 181 } 182 183 } 184 | Popular Tags |