001/* 002 * Copyright 2010-2013 Ning, Inc. 003 * 004 * Ning licenses this file to you under the Apache License, version 2.0 005 * (the "License"); you may not use this file except in compliance with the 006 * License. You may obtain a copy of the License at: 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations 014 * under the License. 015 */ 016 017package com.ning.billing.recurly.model; 018 019import javax.xml.bind.annotation.XmlElement; 020import javax.xml.bind.annotation.XmlRootElement; 021 022import org.joda.time.DateTime; 023 024@XmlRootElement(name = "transaction") 025public class Transaction extends AbstractTransaction { 026 027 @XmlElement(name = "account") 028 private Account account; 029 030 @XmlElement(name = "invoice") 031 private Invoice invoice; 032 033 @XmlElement(name = "subscription") 034 private String subscription; 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 = "source") 049 private String source; 050 051 @XmlElement(name = "recurring") 052 private Boolean recurring; 053 054 @XmlElement(name = "created_at") 055 private DateTime createdAt; 056 057 @XmlElement(name = "details") 058 private TransactionDetails details; 059 060 public Account getAccount() { 061 if (account != null && account.getCreatedAt() == null) { 062 account = fetch(account, Account.class); 063 } 064 return account; 065 } 066 067 public void setAccount(final Account account) { 068 this.account = account; 069 } 070 071 public Invoice getInvoice() { 072 if (invoice != null && invoice.getCreatedAt() == null) { 073 invoice = fetch(invoice, Invoice.class); 074 } 075 return invoice; 076 } 077 078 public void setInvoice(final Invoice invoice) { 079 this.invoice = invoice; 080 } 081 082 public String getSubscription() { 083 return subscription; 084 } 085 086 public void setSubscription(final Object subscription) { 087 this.subscription = stringOrNull(subscription); 088 } 089 090 public String getUuid() { 091 return uuid; 092 } 093 094 public void setUuid(final Object uuid) { 095 this.uuid = stringOrNull(uuid); 096 } 097 098 public Integer getTaxInCents() { 099 return taxInCents; 100 } 101 102 public void setTaxInCents(final Object taxInCents) { 103 this.taxInCents = integerOrNull(taxInCents); 104 } 105 106 public String getCurrency() { 107 return currency; 108 } 109 110 public void setCurrency(final Object currency) { 111 this.currency = stringOrNull(currency); 112 } 113 114 public String getDescription() { 115 return description; 116 } 117 118 public void setDescription(final Object description) { 119 this.description = stringOrNull(description); 120 } 121 122 public String getSource() { 123 return source; 124 } 125 126 public void setSource(final Object source) { 127 this.source = stringOrNull(source); 128 } 129 130 public Boolean getRecurring() { 131 return recurring; 132 } 133 134 public void setRecurring(final Object recurring) { 135 this.recurring = booleanOrNull(recurring); 136 } 137 138 public DateTime getCreatedAt() { 139 return createdAt; 140 } 141 142 public void setCreatedAt(final Object createdAt) { 143 this.createdAt = dateTimeOrNull(createdAt); 144 } 145 146 public TransactionDetails getDetails() { 147 return details; 148 } 149 150 public void setDetails(final TransactionDetails details) { 151 this.details = details; 152 } 153 154 @Override 155 public String toString() { 156 final StringBuilder sb = new StringBuilder("Transaction{"); 157 sb.append("account=").append(account); 158 sb.append(", invoice=").append(invoice); 159 sb.append(", subscription='").append(subscription).append('\''); 160 sb.append(", uuid='").append(uuid).append('\''); 161 sb.append(", taxInCents=").append(taxInCents); 162 sb.append(", currency='").append(currency).append('\''); 163 sb.append(", description='").append(description).append('\''); 164 sb.append(", source='").append(source).append('\''); 165 sb.append(", recurring=").append(recurring); 166 sb.append(", createdAt=").append(createdAt); 167 sb.append(", details=").append(details); 168 sb.append('}'); 169 return sb.toString(); 170 } 171 172 @Override 173 public boolean equals(final Object o) { 174 if (this == o) { 175 return true; 176 } 177 if (o == null || getClass() != o.getClass()) { 178 return false; 179 } 180 if (!super.equals(o)) { 181 return false; 182 } 183 184 final Transaction that = (Transaction) o; 185 186 if (account != null ? !account.equals(that.account) : that.account != null) { 187 return false; 188 } 189 if (createdAt != null ? !createdAt.equals(that.createdAt) : that.createdAt != null) { 190 return false; 191 } 192 if (currency != null ? !currency.equals(that.currency) : that.currency != null) { 193 return false; 194 } 195 if (description != null ? !description.equals(that.description) : that.description != null) { 196 return false; 197 } 198 if (details != null ? !details.equals(that.details) : that.details != null) { 199 return false; 200 } 201 if (invoice != null ? !invoice.equals(that.invoice) : that.invoice != null) { 202 return false; 203 } 204 if (recurring != null ? !recurring.equals(that.recurring) : that.recurring != null) { 205 return false; 206 } 207 if (source != null ? !source.equals(that.source) : that.source != null) { 208 return false; 209 } 210 if (subscription != null ? !subscription.equals(that.subscription) : that.subscription != null) { 211 return false; 212 } 213 if (taxInCents != null ? !taxInCents.equals(that.taxInCents) : that.taxInCents != null) { 214 return false; 215 } 216 if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) { 217 return false; 218 } 219 220 return true; 221 } 222 223 @Override 224 public int hashCode() { 225 int result = super.hashCode(); 226 result = 31 * result + (account != null ? account.hashCode() : 0); 227 result = 31 * result + (invoice != null ? invoice.hashCode() : 0); 228 result = 31 * result + (subscription != null ? subscription.hashCode() : 0); 229 result = 31 * result + (uuid != null ? uuid.hashCode() : 0); 230 result = 31 * result + (taxInCents != null ? taxInCents.hashCode() : 0); 231 result = 31 * result + (currency != null ? currency.hashCode() : 0); 232 result = 31 * result + (description != null ? description.hashCode() : 0); 233 result = 31 * result + (source != null ? source.hashCode() : 0); 234 result = 31 * result + (recurring != null ? recurring.hashCode() : 0); 235 result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 236 result = 31 * result + (details != null ? details.hashCode() : 0); 237 return result; 238 } 239}