You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2008/01/22 01:44:49 UTC

svn commit: r614072 - /ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java

Author: jleroux
Date: Mon Jan 21 16:44:48 2008
New Revision: 614072

URL: http://svn.apache.org/viewvc?rev=614072&view=rev
Log:
A patch from Rashko Rejmer "Prevent NPEs while authorizing GC" (https://issues.apache.org/jira/browse/OFBIZ-1589) - OFBIZ-1589
Commited in CTR mode (reviewed but not tested, only compiled) as this patch makes sense and can't be harmful

Modified:
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java?rev=614072&r1=614071&r2=614072&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java Mon Jan 21 16:44:48 2008
@@ -447,18 +447,23 @@
             GenericValue giftCertSettings = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId));
             GenericValue finAccount = null;
             String finAccountId = null;
-            if ("Y".equals(giftCertSettings.getString("requirePinCode"))) {
-                if (validatePin(delegator, giftCard.getString("cardNumber"), giftCard.getString("pinNumber"))) {
-                    finAccountId = giftCard.getString("cardNumber");
-                    finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", finAccountId));
-                } 
+            if (UtilValidate.isNotEmpty(giftCertSettings)) {
+                if ("Y".equals(giftCertSettings.getString("requirePinCode"))) {
+                    if (validatePin(delegator, giftCard.getString("cardNumber"), giftCard.getString("pinNumber"))) {
+                        finAccountId = giftCard.getString("cardNumber");
+                        finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", finAccountId));
+                    } 
+                } else {
+                        finAccount = FinAccountHelper.getFinAccountFromCode(giftCard.getString("cardNumber"), delegator);
+                        if (finAccount == null) {
+                            return ServiceUtil.returnError("Gift certificate not found");
+                        }
+                        finAccountId = finAccount.getString("finAccountId");
+                }
             } else {
-                    finAccount = FinAccountHelper.getFinAccountFromCode(giftCard.getString("cardNumber"), delegator);
-                    if (finAccount == null) {
-                        return ServiceUtil.returnError("Gift certificate not found");
-                    }
-                    finAccountId = finAccount.getString("finAccountId");
+                return ServiceUtil.returnError("No product store financial account settings available");
             }
+            
             if (finAccountId == null) {
                 return ServiceUtil.returnError("Gift certificate pin number is invalid");
             }
@@ -478,7 +483,7 @@
             BigDecimal amountBd = (new BigDecimal(amount.doubleValue())).setScale(FinAccountHelper.decimals, FinAccountHelper.rounding);
 
             // if availableBalance equal to or greater than amount, then auth
-            if (availableBalance.compareTo(amountBd) > -1) {
+            if (UtilValidate.isNotEmpty(availableBalance) && availableBalance.compareTo(amountBd) > -1) {
                 Timestamp thruDate = null;
                 if (giftCertSettings.getLong("authValidDays") != null) {
                     thruDate = UtilDateTime.getDayEnd(UtilDateTime.nowTimestamp(), giftCertSettings.getLong("authValidDays"));