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;
018
019import javax.xml.bind.annotation.XmlElement;
020import javax.xml.bind.annotation.XmlElementWrapper;
021import javax.xml.bind.annotation.XmlRootElement;
022import javax.xml.bind.annotation.XmlTransient;
023import javax.xml.bind.annotation.XmlValue;
024
025import org.joda.time.DateTime;
026
027import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
028
029@XmlRootElement(name = "plan")
030public class Plan extends RecurlyObject {
031
032    @XmlTransient
033    public static final String PLANS_RESOURCE = "/plans";
034
035    @XmlElementWrapper(name = "add_ons")
036    @XmlElement(name = "add_on")
037    private AddOns addOns;
038
039    @XmlElement(name = "plan_code")
040    private String planCode;
041
042    @XmlElement(name = "name")
043    private String name;
044
045    @XmlElement(name = "description")
046    private String description;
047
048    @XmlElement(name = "success_url")
049    private String successLink;
050
051    @XmlElement(name = "cancel_url")
052    private String cancelLink;
053
054    @XmlElement(name = "display_donation_amounts")
055    private Boolean displayDonationAmounts;
056
057    @XmlElement(name = "display_quantity")
058    private Boolean displayQuantity;
059
060    @XmlElement(name = "display_phone_number")
061    private Boolean displayPhoneNumber;
062
063    @XmlElement(name = "bypass_hosted_confirmation")
064    private Boolean bypassHostedConfirmation;
065
066    @XmlElement(name = "unit_name")
067    private String unitName;
068
069    @XmlElement(name = "plan_interval_unit")
070    private String planIntervalUnit;
071
072    @XmlElement(name = "plan_interval_length")
073    private Integer planIntervalLength;
074
075    @XmlElement(name = "trial_interval_length")
076    private Integer trialIntervalLength;
077
078    @XmlElement(name = "trial_interval_unit")
079    private String trialIntervalUnit;
080
081    @XmlElement(name = "accounting_code")
082    private String accountingCode;
083
084    @XmlElement(name = "created_at")
085    private DateTime createdAt;
086
087    @XmlElement(name = "unit_amount_in_cents")
088    private RecurlyUnitCurrency unitAmountInCents;
089
090    @XmlElement(name = "setup_fee_in_cents")
091    private RecurlyUnitCurrency setupFeeInCents;
092
093    public String getPlanCode() {
094        return planCode;
095    }
096
097    public void setPlanCode(final Object planCode) {
098        this.planCode = stringOrNull(planCode);
099    }
100
101    public String getName() {
102        return name;
103    }
104
105    public void setName(final Object name) {
106        this.name = stringOrNull(name);
107    }
108
109    public String getDescription() {
110        return description;
111    }
112
113    public void setDescription(final Object description) {
114        this.description = stringOrNull(description);
115    }
116
117    public String getSuccessLink() {
118        return successLink;
119    }
120
121    public void setSuccessLink(final Object link) {
122        this.successLink = stringOrNull(link);
123    }
124
125    public String getCancelLink() {
126        return cancelLink;
127    }
128
129    public void setCancelLink(final Object link) {
130        this.cancelLink = stringOrNull(link);
131    }
132
133    public Boolean getDisplayDonationAmounts() {
134        return displayDonationAmounts;
135    }
136
137    public void setDisplayDonationAmounts(final Object displayAmounts) {
138        this.displayDonationAmounts = booleanOrNull(displayAmounts);
139    }
140
141    public Boolean getDisplayQuantity() {
142        return displayQuantity;
143    }
144
145    public void setDisplayQuantity(final Object displayQuantity) {
146        this.displayQuantity = booleanOrNull(displayQuantity);
147    }
148
149    public Boolean getDisplayPhoneNumber() {
150        return displayPhoneNumber;
151    }
152
153    public void setDisplayPhoneNumber(final Object displayPhoneNumber) {
154        this.displayPhoneNumber = booleanOrNull(displayPhoneNumber);
155    }
156
157    public Boolean getBypassHostedConfirmation() {
158        return bypassHostedConfirmation;
159    }
160
161    public void setBypassHostedConfirmation(final Object bypassHostedConfirmation) {
162        this.bypassHostedConfirmation = booleanOrNull(bypassHostedConfirmation);
163    }
164
165    public String getUnitName() {
166        return unitName;
167    }
168
169    public void setUnitName(final Object unitName) {
170        this.unitName = stringOrNull(unitName);
171    }
172
173    public String getPlanIntervalUnit() {
174        return planIntervalUnit;
175    }
176
177    public void setPlanIntervalUnit(final Object planIntervalUnit) {
178        this.planIntervalUnit = stringOrNull(planIntervalUnit);
179    }
180
181    public Integer getPlanIntervalLength() {
182        return planIntervalLength;
183    }
184
185    public void setPlanIntervalLength(final Object planIntervalLength) {
186        this.planIntervalLength = integerOrNull(planIntervalLength);
187    }
188
189    public String getTrialIntervalUnit() {
190        return trialIntervalUnit;
191    }
192
193    public void setTrialIntervalUnit(final Object trialIntervalUnit) {
194        this.trialIntervalUnit = stringOrNull(trialIntervalUnit);
195    }
196
197    public Integer getTrialIntervalLength() {
198        return trialIntervalLength;
199    }
200
201    public void setTrialIntervalLength(final Object trialIntervalLength) {
202        this.trialIntervalLength = integerOrNull(trialIntervalLength);
203    }
204
205    public String getAccountingCode() {
206        return accountingCode;
207    }
208
209    public void setAccountingCode(final Object accountingCode) {
210        this.accountingCode = stringOrNull(accountingCode);
211    }
212
213    public DateTime getCreatedAt() {
214        return createdAt;
215    }
216
217    public void setCreatedAt(final Object createdAt) {
218        this.createdAt = dateTimeOrNull(createdAt);
219    }
220
221    public RecurlyUnitCurrency getUnitAmountInCents() {
222        return unitAmountInCents;
223    }
224
225    public void setUnitAmountInCents(final RecurlyUnitCurrency unitAmountInCents) {
226        this.unitAmountInCents = unitAmountInCents;
227    }
228
229    public RecurlyUnitCurrency getSetupFeeInCents() {
230        return setupFeeInCents;
231    }
232
233    public void setSetupFeeInCents(final RecurlyUnitCurrency setupFeeInCents) {
234        this.setupFeeInCents = setupFeeInCents;
235    }
236
237    public AddOns getAddOns() {
238        return this.addOns;
239    }
240
241    public void setAddOns(final AddOns addOns) {
242        this.addOns = addOns;
243    }
244
245    @Override
246    public String toString() {
247        final StringBuilder sb = new StringBuilder();
248        sb.append("Plan");
249        sb.append("{addOns=").append(addOns);
250        sb.append(", planCode='").append(planCode).append('\'');
251        sb.append(", name='").append(name).append('\'');
252        sb.append(", description='").append(description).append('\'');
253        sb.append(", successLink='").append(successLink).append('\'');
254        sb.append(", cancelLink='").append(cancelLink).append('\'');
255        sb.append(", displayDonationAmounts=").append(displayDonationAmounts);
256        sb.append(", displayQuantity=").append(displayQuantity);
257        sb.append(", displayPhoneNumber=").append(displayPhoneNumber);
258        sb.append(", bypassHostedConfirmation=").append(bypassHostedConfirmation);
259        sb.append(", unitName='").append(unitName).append('\'');
260        sb.append(", planIntervalUnit='").append(planIntervalUnit).append('\'');
261        sb.append(", planIntervalLength=").append(planIntervalLength);
262        sb.append(", trialIntervalLength=").append(trialIntervalLength);
263        sb.append(", trialIntervalUnit='").append(trialIntervalUnit).append('\'');
264        sb.append(", accountingCode='").append(accountingCode).append('\'');
265        sb.append(", createdAt=").append(createdAt);
266        sb.append(", unitAmountInCents=").append(unitAmountInCents);
267        sb.append(", setupFeeInCents=").append(setupFeeInCents);
268        sb.append('}');
269        return sb.toString();
270    }
271
272    @Override
273    public boolean equals(final Object o) {
274        if (this == o) {
275            return true;
276        }
277        if (o == null || getClass() != o.getClass()) {
278            return false;
279        }
280
281        final Plan plan = (Plan) o;
282
283        if (bypassHostedConfirmation != plan.bypassHostedConfirmation) {
284            return false;
285        }
286        if (displayPhoneNumber != plan.displayPhoneNumber) {
287            return false;
288        }
289        if (accountingCode != null ? !accountingCode.equals(plan.accountingCode) : plan.accountingCode != null) {
290            return false;
291        }
292        if (addOns != null ? !addOns.equals(plan.addOns) : plan.addOns != null) {
293            return false;
294        }
295        if (cancelLink != null ? !cancelLink.equals(plan.cancelLink) : plan.cancelLink != null) {
296            return false;
297        }
298        if (createdAt != null ? !createdAt.equals(plan.createdAt) : plan.createdAt != null) {
299            return false;
300        }
301        if (description != null ? !description.equals(plan.description) : plan.description != null) {
302            return false;
303        }
304        if (displayDonationAmounts != null ? !displayDonationAmounts.equals(plan.displayDonationAmounts) : plan.displayDonationAmounts != null) {
305            return false;
306        }
307        if (displayQuantity != null ? !displayQuantity.equals(plan.displayQuantity) : plan.displayQuantity != null) {
308            return false;
309        }
310        if (name != null ? !name.equals(plan.name) : plan.name != null) {
311            return false;
312        }
313        if (planCode != null ? !planCode.equals(plan.planCode) : plan.planCode != null) {
314            return false;
315        }
316        if (planIntervalLength != null ? !planIntervalLength.equals(plan.planIntervalLength) : plan.planIntervalLength != null) {
317            return false;
318        }
319        if (planIntervalUnit != null ? !planIntervalUnit.equals(plan.planIntervalUnit) : plan.planIntervalUnit != null) {
320            return false;
321        }
322        if (setupFeeInCents != null ? !setupFeeInCents.equals(plan.setupFeeInCents) : plan.setupFeeInCents != null) {
323            return false;
324        }
325        if (successLink != null ? !successLink.equals(plan.successLink) : plan.successLink != null) {
326            return false;
327        }
328        if (trialIntervalLength != null ? !trialIntervalLength.equals(plan.trialIntervalLength) : plan.trialIntervalLength != null) {
329            return false;
330        }
331        if (trialIntervalUnit != null ? !trialIntervalUnit.equals(plan.trialIntervalUnit) : plan.trialIntervalUnit != null) {
332            return false;
333        }
334        if (unitAmountInCents != null ? !unitAmountInCents.equals(plan.unitAmountInCents) : plan.unitAmountInCents != null) {
335            return false;
336        }
337        if (unitName != null ? !unitName.equals(plan.unitName) : plan.unitName != null) {
338            return false;
339        }
340
341        return true;
342    }
343
344    @Override
345    public int hashCode() {
346        int result = addOns != null ? addOns.hashCode() : 0;
347        result = 31 * result + (planCode != null ? planCode.hashCode() : 0);
348        result = 31 * result + (name != null ? name.hashCode() : 0);
349        result = 31 * result + (description != null ? description.hashCode() : 0);
350        result = 31 * result + (successLink != null ? successLink.hashCode() : 0);
351        result = 31 * result + (cancelLink != null ? cancelLink.hashCode() : 0);
352        result = 31 * result + (displayDonationAmounts != null ? displayDonationAmounts.hashCode() : 0);
353        result = 31 * result + (displayQuantity != null ? displayQuantity.hashCode() : 0);
354        result = 31 * result + (displayPhoneNumber ? 1 : 0);
355        result = 31 * result + (bypassHostedConfirmation ? 1 : 0);
356        result = 31 * result + (unitName != null ? unitName.hashCode() : 0);
357        result = 31 * result + (planIntervalUnit != null ? planIntervalUnit.hashCode() : 0);
358        result = 31 * result + (planIntervalLength != null ? planIntervalLength.hashCode() : 0);
359        result = 31 * result + (trialIntervalLength != null ? trialIntervalLength.hashCode() : 0);
360        result = 31 * result + (trialIntervalUnit != null ? trialIntervalUnit.hashCode() : 0);
361        result = 31 * result + (accountingCode != null ? accountingCode.hashCode() : 0);
362        result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0);
363        result = 31 * result + (unitAmountInCents != null ? unitAmountInCents.hashCode() : 0);
364        result = 31 * result + (setupFeeInCents != null ? setupFeeInCents.hashCode() : 0);
365        return result;
366    }
367
368    @JsonIgnoreProperties(ignoreUnknown = true)
369    public static class RecurlyUnitCurrency {
370
371        // United States Dollars
372        @XmlElement(name = "USD")
373        @XmlValue
374        private Integer unitAmountUSD;
375
376        // Australian Dollars
377        @XmlElement(name = "AUD")
378        @XmlValue
379        private Integer unitAmountAUD;
380
381        // Canadian Dollars
382        @XmlElement(name = "CAD")
383        @XmlValue
384        private Integer unitAmountCAD;
385
386        // Euros
387        @XmlElement(name = "EUR")
388        @XmlValue
389        private Integer unitAmountEUR;
390
391        // British Pounds
392        @XmlElement(name = "GBP")
393        @XmlValue
394        private Integer unitAmountGBP;
395
396        // Czech Korunas
397        @XmlElement(name = "CZK")
398        @XmlValue
399        private Integer unitAmountCZK;
400
401        // Danish Krones
402        @XmlElement(name = "DKK")
403        @XmlValue
404        private Integer unitAmountDKK;
405
406        // Hungarian Forints
407        @XmlElement(name = "HUF")
408        @XmlValue
409        private Integer unitAmountHUF;
410
411        // Norwegian Krones
412        @XmlElement(name = "NOK")
413        @XmlValue
414        private Integer unitAmountNOK;
415
416        // New Zealand Dollars
417        @XmlElement(name = "NZD")
418        @XmlValue
419        private Integer unitAmountNZD;
420
421        // Polish Zloty
422        @XmlElement(name = "PLN")
423        @XmlValue
424        private Integer unitAmountPLN;
425
426        // Singapore Dollars
427        @XmlElement(name = "SGD")
428        @XmlValue
429        private Integer unitAmountSGD;
430
431        // Swedish Kronas
432        @XmlElement(name = "SEK")
433        @XmlValue
434        private Integer unitAmountSEK;
435
436        // Swiss Francs
437        @XmlElement(name = "CHF")
438        @XmlValue
439        private Integer unitAmountCHF;
440
441        // South African Rand
442        @XmlElement(name = "ZAR")
443        @XmlValue
444        private Integer unitAmountZAR;
445
446        public Integer getUnitAmountUSD() {
447            return unitAmountUSD;
448        }
449
450        public void setUnitAmountUSD(final Object unitAmountUSD) {
451            this.unitAmountUSD = integerOrNull(unitAmountUSD);
452        }
453
454        public Integer getUnitAmountAUD() {
455            return unitAmountAUD;
456        }
457
458        public void setUnitAmountAUD(final Object unitAmountAUD) {
459            this.unitAmountAUD = integerOrNull(unitAmountAUD);
460        }
461
462        public Integer getUnitAmountCAD() {
463            return unitAmountCAD;
464        }
465
466        public void setUnitAmountCAD(final Object unitAmountCAD) {
467            this.unitAmountCAD = integerOrNull(unitAmountCAD);
468        }
469
470        public Integer getUnitAmountEUR() {
471            return unitAmountEUR;
472        }
473
474        public void setUnitAmountEUR(final Object unitAmountEUR) {
475            this.unitAmountEUR = integerOrNull(unitAmountEUR);
476        }
477
478        public Integer getUnitAmountGBP() {
479            return unitAmountGBP;
480        }
481
482        public void setUnitAmountGBP(final Object unitAmountGBP) {
483            this.unitAmountGBP = integerOrNull(unitAmountGBP);
484        }
485
486        public Integer getUnitAmountCZK() {
487            return unitAmountCZK;
488        }
489
490        public void setUnitAmountCZK(final Object unitAmountCZK) {
491            this.unitAmountCZK = integerOrNull(unitAmountCZK);
492        }
493
494        public Integer getUnitAmountDKK() {
495            return unitAmountDKK;
496        }
497
498        public void setUnitAmountDKK(final Object unitAmountDKK) {
499            this.unitAmountDKK = integerOrNull(unitAmountDKK);
500        }
501
502        public Integer getUnitAmountHUF() {
503            return unitAmountHUF;
504        }
505
506        public void setUnitAmountHUF(final Object unitAmountHUF) {
507            this.unitAmountHUF = integerOrNull(unitAmountHUF);
508        }
509
510        public Integer getUnitAmountNOK() {
511            return unitAmountNOK;
512        }
513
514        public void setUnitAmountNOK(final Object unitAmountNOK) {
515            this.unitAmountNOK = integerOrNull(unitAmountNOK);
516        }
517
518        public Integer getUnitAmountNZD() {
519            return unitAmountNZD;
520        }
521
522        public void setUnitAmountNZD(final Object unitAmountNZD) {
523            this.unitAmountNZD = integerOrNull(unitAmountNZD);
524        }
525
526        public Integer getUnitAmountPLN() {
527            return unitAmountPLN;
528        }
529
530        public void setUnitAmountPLN(final Object unitAmountPLN) {
531            this.unitAmountPLN = integerOrNull(unitAmountPLN);
532        }
533
534        public Integer getUnitAmountSGD() {
535            return unitAmountSGD;
536        }
537
538        public void setUnitAmountSGD(final Object unitAmountSGD) {
539            this.unitAmountSGD = integerOrNull(unitAmountSGD);
540        }
541
542        public Integer getUnitAmountSEK() {
543            return unitAmountSEK;
544        }
545
546        public void setUnitAmountSEK(final Object unitAmountSEK) {
547            this.unitAmountSEK = integerOrNull(unitAmountSEK);
548        }
549
550        public Integer getUnitAmountCHF() {
551            return unitAmountCHF;
552        }
553
554        public void setUnitAmountCHF(final Object unitAmountCHF) {
555            this.unitAmountCHF = integerOrNull(unitAmountCHF);
556        }
557
558        public Integer getUnitAmountZAR() {
559            return unitAmountZAR;
560        }
561
562        public void setUnitAmountZAR(final Object unitAmountZAR) {
563            this.unitAmountZAR = integerOrNull(unitAmountZAR);
564        }
565
566        @Override
567        public String toString() {
568            final StringBuilder sb = new StringBuilder();
569            sb.append("RecurlyUnitCurrency");
570            sb.append("{unitAmountUSD=").append(unitAmountUSD);
571            sb.append(", unitAmountAUD=").append(unitAmountAUD);
572            sb.append(", unitAmountCAD=").append(unitAmountCAD);
573            sb.append(", unitAmountEUR=").append(unitAmountEUR);
574            sb.append(", unitAmountGBP=").append(unitAmountGBP);
575            sb.append(", unitAmountCZK=").append(unitAmountCZK);
576            sb.append(", unitAmountDKK=").append(unitAmountDKK);
577            sb.append(", unitAmountHUF=").append(unitAmountHUF);
578            sb.append(", unitAmountNOK=").append(unitAmountNOK);
579            sb.append(", unitAmountNZD=").append(unitAmountNZD);
580            sb.append(", unitAmountPLN=").append(unitAmountPLN);
581            sb.append(", unitAmountSGD=").append(unitAmountSGD);
582            sb.append(", unitAmountSEK=").append(unitAmountSEK);
583            sb.append(", unitAmountCHF=").append(unitAmountCHF);
584            sb.append(", unitAmountZAR=").append(unitAmountZAR);
585            sb.append('}');
586            return sb.toString();
587        }
588
589        @Override
590        public boolean equals(final Object o) {
591            if (this == o) {
592                return true;
593            }
594            if (o == null || getClass() != o.getClass()) {
595                return false;
596            }
597
598            final RecurlyUnitCurrency that = (RecurlyUnitCurrency) o;
599
600            if (unitAmountAUD != null ? !unitAmountAUD.equals(that.unitAmountAUD) : that.unitAmountAUD != null) {
601                return false;
602            }
603            if (unitAmountCAD != null ? !unitAmountCAD.equals(that.unitAmountCAD) : that.unitAmountCAD != null) {
604                return false;
605            }
606            if (unitAmountCHF != null ? !unitAmountCHF.equals(that.unitAmountCHF) : that.unitAmountCHF != null) {
607                return false;
608            }
609            if (unitAmountCZK != null ? !unitAmountCZK.equals(that.unitAmountCZK) : that.unitAmountCZK != null) {
610                return false;
611            }
612            if (unitAmountDKK != null ? !unitAmountDKK.equals(that.unitAmountDKK) : that.unitAmountDKK != null) {
613                return false;
614            }
615            if (unitAmountEUR != null ? !unitAmountEUR.equals(that.unitAmountEUR) : that.unitAmountEUR != null) {
616                return false;
617            }
618            if (unitAmountGBP != null ? !unitAmountGBP.equals(that.unitAmountGBP) : that.unitAmountGBP != null) {
619                return false;
620            }
621            if (unitAmountHUF != null ? !unitAmountHUF.equals(that.unitAmountHUF) : that.unitAmountHUF != null) {
622                return false;
623            }
624            if (unitAmountNOK != null ? !unitAmountNOK.equals(that.unitAmountNOK) : that.unitAmountNOK != null) {
625                return false;
626            }
627            if (unitAmountNZD != null ? !unitAmountNZD.equals(that.unitAmountNZD) : that.unitAmountNZD != null) {
628                return false;
629            }
630            if (unitAmountPLN != null ? !unitAmountPLN.equals(that.unitAmountPLN) : that.unitAmountPLN != null) {
631                return false;
632            }
633            if (unitAmountSEK != null ? !unitAmountSEK.equals(that.unitAmountSEK) : that.unitAmountSEK != null) {
634                return false;
635            }
636            if (unitAmountSGD != null ? !unitAmountSGD.equals(that.unitAmountSGD) : that.unitAmountSGD != null) {
637                return false;
638            }
639            if (unitAmountUSD != null ? !unitAmountUSD.equals(that.unitAmountUSD) : that.unitAmountUSD != null) {
640                return false;
641            }
642            if (unitAmountZAR != null ? !unitAmountZAR.equals(that.unitAmountZAR) : that.unitAmountZAR != null) {
643                return false;
644            }
645
646            return true;
647        }
648
649        @Override
650        public int hashCode() {
651            int result = unitAmountUSD != null ? unitAmountUSD.hashCode() : 0;
652            result = 31 * result + (unitAmountAUD != null ? unitAmountAUD.hashCode() : 0);
653            result = 31 * result + (unitAmountCAD != null ? unitAmountCAD.hashCode() : 0);
654            result = 31 * result + (unitAmountEUR != null ? unitAmountEUR.hashCode() : 0);
655            result = 31 * result + (unitAmountGBP != null ? unitAmountGBP.hashCode() : 0);
656            result = 31 * result + (unitAmountCZK != null ? unitAmountCZK.hashCode() : 0);
657            result = 31 * result + (unitAmountDKK != null ? unitAmountDKK.hashCode() : 0);
658            result = 31 * result + (unitAmountHUF != null ? unitAmountHUF.hashCode() : 0);
659            result = 31 * result + (unitAmountNOK != null ? unitAmountNOK.hashCode() : 0);
660            result = 31 * result + (unitAmountNZD != null ? unitAmountNZD.hashCode() : 0);
661            result = 31 * result + (unitAmountPLN != null ? unitAmountPLN.hashCode() : 0);
662            result = 31 * result + (unitAmountSGD != null ? unitAmountSGD.hashCode() : 0);
663            result = 31 * result + (unitAmountSEK != null ? unitAmountSEK.hashCode() : 0);
664            result = 31 * result + (unitAmountCHF != null ? unitAmountCHF.hashCode() : 0);
665            result = 31 * result + (unitAmountZAR != null ? unitAmountZAR.hashCode() : 0);
666            return result;
667        }
668    }
669}