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