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 org.joda.time.DateTime; 020 021import javax.xml.bind.annotation.XmlElement; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlTransient; 024 025@XmlRootElement(name = "redemption") 026public class Redemption extends RecurlyObject { 027 028 @XmlTransient 029 public static final String REDEEM_RESOURCE = "/redeem"; 030 031 @XmlTransient 032 public static final String REDEMPTION_RESOURCE = "/redemption"; 033 034 @XmlElement(name = "account_code") 035 private String accountCode; 036 037 @XmlElement(name = "coupon") 038 private Coupon coupon; 039 040 @XmlElement(name = "account") 041 private Account account; 042 043 @XmlElement(name = "single_use") 044 private Boolean singleUse; 045 046 @XmlElement(name = "total_discounted_in_cents") 047 private Integer totalDiscountedInCents; 048 049 @XmlElement(name = "currency") 050 private String currency; 051 052 @XmlElement(name = "state") 053 private String state; 054 055 @XmlElement(name = "created_at") 056 private DateTime createdAt; 057 058 public String getAccountCode() { 059 return accountCode; 060 } 061 062 public void setAccountCode(final Object accountCode) { 063 this.accountCode = stringOrNull(accountCode); 064 } 065 066 public Coupon getCoupon() { 067 if (coupon != null && coupon.getCouponCode() == null) { 068 coupon = fetch(coupon, Coupon.class); 069 } 070 return coupon; 071 } 072 073 public void setCoupon(final Coupon coupon) { 074 this.coupon = coupon; 075 } 076 077 public Account getAccount() { 078 if (account != null && account.getCreatedAt() == null) { 079 account = fetch(account, Account.class); 080 } 081 return account; 082 } 083 084 public void setAccount(final Account account) { 085 this.account = account; 086 } 087 088 public Boolean getSingleUse() { 089 return singleUse; 090 } 091 092 public void setSingleUse(final Object singleUse) { 093 this.singleUse = booleanOrNull(singleUse); 094 } 095 096 public Integer getTotalDiscountedInCents() { 097 return totalDiscountedInCents; 098 } 099 100 public void setTotalDiscountedInCents(final Object totalDiscountedInCents) { 101 this.totalDiscountedInCents = integerOrNull(totalDiscountedInCents); 102 } 103 104 public String getCurrency() { 105 return currency; 106 } 107 108 public void setCurrency(final Object currency) { 109 this.currency = stringOrNull(currency); 110 } 111 112 public String getState() { 113 return state; 114 } 115 116 public void setState(final Object state) { 117 this.state = stringOrNull(state); 118 } 119 120 public DateTime getCreatedAt() { 121 return createdAt; 122 } 123 124 public void setCreatedAt(final Object createdAt) { 125 this.createdAt = dateTimeOrNull(createdAt); 126 } 127 128 @Override 129 public String toString() { 130 final StringBuilder sb = new StringBuilder(); 131 sb.append("Redemption"); 132 sb.append("{accountCode=").append(accountCode); 133 sb.append(", coupon=").append(coupon); 134 sb.append(", account=").append(account); 135 sb.append(", single_use=").append(singleUse); 136 sb.append(", totalDiscountedInCents=").append(totalDiscountedInCents); 137 sb.append(", currency='").append(currency).append('\''); 138 sb.append(", state='").append(state).append('\''); 139 sb.append(", createdAt=").append(createdAt); 140 sb.append('}'); 141 return sb.toString(); 142 } 143 144 @Override 145 public boolean equals(final Object o) { 146 if (this == o) { 147 return true; 148 } 149 if (o == null || getClass() != o.getClass()) { 150 return false; 151 } 152 final Redemption that = (Redemption) o; 153 154 if (accountCode != null ? !accountCode.equals(that.accountCode) : that.accountCode != null) { 155 return false; 156 } 157 if (coupon != null ? !coupon.equals(that.coupon) : that.coupon != null) { 158 return false; 159 } 160 if (account != null ? !account.equals(that.account) : that.account != null) { 161 return false; 162 } 163 if (singleUse != null ? !singleUse.equals(that.singleUse) : that.singleUse != null) { 164 return false; 165 } 166 if (totalDiscountedInCents != null ? 167 !totalDiscountedInCents.equals(that.totalDiscountedInCents) : that.totalDiscountedInCents != null) { 168 return false; 169 } 170 if (currency != null ? !currency.equals(that.currency) : that.currency != null) { 171 return false; 172 } 173 if (state != null ? !state.equals(that.state) : that.state != null) { 174 return false; 175 } 176 if (createdAt != null ? !createdAt.equals(that.createdAt) : that.createdAt != null) { 177 return false; 178 } 179 return true; 180 } 181 182 @Override 183 public int hashCode() { 184 int result = accountCode != null ? accountCode.hashCode() : 0; 185 result = 31 * result + (coupon != null ? coupon.hashCode() : 0); 186 result = 31 * result + (account != null ? account.hashCode() : 0); 187 result = 31 * result + (singleUse != null ? singleUse.hashCode() : 0); 188 result = 31 * result + (totalDiscountedInCents != null ? totalDiscountedInCents.hashCode() : 0); 189 result = 31 * result + (currency != null ? currency.hashCode() : 0); 190 result = 31 * result + (state != null ? state.hashCode() : 0); 191 result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 192 return result; 193 } 194 195}