⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ritaservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: RitaServices.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.io.IOException;import java.text.DecimalFormat;import java.sql.Timestamp;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.ServiceUtil;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.GenericServiceException;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.StringUtil;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.accounting.payment.PaymentGatewayServices;/** *  * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 5462 $ * @since      3.2 */public class RitaServices {    public static final String module = RitaServices.class.getName();    public static Map ccAuth(DispatchContext dctx, Map context) {        Properties props = buildPccProperties(context);        RitaApi api = getApi(props, "CREDIT");        if (api == null) {            return ServiceUtil.returnError("RiTA is not configured properly");        }        try {            RitaServices.setCreditCardInfo(api, dctx.getDelegator(), context);        } catch (GeneralException e) {            return ServiceUtil.returnError(e.getMessage());        }        // basic tx info        api.set(RitaApi.TRANS_AMOUNT, getAmountString(context, "processAmount"));        api.set(RitaApi.INVOICE, context.get("orderId"));        // command setting        if ("1".equals(props.getProperty("autoBill"))) {            // sale            api.set(RitaApi.COMMAND, "SALE");        } else {            // pre-auth            api.set(RitaApi.COMMAND, "PRE_AUTH");        }        // send the transaction        RitaApi out = null;        try {            Debug.log("Sending request to RiTA", module);            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(RitaApi.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(RitaApi.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(RitaApi.INTRN_SEQ_NUM) != null ? out.get(RitaApi.INTRN_SEQ_NUM) : "");            result.put("processAmount", context.get("processAmount"));            result.put("authCode", out.get(RitaApi.AUTH_CODE));            result.put("authFlag", out.get(RitaApi.REFERENCE));            result.put("authMessage", out.get(RitaApi.RESULT));            result.put("cvCode", out.get(RitaApi.CVV2_CODE));            result.put("avsCode", out.get(RitaApi.AVS_CODE));            if (!passed) {                String respMsg = out.get(RitaApi.RESULT) + " / " + out.get(RitaApi.INTRN_SEQ_NUM);                                result.put("customerRespMsgs", UtilMisc.toList(respMsg));            }            if (result.get("captureResult") != null) {                result.put("captureCode", out.get(RitaApi.AUTH_CODE));                result.put("captureFlag", out.get(RitaApi.REFERENCE));                result.put("captureRefNum", out.get(RitaApi.INTRN_SEQ_NUM));                result.put("captureMessage", out.get(RitaApi.RESULT));            }            return result;        } else {            return ServiceUtil.returnError("Receive a null result from RiTA");        }    }    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 RiTA Interface        Properties props = buildPccProperties(context);        RitaApi api = getApi(props, "CREDIT");        if (api == null) {            return ServiceUtil.returnError("RiTA is not configured properly");        }        api.set(RitaApi.ORIG_SEQ_NUM, authTransaction.getString("referenceNum"));        api.set(RitaApi.COMMAND, "COMPLETION");        // send the transaction        RitaApi 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(RitaApi.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(RitaApi.INTRN_SEQ_NUM) != null ? out.get(RitaApi.INTRN_SEQ_NUM) : "");            result.put("captureCode", out.get(RitaApi.AUTH_CODE));            result.put("captureFlag", out.get(RitaApi.REFERENCE));            result.put("captureMessage", out.get(RitaApi.RESULT));            return result;        } else {            return ServiceUtil.returnError("Receive a null result from RiTA");        }    }    public static Map ccVoidRelease(DispatchContext dctx, Map context) {        return ccVoid(dctx, context, false);    }    public static Map ccVoidRefund(DispatchContext dctx, Map context) {        return ccVoid(dctx, context, true);    }    private static Map ccVoid(DispatchContext dctx, Map context, boolean isRefund) {        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 RiTA Interface        Properties props = buildPccProperties(context);        RitaApi api = getApi(props, "CREDIT");        if (api == null) {            return ServiceUtil.returnError("RiTA is not configured properly");        }        api.set(RitaApi.TRANS_AMOUNT, getAmountString(context, isRefund ? "refundAmount" : "releaseAmount"));        api.set(RitaApi.ORIG_SEQ_NUM, authTransaction.getString("referenceNum"));        api.set(RitaApi.COMMAND, "VOID");        // check to make sure we are configured for SALE mode        if (!"1".equals(props.getProperty("autoBill"))) {            return ServiceUtil.returnError("RiTA does not support releasing pre-auths.");        }        // send the transaction        RitaApi 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(RitaApi.RESULT);            if ("VOIDED".equals(resultCode)) {                result.put(isRefund ? "refundResult" : "releaseResult", new Boolean(true));            } else {                result.put(isRefund ? "refundResult" : "releaseResult", new Boolean(false));            }            result.put(isRefund ? "refundAmount" : "releaseAmount", context.get(isRefund ? "refundAmount" : "releaseAmount"));            result.put(isRefund ? "refundRefNum" : "releaseRefNum", out.get(RitaApi.INTRN_SEQ_NUM) != null ? out.get(RitaApi.INTRN_SEQ_NUM) : "");            result.put(isRefund ? "refundCode" : "releaseCode", out.get(RitaApi.AUTH_CODE));            result.put(isRefund ? "refundFlag" : "releaseFlag", out.get(RitaApi.REFERENCE));            result.put(isRefund ? "refundMessage" : "releaseMessage", out.get(RitaApi.RESULT));            return result;        } else {            return ServiceUtil.returnError("Receive a null result from RiTA");        }    }    public static Map ccCreditRefund(DispatchContext dctx, Map context) {        GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -