private static BigDecimal determineBillingAccountAmount(String billingAccountId,String billingAccountAmount,LocalDispatcher dispatcher){
  BigDecimal billingAccountAmt=null;
  if (UtilValidate.isNotEmpty(billingAccountId)) {
    if (UtilValidate.isNotEmpty(billingAccountAmount)) {
      try {
        billingAccountAmt=new BigDecimal(billingAccountAmount);
      }
 catch (      NumberFormatException e) {
        return null;
      }
    }
    if (billingAccountAmt == null) {
      billingAccountAmt=BigDecimal.ZERO;
    }
    BigDecimal availableBalance=CheckOutHelper.availableAccountBalance(billingAccountId,dispatcher);
    BigDecimal chargeAmount=BigDecimal.ZERO;
    if (billingAccountAmt.compareTo(availableBalance) < 0) {
      chargeAmount=billingAccountAmt;
    }
 else {
      chargeAmount=availableBalance;
    }
    if (chargeAmount.compareTo(BigDecimal.ZERO) < 0.0) {
      chargeAmount=BigDecimal.ZERO;
    }
    return chargeAmount;
  }
 else {
    return null;
  }
}

private static BigDecimal determineBillingAccountAmount ( String billingAccountId , String billingAccountAmount , LocalDispatcher dispatcher ) { BigDecimal billingAccountAmt = null ; if ( UtilValidate . isNotEmpty ( billingAccountId ) ) { if ( UtilValidate . isNotEmpty ( billingAccountAmount ) ) { try { billingAccountAmt = new BigDecimal ( billingAccountAmount ) ; } catch ( NumberFormatException e ) { return null ; } } if ( billingAccountAmt == null ) { billingAccountAmt = BigDecimal . ZERO ; } BigDecimal availableBalance = CheckOutHelper . availableAccountBalance ( billingAccountId , dispatcher ) ; BigDecimal chargeAmount = BigDecimal . ZERO ; if ( billingAccountAmt . compareTo ( availableBalance ) < 0 ) { chargeAmount = billingAccountAmt ; } else { chargeAmount = availableBalance ; } if ( chargeAmount . compareTo ( BigDecimal . ZERO ) < 0.0 ) { chargeAmount = BigDecimal . ZERO ; } return chargeAmount ; } else { return null ; } }
determine what billing account amount to use based on the form input . this method returns the amount that will be charged to the billing account . an amount can be associated with the billingaccountid with a parameter billingaccountamount . if no amount is specified , then the entire available balance of the given billing account will be used . if there is an error , a null will be returned .
