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 @XmlElement(name = "type") 035 private String type; 036 037 @XmlAttribute(name = "type") 038 private String attributeType; 039 040 @XmlElement(name = "account") 041 private Account account; 042 043 @XmlElement(name = "uuid") 044 private String uuid; 045 046 @XmlElement(name = "name_on_account") 047 private String nameOnAccount; 048 049 @XmlElement(name = "first_name") 050 private String firstName; 051 052 @XmlElement(name = "last_name") 053 private String lastName; 054 055 @XmlElement(name = "mandate_reference") 056 private String mandateReference; 057 058 @XmlElement(name = "company") 059 private String company; 060 061 @XmlElement(name = "address1") 062 private String address1; 063 064 @XmlElement(name = "address2") 065 private String address2; 066 067 @XmlElement(name = "city") 068 private String city; 069 070 @XmlElement(name = "state") 071 private String state; 072 073 @XmlElement(name = "zip") 074 private String zip; 075 076 @XmlElement(name = "country") 077 private String country; 078 079 @XmlElement(name = "phone") 080 private String phone; 081 082 @XmlElement(name = "vat_number") 083 private String vatNumber; 084 085 @XmlElement(name = "ip_address") 086 private String ipAddress; 087 088 @XmlElement(name = "ip_address_country") 089 private String ipAddressCountry; 090 091 @XmlElement(name = "account_type") 092 private String accountType; 093 094 @XmlElement(name = "card_type") 095 private String cardType; 096 097 @XmlElement(name = "year") 098 private Integer year; 099 100 @XmlElement(name = "month") 101 private Integer month; 102 103 @XmlElement(name = "first_six") 104 private String firstSix; 105 106 @XmlElement(name = "last_four") 107 private String lastFour; 108 109 @XmlElement(name = "number") 110 private String number; 111 112 @XmlElement(name = "routing_number") 113 private String routingNumber; 114 115 @XmlElement(name = "account_number") 116 private String accountNumber; 117 118 @XmlElement(name = "verification_value") 119 private String verificationValue; 120 121 @XmlElement(name = "token_id") 122 private String tokenId; 123 124 @XmlElement(name = "currency") 125 private String currency; 126 127 @XmlElement(name = "geo_code") 128 private String geoCode; 129 130 @XmlElement(name = "updated_at") 131 private DateTime updatedAt; 132 133 @XmlElement(name = "external_hpp_type") 134 private String externalHppType; 135 136 @XmlElement(name = "gateway_token") 137 private String gatewayToken; 138 139 @XmlElement(name = "gateway_code") 140 private String gatewayCode; 141 142 @XmlElement(name = "amazon_billing_agreement_id") 143 private String amazonBillingAgreementId; 144 145 @XmlElement(name = "amazon_region") 146 private String amazonRegion; 147 148 @XmlElement(name = "three_d_secure_action_result_token_id") 149 private String threeDSecureActionResultTokenId; 150 151 @XmlElement(name = "transaction_type") 152 private String transactionType; 153 154 @XmlElement(name = "iban") 155 private String iban; 156 157 @XmlElement(name = "last_two") 158 private String lastTwo; 159 160 @XmlElement(name = "sort_code") 161 private String sortCode; 162 163 @XmlElement(name = "bsb_code") 164 private String bsbCode; 165 166 @XmlElement(name = "tax_identifier") 167 private String taxIdentifier; 168 169 @XmlElement(name = "tax_identifier_type") 170 private String taxIdentifierType; 171 172 @XmlElement(name = "primary_payment_method") 173 private String primaryPaymentMethod; 174 175 @XmlElement(name = "backup_payment_method") 176 private String backupPaymentMethod; 177 178 public String getType() { 179 return this.type == null ? this.attributeType : this.type; 180 } 181 182 public void setType(final Object type) { 183 this.type = stringOrNull(type); 184 } 185 186 /** 187 * Account object associated to this BillingInfo 188 * <p> 189 * Note: when fetching a BillingInfo object from Recurly, the account object is not guaranteed to be populated. 190 * 191 * @return account object 192 */ 193 public Account getAccount() { 194 if (account != null && account.getCreatedAt() == null) { 195 account = fetch(account, Account.class); 196 } 197 return account; 198 } 199 200 /** 201 * @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)} 202 * @param account 203 */ 204 @Deprecated 205 public void setAccount(final Account account) { 206 this.account = account; 207 } 208 209 public String getNameOnAccount() { 210 return nameOnAccount; 211 } 212 213 public void setNameOnAccount(final Object nameOnAccount) { 214 this.nameOnAccount = stringOrNull(nameOnAccount); 215 } 216 217 public String getUuid() { 218 return uuid; 219 } 220 221 public void setUuid(final Object uuid) { 222 this.uuid = stringOrNull(uuid); 223 } 224 225 public String getFirstName() { 226 return firstName; 227 } 228 229 public void setFirstName(final Object firstName) { 230 this.firstName = stringOrNull(firstName); 231 } 232 233 public String getLastName() { 234 return lastName; 235 } 236 237 public void setLastName(final Object lastName) { 238 this.lastName = stringOrNull(lastName); 239 } 240 241 public String getMandateReference() { 242 return mandateReference; 243 } 244 245 public void setMandateReference(final Object mandateReference) { 246 this.mandateReference = stringOrNull(mandateReference); 247 } 248 249 public String getCompany() { 250 return company; 251 } 252 253 public void setCompany(final Object company) { 254 this.company = stringOrNull(company); 255 } 256 257 public String getAddress1() { 258 return address1; 259 } 260 261 public void setAddress1(final Object address1) { 262 this.address1 = stringOrNull(address1); 263 } 264 265 public String getAddress2() { 266 return address2; 267 } 268 269 public void setAddress2(final Object address2) { 270 this.address2 = stringOrNull(address2); 271 } 272 273 public String getCity() { 274 return city; 275 } 276 277 public void setCity(final Object city) { 278 this.city = stringOrNull(city); 279 } 280 281 public String getState() { 282 return state; 283 } 284 285 public void setState(final Object state) { 286 this.state = stringOrNull(state); 287 } 288 289 public String getZip() { 290 return zip; 291 } 292 293 public void setZip(final Object zip) { 294 this.zip = stringOrNull(zip); 295 } 296 297 public String getCountry() { 298 return country; 299 } 300 301 public void setCountry(final Object country) { 302 this.country = stringOrNull(country); 303 } 304 305 public String getPhone() { 306 return phone; 307 } 308 309 public void setPhone(final Object phone) { 310 this.phone = stringOrNull(phone); 311 } 312 313 public String getVatNumber() { 314 return vatNumber; 315 } 316 317 public void setVatNumber(final Object vatNumber) { 318 this.vatNumber = stringOrNull(vatNumber); 319 } 320 321 public String getIpAddress() { 322 return ipAddress; 323 } 324 325 public void setIpAddress(final Object ipAddress) { 326 this.ipAddress = stringOrNull(ipAddress); 327 } 328 329 public String getIpAddressCountry() { 330 return ipAddressCountry; 331 } 332 333 public void setIpAddressCountry(final Object ipAddressCountry) { 334 this.ipAddressCountry = stringOrNull(ipAddressCountry); 335 } 336 337 public String getAccountType() { 338 return accountType; 339 } 340 341 public void setAccountType(final Object accountType) { 342 this.accountType = stringOrNull(accountType); 343 } 344 345 public String getCardType() { 346 return cardType; 347 } 348 349 public void setCardType(final Object cardType) { 350 this.cardType = stringOrNull(cardType); 351 } 352 353 public Integer getYear() { 354 return year; 355 } 356 357 public void setYear(final Object year) { 358 this.year = integerOrNull(year); 359 } 360 361 public Integer getMonth() { 362 return month; 363 } 364 365 public void setMonth(final Object month) { 366 this.month = integerOrNull(month); 367 } 368 369 public String getFirstSix() { 370 return firstSix; 371 } 372 373 public void setFirstSix(final Object firstSix) { 374 this.firstSix = stringOrNull(firstSix); 375 } 376 377 public String getLastFour() { 378 return lastFour; 379 } 380 381 public void setLastFour(final Object lastFour) { 382 this.lastFour = stringOrNull(lastFour); 383 } 384 385 public String getRoutingNumber() { 386 return routingNumber; 387 } 388 389 public void setRoutingNumber(final Object routingNumber) { 390 this.routingNumber = stringOrNull(routingNumber); 391 } 392 393 public String getAccountNumber() { 394 return accountNumber; 395 } 396 397 public void setAccountNumber(final Object accountNumber) { 398 this.accountNumber = stringOrNull(accountNumber); 399 } 400 401 public String getNumber() { 402 return number; 403 } 404 405 public void setNumber(final Object number) { 406 this.number = stringOrNull(number); 407 } 408 409 public String getVerificationValue() { 410 return verificationValue; 411 } 412 413 public void setVerificationValue(final Object verificationValue) { 414 this.verificationValue = stringOrNull(verificationValue); 415 } 416 417 public String getTokenId() { 418 return tokenId; 419 } 420 421 public void setTokenId(final String tokenId) { 422 this.tokenId = tokenId; 423 } 424 425 public String getCurrency() { 426 return currency; 427 } 428 429 public void setCurrency(final Object currency) { 430 this.currency = stringOrNull(currency); 431 } 432 433 public String getGeoCode() { 434 return geoCode; 435 } 436 437 public void setGeoCode(final Object geoCode) { 438 this.geoCode = stringOrNull(geoCode); 439 } 440 441 public DateTime getUpdatedAt() { 442 return updatedAt; 443 } 444 445 public void setUpdatedAt(final Object updatedAt) { 446 this.updatedAt = dateTimeOrNull(updatedAt); 447 } 448 449 public String getExternalHppType() { 450 return externalHppType; 451 } 452 453 public void setExternalHppType(final Object externalHppType) { 454 this.externalHppType = stringOrNull(externalHppType); 455 } 456 457 public String getGatewayToken() { 458 return gatewayToken; 459 } 460 461 public void setGatewayToken(final Object gatewayToken) { 462 this.gatewayToken = stringOrNull(gatewayToken); 463 } 464 465 public String getGatewayCode() { 466 return gatewayCode; 467 } 468 469 public void setGatewayCode(final Object gatewayCode) { 470 this.gatewayCode = stringOrNull(gatewayCode); 471 } 472 473 public String getAmazonBillingAgreementId() { 474 return amazonBillingAgreementId; 475 } 476 477 public void setAmazonBillingAgreementId(final Object amazonBillingAgreementId) { 478 this.amazonBillingAgreementId = stringOrNull(amazonBillingAgreementId); 479 } 480 481 public String getAmazonRegion() { 482 return amazonRegion; 483 } 484 485 public void setAmazonRegion(final Object amazonRegion) { 486 this.amazonRegion = stringOrNull(amazonRegion); 487 } 488 489 public String getThreeDSecureActionResultTokenId() { 490 return threeDSecureActionResultTokenId; 491 } 492 493 public void setThreeDSecureActionResultTokenId(final Object threeDSecureActionResultTokenId) { 494 this.threeDSecureActionResultTokenId = stringOrNull(threeDSecureActionResultTokenId); 495 } 496 497 public String getTransactionType() { 498 return transactionType; 499 } 500 501 public void setTransactionType(final Object transactionType) { 502 this.transactionType = stringOrNull(transactionType); 503 } 504 505 public String getIban() { 506 return iban; 507 } 508 509 public void setIban(final Object iban) { 510 this.iban = stringOrNull(iban); 511 } 512 513 public String getLastTwo() { 514 return lastTwo; 515 } 516 517 public void setLastTwo(final Object lastTwo) { 518 this.lastTwo = stringOrNull(lastTwo); 519 } 520 521 public String getSortCode() { 522 return sortCode; 523 } 524 525 public void setSortCode(final Object sortCode) { 526 this.sortCode = stringOrNull(sortCode); 527 } 528 529 public String getBsbCode() { 530 return bsbCode; 531 } 532 533 public void setBsbCode(final Object bsbCode) { 534 this.bsbCode = stringOrNull(bsbCode); 535 } 536 537 public String getTaxIdentifier() { 538 return taxIdentifier; 539 } 540 541 public void setTaxIdentifier(final Object taxIdentifier) { 542 this.taxIdentifier = stringOrNull(taxIdentifier); 543 } 544 545 public String getTaxIdentifierType() { 546 return taxIdentifierType; 547 } 548 549 public void setTaxIdentifierType(final Object taxIdentifierType) { 550 this.taxIdentifierType = stringOrNull(taxIdentifierType); 551 } 552 553 public String getPrimaryPaymentMethod() { 554 return primaryPaymentMethod; 555 } 556 557 public void setPrimaryPaymentMethod(final Object primaryPaymentMethod) { 558 this.primaryPaymentMethod = stringOrNull(primaryPaymentMethod); 559 } 560 561 public String getBackupPaymentMethod() { 562 return backupPaymentMethod; 563 } 564 565 public void setBackupPaymentMethod(final Object backupPaymentMethod) { 566 this.backupPaymentMethod = stringOrNull(backupPaymentMethod); 567 } 568 @Override 569 public String toString() { 570 final StringBuilder sb = new StringBuilder(); 571 sb.append("BillingInfo"); 572 573 // Prevent infinite loop when printing account. 574 // See https://github.com/killbilling/recurly-java-library/issues/326 575 // Prevent Null Pointer Exception when printing updated billing info 576 // See https://github.com/killbilling/recurly-java-library/issues/405 577 Account account = getAccount(); 578 if (account != null && account.getBillingInfo() != null && this.getHref() != null 579 && this.getHref().equals(account.getBillingInfo().getHref())) { 580 sb.append("{account='").append(account.getAccountCode()).append('\''); 581 } else { 582 sb.append("{account='").append(account).append('\''); 583 } 584 585 sb.append(", type='").append(type).append('\''); 586 sb.append(", nameOnAccount='").append(nameOnAccount).append('\''); 587 sb.append(", uuid='").append(uuid); 588 sb.append(", firstName='").append(firstName).append('\''); 589 sb.append(", lastName='").append(lastName).append('\''); 590 sb.append(", mandateReference='").append(mandateReference).append('\''); 591 sb.append(", company='").append(company).append('\''); 592 sb.append(", address1='").append(address1).append('\''); 593 sb.append(", address2='").append(address2).append('\''); 594 sb.append(", city='").append(city).append('\''); 595 sb.append(", state='").append(state).append('\''); 596 sb.append(", zip='").append(zip).append('\''); 597 sb.append(", country='").append(country).append('\''); 598 sb.append(", phone='").append(phone).append('\''); 599 sb.append(", vatNumber='").append(vatNumber).append('\''); 600 sb.append(", ipAddress='").append(ipAddress).append('\''); 601 sb.append(", ipAddressCountry='").append(ipAddressCountry).append('\''); 602 sb.append(", accountType='").append(accountType).append('\''); 603 sb.append(", cardType='").append(cardType).append('\''); 604 sb.append(", year=").append(year); 605 sb.append(", month=").append(month); 606 sb.append(", firstSix='").append(firstSix).append('\''); 607 sb.append(", lastFour='").append(lastFour).append('\''); 608 sb.append(", routingNumber='").append(routingNumber).append('\''); 609 sb.append(", geoCode='").append(geoCode).append('\''); 610 sb.append(", updatedAt='").append(updatedAt).append('\''); 611 sb.append(", externalHppType='").append(externalHppType).append('\''); 612 sb.append(", gatewayToken='").append(gatewayToken).append('\''); 613 sb.append(", gatewayCode='").append(gatewayCode).append('\''); 614 sb.append(", amazonBillingAgreementId='").append(amazonBillingAgreementId).append('\''); 615 sb.append(", amazonRegion='").append(amazonRegion).append('\''); 616 sb.append(", threeDSecureActionResultTokenId='").append(threeDSecureActionResultTokenId).append('\''); 617 sb.append(", iban='").append(iban).append('\''); 618 sb.append(", lastTwo='").append(lastTwo).append('\''); 619 sb.append(", sortCode='").append(sortCode).append('\''); 620 sb.append(", bsbCode='").append(bsbCode).append('\''); 621 sb.append(", taxIdentifier='").append(taxIdentifier).append('\''); 622 sb.append(", taxIdentifierType='").append(taxIdentifierType).append('\''); 623 sb.append(", primaryPaymentMethod='").append(primaryPaymentMethod).append('\''); 624 sb.append(", backupPaymentMethod='").append(backupPaymentMethod).append('\''); 625 sb.append('}'); 626 return sb.toString(); 627 } 628 629 @Override 630 public boolean equals(final Object o) { 631 if (this == o) return true; 632 if (o == null || getClass() != o.getClass()) return false; 633 634 final BillingInfo that = (BillingInfo) o; 635 636 if (account != null ? !account.equals(that.account) : that.account != null) { 637 return false; 638 } 639 if (nameOnAccount != null ? !nameOnAccount.equals(that.nameOnAccount) : that.nameOnAccount != null) { 640 return false; 641 } 642 if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) { 643 return false; 644 } 645 if (address1 != null ? !address1.equals(that.address1) : that.address1 != null) { 646 return false; 647 } 648 if (address2 != null ? !address2.equals(that.address2) : that.address2 != null) { 649 return false; 650 } 651 if (cardType != null ? !cardType.equals(that.cardType) : that.cardType != null) { 652 return false; 653 } 654 if (city != null ? !city.equals(that.city) : that.city != null) { 655 return false; 656 } 657 if (company != null ? !company.equals(that.company) : that.company != null) { 658 return false; 659 } 660 if (country != null ? !country.equals(that.country) : that.country != null) { 661 return false; 662 } 663 if (firstName != null ? !firstName.equals(that.firstName) : that.firstName != null) { 664 return false; 665 } 666 if (mandateReference != null ? !mandateReference.equals(that.mandateReference) : that.mandateReference != null) { 667 return false; 668 } 669 if (firstSix != null ? !firstSix.equals(that.firstSix) : that.firstSix != null) { 670 return false; 671 } 672 if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null) { 673 return false; 674 } 675 if (ipAddressCountry != null ? !ipAddressCountry.equals(that.ipAddressCountry) : that.ipAddressCountry != null) { 676 return false; 677 } 678 if (accountType != null ? !accountType.equals(that.accountType) : that.accountType != null) { 679 return false; 680 } 681 if (lastFour != null ? !lastFour.equals(that.lastFour) : that.lastFour != null) { 682 return false; 683 } 684 if (routingNumber != null ? !routingNumber.equals(that.routingNumber) : that.routingNumber != null) { 685 return false; 686 } 687 if (accountNumber != null ? !accountNumber.equals(that.accountNumber) : that.accountNumber != null) { 688 return false; 689 } 690 if (number != null ? !number.equals(that.number) : that.number != null) { 691 return false; 692 } 693 if (lastName != null ? !lastName.equals(that.lastName) : that.lastName != null) { 694 return false; 695 } 696 if (month != null ? !month.equals(that.month) : that.month != null) { 697 return false; 698 } 699 if (phone != null ? !phone.equals(that.phone) : that.phone != null) { 700 return false; 701 } 702 if (state != null ? !state.equals(that.state) : that.state != null) { 703 return false; 704 } 705 if (type != null ? !type.equals(that.type) : that.type != null) { 706 return false; 707 } 708 if (vatNumber != null ? !vatNumber.equals(that.vatNumber) : that.vatNumber != null) { 709 return false; 710 } 711 if (year != null ? !year.equals(that.year) : that.year != null) { 712 return false; 713 } 714 if (zip != null ? !zip.equals(that.zip) : that.zip != null) { 715 return false; 716 } 717 if (geoCode != null ? !geoCode.equals(that.geoCode) : that.geoCode != null) { 718 return false; 719 } 720 if (gatewayToken != null ? !gatewayToken.equals(that.gatewayToken) : that.gatewayToken != null) { 721 return false; 722 } 723 if (gatewayCode != null ? !gatewayCode.equals(that.gatewayCode) : that.gatewayCode != null) { 724 return false; 725 } 726 if (updatedAt != null ? updatedAt.compareTo(that.updatedAt) != 0 : that.updatedAt != null) { 727 return false; 728 } 729 if (externalHppType != null ? !externalHppType.equals(that.externalHppType) : that.externalHppType != null) { 730 return false; 731 } 732 if (amazonBillingAgreementId != null ? !amazonBillingAgreementId.equals(that.amazonBillingAgreementId) : that.amazonBillingAgreementId != null) { 733 return false; 734 } 735 if (amazonRegion != null ? !amazonRegion.equals(that.amazonRegion) : that.amazonRegion != null) { 736 return false; 737 } 738 if (threeDSecureActionResultTokenId != null ? !threeDSecureActionResultTokenId.equals(that.threeDSecureActionResultTokenId) : that.threeDSecureActionResultTokenId != null) { 739 return false; 740 } 741 if (transactionType != null ? !transactionType.equals(that.transactionType) : that.transactionType != null) { 742 return false; 743 } 744 if (iban != null ? !iban.equals(that.iban) : that.iban != null) { 745 return false; 746 } 747 if (lastTwo != null ? !lastTwo.equals(that.lastTwo) : that.lastTwo != null) { 748 return false; 749 } 750 if (type != null ? !type.equals(that.type) : that.type != null) { 751 return false; 752 } 753 if (sortCode != null ? !sortCode.equals(that.sortCode) : that.sortCode != null ) { 754 return false; 755 } 756 if (bsbCode != null ? !bsbCode.equals(that.bsbCode) : that.bsbCode != null) { 757 return false; 758 } 759 if (taxIdentifier != null ? !taxIdentifier.equals(that.taxIdentifier) : that.taxIdentifier != null) { 760 return false; 761 } 762 if (taxIdentifierType != null ? !taxIdentifierType.equals(that.taxIdentifierType) : that.taxIdentifierType != null) { 763 return false; 764 } 765 if (primaryPaymentMethod != null ? !primaryPaymentMethod.equals(that.primaryPaymentMethod) : that.primaryPaymentMethod != null) { 766 return false; 767 } 768 if (backupPaymentMethod != null ? !backupPaymentMethod.equals(that.backupPaymentMethod) : that.backupPaymentMethod != null) { 769 return false; 770 } 771 772 return true; 773 } 774 775 @Override 776 public int hashCode() { 777 return Objects.hashCode( 778 account, 779 nameOnAccount, 780 uuid, 781 firstName, 782 lastName, 783 mandateReference, 784 company, 785 address1, 786 address2, 787 city, 788 state, 789 zip, 790 country, 791 phone, 792 vatNumber, 793 ipAddress, 794 ipAddressCountry, 795 accountType, 796 cardType, 797 year, 798 month, 799 firstSix, 800 lastFour, 801 number, 802 routingNumber, 803 accountNumber, 804 updatedAt, 805 geoCode, 806 type, 807 externalHppType, 808 gatewayToken, 809 gatewayCode, 810 amazonBillingAgreementId, 811 amazonRegion, 812 threeDSecureActionResultTokenId, 813 transactionType, 814 iban, 815 lastTwo, 816 sortCode, 817 bsbCode, 818 taxIdentifier, 819 taxIdentifierType, 820 primaryPaymentMethod, 821 backupPaymentMethod 822 ); 823 } 824}