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

📄 paymentgatewayservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            // type credit card            GenericValue creditCard = paymentMethod.getRelatedOne("CreditCard");            GenericValue billingAddress = creditCard.getRelatedOne("PostalAddress");            toContext.put("creditCard", creditCard);            toContext.put("billingAddress", billingAddress);        } else if (paymentMethod != null && paymentMethod.getString("paymentMethodTypeId").equals("EFT_ACCOUNT")) {            // type eft            GenericValue eftAccount = paymentMethod.getRelatedOne("EftAccount");            GenericValue billingAddress = eftAccount.getRelatedOne("PostalAddress");            toContext.put("eftAccount", eftAccount);            toContext.put("billingAddress", billingAddress);        } else if (paymentMethod != null && paymentMethod.getString("paymentMethodTypeId").equals("GIFT_CARD")) {            // type gift card            GenericValue giftCard = paymentMethod.getRelatedOne("GiftCard");            toContext.put("giftCard", giftCard);        } else {            // add other payment types here; i.e. gift cards, etc.            // unknown payment type; ignoring.            Debug.logError("ERROR: Unsupported PaymentMethodType passed for authorization", module);            return null;        }        // get some contact info.        GenericValue billToPersonOrGroup = orh.getBillToParty();        GenericValue billToEmail = null;        Collection emails = ContactHelper.getContactMech(billToPersonOrGroup.getRelatedOne("Party"), "PRIMARY_EMAIL", "EMAIL_ADDRESS", false);        if (UtilValidate.isNotEmpty(emails)) {            billToEmail = (GenericValue) emails.iterator().next();        }        toContext.put("billToParty", billToPersonOrGroup);        toContext.put("billToEmail", billToEmail);        return billToPersonOrGroup.getString("partyId");    }    /**     *     * Releases authorizations through service calls to the defined processing service for the ProductStore/PaymentMethodType     * @return COMPLETE|FAILED|ERROR for complete processing of ALL payments.     */    public static Map releaseOrderPayments(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        String orderId = (String) context.get("orderId");        Map result = new HashMap();        // get the order header and payment preferences        GenericValue orderHeader = null;        List paymentPrefs = null;        try {            // first get the order header            orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));            // get the valid payment prefs            List othExpr = UtilMisc.toList(new EntityExpr("paymentMethodTypeId", EntityOperator.EQUALS, "EFT_ACCOUNT"));            othExpr.add(new EntityExpr("paymentMethodTypeId", EntityOperator.EQUALS, "CREDIT_CARD"));            othExpr.add(new EntityExpr("paymentMethodTypeId", EntityOperator.EQUALS, "GIFT_CARD"));            EntityCondition con1 = new EntityConditionList(othExpr, EntityJoinOperator.OR);            EntityCondition statExpr = new EntityExpr("statusId", EntityOperator.EQUALS, "PAYMENT_SETTLED");            EntityCondition con2 = new EntityConditionList(UtilMisc.toList(con1, statExpr), EntityOperator.AND);            EntityCondition authExpr = new EntityExpr("statusId", EntityOperator.EQUALS, "PAYMENT_AUTHORIZED");            EntityCondition con3 = new EntityConditionList(UtilMisc.toList(con2, authExpr), EntityOperator.OR);            EntityExpr orderExpr = new EntityExpr("orderId", EntityOperator.EQUALS, orderId);            EntityCondition con4 = new EntityConditionList(UtilMisc.toList(con3, orderExpr), EntityOperator.AND);            paymentPrefs = delegator.findByCondition("OrderPaymentPreference", con4, null, null);        } catch (GenericEntityException gee) {            Debug.logError(gee, "Problems getting entity record(s), see stack trace", module);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, "ERROR: Could not get order information (" + gee.getMessage() + ").");            return result;        }        // error if no order was found        if (orderHeader == null) {            return ServiceUtil.returnError("Could not find OrderHeader with orderId: " + orderId + "; not processing payments.");        }        // return complete if no payment prefs were found        if (paymentPrefs == null || paymentPrefs.size() == 0) {            Debug.logWarning("No OrderPaymentPreference records available for release", module);            result.put("processResult", "COMPLETE");            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);            return result;        }        OrderReadHelper orh = new OrderReadHelper(orderHeader);        String currency = orh.getCurrency();        // iterate over the prefs and release each one        List finished = new ArrayList();        Iterator payments = paymentPrefs.iterator();        while (payments.hasNext()) {            GenericValue paymentPref = (GenericValue) payments.next();            // look up the payment configuration settings            String serviceName = null;            String paymentConfig = null;            // get the payment settings i.e. serviceName and config properties file name            GenericValue paymentSettings = getPaymentSettings(orh.getOrderHeader(), paymentPref, RELEASE_SERVICE_TYPE, false);            if (paymentSettings != null) {                paymentConfig = paymentSettings.getString("paymentPropertiesPath");                serviceName = paymentSettings.getString("paymentService");                if (serviceName == null) {                    Debug.logWarning("No payment release service for - " + paymentPref.getString("paymentMethodTypeId"), module);                    continue; // no release service available -- has been logged                }            } else {                Debug.logWarning("No payment release settings found for - " + paymentPref.getString("paymentMethodTypeId"), module);                continue; // no release service available -- has been logged            }            if (paymentConfig == null || paymentConfig.length() == 0) {                paymentConfig = "payment.properties";            }            GenericValue authTransaction = PaymentGatewayServices.getAuthTransaction(paymentPref);            Map releaseContext = new HashMap();            releaseContext.put("orderPaymentPreference", paymentPref);            releaseContext.put("releaseAmount", authTransaction.getDouble("amount"));            releaseContext.put("currency", currency);            releaseContext.put("paymentConfig", paymentConfig);            releaseContext.put("userLogin", userLogin);            // run the defined service            Map releaseResult = null;            try {                releaseResult = dispatcher.runSync(serviceName, releaseContext, TX_TIME, true);            } catch (GenericServiceException e) {                Debug.logError(e, "Problem releasing payment", module);            }            // get the release result code            if (releaseResult != null && !ServiceUtil.isError(releaseResult)) {                Boolean releaseResponse = (Boolean) releaseResult.get("releaseResult");                // create the PaymentGatewayResponse                String responseId = delegator.getNextSeqId("PaymentGatewayResponse");                GenericValue pgResponse = delegator.makeValue("PaymentGatewayResponse", null);                pgResponse.set("paymentGatewayResponseId", responseId);                pgResponse.set("paymentServiceTypeEnumId", RELEASE_SERVICE_TYPE);                pgResponse.set("orderPaymentPreferenceId", paymentPref.get("orderPaymentPreferenceId"));                pgResponse.set("paymentMethodTypeId", paymentPref.get("paymentMethodTypeId"));                pgResponse.set("paymentMethodId", paymentPref.get("paymentMethodId"));                pgResponse.set("transCodeEnumId", "PGT_RELEASE");                // set the release info                pgResponse.set("referenceNum", releaseResult.get("releaseRefNum"));                pgResponse.set("altReference", releaseResult.get("releaseAltRefNum"));                pgResponse.set("gatewayCode", releaseResult.get("releaseCode"));                pgResponse.set("gatewayFlag", releaseResult.get("releaseFlag"));                pgResponse.set("gatewayMessage", releaseResult.get("releaseMessage"));                pgResponse.set("transactionDate", UtilDateTime.nowTimestamp());                // store the gateway response                try {                    pgResponse.create();                } catch (GenericEntityException e) {                    Debug.logError(e, "Problem storing PaymentGatewayResponse entity; authorization was released! : " + pgResponse, module);                }                // create the internal messages                List messages = (List) releaseResult.get("internalRespMsgs");                if (messages != null && messages.size() > 0) {                    Iterator i = messages.iterator();                    while (i.hasNext()) {                        GenericValue respMsg = delegator.makeValue("PaymentGatewayRespMsg", null);                        String respMsgId = delegator.getNextSeqId("PaymentGatewayRespMsg");                        String message = (String) i.next();                        respMsg.set("paymentGatewayRespMsgId", respMsgId);                        respMsg.set("paymentGatewayResponseId", responseId);                        respMsg.set("pgrMessage", message);                        try {                            delegator.create(respMsg);                        } catch (GenericEntityException e) {                            Debug.logError(e, module);                            return ServiceUtil.returnError("Unable to create PaymentGatewayRespMsg record");                        }                    }                }                if (releaseResponse != null && releaseResponse.booleanValue()) {                    paymentPref.set("statusId", "PAYMENT_CANCELLED");                    try {                        paymentPref.store();                    } catch (GenericEntityException e) {                        Debug.logError(e, "Problem storing updated payment preference; authorization was released!", module);                    }                    finished.add(paymentPref);                    // cancel any payment records                    List paymentList = null;                    try {                        paymentList = paymentPref.getRelated("Payment");                    } catch (GenericEntityException e) {                        Debug.logError(e, "Unable to get Payment records from OrderPaymentPreference : " + paymentPref, module);                    }                    if (paymentList != null) {                        Iterator pi = paymentList.iterator();                        while (pi.hasNext()) {                            GenericValue pay = (GenericValue) pi.next();                            pay.set("statusId", "PMNT_CANCELLED");                            try {                                pay.store();                            } catch (GenericEntityException e) {                                Debug.logError(e, "Unable to store Payment : " + pay, module);                            }                        }                    }                } else {                    Debug.logError("Release failed for pref : " + paymentPref, module);                }            } else if (ServiceUtil.isError(releaseResult)) {                saveError(dispatcher, userLogin, paymentPref, releaseResult, "PRDS_PAY_RELEASE", "PGT_RELEASE");            }        }        result = ServiceUtil.returnSuccess();        if (finished.size() == paymentPrefs.size()) {            result.put("processResult", "COMPLETE");        } else {            result.put("processResult", "FAILED");        }        return result;    }    /**     * Captures payments through service calls to the defined processing service for the ProductStore/PaymentMethodType     * @return COMPLETE|FAILED|ERROR for complete processing of ALL payment methods.     */    public static Map capturePaymentsByInvoice(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        String invoiceId = (String) context.get("invoiceId");        // lookup the invoice        GenericValue invoice = null;        try {            invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));        } catch (GenericEntityException e) {            Debug.logError(e, "Trouble looking up Invoice #" + invoiceId, module);            return ServiceUtil.returnError("Trouble looking up Invoice #" + invoiceId);        }

⌨️ 快捷键说明

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