KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > accounting > thirdparty > authorizedotnet > AIMPaymentServices


1 /*
2  * Copyright 2001-2006 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  */

16
17 package org.ofbiz.accounting.thirdparty.authorizedotnet;
18
19 import java.util.*;
20
21 import org.ofbiz.base.util.*;
22 import org.ofbiz.entity.*;
23 import org.ofbiz.service.*;
24
25 import org.ofbiz.accounting.payment.PaymentGatewayServices;
26
27 /**
28  *
29  * @author Fred Forrester (foresterf@fredforester.org)
30  * @author Si Chen (sichen@opensourcestrategies.com)
31  */

32 public class AIMPaymentServices {
33
34     public static final String JavaDoc module = AIMPaymentServices.class.getName();
35
36     private static Properties AIMProperties = null;
37
38     public static Map ccAuth(DispatchContext ctx, Map context) {
39         Map results = ServiceUtil.returnSuccess();
40         Map request = new HashMap();
41
42         Properties props = buildAIMProperties(context);
43         buildMerchantInfo(context,props,request);
44         buildGatewayResponeConfig(context,props,request);
45         buildCustomerBillingInfo(context,props,request);
46         buildEmailSettings(context,props,request);
47         buildInvoiceInfo(context,props,request);
48         props.put("transType","AUTH_ONLY");
49         buildAuthTransaction(context,props,request);
50
51         Map validateResults = validateRequest(context,props,request);
52         String JavaDoc respMsg = (String JavaDoc)validateResults.get(ModelService.RESPONSE_MESSAGE);
53         if(respMsg != null) {
54             if(respMsg.equals(ModelService.RESPOND_ERROR)) {
55                 results.put(ModelService.ERROR_MESSAGE, "Validation Failed - invalid values");
56                 return results;
57             }
58         }
59
60         Map reply = processCard(request, props);
61
62         //now we need to process the result
63
processAuthTransResult(reply, results);
64         return results;
65     }
66
67     public static Map ccCapture(DispatchContext ctx, Map context) {
68         GenericDelegator delegator = ctx.getDelegator();
69         GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
70
71         GenericValue creditCard = null;
72         try {
73             creditCard = delegator.getRelatedOne("CreditCard",orderPaymentPreference);
74         } catch (GenericEntityException e) {
75             Debug.logError(e, module);
76             return ServiceUtil.returnError("Unable to obtain cc information from payment preference");
77         }
78         GenericValue authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
79         if (authTransaction == null) {
80             return ServiceUtil.returnError("No authorization transaction found for the OrderPaymentPreference; cannot Capture");
81         }
82         context.put("creditCard",creditCard);
83         context.put("authTransaction",authTransaction);
84
85         Map results = ServiceUtil.returnSuccess();
86         Map request = new HashMap();
87
88         Properties props = buildAIMProperties(context);
89         buildMerchantInfo(context,props,request);
90         buildGatewayResponeConfig(context,props,request);
91         buildCustomerBillingInfo(context,props,request);
92         buildEmailSettings(context,props,request);
93         request.put("x_Invoice_Num","Order " + orderPaymentPreference.getString("orderId"));
94         //props.put("transType","PRIOR_AUTH_CAPTURE");
95
props.put("transType","CAPTURE_ONLY");
96         props.put("cardtype", (String JavaDoc)creditCard.get("cardType"));
97         buildCaptureTransaction(context,props,request);
98
99         Map validateResults = validateRequest(context,props,request);
100         String JavaDoc respMsg = (String JavaDoc)validateResults.get(ModelService.RESPONSE_MESSAGE);
101         if(respMsg != null) {
102             if(respMsg.equals(ModelService.RESPOND_ERROR)) {
103                 results.put(ModelService.ERROR_MESSAGE, "Validation Failed - invalid values");
104                 return results;
105             }
106         }
107
108         Map reply = processCard(request, props);
109
110         processCaptureTransResult(reply,results);
111         return results;
112     }
113
114     public static Map ccRelease(DispatchContext ctx, Map context) {
115         Map results = new HashMap();
116         results.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
117         results.put(ModelService.ERROR_MESSAGE, "Authorize.net ccRelease unsupported with version 3.0");
118         return results;
119     }
120
121     public static Map ccRefund(DispatchContext ctx, Map context) {
122         GenericDelegator delegator = ctx.getDelegator();
123         GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
124         
125         GenericValue creditCard = null;
126         try {
127             creditCard = delegator.getRelatedOne("CreditCard",orderPaymentPreference);
128         } catch (GenericEntityException e) {
129             Debug.logError(e, module);
130             return ServiceUtil.returnError("Unable to obtain cc information from payment preference");
131         }
132         
133         GenericValue authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
134         if (authTransaction == null) {
135             return ServiceUtil.returnError("No authorization transaction found for the OrderPaymentPreference; cannot Capture");
136         }
137         
138         context.put("creditCard",creditCard);
139         context.put("authTransaction",authTransaction);
140         Map results = ServiceUtil.returnSuccess();
141         Map request = new HashMap();
142
143         Properties props = buildAIMProperties(context);
144         buildMerchantInfo(context,props,request);
145         buildGatewayResponeConfig(context,props,request);
146         buildEmailSettings(context,props,request);
147         //props.put("transType","PRIOR_AUTH_CAPTURE");
148
props.put("transType","CREDIT");
149         props.put("cardtype", (String JavaDoc)creditCard.get("cardType"));
150         buildRefundTransaction(context,props,request);
151
152         Map validateResults = validateRequest(context,props,request);
153         String JavaDoc respMsg = (String JavaDoc)validateResults.get(ModelService.RESPONSE_MESSAGE);
154         if(respMsg != null) {
155             if(respMsg.equals(ModelService.RESPOND_ERROR)) {
156                 results.put(ModelService.ERROR_MESSAGE, "Validation Failed - invalid values");
157                 return results;
158             }
159         }
160
161         Map reply = processCard(request, props);
162
163         processRefundTransResult(reply,results);
164         return results;
165     }
166
167     public static Map ccCredit(DispatchContext ctx, Map context) {
168         Map results = new HashMap();
169         results.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
170         results.put(ModelService.ERROR_MESSAGE, "Authorize.net ccCredit unsupported with version 3.0");
171         return results;
172     }
173
174     public static Map ccAuthCapture(DispatchContext ctx, Map context) {
175         Map results = ServiceUtil.returnSuccess();
176         Map request = new HashMap();
177
178         Properties props = buildAIMProperties(context);
179         buildMerchantInfo(context,props,request);
180         buildGatewayResponeConfig(context,props,request);
181         buildCustomerBillingInfo(context,props,request);
182         buildEmailSettings(context,props,request);
183         buildInvoiceInfo(context,props,request);
184         props.put("transType","AUTH_CAPTURE");
185         buildAuthTransaction(context,props,request);
186
187         Map validateResults = validateRequest(context,props,request);
188         String JavaDoc respMsg = (String JavaDoc)validateResults.get(ModelService.RESPONSE_MESSAGE);
189         if(respMsg != null) {
190             if(respMsg.equals(ModelService.RESPOND_ERROR)) {
191                 results.put(ModelService.ERROR_MESSAGE, "Validation Failed - invalid values");
192                 return results;
193             }
194         }
195
196         Map reply = processCard(request, props);
197
198         //now we need to process the result
199
processAuthCaptureTransResult(reply, results);
200         return results;
201     }
202
203     private static HashMap processCard(Map request, Properties props) {
204         HashMap result = new HashMap();
205
206         String JavaDoc url = props.getProperty("url");
207         if (url == null || url.length() == 0) {
208             url = "https://certification.authorize.net/gateway/transact.dll"; // test url
209
Debug.logWarning("No payment.authorizedotnet.url found. Using a default of [" + url + "]", module);
210         }
211         if(isTestMode()) {
212             Debug.logInfo("TEST Authorize.net using url [" + url + "]", module);
213             Debug.logInfo("TEST Authorize.net request string " + request.toString(),module);
214             Debug.logInfo("TEST Authorize.net properties string " + props.toString(),module);
215         }
216
217         try {
218             HttpClient httpClient = new HttpClient(url, request);
219
220             httpClient.setClientCertificateAlias("AUTHORIZE_NET");
221             String JavaDoc httpResponse = httpClient.post();
222
223             Debug.logInfo("transaction response: " + httpResponse,module);
224
225             AuthorizeResponse ar = new AuthorizeResponse(httpResponse);
226             String JavaDoc resp = ar.getResponseCode();
227
228             if (resp.equals(ar.APPROVED)) {
229                 result.put("authResult", new Boolean JavaDoc(true));
230             } else {
231                 result.put("authResult", new Boolean JavaDoc(false));
232                 Debug.logInfo("responseCode: " + ar.getResponseField(AuthorizeResponse.RESPONSE_CODE),module);
233                 Debug.logInfo("responseReason: " + ar.getResponseField(AuthorizeResponse.RESPONSE_REASON_CODE),module);
234                 Debug.logInfo("reasonText: " + ar.getResponseField(AuthorizeResponse.RESPONSE_REASON_TEXT),module);
235             }
236
237             result.put("httpResponse", httpResponse);
238             result.put("authorizeResponse", ar);
239
240         } catch (HttpClientException e) {
241             Debug.logInfo("Could not complete Authorize.Net transaction: " + e.toString(),module);
242         }
243
244         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
245         return result;
246     }
247
248     private static boolean isTestMode() {
249         boolean ret = true;
250         String JavaDoc testReq = (String JavaDoc)AIMProperties.get("testReq");
251         if(testReq != null) {
252             if(testReq.equals("TRUE"))
253                 ret = true;
254             else
255                 ret = false;
256         }
257         return ret;
258     }
259
260     private static String JavaDoc getVersion() {
261         String JavaDoc ver = (String JavaDoc)AIMProperties.get("ver");
262         return ver;
263
264     }
265
266     private static Properties buildAIMProperties(Map context) {
267         String JavaDoc configStr = (String JavaDoc)context.get("paymentConfig");
268         if(configStr == null) {
269             configStr = "payment.properties";
270         }
271
272         GenericValue cc = (GenericValue)context.get("creditCard");
273
274         String JavaDoc url = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.url");
275         String JavaDoc ver = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.version");
276         String JavaDoc delimited = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.delimited");
277         String JavaDoc delimiter = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.delimiter");
278         String JavaDoc method = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.method");
279         //String transType = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.type");
280
String JavaDoc emailCustomer = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.emailcustomer");
281         String JavaDoc emailMerchant = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.emailmerchant");
282         String JavaDoc testReq = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.test");
283         String JavaDoc relay = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.relay");
284         String JavaDoc login = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.login");
285         String JavaDoc transDescription = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.transdescription");
286         String JavaDoc tranKey = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.trankey");
287         String JavaDoc password = UtilProperties.getPropertyValue(configStr, "payment.authorizedotnet.password");
288
289         if (ver == null || ver.length() == 0) {
290             ver = "3.0";
291         }
292
293         if(login == null || login.length() == 0) {
294             Debug.logInfo("the login property in " + configStr + " is not configured.",module);
295         }
296
297         if(password == null || password.length() == 0) {
298             Debug.logInfo("The password property in " + configStr + " is not configured.",module);
299         }
300
301         if (ver.equals("3.1")) {
302             if (tranKey == null && tranKey.length() <= 0) {
303                 Debug.logInfo("Trankey property required for version 3.1 reverting to 3.0",module);
304                 ver = "3.0";
305             }
306         }
307
308         Properties props = new Properties();
309         props.put("url", url);
310         props.put("ver", ver);
311         props.put("delimited", delimited);
312         props.put("delimiter", delimiter);
313         props.put("method", method);
314         //props.put("transType", transType);
315
props.put("emailCustomer", emailCustomer);
316         props.put("emailMerchant", emailMerchant);
317         props.put("testReq", testReq);
318         props.put("relay", relay);
319         props.put("transDescription", transDescription);
320         props.put("login", login);
321         props.put("password", password);
322         props.put("trankey", tranKey);
323
324         if (cc != null)
325             props.put("cardtype", (String JavaDoc)cc.get("cardType"));
326
327         if (AIMProperties == null)
328             AIMProperties = props;
329
330         Debug.logInfo("Created Authorize.Net properties file: " + props.toString(),module);
331
332         return props;
333
334     }
335
336     private static void buildMerchantInfo(Map params, Properties props, Map AIMRequest) {
337         AIMRequest.put("x_Login", props.getProperty("login"));
338         String JavaDoc trankey = props.getProperty("trankey");
339         if (trankey != null && trankey.length() > 0)
340             AIMRequest.put("x_Tran_Key",props.getProperty("trankey"));
341         AIMRequest.put("x_Password",props.getProperty("password"));
342         AIMRequest.put("x_Version", props.getProperty("ver"));
343         return;
344     }
345
346     private static void buildGatewayResponeConfig(Map params, Properties props, Map AIMRequest) {
347         AIMRequest.put("x_Delim_Data", props.getProperty("delimited"));
348         AIMRequest.put("x_Delim_Char", props.getProperty("delimiter"));
349         return;
350     }
351
352     private static void buildCustomerBillingInfo(Map params, Properties props, Map AIMRequest) {
353         try {
354             // this would be used in the case of a capture, where one of the parameters is an OrderPaymentPreference
355
if (params.get("orderPaymentPreference") != null) {
356                 GenericValue opp = (GenericValue) params.get("orderPaymentPreference");
357                 if ("CREDIT_CARD".equals(opp.getString("paymentMethodTypeId"))) {
358                     GenericValue creditCard = opp.getRelatedOne("CreditCard");
359                     AIMRequest.put("x_First_Name",UtilFormatOut.checkNull(creditCard.getString("firstNameOnCard")));
360                     AIMRequest.put("x_Last_Name",UtilFormatOut.checkNull(creditCard.getString("lastNameOnCard")));
361                     AIMRequest.put("x_Company",UtilFormatOut.checkNull(creditCard.getString("companyNameOnCard")));
362                     if (UtilValidate.isNotEmpty(creditCard.getString("contactMechId"))) {
363                         GenericValue address = creditCard.getRelatedOne("PostalAddress");
364                         AIMRequest.put("x_Address",UtilFormatOut.checkNull(address.getString("address1")));
365                         AIMRequest.put("x_City",UtilFormatOut.checkNull(address.getString("city")));
366                         AIMRequest.put("x_State",UtilFormatOut.checkNull(address.getString("stateProvinceGeoId")));
367                         AIMRequest.put("x_Zip",UtilFormatOut.checkNull(address.getString("postalCode")));
368                         AIMRequest.put("x_Country",UtilFormatOut.checkNull(address.getString("countryGeoId")));
369                     }
370                 } else {
371                     Debug.logWarning("Payment preference " + opp + " is not a credit card", module);
372                 }
373             } else {
374                 // this would be the case for an authorization
375
GenericValue cp = (GenericValue)params.get("billToParty");
376                 GenericValue ba = (GenericValue)params.get("billingAddress");
377
378                 AIMRequest.put("x_First_Name",UtilFormatOut.checkNull(cp.getString("firstName")));
379                 AIMRequest.put("x_Last_Name",UtilFormatOut.checkNull(cp.getString("lastName")));
380                 AIMRequest.put("x_Address",UtilFormatOut.checkNull(ba.getString("address1")));
381                 AIMRequest.put("x_City",UtilFormatOut.checkNull(ba.getString("city")));
382                 AIMRequest.put("x_State",UtilFormatOut.checkNull(ba.getString("stateProvinceGeoId")));
383                 AIMRequest.put("x_Zip",UtilFormatOut.checkNull(ba.getString("postalCode")));
384                 AIMRequest.put("x_Country",UtilFormatOut.checkNull(ba.getString("countryGeoId")));
385             }
386             return;
387     
388         } catch (GenericEntityException ex) {
389             Debug.logError("Cannot build customer information for " + params + " due to error: " + ex.getMessage(), module);
390             return;
391         }
392     }
393
394     private static void buildEmailSettings(Map params, Properties props, Map AIMRequest) {
395         GenericValue ea = (GenericValue)params.get("billToEmail");
396         AIMRequest.put("x_Email_Customer", props.getProperty("emailCustomer"));
397         AIMRequest.put("x_Email_Merchant", props.getProperty("emailMerchant"));
398
399         if (ea != null)
400             AIMRequest.put("x_Email",UtilFormatOut.checkNull(ea.getString("infoString")));
401         return;
402     }
403
404     private static void buildInvoiceInfo(Map params, Properties props, Map AIMRequest) {
405         String JavaDoc description = (String JavaDoc) UtilFormatOut.checkNull(props.getProperty("transDescription"));
406         String JavaDoc orderId = (String JavaDoc) UtilFormatOut.checkNull((String JavaDoc)params.get("orderId"));
407         AIMRequest.put("x_Invoice_Num","Order " + orderId);
408         AIMRequest.put("x_Description", description);
409         return;
410     }
411
412     private static void buildAuthTransaction(Map params, Properties props, Map AIMRequest) {
413         GenericValue cc = (GenericValue)params.get("creditCard");
414         String JavaDoc currency = (String JavaDoc) params.get("currency");
415         String JavaDoc amount = ((Double JavaDoc)params.get("processAmount")).toString();
416         String JavaDoc number = (String JavaDoc) UtilFormatOut.checkNull(cc.getString("cardNumber"));
417         String JavaDoc expDate = (String JavaDoc) UtilFormatOut.checkNull(cc.getString("expireDate"));
418
419         AIMRequest.put("x_Amount",amount);
420         AIMRequest.put("x_Currency_Code",currency);
421         AIMRequest.put("x_Method", props.getProperty("method"));
422         AIMRequest.put("x_Type", props.getProperty("transType"));
423         AIMRequest.put("x_Card_Num",number);
424         AIMRequest.put("x_Exp_Date",expDate);
425     }
426
427     private static void buildCaptureTransaction(Map params, Properties props, Map AIMRequest) {
428
429         GenericValue at = (GenericValue)params.get("authTransaction");
430         GenericValue cc = (GenericValue)params.get("creditCard");
431         String JavaDoc currency = (String JavaDoc) params.get("currency");
432         String JavaDoc amount = ((Double JavaDoc)params.get("captureAmount")).toString();
433         String JavaDoc number = (String JavaDoc) UtilFormatOut.checkNull(cc.getString("cardNumber"));
434         String JavaDoc expDate = (String JavaDoc) UtilFormatOut.checkNull(cc.getString("expireDate"));
435
436         AIMRequest.put("x_Amount",amount);
437         AIMRequest.put("x_Currency_Code",currency);
438         AIMRequest.put("x_Method", props.getProperty("method"));
439         AIMRequest.put("x_Type", props.getProperty("transType"));
440         AIMRequest.put("x_Card_Num",number);
441         AIMRequest.put("x_Exp_Date",expDate);
442         AIMRequest.put("x_Trans_ID",at.get("referenceNum"));
443         AIMRequest.put("x_Auth_Code",at.get("gatewayCode"));
444     }
445
446     private static void buildRefundTransaction(Map params, Properties props, Map AIMRequest) {
447         GenericValue at = (GenericValue)params.get("authTransaction");
448         GenericValue cc = (GenericValue)params.get("creditCard");
449         String JavaDoc currency = (String JavaDoc) params.get("currency");
450         String JavaDoc amount = ((Double JavaDoc)params.get("refundAmount")).toString();
451         String JavaDoc number = (String JavaDoc) UtilFormatOut.checkNull(cc.getString("cardNumber"));
452         String JavaDoc expDate = (String JavaDoc) UtilFormatOut.checkNull(cc.getString("expireDate"));
453
454         AIMRequest.put("x_Amount",amount);
455         AIMRequest.put("x_Currency_Code",currency);
456         AIMRequest.put("x_Method", props.getProperty("method"));
457         AIMRequest.put("x_Type", props.getProperty("transType"));
458         AIMRequest.put("x_Card_Num",number);
459         AIMRequest.put("x_Exp_Date",expDate);
460         AIMRequest.put("x_Trans_ID",at.get("referenceNum"));
461         AIMRequest.put("x_Auth_Code",at.get("gatewayCode"));
462
463         Debug.logInfo("buildCaptureTransaction. " + at.toString(),module);
464     }
465
466     private static Map validateRequest(Map params, Properties props, Map AIMRequest) {
467         Map result = new HashMap();
468         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
469         return result;
470     }
471
472
473     private static void processAuthTransResult(Map reply, Map results) {
474         String JavaDoc version = getVersion();
475         AuthorizeResponse ar = (AuthorizeResponse)reply.get("authorizeResponse");
476         Boolean JavaDoc authResult = (Boolean JavaDoc)reply.get("authResult");
477         results.put("authResult", new Boolean JavaDoc(authResult.booleanValue()));
478         results.put("authFlag",ar.getReasonCode());
479         results.put("authMessage",ar.getReasonText());
480
481
482         if(authResult.booleanValue()) { //passed
483
results.put("authCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
484             results.put("authRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
485             results.put("cvCode", ar.getResponseField(AuthorizeResponse.CID_RESPONSE_CODE));
486             results.put("avsCode", ar.getResponseField(AuthorizeResponse.AVS_RESULT_CODE));
487             results.put("processAmount", new Double JavaDoc((String JavaDoc)ar.getResponseField(AuthorizeResponse.AMOUNT)));
488         } else {
489             results.put("authCode", ar.getResponseCode());
490             results.put("processAmount", new Double JavaDoc("0.00"));
491             results.put("authRefNum", AuthorizeResponse.ERROR);
492
493         }
494
495         Debug.logInfo("processAuthTransResult: " + results.toString(),module);
496     }
497
498     private static void processCaptureTransResult(Map reply, Map results) {
499         AuthorizeResponse ar = (AuthorizeResponse)reply.get("authorizeResponse");
500         Boolean JavaDoc captureResult = (Boolean JavaDoc)reply.get("authResult");
501         results.put("captureResult", new Boolean JavaDoc(captureResult.booleanValue()));
502         results.put("captureFlag",ar.getReasonCode());
503         results.put("captureMessage",ar.getReasonText());
504
505         if(captureResult.booleanValue()) { //passed
506
results.put("captureCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
507             results.put("captureRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
508             results.put("captureAmount", new Double JavaDoc((String JavaDoc)ar.getResponseField(AuthorizeResponse.AMOUNT)));
509         } else {
510             results.put("captureAmount", new Double JavaDoc("0.00"));
511
512         }
513
514         Debug.logInfo("processCaptureTransResult: " + results.toString(),module);
515     }
516
517     private static void processRefundTransResult(Map reply, Map results) {
518         AuthorizeResponse ar = (AuthorizeResponse)reply.get("authorizeResponse");
519         Boolean JavaDoc captureResult = (Boolean JavaDoc)reply.get("authResult");
520         results.put("refundResult", new Boolean JavaDoc(captureResult.booleanValue()));
521         results.put("refundFlag",ar.getReasonCode());
522         results.put("refundMessage",ar.getReasonText());
523
524         if(captureResult.booleanValue()) { //passed
525
results.put("refundCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
526             results.put("refundRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
527             results.put("refundAmount", new Double JavaDoc((String JavaDoc)ar.getResponseField(AuthorizeResponse.AMOUNT)));
528         } else {
529             results.put("refundAmount", new Double JavaDoc("0.00"));
530
531         }
532
533         Debug.logInfo("processRefundTransResult: " + results.toString(),module);
534     }
535
536     private static void processAuthCaptureTransResult(Map reply, Map results) {
537         AuthorizeResponse ar = (AuthorizeResponse)reply.get("authorizeResponse");
538         Boolean JavaDoc authResult = (Boolean JavaDoc)reply.get("authResult");
539         results.put("authResult", new Boolean JavaDoc(authResult.booleanValue()));
540         results.put("authFlag",ar.getReasonCode());
541         results.put("authMessage",ar.getReasonText());
542         results.put("captureResult", new Boolean JavaDoc(authResult.booleanValue()));
543         results.put("captureFlag",ar.getReasonCode());
544         results.put("captureMessage",ar.getReasonText());
545
546         if(authResult.booleanValue()) { //passed
547
results.put("authCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
548             results.put("authRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
549             results.put("captureRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
550             results.put("cvCode", ar.getResponseField(AuthorizeResponse.CID_RESPONSE_CODE));
551             results.put("avsCode", ar.getResponseField(AuthorizeResponse.AVS_RESULT_CODE));
552             results.put("processAmount", new Double JavaDoc((String JavaDoc)ar.getResponseField(AuthorizeResponse.AMOUNT)));
553         } else {
554             results.put("authCode", ar.getResponseCode());
555             results.put("processAmount", new Double JavaDoc("0.00"));
556             results.put("authRefNum", AuthorizeResponse.ERROR);
557         }
558
559         Debug.logInfo("processAuthTransResult: " + results.toString(),module);
560     }
561 }
562
Popular Tags