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

📄 valuelinkservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        }        // make sure we have a currency        if (currency == null) {            currency = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD");        }        Map redeemCtx = new HashMap();        redeemCtx.put("userLogin", userLogin);        redeemCtx.put("paymentConfig", paymentConfig);        redeemCtx.put("cardNumber", giftCard.get("cardNumber"));        redeemCtx.put("pin", giftCard.get("pinNumber"));        redeemCtx.put("currency", currency);        redeemCtx.put("orderId", orderId);        redeemCtx.put("amount", amount);        // invoke the void redeem service        Map redeemResult = null;        try {            redeemResult = dispatcher.runSync("voidRedeemGiftCard", redeemCtx);        } catch (GenericServiceException e) {            Debug.logError(e, "Problem calling the redeem service", module);            return ServiceUtil.returnError("Redeem service failed");        }        Map result = ServiceUtil.returnSuccess();        if (redeemResult != null) {            Boolean processResult = (Boolean) redeemResult.get("processResult");            result.put("releaseAmount", redeemResult.get("amount"));            result.put("releaseFlag", redeemResult.get("responseCode"));            result.put("releaseResult", processResult);            result.put("releaseCode", redeemResult.get("authCode"));            result.put("releaseRefNum", redeemResult.get("referenceNum"));        }        return result;    }    public static Map giftCardRefund(DispatchContext dctx, Map context) {        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");        String paymentConfig = (String) context.get("paymentConfig");        String currency = (String) context.get("currency");        Double amount = (Double) context.get("refundAmount");        // get the orderId for tracking        String orderId = paymentPref.getString("orderId");        // get the GiftCard VO        GenericValue giftCard = null;        try {            giftCard = paymentPref.getRelatedOne("GiftCard");        } catch (GenericEntityException e) {            Debug.logError("Unable to get GiftCard from OrderPaymentPreference", module);            return ServiceUtil.returnError("Unable to locate GiftCard Information");        }        if (giftCard == null) {            return ServiceUtil.returnError("Attempt to release GiftCard payment faild; not a valid GiftCard record");        }        // make sure we have a currency        if (currency == null) {            currency = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD");        }        Map refundCtx = new HashMap();        refundCtx.put("userLogin", userLogin);        refundCtx.put("paymentConfig", paymentConfig);        refundCtx.put("cardNumber", giftCard.get("cardNumber"));        refundCtx.put("pin", giftCard.get("pinNumber"));        refundCtx.put("currency", currency);        refundCtx.put("orderId", orderId);        refundCtx.put("amount", amount);        // invoke the refund service        Map redeemResult = null;        try {            redeemResult = dispatcher.runSync("refundGiftCard", refundCtx);        } catch (GenericServiceException e) {            Debug.logError(e, "Problem calling the refund service", module);            return ServiceUtil.returnError("Refund service failed");        }        Map result = ServiceUtil.returnSuccess();        if (redeemResult != null) {            Boolean processResult = (Boolean) redeemResult.get("processResult");            result.put("refundAmount", redeemResult.get("amount"));            result.put("refundFlag", redeemResult.get("responseCode"));            result.put("refundResult", processResult);            result.put("refundCode", redeemResult.get("authCode"));            result.put("refundRefNum", redeemResult.get("referenceNum"));        }        return result;    }    // item fulfillment wrappers (purchase/reload)    public static Map giftCardPurchase(DispatchContext dctx, Map context) {        // this service should always be called via FULFILLMENT_EXTASYNC        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericDelegator delegator = dctx.getDelegator();        GenericValue userLogin = (GenericValue) context.get("userLogin");        GenericValue orderItem = (GenericValue) context.get("orderItem");        Locale locale = (Locale) context.get("locale");        // order ID for tracking        String orderId = orderItem.getString("orderId");        // the order header for store info        GenericValue orderHeader = null;        try {            orderHeader = orderItem.getRelatedOne("OrderHeader");        } catch (GenericEntityException e) {            Debug.logError(e, "Unable to get OrderHeader from OrderItem",module);            return ServiceUtil.returnError("Unable to get OrderHeader from OrderItem");        }        // get the order read helper        OrderReadHelper orh = new OrderReadHelper(orderHeader);        // get the currency        String currency = orh.getCurrency();        // make sure we have a currency        if (currency == null) {            currency = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD");        }        // get the product store        String productStoreId = null;        if (orderHeader != null) {            productStoreId = orh.getProductStoreId();        }        if (productStoreId == null) {            return ServiceUtil.returnError("Unable to process gift card purchase; no productStoreId on OrderHeader : " + orderId);        }        // payment config        GenericValue paymentSetting = ProductStoreWorker.getProductStorePaymentSetting(delegator, productStoreId, "GIFT_CARD", null, true);        String paymentConfig = null;        if (paymentSetting != null) {            paymentConfig = paymentSetting.getString("paymentPropertiesPath");        }        if (paymentConfig == null) {            return ServiceUtil.returnError("Unable to get payment configuration file");        }        // party ID for tracking        GenericValue placingParty = orh.getPlacingParty();        String partyId = null;        if (placingParty != null) {            partyId = placingParty.getString("partyId");        }        // amount/quantity of the gift card(s)        Double amount = orderItem.getDouble("unitPrice");        Double quantity = orderItem.getDouble("quantity");        // the product entity needed for information        GenericValue product = null;        try {            product = orderItem.getRelatedOne("Product");        } catch (GenericEntityException e) {            Debug.logError("Unable to get Product from OrderItem", module);        }        if (product == null) {            return ServiceUtil.returnError("No product associated with OrderItem, cannot fulfill gift card");        }        // get the productFeature type TYPE (VL promo code)        GenericValue typeFeature = null;        try {            Map fields = UtilMisc.toMap("productId", product.get("productId"), "productFeatureTypeId", "TYPE");            List order = UtilMisc.toList("-fromDate");            List featureAppls = delegator.findByAndCache("ProductFeatureAndAppl", fields, order);            featureAppls = EntityUtil.filterByDate(featureAppls);            typeFeature = EntityUtil.getFirst(featureAppls);        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError("Unable to get the required feature type TYPE from Product");        }        if (typeFeature == null) {            return ServiceUtil.returnError("Required feature type TYPE not found for product : " + product.get("productId"));        }        // get the VL promo code        String promoCode = typeFeature.getString("idCode");        if (promoCode == null || promoCode.length() == 0) {            return ServiceUtil.returnError("Invalid promo code set on idCode field of feature type TYPE");        }        // survey information        String surveyId = UtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.purchase.surveyId");        // get the survey response        GenericValue surveyResponse = null;        try {            Map fields = UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItem.get("orderItemSeqId"), "surveyId", surveyId);            List order = UtilMisc.toList("-responseDate");            List responses = delegator.findByAnd("SurveyResponse", fields, order);            // there should be only one            surveyResponse = EntityUtil.getFirst(responses);        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError("Unable to get survey response information; cannot fulfill gift card");        }        // get the response answers        List responseAnswers = null;        try {            responseAnswers = surveyResponse.getRelated("SurveyResponseAnswer");        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError("Unable to get survey response answers from survey response; cannot fulfill gift card");        }        // make a map of answer info        Map answerMap = new HashMap();        if (responseAnswers != null) {            Iterator rai = responseAnswers.iterator();            while (rai.hasNext()) {                GenericValue answer = (GenericValue) rai.next();                GenericValue question = null;                try {                    question = answer.getRelatedOne("SurveyQuestion");                } catch (GenericEntityException e) {                    Debug.logError(e, module);                    return ServiceUtil.returnError("Unable to get survey question from answer");                }                if (question != null) {                    String desc = question.getString("description");                    String ans = answer.getString("textResponse");  // only support text response types for now                    answerMap.put(desc, ans);                }            }        }        // get the send to email address - key defined in properties file        String sendToKey = UtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.purchase.survey.sendToEmail");        String sendToEmail = (String) answerMap.get(sendToKey);        // get the copyMe flag and set the order email address        String orderEmails = orh.getOrderEmailString();        String copyMeField = UtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.purchase.survey.copyMe");        String copyMeResp = copyMeField != null ? (String) answerMap.get(copyMeField) : null;        boolean copyMe = (UtilValidate.isNotEmpty(copyMeField)                && UtilValidate.isNotEmpty(copyMeResp) && "true".equalsIgnoreCase(copyMeResp)) ? true : false;        int qtyLoop = quantity.intValue();        for (int i = 0; i < qtyLoop; i++) {            // activate a gift card            Map activateCtx = new HashMap();            activateCtx.put("paymentConfig", paymentConfig);            activateCtx.put("vlPromoCode", promoCode);            activateCtx.put("currency", currency);            activateCtx.put("partyId", partyId);            activateCtx.put("orderId", orderId);            activateCtx.put("amount", amount);            activateCtx.put("userLogin", userLogin);            boolean failure = false;            Map activateResult = null;            try {                activateResult = dispatcher.runSync("activateGiftCard", activateCtx);            } catch (GenericServiceException e) {                Debug.logError(e, "Unable to activate gift card(s)", module);                return ServiceUtil.returnError("Problem running activation service");            }            Boolean processResult = (Boolean) activateResult.get("processResult");            if (activateResult == null || activateResult.containsKey(ModelService.ERROR_MESSAGE) || !processResult.booleanValue()) {                failure = true;            }            if (!failure) {                // set the void on rollback wrapper                ServiceXaWrapper xaw = new ServiceXaWrapper(dctx);                activateCtx.put("cardNumber", activateResult.get("cardNumber"));                activateCtx.put("pin", activateResult.get("pin"));                xaw.setRollbackService("voidActivateGiftCard", activateCtx);                try {                    xaw.enlist();                } catch (XAException e) {                    Debug.logError(e, "Unable to setup Activate/Void on error", module);                }            }            // create the fulfillment record            Map vlFulFill = new HashMap();            vlFulFill.put("typeEnumId", "GC_ACTIVATE");

⌨️ 快捷键说明

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