📄 pcchargeservices.java
字号:
/* * $Id: PcChargeServices.java 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */package org.ofbiz.accounting.thirdparty.gosoftware;import java.util.Map;import java.util.Properties;import java.util.List;import java.text.DecimalFormat;import java.io.IOException;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.ServiceUtil;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.StringUtil;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.entity.GenericValue;import org.ofbiz.accounting.payment.PaymentGatewayServices;/** * * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version $Rev: 5462 $ * @since 3.2 */public class PcChargeServices { public static final String module = PcChargeServices.class.getName(); public static Map ccAuth(DispatchContext dctx, Map context) { Properties props = buildPccProperties(context); PcChargeApi api = getApi(props); if (api == null) { return ServiceUtil.returnError("PCCharge is not configured properly"); } try { PcChargeServices.setCreditCardInfo(api, context); } catch (GeneralException e) { return ServiceUtil.returnError(e.getMessage()); } // basic tx info api.set(PcChargeApi.TRANS_AMOUNT, getAmountString(context, "processAmount")); api.set(PcChargeApi.TICKET_NUM, context.get("orderId")); api.set(PcChargeApi.MANUAL_FLAG, "0"); api.set(PcChargeApi.PRESENT_FLAG, "1"); // command setting if ("1".equals(props.getProperty("autoBill"))) { // sale api.set(PcChargeApi.COMMAND, "1"); } else { // pre-auth api.set(PcChargeApi.COMMAND, "4"); } // send the transaction PcChargeApi out = null; try { out = api.send(); } catch (IOException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } catch (GeneralException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } if (out != null) { Map result = ServiceUtil.returnSuccess(); String resultCode = out.get(PcChargeApi.RESULT); boolean passed = false; if ("CAPTURED".equals(resultCode)) { result.put("authResult", new Boolean(true)); result.put("captureResult", new Boolean(true)); passed = true; } else if ("APPROVED".equals(resultCode)) { result.put("authCode", out.get(PcChargeApi.AUTH_CODE)); result.put("authResult", new Boolean(true)); passed = true; } else if ("PROCESSED".equals(resultCode)) { result.put("authResult", new Boolean(true)); } else { result.put("authResult", new Boolean(false)); } result.put("authRefNum", out.get(PcChargeApi.TROUTD) != null ? out.get(PcChargeApi.TROUTD) : ""); result.put("processAmount", context.get("processAmount")); result.put("authCode", out.get(PcChargeApi.AUTH_CODE)); result.put("authFlag", out.get(PcChargeApi.REFERENCE)); result.put("authMessage", out.get(PcChargeApi.RESULT)); result.put("cvCode", out.get(PcChargeApi.CVV2_CODE)); result.put("avsCode", out.get(PcChargeApi.AVS_CODE)); if (!passed) { String respMsg = out.get(PcChargeApi.RESULT) + " / " + out.get(PcChargeApi.AUTH_CODE); String refNum = out.get(PcChargeApi.TROUTD); result.put("customerRespMsgs", UtilMisc.toList(respMsg, refNum)); } if (result.get("captureResult") != null) { result.put("captureCode", out.get(PcChargeApi.AUTH_CODE)); result.put("captureFlag", out.get(PcChargeApi.REFERENCE)); result.put("captureRefNum", out.get(PcChargeApi.TROUTD)); result.put("captureMessage", out.get(PcChargeApi.RESULT)); } return result; } else { return ServiceUtil.returnError("Receive a null result from PcCharge"); } } public static Map ccCapture(DispatchContext dctx, Map context) { GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference"); //lets see if there is a auth transaction already in context GenericValue authTransaction = (GenericValue) context.get("authTrans"); if(authTransaction == null){ authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference); } if (authTransaction == null) { return ServiceUtil.returnError("No authorization transaction found for the OrderPaymentPreference; cannot capture"); } // setup the PCCharge Interface Properties props = buildPccProperties(context); PcChargeApi api = getApi(props); if (api == null) { return ServiceUtil.returnError("PCCharge is not configured properly"); } api.set(PcChargeApi.TROUTD, authTransaction.getString("referenceNum")); api.set(PcChargeApi.COMMAND, "5"); // send the transaction PcChargeApi out = null; try { out = api.send(); } catch (IOException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } catch (GeneralException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } if (out != null) { Map result = ServiceUtil.returnSuccess(); String resultCode = out.get(PcChargeApi.RESULT); if ("CAPTURED".equals(resultCode)) { result.put("captureResult", new Boolean(true)); } else { result.put("captureResult", new Boolean(false)); } result.put("captureAmount", context.get("captureAmount")); result.put("captureRefNum", out.get(PcChargeApi.TROUTD) != null ? out.get(PcChargeApi.TROUTD) : ""); result.put("captureCode", out.get(PcChargeApi.AUTH_CODE)); result.put("captureFlag", out.get(PcChargeApi.REFERENCE)); result.put("captureMessage", out.get(PcChargeApi.RESULT)); return result; } else { return ServiceUtil.returnError("Receive a null result from PcCharge"); } } public static Map ccRelease(DispatchContext dctx, Map context) { GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference"); //lets see if there is a auth transaction already in context GenericValue authTransaction = (GenericValue) context.get("authTrans"); if(authTransaction == null){ authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference); } if (authTransaction == null) { return ServiceUtil.returnError("No authorization transaction found for the OrderPaymentPreference; cannot release"); } // setup the PCCharge Interface Properties props = buildPccProperties(context); PcChargeApi api = getApi(props); if (api == null) { return ServiceUtil.returnError("PCCharge is not configured properly"); } api.set(PcChargeApi.TROUTD, authTransaction.getString("referenceNum")); api.set(PcChargeApi.COMMAND, "3"); // check to make sure we are configured for SALE mode if (!"true".equalsIgnoreCase(props.getProperty("autoBill"))) { return ServiceUtil.returnError("PCCharge does not support releasing pre-auths.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -