001: /*
002: * $Id: IcsPaymentServices.java,v 1.9 2004/02/05 21:39:39 ajzeneski Exp $
003: *
004: * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.accounting.thirdparty.cybersource;
026:
027: import java.util.*;
028: import java.text.DecimalFormat;
029:
030: import org.ofbiz.service.DispatchContext;
031: import org.ofbiz.service.ServiceUtil;
032: import org.ofbiz.entity.GenericValue;
033: import org.ofbiz.entity.GenericEntityException;
034: import org.ofbiz.base.util.*;
035: import org.ofbiz.accounting.payment.PaymentGatewayServices;
036:
037: import com.cybersource.ws.client.axis.basic.Client;
038: import com.cybersource.ws.client.axis.basic.BasicClientException;
039: import com.cybersource.ws.client.axis.AxisFaultException;
040:
041: /**
042: * CyberSource WS Integration Services
043: *
044: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
045: * @version $Revision: 1.9 $
046: * @since 3.0
047: */
048: public class IcsPaymentServices {
049:
050: public static final String module = IcsPaymentServices.class
051: .getName();
052:
053: // load the JSSE properties
054: static {
055: SSLUtil.loadJsseProperties();
056: }
057:
058: public static Map ccAuth(DispatchContext dctx, Map context) {
059: // generate the request/properties
060: Properties props = buildCsProperties(context);
061: Map request = buildAuthRequest(context);
062: request.put("merchantID", props.get("merchantID"));
063:
064: // transmit the request
065: Map reply = null;
066: try {
067: reply = Client.runTransaction(request, props);
068: } catch (AxisFaultException e) {
069: Debug
070: .logError(
071: e,
072: "ERROR: Exception from Axis to CyberSource",
073: module);
074: Debug.logError(e.getAxisFault(), "Axis Fault : "
075: + e.getAxisFault().getFaultString(), module);
076: return ServiceUtil
077: .returnError("Unable to communicate with CyberSource");
078: } catch (BasicClientException e) {
079: Debug.logError(e, "ERROR: CyberSource Client exception : "
080: + e.getMessage(), module);
081: return ServiceUtil
082: .returnError("Unable to communicate with CyberSource");
083: }
084:
085: // process the reply
086: Map result = ServiceUtil.returnSuccess();
087: processAuthResult(reply, result);
088: return result;
089: }
090:
091: public static Map ccReAuth(DispatchContext dctx, Map context) {
092: return ServiceUtil.returnSuccess();
093: }
094:
095: public static Map ccCapture(DispatchContext dctx, Map context) {
096: GenericValue orderPaymentPreference = (GenericValue) context
097: .get("orderPaymentPreference");
098: GenericValue authTransaction = PaymentGatewayServices
099: .getAuthTransaction(orderPaymentPreference);
100: if (authTransaction == null) {
101: return ServiceUtil
102: .returnError("No authorization transaction found for the OrderPaymentPreference; cannot capture");
103: }
104:
105: // generate the request/properties
106: Properties props = buildCsProperties(context);
107: Map request = buildCaptureRequest(context, authTransaction);
108: request.put("merchantID", props.get("merchantID"));
109:
110: // transmit the request
111: Map reply = null;
112: try {
113: reply = Client.runTransaction(request, props);
114: } catch (AxisFaultException e) {
115: Debug
116: .logError(
117: e,
118: "ERROR: Exception from Axis to CyberSource",
119: module);
120: return ServiceUtil
121: .returnError("Unable to communicate with CyberSource");
122: } catch (BasicClientException e) {
123: Debug.logError(e, "ERROR: CyberSource Client exception : "
124: + e.getMessage(), module);
125: return ServiceUtil
126: .returnError("Unable to communicate with CyberSource");
127: }
128:
129: // process the reply
130: Map result = ServiceUtil.returnSuccess();
131: processCaptureResult(reply, result);
132: return result;
133: }
134:
135: public static Map ccRelease(DispatchContext dctx, Map context) {
136: GenericValue orderPaymentPreference = (GenericValue) context
137: .get("orderPaymentPreference");
138: GenericValue authTransaction = PaymentGatewayServices
139: .getAuthTransaction(orderPaymentPreference);
140: if (authTransaction == null) {
141: return ServiceUtil
142: .returnError("No authorization transaction found for the OrderPaymentPreference; cannot release");
143: }
144:
145: // generate the request/properties
146: Properties props = buildCsProperties(context);
147: Map request = buildReleaseRequest(context, authTransaction);
148: request.put("merchantID", props.get("merchantID"));
149:
150: // transmit the request
151: Map reply = null;
152: try {
153: reply = Client.runTransaction(request, props);
154: } catch (AxisFaultException e) {
155: Debug
156: .logError(
157: e,
158: "ERROR: Exception from Axis to CyberSource",
159: module);
160: return ServiceUtil
161: .returnError("Unable to communicate with CyberSource");
162: } catch (BasicClientException e) {
163: Debug.logError(e, "ERROR: CyberSource Client exception : "
164: + e.getMessage(), module);
165: return ServiceUtil
166: .returnError("Unable to communicate with CyberSource");
167: }
168:
169: // process the reply
170: Map result = ServiceUtil.returnSuccess();
171: processReleaseResult(reply, result);
172: return result;
173: }
174:
175: public static Map ccRefund(DispatchContext dctx, Map context) {
176: GenericValue orderPaymentPreference = (GenericValue) context
177: .get("orderPaymentPreference");
178: GenericValue authTransaction = PaymentGatewayServices
179: .getAuthTransaction(orderPaymentPreference);
180: if (authTransaction == null) {
181: return ServiceUtil
182: .returnError("No authorization transaction found for the OrderPaymentPreference; cannot refund");
183: }
184:
185: // generate the request/properties
186: Properties props = buildCsProperties(context);
187: Map request = buildRefundRequest(context, authTransaction);
188: request.put("merchantID", props.get("merchantID"));
189:
190: // transmit the request
191: Map reply = null;
192: try {
193: reply = Client.runTransaction(request, props);
194: } catch (AxisFaultException e) {
195: Debug
196: .logError(
197: e,
198: "ERROR: Exception from Axis to CyberSource",
199: module);
200: return ServiceUtil
201: .returnError("Unable to communicate with CyberSource");
202: } catch (BasicClientException e) {
203: Debug.logError(e, "ERROR: CyberSource Client exception : "
204: + e.getMessage(), module);
205: return ServiceUtil
206: .returnError("Unable to communicate with CyberSource");
207: }
208:
209: // process the reply
210: Map result = ServiceUtil.returnSuccess();
211: processRefundResult(reply, result);
212: return result;
213: }
214:
215: public static Map ccCredit(DispatchContext dctx, Map context) {
216: // generate the request/properties
217: Properties props = buildCsProperties(context);
218: Map request = buildCreditRequest(context);
219: request.put("merchantID", props.get("merchantID"));
220:
221: // transmit the request
222: Map reply = null;
223: try {
224: reply = Client.runTransaction(request, props);
225: } catch (AxisFaultException e) {
226: Debug
227: .logError(
228: e,
229: "ERROR: Exception from Axis to CyberSource",
230: module);
231: return ServiceUtil
232: .returnError("Unable to communicate with CyberSource");
233: } catch (BasicClientException e) {
234: Debug.logError(e, "ERROR: CyberSource Client exception : "
235: + e.getMessage(), module);
236: return ServiceUtil
237: .returnError("Unable to communicate with CyberSource");
238: }
239:
240: // process the reply
241: Map result = ServiceUtil.returnSuccess();
242: processCreditResult(reply, result);
243: return result;
244: }
245:
246: private static Properties buildCsProperties(Map context) {
247: String configString = (String) context.get("paymentConfig");
248: if (configString == null) {
249: configString = "payment.properties";
250: }
251:
252: String merchantId = UtilProperties.getPropertyValue(
253: configString, "payment.cybersource.merchantID");
254: String serverUrl = UtilProperties.getPropertyValue(
255: configString, "payment.cybersource.serverURL");
256:
257: String keysPath = UtilProperties.getPropertyValue(configString,
258: "payment.cybersource.keysDir");
259: String keysFile = UtilProperties.getPropertyValue(configString,
260: "payment.cybersource.keysFile");
261: String demo = UtilProperties.getPropertyValue(configString,
262: "payment.cybersource.demo", "N");
263: demo = "Y".equalsIgnoreCase(demo) ? "true" : "false";
264:
265: // create some properties for CS Client
266: Properties props = new Properties();
267: props.put("merchantID", merchantId);
268: props.put("cybersourceURL", serverUrl);
269: props.put("keysDir", keysPath);
270:
271: if (keysFile != null && keysFile.length() > 0) {
272: props.put("keyFilename", keysFile);
273: }
274: props.put("demo", demo);
275: //Debug.logInfo("Created CyberSource Properties : " + props, module);
276:
277: return props;
278: }
279:
280: private static Map buildAuthRequest(Map context) {
281: // make the request map
282: String orderId = (String) context.get("orderId");
283: Map request = new HashMap();
284: request.put("ccAuthService_run", "true"); // run auth service
285: request.put("merchantReferenceCode", orderId); // set the order ref number
286: appendFullBillingInfo(request, context); // add in all address info
287: appendItemLineInfo(request, context, "processAmount"); // add in the item info
288: appendAvsRules(request, context); // add in the AVS flags and decline codes
289: return request;
290: }
291:
292: private static Map buildCaptureRequest(Map context,
293: GenericValue authTransaction) {
294: GenericValue orderPaymentPreference = (GenericValue) context
295: .get("orderPaymentPreference");
296: String configString = (String) context.get("paymentConfig");
297: String currency = (String) context.get("currency");
298: if (configString == null) {
299: configString = "payment.properties";
300: }
301: String merchantDesc = UtilProperties
302: .getPropertyValue(configString,
303: "payment.cybersource.merchantDescr", null);
304: String merchantCont = UtilProperties.getPropertyValue(
305: configString, "payment.cybersource.merchantContact",
306: null);
307:
308: Map request = new HashMap();
309: request.put("ccCaptureService_run", "true");
310: request.put("ccCaptureService_authRequestID", authTransaction
311: .getString("referenceNum"));
312: request.put("item_0_unitPrice", getAmountString(context,
313: "captureAmount"));
314: request.put("merchantReferenceCode", orderPaymentPreference
315: .getString("orderId"));
316: request.put("purchaseTotals_currency", currency);
317:
318: // TODO: add support for verbal authorizations
319: //request.put("ccCaptureService_authType", null); -- should be 'verbal'
320: //request.put("ccCaptureService_verbalAuthCode", null); -- code from verbal auth
321:
322: if (merchantDesc != null) {
323: request.put("invoiceHeader_merchantDescriptor",
324: merchantDesc); // merchant description
325: }
326: if (merchantCont != null) {
327: request.put("invoiceHeader_merchantDescriptorContact",
328: merchantCont); // merchant contact info
329: }
330:
331: return request;
332: }
333:
334: private static Map buildReleaseRequest(Map context,
335: GenericValue authTransaction) {
336: GenericValue orderPaymentPreference = (GenericValue) context
337: .get("orderPaymentPreference");
338: String currency = (String) context.get("currency");
339: Map request = new HashMap();
340: request.put("ccAuthReversalService_run", "true");
341: request.put("ccAuthReversalService_authRequestID",
342: authTransaction.getString("referenceNum"));
343: request.put("item_0_unitPrice", getAmountString(context,
344: "releaseAmount"));
345: request.put("merchantReferenceCode", orderPaymentPreference
346: .getString("orderId"));
347: request.put("purchaseTotals_currency", currency);
348: return request;
349: }
350:
351: private static Map buildRefundRequest(Map context,
352: GenericValue authTransaction) {
353: GenericValue orderPaymentPreference = (GenericValue) context
354: .get("orderPaymentPreference");
355: String configString = (String) context.get("paymentConfig");
356: String currency = (String) context.get("currency");
357: if (configString == null) {
358: configString = "payment.properties";
359: }
360: String merchantDesc = UtilProperties
361: .getPropertyValue(configString,
362: "payment.cybersource.merchantDescr", null);
363: String merchantCont = UtilProperties.getPropertyValue(
364: configString, "payment.cybersource.merchantContact",
365: null);
366:
367: Map request = new HashMap();
368: request.put("ccCreditService_run", "true");
369: request.put("ccCreditService_captureRequestID", authTransaction
370: .getString("referenceNum"));
371: request.put("item_0_unitPrice", getAmountString(context,
372: "refundAmount"));
373: request.put("merchantReferenceCode", orderPaymentPreference
374: .getString("orderId"));
375: request.put("purchaseTotals_currency", currency);
376:
377: if (merchantDesc != null) {
378: request.put("invoiceHeader_merchantDescriptor",
379: merchantDesc); // merchant description
380: }
381: if (merchantCont != null) {
382: request.put("invoiceHeader_merchantDescriptorContact",
383: merchantCont); // merchant contact info
384: }
385:
386: return request;
387: }
388:
389: private static Map buildCreditRequest(Map context) {
390: String refCode = (String) context.get("referenceCode");
391: Map request = new HashMap();
392: request.put("ccCreditService_run", "true"); // run credit service
393: request.put("merchantReferenceCode", refCode); // set the ref number could be order id
394: appendFullBillingInfo(request, context); // add in all address info
395: appendItemLineInfo(request, context, "creditAmount"); // add in the item info
396: return request;
397: }
398:
399: private static void appendAvsRules(Map request, Map context) {
400: String configString = (String) context.get("paymentConfig");
401: if (configString == null) {
402: configString = "payment.properties";
403: }
404: String avsCodes = UtilProperties.getPropertyValue(configString,
405: "payment.cybersource.avsDeclineCodes", null);
406:
407: GenericValue person = (GenericValue) context
408: .get("contactPerson");
409: if (person != null) {
410: GenericValue avsOverride = null;
411:
412: try {
413: avsOverride = person.getDelegator().findByPrimaryKey(
414: "PartyIcsAvsOverride",
415: UtilMisc.toMap("partyId", person
416: .getString("partyId")));
417: } catch (GenericEntityException e) {
418: Debug.logError(e, module);
419: }
420: if (avsOverride != null
421: && avsOverride.get("avsDeclineString") != null) {
422: String overrideString = avsOverride
423: .getString("avsDeclineString");
424: if (overrideString != null
425: && overrideString.length() > 0) {
426: avsCodes = overrideString;
427: }
428: }
429: }
430:
431: if (avsCodes != null && avsCodes.length() > 0) {
432: request.put("businessRules_declineAVSFlags", avsCodes);
433: }
434:
435: String avsIgnore = UtilProperties.getPropertyValue(
436: configString, "payment.cybersource.avsDeclineCodes",
437: "N");
438: avsIgnore = "Y".equalsIgnoreCase(avsIgnore) ? "true" : "false";
439: request.put("businessRules_ignoreAVS", avsIgnore);
440: }
441:
442: private static void appendFullBillingInfo(Map request, Map context) {
443: // person info
444: GenericValue person = (GenericValue) context
445: .get("contactPerson");
446: request.put("billTo_firstName", person.getString("firstName"));
447: request.put("billTo_lastName", person.getString("lastName"));
448:
449: // contact info
450: GenericValue email = (GenericValue) context.get("contactEmail");
451: if (email != null) {
452: request.put("billTo_email", email.getString("infoString"));
453: } else {
454: Debug
455: .logWarning(
456: "Email not defined; Cybersource will fail.",
457: module);
458: }
459:
460: // phone number seems to not be used; possibly only for reporting.
461:
462: // payment Info
463: GenericValue creditCard = (GenericValue) context
464: .get("creditCard");
465: if (creditCard != null) {
466: List expDateList = StringUtil.split(creditCard
467: .getString("expireDate"), "/");
468:
469: request.put("card_accountNumber", creditCard
470: .getString("cardNumber"));
471: request.put("card_expirationMonth", expDateList.get(0));
472: request.put("card_expirationYear", expDateList.get(1));
473: } else {
474: Debug.logWarning(
475: "CreditCard not defined; Cybersource will fail.",
476: module);
477: }
478:
479: // payment contact info
480: GenericValue billingAddress = (GenericValue) context
481: .get("billingAddress");
482:
483: if (billingAddress != null) {
484: request.put("billTo_street1", billingAddress
485: .getString("address1"));
486: if (billingAddress.get("address2") != null) {
487: request.put("billTo_street2", billingAddress
488: .getString("address2"));
489: }
490: request
491: .put("billTo_city", billingAddress
492: .getString("city"));
493: String bCountry = billingAddress.get("countryGeoId") != null ? billingAddress
494: .getString("countryGeoId")
495: : "USA";
496:
497: request.put("billTo_country", bCountry);
498: request.put("billTo_postalCode", billingAddress
499: .getString("postalCode"));
500: if (billingAddress.get("stateProvinceGeoId") != null) {
501: request.put("billTo_state", billingAddress
502: .getString("stateProvinceGeoId"));
503: }
504: } else {
505: Debug
506: .logWarning(
507: "BillingAddress not defined; Cybersource will fail.",
508: module);
509: }
510:
511: // order shipping information
512: GenericValue shippingAddress = (GenericValue) context
513: .get("shippingAddress");
514: if (shippingAddress != null) {
515: // TODO: add first/last name
516: //request.put("shipTo_firstName", "");
517: //request.put("shipTo_lastName", "");
518:
519: request.put("shipTo_street1", shippingAddress
520: .getString("address1"));
521: if (shippingAddress.get("address2") != null) {
522: request.put("shipTo_street2", shippingAddress
523: .getString("address2"));
524: }
525: request.put("shipTo_city", shippingAddress
526: .getString("city"));
527: String sCountry = shippingAddress.get("countryGeoId") != null ? shippingAddress
528: .getString("countryGeoId")
529: : "USA";
530:
531: request.put("shipTo_country", sCountry);
532: request.put("shipTo_postalCode", shippingAddress
533: .getString("postalCode"));
534: if (shippingAddress.get("stateProvinceGeoId") != null) {
535: request.put("shipTo_state", shippingAddress
536: .getString("stateProvinceGeoId"));
537: }
538: }
539: }
540:
541: private static void appendItemLineInfo(Map request, Map context,
542: String amountField) {
543: // send over a line item total offer w/ the total for billing; don't trust CyberSource for calc
544: String currency = (String) context.get("currency");
545:
546: int lineNumber = 0;
547: request.put("item_" + lineNumber + "_unitPrice",
548: getAmountString(context, amountField));
549:
550: // the currency
551: request.put("purchaseTotals_currency", currency);
552:
553: // create the offers (one for each line item)
554: List orderItems = (List) context.get("orderItems");
555: if (orderItems != null) {
556: Iterator itemIterator = orderItems.iterator();
557:
558: while (itemIterator.hasNext()) {
559: lineNumber++;
560: GenericValue item = (GenericValue) itemIterator.next();
561: GenericValue product = null;
562: try {
563: product = item.getRelatedOne("Product");
564: } catch (GenericEntityException e) {
565: Debug
566: .logError(e,
567: "ERROR: Unable to get Product from OrderItem, not passing info to CyberSource");
568: }
569:
570: if (product != null) {
571: request.put("item_" + lineNumber + "_productName",
572: product.getString("productName"));
573: request.put("item_" + lineNumber + "_productSKU",
574: product.getString("productId"));
575: } else {
576: // no product; just send the item description -- non product items
577: request.put("item_" + lineNumber + "_productName",
578: item.getString("description"));
579: }
580:
581: // get the quantity..
582: Double quantity = item.getDouble("quantity");
583:
584: // test quantity if INT pass as is; if not pass as 1
585: long roundQ = Math.round(quantity.doubleValue());
586: Double rounded = new Double(new Long(roundQ).toString());
587:
588: if (rounded.doubleValue() != quantity.doubleValue()) {
589: request
590: .put("item_" + lineNumber + "_quantity",
591: "1");
592: } else {
593: request.put("", new Integer(quantity.intValue())
594: .toString());
595: }
596:
597: // set the amount to 0.0000 -- we will send a total too.
598: request.put("item_" + lineNumber + "_unitPrice",
599: "0.0000");
600: }
601: }
602: }
603:
604: private static String getAmountString(Map context,
605: String amountField) {
606: String currencyFormat = UtilProperties.getPropertyValue(
607: "general.properties", "currency.decimal.format",
608: "##0.00");
609: DecimalFormat formatter = new DecimalFormat(currencyFormat);
610: Double processAmount = (Double) context.get(amountField);
611: return formatter.format(processAmount);
612: }
613:
614: private static void processAuthResult(Map reply, Map result) {
615: String decision = getDecision(reply);
616: if ("ACCEPT".equalsIgnoreCase(decision)) {
617: result.put("authCode", reply
618: .get("ccAuthReply_authorizationCode"));
619: result.put("authResult", new Boolean(true));
620: } else {
621: result.put("authCode", decision);
622: result.put("authResult", new Boolean(false));
623: }
624:
625: if (reply.get("ccAuthReply_amount") != null) {
626: result.put("processAmount", new Double((String) reply
627: .get("ccAuthReply_amount")));
628: } else {
629: result.put("processAmount", new Double(0.00));
630: }
631:
632: result.put("authRefNum", reply.get("requestID"));
633: result.put("authFlag", reply.get("ccAuthReply_reasonCode"));
634: result.put("authMessage", reply
635: .get("ccAuthReply_processorResponse"));
636: result.put("avsCode", reply.get("ccAuthReply_avsCode"));
637: result
638: .put("scoreCode", reply
639: .get("ccAuthReply_authFactorCode"));
640: }
641:
642: private static void processCaptureResult(Map reply, Map result) {
643: String decision = getDecision(reply);
644: if ("ACCEPT".equalsIgnoreCase(decision)) {
645: result.put("captureResult", new Boolean(true));
646: } else {
647: result.put("captureResult", new Boolean(false));
648: }
649:
650: if (reply.get("ccCaptureReply_amount") != null) {
651: result.put("captureAmount", new Double((String) reply
652: .get("ccCaptureReply_amount")));
653: } else {
654: result.put("captureAmount", new Double(0.00));
655: }
656:
657: result.put("captureRefNum", reply.get("requestID"));
658: result.put("captureCode", reply
659: .get("ccCaptureReply_reconciliationID"));
660: result.put("captureFlag", reply
661: .get("ccCaptureReply_reasonCode"));
662: result.put("captureMessage", reply.get("decision"));
663: }
664:
665: private static void processReleaseResult(Map reply, Map result) {
666: String decision = getDecision(reply);
667: if ("ACCEPT".equalsIgnoreCase(decision)) {
668: result.put("releaseResult", new Boolean(true));
669: } else {
670: result.put("releaseResult", new Boolean(false));
671: }
672:
673: if (reply.get("ccAuthReversalReply_amount") != null) {
674: result.put("releaseAmount", new Double((String) reply
675: .get("ccAuthReversalReply_amount")));
676: } else {
677: result.put("releaseAmount", new Double(0.00));
678: }
679:
680: result.put("releaseRefNum", reply.get("requestID"));
681: result.put("releaseCode", reply
682: .get("ccAuthReversalReply_authorizationCode"));
683: result.put("releaseFlag", reply
684: .get("ccAuthReversalReply_reasonCode"));
685: result.put("releaseMessage", reply.get("decision"));
686: }
687:
688: private static void processRefundResult(Map reply, Map result) {
689: String decision = getDecision(reply);
690: if ("ACCEPT".equalsIgnoreCase(decision)) {
691: result.put("refundResult", new Boolean(true));
692: } else {
693: result.put("refundResult", new Boolean(false));
694: }
695:
696: if (reply.get("ccCreditReply_amount") != null) {
697: result.put("refundAmount", new Double((String) reply
698: .get("ccCreditReply_amount")));
699: } else {
700: result.put("refundAmount", new Double(0.00));
701: }
702:
703: result.put("refundRefNum", reply.get("requestID"));
704: result.put("refundCode", reply
705: .get("ccCreditReply_reconciliationID"));
706: result.put("refundFlag", reply.get("ccCreditReply_reasonCode"));
707: result.put("refundMessage", reply.get("decision"));
708: }
709:
710: private static void processCreditResult(Map reply, Map result) {
711: String decision = (String) reply.get("decision");
712: if ("ACCEPT".equalsIgnoreCase(decision)) {
713: result.put("creditResult", new Boolean(true));
714: } else {
715: result.put("creditResult", new Boolean(false));
716: }
717:
718: if (reply.get("ccCreditReply_amount") != null) {
719: result.put("creditAmount", new Double((String) reply
720: .get("ccCreditReply_amount")));
721: } else {
722: result.put("creditAmount", new Double(0.00));
723: }
724:
725: result.put("creditRefNum", reply.get("requestID"));
726: result.put("creditCode", reply
727: .get("ccCreditReply_reconciliationID"));
728: result.put("creditFlag", reply.get("ccCreditReply_reasonCode"));
729: result.put("creditMessage", reply.get("decision"));
730: }
731:
732: private static String getDecision(Map reply) {
733: String decision = (String) reply.get("decision");
734: String reasonCode = (String) reply.get("reasonCode");
735: if (!"ACCEPT".equalsIgnoreCase(decision)) {
736: Debug.logInfo("CyberSource : " + decision + " ("
737: + reasonCode + ")", module);
738: Debug.logInfo("Reply Dump : " + reply, module);
739: }
740: return decision;
741: }
742: }
|