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

📄 paymentgatewayservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    processResult(dctx, captureResult, userLogin, paymentPref);                } catch (GeneralException e) {                    Debug.logError(e, "Trouble processing the result; captureResult: " + captureResult, module);                    return ServiceUtil.returnError("Trouble processing the capture results");                }                // create any splits which are needed                BigDecimal totalAmountCaptured = new BigDecimal(amountThisCapture);                if (authAmount.doubleValue() > totalAmountCaptured.doubleValue()) {                    // create a new payment preference and authorize it                    double newAmount = authAmount.doubleValue() - totalAmountCaptured.doubleValue(); // TODO: use BigDecimal arithmetic here (and everywhere else for that matter)                    Debug.logInfo("Creating payment preference split", module);                    String newPrefId = delegator.getNextSeqId("OrderPaymentPreference");                    GenericValue newPref = delegator.makeValue("OrderPaymentPreference", UtilMisc.toMap("orderPaymentPreferenceId", newPrefId));                    newPref.set("orderId", paymentPref.get("orderId"));                    newPref.set("paymentMethodTypeId", paymentPref.get("paymentMethodTypeId"));                    newPref.set("paymentMethodId", paymentPref.get("paymentMethodId"));                    newPref.set("maxAmount", paymentPref.get("maxAmount"));                    newPref.set("statusId", "PAYMENT_NOT_AUTH");                    newPref.set("createdDate", UtilDateTime.nowTimestamp());                    if (userLogin != null) {                        newPref.set("createdByUserLogin", userLogin.getString("userLoginId"));                    }                    Debug.logInfo("New preference : " + newPref, module);                    try {                        // create the new payment preference                        delegator.create(newPref);                        // authorize the new preference                        Map processorResult = authPayment(dispatcher, userLogin, orh, newPref, newAmount, false);                        if (processorResult != null) {                            // process the auth results                            boolean authResult = false;                            try {                                authResult = processResult(dctx, processorResult, userLogin, newPref);                                if (!authResult) {                                    Debug.logError("Authorization failed : " + newPref + " : " + processorResult, module);                                }                            } catch (GeneralException e) {                                Debug.logError(e, "Trouble processing the auth result : " + newPref + " : " + processorResult, module);                            }                        } else {                            Debug.logError("Payment not authorized : " + newPref + " : " + processorResult, module);                        }                    } catch (GenericEntityException e) {                        Debug.logError(e, "ERROR: cannot create new payment preference : " + newPref, module);                    }                }            } else {                Debug.logError("Payment not captured", module);                continue;            }        }        if (amountToCapture > 0.00) {            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);            result.put("processResult", "FAILED");            return result;        } else {            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);            result.put("processResult", "COMPLETE");            return result;        }    }    public static Map captureBillingAccountPayment(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        String invoiceId = (String) context.get("invoiceId");        String billingAccountId = (String) context.get("billingAccountId");        Double captureAmount = (Double) context.get("captureAmount");        Map results = ServiceUtil.returnSuccess();                try {            // Note that the partyIdFrom of the Payment should be the partyIdTo of the invoice, since you're receiving a payment from the party you billed            GenericValue invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));            Map paymentParams = UtilMisc.toMap("paymentTypeId", "CUSTOMER_PAYMENT", "paymentMethodTypeId", "EXT_BILLACT",                     "partyIdFrom", invoice.getString("partyId"), "partyIdTo", invoice.getString("partyIdFrom"),                     "statusId", "PMNT_RECEIVED", "effectiveDate", UtilDateTime.nowTimestamp());            paymentParams.put("amount", captureAmount);            paymentParams.put("currencyUomId", invoice.getString("currencyUomId"));            paymentParams.put("userLogin", userLogin);            Map tmpResult = dispatcher.runSync("createPayment", paymentParams);            if (ServiceUtil.isError(tmpResult)) {                return tmpResult;            }                         String paymentId = (String) tmpResult.get("paymentId");            tmpResult = dispatcher.runSync("createPaymentApplication", UtilMisc.toMap("paymentId", paymentId, "invoiceId", invoiceId, "billingAccountId", billingAccountId,                     "amountApplied", captureAmount, "userLogin", userLogin));            if (ServiceUtil.isError(tmpResult)) {                return tmpResult;            }            if (paymentId == null) {                return ServiceUtil.returnError("No payment created for invoice [" + invoiceId + "] and billing account [" + billingAccountId + "]");            }            results.put("paymentId", paymentId);        } catch (GenericEntityException ex) {            return ServiceUtil.returnError(ex.getMessage());        } catch (GenericServiceException ex) {            return ServiceUtil.returnError(ex.getMessage());        }        return results;    }        private static Map capturePayment(DispatchContext dctx, GenericValue userLogin, OrderReadHelper orh, GenericValue paymentPref, double amount) {    	return capturePayment(dctx, userLogin, orh, paymentPref, amount, null);    }    private static Map capturePayment(DispatchContext dctx, GenericValue userLogin, OrderReadHelper orh, GenericValue paymentPref, double amount, GenericValue authTrans) {        LocalDispatcher dispatcher = dctx.getDispatcher();        // 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, CAPTURE_SERVICE_TYPE, false);        if (paymentSettings != null) {            paymentConfig = paymentSettings.getString("paymentPropertiesPath");            serviceName = paymentSettings.getString("paymentService");            if (serviceName == null) {                Debug.logError("Service name is null for payment setting; cannot process", module);                return null;            }        } else {            Debug.logError("Invalid payment settings entity, no payment settings found", module);            return null;        }        if (paymentConfig == null || paymentConfig.length() == 0) {            paymentConfig = "payment.properties";        }        // check the validity of the authorization; re-auth if necessary        if (!PaymentGatewayServices.checkAuthValidity(paymentPref, paymentConfig)) {            // re-auth required before capture            Map processorResult = PaymentGatewayServices.authPayment(dispatcher, userLogin, orh, paymentPref, amount, true);            boolean authResult = false;            if (processorResult != null) {                // process the auth results                try {                    authResult = processResult(dctx, processorResult, userLogin, paymentPref);                    if (!authResult) {                        Debug.logError("Re-Authorization failed : " + paymentPref + " : " + processorResult, module);                    }                } catch (GeneralException e) {                    Debug.logError(e, "Trouble processing the re-auth result : " + paymentPref + " : " + processorResult, module);                }            } else {                Debug.logError("Payment not re-authorized : " + paymentPref + " : " + processorResult, module);            }            if (!authResult) {                // returning null to cancel the capture process.                return null;            }            // get the new auth transaction            authTrans = getAuthTransaction(paymentPref);        }        // prepare the context for the capture service (must follow the ccCaptureInterface        Map captureContext = new HashMap();        captureContext.put("userLogin", userLogin);        captureContext.put("orderPaymentPreference", paymentPref);        captureContext.put("paymentConfig", paymentConfig);        captureContext.put("currency", orh.getCurrency());        // this is necessary because the ccCaptureInterface uses "captureAmount" but the paymentProcessInterface uses "processAmount"        try {            ModelService captureService = dctx.getModelService(serviceName);            Set inParams = captureService.getInParamNames();            if (inParams.contains("captureAmount")) {                captureContext.put("captureAmount", new Double(amount));                } else if (inParams.contains("processAmount")) {                captureContext.put("processAmount", new Double(amount));                } else {                return ServiceUtil.returnError("Service [" + serviceName + "] does not have a captureAmount or processAmount.  Its parameters are: " + inParams);            }        } catch (GenericServiceException ex) {            return ServiceUtil.returnError("Cannot get model service for " + serviceName);        }                        if (authTrans != null) {            captureContext.put("authTrans", authTrans);        }        Debug.logInfo("Capture [" + serviceName + "] : " + captureContext, module);        // now invoke the capture service        Map captureResult = null;        try {            captureResult = dispatcher.runSync(serviceName, captureContext, TX_TIME, true);        } catch (GenericServiceException e) {            Debug.logError(e, "Could not capture payment ... serviceName: " + serviceName + " ... context: " + captureContext, module);            return null;        }        // pass the payTo partyId to the result processor; we just add it to the result context.        String payToPartyId = getPayToPartyId(orh.getOrderHeader());        captureResult.put("payToPartyId", payToPartyId);        // add paymentSettings to result; for use by later processors        captureResult.put("paymentSettings", paymentSettings);        // pass the currencyUomId as well        captureResult.put("currencyUomId", orh.getCurrency());        // log the error message as a gateway response when it fails        if (ServiceUtil.isError(captureResult)) {            saveError(dispatcher, userLogin, paymentPref, captureResult, "PRDS_PAY_CAPTURE", "PGT_CAPTURE");        }        return captureResult;    }    private static void saveError(LocalDispatcher dispatcher, GenericValue userLogin, GenericValue paymentPref, Map result, String serviceType, String transactionCode) {        Map serviceContext = new HashMap();        serviceContext.put("paymentServiceTypeEnumId", serviceType);        serviceContext.put("orderPaymentPreference", paymentPref);        serviceContext.put("transCodeEnumId", transactionCode);        serviceContext.put("serviceResultMap", result);        serviceContext.put("userLogin", userLogin);        try {            dispatcher.runAsync("processPaymentServiceError", serviceContext);        } catch (GenericServiceException e) {            Debug.logError(e, module);        }    }    public static Map storePaymentErrorMessage(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");        String serviceType = (String) context.get("paymentServiceTypeEnumId");        String transactionCode = (String) context.get("transCodeEnumId");        Map result = (Map) context.get("serviceResultMap");        String responseId = delegator.getNextSeqId("PaymentGatewayResponse");        GenericValue response = delegator.makeValue("PaymentGatewayResponse", null);        response.set("paymentGatewayResponseId", responseId);        response.set("paymentServiceTypeEnumId", serviceType);        response.set("orderPaymentPreferenceId", paymentPref.get("orderPaymentPreferenceId"));        response.set("paymentMethodTypeId", paymentPref.get("paymentMethodTypeId"));        response.set("paymentMethodId", paymentPref.get("paymentMethodId"));        response.set("transCodeEnumId", transactionCode);        response.set("referenceNum", "ERROR");        response.set("gatewayMessage", ServiceUtil.getErrorMessage(

⌨️ 快捷键说明

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