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

📄 worldpayevents.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        GenericValue productStore = null;
        try {
            productStore = orderHeader.getRelatedOne("ProductStore");
        } catch (GenericEntityException e) {
            Debug.logError(e, "Unable to get ProductStore from OrderHeader", module);
            
        }
        if (productStore == null) {
            Debug.logError("ProductStore is null", module);
            request.setAttribute("_ERROR_MESSAGE_", "<li>Problems getting merchant configuration, please contact customer service.");
            return "error";
        }
        
        // get the payment properties file       
        GenericValue paymentConfig = ProductStoreWorker.getProductStorePaymentSetting(delegator, productStore.getString("productStoreId"), "EXT_WORLDPAY", null, true);
        String configString = null;
        if (paymentConfig != null) {
            configString = paymentConfig.getString("paymentPropertiesPath");    
        }
                
        if (configString == null) {
            configString = "payment.properties";
        }
            
        String instId = UtilProperties.getPropertyValue(configString, "payment.worldpay.instId", "NONE");
        String authMode = UtilProperties.getPropertyValue(configString, "payment.worldpay.authMode", "A");
        String testMode = UtilProperties.getPropertyValue(configString, "payment.worldpay.testMode", "100");
        String fixContact = UtilProperties.getPropertyValue(configString, "payment.worldpay.fixContact", "N");
        String hideContact = UtilProperties.getPropertyValue(configString, "payment.worldpay.hideContact", "N");
        String confirmTemplate = UtilProperties.getPropertyValue(configString, "payment.worldpay.confirmTemplate", "");
        String timeout = UtilProperties.getPropertyValue(configString, "payment.worldpay.timeout", "0");
        String company = UtilFormatOut.checkEmpty(productStore.getString("companyName"), "");
        String defCur = UtilFormatOut.checkEmpty(productStore.getString("defaultCurrencyUomId"), "USD");                       
                           
        // order description
        String description = "Order #" + orderId;
        if (company != null && company.length() > 0)
        description = description + " from " + company;
        
        // check the instId - very important
        if (instId == null || instId.equals("NONE")) {
            Debug.logError("Worldpay InstId not found, cannot continue", module);
            request.setAttribute("_ERROR_MESSAGE_", "<li>Problems getting merchant configuration, please contact customer service.");
            return "error";
        }  
        
        int instIdInt = 0;
        try {
            instIdInt = Integer.parseInt(instId);
        } catch (NumberFormatException nfe) {
            Debug.logError(nfe, "Problem converting instId string to integer", module);
            request.setAttribute("_ERROR_MESSAGE_", "<li>Problems getting merchant configuration, please contact customer service.");
            return "error";
        }
        
        // check the testMode
        int testModeInt = -1;
        if (testMode != null) {
            try {
                testModeInt = Integer.parseInt(testMode);
            } catch (NumberFormatException nfe) {
                Debug.logWarning(nfe, "Problems getting the testMode value, setting to 0", module);
                testModeInt = 0;
            }            
        }
        
        // create the purchase link
        String purchaseURL = null;
        HTTPURL link = null;
        URLParameters linkParms = null;
        try {
            purchaseURL = Select.getPurchaseURL();
            link = new HTTPURL(purchaseURL);
            linkParms = link.getParameters();
        } catch (SelectException e) {
            Debug.logError(e, "Problems creating the purchase url", module);
            request.setAttribute("_ERROR_MESSAGE_", "<li>Problem creating link to WorldPay, please contact customer service.");
            return "error";
        } catch (ArgumentException e) {
            Debug.logError(e, "Problems creating HTTPURL link", module);
            request.setAttribute("_ERROR_MESSAGE_", "<li>Problem creating link to WorldPay, please contact customer service.");
            return "error";
        }                                                      
        
        // create the currency amount
        double orderTotal = orderHeader.getDouble("grandTotal").doubleValue();
        CurrencyAmount currencyAmount = null;         
        try {
            Currency currency = SelectCurrency.getInstanceByISOCode(defCur);
            currencyAmount = new CurrencyAmount(orderTotal, currency);
        } catch (ArgumentException ae) {
            Debug.logError(ae, "Problems building CurrencyAmount", module);
            request.setAttribute("_ERROR_MESSAGE_", "<li>Merchant Configuration Error, please contact customer service.");
            return "error";
        }
                
        // create a purchase token
        PurchaseToken token = null;   
        try {
            token = new PurchaseToken(instIdInt, currencyAmount, orderId);
        } catch (SelectException e) {
            Debug.logError(e, "Cannot create purchase token", module);
        } catch (ArgumentException e) {
            Debug.logError(e, "Cannot create purchase token", module);
        } 
        if (token == null) {
            request.setAttribute("_ERROR_MESSAGE_", "<li>Problems creating a purchase token, please contact customer service.");
            return "error"; 
        }
        
        // set the auth/test modes        
        try {
            token.setAuthorisationMode(authMode);
        } catch (SelectException e) {
            Debug.logWarning(e, "Problems setting the authorization mode", module);
        }
        token.setTestMode(testModeInt);
                        
        // set the token to the purchase link
        try {
            linkParms.setValue(SelectDefs.SEL_purchase, token.produce());
        } catch (SelectException e) {
            Debug.logError(e, "Problems producing token", module);
            request.setAttribute("_ERROR_MESSAGE_", "<li>Problems producing purchase token, please contact customer service.");
            return "error";
        }
        
        // set the customer data in the link
        linkParms.setValue(SelectDefs.SEL_desc, description);
        linkParms.setValue(SelectDefs.SEL_name, name != null ? name : "");
        linkParms.setValue(SelectDefs.SEL_address, address != null ? address.toString() : "");
        linkParms.setValue(SelectDefs.SEL_postcode, contactAddress != null ? contactAddress.getString("postalCode") : "");
        linkParms.setValue(SelectDefs.SEL_country, countryGeo.getString("geoCode"));
        linkParms.setValue(SelectDefs.SEL_tel, phoneNumber != null ? phoneNumber : ""); 
        linkParms.setValue(SelectDefs.SEL_email, emailAddress != null ? emailAddress : "");
        
        // set some optional data
        if (fixContact != null && fixContact.toUpperCase().startsWith("Y")) {
            linkParms.setValue(SelectDefs.SEL_fixContact, "Y");
        }
        if (hideContact != null && hideContact.toUpperCase().startsWith("Y")) {
            linkParms.setValue("hideContact", "Y"); // why is this not in SelectDefs??
        }
        
        // now set some send-back parameters
        linkParms.setValue("M_controlPath", (String)request.getAttribute("_CONTROL_PATH_"));
        linkParms.setValue("M_userLoginId", userLogin.getString("userLoginId"));               
        linkParms.setValue("M_dispatchName", dispatcher.getName());
        linkParms.setValue("M_delegatorName", delegator.getDelegatorName());        
        linkParms.setValue("M_webSiteId", webSiteId);        
        linkParms.setValue("M_localLocale", UtilHttp.getLocale(request).toString());               
        linkParms.setValue("M_confirmTemplate", confirmTemplate != null ? confirmTemplate : "");
                    
        // redirect to worldpay
        try {
            response.sendRedirect(link.produce());
        } catch (IOException e) {
            Debug.logError(e, "Problems redirecting to Worldpay", module);
            request.setAttribute("_ERROR_MESSAGE_", "<li>Problems connecting with WorldPay, please contact customer service.");
            return "error";
        }
        
        return "success";
    }

}

⌨️ 快捷键说明

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