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

📄 ccpaymentservices.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                while (sb.length() < 4) {
                    sb.append(" ");
                }
                cvmCode = sb.toString();
            }
            recCreditCard.setFieldString("Cvv2Val", cvmCode.substring(0, 4)); // this must be exactly 4 characters
            recCreditCard.setFieldString("Cvv2Indicator", "1");
        }
            
        // EngineDocList.EngineDoc.OrderFormDoc.Consumer.BillTo
        CcApiRecord recBillTo = recConsumer.addRecord("BillTo");

        // EngineDocList.EngineDoc.OrderFormDoc.Consumer.BillTo.Location
        CcApiRecord recLocation = recBillTo.addRecord("Location");

        // EngineDocList.EngineDoc.OrderFormDoc.Consumer.BillTo.Location.Address
        CcApiRecord recAddress = recLocation.addRecord("Address");
        GenericValue contactPerson = (GenericValue) context.get("contactPerson");
        String billToName = new String(contactPerson.getString("firstName") + " " + contactPerson.getString("lastName"));

        recAddress.setFieldString("Name", billToName);
        GenericValue billingAddress = (GenericValue) context.get("billingAddress");

        recAddress.setFieldString("Street1", billingAddress.getString("address1"));
        if (billingAddress.get("address2") != null) {
            recAddress.setFieldString("Street2", billingAddress.getString("address2"));
        }
        recAddress.setFieldString("City", billingAddress.getString("city"));
        if (billingAddress.get("stateProvinceGeoId") != null) {
            recAddress.setFieldString("StateProv", billingAddress.getString("stateProvinceGeoId"));
        }
        recAddress.setFieldString("PostalCode", billingAddress.getString("postalCode"));
        GenericValue geo = billingAddress.getRelatedOneCache("CountryGeo");

        recAddress.setFieldString("Country", geo.getString("geoSecCode"));
            
        // EngineDocList.EngineDoc.OrderFormDoc.Transaction
        CcApiRecord recTransaction = recOrderFormDoc.addRecord("Transaction");

        recTransaction.setFieldString("Type", TYPE_AUTH);

        // EngineDocList.EngineDoc.OrderFormDoc.Transaction.CurrentTotals
        CcApiRecord recCurrentTotals = recTransaction.addRecord("CurrentTotals");

        // Used in the following code to format for CcApiMoney
        NumberFormat nf = new DecimalFormat("#");
        
        // EngineDocList.EngineDoc.OrderFormDoc.Transaction.CurrentTotals.Totals
        CcApiRecord recTotals = recCurrentTotals.addRecord("Totals");
        Double processAmount = (Double) context.get("processAmount");
        CcApiMoney total = new CcApiMoney(nf.format(processAmount.doubleValue() * 100), "840");

        recTotals.setFieldMoney("Total", total);
            
        List orderItems = (List) context.get("orderItems");
        Iterator itemIterator = orderItems.iterator();
        CcApiRecord recOrderItemList = recOrderFormDoc.addRecord("OrderItemList");
            
        while (itemIterator.hasNext()) {
            GenericValue item = (GenericValue) itemIterator.next();
            GenericValue product = item.getRelatedOneCache("Product");
            CcApiRecord recOrderItem = recOrderItemList.addRecord("OrderItem");
            Integer orderItemSeqId = new Integer(item.getString("orderItemSeqId"));

            recOrderItem.setFieldS32("ItemNumber", orderItemSeqId.intValue());
            recOrderItem.setFieldString("Id", product.getString("productId"));
            Double qty = new Double(item.getString("quantity"));

            recOrderItem.setFieldS32("Qty", qty.intValue());
            recOrderItem.setFieldString("Desc", item.getString("itemDescription"));
            CcApiMoney unitPrice = new CcApiMoney(nf.format(item.getDouble("unitPrice").doubleValue() * 100), "840");

            recOrderItem.setFieldMoney("Price", unitPrice);    
        }
            
        return;
        
    }
    
    private static void buildCaptureRequest(CcApiDocument doc, Map context) throws CcApiException, GenericEntityException {        
        initDoc(doc, context);
        
        CcApiRecord recEngineDoc = doc.getFirstRecord("EngineDoc");

        // EngineDocList.EngineDoc.Instructions
        CcApiRecord recInstructions = recEngineDoc.addRecord("Instructions");

        recInstructions.setFieldString("Pipeline", "PaymentNoFraud");

        // EngineDocList.EngineDoc.OrderFormDoc
        CcApiRecord recOrderFormDoc = recEngineDoc.getFirstRecord("OrderFormDoc");
        GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");

        recOrderFormDoc.setFieldString("Id", paymentPref.getString("authRefNum"));
            
        // EngineDocList.EngineDoc.OrderFormDoc.Transaction
        CcApiRecord recTransaction = recOrderFormDoc.addRecord("Transaction");

        recTransaction.setFieldString("Type", TYPE_CAPTURE);

        // EngineDocList.EngineDoc.OrderFormDoc.Transaction.CurrentTotals
        CcApiRecord recCurrentTotals = recTransaction.addRecord("CurrentTotals");
            
        // EngineDocList.EngineDoc.OrderFormDoc.Transaction.CurrentTotals.Totals
        CcApiRecord recTotals = recCurrentTotals.addRecord("Totals");
        Double captureAmount = (Double) context.get("captureAmount");
        NumberFormat nf = new DecimalFormat("#");
        CcApiMoney total = new CcApiMoney(nf.format(captureAmount.doubleValue() * 100), "840");

        recTotals.setFieldMoney("Total", total);
        
        return;
    }

    private static void processAuthResponse(CcApiDocument response, Map result) throws CcApiException {        
        CcApiRecord recEngineDoc = response.getFirstRecord("EngineDoc");
        CcApiRecord recOrderFormDoc = recEngineDoc.getFirstRecord("OrderFormDoc");
        CcApiRecord recTransaction = recOrderFormDoc.getFirstRecord("Transaction");
        CcApiRecord recProcResponse = recTransaction.getFirstRecord("CardProcResp");
        
        Integer errCode = recProcResponse.getFieldS32("CcErrCode");
 
        if (errCode.intValue() == 1) {
            result.put("authCode", recTransaction.getFieldString("AuthCode"));
            result.put("authResult", new Boolean(true));
            CcApiRecord recCurrentTotals = recTransaction.getFirstRecord("CurrentTotals");
            CcApiRecord recTotals = recCurrentTotals.getFirstRecord("Totals");
            CcApiMoney authAmount = recTotals.getFieldMoney("Total"); 
            Double authAmountDouble = new Double(authAmount.getAmount());
            
            result.put("processAmount", new Double(authAmountDouble.doubleValue() / 100));
        } else {
            result.put("authResult", new Boolean(false));
            result.put("processAmount", new Double(0.00));
        }
        result.put("authRefNum", recOrderFormDoc.getFieldString("Id"));
        result.put("authFlag", recProcResponse.getFieldString("Status"));
        result.put("authMessage", recProcResponse.getFieldString("CcReturnMsg"));
        String avsDisplay = recProcResponse.getFieldString("AvsDisplay");

        if (avsDisplay != null) {
            result.put("avsCode", avsDisplay);
        }
    }
    
    private static void processCaptureResponse(CcApiDocument response, Map result) throws CcApiException {                
        CcApiRecord recEngineDoc = response.getFirstRecord("EngineDoc");
        CcApiRecord recOrderFormDoc = recEngineDoc.getFirstRecord("OrderFormDoc");
        CcApiRecord recTransaction = recOrderFormDoc.getFirstRecord("Transaction");
        CcApiRecord recProcResponse = recTransaction.getFirstRecord("CardProcResp");
        
        Integer errCode = recProcResponse.getFieldS32("CcErrCode");
        
        if (errCode.intValue() == 1) {
            CcApiRecord recCurrentTotals = recTransaction.getFirstRecord("CurrentTotals");
            CcApiRecord recTotals = recCurrentTotals.getFirstRecord("Totals");
            CcApiMoney captureAmount = recTotals.getFieldMoney("Total");
            Double captureAmountDouble = new Double(captureAmount.getAmount());
            
            result.put("captureAmount", new Double(captureAmountDouble.doubleValue() / 100));
            result.put("captureResult", new Boolean(true));
        } else {
            result.put("captureAmount", new Double(0.00));
            result.put("captureResult", new Boolean(false));
        }
        result.put("captureRefNum", recOrderFormDoc.getFieldString("Id"));
    }
    
    private static void initDoc(CcApiDocument doc, Map context) throws CcApiException {            
        String configString = (String) context.get("paymentConfig");

        if (configString == null) {
            configString = "payment.properties";
        }

        // Some default values  
        String sourceId = UtilProperties.getPropertyValue(configString, "payment.clearcommerce.sourceId", "mySourceId");
        String groupId = UtilProperties.getPropertyValue(configString, "payment.clearcommerce.groupId", "myGroup");
        String userName = UtilProperties.getPropertyValue(configString, "payment.clearcommerce.username", "myUsername");
        String userPassword = UtilProperties.getPropertyValue(configString, "payment.clearcommerce.password", "myPassword");
        String alias = UtilProperties.getPropertyValue(configString, "payment.clearcommerce.alias", "myAlias");
        String effectiveAlias = UtilProperties.getPropertyValue(configString, "payment.clearcommerce.effectiveAlias", "");
        String processMode = UtilProperties.getPropertyValue(configString, "payment.clearcommerce.processMode", "Y");
        String hostAddress = UtilProperties.getPropertyValue(configString, "payment.clearcommerce.hostAddress", "test5x.clearcommerce.com");
        String hostPort = UtilProperties.getPropertyValue(configString, "payment.clearcommerce.hostPort", "12000");
        	    
        // Connection params
        doc.setHost(hostAddress);
        doc.setPort(Short.parseShort(hostPort));
        doc.useCRYPTO();
 
        // EngineDocList
        doc.setFieldString("DocVersion", "1.0");
			
        // EngineDocList.EngineDoc
        CcApiRecord engineDoc = doc.addRecord("EngineDoc");

        engineDoc.setFieldString("DocumentId", "1");
        engineDoc.setFieldString("ContentType", "OrderFormDoc");
        engineDoc.setFieldString("SourceId", sourceId);
            
        // EngineDocList.EngineDoc.User
        CcApiRecord user = engineDoc.addRecord("User");

        user.setFieldString("Name", userName);
        user.setFieldString("Password", userPassword);
        user.setFieldString("Alias", alias);
        if (!effectiveAlias.equals("")) {
            user.setFieldString("EffectiveAlias", effectiveAlias);
        }
			
        // EngineDocList.EngineDoc.OrderFormDoc
        CcApiRecord orderFormDoc = engineDoc.addRecord("OrderFormDoc");

        orderFormDoc.setFieldString("Mode", processMode);
        orderFormDoc.setFieldString("GroupId", groupId);
        
        return;
    }

}

⌨️ 快捷键说明

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