001: package epayment.adapters;
002:
003: import epayment.framework.IGatewayAdapter;
004: import epayment.framework.IPaymentRequest;
005: import epayment.framework.IPaymentResponse;
006: import epayment.framework.PaymentException;
007: import epayment.response.PaymentResponse;
008:
009: /**
010: * The <code>XYZGatewayAdapter</code> class is an
011: * <code>IGatewayAdapter</code> which adapts
012: * to a vendor-specific epayment package.
013: * <p>
014: * This class is strictly an example.
015: *
016: * @author <a href="mailto:mike@clarkware.com">Mike Clark</a>
017: * @author <a href="http://www.clarkware.com">Clarkware Consulting</a>
018: */
019:
020: public class XYZGatewayAdapter implements IGatewayAdapter {
021:
022: //
023: // Vendor-specific proxy class.
024: //
025: //private XYZProxy _proxy;
026:
027: /**
028: * Constructs an <code>XYZGatewayAdapter</code> instance.
029: */
030: public XYZGatewayAdapter() {
031: //_proxy = new XYZProxy();
032: }
033:
034: /**
035: * Sets the payment gateway host.
036: *
037: * @param host Gateway host.
038: */
039: public void setHost(String host) {
040: //_proxy.setHostName(host);
041: }
042:
043: /**
044: * Performs an authorize for the specified payment request
045: * information and returns a payment response.
046: *
047: * @param request Payment request.
048: * @return Payment response.
049: * @throws PaymentException If an error occurs.
050: */
051: public IPaymentResponse authorize(IPaymentRequest request)
052: throws PaymentException {
053:
054: PaymentResponse response = new PaymentResponse();
055:
056: //
057: // Adapt the request information to the
058: // vendor-specific proxy API.
059: //
060: /*
061: _proxy.setAction("1");
062: _proxy.setUser(request.getUserId());
063: _proxy.setPass(request.getUserPassword());
064: _proxy.setName(request.getAccountName());
065: _proxy.setNumber(request.getAccountNumber());
066: _proxy.setComment(request.getComment());
067: _proxy.setAmount(request.getAmount());
068: */
069:
070: //
071: // Perform the transaction against
072: // the vendor-specific API.
073: //
074: /*
075: boolean success = false;
076: try {
077:
078: success = _proxy.execute();
079:
080: } catch (Exception e) {
081: throw new PaymentException(e.getMessage());
082: }
083: */
084:
085: //
086: // Adapt the vendor-specific response information
087: // to the generic response API.
088: //
089: /*
090: if (success) {
091:
092: response.setResponseMessage(_proxy.getExecutionResult());
093: response.setProcessedDate(_proxy.getDateTime());
094:
095: } else {
096: throw new PaymentException(_proxy.getResult());
097: }
098: */
099:
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: }
|