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

📄 ccpaymentservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        // payment mech        GenericValue creditCard = (GenericValue) context.get("creditCard");        boolean enableCVM = UtilProperties.propertyValueEqualsIgnoreCase(paymentConfig, "payment.clearcommerce.enableCVM", "Y");        String cardSecurityCode = enableCVM ? (String) context.get("cardSecurityCode") : null;        // Default to locale code 840 (United States)        String localCode = UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.localeCode", "840");        appendPaymentMechNode(consumerElement, creditCard, cardSecurityCode, localCode);        // billing address        GenericValue billingAddress = (GenericValue) context.get("billingAddress");        if (billingAddress != null) {            Element billToElement = UtilXml.addChildElement(consumerElement, "BillTo", requestDocument);            Element billToLocationElement = UtilXml.addChildElement(billToElement, "Location", requestDocument);            appendAddressNode(billToLocationElement, billingAddress);        }        // shipping address        GenericValue shippingAddress = (GenericValue) context.get("shippingAddress");        if (shippingAddress != null) {            Element shipToElement = UtilXml.addChildElement(consumerElement, "ShipTo", requestDocument);            Element shipToLocationElement = UtilXml.addChildElement(shipToElement, "Location", requestDocument);            appendAddressNode(shipToLocationElement, shippingAddress);        }        // Default to currency code 840 (USD)        String currencyCode = UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.currencyCode", "840");        // transaction        appendTransactionNode(orderFormDocElement, type, amount, currencyCode);        // TODO: determine if adding OrderItemList is worthwhile - JFE 2004.02.14        return requestDocument;    }    private static Document buildSecondaryTxRequest(Map context, String id, String type, Double amount) {        String paymentConfig = (String) context.get("paymentConfig");        if (UtilValidate.isEmpty(paymentConfig)) {            paymentConfig = "payment.properties";        }        Document requestDocument = createRequestDocument(paymentConfig);        Element engineDocElement = UtilXml.firstChildElement(requestDocument.getDocumentElement(), "EngineDoc");        Element orderFormDocElement = UtilXml.firstChildElement(engineDocElement, "OrderFormDoc");        UtilXml.addChildElementValue(orderFormDocElement, "Id", id, requestDocument);        // Default to currency code 840 (USD)        String currencyCode = UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.currencyCode", "840");        appendTransactionNode(orderFormDocElement, type, amount, currencyCode);        return requestDocument;    }    private static void appendPaymentMechNode(Element element, GenericValue creditCard, String cardSecurityCode, String localeCode) {        Document document = element.getOwnerDocument();        Element paymentMechElement = UtilXml.addChildElement(element, "PaymentMech", document);        Element creditCardElement = UtilXml.addChildElement(paymentMechElement, "CreditCard", document);        UtilXml.addChildElementValue(creditCardElement, "Number", creditCard.getString("cardNumber"), document);        String expDate = creditCard.getString("expireDate");        Element expiresElement = UtilXml.addChildElementValue(creditCardElement, "Expires",                expDate.substring(0, 3) + expDate.substring(5), document);        expiresElement.setAttribute("DataType", "ExpirationDate");        expiresElement.setAttribute("Locale", localeCode);        if (UtilValidate.isNotEmpty(cardSecurityCode)) {            // Cvv2Val must be exactly 4 characters            if (cardSecurityCode.length() < 4) {                while (cardSecurityCode.length() < 4) {                    cardSecurityCode = cardSecurityCode + " ";                }            } else if (cardSecurityCode.length() > 4) {                cardSecurityCode = cardSecurityCode.substring(0, 4);            }            UtilXml.addChildElementValue(creditCardElement, "Cvv2Val", cardSecurityCode, document);            UtilXml.addChildElementValue(creditCardElement, "Cvv2Indicator", "1", document);        }    }    private static void appendAddressNode(Element element, GenericValue address) {        Document document = element.getOwnerDocument();        Element addressElement = UtilXml.addChildElement(element, "Address", document);        UtilXml.addChildElementValue(addressElement, "Name", address.getString("toName"), document);        UtilXml.addChildElementValue(addressElement, "Street1", address.getString("address1"), document);        UtilXml.addChildElementValue(addressElement, "Street2", address.getString("address2"), document);        UtilXml.addChildElementValue(addressElement, "City", address.getString("city"), document);        UtilXml.addChildElementValue(addressElement, "StateProv", address.getString("stateProvinceGeoId"), document);        UtilXml.addChildElementValue(addressElement, "PostalCode", address.getString("postalCode"), document);        String countryGeoId = address.getString("countryGeoId");        if (UtilValidate.isNotEmpty(countryGeoId)) {            try {                GenericValue countryGeo = address.getRelatedOneCache("CountryGeo");                UtilXml.addChildElementValue(addressElement, "Country", countryGeo.getString("geoSecCode"), document);            } catch (GenericEntityException gee) {                Debug.log(gee, "Error finding related Geo for countryGeoId: " + countryGeoId, module);            }        }    }    private static void appendTransactionNode(Element element, String type, Double amount, String currencyCode) {        Document document = element.getOwnerDocument();        Element transactionElement = UtilXml.addChildElement(element, "Transaction", document);        UtilXml.addChildElementValue(transactionElement, "Type", type, document);        // Some transactions will not have an amount (release, reAuth)        if (amount != null) {            Element currentTotalsElement = UtilXml.addChildElement(transactionElement, "CurrentTotals", document);            Element totalsElement = UtilXml.addChildElement(currentTotalsElement, "Totals", document);            // DecimalFormat("#") is used here in case the total is something like 9.9999999...            // in that case, we want to send 999, not 999.9999999...            String totalString = new DecimalFormat("#").format(amount.doubleValue() * 100);            Element totalElement = UtilXml.addChildElementValue(totalsElement, "Total", totalString, document);            totalElement.setAttribute("DataType", "Money");            totalElement.setAttribute("Currency", currencyCode);        }    }    private static Document createRequestDocument(String paymentConfig) {        // EngineDocList        Document requestDocument = UtilXml.makeEmptyXmlDocument("EngineDocList");        Element engineDocListElement = requestDocument.getDocumentElement();        UtilXml.addChildElementValue(engineDocListElement, "DocVersion", "1.0", requestDocument);        // EngineDocList.EngineDoc        Element engineDocElement = UtilXml.addChildElement(engineDocListElement, "EngineDoc", requestDocument);        UtilXml.addChildElementValue(engineDocElement, "ContentType", "OrderFormDoc", requestDocument);        String sourceId = UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.sourceId");        if (UtilValidate.isNotEmpty(sourceId)) {            UtilXml.addChildElementValue(engineDocElement, "SourceId", sourceId, requestDocument);        }        String groupId = UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.groupId");        if (UtilValidate.isNotEmpty(groupId)) {            UtilXml.addChildElementValue(engineDocElement, "GroupId", groupId, requestDocument);        }        // EngineDocList.EngineDoc.User        Element userElement = UtilXml.addChildElement(engineDocElement, "User", requestDocument);        UtilXml.addChildElementValue(userElement, "Name",                UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.username", ""), requestDocument);        UtilXml.addChildElementValue(userElement, "Password",                UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.password", ""), requestDocument);        UtilXml.addChildElementValue(userElement, "Alias",                UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.alias", ""), requestDocument);        String effectiveAlias = UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.effectiveAlias");        if (UtilValidate.isNotEmpty(effectiveAlias)) {            UtilXml.addChildElementValue(userElement, "EffectiveAlias", effectiveAlias, requestDocument);        }        // EngineDocList.EngineDoc.Instructions        Element instructionsElement = UtilXml.addChildElement(engineDocElement, "Instructions", requestDocument);        String pipeline = "PaymentNoFraud";        if (UtilProperties.propertyValueEqualsIgnoreCase(paymentConfig, "payment.clearcommerce.enableFraudShield", "Y")) {            pipeline = "Payment";        }        UtilXml.addChildElementValue(instructionsElement, "Pipeline", pipeline, requestDocument);        // EngineDocList.EngineDoc.OrderFormDoc        Element orderFormDocElement = UtilXml.addChildElement(engineDocElement, "OrderFormDoc", requestDocument);        // default to "P" for Production Mode        String mode = UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.processMode", "P");        UtilXml.addChildElementValue(orderFormDocElement, "Mode", mode, requestDocument);        return requestDocument;    }    private static Document sendRequest(Document requestDocument, String paymentConfig) throws ClearCommerceException {        if (UtilValidate.isEmpty(paymentConfig)) {            paymentConfig = "payment.properties";        }        String serverURL = UtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.serverURL");        if (UtilValidate.isEmpty(serverURL)) {            throw new ClearCommerceException("Missing server URL; check your ClearCommerce configuration");        }        if (Debug.verboseOn()) {            Debug.logVerbose("ClearCommerce server URL: " + serverURL, module);        }        OutputStream os = new ByteArrayOutputStream();        OutputFormat format = new OutputFormat();        format.setOmitDocumentType(true);        format.setOmitXMLDeclaration(true);        format.setIndenting(false);        XMLSerializer serializer = new XMLSerializer(os, format);        try {            serializer.asDOMSerializer();            serializer.serialize(requestDocument.getDocumentElement());        } catch (IOException ioe) {            throw new ClearCommerceException("Error serializing requestDocument: " + ioe.getMessage());        }        String xmlString = os.toString();        if (Debug.verboseOn()) {            Debug.logVerbose("ClearCommerce XML request string: " + xmlString, module);        }        HttpClient http = new HttpClient(serverURL);        http.setParameter("CLRCMRC_XML", xmlString);        String response = null;        try {            response = http.post();        } catch (HttpClientException hce) {            Debug.log(hce, module);            throw new ClearCommerceException("ClearCommerce connection problem", hce);        }        // Note: if Debug.verboseOn(), HttpClient will log this...        //if (Debug.verboseOn()) {        //    Debug.logVerbose("ClearCommerce response: " + response, module);        //}        Document responseDocument = null;        try {            responseDocument = UtilXml.readXmlDocument(response, false);        } catch (SAXException se) {            throw new ClearCommerceException("Error reading response Document from a String: " + se.getMessage());        } catch (ParserConfigurationException pce) {            throw new ClearCommerceException("Error reading response Document from a String: " + pce.getMessage());        } catch (IOException ioe) {            throw new ClearCommerceException("Error reading response Document from a String: " + ioe.getMessage());        }        return responseDocument;    }}class ClearCommerceException extends GeneralException {    ClearCommerceException() {        super();    }    ClearCommerceException(String msg) {        super(msg);    }    ClearCommerceException(Throwable t) {        super(t);    }    ClearCommerceException(String msg, Throwable t) {        super(msg, t);    }}

⌨️ 快捷键说明

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