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; 022 023import org.joda.time.DateTime; 024 025import com.google.common.base.Objects; 026 027@XmlRootElement(name = "transaction") 028public class Transaction extends AbstractTransaction { 029 030 @XmlElement(name = "account") 031 private Account account; 032 033 @XmlElement(name = "invoice") 034 private Invoice invoice; 035 036 @XmlElement(name = "uuid") 037 private String uuid; 038 039 @XmlElement(name = "tax_in_cents") 040 private Integer taxInCents; 041 042 @XmlElement(name = "currency") 043 private String currency; 044 045 @XmlElement(name = "description") 046 private String description; 047 048 @XmlElement(name = "recurring") 049 private Boolean recurring; 050 051 @XmlElement(name = "product_code") 052 private String productCode; 053 054 @XmlElement(name = "created_at") 055 private DateTime createdAt; 056 057 @XmlElement(name = "updated_at") 058 private DateTime updatedAt; 059 060 @XmlElement(name = "details") 061 private TransactionDetails details; 062 063 @XmlElement(name = "collected_at") 064 private DateTime collectedAt; 065 066 @XmlElement(name = "gateway_type") 067 private String gatewayType; 068 069 @XmlElement(name = "origin") 070 private String origin; 071 072 @XmlElement(name = "approval_code") 073 private String approvalCode; 074 075 public Account getAccount() { 076 if (account != null && account.getCreatedAt() == null) { 077 account = fetch(account, Account.class); 078 } 079 return account; 080 } 081 082 public void setAccount(final Account account) { 083 this.account = account; 084 } 085 086 public Invoice getInvoice() { 087 if (invoice != null && invoice.getCreatedAt() == null) { 088 invoice = fetch(invoice, Invoice.class); 089 } 090 return invoice; 091 } 092 093 public void setInvoice(final Invoice invoice) { 094 this.invoice = invoice; 095 } 096 097 public String getUuid() { 098 return uuid; 099 } 100 101 public void setUuid(final Object uuid) { 102 this.uuid = stringOrNull(uuid); 103 } 104 105 public Integer getTaxInCents() { 106 return taxInCents; 107 } 108 109 public void setTaxInCents(final Object taxInCents) { 110 this.taxInCents = integerOrNull(taxInCents); 111 } 112 113 public String getCurrency() { 114 return currency; 115 } 116 117 public void setCurrency(final Object currency) { 118 this.currency = stringOrNull(currency); 119 } 120 121 public String getDescription() { 122 return description; 123 } 124 125 public void setDescription(final Object description) { 126 this.description = stringOrNull(description); 127 } 128 129 public Boolean getRecurring() { 130 return recurring; 131 } 132 133 public void setRecurring(final Object recurring) { this.recurring = booleanOrNull(recurring); } 134 135 protected String getProductCode() { return productCode; } 136 137 public void setProductCode(final Object productCode) { this.productCode = stringOrNull(productCode); } 138 139 public DateTime getCreatedAt() { 140 return createdAt; 141 } 142 143 public void setCreatedAt(final Object createdAt) { 144 this.createdAt = dateTimeOrNull(createdAt); 145 } 146 147 public DateTime getUpdatedAt() { 148 return updatedAt; 149 } 150 151 public void setUpdatedAt(final Object updatedAt) { 152 this.updatedAt = dateTimeOrNull(updatedAt); 153 } 154 155 public TransactionDetails getDetails() { 156 return details; 157 } 158 159 public void setDetails(final TransactionDetails details) { 160 this.details = details; 161 } 162 163 public DateTime getCollectedAt() { 164 return collectedAt; 165 } 166 167 public void setCollectedAt(final Object collectedAt) { 168 this.collectedAt = dateTimeOrNull(collectedAt); 169 } 170 171 public String getGatewayType() { 172 return this.gatewayType; 173 } 174 175 protected void setGatewayType(final Object gatewayType) { 176 this.gatewayType = stringOrNull(gatewayType); 177 } 178 179 public String getOrigin() { 180 return this.origin; 181 } 182 183 protected void setOrigin(final Object origin) { 184 this.origin = stringOrNull(origin); 185 } 186 187 public String getApprovalCode() { 188 return this.approvalCode; 189 } 190 191 protected void setApprovalCode(final Object approvalCode) { 192 this.approvalCode = stringOrNull(approvalCode); 193 } 194 195 @Override 196 public String toString() { 197 final StringBuilder sb = new StringBuilder("Transaction{"); 198 sb.append("account=").append(account); 199 sb.append(", invoice=").append(invoice); 200 sb.append(", uuid='").append(uuid).append('\''); 201 sb.append(", taxInCents=").append(taxInCents); 202 sb.append(", currency='").append(currency).append('\''); 203 sb.append(", description='").append(description).append('\''); 204 sb.append(", recurring=").append(recurring); 205 sb.append(", productCode=").append(productCode); 206 sb.append(", createdAt=").append(createdAt); 207 sb.append(", details=").append(details); 208 sb.append(", collectedAt=").append(collectedAt); 209 sb.append(", updatedAt=").append(updatedAt); 210 sb.append(", origin=").append(origin); 211 sb.append(", gatewayType=").append(gatewayType); 212 sb.append(", approvalCode=").append(approvalCode); 213 sb.append('}'); 214 return sb.toString(); 215 } 216 217 @Override 218 public boolean equals(final Object o) { 219 if (this == o) return true; 220 if (o == null || getClass() != o.getClass()) return false; 221 222 final Transaction that = (Transaction) o; 223 224 if (account != null ? !account.equals(that.account) : that.account != null) { 225 return false; 226 } 227 if (createdAt != null ? createdAt.compareTo(that.createdAt) != 0 : that.createdAt != null) { 228 return false; 229 } 230 if (currency != null ? !currency.equals(that.currency) : that.currency != null) { 231 return false; 232 } 233 if (description != null ? !description.equals(that.description) : that.description != null) { 234 return false; 235 } 236 if (details != null ? !details.equals(that.details) : that.details != null) { 237 return false; 238 } 239 if (invoice != null ? !invoice.equals(that.invoice) : that.invoice != null) { 240 return false; 241 } 242 if (recurring != null ? !recurring.equals(that.recurring) : that.recurring != null) { 243 return false; 244 } 245 if (productCode != null ? !productCode.equals(that.productCode) : that.productCode != null) { 246 return false; 247 } 248 if (taxInCents != null ? !taxInCents.equals(that.taxInCents) : that.taxInCents != null) { 249 return false; 250 } 251 if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) { 252 return false; 253 } 254 if (updatedAt != null ? updatedAt.compareTo(that.updatedAt) != 0 : that.updatedAt != null) { 255 return false; 256 } 257 if (collectedAt != null ? collectedAt.compareTo(that.collectedAt) != 0 : that.collectedAt != null) { 258 return false; 259 } 260 if (origin != null ? !origin.equals(that.origin) : that.origin != null) { 261 return false; 262 } 263 if (approvalCode != null ? !approvalCode.equals(that.approvalCode) : that.approvalCode != null) { 264 return false; 265 } 266 if (gatewayType != null ? !gatewayType.equals(that.gatewayType) : that.gatewayType != null) { 267 return false; 268 } 269 270 return true; 271 } 272 273 @Override 274 public int hashCode() { 275 return Objects.hashCode( 276 account, 277 invoice, 278 uuid, 279 taxInCents, 280 currency, 281 description, 282 productCode, 283 recurring, 284 createdAt, 285 updatedAt, 286 details, 287 gatewayType, 288 origin, 289 approvalCode 290 ); 291 } 292}