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 com.google.common.base.Objects; 021 022import javax.xml.bind.annotation.XmlElement; 023import javax.xml.bind.annotation.XmlElementWrapper; 024import javax.xml.bind.annotation.XmlList; 025import javax.xml.bind.annotation.XmlRootElement; 026import javax.xml.bind.annotation.XmlTransient; 027import java.util.List; 028 029@XmlRootElement(name = "purchase") 030public class Purchase extends RecurlyObject { 031 @XmlTransient 032 public static final String PURCHASES_ENDPOINT = "/purchases"; 033 034 @XmlElement(name = "currency") 035 private String currency; 036 037 @XmlElement(name = "collection_method") 038 private String collectionMethod; 039 040 @XmlElement(name = "po_number") 041 private String poNumber; 042 043 @XmlElement(name = "net_terms") 044 private Integer netTerms; 045 046 @XmlElement(name = "account") 047 private Account account; 048 049 @XmlElementWrapper(name = "adjustments") 050 @XmlElement(name = "adjustment") 051 private Adjustments adjustments; 052 053 @XmlElementWrapper(name = "subscriptions") 054 @XmlElement(name = "subscription") 055 private Subscriptions subscriptions; 056 057 @XmlElement(name = "shipping_address") 058 private ShippingAddress shippingAddress; 059 060 @XmlElementWrapper(name = "shipping_fees") 061 @XmlElement(name = "shipping_fee") 062 private ShippingFees shippingFees; 063 064 @XmlElement(name = "gift_card") 065 private GiftCard giftCard; 066 067 @XmlElement(name = "customer_notes") 068 private String customerNotes; 069 070 @XmlElement(name = "vat_reverse_charge_notes") 071 private String vatReverseChargeNotes; 072 073 @XmlElement(name = "terms_and_conditions") 074 private String termsAndConditions; 075 076 @XmlElement(name = "shipping_address_id") 077 private Long shippingAddressId; 078 079 @XmlElement(name = "gateway_code") 080 private String gatewayCode; 081 082 @XmlElement(name = "transaction_type") 083 private String transactionType; 084 085 @XmlList 086 @XmlElementWrapper(name = "coupon_codes") 087 @XmlElement(name = "coupon_code") 088 private List<String> couponCodes; 089 090 public void setAccount(final Account account) { 091 this.account = account; 092 } 093 094 public Account getAccount() { 095 return account; 096 } 097 098 public void setAdjustments(final Adjustments adjustments) { 099 this.adjustments = adjustments; 100 } 101 102 public Adjustments getAdjustments() { 103 return adjustments; 104 } 105 106 public String getCollectionMethod() { 107 return collectionMethod; 108 } 109 110 public void setCollectionMethod(final Object collectionMethod) { 111 this.collectionMethod = stringOrNull(collectionMethod); 112 } 113 114 public void setCouponCodes(final List<String> couponCodes) { 115 this.couponCodes = couponCodes; 116 } 117 118 public List<String> getCouponCodes() { 119 return this.couponCodes; 120 } 121 122 public GiftCard getGiftCard() { 123 return giftCard; 124 } 125 126 public void setGiftCard(final GiftCard giftCard) { 127 this.giftCard = giftCard; 128 } 129 130 public Integer getNetTerms() { 131 return netTerms; 132 } 133 134 public void setNetTerms(final Object terms) { 135 this.netTerms = integerOrNull(terms); 136 } 137 138 public String getPoNumber() { 139 return poNumber; 140 } 141 142 public void setPoNumber(final Object poNumber) { 143 this.poNumber = stringOrNull(poNumber); 144 } 145 146 public String getCurrency() { 147 return currency; 148 } 149 150 public void setCurrency(final Object currency) { 151 this.currency = stringOrNull(currency); 152 } 153 154 public ShippingAddress getShippingAddress() { 155 return shippingAddress; 156 } 157 158 public void setShippingAddress(final ShippingAddress shippingAddress) { 159 this.shippingAddress = shippingAddress; 160 } 161 162 public void setShippingFees(final ShippingFees shippingFees) { 163 this.shippingFees = shippingFees; 164 } 165 166 public ShippingFees getShippingFees() { 167 return shippingFees; 168 } 169 170 public void setSubscriptions(final Subscriptions subscriptions) { 171 this.subscriptions = subscriptions; 172 } 173 174 public Subscriptions getSubscriptions() { 175 return subscriptions; 176 } 177 178 public String getCustomerNotes() { 179 return customerNotes; 180 } 181 182 public void setCustomerNotes(final Object customerNotes) { 183 this.customerNotes = stringOrNull(customerNotes); 184 } 185 186 public String getTermsAndConditions() { 187 return termsAndConditions; 188 } 189 190 public void setTermsAndConditions(final Object termsAndConditions) { 191 this.termsAndConditions = stringOrNull(termsAndConditions); 192 } 193 194 public String getVatReverseChargeNotes() { 195 return vatReverseChargeNotes; 196 } 197 198 public void setVatReverseChargeNotes(final Object vatReverseChargeNotes) { 199 this.vatReverseChargeNotes = stringOrNull(vatReverseChargeNotes); 200 } 201 202 public Long getShippingAddressId() { 203 return shippingAddressId; 204 } 205 206 public void setShippingAddressId(final Object shippingAddressId) { 207 this.shippingAddressId = longOrNull(shippingAddressId); 208 } 209 210 public String getGatewayCode() { 211 return gatewayCode; 212 } 213 214 public void setGatewayCode(final Object gatewayCode) { 215 this.gatewayCode = stringOrNull(gatewayCode); 216 } 217 218 public String getTransactionType() { 219 return transactionType; 220 } 221 222 public void setTransactionType(final Object transactionType) { 223 this.transactionType = stringOrNull(transactionType); 224 } 225 226 @Override 227 public String toString() { 228 final StringBuilder sb = new StringBuilder(); 229 sb.append("Purchase"); 230 sb.append("{account=").append(account); 231 sb.append(", adjustments=").append(adjustments); 232 sb.append(", collectionMethod='").append(collectionMethod).append('\''); 233 sb.append(", currency='").append(currency).append('\''); 234 sb.append(", poNumber='").append(poNumber).append('\''); 235 sb.append(", netTerms='").append(netTerms).append('\''); 236 sb.append(", giftCard='").append(giftCard).append('\''); 237 sb.append(", shippingAddress='").append(shippingAddress).append('\''); 238 sb.append(", shippingFees=").append(shippingFees); 239 sb.append(", subscriptions='").append(subscriptions).append('\''); 240 sb.append(", couponCodes='").append(couponCodes).append('\''); 241 sb.append(", customerNotes='").append(customerNotes).append('\''); 242 sb.append(", termsAndConditions='").append(termsAndConditions).append('\''); 243 sb.append(", vatReverseChargeNotes='").append(vatReverseChargeNotes).append('\''); 244 sb.append(", shippingAddressId='").append(shippingAddressId).append('\''); 245 sb.append(", gatewayCode='").append(gatewayCode).append('\''); 246 sb.append(", transactionType='").append(transactionType).append('\''); 247 sb.append('}'); 248 return sb.toString(); 249 } 250 251 @Override 252 public boolean equals(final Object o) { 253 if (this == o) return true; 254 if (o == null || getClass() != o.getClass()) return false; 255 256 final Purchase purchase = (Purchase) o; 257 258 if (account != null ? !account.equals(purchase.account) : purchase.account != null) { 259 return false; 260 } 261 if (adjustments != null ? !adjustments.equals(purchase.adjustments) : purchase.adjustments != null) { 262 return false; 263 } 264 if (collectionMethod != null ? !collectionMethod.equals(purchase.collectionMethod) : purchase.collectionMethod != null) { 265 return false; 266 } 267 if (couponCodes != null ? !couponCodes.equals(purchase.couponCodes) : purchase.couponCodes != null) { 268 return false; 269 } 270 if (currency != null ? !currency.equals(purchase.currency) : purchase.currency != null) { 271 return false; 272 } 273 if (customerNotes != null ? !customerNotes.equals(purchase.customerNotes) : purchase.customerNotes != null) { 274 return false; 275 } 276 if (gatewayCode != null ? !gatewayCode.equals(purchase.gatewayCode) : purchase.gatewayCode != null) { 277 return false; 278 } 279 if (giftCard != null ? !giftCard.equals(purchase.giftCard) : purchase.giftCard != null) { 280 return false; 281 } 282 if (poNumber != null ? !poNumber.equals(purchase.poNumber) : purchase.poNumber != null) { 283 return false; 284 } 285 if (netTerms != null ? !netTerms.equals(purchase.netTerms) : purchase.netTerms != null) { 286 return false; 287 } 288 if (shippingAddress != null ? !shippingAddress.equals(purchase.shippingAddress) : purchase.shippingAddress != null) { 289 return false; 290 } 291 if (shippingAddressId != null ? !shippingAddressId.equals(purchase.shippingAddressId) : purchase.shippingAddressId != null) { 292 return false; 293 } 294 if (shippingFees != null ? !shippingFees.equals(purchase.shippingFees) : purchase.shippingFees != null) { 295 return false; 296 } 297 if (subscriptions != null ? !subscriptions.equals(purchase.subscriptions) : purchase.subscriptions != null) { 298 return false; 299 } 300 if (termsAndConditions != null ? !termsAndConditions.equals(purchase.termsAndConditions) : purchase.termsAndConditions != null) { 301 return false; 302 } 303 if (transactionType != null ? !transactionType.equals(purchase.transactionType) : purchase.transactionType != null) { 304 return false; 305 } 306 if (vatReverseChargeNotes != null ? !vatReverseChargeNotes.equals(purchase.vatReverseChargeNotes) : purchase.vatReverseChargeNotes != null) { 307 return false; 308 } 309 310 return true; 311 } 312 313 @Override 314 public int hashCode() { 315 return Objects.hashCode( 316 account, 317 adjustments, 318 collectionMethod, 319 currency, 320 giftCard, 321 poNumber, 322 netTerms, 323 shippingAddress, 324 shippingFees, 325 subscriptions, 326 couponCodes, 327 customerNotes, 328 termsAndConditions, 329 vatReverseChargeNotes, 330 shippingAddressId, 331 gatewayCode, 332 transactionType 333 ); 334 } 335 336} 337 338