001/* 002 * Copyright 2010-2014 Ning, Inc. 003 * Copyright 2014-2015 The Billing Project, LLC 004 * 005 * The Billing Project licenses this file to you under the Apache License, version 2.0 006 * (the "License"); you may not use this file except in compliance with the 007 * License. You may obtain a copy of the License at: 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 014 * License for the specific language governing permissions and limitations 015 * under the License. 016 */ 017 018package com.ning.billing.recurly.model; 019 020import javax.xml.bind.annotation.XmlElement; 021import javax.xml.bind.annotation.XmlRootElement; 022import java.util.Map; 023import com.google.common.base.Objects; 024 025@XmlRootElement(name = "transaction") 026public class AbstractTransaction extends RecurlyObject { 027 028 public static class VerificationResult { 029 030 private String code; 031 032 private String message; 033 034 public VerificationResult() { 035 } 036 037 public VerificationResult(final String code, final String message) { 038 this.code = code; 039 this.message = message; 040 } 041 042 public String getCode() { 043 return code; 044 } 045 046 public void setCode(final String code) { 047 this.code = code; 048 } 049 050 public String getMessage() { 051 return message; 052 } 053 054 public void setMessage(final String message) { 055 this.message = message; 056 } 057 058 public static VerificationResult as(final Object object) { 059 if (isNull(object)) { 060 return null; 061 } 062 063 if (object instanceof Map) { 064 final Map map = (Map) object; 065 return new VerificationResult(stringOrNull(map.get("code")), stringOrNull(map.get(""))); 066 } 067 068 return new VerificationResult(null, object.toString()); 069 } 070 } 071 072 @XmlElement(name = "action") 073 protected String action; 074 075 @XmlElement(name = "amount_in_cents") 076 protected Integer amountInCents; 077 078 @XmlElement(name = "status") 079 protected String status; 080 081 @XmlElement(name = "reference") 082 protected String reference; 083 084 @XmlElement(name = "test") 085 protected Boolean test; 086 087 @XmlElement(name = "voidable") 088 protected Boolean voidable; 089 090 @XmlElement(name = "refundable") 091 protected Boolean refundable; 092 093 @XmlElement(name = "transaction_error") 094 private TransactionError transactionError; 095 096 @XmlElement(name = "source") 097 private String source; 098 099 @XmlElement(name = "ip_address") 100 private String ipAddress; 101 102 @XmlElement(name = "cvv_result") 103 private VerificationResult cvvResult; 104 105 @XmlElement(name = "avs_result") 106 private VerificationResult avsResult; 107 108 @XmlElement(name = "avs_result_street") 109 private String avsResultStreet; 110 111 @XmlElement(name = "avs_result_postal") 112 private String avsResultPostal; 113 114 @XmlElement(name = "failure_type") 115 private String failureType; 116 117 @XmlElement(name = "gateway_error_codes") 118 private String gatewayErrorCodes; 119 120 @XmlElement(name = "payment_method") 121 private String paymentMethod; 122 123 @XmlElement(name = "message") 124 private String message; 125 126 public String getFailureType() { 127 return failureType; 128 } 129 130 public void setFailureType(final Object failureType) { 131 this.failureType = stringOrNull(failureType); 132 } 133 134 public String getAction() { 135 return action; 136 } 137 138 public void setAction(final Object action) { 139 this.action = stringOrNull(action); 140 } 141 142 public Integer getAmountInCents() { 143 return amountInCents; 144 } 145 146 public void setAmountInCents(final Object amountInCents) { 147 this.amountInCents = integerOrNull(amountInCents); 148 } 149 150 public String getStatus() { 151 return status; 152 } 153 154 public void setStatus(final Object status) { 155 this.status = stringOrNull(status); 156 } 157 158 public String getReference() { 159 return reference; 160 } 161 162 public void setReference(final Object reference) { 163 this.reference = stringOrNull(reference); 164 } 165 166 public Boolean getTest() { 167 return test; 168 } 169 170 public void setTest(final Object test) { 171 this.test = booleanOrNull(test); 172 } 173 174 public Boolean getVoidable() { 175 return voidable; 176 } 177 178 public void setVoidable(final Object voidable) { 179 this.voidable = booleanOrNull(voidable); 180 } 181 182 public Boolean getRefundable() { 183 return refundable; 184 } 185 186 public void setRefundable(final Object refundable) { 187 this.refundable = booleanOrNull(refundable); 188 } 189 190 public TransactionError getTransactionError() { 191 return transactionError; 192 } 193 194 public void setTransactionError(final TransactionError transactionError) { 195 this.transactionError = transactionError; 196 } 197 198 public String getSource() { 199 return source; 200 } 201 202 public void setSource(final Object source) { 203 this.source = stringOrNull(source); 204 } 205 206 public String getIpAddress() { 207 return ipAddress; 208 } 209 210 public void setIpAddress(final Object ipAddress) { 211 this.ipAddress = stringOrNull(ipAddress); 212 } 213 214 public VerificationResult getCvvResult() { 215 return cvvResult; 216 } 217 218 public void setCvvResult(final Object cvvResult) { 219 this.cvvResult = VerificationResult.as(cvvResult); 220 } 221 222 public VerificationResult getAvsResult() { 223 return avsResult; 224 } 225 226 public void setAvsResult(final Object avsResult) { 227 this.avsResult = VerificationResult.as(avsResult); 228 } 229 230 public String getAvsResultStreet() { 231 return avsResultStreet; 232 } 233 234 public void setAvsResultStreet(final Object avsResultStreet) { 235 this.avsResultStreet = stringOrNull(avsResultStreet); 236 } 237 238 public String getAvsResultPostal() { 239 return avsResultPostal; 240 } 241 242 public void setAvsResultPostal(final Object avsResultPostal) { 243 this.avsResultPostal = stringOrNull(avsResultPostal); 244 } 245 246 public String getGatewayErrorCodes() { 247 return gatewayErrorCodes; 248 } 249 250 public void setGatewayErrorCodes(final Object gatewayErrorCodes) { 251 this.gatewayErrorCodes = stringOrNull(gatewayErrorCodes); 252 } 253 254 public String getPaymentMethod() { 255 return paymentMethod; 256 } 257 258 public void setPaymentMethod(final Object paymentMethod) { 259 this.paymentMethod = stringOrNull(paymentMethod); 260 } 261 262 public String getMessage() { 263 return this.message; 264 } 265 266 protected void setMessage(final Object message) { 267 this.message = stringOrNull(message); 268 } 269 270 @Override 271 public boolean equals(final Object o) { 272 if (this == o) return true; 273 if (o == null || getClass() != o.getClass()) return false; 274 275 final AbstractTransaction that = (AbstractTransaction) o; 276 277 if (action != null ? !action.equals(that.action) : that.action != null) { 278 return false; 279 } 280 if (amountInCents != null ? !amountInCents.equals(that.amountInCents) : that.amountInCents != null) { 281 return false; 282 } 283 if (reference != null ? !reference.equals(that.reference) : that.reference != null) { 284 return false; 285 } 286 if (refundable != null ? !refundable.equals(that.refundable) : that.refundable != null) { 287 return false; 288 } 289 if (status != null ? !status.equals(that.status) : that.status != null) { 290 return false; 291 } 292 if (test != null ? !test.equals(that.test) : that.test != null) { 293 return false; 294 } 295 if (transactionError != null ? !transactionError.equals(that.transactionError) : that.transactionError != null) { 296 return false; 297 } 298 if (voidable != null ? !voidable.equals(that.voidable) : that.voidable != null) { 299 return false; 300 } 301 if (source != null ? !source.equals(that.source) : that.source != null) { 302 return false; 303 } 304 if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null) { 305 return false; 306 } 307 if (avsResult != null ? !avsResult.equals(that.avsResult) : that.avsResult != null) { 308 return false; 309 } 310 if (cvvResult != null ? !cvvResult.equals(that.cvvResult) : that.cvvResult != null) { 311 return false; 312 } 313 if (avsResultStreet != null ? !avsResultStreet.equals(that.avsResultStreet) : that.avsResultStreet != null) { 314 return false; 315 } 316 if (avsResultPostal != null ? !avsResultPostal.equals(that.avsResultPostal) : that.avsResultPostal != null) { 317 return false; 318 } 319 if (failureType != null ? !failureType.equals(that.failureType) : that.failureType != null) { 320 return false; 321 } 322 if (paymentMethod != null ? !paymentMethod.equals(that.paymentMethod) : that.paymentMethod != null) { 323 return false; 324 } 325 if (message != null ? !message.equals(that.message) : that.message != null) { 326 return false; 327 } 328 if (gatewayErrorCodes != null ? !gatewayErrorCodes.equals(that.gatewayErrorCodes) : that.gatewayErrorCodes != null) { 329 return false; 330 } 331 332 return true; 333 } 334 335 @Override 336 public int hashCode() { 337 return Objects.hashCode( 338 action, 339 amountInCents, 340 status, 341 reference, 342 test, 343 voidable, 344 refundable, 345 transactionError, 346 source, 347 ipAddress, 348 message, 349 gatewayErrorCodes, 350 paymentMethod, 351 cvvResult, 352 avsResult, 353 avsResultStreet, 354 avsResultPostal 355 ); 356 } 357}