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 javax.xml.bind.annotation.XmlElement; 021import javax.xml.bind.annotation.XmlRootElement; 022import javax.xml.bind.annotation.XmlTransient; 023import javax.xml.bind.annotation.XmlAttribute; 024 025import com.google.common.base.Objects; 026import org.joda.time.DateTime; 027 028@XmlRootElement(name = "billing_info") 029public class BillingInfo extends RecurlyObject { 030 031 @XmlTransient 032 public static final String BILLING_INFO_RESOURCE = "/billing_info"; 033 034 @XmlAttribute(name = "type") 035 private String type; 036 037 @XmlElement(name = "account") 038 private Account account; 039 040 @XmlElement(name = "name_on_account") 041 private String nameOnAccount; 042 043 @XmlElement(name = "first_name") 044 private String firstName; 045 046 @XmlElement(name = "last_name") 047 private String lastName; 048 049 @XmlElement(name = "company") 050 private String company; 051 052 @XmlElement(name = "address1") 053 private String address1; 054 055 @XmlElement(name = "address2") 056 private String address2; 057 058 @XmlElement(name = "city") 059 private String city; 060 061 @XmlElement(name = "state") 062 private String state; 063 064 @XmlElement(name = "zip") 065 private String zip; 066 067 @XmlElement(name = "country") 068 private String country; 069 070 @XmlElement(name = "phone") 071 private String phone; 072 073 @XmlElement(name = "vat_number") 074 private String vatNumber; 075 076 @XmlElement(name = "ip_address") 077 private String ipAddress; 078 079 @XmlElement(name = "ip_address_country") 080 private String ipAddressCountry; 081 082 @XmlElement(name = "account_type") 083 private String accountType; 084 085 @XmlElement(name = "card_type") 086 private String cardType; 087 088 @XmlElement(name = "year") 089 private Integer year; 090 091 @XmlElement(name = "month") 092 private Integer month; 093 094 @XmlElement(name = "first_six") 095 private String firstSix; 096 097 @XmlElement(name = "last_four") 098 private String lastFour; 099 100 @XmlElement(name = "number") 101 private String number; 102 103 @XmlElement(name = "routing_number") 104 private String routingNumber; 105 106 @XmlElement(name = "account_number") 107 private String accountNumber; 108 109 @XmlElement(name = "verification_value") 110 private String verificationValue; 111 112 @XmlElement(name = "token_id") 113 private String tokenId; 114 115 @XmlElement(name = "currency") 116 private String currency; 117 118 @XmlElement(name = "geo_code") 119 private String geoCode; 120 121 @XmlElement(name = "updated_at") 122 private DateTime updatedAt; 123 124 @XmlElement(name = "external_hpp_type") 125 private String externalHppType; 126 127 @XmlElement(name = "gateway_token") 128 private String gatewayToken; 129 130 @XmlElement(name = "gateway_code") 131 private String gatewayCode; 132 133 @XmlElement(name = "amazon_billing_agreement_id") 134 private String amazonBillingAgreementId; 135 136 @XmlElement(name = "amazon_region") 137 private String amazonRegion; 138 139 @XmlElement(name = "three_d_secure_action_result_token_id") 140 private String threeDSecureActionResultTokenId; 141 142 @XmlElement(name = "transaction_type") 143 private String transactionType; 144 145 public String getType() { 146 return type; 147 } 148 149 protected void setType(final Object type) { 150 this.type = stringOrNull(type); 151 } 152 153 /** 154 * Account object associated to this BillingInfo 155 * <p> 156 * Note: when fetching a BillingInfo object from Recurly, the account object is not guaranteed to be populated. 157 * 158 * @return account object 159 */ 160 public Account getAccount() { 161 if (account != null && account.getCreatedAt() == null) { 162 account = fetch(account, Account.class); 163 } 164 return account; 165 } 166 167 /** 168 * @deprecated Please do not attach an account to a BillingInfo object. Pass the account code into {@link com.ning.billing.recurly.RecurlyClient#createOrUpdateBillingInfo(String, BillingInfo)} 169 * @param account 170 */ 171 @Deprecated 172 public void setAccount(final Account account) { 173 this.account = account; 174 } 175 176 public String getNameOnAccount() { 177 return nameOnAccount; 178 } 179 180 public void setNameOnAccount(final Object nameOnAccount) { 181 this.nameOnAccount = stringOrNull(nameOnAccount); 182 } 183 184 public String getFirstName() { 185 return firstName; 186 } 187 188 public void setFirstName(final Object firstName) { 189 this.firstName = stringOrNull(firstName); 190 } 191 192 public String getLastName() { 193 return lastName; 194 } 195 196 public void setLastName(final Object lastName) { 197 this.lastName = stringOrNull(lastName); 198 } 199 200 public String getCompany() { 201 return company; 202 } 203 204 public void setCompany(final Object company) { 205 this.company = stringOrNull(company); 206 } 207 208 public String getAddress1() { 209 return address1; 210 } 211 212 public void setAddress1(final Object address1) { 213 this.address1 = stringOrNull(address1); 214 } 215 216 public String getAddress2() { 217 return address2; 218 } 219 220 public void setAddress2(final Object address2) { 221 this.address2 = stringOrNull(address2); 222 } 223 224 public String getCity() { 225 return city; 226 } 227 228 public void setCity(final Object city) { 229 this.city = stringOrNull(city); 230 } 231 232 public String getState() { 233 return state; 234 } 235 236 public void setState(final Object state) { 237 this.state = stringOrNull(state); 238 } 239 240 public String getZip() { 241 return zip; 242 } 243 244 public void setZip(final Object zip) { 245 this.zip = stringOrNull(zip); 246 } 247 248 public String getCountry() { 249 return country; 250 } 251 252 public void setCountry(final Object country) { 253 this.country = stringOrNull(country); 254 } 255 256 public String getPhone() { 257 return phone; 258 } 259 260 public void setPhone(final Object phone) { 261 this.phone = stringOrNull(phone); 262 } 263 264 public String getVatNumber() { 265 return vatNumber; 266 } 267 268 public void setVatNumber(final Object vatNumber) { 269 this.vatNumber = stringOrNull(vatNumber); 270 } 271 272 public String getIpAddress() { 273 return ipAddress; 274 } 275 276 public void setIpAddress(final Object ipAddress) { 277 this.ipAddress = stringOrNull(ipAddress); 278 } 279 280 public String getIpAddressCountry() { 281 return ipAddressCountry; 282 } 283 284 public void setIpAddressCountry(final Object ipAddressCountry) { 285 this.ipAddressCountry = stringOrNull(ipAddressCountry); 286 } 287 288 public String getAccountType() { 289 return accountType; 290 } 291 292 public void setAccountType(final Object accountType) { 293 this.accountType = stringOrNull(accountType); 294 } 295 296 public String getCardType() { 297 return cardType; 298 } 299 300 public void setCardType(final Object cardType) { 301 this.cardType = stringOrNull(cardType); 302 } 303 304 public Integer getYear() { 305 return year; 306 } 307 308 public void setYear(final Object year) { 309 this.year = integerOrNull(year); 310 } 311 312 public Integer getMonth() { 313 return month; 314 } 315 316 public void setMonth(final Object month) { 317 this.month = integerOrNull(month); 318 } 319 320 public String getFirstSix() { 321 return firstSix; 322 } 323 324 public void setFirstSix(final Object firstSix) { 325 this.firstSix = stringOrNull(firstSix); 326 } 327 328 public String getLastFour() { 329 return lastFour; 330 } 331 332 public void setLastFour(final Object lastFour) { 333 this.lastFour = stringOrNull(lastFour); 334 } 335 336 public String getRoutingNumber() { 337 return routingNumber; 338 } 339 340 public void setRoutingNumber(final Object routingNumber) { 341 this.routingNumber = stringOrNull(routingNumber); 342 } 343 344 public String getAccountNumber() { 345 return accountNumber; 346 } 347 348 public void setAccountNumber(final Object accountNumber) { 349 this.accountNumber = stringOrNull(accountNumber); 350 } 351 352 public String getNumber() { 353 return number; 354 } 355 356 public void setNumber(final Object number) { 357 this.number = stringOrNull(number); 358 } 359 360 public String getVerificationValue() { 361 return verificationValue; 362 } 363 364 public void setVerificationValue(final Object verificationValue) { 365 this.verificationValue = stringOrNull(verificationValue); 366 } 367 368 public String getTokenId() { 369 return tokenId; 370 } 371 372 public void setTokenId(final String tokenId) { 373 this.tokenId = tokenId; 374 } 375 376 public String getCurrency() { 377 return currency; 378 } 379 380 public void setCurrency(final Object currency) { 381 this.currency = stringOrNull(currency); 382 } 383 384 public String getGeoCode() { 385 return geoCode; 386 } 387 388 public void setGeoCode(final Object geoCode) { 389 this.geoCode = stringOrNull(geoCode); 390 } 391 392 public DateTime getUpdatedAt() { 393 return updatedAt; 394 } 395 396 public void setUpdatedAt(final Object updatedAt) { 397 this.updatedAt = dateTimeOrNull(updatedAt); 398 } 399 400 public String getExternalHppType() { 401 return externalHppType; 402 } 403 404 public void setExternalHppType(final Object externalHppType) { 405 this.externalHppType = stringOrNull(externalHppType); 406 } 407 408 public String getGatewayToken() { 409 return gatewayToken; 410 } 411 412 public void setGatewayToken(final Object gatewayToken) { 413 this.gatewayToken = stringOrNull(gatewayToken); 414 } 415 416 public String getGatewayCode() { 417 return gatewayCode; 418 } 419 420 public void setGatewayCode(final Object gatewayCode) { 421 this.gatewayCode = stringOrNull(gatewayCode); 422 } 423 424 public String getAmazonBillingAgreementId() { 425 return amazonBillingAgreementId; 426 } 427 428 public void setAmazonBillingAgreementId(final Object amazonBillingAgreementId) { 429 this.amazonBillingAgreementId = stringOrNull(amazonBillingAgreementId); 430 } 431 432 public String getAmazonRegion() { 433 return amazonRegion; 434 } 435 436 public void setAmazonRegion(final Object amazonRegion) { 437 this.amazonRegion = stringOrNull(amazonRegion); 438 } 439 440 public String getThreeDSecureActionResultTokenId() { 441 return threeDSecureActionResultTokenId; 442 } 443 444 public void setThreeDSecureActionResultTokenId(final Object threeDSecureActionResultTokenId) { 445 this.threeDSecureActionResultTokenId = stringOrNull(threeDSecureActionResultTokenId); 446 } 447 448 public String getTransactionType() { 449 return transactionType; 450 } 451 452 public void setTransactionType(final Object transactionType) { 453 this.transactionType = stringOrNull(transactionType); 454 } 455 456 @Override 457 public String toString() { 458 final StringBuilder sb = new StringBuilder(); 459 sb.append("BillingInfo"); 460 461 // Prevent infinite loop when printing account. 462 // See https://github.com/killbilling/recurly-java-library/issues/326 463 if (account != null && account.getBillingInfo().equals(this)) { 464 sb.append("{account='").append(account.getAccountCode()).append('\''); 465 } 466 else { 467 sb.append("{account='").append(account).append('\''); 468 } 469 470 sb.append(", type='").append(type).append('\''); 471 sb.append(", nameOnAccount='").append(nameOnAccount).append('\''); 472 sb.append(", firstName='").append(firstName).append('\''); 473 sb.append(", lastName='").append(lastName).append('\''); 474 sb.append(", company='").append(company).append('\''); 475 sb.append(", address1='").append(address1).append('\''); 476 sb.append(", address2='").append(address2).append('\''); 477 sb.append(", city='").append(city).append('\''); 478 sb.append(", state='").append(state).append('\''); 479 sb.append(", zip='").append(zip).append('\''); 480 sb.append(", country='").append(country).append('\''); 481 sb.append(", phone='").append(phone).append('\''); 482 sb.append(", vatNumber='").append(vatNumber).append('\''); 483 sb.append(", ipAddress='").append(ipAddress).append('\''); 484 sb.append(", ipAddressCountry='").append(ipAddressCountry).append('\''); 485 sb.append(", accountType='").append(accountType).append('\''); 486 sb.append(", cardType='").append(cardType).append('\''); 487 sb.append(", year=").append(year); 488 sb.append(", month=").append(month); 489 sb.append(", firstSix='").append(firstSix).append('\''); 490 sb.append(", lastFour='").append(lastFour).append('\''); 491 sb.append(", routingNumber='").append(routingNumber).append('\''); 492 sb.append(", geoCode='").append(geoCode).append('\''); 493 sb.append(", updatedAt='").append(updatedAt).append('\''); 494 sb.append(", externalHppType='").append(externalHppType).append('\''); 495 sb.append(", gatewayToken='").append(gatewayToken).append('\''); 496 sb.append(", gatewayCode='").append(gatewayCode).append('\''); 497 sb.append(", amazonBillingAgreementId='").append(amazonBillingAgreementId).append('\''); 498 sb.append(", amazonRegion='").append(amazonRegion).append('\''); 499 sb.append(", threeDSecureActionResultTokenId='").append(threeDSecureActionResultTokenId).append('\''); 500 sb.append('}'); 501 return sb.toString(); 502 } 503 504 @Override 505 public boolean equals(final Object o) { 506 if (this == o) return true; 507 if (o == null || getClass() != o.getClass()) return false; 508 509 final BillingInfo that = (BillingInfo) o; 510 511 if (account != null ? !account.equals(that.account) : that.account != null) { 512 return false; 513 } 514 if (nameOnAccount != null ? !nameOnAccount.equals(that.nameOnAccount) : that.nameOnAccount != null) { 515 return false; 516 } 517 if (address1 != null ? !address1.equals(that.address1) : that.address1 != null) { 518 return false; 519 } 520 if (address2 != null ? !address2.equals(that.address2) : that.address2 != null) { 521 return false; 522 } 523 if (cardType != null ? !cardType.equals(that.cardType) : that.cardType != null) { 524 return false; 525 } 526 if (city != null ? !city.equals(that.city) : that.city != null) { 527 return false; 528 } 529 if (company != null ? !company.equals(that.company) : that.company != null) { 530 return false; 531 } 532 if (country != null ? !country.equals(that.country) : that.country != null) { 533 return false; 534 } 535 if (firstName != null ? !firstName.equals(that.firstName) : that.firstName != null) { 536 return false; 537 } 538 if (firstSix != null ? !firstSix.equals(that.firstSix) : that.firstSix != null) { 539 return false; 540 } 541 if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null) { 542 return false; 543 } 544 if (ipAddressCountry != null ? !ipAddressCountry.equals(that.ipAddressCountry) : that.ipAddressCountry != null) { 545 return false; 546 } 547 if (accountType != null ? !accountType.equals(that.accountType) : that.accountType != null) { 548 return false; 549 } 550 if (lastFour != null ? !lastFour.equals(that.lastFour) : that.lastFour != null) { 551 return false; 552 } 553 if (routingNumber != null ? !routingNumber.equals(that.routingNumber) : that.routingNumber != null) { 554 return false; 555 } 556 if (accountNumber != null ? !accountNumber.equals(that.accountNumber) : that.accountNumber != null) { 557 return false; 558 } 559 if (number != null ? !number.equals(that.number) : that.number != null) { 560 return false; 561 } 562 if (lastName != null ? !lastName.equals(that.lastName) : that.lastName != null) { 563 return false; 564 } 565 if (month != null ? !month.equals(that.month) : that.month != null) { 566 return false; 567 } 568 if (phone != null ? !phone.equals(that.phone) : that.phone != null) { 569 return false; 570 } 571 if (state != null ? !state.equals(that.state) : that.state != null) { 572 return false; 573 } 574 if (type != null ? !type.equals(that.type) : that.type != null) { 575 return false; 576 } 577 if (vatNumber != null ? !vatNumber.equals(that.vatNumber) : that.vatNumber != null) { 578 return false; 579 } 580 if (year != null ? !year.equals(that.year) : that.year != null) { 581 return false; 582 } 583 if (zip != null ? !zip.equals(that.zip) : that.zip != null) { 584 return false; 585 } 586 if (geoCode != null ? !geoCode.equals(that.geoCode) : that.geoCode != null) { 587 return false; 588 } 589 if (gatewayToken != null ? !gatewayToken.equals(that.gatewayToken) : that.gatewayToken != null) { 590 return false; 591 } 592 if (gatewayCode != null ? !gatewayCode.equals(that.gatewayCode) : that.gatewayCode != null) { 593 return false; 594 } 595 if (updatedAt != null ? updatedAt.compareTo(that.updatedAt) != 0 : that.updatedAt != null) { 596 return false; 597 } 598 if (externalHppType != null ? !externalHppType.equals(that.externalHppType) : that.externalHppType != null) { 599 return false; 600 } 601 if (amazonBillingAgreementId != null ? !amazonBillingAgreementId.equals(that.amazonBillingAgreementId) : that.amazonBillingAgreementId != null) { 602 return false; 603 } 604 if (amazonRegion != null ? !amazonRegion.equals(that.amazonRegion) : that.amazonRegion != null) { 605 return false; 606 } 607 if (threeDSecureActionResultTokenId != null ? !threeDSecureActionResultTokenId.equals(that.threeDSecureActionResultTokenId) : that.threeDSecureActionResultTokenId != null) { 608 return false; 609 } 610 if (transactionType != null ? !transactionType.equals(that.transactionType) : that.transactionType != null) { 611 return false; 612 } 613 614 return true; 615 } 616 617 @Override 618 public int hashCode() { 619 return Objects.hashCode( 620 account, 621 nameOnAccount, 622 firstName, 623 lastName, 624 company, 625 address1, 626 address2, 627 city, 628 state, 629 zip, 630 country, 631 phone, 632 vatNumber, 633 ipAddress, 634 ipAddressCountry, 635 accountType, 636 cardType, 637 year, 638 month, 639 firstSix, 640 lastFour, 641 number, 642 routingNumber, 643 accountNumber, 644 updatedAt, 645 geoCode, 646 type, 647 externalHppType, 648 gatewayToken, 649 gatewayCode, 650 amazonBillingAgreementId, 651 amazonRegion, 652 threeDSecureActionResultTokenId, 653 transactionType 654 ); 655 } 656}