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; 021import org.joda.time.DateTime; 022 023import javax.xml.bind.annotation.XmlElement; 024import javax.xml.bind.annotation.XmlRootElement; 025 026/** 027 * Class that represents a gift card in the Recurly API. 028 */ 029@XmlRootElement(name = "gift_card") 030public class GiftCard extends RecurlyObject { 031 032 @XmlElement(name = "product_code") 033 private String productCode; 034 035 @XmlElement(name = "currency") 036 private String currency; 037 038 @XmlElement(name = "id") 039 private Long id; 040 041 @XmlElement(name = "redemption_code") 042 private String redemptionCode; 043 044 @XmlElement(name = "gifter_account_code") 045 private String gifterAccountCode; 046 047 @XmlElement(name = "recipient_account_code") 048 private String recipientAccountCode; 049 050 @XmlElement(name = "unit_amount_in_cents") 051 private Integer unitAmountInCents; 052 053 @XmlElement(name = "balance_in_cents") 054 private Integer balanceInCents; 055 056 @XmlElement(name = "invoice_number") 057 private Integer invoiceNumber; 058 059 @XmlElement(name = "gifter_account") 060 private Account gifterAccount; 061 062 @XmlElement(name = "delivery") 063 private Delivery delivery; 064 065 @XmlElement(name = "created_at") 066 private DateTime createdAt; 067 068 @XmlElement(name = "updated_at") 069 private DateTime updatedAt; 070 071 @XmlElement(name = "redeemed_at") 072 private DateTime redeemedAt; 073 074 @XmlElement(name = "delivered_at") 075 private DateTime deliveredAt; 076 077 @XmlElement(name = "canceled_at") 078 private DateTime canceledAt; 079 080 public Long getId() { 081 return id; 082 } 083 084 public void setId(final Object id) { this.id = longOrNull(id); } 085 086 public String getProductCode() { 087 return productCode; 088 } 089 090 public void setProductCode(final Object productCode) { 091 this.productCode = stringOrNull(productCode); 092 } 093 094 public String getRedemptionCode() { 095 return redemptionCode; 096 } 097 098 public void setRedemptionCode(final Object redemptionCode) { 099 this.redemptionCode = stringOrNull(redemptionCode); 100 } 101 102 public String getGifterAccountCode() { 103 return gifterAccountCode; 104 } 105 106 public void setGifterAccountCode(final Object gifterAccountCode) { 107 this.gifterAccountCode = stringOrNull(gifterAccountCode); 108 } 109 110 public String getRecipientAccountCode() { 111 return recipientAccountCode; 112 } 113 114 public void setRecipientAccountCode(final Object recipientAccountCode) { 115 this.recipientAccountCode = stringOrNull(recipientAccountCode); 116 } 117 118 public String getCurrency() { 119 return currency; 120 } 121 122 public void setCurrency(final Object currency) { 123 this.currency = stringOrNull(currency); 124 } 125 126 public Delivery getDelivery() { return delivery; } 127 128 public void setDelivery(final Delivery delivery) { 129 this.delivery = delivery; 130 } 131 132 public Account getGifterAccount() { return gifterAccount; } 133 134 public void setGifterAccount(final Account gifterAccount) { 135 this.gifterAccount = gifterAccount; 136 } 137 138 public Integer getUnitAmountInCents() { return unitAmountInCents; } 139 140 public void setUnitAmountInCents(final Object unitAmountInCents) { 141 this.unitAmountInCents = integerOrNull(unitAmountInCents); 142 } 143 144 public Integer getBalanceInCents() { return balanceInCents; } 145 146 public void setBalanceInCents(final Object balanceInCents) { 147 this.balanceInCents = integerOrNull(balanceInCents); 148 } 149 150 public Integer getInvoiceNumber() { 151 return invoiceNumber; 152 } 153 154 public void setInvoiceNumber(final Object invoiceNumber) { 155 this.invoiceNumber = integerOrNull(invoiceNumber); 156 } 157 158 public DateTime getCreatedAt() { 159 return createdAt; 160 } 161 162 public void setCreatedAt(final Object createdAt) { 163 this.createdAt = dateTimeOrNull(createdAt); 164 } 165 166 public DateTime getUpdatedAt() { 167 return updatedAt; 168 } 169 170 public void setUpdatedAt(final Object updatedAt) { 171 this.updatedAt = dateTimeOrNull(updatedAt); 172 } 173 174 public DateTime getRedeemedAt() { 175 return redeemedAt; 176 } 177 178 public void setRedeemedAt(final Object redeemedAt) { 179 this.redeemedAt = dateTimeOrNull(redeemedAt); 180 } 181 182 public DateTime getDeliveredAt() { 183 return deliveredAt; 184 } 185 186 public void setDeliveredAt(final Object deliveredAt) { 187 this.deliveredAt = dateTimeOrNull(deliveredAt); 188 } 189 190 public DateTime getCanceledAt() { 191 return canceledAt; 192 } 193 194 public void setCanceledAt(final Object canceledAt) { 195 this.canceledAt = dateTimeOrNull(canceledAt); 196 } 197 198 /** 199 * Builds a redemption request 200 * 201 * @param accountCode Account code to redeem 202 * @return gift card redemption data for an account 203 */ 204 public static GiftCard.Redemption createRedemption(String accountCode) { 205 Redemption redemption = new Redemption(); 206 redemption.setAccountCode(accountCode); 207 return redemption; 208 } 209 210 /** 211 * Represents gift card redemption data 212 */ 213 @XmlRootElement(name = "recipient_account") 214 public static class Redemption extends RecurlyObject { 215 216 @XmlElement(name = "account_code") 217 private String accountCode; 218 219 public String getAccountCode() { return accountCode; } 220 221 public void setAccountCode(final String accountCode) { 222 this.accountCode = accountCode; 223 } 224 } 225 226 @Override 227 public String toString() { 228 final StringBuilder sb = new StringBuilder(); 229 sb.append("GiftCard"); 230 sb.append("{ productCode='").append(productCode).append('\''); 231 sb.append(", currency='").append(currency).append('\''); 232 sb.append(", id='").append(id).append('\''); 233 sb.append(", redemptionCode='").append(redemptionCode).append('\''); 234 sb.append(", gifterAccountCode='").append(gifterAccountCode).append('\''); 235 sb.append(", recipientAccountCode='").append(recipientAccountCode).append('\''); 236 sb.append(", unitAmountInCents='").append(unitAmountInCents).append('\''); 237 sb.append(", balanceInCents='").append(balanceInCents).append('\''); 238 sb.append(", invoiceNumber='").append(invoiceNumber).append('\''); 239 sb.append(", gifterAccount='").append(gifterAccount).append('\''); 240 sb.append(", delivery='").append(delivery).append('\''); 241 sb.append(", createdAt='").append(createdAt).append('\''); 242 sb.append(", updatedAt='").append(updatedAt).append('\''); 243 sb.append(", redeemedAt='").append(redeemedAt).append('\''); 244 sb.append(", canceledAt='").append(canceledAt).append('\''); 245 sb.append('}'); 246 return sb.toString(); 247 } 248 249 @Override 250 public boolean equals(final Object o) { 251 if (this == o) return true; 252 if (o == null || getClass() != o.getClass()) return false; 253 254 final GiftCard that = (GiftCard) o; 255 256 if (productCode != null ? !productCode.equals(that.productCode) : that.productCode != null) { 257 return false; 258 } 259 if (currency != null ? !currency.equals(that.currency) : that.currency != null) { 260 return false; 261 } 262 if (id != null ? !id.equals(that.id) : that.id != null) { 263 return false; 264 } 265 if (redemptionCode != null ? !redemptionCode.equals(that.redemptionCode) : that.redemptionCode != null) { 266 return false; 267 } 268 if (gifterAccountCode != null ? !gifterAccountCode.equals(that.gifterAccountCode) : that.gifterAccountCode != null) { 269 return false; 270 } 271 if (recipientAccountCode != null ? !recipientAccountCode.equals(that.recipientAccountCode) : that.recipientAccountCode != null) { 272 return false; 273 } 274 if (unitAmountInCents != null ? !unitAmountInCents.equals(that.unitAmountInCents) : that.unitAmountInCents != null) { 275 return false; 276 } 277 if (balanceInCents != null ? !balanceInCents.equals(that.balanceInCents) : that.balanceInCents != null) { 278 return false; 279 } 280 if (invoiceNumber != null ? !invoiceNumber.equals(that.invoiceNumber) : that.invoiceNumber != null) { 281 return false; 282 } 283 if (gifterAccount != null ? !gifterAccount.equals(that.gifterAccount) : that.gifterAccount != null) { 284 return false; 285 } 286 if (delivery != null ? !delivery.equals(that.delivery) : that.delivery != null) { 287 return false; 288 } 289 if (createdAt != null ? createdAt.compareTo(that.createdAt) != 0 : that.createdAt != null) { 290 return false; 291 } 292 if (updatedAt != null ? updatedAt.compareTo(that.updatedAt) != 0 : that.updatedAt != null) { 293 return false; 294 } 295 if (redeemedAt != null ? redeemedAt.compareTo(that.redeemedAt) != 0 : that.redeemedAt != null) { 296 return false; 297 } 298 if (canceledAt != null ? canceledAt.compareTo(that.canceledAt) != 0 : that.canceledAt != null) { 299 return false; 300 } 301 302 return true; 303 } 304 305 @Override 306 public int hashCode() { 307 return Objects.hashCode( 308 productCode, 309 currency, 310 id, 311 redemptionCode, 312 gifterAccountCode, 313 recipientAccountCode, 314 unitAmountInCents, 315 balanceInCents, 316 invoiceNumber, 317 gifterAccount, 318 delivery, 319 createdAt, 320 updatedAt, 321 redeemedAt, 322 deliveredAt, 323 canceledAt 324 ); 325 } 326}