You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2009/01/06 08:13:44 UTC
svn commit: r731851 [4/22] - in /ofbiz/trunk:
applications/accounting/entitydef/
applications/accounting/script/org/ofbiz/accounting/finaccount/
applications/accounting/script/org/ofbiz/accounting/fixedasset/
applications/accounting/script/org/ofbiz/ac...
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java Mon Jan 5 23:13:36 2009
@@ -30,6 +30,7 @@
import org.ofbiz.accounting.invoice.InvoiceWorker;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.ObjectType;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.base.util.UtilMisc;
@@ -83,7 +84,7 @@
/**
* Authorizes a single order preference with an option to specify an amount. The result map has the Booleans
* "errors" and "finished" which notify the user if there were any errors and if the authorizatoin was finished.
- * There is also a List "messages" for the authorization response messages and a Double, "processAmount" as the
+ * There is also a List "messages" for the authorization response messages and a BigDecimal, "processAmount" as the
* amount processed.
*
* TODO: it might be nice to return the paymentGatewayResponseId
@@ -94,12 +95,12 @@
GenericValue userLogin = (GenericValue) context.get("userLogin");
String orderPaymentPreferenceId = (String) context.get("orderPaymentPreferenceId");
- Double overrideAmount = (Double) context.get("overrideAmount");
+ BigDecimal overrideAmount = (BigDecimal) context.get("overrideAmount");
// validate overrideAmount if its available
if (overrideAmount != null) {
- if (overrideAmount.doubleValue() < 0) return ServiceUtil.returnError("Amount entered (" + overrideAmount + ") is negative.");
- if (overrideAmount.doubleValue() == 0) return ServiceUtil.returnError("Amount entered (" + overrideAmount + ") is zero.");
+ if (overrideAmount.compareTo(BigDecimal.ZERO) < 0) return ServiceUtil.returnError("Amount entered (" + overrideAmount + ") is negative.");
+ if (overrideAmount.compareTo(BigDecimal.ZERO) == 0) return ServiceUtil.returnError("Amount entered (" + overrideAmount + ") is zero.");
}
GenericValue orderHeader = null;
@@ -114,9 +115,7 @@
OrderReadHelper orh = new OrderReadHelper(orderHeader);
// get the total remaining
- BigDecimal orderGrandTotal = orh.getOrderGrandTotal();
- orderGrandTotal = orderGrandTotal.setScale(decimals, rounding);
- double totalRemaining = orderGrandTotal.doubleValue();
+ BigDecimal totalRemaining = orh.getOrderGrandTotal();
// get the process attempts so far
Long procAttempt = orderPaymentPreference.getLong("processAttempt");
@@ -141,18 +140,18 @@
}
// use overrideAmount or maxAmount
- Double transAmount = null;
+ BigDecimal transAmount = null;
if (overrideAmount != null) {
transAmount = overrideAmount;
} else {
- transAmount = orderPaymentPreference.getDouble("maxAmount");
+ transAmount = orderPaymentPreference.getBigDecimal("maxAmount");
}
// round this before moving on just in case a funny number made it this far
- transAmount = (new BigDecimal(transAmount)).setScale(decimals, rounding).doubleValue();
+ transAmount = transAmount.setScale(decimals, rounding);
// if our transaction amount exists and is zero, there's nothing to process, so return
- if ((transAmount != null) && (transAmount.doubleValue() <= 0)) {
+ if ((transAmount != null) && (transAmount.compareTo(BigDecimal.ZERO) <= 0)) {
Map results = ServiceUtil.returnSuccess();
results.put("finished", Boolean.TRUE); // finished is true since there is nothing to do
results.put("errors", Boolean.FALSE); // errors is false since no error occured
@@ -166,7 +165,7 @@
// handle the response
if (authPaymentResult != null) {
// not null result means either an approval or decline; null would mean error
- Double thisAmount = (Double) authPaymentResult.get("processAmount");
+ BigDecimal thisAmount = (BigDecimal) authPaymentResult.get("processAmount");
// process the auth results
try {
@@ -333,9 +332,7 @@
// get the order amounts
OrderReadHelper orh = new OrderReadHelper(orderHeader);
- BigDecimal orderGrandTotal = orh.getOrderGrandTotal();
- orderGrandTotal = orderGrandTotal.setScale(decimals, rounding);
- double totalRemaining = orderGrandTotal.doubleValue();
+ BigDecimal totalRemaining = orh.getOrderGrandTotal();
// loop through and auth each order payment preference
int finished = 0;
@@ -383,7 +380,7 @@
if (((Boolean) results.get("finished")).booleanValue()) finished += 1;
if (((Boolean) results.get("errors")).booleanValue()) hadError += 1;
if (results.get("messages") != null) messages.addAll((List) results.get("messages"));
- if (results.get("processAmount") != null) totalRemaining -= ((Double) results.get("processAmount")).doubleValue();
+ if (results.get("processAmount") != null) totalRemaining = totalRemaining.subtract(((BigDecimal) results.get("processAmount")));
}
Debug.logInfo("Finished with auth(s) checking results", module);
@@ -410,7 +407,7 @@
}
- private static Map authPayment(LocalDispatcher dispatcher, GenericValue userLogin, OrderReadHelper orh, GenericValue paymentPreference, double totalRemaining, boolean reauth, Double overrideAmount) throws GeneralException {
+ private static Map authPayment(LocalDispatcher dispatcher, GenericValue userLogin, OrderReadHelper orh, GenericValue paymentPreference, BigDecimal totalRemaining, boolean reauth, BigDecimal overrideAmount) throws GeneralException {
String paymentConfig = null;
String serviceName = null;
@@ -471,31 +468,22 @@
getBillingInformation(orh, paymentPreference, processContext);
// default charge is totalRemaining
- double thisAmount = totalRemaining;
+ BigDecimal processAmount = totalRemaining;
// use override or max amount available
if (overrideAmount != null) {
- thisAmount = overrideAmount.doubleValue();
+ processAmount = overrideAmount;
} else if (paymentPreference.get("maxAmount") != null) {
- thisAmount = paymentPreference.getDouble("maxAmount").doubleValue();
+ processAmount = paymentPreference.getBigDecimal("maxAmount");
}
// don't authorized more then what is required
- if (thisAmount > totalRemaining) {
- thisAmount = totalRemaining;
+ if (processAmount.compareTo(totalRemaining) > 0) {
+ processAmount = totalRemaining;
}
// format the decimal
- String currencyFormat = UtilProperties.getPropertyValue("general.properties", "currency.decimal.format", "##0.00");
- DecimalFormat formatter = new DecimalFormat(currencyFormat);
- String amountString = formatter.format(thisAmount);
- Double processAmount = null;
- try {
- processAmount = new Double(formatter.parse(amountString).doubleValue());
- } catch (ParseException e) {
- Debug.logError(e, "Problems parsing string formatted double to Double", module);
- throw new GeneralException("ParseException in number format", e);
- }
+ processAmount = processAmount.setScale(decimals, rounding);
if (Debug.verboseOn()) Debug.logVerbose("Charging amount: " + processAmount, module);
processContext.put("processAmount", processAmount);
@@ -815,7 +803,7 @@
GenericValue authTransaction = PaymentGatewayServices.getAuthTransaction(paymentPref);
Map releaseContext = new HashMap();
releaseContext.put("orderPaymentPreference", paymentPref);
- releaseContext.put("releaseAmount", authTransaction.getDouble("amount"));
+ releaseContext.put("releaseAmount", authTransaction.getBigDecimal("amount"));
releaseContext.put("currency", currency);
releaseContext.put("paymentConfig", paymentConfig);
releaseContext.put("userLogin", userLogin);
@@ -1001,11 +989,11 @@
}
// get the invoice amount (amount to bill)
- double invoiceTotal = InvoiceWorker.getInvoiceNotApplied(invoice).doubleValue();
+ BigDecimal invoiceTotal = InvoiceWorker.getInvoiceNotApplied(invoice);
if (Debug.infoOn()) Debug.logInfo("(Capture) Invoice [#" + invoiceId + "] total: " + invoiceTotal, module);
// now capture the order
- Map serviceContext = UtilMisc.toMap("userLogin", userLogin, "orderId", testOrderId, "invoiceId", invoiceId, "captureAmount", new Double(invoiceTotal));
+ Map serviceContext = UtilMisc.toMap("userLogin", userLogin, "orderId", testOrderId, "invoiceId", invoiceId, "captureAmount", invoiceTotal);
if (UtilValidate.isNotEmpty(billingAccountId)) {
serviceContext.put("billingAccountId", billingAccountId);
}
@@ -1028,8 +1016,7 @@
String orderId = (String) context.get("orderId");
String invoiceId = (String) context.get("invoiceId");
String billingAccountId = (String) context.get("billingAccountId");
- Double captureAmount = (Double) context.get("captureAmount");
- BigDecimal amountToCapture = new BigDecimal(captureAmount.doubleValue());
+ BigDecimal amountToCapture = (BigDecimal) context.get("captureAmount");
amountToCapture = amountToCapture.setScale(decimals, rounding);
// get the order header and payment preferences
@@ -1066,10 +1053,10 @@
orderGrandTotal = orderGrandTotal.setScale(decimals, rounding);
BigDecimal totalPayments = PaymentWorker.getPaymentsTotal(orh.getOrderPayments());
totalPayments = totalPayments.setScale(decimals, rounding);
- BigDecimal remainingTotalBd = orderGrandTotal.subtract(totalPayments);
- if (Debug.infoOn()) Debug.logInfo("The Remaining Total for order: " + orderId + " is: " + remainingTotalBd, module);
+ BigDecimal remainingTotal = orderGrandTotal.subtract(totalPayments);
+ if (Debug.infoOn()) Debug.logInfo("The Remaining Total for order: " + orderId + " is: " + remainingTotal, module);
// The amount to capture cannot be greater than the remaining total
- amountToCapture = amountToCapture.min(remainingTotalBd);
+ amountToCapture = amountToCapture.min(remainingTotal);
if (Debug.infoOn()) Debug.logInfo("Actual Expected Capture Amount : " + amountToCapture, module);
// Process billing accounts payments
@@ -1100,7 +1087,7 @@
try {
captureResult = dispatcher.runSync("captureBillingAccountPayments", UtilMisc.<String, Object>toMap("invoiceId", invoiceId,
"billingAccountId", billingAccountId,
- "captureAmount", new Double(amountThisCapture.doubleValue()),
+ "captureAmount", amountThisCapture,
"orderId", orderId,
"userLogin", userLogin));
if (ServiceUtil.isError(captureResult)) {
@@ -1111,14 +1098,12 @@
}
if (captureResult != null) {
- Double amountCaptured = (Double) captureResult.get("captureAmount");
+ BigDecimal amountCaptured = (BigDecimal) captureResult.get("captureAmount");
Debug.logInfo("Amount captured for order [" + orderId + "] from unapplied payments associated to billing account [" + billingAccountId + "] is: " + amountCaptured, module);
- // big decimal reference to the capture amount
- BigDecimal amountCapturedBd = BigDecimal.valueOf(amountCaptured);
- amountCapturedBd = amountCapturedBd.setScale(decimals, rounding);
+ amountCaptured = amountCaptured.setScale(decimals, rounding);
- if (amountCapturedBd.compareTo(BigDecimal.ZERO) == 0) {
+ if (amountCaptured.compareTo(BigDecimal.ZERO) == 0) {
continue;
}
// add the invoiceId to the result for processing
@@ -1130,7 +1115,7 @@
// process the capture's results
try {
// the following method will set on the OrderPaymentPreference:
- // maxAmount = amountCapturedBd and
+ // maxAmount = amountCaptured and
// statusId = PAYMENT_RECEIVED
processResult(dctx, captureResult, userLogin, paymentPref);
} catch (GeneralException e) {
@@ -1139,8 +1124,8 @@
}
// create any splits which are needed
- if (authAmount.compareTo(amountCapturedBd) == 1) {
- BigDecimal splitAmount = authAmount.subtract(amountCapturedBd);
+ if (authAmount.compareTo(amountCaptured) > 0) {
+ BigDecimal splitAmount = authAmount.subtract(amountCaptured);
try {
Map splitCtx = UtilMisc.toMap("userLogin", userLogin, "orderPaymentPreference", paymentPref, "splitAmount", splitAmount);
dispatcher.addCommitService("processCaptureSplitPayment", splitCtx, true);
@@ -1203,20 +1188,18 @@
amountThisCapture = authAmount;
}
- Map captureResult = capturePayment(dctx, userLogin, orh, paymentPref, amountThisCapture.doubleValue());
+ Map captureResult = capturePayment(dctx, userLogin, orh, paymentPref, amountThisCapture);
if (captureResult != null && !ServiceUtil.isError(captureResult)) {
// credit card processors return captureAmount, but gift certificate processors return processAmount
- Double amountCaptured = (Double) captureResult.get("captureAmount");
+ BigDecimal amountCaptured = (BigDecimal) captureResult.get("captureAmount");
if (amountCaptured == null) {
- amountCaptured = (Double) captureResult.get("processAmount");
+ amountCaptured = (BigDecimal) captureResult.get("processAmount");
}
- // big decimal reference to the capture amount
- BigDecimal amountCapturedBd = new BigDecimal(amountCaptured.doubleValue());
- amountCapturedBd = amountCapturedBd.setScale(decimals, rounding);
+ amountCaptured = amountCaptured.setScale(decimals, rounding);
// decrease amount of next payment preference to capture
- amountToCapture = amountToCapture.subtract(amountCapturedBd);
+ amountToCapture = amountToCapture.subtract(amountCaptured);
// add the invoiceId to the result for processing
captureResult.put("invoiceId", invoiceId);
@@ -1230,8 +1213,8 @@
}
// create any splits which are needed
- if (authAmount.compareTo(amountCapturedBd) == 1) {
- BigDecimal splitAmount = authAmount.subtract(amountCapturedBd);
+ if (authAmount.compareTo(amountCaptured) > 0) {
+ BigDecimal splitAmount = authAmount.subtract(amountCaptured);
try {
Map splitCtx = UtilMisc.toMap("userLogin", userLogin, "orderPaymentPreference", paymentPref, "splitAmount", splitAmount);
dispatcher.addCommitService("processCaptureSplitPayment", splitCtx, true);
@@ -1298,7 +1281,7 @@
if ("PAYMENT_NOT_AUTH".equals(statusId)) {
// authorize the new preference
- processorResult = authPayment(dispatcher, userLogin, orh, newPref, splitAmount.doubleValue(), false, null);
+ processorResult = authPayment(dispatcher, userLogin, orh, newPref, splitAmount, false, null);
if (processorResult != null) {
// process the auth results
boolean authResult = processResult(dctx, processorResult, userLogin, newPref);
@@ -1328,7 +1311,7 @@
GenericValue userLogin = (GenericValue) context.get("userLogin");
String invoiceId = (String) context.get("invoiceId");
String billingAccountId = (String) context.get("billingAccountId");
- Double captureAmount = (Double) context.get("captureAmount");
+ BigDecimal captureAmount = (BigDecimal) context.get("captureAmount");
String orderId = (String) context.get("orderId");
Map results = ServiceUtil.returnSuccess();
@@ -1357,7 +1340,7 @@
}
results.put("paymentId", paymentId);
- if (orderId != null && captureAmount.doubleValue() > 0) {
+ if (orderId != null && captureAmount.compareTo(BigDecimal.ZERO) > 0) {
// Create a paymentGatewayResponse, if necessary
GenericValue order = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
if (order == null) {
@@ -1411,8 +1394,7 @@
GenericValue userLogin = (GenericValue) context.get("userLogin");
String invoiceId = (String) context.get("invoiceId");
String billingAccountId = (String) context.get("billingAccountId");
- Double captureAmountDbl = (Double) context.get("captureAmount");
- BigDecimal captureAmount = new BigDecimal(captureAmountDbl.doubleValue());
+ BigDecimal captureAmount = (BigDecimal) context.get("captureAmount");
captureAmount = captureAmount.setScale(decimals, rounding);
String orderId = (String) context.get("orderId");
BigDecimal capturedAmount = BigDecimal.ZERO;
@@ -1466,15 +1448,15 @@
}
capturedAmount = capturedAmount.setScale(decimals, rounding);
Map results = ServiceUtil.returnSuccess();
- results.put("captureAmount", new Double(capturedAmount.doubleValue()));
+ results.put("captureAmount", capturedAmount);
return results;
}
- private static Map capturePayment(DispatchContext dctx, GenericValue userLogin, OrderReadHelper orh, GenericValue paymentPref, double amount) {
+ private static Map capturePayment(DispatchContext dctx, GenericValue userLogin, OrderReadHelper orh, GenericValue paymentPref, BigDecimal 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) {
+ private static Map capturePayment(DispatchContext dctx, GenericValue userLogin, OrderReadHelper orh, GenericValue paymentPref, BigDecimal amount, GenericValue authTrans) {
LocalDispatcher dispatcher = dctx.getDispatcher();
// look up the payment configuration settings
String serviceName = null;
@@ -1545,9 +1527,9 @@
ModelService captureService = dctx.getModelService(serviceName);
Set inParams = captureService.getInParamNames();
if (inParams.contains("captureAmount")) {
- captureContext.put("captureAmount", new Double(amount));
+ captureContext.put("captureAmount", amount);
} else if (inParams.contains("processAmount")) {
- captureContext.put("processAmount", new Double(amount));
+ captureContext.put("processAmount", amount);
} else {
return ServiceUtil.returnError("Service [" + serviceName + "] does not have a captureAmount or processAmount. Its parameters are: " + inParams);
}
@@ -1733,7 +1715,8 @@
response.set("gatewayScoreResult", context.get("scoreCode"));
// set the auth info
- response.set("amount", context.get("processAmount"));
+ BigDecimal processAmount = (BigDecimal) context.get("processAmount");
+ response.set("amount", processAmount);
response.set("referenceNum", context.get("authRefNum"));
response.set("altReference", context.get("authAltRefNum"));
response.set("gatewayCode", context.get("authCode"));
@@ -1764,7 +1747,7 @@
}
}
- if (response.getDouble("amount").doubleValue() != ((Double) context.get("processAmount")).doubleValue()) {
+ if (response.getBigDecimal("amount").compareTo((BigDecimal)context.get("processAmount")) != 0) {
Debug.logWarning("The authorized amount does not match the max amount : Response - " + response + " : result - " + context, module);
}
@@ -1881,11 +1864,11 @@
LocalDispatcher dispatcher = dctx.getDispatcher();
Boolean captureResult = (Boolean) result.get("captureResult");
- Double amount = null;
+ BigDecimal amount = null;
if (result.get("captureAmount") != null) {
- amount = (Double) result.get("captureAmount");
+ amount = (BigDecimal) result.get("captureAmount");
} else if (result.get("processAmount") != null) {
- amount = (Double) result.get("processAmount");
+ amount = (BigDecimal) result.get("processAmount");
result.put("captureAmount", amount);
}
@@ -1894,8 +1877,7 @@
}
// setup the amount big decimal
- BigDecimal amtBd = new BigDecimal(amount.doubleValue());
- amtBd = amtBd.setScale(decimals, rounding);
+ amount = amount.setScale(decimals, rounding);
result.put("orderPaymentPreference", paymentPreference);
result.put("userLogin", userLogin);
@@ -1916,7 +1898,7 @@
if (!captureResult.booleanValue()) {
// capture returned false (error)
try {
- processReAuthFromCaptureFailure(dctx, result, amtBd, userLogin, paymentPreference);
+ processReAuthFromCaptureFailure(dctx, result, amount, userLogin, paymentPreference);
} catch (GeneralException e) {
// just log this for now (same as previous implementation)
Debug.logError(e, module);
@@ -1953,7 +1935,7 @@
Debug.log("reauth with amount: " + amount, module);
// first re-auth the card
- Map authPayRes = authPayment(dispatcher, userLogin, orh, paymentPreference, amount.doubleValue(), true, null);
+ Map authPayRes = authPayment(dispatcher, userLogin, orh, paymentPreference, amount, true, null);
if (authPayRes == null) {
throw new GeneralException("Null result returned from payment re-authorization");
}
@@ -1968,7 +1950,7 @@
processCaptureResult(dctx, result, userLogin, paymentPreference);
} else {
// no auto-capture; do manual capture now
- Map capPayRes = capturePayment(dctx, userLogin, orh, paymentPreference, amount.doubleValue(), authTrans);
+ Map capPayRes = capturePayment(dctx, userLogin, orh, paymentPreference, amount, authTrans);
if (capPayRes == null) {
throw new GeneralException("Problems trying to capture payment (null result)");
}
@@ -1995,7 +1977,7 @@
GenericValue userLogin = (GenericValue) context.get("userLogin");
String invoiceId = (String) context.get("invoiceId");
String payTo = (String) context.get("payToPartyId");
- Double amount = (Double) context.get("captureAmount");
+ BigDecimal amount = (BigDecimal) context.get("captureAmount");
String serviceType = (String) context.get("serviceTypeEnum");
String currencyUomId = (String) context.get("currencyUomId");
boolean captureSuccessful = ((Boolean) context.get("captureResult")).booleanValue();
@@ -2176,7 +2158,7 @@
GenericValue userLogin = (GenericValue) context.get("userLogin");
GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
- Double refundAmount = (Double) context.get("refundAmount");
+ BigDecimal refundAmount = (BigDecimal) context.get("refundAmount");
GenericValue orderHeader = null;
try {
@@ -2211,17 +2193,7 @@
return ServiceUtil.returnError("Problems getting billing information");
}
- // format the price
- String currencyFormat = UtilProperties.getPropertyValue("general.properties", "currency.decimal.format", "##0.00");
- DecimalFormat formatter = new DecimalFormat(currencyFormat);
- String amountString = formatter.format(refundAmount);
- Double processAmount = null;
- try {
- processAmount = new Double(formatter.parse(amountString).doubleValue());
- } catch (ParseException e) {
- Debug.logError(e, "Problem parsing amount using DecimalFormat", module);
- return ServiceUtil.returnError("Refund processor problems; see logs");
- }
+ BigDecimal processAmount = refundAmount.setScale(decimals, rounding);
serviceContext.put("refundAmount", processAmount);
serviceContext.put("userLogin", userLogin);
@@ -2258,8 +2230,8 @@
// such as having to void the entire original auth amount and re-authorize the new order total.
// However, since some legacy services might be non-compliant, so as a safety measure we will
// override the original refund amount if the refund response has a positive value
- Double actualRefundAmount = (Double) refundResponse.get("refundAmount");
- if (actualRefundAmount != null && actualRefundAmount.doubleValue() > 0) {
+ BigDecimal actualRefundAmount = (BigDecimal) refundResponse.get("refundAmount");
+ if (actualRefundAmount != null && actualRefundAmount.compareTo(BigDecimal.ZERO) > 0) {
refundResCtx.put("refundAmount", refundResponse.get("refundAmount"));
}
refundResRes = dispatcher.runSync(model.name, refundResCtx);
@@ -2695,7 +2667,7 @@
String paymentMethodId = (String) context.get("paymentMethodId");
String productStoreId = (String) context.get("productStoreId");
String securityCode = (String) context.get("securityCode");
- Double amount = (Double) context.get("amount");
+ BigDecimal amount = (BigDecimal) context.get("amount");
// check the payment method; verify type
GenericValue paymentMethod;
@@ -2936,8 +2908,8 @@
Debug.logInfo("Running credit card verification [" + paymentMethodId + "] (" + amount + ") : " + productStorePaymentProperties + " : " + mode, module);
if (amount != null && amount.length() > 0) {
- double authAmount = Double.parseDouble(amount);
- if (authAmount > 0.0) {
+ BigDecimal authAmount = new BigDecimal(amount);
+ if (authAmount.compareTo(BigDecimal.ZERO) > 0) {
Map<String, Object> ccAuthContext = FastMap.newInstance();
ccAuthContext.put("paymentMethodId", paymentMethodId);
ccAuthContext.put("productStoreId", productStoreId);
@@ -2972,11 +2944,11 @@
*/
public static Map testProcessor(DispatchContext dctx, Map context) {
Map result = new HashMap();
- Double processAmount = (Double) context.get("processAmount");
+ BigDecimal processAmount = (BigDecimal) context.get("processAmount");
- if (processAmount != null && processAmount.doubleValue() >= 100.00)
+ if (processAmount != null && processAmount.compareTo(new BigDecimal("100.00")) >= 0)
result.put("authResult", Boolean.TRUE);
- if (processAmount != null && processAmount.doubleValue() < 100.00)
+ if (processAmount != null && processAmount.compareTo(new BigDecimal("100.00")) < 0)
result.put("authResult", Boolean.FALSE);
result.put("customerRespMsgs", UtilMisc.toList("Sorry this processor requires at least a $100.00 purchase."));
if (processAmount == null)
@@ -2999,12 +2971,12 @@
*/
public static Map testProcessorWithCapture(DispatchContext dctx, Map context) {
Map result = new HashMap();
- Double processAmount = (Double) context.get("processAmount");
+ BigDecimal processAmount = (BigDecimal) context.get("processAmount");
- if (processAmount != null && processAmount.doubleValue() >= 100.00)
+ if (processAmount != null && processAmount.compareTo(new BigDecimal("100.00")) >= 0)
result.put("authResult", Boolean.TRUE);
result.put("captureResult", Boolean.TRUE);
- if (processAmount != null && processAmount.doubleValue() < 100.00)
+ if (processAmount != null && processAmount.compareTo(new BigDecimal("100.00")) < 0)
result.put("authResult", Boolean.FALSE);
result.put("captureResult", Boolean.FALSE);
result.put("customerRespMsgs", UtilMisc.toList("Sorry this processor requires at least a $100.00 purchase."));
@@ -3095,7 +3067,7 @@
*/
public static Map alwaysDeclineProcessor(DispatchContext dctx, Map context) {
Map result = ServiceUtil.returnSuccess();
- Double processAmount = (Double) context.get("processAmount");
+ BigDecimal processAmount = (BigDecimal) context.get("processAmount");
Debug.logInfo("Test Processor Declining Credit Card", module);
String refNum = UtilDateTime.nowAsString();
@@ -3114,7 +3086,7 @@
*/
public static Map alwaysNsfProcessor(DispatchContext dctx, Map context) {
Map result = ServiceUtil.returnSuccess();
- Double processAmount = (Double) context.get("processAmount");
+ BigDecimal processAmount = (BigDecimal) context.get("processAmount");
Debug.logInfo("Test Processor NSF Credit Card", module);
String refNum = UtilDateTime.nowAsString();
@@ -3134,7 +3106,7 @@
*/
public static Map alwaysBadExpireProcessor(DispatchContext dctx, Map context) {
Map result = ServiceUtil.returnSuccess();
- Double processAmount = (Double) context.get("processAmount");
+ BigDecimal processAmount = (BigDecimal) context.get("processAmount");
Debug.logInfo("Test Processor Bad Expire Date Credit Card", module);
String refNum = UtilDateTime.nowAsString();
@@ -3170,7 +3142,7 @@
*/
public static Map alwaysBadCardNumberProcessor(DispatchContext dctx, Map context) {
Map result = ServiceUtil.returnSuccess();
- Double processAmount = (Double) context.get("processAmount");
+ BigDecimal processAmount = (BigDecimal) context.get("processAmount");
Debug.logInfo("Test Processor Bad Card Number Credit Card", module);
String refNum = UtilDateTime.nowAsString();
@@ -3229,7 +3201,7 @@
*/
public static Map testCCProcessorCaptureAlwaysDecline(DispatchContext dctx, Map context) {
Map result = ServiceUtil.returnSuccess();
- Double processAmount = (Double) context.get("captureAmount");
+ BigDecimal processAmount = (BigDecimal) context.get("captureAmount");
Debug.logInfo("Test Processor Declining Credit Card capture", module);
String refNum = UtilDateTime.nowAsString();
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java Mon Jan 5 23:13:36 2009
@@ -233,13 +233,13 @@
/**
* Method to return the total amount of an payment which is applied to a payment
* @param payment GenericValue object of the Payment
- * @return the applied total as double
+ * @return the applied total as BigDecimal
*/
- public static double getPaymentApplied(GenericDelegator delegator, String paymentId) {
- return getPaymentAppliedBd(delegator, paymentId, false).doubleValue();
+ public static BigDecimal getPaymentApplied(GenericDelegator delegator, String paymentId) {
+ return getPaymentApplied(delegator, paymentId, false);
}
- public static BigDecimal getPaymentAppliedBd(GenericDelegator delegator, String paymentId, Boolean actual) {
+ public static BigDecimal getPaymentApplied(GenericDelegator delegator, String paymentId, Boolean actual) {
if (delegator == null) {
throw new IllegalArgumentException("Null delegator is not allowed in this method");
}
@@ -255,7 +255,7 @@
throw new IllegalArgumentException("The paymentId passed does not match an existing payment");
}
- return getPaymentAppliedBd(payment, actual);
+ return getPaymentApplied(payment, actual);
}
/**
* Method to return the amount applied converted to the currency of payment
@@ -286,19 +286,10 @@
/**
* Method to return the total amount of an payment which is applied to a payment
* @param payment GenericValue object of the Payment
- * @return the applied total as double
- */
- public static double getPaymentApplied(GenericValue payment) {
- return getPaymentAppliedBd(payment).doubleValue();
- }
-
- /**
- * Method to return the total amount of an payment which is applied to a payment
- * @param payment GenericValue object of the Payment
* @return the applied total as BigDecimal in the currency of the payment
*/
- public static BigDecimal getPaymentAppliedBd(GenericValue payment) {
- return getPaymentAppliedBd(payment, false);
+ public static BigDecimal getPaymentApplied(GenericValue payment) {
+ return getPaymentApplied(payment, false);
}
/**
@@ -307,7 +298,7 @@
* @param false for currency of the payment, true for the actual currency
* @return the applied total as BigDecimal in the currency of the payment
*/
- public static BigDecimal getPaymentAppliedBd(GenericValue payment, Boolean actual) {
+ public static BigDecimal getPaymentApplied(GenericValue payment, Boolean actual) {
BigDecimal paymentApplied = BigDecimal.ZERO;
List paymentApplications = null;
try {
@@ -337,28 +328,20 @@
}
return paymentApplied;
}
- public static double getPaymentNotApplied(GenericValue payment) {
- return getPaymentNotAppliedBd(payment).doubleValue();
- }
-
- public static BigDecimal getPaymentNotAppliedBd(GenericValue payment) {
- return payment.getBigDecimal("amount").subtract(getPaymentAppliedBd(payment)).setScale(decimals,rounding);
+ public static BigDecimal getPaymentNotApplied(GenericValue payment) {
+ return payment.getBigDecimal("amount").subtract(getPaymentApplied(payment)).setScale(decimals,rounding);
}
- public static BigDecimal getPaymentNotAppliedBd(GenericValue payment, Boolean actual) {
+ public static BigDecimal getPaymentNotApplied(GenericValue payment, Boolean actual) {
if (actual.equals(Boolean.TRUE) && UtilValidate.isNotEmpty(payment.getBigDecimal("actualCurrencyAmount"))) {
- return payment.getBigDecimal("actualCurrencyAmount").subtract(getPaymentAppliedBd(payment, actual)).setScale(decimals,rounding);
+ return payment.getBigDecimal("actualCurrencyAmount").subtract(getPaymentApplied(payment, actual)).setScale(decimals,rounding);
}
- return payment.getBigDecimal("amount").subtract(getPaymentAppliedBd(payment)).setScale(decimals,rounding);
+ return payment.getBigDecimal("amount").subtract(getPaymentApplied(payment)).setScale(decimals,rounding);
}
- public static double getPaymentNotApplied(GenericDelegator delegator, String paymentId) {
- return getPaymentNotAppliedBd(delegator,paymentId, false).doubleValue();
+ public static BigDecimal getPaymentNotApplied(GenericDelegator delegator, String paymentId) {
+ return getPaymentNotApplied(delegator,paymentId, false);
}
public static BigDecimal getPaymentNotApplied(GenericDelegator delegator, String paymentId, Boolean actual) {
- return getPaymentNotAppliedBd(delegator,paymentId, actual);
- }
-
- public static BigDecimal getPaymentNotAppliedBd(GenericDelegator delegator, String paymentId, Boolean actual) {
if (delegator == null) {
throw new IllegalArgumentException("Null delegator is not allowed in this method");
}
@@ -373,6 +356,6 @@
if (payment == null) {
throw new IllegalArgumentException("The paymentId passed does not match an existing payment");
}
- return payment.getBigDecimal("amount").subtract(getPaymentAppliedBd(delegator,paymentId, actual)).setScale(decimals,rounding);
+ return payment.getBigDecimal("amount").subtract(getPaymentApplied(delegator,paymentId, actual)).setScale(decimals,rounding);
}
}
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java Mon Jan 5 23:13:36 2009
@@ -409,7 +409,7 @@
GenericValue partyTaxInfo = (GenericValue) partyTaxInfos.get(0);
adjValue.set("customerReferenceId", partyTaxInfo.get("partyTaxId"));
if ("Y".equals(partyTaxInfo.getString("isExempt"))) {
- adjValue.set("amount", new Double(0));
+ adjValue.set("amount", BigDecimal.ZERO);
adjValue.set("exemptAmount", taxAmount);
foundExemption = true;
}
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/test/FinAccountTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/test/FinAccountTests.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/test/FinAccountTests.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/test/FinAccountTests.java Mon Jan 5 23:13:36 2009
@@ -27,6 +27,7 @@
import org.ofbiz.service.ModelService;
import org.ofbiz.base.util.UtilMisc;
+import java.math.BigDecimal;
import java.util.Map;
import javolution.util.FastMap;
@@ -65,21 +66,21 @@
public void testDeposit() throws Exception {
Map ctx = FastMap.newInstance();
ctx.put("finAccountId", "TESTACCOUNT1");
- ctx.put("amount", new Double(100.00));
+ ctx.put("amount", new BigDecimal("100.00"));
ctx.put("userLogin", userLogin);
Map resp = dispatcher.runSync("finAccountDeposit", ctx);
- Double balance = ((Double) resp.get("balance")).doubleValue();
- assertEquals(balance, 100.00, 0.0);
+ BigDecimal balance = (BigDecimal) resp.get("balance");
+ assertEquals(balance.toPlainString(), "100.00");
}
public void testWithdraw() throws Exception {
Map ctx = FastMap.newInstance();
ctx.put("finAccountId", "TESTACCOUNT1");
- ctx.put("amount", new Double(50.00));
+ ctx.put("amount", new BigDecimal("50.00"));
ctx.put("userLogin", userLogin);
Map resp = dispatcher.runSync("finAccountWithdraw", ctx);
- Double previousBalance = (Double) resp.get("previousBalance");
- Double balance = ((Double) resp.get("balance")).doubleValue();
- assertEquals((balance + 50.00), previousBalance.doubleValue(), 0.0);
+ BigDecimal previousBalance = (BigDecimal) resp.get("previousBalance");
+ BigDecimal balance = ((BigDecimal) resp.get("balance"));
+ assertEquals(balance.add(new BigDecimal("50.00")).toPlainString(), previousBalance.toPlainString());
}
}
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMPaymentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMPaymentServices.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMPaymentServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMPaymentServices.java Mon Jan 5 23:13:36 2009
@@ -28,6 +28,7 @@
import org.ofbiz.service.ModelService;
import org.ofbiz.service.ServiceUtil;
+import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.*;
@@ -212,13 +213,13 @@
if (canDoVoid) {
Debug.logWarning("Refund was unsuccessful; will now attempt a VOID transaction.", module);
- Double authAmountObj = authTransaction.getDouble("amount");
- Double refundAmountObj = (Double)context.get("refundAmount");
+ BigDecimal authAmountObj = authTransaction.getBigDecimal("amount");
+ BigDecimal refundAmountObj = (BigDecimal)context.get("refundAmount");
- double authAmount = authAmountObj != null? authAmountObj.doubleValue() : 0.0;
- double refundAmount = refundAmountObj != null? refundAmountObj.doubleValue() : 0.0;
+ BigDecimal authAmount = authAmountObj != null ? authAmountObj : BigDecimal.ZERO;
+ BigDecimal refundAmount = refundAmountObj != null ? refundAmountObj : BigDecimal.ZERO;
- if (authAmount == refundAmount) {
+ if (authAmount.compareTo(refundAmount) == 0) {
reply = voidTransaction(authTransaction, context);
if (ServiceUtil.isError(reply)) {
return reply;
@@ -534,7 +535,7 @@
private static void buildAuthTransaction(Map params, Properties props, Map AIMRequest) {
GenericValue cc = (GenericValue)params.get("creditCard");
String currency = (String) params.get("currency");
- String amount = ((Double)params.get("processAmount")).toString();
+ String amount = ((BigDecimal)params.get("processAmount")).toString();
String number = UtilFormatOut.checkNull(cc.getString("cardNumber"));
String expDate = UtilFormatOut.checkNull(cc.getString("expireDate"));
String cardSecurityCode = (String) params.get("cardSecurityCode");
@@ -555,7 +556,7 @@
GenericValue at = (GenericValue)params.get("authTransaction");
GenericValue cc = (GenericValue)params.get("creditCard");
String currency = (String) params.get("currency");
- String amount = ((Double)params.get("captureAmount")).toString();
+ String amount = ((BigDecimal)params.get("captureAmount")).toString();
String number = UtilFormatOut.checkNull(cc.getString("cardNumber"));
String expDate = UtilFormatOut.checkNull(cc.getString("expireDate"));
@@ -573,7 +574,7 @@
GenericValue at = (GenericValue)params.get("authTransaction");
GenericValue cc = (GenericValue)params.get("creditCard");
String currency = (String) params.get("currency");
- String amount = ((Double)params.get("refundAmount")).toString();
+ String amount = ((BigDecimal)params.get("refundAmount")).toString();
String number = UtilFormatOut.checkNull(cc.getString("cardNumber"));
String expDate = UtilFormatOut.checkNull(cc.getString("expireDate"));
@@ -622,10 +623,10 @@
results.put("authRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
results.put("cvCode", ar.getResponseField(AuthorizeResponse.CID_RESPONSE_CODE));
results.put("avsCode", ar.getResponseField(AuthorizeResponse.AVS_RESULT_CODE));
- results.put("processAmount", new Double(ar.getResponseField(AuthorizeResponse.AMOUNT)));
+ results.put("processAmount", new BigDecimal(ar.getResponseField(AuthorizeResponse.AMOUNT)));
} else {
results.put("authCode", ar.getResponseCode());
- results.put("processAmount", new Double("0.00"));
+ results.put("processAmount", new BigDecimal("0.00"));
results.put("authRefNum", AuthorizeResponse.ERROR);
}
@@ -643,9 +644,9 @@
if(captureResult.booleanValue()) { //passed
results.put("captureCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
- results.put("captureAmount", new Double(ar.getResponseField(AuthorizeResponse.AMOUNT)));
+ results.put("captureAmount", new BigDecimal(ar.getResponseField(AuthorizeResponse.AMOUNT)));
} else {
- results.put("captureAmount", new Double("0.00"));
+ results.put("captureAmount", new BigDecimal("0.00"));
}
@@ -663,9 +664,9 @@
if(captureResult.booleanValue()) { //passed
results.put("refundCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
- results.put("refundAmount", new Double(ar.getResponseField(AuthorizeResponse.AMOUNT)));
+ results.put("refundAmount", new BigDecimal(ar.getResponseField(AuthorizeResponse.AMOUNT)));
} else {
- results.put("refundAmount", new Double("0.00"));
+ results.put("refundAmount", new BigDecimal("0.00"));
}
Debug.logInfo("processRefundTransResult: " + results.toString(),module);
@@ -683,9 +684,9 @@
if(captureResult.booleanValue()) { //passed
results.put("releaseCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
- results.put("releaseAmount", new Double(ar.getResponseField(AuthorizeResponse.AMOUNT)));
+ results.put("releaseAmount", new BigDecimal(ar.getResponseField(AuthorizeResponse.AMOUNT)));
} else {
- results.put("releaseAmount", new Double("0.00"));
+ results.put("releaseAmount", new BigDecimal("0.00"));
}
@@ -709,10 +710,10 @@
results.put("authRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
results.put("cvCode", ar.getResponseField(AuthorizeResponse.CID_RESPONSE_CODE));
results.put("avsCode", ar.getResponseField(AuthorizeResponse.AVS_RESULT_CODE));
- results.put("processAmount", new Double(ar.getResponseField(AuthorizeResponse.AMOUNT)));
+ results.put("processAmount", new BigDecimal(ar.getResponseField(AuthorizeResponse.AMOUNT)));
} else {
results.put("authCode", ar.getResponseCode());
- results.put("processAmount", new Double("0.00"));
+ results.put("processAmount", new BigDecimal("0.00"));
results.put("authRefNum", AuthorizeResponse.ERROR);
}
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCPaymentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCPaymentServices.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCPaymentServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCPaymentServices.java Mon Jan 5 23:13:36 2009
@@ -26,6 +26,7 @@
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.math.BigDecimal;
import javax.xml.parsers.ParserConfigurationException;
@@ -48,11 +49,14 @@
public class CCPaymentServices {
public final static String module = CCPaymentServices.class.getName();
+ private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
+ private static int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
+
public static Map ccAuth(DispatchContext dctx, Map context) {
String ccAction = (String) context.get("ccAction");
if (ccAction == null) ccAction = new String("PreAuth");
- Document authRequestDoc = buildPrimaryTxRequest(context, ccAction, (Double) context.get("processAmount"),
+ Document authRequestDoc = buildPrimaryTxRequest(context, ccAction, (BigDecimal) context.get("processAmount"),
(String) context.get("orderId"));
Document authResponseDoc = null;
@@ -65,7 +69,7 @@
if (getMessageListMaxSev(authResponseDoc) > 4) { // 5 and higher, process error from HSBC
Map result = ServiceUtil.returnSuccess();
result.put("authResult", new Boolean(false));
- result.put("processAmount", new Double(0.00));
+ result.put("processAmount", new BigDecimal("0.00"));
result.put("authRefNum", getReferenceNum(authResponseDoc));
List messages = getMessageList(authResponseDoc);
if (UtilValidate.isNotEmpty(messages)) {
@@ -83,7 +87,7 @@
action = new String("Auth"); // required for periodic billing....
}
- Document creditRequestDoc = buildPrimaryTxRequest(context, action, (Double) context.get("creditAmount"),
+ Document creditRequestDoc = buildPrimaryTxRequest(context, action, (BigDecimal) context.get("creditAmount"),
(String) context.get("referenceCode"));
Document creditResponseDoc = null;
try {
@@ -95,7 +99,7 @@
if (getMessageListMaxSev(creditResponseDoc) > 4) {
Map result = ServiceUtil.returnSuccess();
result.put("creditResult", new Boolean(false));
- result.put("creditAmount", new Double(0.00));
+ result.put("creditAmount", new BigDecimal("0.00"));
result.put("creditRefNum", getReferenceNum(creditResponseDoc));
List messages = getMessageList(creditResponseDoc);
if (UtilValidate.isNotEmpty(messages)) {
@@ -116,7 +120,7 @@
}
Document captureRequestDoc = buildSecondaryTxRequest(context, authTransaction.getString("referenceNum"),
- "PostAuth", (Double) context.get("captureAmount"));
+ "PostAuth", (BigDecimal) context.get("captureAmount"));
Document captureResponseDoc = null;
try {
@@ -128,7 +132,7 @@
if (getMessageListMaxSev(captureResponseDoc) > 4) {
Map result = ServiceUtil.returnSuccess();
result.put("captureResult", new Boolean(false));
- result.put("captureAmount", new Double(0.00));
+ result.put("captureAmount", new BigDecimal("0.00"));
result.put("captureRefNum", getReferenceNum(captureResponseDoc));
List messages = getMessageList(captureResponseDoc);
if (UtilValidate.isNotEmpty(messages)) {
@@ -160,7 +164,7 @@
if (getMessageListMaxSev(releaseResponseDoc) > 4) {
Map result = ServiceUtil.returnSuccess();
result.put("releaseResult", new Boolean(false));
- result.put("releaseAmount", new Double(0.00));
+ result.put("releaseAmount", new BigDecimal("0.00"));
result.put("releaseRefNum", getReferenceNum(releaseResponseDoc));
List messages = getMessageList(releaseResponseDoc);
if (UtilValidate.isNotEmpty(messages)) {
@@ -183,7 +187,7 @@
Map result = ServiceUtil.returnSuccess();
result.put("releaseResult", Boolean.valueOf(true));
result.put("releaseCode", authTransaction.getString("gatewayCode"));
- result.put("releaseAmount", authTransaction.getDouble("amount"));
+ result.put("releaseAmount", authTransaction.getBigDecimal("amount"));
result.put("releaseRefNum", authTransaction.getString("referenceNum"));
result.put("releaseFlag", authTransaction.getString("gatewayFlag"));
result.put("releaseMessage", "Approved.");
@@ -202,7 +206,7 @@
// Although refunds are applied to captured transactions, using the auth reference number is ok here
// Related auth and capture transactions will always have the same reference number
Document refundRequestDoc = buildSecondaryTxRequest(context, authTransaction.getString("referenceNum"),
- "Credit", (Double) context.get("refundAmount"));
+ "Credit", (BigDecimal) context.get("refundAmount"));
Document refundResponseDoc = null;
try {
@@ -214,7 +218,7 @@
if (getMessageListMaxSev(refundResponseDoc) > 4) {
Map result = ServiceUtil.returnSuccess();
result.put("refundResult", new Boolean(false));
- result.put("refundAmount", new Double(0.00));
+ result.put("refundAmount", new BigDecimal("0.00"));
result.put("refundRefNum", getReferenceNum(refundResponseDoc));
List messages = getMessageList(refundResponseDoc);
if (UtilValidate.isNotEmpty(messages)) {
@@ -235,7 +239,7 @@
}
Document reauthRequestDoc = buildSecondaryTxRequest(context, authTransaction.getString("referenceNum"),
- "RePreAuth", (Double) context.get("reauthAmount"));
+ "RePreAuth", (BigDecimal) context.get("reauthAmount"));
Document reauthResponseDoc = null;
try {
@@ -247,7 +251,7 @@
if (getMessageListMaxSev(reauthResponseDoc) > 4) {
Map result = ServiceUtil.returnSuccess();
result.put("reauthResult", new Boolean(false));
- result.put("reauthAmount", new Double(0.00));
+ result.put("reauthAmount", new BigDecimal("0.00"));
result.put("reauthRefNum", getReferenceNum(reauthResponseDoc));
List messages = getMessageList(reauthResponseDoc);
if (UtilValidate.isNotEmpty(messages)) {
@@ -372,10 +376,10 @@
Element currentTotalsElement = UtilXml.firstChildElement(transactionElement, "CurrentTotals");
Element totalsElement = UtilXml.firstChildElement(currentTotalsElement, "Totals");
String authAmountStr = UtilXml.childElementValue(totalsElement, "Total");
- result.put("processAmount", new Double(Double.parseDouble(authAmountStr) / 100));
+ result.put("processAmount", new BigDecimal(authAmountStr).movePointLeft(2));
} else {
result.put("authResult", Boolean.valueOf(false));
- result.put("processAmount", Double.valueOf("0.00"));
+ result.put("processAmount", new BigDecimal("0.00"));
}
result.put("authRefNum", UtilXml.childElementValue(orderFormElement, "Id"));
@@ -418,10 +422,10 @@
Element currentTotalsElement = UtilXml.firstChildElement(transactionElement, "CurrentTotals");
Element totalsElement = UtilXml.firstChildElement(currentTotalsElement, "Totals");
String creditAmountStr = UtilXml.childElementValue(totalsElement, "Total");
- result.put("creditAmount", new Double(Double.parseDouble(creditAmountStr) / 100));
+ result.put("creditAmount", new BigDecimal(creditAmountStr).movePointLeft(2));
} else {
result.put("creditResult", Boolean.valueOf(false));
- result.put("creditAmount", Double.valueOf("0.00"));
+ result.put("creditAmount", new BigDecimal("0.00"));
}
result.put("creditRefNum", UtilXml.childElementValue(orderFormElement, "Id"));
@@ -452,10 +456,10 @@
Element currentTotalsElement = UtilXml.firstChildElement(transactionElement, "CurrentTotals");
Element totalsElement = UtilXml.firstChildElement(currentTotalsElement, "Totals");
String captureAmountStr = UtilXml.childElementValue(totalsElement, "Total");
- result.put("captureAmount", new Double(Double.parseDouble(captureAmountStr) / 100));
+ result.put("captureAmount", new BigDecimal(captureAmountStr).movePointLeft(2));
} else {
result.put("captureResult", Boolean.valueOf(false));
- result.put("captureAmount", Double.valueOf("0.00"));
+ result.put("captureAmount", new BigDecimal("0.00"));
}
result.put("captureRefNum", UtilXml.childElementValue(orderFormElement, "Id"));
@@ -486,10 +490,10 @@
Element currentTotalsElement = UtilXml.firstChildElement(transactionElement, "CurrentTotals");
Element totalsElement = UtilXml.firstChildElement(currentTotalsElement, "Totals");
String releaseAmountStr = UtilXml.childElementValue(totalsElement, "Total");
- result.put("releaseAmount", new Double(Double.parseDouble(releaseAmountStr) / 100));
+ result.put("releaseAmount", new BigDecimal(releaseAmountStr).movePointLeft(2));
} else {
result.put("releaseResult", Boolean.valueOf(false));
- result.put("releaseAmount", Double.valueOf("0.00"));
+ result.put("releaseAmount", new BigDecimal("0.00"));
}
result.put("releaseRefNum", UtilXml.childElementValue(orderFormElement, "Id"));
@@ -520,10 +524,10 @@
Element currentTotalsElement = UtilXml.firstChildElement(transactionElement, "CurrentTotals");
Element totalsElement = UtilXml.firstChildElement(currentTotalsElement, "Totals");
String refundAmountStr = UtilXml.childElementValue(totalsElement, "Total");
- result.put("refundAmount", new Double(Double.parseDouble(refundAmountStr) / 100));
+ result.put("refundAmount", new BigDecimal(refundAmountStr).movePointLeft(2));
} else {
result.put("refundResult", Boolean.valueOf(false));
- result.put("refundAmount", Double.valueOf("0.00"));
+ result.put("refundAmount", new BigDecimal("0.00"));
}
result.put("refundRefNum", UtilXml.childElementValue(orderFormElement, "Id"));
@@ -554,10 +558,10 @@
Element currentTotalsElement = UtilXml.firstChildElement(transactionElement, "CurrentTotals");
Element totalsElement = UtilXml.firstChildElement(currentTotalsElement, "Totals");
String reauthAmountStr = UtilXml.childElementValue(totalsElement, "Total");
- result.put("reauthAmount", new Double(Double.parseDouble(reauthAmountStr) / 100));
+ result.put("reauthAmount", new BigDecimal(reauthAmountStr).movePointLeft(2));
} else {
result.put("reauthResult", Boolean.valueOf(false));
- result.put("reauthAmount", Double.valueOf("0.00"));
+ result.put("reauthAmount", new BigDecimal("0.00"));
}
result.put("reauthRefNum", UtilXml.childElementValue(orderFormElement, "Id"));
@@ -627,7 +631,7 @@
return referenceNum;
}
- private static Document buildPrimaryTxRequest(Map context, String type, Double amount, String refNum) {
+ private static Document buildPrimaryTxRequest(Map context, String type, BigDecimal amount, String refNum) {
String paymentConfig = (String) context.get("paymentConfig");
if (UtilValidate.isEmpty(paymentConfig)) {
@@ -707,7 +711,7 @@
return requestDocument;
}
- private static Document buildSecondaryTxRequest(Map context, String id, String type, Double amount) {
+ private static Document buildSecondaryTxRequest(Map context, String id, String type, BigDecimal amount) {
String paymentConfig = (String) context.get("paymentConfig");
if (UtilValidate.isEmpty(paymentConfig)) {
@@ -781,7 +785,7 @@
}
}
- private static void appendTransactionNode(Element element, String type, Double amount, String currencyCode) {
+ private static void appendTransactionNode(Element element, String type, BigDecimal amount, String currencyCode) {
Document document = element.getOwnerDocument();
@@ -795,7 +799,7 @@
// 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);
+ String totalString = amount.setScale(decimals, rounding).movePointRight(2).toPlainString();
Element totalElement = UtilXml.addChildElementValue(totalsElement, "Total", totalString, document);
totalElement.setAttribute("DataType", "Money");
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCServicesTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCServicesTest.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCServicesTest.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCServicesTest.java Mon Jan 5 23:13:36 2009
@@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.lang.Thread;
+import java.math.BigDecimal;
import junit.framework.TestCase;
@@ -57,7 +58,7 @@
protected GenericValue billingAddress = null;
protected GenericValue shippingAddress = null;
protected Map pbOrder = null;
- protected Double creditAmount = null;
+ protected BigDecimal creditAmount = null;
protected String configFile = null;
public CCServicesTest(String name) {
@@ -70,7 +71,7 @@
// populate test data
configFile = new String("paymentTest.properties");
- creditAmount = new Double(234.00);
+ creditAmount = new BigDecimal("234.00");
emailAddr = delegator.makeValue("ContactMech", UtilMisc.toMap(
"infoString","test@hansbakker.com"));
orderId = new String("testOrder1000");
@@ -115,7 +116,7 @@
"shippingAddress", shippingAddress,
"orderId", orderId
);
- serviceInput.put("processAmount", new Double(200.00));
+ serviceInput.put("processAmount", new BigDecimal("200.00"));
// run the service (make sure in payment
Map result = dispatcher.runSync("clearCommerceCCAuth",serviceInput);
@@ -147,7 +148,7 @@
"creditAmount", creditAmount,
"billToEmail", emailAddr,
"creditCard", creditCard,
- "creditAmount", new Double(200.00)
+ "creditAmount", new BigDecimal("200.00")
);
// run the service
Map result = dispatcher.runSync("clearCommerceCCCredit",serviceMap);
@@ -181,7 +182,7 @@
"creditCard", creditCard,
"pbOrder", pbOrder // if supplied, the crediting is for a subscription and credit by period is managed by ClearCommerce
);
- serviceMap.put("creditAmount", new Double(200.00));
+ serviceMap.put("creditAmount", new BigDecimal("200.00"));
// run the service
Map result = dispatcher.runSync("clearCommerceCCCredit",serviceMap);
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/cybersource/IcsPaymentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/cybersource/IcsPaymentServices.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/cybersource/IcsPaymentServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/cybersource/IcsPaymentServices.java Mon Jan 5 23:13:36 2009
@@ -18,6 +18,7 @@
*******************************************************************************/
package org.ofbiz.accounting.thirdparty.cybersource;
+import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
@@ -33,6 +34,7 @@
import org.ofbiz.base.util.SSLUtil;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilNumber;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.string.FlexibleStringExpander;
@@ -47,6 +49,8 @@
public class IcsPaymentServices {
public static final String module = IcsPaymentServices.class.getName();
+ private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
+ private static int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
// load the JSSE properties
static {
@@ -520,13 +524,10 @@
}
// get the quantity..
- Double quantity = item.getDouble("quantity");
+ BigDecimal quantity = item.getBigDecimal("quantity");
// test quantity if INT pass as is; if not pass as 1
- long roundQ = Math.round(quantity);
- Double rounded = new Double(Long.toString(roundQ));
-
- if (rounded.doubleValue() != quantity.doubleValue()) {
+ if (quantity.scale() > 0) {
request.put("item_" + lineNumber + "_quantity", "1");
} else {
request.put("", Integer.toString(quantity.intValue()));
@@ -539,10 +540,8 @@
}
private static String getAmountString(Map context, String amountField) {
- String currencyFormat = UtilProperties.getPropertyValue("general.properties", "currency.decimal.format", "##0.00");
- DecimalFormat formatter = new DecimalFormat(currencyFormat);
- Double processAmount = (Double) context.get(amountField);
- return formatter.format(processAmount);
+ BigDecimal processAmount = (BigDecimal) context.get(amountField);
+ return processAmount.setScale(decimals, rounding).toPlainString();
}
private static void processAuthResult(Map reply, Map<String, Object> result) {
@@ -557,9 +556,9 @@
}
if (reply.get("ccAuthReply_amount") != null) {
- result.put("processAmount", new Double((String) reply.get("ccAuthReply_amount")));
+ result.put("processAmount", new BigDecimal((String) reply.get("ccAuthReply_amount")));
} else {
- result.put("processAmount", 0.00);
+ result.put("processAmount", BigDecimal.ZERO);
}
result.put("authRefNum", reply.get("requestID"));
@@ -583,9 +582,9 @@
}
if (reply.get("ccCaptureReply_amount") != null) {
- result.put("captureAmount", new Double((String) reply.get("ccCaptureReply_amount")));
+ result.put("captureAmount", new BigDecimal((String) reply.get("ccCaptureReply_amount")));
} else {
- result.put("captureAmount", 0.00);
+ result.put("captureAmount", BigDecimal.ZERO);
}
result.put("captureRefNum", reply.get("requestID"));
@@ -605,9 +604,9 @@
}
if (reply.get("ccAuthReversalReply_amount") != null) {
- result.put("releaseAmount", new Double((String) reply.get("ccAuthReversalReply_amount")));
+ result.put("releaseAmount", new BigDecimal((String) reply.get("ccAuthReversalReply_amount")));
} else {
- result.put("releaseAmount", 0.00);
+ result.put("releaseAmount", BigDecimal.ZERO);
}
result.put("releaseRefNum", reply.get("requestID"));
@@ -627,9 +626,9 @@
}
if (reply.get("ccCreditReply_amount") != null) {
- result.put("refundAmount", new Double((String) reply.get("ccCreditReply_amount")));
+ result.put("refundAmount", new BigDecimal((String) reply.get("ccCreditReply_amount")));
} else {
- result.put("refundAmount", 0.00);
+ result.put("refundAmount", BigDecimal.ZERO);
}
result.put("refundRefNum", reply.get("requestID"));
@@ -649,9 +648,9 @@
}
if (reply.get("ccCreditReply_amount") != null) {
- result.put("creditAmount", new Double((String) reply.get("ccCreditReply_amount")));
+ result.put("creditAmount", new BigDecimal((String) reply.get("ccCreditReply_amount")));
} else {
- result.put("creditAmount", 0.00);
+ result.put("creditAmount", BigDecimal.ZERO);
}
result.put("creditRefNum", reply.get("requestID"));
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java Mon Jan 5 23:13:36 2009
@@ -23,9 +23,11 @@
import java.util.List;
import java.text.DecimalFormat;
import java.io.IOException;
+import java.math.BigDecimal;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.base.util.UtilNumber;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.Debug;
@@ -39,6 +41,8 @@
public class PcChargeServices {
public static final String module = PcChargeServices.class.getName();
+ private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
+ private static int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
public static Map ccAuth(DispatchContext dctx, Map context) {
Properties props = buildPccProperties(context);
@@ -423,10 +427,8 @@
}
private static String getAmountString(Map context, String amountField) {
- String currencyFormat = UtilProperties.getPropertyValue("general.properties", "currency.decimal.format", "##0.00");
- DecimalFormat formatter = new DecimalFormat(currencyFormat);
- Double processAmount = (Double) context.get(amountField);
- return formatter.format(processAmount);
+ BigDecimal processAmount = (BigDecimal) context.get(amountField);
+ return processAmount.setScale(decimals, rounding).toPlainString();
}
}
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/gosoftware/RitaServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/gosoftware/RitaServices.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/gosoftware/RitaServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/gosoftware/RitaServices.java Mon Jan 5 23:13:36 2009
@@ -22,6 +22,7 @@
import java.util.Properties;
import java.util.List;
import java.io.IOException;
+import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.sql.Timestamp;
@@ -33,6 +34,7 @@
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.StringUtil;
+import org.ofbiz.base.util.UtilNumber;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilDateTime;
@@ -46,6 +48,8 @@
public class RitaServices {
public static final String module = RitaServices.class.getName();
+ private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
+ private static int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
public static Map ccAuth(DispatchContext dctx, Map context) {
Properties props = buildPccProperties(context);
@@ -524,9 +528,7 @@
}
private static String getAmountString(Map context, String amountField) {
- String currencyFormat = UtilProperties.getPropertyValue("general.properties", "currency.decimal.format", "##0.00");
- DecimalFormat formatter = new DecimalFormat(currencyFormat);
- Double processAmount = (Double) context.get(amountField);
- return formatter.format(processAmount);
+ BigDecimal processAmount = (BigDecimal) context.get(amountField);
+ return processAmount.setScale(decimals, rounding).toPlainString();
}
}
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java Mon Jan 5 23:13:36 2009
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.math.BigDecimal;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
@@ -82,7 +83,7 @@
}
// get the order total
- String orderTotal = UtilFormatOut.formatPrice(orderHeader.getDouble("grandTotal"));
+ String orderTotal = orderHeader.getBigDecimal("grandTotal").toPlainString();
// get the product store
GenericValue productStore = ProductStoreWorker.getProductStore(request);
@@ -445,7 +446,7 @@
authDate = UtilDateTime.nowTimestamp();
}
- paymentPreference.set("maxAmount", new Double(paymentAmount));
+ paymentPreference.set("maxAmount", new BigDecimal(paymentAmount));
if (paymentStatus.equals("Completed")) {
paymentPreference.set("statusId", "PAYMENT_RECEIVED");
} else if (paymentStatus.equals("Pending")) {
@@ -468,7 +469,7 @@
response.set("paymentMethodId", paymentPreference.get("paymentMethodId"));
// set the auth info
- response.set("amount", new Double(paymentAmount));
+ response.set("amount", new BigDecimal(paymentAmount));
response.set("referenceNum", transactionId);
response.set("gatewayCode", paymentStatus);
response.set("gatewayFlag", paymentStatus.substring(0,1));
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/valuelink/ValueLinkApi.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/valuelink/ValueLinkApi.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/valuelink/ValueLinkApi.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/valuelink/ValueLinkApi.java Mon Jan 5 23:13:36 2009
@@ -18,6 +18,7 @@
*******************************************************************************/
package org.ofbiz.accounting.thirdparty.valuelink;
+import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@@ -664,42 +665,27 @@
/**
* Returns a ValueLink formatted amount String
- * @param amount Double value to format
+ * @param amount BigDecimal value to format
* @return Formatted String
*/
- public String getAmount(Double amount) {
+ public String getAmount(BigDecimal amount) {
if (amount == null) {
return "0.00";
}
- String currencyFormat = UtilProperties.getPropertyValue("general.properties", "currency.decimal.format", "##0.00");
- DecimalFormat formatter = new DecimalFormat(currencyFormat);
- String amountString = formatter.format(amount.doubleValue());
- Double newAmount = null;
- try {
- newAmount = new Double(formatter.parse(amountString).doubleValue());
- } catch (ParseException e) {
- Debug.logError(e, "Unable to parse amount Double");
- }
-
- String formattedString = null;
- if (newAmount != null) {
- double amountDouble = newAmount.doubleValue() * 100;
- formattedString = Integer.toString(new Double(amountDouble).intValue());
- }
- return formattedString;
+ return Integer.toString(amount.movePointRight(2).intValue());
}
/**
- * Returns a Double from a ValueLink formatted amount String
+ * Returns a BigDecimal from a ValueLink formatted amount String
* @param amount The ValueLink formatted amount String
- * @return Double object
+ * @return BigDecimal object
*/
- public Double getAmount(String amount) {
+ public BigDecimal getAmount(String amount) {
if (amount == null) {
- return new Double(0.00);
+ return new BigDecimal("0.00");
}
- Double doubleAmount = new Double(amount);
- return new Double(doubleAmount.doubleValue() / 100);
+ BigDecimal amountBd = new BigDecimal(amount);
+ return amountBd.movePointLeft(2);
}
public String getCurrency(String currency) {
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/valuelink/ValueLinkServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/valuelink/ValueLinkServices.java?rev=731851&r1=731850&r2=731851&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/valuelink/ValueLinkServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/valuelink/ValueLinkServices.java Mon Jan 5 23:13:36 2009
@@ -18,6 +18,7 @@
*******************************************************************************/
package org.ofbiz.accounting.thirdparty.valuelink;
+import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -199,7 +200,7 @@
String currency = (String) context.get("currency");
String orderId = (String) context.get("orderId");
String partyId = (String) context.get("partyId");
- Double amount = (Double) context.get("amount");
+ BigDecimal amount = (BigDecimal) context.get("amount");
// override interface for void/rollback
String iFace = (String) context.get("Interface");
@@ -328,7 +329,7 @@
String pin = (String) context.get("pin");
String orderId = (String) context.get("orderId");
String partyId = (String) context.get("partyId");
- Double amount = (Double) context.get("amount");
+ BigDecimal amount = (BigDecimal) context.get("amount");
// get an api instance
ValueLinkApi vl = ValueLinkApi.getInstance(delegator, props);
@@ -385,7 +386,7 @@
String currency = (String) context.get("currency");
String orderId = (String) context.get("orderId");
String partyId = (String) context.get("partyId");
- Double amount = (Double) context.get("amount");
+ BigDecimal amount = (BigDecimal) context.get("amount");
// override interface for void/rollback
String iFace = (String) context.get("Interface");
@@ -452,7 +453,7 @@
String currency = (String) context.get("currency");
String orderId = (String) context.get("orderId");
String partyId = (String) context.get("partyId");
- Double amount = (Double) context.get("amount");
+ BigDecimal amount = (BigDecimal) context.get("amount");
// override interface for void/rollback
String iFace = (String) context.get("Interface");
@@ -629,7 +630,7 @@
String currency = (String) context.get("currency");
String orderId = (String) context.get("orderId");
String partyId = (String) context.get("partyId");
- Double amount = (Double) context.get("amount");
+ BigDecimal amount = (BigDecimal) context.get("amount");
// override interface for void/rollback
String iFace = (String) context.get("Interface");
@@ -781,7 +782,7 @@
String paymentConfig = (String) context.get("paymentConfig");
String currency = (String) context.get("currency");
String orderId = (String) context.get("orderId");
- Double amount = (Double) context.get("processAmount");
+ BigDecimal amount = (BigDecimal) context.get("processAmount");
// make sure we have a currency
if (currency == null) {
@@ -812,13 +813,13 @@
Boolean processResult = (Boolean) redeemResult.get("processResult");
// confirm the amount redeemed; since VL does not error in insufficient funds
if (processResult.booleanValue()) {
- Double previous = (Double) redeemResult.get("previousAmount");
- if (previous == null) previous = new Double(0);
- Double current = (Double) redeemResult.get("amount");
- if (current == null) current = new Double(0);
- double redeemed = (((double) Math.round((previous.doubleValue() - current.doubleValue()) * 100)) / 100);
+ BigDecimal previous = (BigDecimal) redeemResult.get("previousAmount");
+ if (previous == null) previous = BigDecimal.ZERO;
+ BigDecimal current = (BigDecimal) redeemResult.get("amount");
+ if (current == null) current = BigDecimal.ZERO;
+ BigDecimal redeemed = previous.subtract(current);
Debug.logInfo("Redeemed (" + amount + "): " + redeemed + " / " + previous + " : " + current, module);
- if (redeemed < amount.doubleValue()) {
+ if (redeemed.compareTo(amount) < 0) {
// we didn't redeem enough void the transaction and return false
Map voidResult = null;
try {
@@ -830,7 +831,7 @@
return voidResult;
}
processResult = Boolean.FALSE;
- amount = new Double(redeemed);
+ amount = redeemed;
result.put("authMessage", "Gift card did not contain enough funds");
}
}
@@ -854,7 +855,7 @@
GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
String paymentConfig = (String) context.get("paymentConfig");
String currency = (String) context.get("currency");
- Double amount = (Double) context.get("releaseAmount");
+ BigDecimal amount = (BigDecimal) context.get("releaseAmount");
// get the orderId for tracking
String orderId = paymentPref.getString("orderId");
@@ -915,7 +916,7 @@
GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
String paymentConfig = (String) context.get("paymentConfig");
String currency = (String) context.get("currency");
- Double amount = (Double) context.get("refundAmount");
+ BigDecimal amount = (BigDecimal) context.get("refundAmount");
// get the orderId for tracking
String orderId = paymentPref.getString("orderId");
@@ -1029,8 +1030,8 @@
}
// amount/quantity of the gift card(s)
- Double amount = orderItem.getDouble("unitPrice");
- Double quantity = orderItem.getDouble("quantity");
+ BigDecimal amount = orderItem.getBigDecimal("unitPrice");
+ BigDecimal quantity = orderItem.getBigDecimal("quantity");
// the product entity needed for information
GenericValue product = null;
@@ -1306,7 +1307,7 @@
}
// amount of the gift card reload
- Double amount = orderItem.getDouble("unitPrice");
+ BigDecimal amount = orderItem.getBigDecimal("unitPrice");
// survey information
String surveyId = UtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.reload.surveyId");