KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > epayment > adapters > ABCGatewayAdapter


1 package epayment.adapters;
2
3 import epayment.adapters.*;
4
5 import epayment.framework.IGatewayAdapter;
6 import epayment.framework.IPaymentRequest;
7 import epayment.framework.IPaymentResponse;
8 import epayment.framework.PaymentException;
9 import epayment.response.PaymentResponse;
10
11 /**
12  * The <code>ABCGatewayAdapter</code> class is an
13  * <code>IGatewayAdapter</code> which adapts
14  * to a vendor-specific epayment package.
15  * <p>
16  * This class is strictly an example.
17  *
18  * @author <a HREF="mailto:mike@clarkware.com">Mike Clark</a>
19  * @author <a HREF="http://www.clarkware.com">Clarkware Consulting</a>
20  */

21  
22 public class ABCGatewayAdapter implements IGatewayAdapter {
23
24     //
25
// Vendor-specific proxy class.
26
//
27
//private ABCProxy _proxy;
28

29     /**
30      * Constructs an <code>ABCGatewayAdapter</code> instance.
31      */

32     public ABCGatewayAdapter() {
33         //_proxy = new ABCProxy();
34
}
35     
36     /**
37      * Sets the payment gateway host.
38      *
39      * @param host Gateway host.
40      */

41     public void setHost(String JavaDoc host) {
42         //_proxy.setGatewayHostName(host);
43
}
44     
45     /**
46      * Performs an authorize for the specified payment request
47      * information and returns a payment response.
48      *
49      * @param request Payment request.
50      * @return Payment response.
51      * @throws PaymentException If an error occurs.
52      */

53     public IPaymentResponse authorize(IPaymentRequest request)
54         throws PaymentException {
55         
56         PaymentResponse response = new PaymentResponse();
57         
58         //
59
// Adapt the request information to the
60
// vendor-specific proxy API.
61
//
62
/*
63         _proxy.setAction("authorize");
64         _proxy.setUserId(request.getUserId());
65         _proxy.setPassword(request.getUserPassword());
66         _proxy.setAccountHolderName(request.getAccountName());
67         _proxy.setAccountHolderNumber(request.getAccountNumber());
68         _proxy.setUserDefinedField1(request.getComment());
69         _proxy.setTransactionAmount(request.getAmount());
70         */

71         
72         //
73
// Perform the transaction against
74
// the vendor-specific API.
75
//
76
/*
77         boolean success = false;
78         try {
79         
80             success = _proxy.performTransaction();
81         
82         } catch (Exception e) {
83             throw new PaymentException(e.getMessage());
84         }
85         */

86         
87         //
88
// Adapt the vendor-specific response information
89
// to the generic response API.
90
//
91
/*
92         if (success) {
93         
94             response.setResponseMessage(_proxy.getResult());
95             response.setProcessedDate(_proxy.getDate());
96     
97         } else {
98             throw new PaymentException(_proxy.getResult());
99         }
100         */

101
102         return response;
103     }
104     
105     /**
106      * Performs a capture for the specified payment
107      * request information and returns a payment response.
108      *
109      * @param request Payment request.
110      * @return Payment response.
111      * @throws PaymentException If an error occurs.
112      */

113     public IPaymentResponse capture(IPaymentRequest request)
114         throws PaymentException {
115         
116         // similar to authorize()
117

118         return new PaymentResponse();
119     }
120     
121     /**
122      * Performs a sale (authorize and capture) for the specified
123      * payment request information and returns a payment response.
124      *
125      * @param request Payment request.
126      * @return Payment response.
127      * @throws PaymentException If an error occurs.
128      */

129     public IPaymentResponse sale(IPaymentRequest request)
130         throws PaymentException {
131         
132         // similar to authorize()
133

134         return new PaymentResponse();
135     }
136     
137     /**
138      * Performs a credit for the specified payment request
139      * information and returns a payment response.
140      *
141      * @param request Payment request.
142      * @return Payment response.
143      * @throws PaymentException If an error occurs.
144      */

145     public IPaymentResponse credit(IPaymentRequest request)
146         throws PaymentException {
147         
148         // similar to authorize()
149

150         return new PaymentResponse();
151     }
152     
153     /**
154      * Performs a void for the specified payment request
155      * information and returns a payment response.
156      *
157      * @param request Payment request.
158      * @return Payment response.
159      * @throws PaymentException If an error occurs.
160      */

161     public IPaymentResponse voidSale(IPaymentRequest request)
162         throws PaymentException {
163         
164         // similar to authorize()
165

166         return new PaymentResponse();
167     }
168 }
169
Popular Tags