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.push.payment;
018
019import java.util.Map;
020
021import javax.xml.bind.annotation.XmlElement;
022
023import org.joda.time.DateTime;
024
025import com.ning.billing.recurly.model.AbstractTransaction;
026
027public class PushTransaction extends AbstractTransaction {
028
029    public static class VerificationResult {
030
031        private String code;
032
033        private String message;
034
035        public VerificationResult() {
036        }
037
038        public VerificationResult(final String code, final String message) {
039            this.code = code;
040            this.message = message;
041        }
042
043        public String getCode() {
044            return code;
045        }
046
047        public void setCode(final String code) {
048            this.code = code;
049        }
050
051        public String getMessage() {
052            return message;
053        }
054
055        public void setMessage(final String message) {
056            this.message = message;
057        }
058
059        public static VerificationResult as(final Object object) {
060            if (isNull(object)) {
061                return null;
062            }
063
064            if (object instanceof Map) {
065                final Map map = (Map) object;
066                return new VerificationResult(stringOrNull(map.get("code")), stringOrNull(map.get("")));
067            }
068
069            return new VerificationResult(null, object.toString());
070        }
071    }
072
073    @XmlElement
074    private String id;
075
076    @XmlElement(name = "invoice_id")
077    private String invoiceId;
078
079    @XmlElement(name = "invoice_number")
080    private Integer invoiceNumber;
081
082    @XmlElement(name = "subscription_id")
083    private String subscriptionId;
084
085    @XmlElement
086    private DateTime date;
087
088    @XmlElement
089    private String message;
090
091    @XmlElement(name = "cvv_result")
092    private VerificationResult cvvResult;
093
094    @XmlElement(name = "avs_result")
095    private VerificationResult avsResult;
096
097    public String getId() {
098        return id;
099    }
100
101    public void setId(final Object id) {
102        this.id = stringOrNull(id);
103    }
104
105    public String getInvoiceId() {
106        return invoiceId;
107    }
108
109    public void setInvoiceId(final Object invoiceId) {
110        this.invoiceId = stringOrNull(invoiceId);
111    }
112
113    public Integer getInvoiceNumber() {
114        return invoiceNumber;
115    }
116
117    public void setInvoiceNumber(final Object invoiceNumber) {
118        this.invoiceNumber = integerOrNull(invoiceNumber);
119    }
120
121    public String getSubscriptionId() {
122        return subscriptionId;
123    }
124
125    public void setSubscriptionId(final Object subscriptionId) {
126        this.subscriptionId = stringOrNull(subscriptionId);
127    }
128
129    public DateTime getDate() {
130        return date;
131    }
132
133    public void setDate(final Object date) {
134        this.date = dateTimeOrNull(date);
135    }
136
137    public String getMessage() {
138        return message;
139    }
140
141    public void setMessage(final Object message) {
142        this.message = stringOrNull(message);
143    }
144
145    public VerificationResult getCvvResult() {
146        return cvvResult;
147    }
148
149    public void setCvvResult(final Object cvvResult) {
150        this.cvvResult = VerificationResult.as(cvvResult);
151    }
152
153    public VerificationResult getAvsResult() {
154        return avsResult;
155    }
156
157    public void setAvsResult(final Object avsResult) {
158        this.avsResult = VerificationResult.as(avsResult);
159    }
160
161    @Override
162    public boolean equals(final Object o) {
163        if (this == o) {
164            return true;
165        }
166        if (!(o instanceof PushTransaction)) {
167            return false;
168        }
169        if (!super.equals(o)) {
170            return false;
171        }
172
173        final PushTransaction that = (PushTransaction) o;
174
175        if (avsResult != null ? !avsResult.equals(that.avsResult) : that.avsResult != null) {
176            return false;
177        }
178        if (cvvResult != null ? !cvvResult.equals(that.cvvResult) : that.cvvResult != null) {
179            return false;
180        }
181        if (date != null ? !date.equals(that.date) : that.date != null) {
182            return false;
183        }
184        if (id != null ? !id.equals(that.id) : that.id != null) {
185            return false;
186        }
187        if (invoiceId != null ? !invoiceId.equals(that.invoiceId) : that.invoiceId != null) {
188            return false;
189        }
190        if (invoiceNumber != null ? !invoiceNumber.equals(that.invoiceNumber) : that.invoiceNumber != null) {
191            return false;
192        }
193        if (message != null ? !message.equals(that.message) : that.message != null) {
194            return false;
195        }
196        if (subscriptionId != null ? !subscriptionId.equals(that.subscriptionId) : that.subscriptionId != null) {
197            return false;
198        }
199
200        return true;
201    }
202
203    @Override
204    public int hashCode() {
205        int result = super.hashCode();
206        result = 31 * result + (id != null ? id.hashCode() : 0);
207        result = 31 * result + (invoiceId != null ? invoiceId.hashCode() : 0);
208        result = 31 * result + (invoiceNumber != null ? invoiceNumber.hashCode() : 0);
209        result = 31 * result + (subscriptionId != null ? subscriptionId.hashCode() : 0);
210        result = 31 * result + (date != null ? date.hashCode() : 0);
211        result = 31 * result + (message != null ? message.hashCode() : 0);
212        result = 31 * result + (cvvResult != null ? cvvResult.hashCode() : 0);
213        result = 31 * result + (avsResult != null ? avsResult.hashCode() : 0);
214        return result;
215    }
216}