This is an automated email from the ASF dual-hosted git repository.
surajk pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new f85d643 Improved: Changed decimals, rounding, zero static variables names as per best practices in third party payment component. (#201) f85d643 is described below commit f85d6439aaccdf0f80f63c589e0ec76a79f8207c Author: Suraj Khurana <[hidden email]> AuthorDate: Sat Jun 13 14:58:50 2020 +0530 Improved: Changed decimals, rounding, zero static variables names as per best practices in third party payment component. (#201) (OFBIZ-11804) Also make them private data members of the class. --- .../clearcommerce/CCPaymentServices.java | 26 +++++++++++----------- .../thirdparty/cybersource/IcsPaymentServices.java | 9 ++++---- .../thirdparty/gosoftware/PcChargeServices.java | 8 +++---- .../thirdparty/gosoftware/RitaServices.java | 9 ++++---- .../thirdparty/orbital/OrbitalPaymentServices.java | 20 ++++++++--------- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/clearcommerce/CCPaymentServices.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/clearcommerce/CCPaymentServices.java index e373dbf..b4ef15c 100644 --- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/clearcommerce/CCPaymentServices.java +++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/clearcommerce/CCPaymentServices.java @@ -53,11 +53,11 @@ import org.w3c.dom.Element; */ public class CCPaymentServices { - public final static String MODULE = CCPaymentServices.class.getName(); - private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals"); - private static RoundingMode rounding = UtilNumber.getRoundingMode("invoice.rounding"); - public final static String RESOURCE = "AccountingUiLabels"; - private final static int maxSevComp = 4; + private static final String MODULE = CCPaymentServices.class.getName(); + private static final String RESOURCE = "AccountingUiLabels"; + private static final int DECIMALS = UtilNumber.getBigDecimalScale("invoice.decimals"); + private static final RoundingMode ROUNDING_MODE = UtilNumber.getRoundingMode("invoice.rounding"); + private final static int MAX_SEV_COMP = 4; public static Map<String, Object> ccAuth(DispatchContext dctx, Map<String, Object> context) { String ccAction = (String) context.get("ccAction"); @@ -75,7 +75,7 @@ public class CCPaymentServices { return ServiceUtil.returnError(cce.getMessage()); } - if (getMessageListMaxSev(authResponseDoc) > maxSevComp) { // 5 and higher, process error from HSBC + if (getMessageListMaxSev(authResponseDoc) > MAX_SEV_COMP) { // 5 and higher, process error from HSBC Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("authResult", Boolean.FALSE); result.put("processAmount", BigDecimal.ZERO); @@ -106,7 +106,7 @@ public class CCPaymentServices { return ServiceUtil.returnError(cce.getMessage()); } - if (getMessageListMaxSev(creditResponseDoc) > maxSevComp) { + if (getMessageListMaxSev(creditResponseDoc) > MAX_SEV_COMP) { Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("creditResult", Boolean.FALSE); result.put("creditAmount", BigDecimal.ZERO); @@ -141,7 +141,7 @@ public class CCPaymentServices { return ServiceUtil.returnError(cce.getMessage()); } - if (getMessageListMaxSev(captureResponseDoc) > maxSevComp) { + if (getMessageListMaxSev(captureResponseDoc) > MAX_SEV_COMP) { Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("captureResult", Boolean.FALSE); result.put("captureAmount", BigDecimal.ZERO); @@ -176,7 +176,7 @@ public class CCPaymentServices { return ServiceUtil.returnError(cce.getMessage()); } - if (getMessageListMaxSev(releaseResponseDoc) > maxSevComp) { + if (getMessageListMaxSev(releaseResponseDoc) > MAX_SEV_COMP) { Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("releaseResult", Boolean.FALSE); result.put("releaseAmount", BigDecimal.ZERO); @@ -233,7 +233,7 @@ public class CCPaymentServices { return ServiceUtil.returnError(cce.getMessage()); } - if (getMessageListMaxSev(refundResponseDoc) > maxSevComp) { + if (getMessageListMaxSev(refundResponseDoc) > MAX_SEV_COMP) { Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("refundResult", Boolean.FALSE); result.put("refundAmount", BigDecimal.ZERO); @@ -268,7 +268,7 @@ public class CCPaymentServices { return ServiceUtil.returnError(cce.getMessage()); } - if (getMessageListMaxSev(reauthResponseDoc) > maxSevComp) { + if (getMessageListMaxSev(reauthResponseDoc) > MAX_SEV_COMP) { Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("reauthResult", Boolean.FALSE); result.put("reauthAmount", BigDecimal.ZERO); @@ -825,7 +825,7 @@ public class CCPaymentServices { // 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 = amount.setScale(decimals, rounding).movePointRight(2).toPlainString(); + String totalString = amount.setScale(DECIMALS, ROUNDING_MODE).movePointRight(2).toPlainString(); Element totalElement = UtilXml.addChildElementValue(totalsElement, "Total", totalString, document); totalElement.setAttribute("DataType", "Money"); @@ -934,7 +934,7 @@ public class CCPaymentServices { if (Debug.verboseOn()) { Debug.logVerbose("Result severity from clearCommerce:" + getMessageListMaxSev(responseDocument), MODULE); } - if (Debug.verboseOn() && getMessageListMaxSev(responseDocument) > maxSevComp) { + if (Debug.verboseOn() && getMessageListMaxSev(responseDocument) > MAX_SEV_COMP) { Debug.logVerbose("Returned messages:" + getMessageList(responseDocument), MODULE); } return responseDocument; diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/cybersource/IcsPaymentServices.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/cybersource/IcsPaymentServices.java index 51700f9..591ba8c 100644 --- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/cybersource/IcsPaymentServices.java +++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/cybersource/IcsPaymentServices.java @@ -19,6 +19,7 @@ package org.apache.ofbiz.accounting.thirdparty.cybersource; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -52,9 +53,9 @@ import com.cybersource.ws.client.FaultException; public class IcsPaymentServices { private static final String MODULE = IcsPaymentServices.class.getName(); - private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals"); - private static RoundingMode rounding = UtilNumber.getRoundingMode("invoice.rounding"); - public final static String RESOURCE = "AccountingUiLabels"; + private static final String RESOURCE = "AccountingUiLabels"; + private static final int DECIMALS = UtilNumber.getBigDecimalScale("invoice.decimals"); + private static final RoundingMode ROUNDING = UtilNumber.getRoundingMode("invoice.rounding"); // load the JSSE properties static { @@ -529,7 +530,7 @@ public class IcsPaymentServices { private static String getAmountString(Map<String, ? extends Object> context, String amountField) { BigDecimal processAmount = (BigDecimal) context.get(amountField); - return processAmount.setScale(decimals, rounding).toPlainString(); + return processAmount.setScale(DECIMALS, ROUNDING).toPlainString(); } private static void processAuthResult(Map<String, Object> reply, Map<String, Object> result, Delegator delegator) { diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java index bb60f69..ea7d753 100644 --- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java +++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java @@ -43,9 +43,9 @@ import org.apache.ofbiz.service.ServiceUtil; public class PcChargeServices { private static final String MODULE = PcChargeServices.class.getName(); - private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals"); - private static RoundingMode rounding = UtilNumber.getRoundingMode("invoice.rounding"); - public final static String RESOURCE = "AccountingUiLabels"; + private static final String RESOURCE = "AccountingUiLabels"; + private static final int DECIMALS = UtilNumber.getBigDecimalScale("invoice.decimals"); + private static final RoundingMode ROUNDING_MODE = UtilNumber.getRoundingMode("invoice.rounding"); public static Map<String, Object> ccAuth(DispatchContext dctx, Map<String, ? extends Object> context) { Locale locale = (Locale) context.get("locale"); @@ -417,7 +417,7 @@ public class PcChargeServices { private static String getAmountString(Map<String, ? extends Object> context, String amountField) { BigDecimal processAmount = (BigDecimal) context.get(amountField); - return processAmount.setScale(decimals, rounding).toPlainString(); + return processAmount.setScale(DECIMALS, ROUNDING_MODE).toPlainString(); } } diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/RitaServices.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/RitaServices.java index 4451092..ec6d58e 100644 --- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/RitaServices.java +++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/RitaServices.java @@ -48,11 +48,12 @@ import org.apache.ofbiz.service.ServiceUtil; public class RitaServices { private static final String MODULE = RitaServices.class.getName(); - private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals"); - private static RoundingMode rounding = UtilNumber.getRoundingMode("invoice.rounding"); - public final static String RESOURCE = "AccountingUiLabels"; + private static final String RESOURCE = "AccountingUiLabels"; private static final String RES_ORDER = "OrderUiLabels"; + private static final int DECIMALS = UtilNumber.getBigDecimalScale("invoice.decimals"); + private static final RoundingMode ROUNDING = UtilNumber.getRoundingMode("invoice.rounding"); + public static Map<String, Object> ccAuth(DispatchContext dctx, Map<String, ? extends Object> context) { Locale locale = (Locale) context.get("locale"); Delegator delegator = dctx.getDelegator(); @@ -522,6 +523,6 @@ public class RitaServices { private static String getAmountString(Map<String, ? extends Object> context, String amountField) { BigDecimal processAmount = (BigDecimal) context.get(amountField); - return processAmount.setScale(decimals, rounding).toPlainString(); + return processAmount.setScale(DECIMALS, ROUNDING).toPlainString(); } } diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java index 1fa3f73..15c44e7 100644 --- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java +++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java @@ -19,6 +19,7 @@ package org.apache.ofbiz.accounting.thirdparty.orbital; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -26,7 +27,6 @@ import java.util.Map; import org.apache.ofbiz.accounting.payment.PaymentGatewayServices; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.UtilFormatOut; -import org.apache.ofbiz.base.util.UtilMisc; import org.apache.ofbiz.base.util.UtilNumber; import org.apache.ofbiz.base.util.UtilProperties; import org.apache.ofbiz.base.util.UtilValidate; @@ -34,7 +34,6 @@ import org.apache.ofbiz.entity.Delegator; import org.apache.ofbiz.entity.GenericEntityException; import org.apache.ofbiz.entity.GenericValue; import org.apache.ofbiz.entity.util.EntityQuery; -import org.apache.ofbiz.entity.util.EntityUtil; import org.apache.ofbiz.service.DispatchContext; import org.apache.ofbiz.service.ModelService; import org.apache.ofbiz.service.ServiceUtil; @@ -51,12 +50,13 @@ import com.paymentech.orbital.sdk.util.exceptions.InitializationException; public class OrbitalPaymentServices { - public static String MODULE = OrbitalPaymentServices.class.getName(); - private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals"); - private static RoundingMode rounding = UtilNumber.getRoundingMode("invoice.rounding"); - public final static String RESOURCE = "AccountingUiLabels"; + private static final String MODULE = OrbitalPaymentServices.class.getName(); + private static final String RESOURCE = "AccountingUiLabels"; + private static final String ERROR = "Error"; + + private static final int DECIMALS = UtilNumber.getBigDecimalScale("invoice.decimals"); + private static final RoundingMode ROUNDING = UtilNumber.getRoundingMode("invoice.rounding"); - public static String ERROR = "Error"; public static final String BIN_VALUE = "000002"; public static TransactionProcessorIF tp = null; @@ -300,7 +300,7 @@ public class OrbitalPaymentServices { private static void buildAuthOrAuthCaptureTransaction(Map<String, Object> params, Delegator delegator, Map<String, Object> props, RequestIF request, Map<String, Object> results) { GenericValue cc = (GenericValue) params.get("creditCard"); BigDecimal amount = (BigDecimal) params.get("processAmount"); - String amountValue = amount.setScale(decimals, rounding).movePointRight(2).toPlainString(); + String amountValue = amount.setScale(DECIMALS, ROUNDING).movePointRight(2).toPlainString(); String number = UtilFormatOut.checkNull(cc.getString("cardNumber")); String expDate = UtilFormatOut.checkNull(cc.getString("expireDate")); expDate = formatExpDateForOrbital(expDate); @@ -382,7 +382,7 @@ public class OrbitalPaymentServices { GenericValue authTransaction = (GenericValue) params.get("authTransaction"); GenericValue creditCard = (GenericValue) params.get("creditCard"); BigDecimal amount = (BigDecimal) params.get("captureAmount"); - String amountValue = amount.setScale(decimals, rounding).movePointRight(2).toPlainString(); + String amountValue = amount.setScale(DECIMALS, ROUNDING).movePointRight(2).toPlainString(); String orderId = UtilFormatOut.checkNull((String)params.get("orderId")); try { //If there were no errors preparing the template, we can now specify the data @@ -420,7 +420,7 @@ public class OrbitalPaymentServices { private static void buildRefundTransaction(Map<String, Object> params, Map<String, Object> props, RequestIF request, Map<String, Object> results) { GenericValue cc = (GenericValue) params.get("creditCard"); BigDecimal amount = (BigDecimal) params.get("refundAmount"); - String amountValue = amount.setScale(decimals, rounding).movePointRight(2).toPlainString(); + String amountValue = amount.setScale(DECIMALS, ROUNDING).movePointRight(2).toPlainString(); String number = UtilFormatOut.checkNull(cc.getString("cardNumber")); String expDate = UtilFormatOut.checkNull(cc.getString("expireDate")); expDate = formatExpDateForOrbital(expDate); |
Free forum by Nabble | Edit this page |