KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > CreditPaymentMethod


1 /*
2  * Created on Mar 4, 2004
3  *
4  */

5 package com.openedit.store;
6
7 import java.text.NumberFormat JavaDoc;
8
9 /**
10  * @author dbrown
11  *
12  */

13 public class CreditPaymentMethod extends PaymentMethod
14 {
15     protected CreditCardType fieldCreditCardType;
16     protected String JavaDoc fieldCardNumber = "";
17     protected int fieldExpirationMonth = 0;
18     protected int fieldExpirationYear = 0;
19     protected String JavaDoc fieldNote;
20     protected boolean fieldBillMeLater; //TODO: extract into a BillMeLaterPaymentMethod class
21

22     public CreditPaymentMethod()
23     {
24         super();
25     }
26
27     public String JavaDoc getCardNumber()
28     {
29         return fieldCardNumber;
30     }
31
32     public CreditCardType getCreditCardType()
33     {
34         if ( fieldCreditCardType == null )
35         {
36             fieldCreditCardType = new CreditCardType();
37         }
38         return fieldCreditCardType;
39     }
40
41     public String JavaDoc getExpirationDateString()
42     {
43         NumberFormat JavaDoc twoDigitIntFormat = NumberFormat.getIntegerInstance();
44         twoDigitIntFormat.setMinimumIntegerDigits(2);
45         return twoDigitIntFormat.format(getExpirationMonth()) + '/' +
46             twoDigitIntFormat.format(getExpirationYear() % 100);
47     }
48
49     public String JavaDoc getExpirationMonthString()
50     {
51         String JavaDoc dateString = getExpirationDateString();
52         String JavaDoc monthString = dateString.substring(0,2);
53         return monthString;
54     }
55     
56     public String JavaDoc getExpirationYearString()
57     {
58         String JavaDoc dateString = getExpirationDateString();
59         String JavaDoc yearString = dateString.substring(3,5);
60         return yearString;
61     }
62     
63     public int getExpirationMonth()
64     {
65         return fieldExpirationMonth;
66     }
67
68     public int getExpirationYear()
69     {
70         return fieldExpirationYear;
71     }
72
73     public void setCardNumber(String JavaDoc inString)
74     {
75         fieldCardNumber = inString;
76     }
77
78     public void setCreditCardType(CreditCardType inType)
79     {
80         fieldCreditCardType = inType;
81     }
82
83     public void setExpirationMonth(int inI)
84     {
85         fieldExpirationMonth = inI;
86     }
87
88     public void setExpirationYear(int inI)
89     {
90         fieldExpirationYear = inI;
91     }
92
93     public String JavaDoc toString()
94     {
95         StringBuffer JavaDoc sb = new StringBuffer JavaDoc( "Credit Card: " );
96         sb.append( fieldCreditCardType );
97         sb.append( '\n' );
98         sb.append( fieldCardNumber );
99         sb.append( " Expiration: " );
100         sb.append( fieldExpirationMonth );
101         sb.append( '/' );
102         sb.append( fieldExpirationYear );
103         sb.append( '\n' );
104         return sb.toString();
105     }
106
107     /* (non-javadoc)
108      * @see com.openedit.store.PaymentMethod#requiresValidation()
109      */

110     public boolean requiresValidation()
111     {
112         // This requires validation if "bill me later" is not turned on.
113
return !getBillMeLater();
114     }
115
116     /* (non-javadoc)
117      * @see com.openedit.store.PaymentMethod#getType()
118      */

119     public String JavaDoc getType()
120     {
121         return "creditcard";
122     }
123     public boolean getBillMeLater()
124     {
125         return fieldBillMeLater;
126     }
127     public void setBillMeLater(boolean inBillMeLater)
128     {
129         fieldBillMeLater = inBillMeLater;
130     }
131     
132     public String JavaDoc getNote()
133     {
134         return fieldNote;
135     }
136     public void setNote( String JavaDoc inNote )
137     {
138         fieldNote = inNote;
139     }
140 }
141
Popular Tags