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;
021import javax.xml.bind.annotation.XmlTransient;
022
023@XmlRootElement(name = "billing_info")
024public class BillingInfo extends RecurlyObject {
025
026    @XmlTransient
027    public static final String BILLING_INFO_RESOURCE = "/billing_info";
028
029    @XmlElement(name = "account")
030    private Account account;
031
032    @XmlElement(name = "first_name")
033    private String firstName;
034
035    @XmlElement(name = "last_name")
036    private String lastName;
037
038    @XmlElement(name = "company")
039    private String company;
040
041    @XmlElement(name = "address1")
042    private String address1;
043
044    @XmlElement(name = "address2")
045    private String address2;
046
047    @XmlElement(name = "city")
048    private String city;
049
050    @XmlElement(name = "state")
051    private String state;
052
053    @XmlElement(name = "zip")
054    private String zip;
055
056    @XmlElement(name = "country")
057    private String country;
058
059    @XmlElement(name = "phone")
060    private String phone;
061
062    @XmlElement(name = "vat_number")
063    private String vatNumber;
064
065    @XmlElement(name = "ip_address")
066    private String ipAddress;
067
068    @XmlElement(name = "ip_address_country")
069    private String ipAddressCountry;
070
071    @XmlElement(name = "card_type")
072    private String cardType;
073
074    @XmlElement(name = "year")
075    private Integer year;
076
077    @XmlElement(name = "month")
078    private Integer month;
079
080    @XmlElement(name = "first_six")
081    private String firstSix;
082
083    @XmlElement(name = "last_four")
084    private String lastFour;
085
086    @XmlElement(name = "number")
087    private String number;
088
089    @XmlElement(name = "verification_value")
090    private String verificationValue;
091
092    @XmlElement(name = "token_id")
093    private String tokenId;
094
095
096    /**
097     * Account object associated to this BillingInfo
098     * <p/>
099     * Note: when fetching a BillingInfo object from Recurly, the account object is not guaranteed to be populated.
100     *
101     * @return account object
102     */
103    public Account getAccount() {
104        if (account != null && account.getCreatedAt() == null) {
105            account = fetch(account, Account.class);
106        }
107        return account;
108    }
109
110    public void setAccount(final Account account) {
111        this.account = account;
112    }
113
114    public String getFirstName() {
115        return firstName;
116    }
117
118    public void setFirstName(final Object firstName) {
119        this.firstName = stringOrNull(firstName);
120    }
121
122    public String getLastName() {
123        return lastName;
124    }
125
126    public void setLastName(final Object lastName) {
127        this.lastName = stringOrNull(lastName);
128    }
129
130    public String getCompany() {
131        return company;
132    }
133
134    public void setCompany(final Object company) {
135        this.company = stringOrNull(company);
136    }
137
138    public String getAddress1() {
139        return address1;
140    }
141
142    public void setAddress1(final Object address1) {
143        this.address1 = stringOrNull(address1);
144    }
145
146    public String getAddress2() {
147        return address2;
148    }
149
150    public void setAddress2(final Object address2) {
151        this.address2 = stringOrNull(address2);
152    }
153
154    public String getCity() {
155        return city;
156    }
157
158    public void setCity(final Object city) {
159        this.city = stringOrNull(city);
160    }
161
162    public String getState() {
163        return state;
164    }
165
166    public void setState(final Object state) {
167        this.state = stringOrNull(state);
168    }
169
170    public String getZip() {
171        return zip;
172    }
173
174    public void setZip(final Object zip) {
175        this.zip = stringOrNull(zip);
176    }
177
178    public String getCountry() {
179        return country;
180    }
181
182    public void setCountry(final Object country) {
183        this.country = stringOrNull(country);
184    }
185
186    public String getPhone() {
187        return phone;
188    }
189
190    public void setPhone(final Object phone) {
191        this.phone = stringOrNull(phone);
192    }
193
194    public String getVatNumber() {
195        return vatNumber;
196    }
197
198    public void setVatNumber(final Object vatNumber) {
199        this.vatNumber = stringOrNull(vatNumber);
200    }
201
202    public String getIpAddress() {
203        return ipAddress;
204    }
205
206    public void setIpAddress(final Object ipAddress) {
207        this.ipAddress = stringOrNull(ipAddress);
208    }
209
210    public String getIpAddressCountry() {
211        return ipAddressCountry;
212    }
213
214    public void setIpAddressCountry(final Object ipAddressCountry) {
215        this.ipAddressCountry = stringOrNull(ipAddressCountry);
216    }
217
218    public String getCardType() {
219        return cardType;
220    }
221
222    public void setCardType(final Object cardType) {
223        this.cardType = stringOrNull(cardType);
224    }
225
226    public Integer getYear() {
227        return year;
228    }
229
230    public void setYear(final Object year) {
231        this.year = integerOrNull(year);
232    }
233
234    public Integer getMonth() {
235        return month;
236    }
237
238    public void setMonth(final Object month) {
239        this.month = integerOrNull(month);
240    }
241
242    public String getFirstSix() {
243        return firstSix;
244    }
245
246    public void setFirstSix(final Object firstSix) {
247        this.firstSix = stringOrNull(firstSix);
248    }
249
250    public String getLastFour() {
251        return lastFour;
252    }
253
254    public void setLastFour(final Object lastFour) {
255        this.lastFour = stringOrNull(lastFour);
256    }
257
258    public String getNumber() {
259        return number;
260    }
261
262    public void setNumber(final Object number) {
263        this.number = stringOrNull(number);
264    }
265
266    public String getVerificationValue() {
267        return verificationValue;
268    }
269
270    public void setVerificationValue(final Object verificationValue) {
271        this.verificationValue = stringOrNull(verificationValue);
272    }
273
274    public String getTokenId(){
275        return tokenId;
276    }
277
278    public void setTokenId(final String tokenId){
279        this.tokenId = tokenId;
280    }
281
282    @Override
283    public String toString() {
284        final StringBuilder sb = new StringBuilder();
285        sb.append("BillingInfo");
286        sb.append("{account='").append(account).append('\'');
287        sb.append(", firstName='").append(firstName).append('\'');
288        sb.append(", lastName='").append(lastName).append('\'');
289        sb.append(", company='").append(company).append('\'');
290        sb.append(", address1='").append(address1).append('\'');
291        sb.append(", address2='").append(address2).append('\'');
292        sb.append(", city='").append(city).append('\'');
293        sb.append(", state='").append(state).append('\'');
294        sb.append(", zip='").append(zip).append('\'');
295        sb.append(", country='").append(country).append('\'');
296        sb.append(", phone='").append(phone).append('\'');
297        sb.append(", vatNumber='").append(vatNumber).append('\'');
298        sb.append(", ipAddress='").append(ipAddress).append('\'');
299        sb.append(", ipAddressCountry='").append(ipAddressCountry).append('\'');
300        sb.append(", cardType='").append(cardType).append('\'');
301        sb.append(", year=").append(year);
302        sb.append(", month=").append(month);
303        sb.append(", firstSix='").append(firstSix).append('\'');
304        sb.append(", lastFour='").append(lastFour).append('\'');
305        sb.append('}');
306        return sb.toString();
307    }
308
309    @Override
310    public boolean equals(final Object o) {
311        if (this == o) {
312            return true;
313        }
314        if (o == null || getClass() != o.getClass()) {
315            return false;
316        }
317
318        final BillingInfo that = (BillingInfo) o;
319
320        if (account != null ? !account.equals(that.account) : that.account != null) {
321            return false;
322        }
323        if (address1 != null ? !address1.equals(that.address1) : that.address1 != null) {
324            return false;
325        }
326        if (address2 != null ? !address2.equals(that.address2) : that.address2 != null) {
327            return false;
328        }
329        if (cardType != null ? !cardType.equals(that.cardType) : that.cardType != null) {
330            return false;
331        }
332        if (city != null ? !city.equals(that.city) : that.city != null) {
333            return false;
334        }
335        if (company != null ? !company.equals(that.company) : that.company != null) {
336            return false;
337        }
338        if (country != null ? !country.equals(that.country) : that.country != null) {
339            return false;
340        }
341        if (firstName != null ? !firstName.equals(that.firstName) : that.firstName != null) {
342            return false;
343        }
344        if (firstSix != null ? !firstSix.equals(that.firstSix) : that.firstSix != null) {
345            return false;
346        }
347        if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null) {
348            return false;
349        }
350        if (ipAddressCountry != null ? !ipAddressCountry.equals(that.ipAddressCountry) : that.ipAddressCountry != null) {
351            return false;
352        }
353        if (lastFour != null ? !lastFour.equals(that.lastFour) : that.lastFour != null) {
354            return false;
355        }
356        if (lastName != null ? !lastName.equals(that.lastName) : that.lastName != null) {
357            return false;
358        }
359        if (month != null ? !month.equals(that.month) : that.month != null) {
360            return false;
361        }
362        if (phone != null ? !phone.equals(that.phone) : that.phone != null) {
363            return false;
364        }
365        if (state != null ? !state.equals(that.state) : that.state != null) {
366            return false;
367        }
368        if (vatNumber != null ? !vatNumber.equals(that.vatNumber) : that.vatNumber != null) {
369            return false;
370        }
371        if (year != null ? !year.equals(that.year) : that.year != null) {
372            return false;
373        }
374        if (zip != null ? !zip.equals(that.zip) : that.zip != null) {
375            return false;
376        }
377
378        return true;
379    }
380
381    @Override
382    public int hashCode() {
383        int result = account != null ? account.hashCode() : 0;
384        result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
385        result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
386        result = 31 * result + (company != null ? company.hashCode() : 0);
387        result = 31 * result + (address1 != null ? address1.hashCode() : 0);
388        result = 31 * result + (address2 != null ? address2.hashCode() : 0);
389        result = 31 * result + (city != null ? city.hashCode() : 0);
390        result = 31 * result + (state != null ? state.hashCode() : 0);
391        result = 31 * result + (zip != null ? zip.hashCode() : 0);
392        result = 31 * result + (country != null ? country.hashCode() : 0);
393        result = 31 * result + (phone != null ? phone.hashCode() : 0);
394        result = 31 * result + (vatNumber != null ? vatNumber.hashCode() : 0);
395        result = 31 * result + (ipAddress != null ? ipAddress.hashCode() : 0);
396        result = 31 * result + (ipAddressCountry != null ? ipAddressCountry.hashCode() : 0);
397        result = 31 * result + (cardType != null ? cardType.hashCode() : 0);
398        result = 31 * result + (year != null ? year.hashCode() : 0);
399        result = 31 * result + (month != null ? month.hashCode() : 0);
400        result = 31 * result + (firstSix != null ? firstSix.hashCode() : 0);
401        result = 31 * result + (lastFour != null ? lastFour.hashCode() : 0);
402        return result;
403    }
404}