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;
021
022import javax.xml.bind.annotation.XmlElement;
023import javax.xml.bind.annotation.XmlElementWrapper;
024import javax.xml.bind.annotation.XmlList;
025import javax.xml.bind.annotation.XmlRootElement;
026import javax.xml.bind.annotation.XmlTransient;
027import java.util.List;
028
029@XmlRootElement(name = "purchase")
030public class Purchase extends RecurlyObject {
031    @XmlTransient
032    public static final String PURCHASES_ENDPOINT = "/purchases";
033
034    @XmlElement(name = "currency")
035    private String currency;
036
037    @XmlElement(name = "collection_method")
038    private String collectionMethod;
039
040    @XmlElement(name = "po_number")
041    private String poNumber;
042
043    @XmlElement(name = "net_terms")
044    private Integer netTerms;
045
046    @XmlElement(name = "account")
047    private Account account;
048
049    @XmlElementWrapper(name = "adjustments")
050    @XmlElement(name = "adjustment")
051    private Adjustments adjustments;
052
053    @XmlElementWrapper(name = "subscriptions")
054    @XmlElement(name = "subscription")
055    private Subscriptions subscriptions;
056
057    @XmlElement(name = "shipping_address")
058    private ShippingAddress shippingAddress;
059
060    @XmlElementWrapper(name = "shipping_fees")
061    @XmlElement(name = "shipping_fee")
062    private ShippingFees shippingFees;
063
064    @XmlElement(name = "gift_card")
065    private GiftCard giftCard;
066
067    @XmlElement(name = "customer_notes")
068    private String customerNotes;
069
070    @XmlElement(name = "vat_reverse_charge_notes")
071    private String vatReverseChargeNotes;
072
073    @XmlElement(name = "terms_and_conditions")
074    private String termsAndConditions;
075
076    @XmlElement(name = "billing_info_uuid")
077    private String billingInfoUuid;
078
079    @XmlElement(name = "shipping_address_id")
080    private Long shippingAddressId;
081
082    @XmlElement(name = "gateway_code")
083    private String gatewayCode;
084
085    @XmlElement(name = "transaction_type")
086    private String transactionType;
087
088    @XmlList
089    @XmlElementWrapper(name = "coupon_codes")
090    @XmlElement(name = "coupon_code")
091    private List<String> couponCodes;
092
093    public void setAccount(final Account account) {
094        this.account = account;
095    }
096
097    public Account getAccount() {
098        return account;
099    }
100
101    public void setAdjustments(final Adjustments adjustments) {
102        this.adjustments = adjustments;
103    }
104
105    public Adjustments getAdjustments() {
106        return adjustments;
107    }
108
109    public String getCollectionMethod() {
110        return collectionMethod;
111    }
112
113    public void setCollectionMethod(final Object collectionMethod) {
114        this.collectionMethod = stringOrNull(collectionMethod);
115    }
116
117    public void setCouponCodes(final List<String> couponCodes) {
118        this.couponCodes = couponCodes;
119    }
120
121    public List<String> getCouponCodes() {
122        return this.couponCodes;
123    }
124
125    public GiftCard getGiftCard() {
126        return giftCard;
127    }
128
129    public void setGiftCard(final GiftCard giftCard) {
130        this.giftCard = giftCard;
131    }
132
133    public Integer getNetTerms() {
134        return netTerms;
135    }
136
137    public void setNetTerms(final Object terms) {
138        this.netTerms = integerOrNull(terms);
139    }
140
141    public String getPoNumber() {
142        return poNumber;
143    }
144
145    public void setPoNumber(final Object poNumber) {
146        this.poNumber = stringOrNull(poNumber);
147    }
148
149    public String getCurrency() {
150        return currency;
151    }
152
153    public void setCurrency(final Object currency) {
154        this.currency = stringOrNull(currency);
155    }
156
157    public ShippingAddress getShippingAddress() {
158        return shippingAddress;
159    }
160
161    public void setShippingAddress(final ShippingAddress shippingAddress) {
162        this.shippingAddress = shippingAddress;
163    }
164
165    public void setShippingFees(final ShippingFees shippingFees) {
166        this.shippingFees = shippingFees;
167    }
168
169    public ShippingFees getShippingFees() {
170        return shippingFees;
171    }
172
173    public void setSubscriptions(final Subscriptions subscriptions) {
174        this.subscriptions = subscriptions;
175    }
176
177    public Subscriptions getSubscriptions() {
178        return subscriptions;
179    }
180
181    public String getCustomerNotes() {
182        return customerNotes;
183    }
184
185    public void setCustomerNotes(final Object customerNotes) {
186        this.customerNotes = stringOrNull(customerNotes);
187    }
188
189    public String getTermsAndConditions() {
190        return termsAndConditions;
191    }
192
193    public void setTermsAndConditions(final Object termsAndConditions) {
194        this.termsAndConditions = stringOrNull(termsAndConditions);
195    }
196
197    public String getVatReverseChargeNotes() {
198        return vatReverseChargeNotes;
199    }
200
201    public void setVatReverseChargeNotes(final Object vatReverseChargeNotes) {
202        this.vatReverseChargeNotes = stringOrNull(vatReverseChargeNotes);
203    }
204
205    public String getBillingInfoUuid() {
206      return billingInfoUuid;
207    }
208
209    public void setBillingInfoUuid(final Object billingInfoUuid) {
210        this.billingInfoUuid = stringOrNull(billingInfoUuid);
211    }
212
213    public Long getShippingAddressId() {
214        return shippingAddressId;
215    }
216
217    public void setShippingAddressId(final Object shippingAddressId) {
218        this.shippingAddressId = longOrNull(shippingAddressId);
219    }
220
221    public String getGatewayCode() {
222        return gatewayCode;
223    }
224
225    public void setGatewayCode(final Object gatewayCode) {
226        this.gatewayCode = stringOrNull(gatewayCode);
227    }
228
229    public String getTransactionType() {
230        return transactionType;
231    }
232
233    public void setTransactionType(final Object transactionType) {
234        this.transactionType = stringOrNull(transactionType);
235    }
236
237    @Override
238    public String toString() {
239        final StringBuilder sb = new StringBuilder();
240        sb.append("Purchase");
241        sb.append("{account=").append(account);
242        sb.append(", adjustments=").append(adjustments);
243        sb.append(", collectionMethod='").append(collectionMethod).append('\'');
244        sb.append(", currency='").append(currency).append('\'');
245        sb.append(", poNumber='").append(poNumber).append('\'');
246        sb.append(", netTerms='").append(netTerms).append('\'');
247        sb.append(", giftCard='").append(giftCard).append('\'');
248        sb.append(", shippingAddress='").append(shippingAddress).append('\'');
249        sb.append(", shippingFees=").append(shippingFees);
250        sb.append(", subscriptions='").append(subscriptions).append('\'');
251        sb.append(", couponCodes='").append(couponCodes).append('\'');
252        sb.append(", customerNotes='").append(customerNotes).append('\'');
253        sb.append(", termsAndConditions='").append(termsAndConditions).append('\'');
254        sb.append(", vatReverseChargeNotes='").append(vatReverseChargeNotes).append('\'');
255        sb.append(", billingInfoUuid='").append(billingInfoUuid).append('\'');
256        sb.append(", shippingAddressId='").append(shippingAddressId).append('\'');
257        sb.append(", gatewayCode='").append(gatewayCode).append('\'');
258        sb.append(", transactionType='").append(transactionType).append('\'');
259        sb.append('}');
260        return sb.toString();
261    }
262
263    @Override
264    public boolean equals(final Object o) {
265        if (this == o) return true;
266        if (o == null || getClass() != o.getClass()) return false;
267
268        final Purchase purchase = (Purchase) o;
269
270        if (account != null ? !account.equals(purchase.account) : purchase.account != null) {
271            return false;
272        }
273        if (adjustments != null ? !adjustments.equals(purchase.adjustments) : purchase.adjustments != null) {
274            return false;
275        }
276        if (collectionMethod != null ? !collectionMethod.equals(purchase.collectionMethod) : purchase.collectionMethod != null) {
277            return false;
278        }
279        if (couponCodes != null ? !couponCodes.equals(purchase.couponCodes) : purchase.couponCodes != null) {
280            return false;
281        }
282        if (currency != null ? !currency.equals(purchase.currency) : purchase.currency != null) {
283            return false;
284        }
285        if (customerNotes != null ? !customerNotes.equals(purchase.customerNotes) : purchase.customerNotes != null) {
286            return false;
287        }
288        if (gatewayCode != null ? !gatewayCode.equals(purchase.gatewayCode) : purchase.gatewayCode != null) {
289            return false;
290        }
291        if (giftCard != null ? !giftCard.equals(purchase.giftCard) : purchase.giftCard != null) {
292            return false;
293        }
294        if (poNumber != null ? !poNumber.equals(purchase.poNumber) : purchase.poNumber != null) {
295            return false;
296        }
297        if (netTerms != null ? !netTerms.equals(purchase.netTerms) : purchase.netTerms != null) {
298            return false;
299        }
300        if (shippingAddress != null ? !shippingAddress.equals(purchase.shippingAddress) : purchase.shippingAddress != null) {
301            return false;
302        }    
303        if (shippingAddressId != null ? !shippingAddressId.equals(purchase.shippingAddressId) : purchase.shippingAddressId != null) {
304            return false;
305        }
306        if (billingInfoUuid != null ? !billingInfoUuid.equals(purchase.billingInfoUuid) : purchase.billingInfoUuid != null) {
307            return false;
308        }
309        if (shippingFees != null ? !shippingFees.equals(purchase.shippingFees) : purchase.shippingFees != null) {
310            return false;
311        }
312        if (subscriptions != null ? !subscriptions.equals(purchase.subscriptions) : purchase.subscriptions != null) {
313            return false;
314        }
315        if (termsAndConditions != null ? !termsAndConditions.equals(purchase.termsAndConditions) : purchase.termsAndConditions != null) {
316            return false;
317        }
318        if (transactionType != null ? !transactionType.equals(purchase.transactionType) : purchase.transactionType != null) {
319            return false;
320        }
321        if (vatReverseChargeNotes != null ? !vatReverseChargeNotes.equals(purchase.vatReverseChargeNotes) : purchase.vatReverseChargeNotes != null) {
322            return false;
323        }
324
325        return true;
326    }
327
328    @Override
329    public int hashCode() {
330        return Objects.hashCode(
331                account,
332                adjustments,
333                collectionMethod,
334                currency,
335                giftCard,
336                poNumber,
337                netTerms,
338                shippingAddress,
339                shippingFees,
340                subscriptions,
341                couponCodes,
342                customerNotes,
343                termsAndConditions,
344                vatReverseChargeNotes,
345                billingInfoUuid,
346                shippingAddressId,
347                gatewayCode,
348                transactionType
349        );
350    }
351
352}
353
354