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.XmlElementWrapper; 025import javax.xml.bind.annotation.XmlRootElement; 026import java.util.List; 027 028@XmlRootElement(name = "invoice") 029public class InvoiceRefund extends RecurlyObject { 030 @XmlElement(name = "refund_method") 031 private RefundMethod refundMethod; 032 033 @XmlElement(name = "amount_in_cents") 034 private Integer amountInCents; 035 036 @XmlElementWrapper(name = "line_items") 037 @XmlElement(name = "adjustment") 038 private List<AdjustmentRefund> lineItems; 039 040 @XmlElement(name = "external_refund") 041 private Boolean externalRefund; 042 043 @XmlElement(name = "credit_customer_notes") 044 private String creditCustomerNotes; 045 046 @XmlElement(name = "payment_method") 047 private String paymentMethod; 048 049 @XmlElement(name = "description") 050 private String description; 051 052 @XmlElement(name = "refunded_at") 053 private DateTime refundedAt; 054 055 public void setRefundMethod(final RefundMethod refundMethod) { 056 this.refundMethod = refundMethod; 057 } 058 059 public RefundMethod getRefundMethod() { 060 return this.refundMethod; 061 } 062 063 public void setAmountInCents(final Object amountInCents) { 064 this.amountInCents = integerOrNull(amountInCents); 065 } 066 067 public Integer getAmountInCents() { 068 return this.amountInCents; 069 } 070 071 public void setLineItems(final List<AdjustmentRefund> lineItems) { 072 this.lineItems = lineItems; 073 } 074 075 public List<AdjustmentRefund> getLineItems() { 076 return this.lineItems; 077 } 078 079 public String getCreditCustomerNotes() { 080 return creditCustomerNotes; 081 } 082 083 public void setCreditCustomerNotes(final Object creditCustomerNotes) { 084 this.creditCustomerNotes = stringOrNull(creditCustomerNotes); 085 } 086 087 public void setExternalRefund(final Object externalRefund) { 088 this.externalRefund = booleanOrNull(externalRefund); 089 } 090 091 public Boolean getExternalRefund() { 092 return this.externalRefund; 093 } 094 095 public void setPaymentMethod(final Object paymentMethod) { 096 this.paymentMethod = stringOrNull(paymentMethod); 097 } 098 099 public String getPaymentMethod() { 100 return this.paymentMethod; 101 } 102 103 public void setDescription(final Object description) { 104 this.description = stringOrNull(description); 105 } 106 107 public String getDescription() { 108 return this.description; 109 } 110 111 public void setRefundedAt(final Object refundedAt) { 112 this.refundedAt = dateTimeOrNull(refundedAt); 113 } 114 115 public DateTime getRefundedAt() { 116 return this.refundedAt; 117 } 118 119 @Override 120 public int hashCode() { 121 return Objects.hashCode(refundMethod, amountInCents); 122 } 123 124 @Override 125 public boolean equals(final Object o) { 126 if (this == o) return true; 127 if (o == null || getClass() != o.getClass()) return false; 128 129 final InvoiceRefund refund = (InvoiceRefund) o; 130 131 if (amountInCents != null ? !amountInCents.equals(refund.amountInCents) : refund.amountInCents != null) { 132 return false; 133 } 134 if (externalRefund != null ? !externalRefund.equals(refund.externalRefund) : refund.externalRefund != null) { 135 return false; 136 } 137 if (refundMethod != null ? !refundMethod.equals(refund.refundMethod) : refund.refundMethod != null) { 138 return false; 139 } 140 if (creditCustomerNotes != null ? !creditCustomerNotes.equals(refund.creditCustomerNotes) : refund.creditCustomerNotes != null) { 141 return false; 142 } 143 if (description != null ? !description.equals(refund.description) : refund.description != null) { 144 return false; 145 } 146 if (paymentMethod != null ? !paymentMethod.equals(refund.paymentMethod) : refund.paymentMethod != null) { 147 return false; 148 } 149 if (refundedAt != null ? refundedAt.compareTo(refund.refundedAt) != 0: refund.refundedAt != null) { 150 return false; 151 } 152 return true; 153 } 154 155 @Override 156 public String toString() { 157 final StringBuilder sb = new StringBuilder("InvoiceRefund{"); 158 sb.append("amountInCents=").append(amountInCents); 159 sb.append(", refundMethod='").append(refundMethod).append('\''); 160 sb.append(", externalRefund='").append(externalRefund).append('\''); 161 sb.append(", creditCustomerNotes='").append(creditCustomerNotes).append('\''); 162 sb.append(", description='").append(description).append('\''); 163 sb.append(", paymentMethod='").append(paymentMethod).append('\''); 164 sb.append(", refundedAt='").append(refundedAt).append('\''); 165 sb.append('}'); 166 return sb.toString(); 167 } 168}