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

📄 ritaservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        //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 refund");        }        // setup the RiTA Interface        Properties props = buildPccProperties(context);        RitaApi api = getApi(props, "CREDIT");        if (api == null) {            return ServiceUtil.returnError("RiTA is not configured properly");        }        // set the required cc info        try {            RitaServices.setCreditCardInfo(api, dctx.getDelegator(), context);        } catch (GeneralException e) {            return ServiceUtil.returnError(e.getMessage());        }        api.set(RitaApi.TRANS_AMOUNT, getAmountString(context, "refundAmount"));        api.set(RitaApi.ORIG_SEQ_NUM, authTransaction.getString("referenceNum"));        api.set(RitaApi.COMMAND, "CREDIT");        // 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("refundResult", new Boolean(true));            } else {                result.put("refundResult", new Boolean(false));            }            result.put("refundAmount", context.get("refundAmount"));            result.put("refundRefNum", out.get(RitaApi.INTRN_SEQ_NUM) != null ? out.get(RitaApi.INTRN_SEQ_NUM) : "");            result.put("refundCode", out.get(RitaApi.AUTH_CODE));            result.put("refundFlag", out.get(RitaApi.REFERENCE));            result.put("refundMessage", out.get(RitaApi.RESULT));            return result;        } else {            return ServiceUtil.returnError("Receive a null result from RiTA");        }    }    public static Map ccRefund(DispatchContext dctx, Map context) {        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericDelegator delegator = dctx.getDelegator();        GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");        GenericValue orderHeader = null;        try {            orderHeader = orderPaymentPreference.getRelatedOne("OrderHeader");        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError("Unable to obtain order header information from payment preference");        }        if (orderHeader != null) {            String terminalId = orderHeader.getString("terminalId");            boolean isVoid = false;            if (terminalId != null) {                Timestamp orderDate = orderHeader.getTimestamp("orderDate");                GenericValue terminalState = null;                try {                    List states = delegator.findByAnd("PosTerminalState", UtilMisc.toMap("posTerminalId", terminalId));                    states = EntityUtil.filterByDate(states, UtilDateTime.nowTimestamp(), "openedDate", "closedDate", true);                    terminalState = EntityUtil.getFirst(states);                } catch (GenericEntityException e) {                    Debug.logError(e, module);                }                // this is the current opened terminal                if (terminalState != null) {                    Timestamp openDate = terminalState.getTimestamp("openedDate");                    // if the order date is after the open date of the current state                    // the order happend within the current open/close of the terminal                    if (orderDate.after(openDate)) {                        isVoid = true;                    }                }            }            Map refundResp = null;            try {                if (isVoid) {                    refundResp = dispatcher.runSync("ritaCCVoidRefund", context);                } else {                    refundResp = dispatcher.runSync("ritaCCCreditRefund", context);                }            } catch (GenericServiceException e) {                Debug.logError(e, module);                return ServiceUtil.returnError("Service invocation exception");            }            return refundResp;        } else {            return ServiceUtil.returnError("Unable to find order information; cannot complete the refund");        }    }    private static void setCreditCardInfo(RitaApi api, GenericDelegator delegator, Map context) throws GeneralException {        GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");        GenericValue creditCard = (GenericValue) context.get("creditCard");        if (creditCard == null) {            creditCard = delegator.findByPrimaryKey("CreditCard", UtilMisc.toMap("paymentMethodId", orderPaymentPreference.getString("paymentMethodId")));        }        if (creditCard != null) {            List expDateList = StringUtil.split(creditCard.getString("expireDate"), "/");            String month = (String) expDateList.get(0);            String year = (String) expDateList.get(1);            String y2d = year.substring(2);            String title = creditCard.getString("titleOnCard");            String fname = creditCard.getString("firstNameOnCard");            String mname = creditCard.getString("middleNameOnCard");            String lname = creditCard.getString("lastNameOnCard");            String sufix = creditCard.getString("suffixOnCard");            StringBuffer name = new StringBuffer();            if (UtilValidate.isNotEmpty(title)) {                name.append(title + " ");            }            if (UtilValidate.isNotEmpty(fname)) {                name.append(fname + " ");            }            if (UtilValidate.isNotEmpty(mname)) {                name.append(mname + " ");            }            if (UtilValidate.isNotEmpty(lname)) {                name.append(lname + " ");            }            if (UtilValidate.isNotEmpty(sufix)) {                name.append(sufix);            }            String nameOnCard = name.toString().trim();            String acctNumber = creditCard.getString("cardNumber");            String cvNum = (String) context.get("cardSecurityCode");            api.set(RitaApi.ACCT_NUM, acctNumber);            api.set(RitaApi.EXP_MONTH, month);            api.set(RitaApi.EXP_YEAR, y2d);            api.set(RitaApi.CARDHOLDER, nameOnCard);            if (UtilValidate.isNotEmpty(cvNum)) {                api.set(RitaApi.CVV2, cvNum);            }            // billing address information            GenericValue billingAddress = (GenericValue) context.get("billingAddress");            if (billingAddress != null) {                api.set(RitaApi.CUSTOMER_STREET, billingAddress.getString("address1"));                api.set(RitaApi.CUSTOMER_ZIP, billingAddress.getString("postalCode"));            } else {                String zipCode = orderPaymentPreference.getString("billingPostalCode");                if (UtilValidate.isNotEmpty(zipCode)) {                    api.set(RitaApi.CUSTOMER_ZIP, zipCode);                }            }            // set the present flag            String presentFlag = orderPaymentPreference.getString("presentFlag");            if (presentFlag == null) {                presentFlag = "N";            }            api.set(RitaApi.PRESENT_FLAG, presentFlag.equals("Y") ? "3" : "1"); // 1, no present, 2 present, 3 swiped        } else {            throw new GeneralException("No CreditCard object found");        }    }    private static RitaApi getApi(Properties props) {        if (props == null) {            Debug.logError("Cannot load API w/ null properties", module);            return null;        }        String host = props.getProperty("host");        int port = 0;        try {            port = Integer.parseInt(props.getProperty("port"));        } catch (Exception e) {            Debug.logError(e, module);        }        boolean ssl = props.getProperty("ssl", "N").equals("Y") ? true : false;        RitaApi api = null;        if (port > 0 && host != null) {            api = new RitaApi(host, port, ssl);        } else {            api = new RitaApi();        }        api.set(RitaApi.CLIENT_ID, props.getProperty("clientID"));        api.set(RitaApi.USER_ID, props.getProperty("userID"));        api.set(RitaApi.USER_PW, props.getProperty("userPW"));        api.set(RitaApi.FORCE_FLAG, props.getProperty("forceTx"));        return api;    }    private static RitaApi getApi(Properties props, String paymentType) {        RitaApi api = getApi(props);        api.set(RitaApi.FUNCTION_TYPE, "PAYMENT");        api.set(RitaApi.PAYMENT_TYPE, paymentType);        return api;    }    private static Properties buildPccProperties(Map context) {        String configString = (String) context.get("paymentConfig");        if (configString == null) {            configString = "payment.properties";        }        String clientId = UtilProperties.getPropertyValue(configString, "payment.rita.clientID");        String userId = UtilProperties.getPropertyValue(configString, "payment.rita.userID");        String userPw = UtilProperties.getPropertyValue(configString, "payment.rita.userPW");        String host = UtilProperties.getPropertyValue(configString, "payment.rita.host");        String port = UtilProperties.getPropertyValue(configString, "payment.rita.port");        String ssl = UtilProperties.getPropertyValue(configString, "payment.rita.ssl", "N");        String autoBill = UtilProperties.getPropertyValue(configString, "payment.rita.autoBill", "0");        String forceTx = UtilProperties.getPropertyValue(configString, "payment.rita.forceTx", "0");        // some property checking        if (UtilValidate.isEmpty(clientId)) {            Debug.logWarning("The clientID property in [" + configString + "] is not configured", module);            return null;        }        if (UtilValidate.isEmpty(userId)) {            Debug.logWarning("The userID property in [" + configString + "] is not configured", module);            return null;        }        if (UtilValidate.isEmpty(userPw)) {            Debug.logWarning("The userPW property in [" + configString + "] is not configured", module);            return null;        }        // create some properties for CS Client        Properties props = new Properties();        props.put("clientID", clientId);        props.put("userID", userId);        props.put("userPW", userPw);        props.put("host", host);        props.put("port", port);        props.put("ssl", ssl);        props.put("autoBill", autoBill);        props.put("forceTx", forceTx);        Debug.log("Returning properties - " + props, module);        return props;    }    private static String getAmountString(Map context, String amountField) {        String currencyFormat = UtilProperties.getPropertyValue("general.properties", "currency.decimal.format", "##0.00");        DecimalFormat formatter = new DecimalFormat(currencyFormat);        Double processAmount = (Double) context.get(amountField);        return formatter.format(processAmount);    }}

⌨️ 快捷键说明

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