KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > epayment > adapters > XYZGatewayAdapter


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

19  
20 public class XYZGatewayAdapter implements IGatewayAdapter {
21
22     //
23
// Vendor-specific proxy class.
24
//
25
//private XYZProxy _proxy;
26

27     /**
28      * Constructs an <code>XYZGatewayAdapter</code> instance.
29      */

30     public XYZGatewayAdapter() {
31         //_proxy = new XYZProxy();
32
}
33     
34     /**
35      * Sets the payment gateway host.
36      *
37      * @param host Gateway host.
38      */

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

51     public IPaymentResponse authorize(IPaymentRequest request)
52         throws PaymentException {
53         
54         PaymentResponse response = new PaymentResponse();
55         
56         //
57
// Adapt the request information to the
58
// vendor-specific proxy API.
59
//
60
/*
61         _proxy.setAction("1");
62         _proxy.setUser(request.getUserId());
63         _proxy.setPass(request.getUserPassword());
64         _proxy.setName(request.getAccountName());
65         _proxy.setNumber(request.getAccountNumber());
66         _proxy.setComment(request.getComment());
67         _proxy.setAmount(request.getAmount());
68         */

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

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

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

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

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

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

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

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

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

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

164         return new PaymentResponse();
165     }
166 }
167
Popular Tags