/** * Adds a parameter to the request after checking its length. * If longer, throws an ErrorCodeException with the provided <code>TransactionResult.ErrorCode</code>, otherwise appends the value. */ protected static void addMaxLengthParameter(Map<String,String> request, String name, String value, int maxLength, TransactionResult.ErrorCode errorCode) throws ErrorCodeException { if(value.length()>maxLength) { throw new ErrorCodeException( errorCode, "TransactionRequest.field.tooLong", name, maxLength ); } request.put(name, value); }
throw new ErrorCodeException( err, TransactionResult.ErrorCode.ERROR_TRY_AGAIN,
throw new ErrorCodeException(TransactionResult.ErrorCode.INVALID_CURRENCY_CODE, "TransactionResult.ErrorCode.INVALID_CURRENCY_CODE"); if(command.indexOf(':')!=-1) throw new ErrorCodeException(new IllegalArgumentException("command may not contain a colon (:): "+command), TransactionResult.ErrorCode.HASH_CHECK_FAILED, "TransactionResult.ErrorCode.HASH_CHECK_FAILED"); if(pin.indexOf(':')!=-1) throw new ErrorCodeException(new IllegalArgumentException("pin may not contain a colon (:): "+pin), TransactionResult.ErrorCode.HASH_CHECK_FAILED, "TransactionResult.ErrorCode.HASH_CHECK_FAILED"); hashData.append(command).append(':').append(pin).append(':').append(amount.toString()).append(':'); if(invoiceNumber!=null && invoiceNumber.length()>0) hashData.append(invoiceNumber); request.put("UMhash", hash); } catch(NoSuchAlgorithmException err) { throw new ErrorCodeException(err, TransactionResult.ErrorCode.HASH_CHECK_FAILED, "TransactionResult.ErrorCode.HASH_CHECK_FAILED"); throw new ErrorCodeException(TransactionResult.ErrorCode.HASH_CHECK_FAILED, "TransactionResult.ErrorCode.HASH_CHECK_FAILED"); if(slashPos1==-1) { System.err.println("Unable to find first slash: "+responseHash); throw new ErrorCodeException(TransactionResult.ErrorCode.HASH_CHECK_FAILED, "TransactionResult.ErrorCode.HASH_CHECK_FAILED"); throw new ErrorCodeException(TransactionResult.ErrorCode.HASH_CHECK_FAILED, "TransactionResult.ErrorCode.HASH_CHECK_FAILED"); if(slashPos2==-1) { System.err.println("Unable to find second slash: "+responseHash); throw new ErrorCodeException(TransactionResult.ErrorCode.HASH_CHECK_FAILED, "TransactionResult.ErrorCode.HASH_CHECK_FAILED"); if(!expectedMd5.equalsIgnoreCase(responseMd5)) { System.err.println("Response MD5 != Expected MD5: "+responseMd5+" != "+expectedMd5); throw new ErrorCodeException(TransactionResult.ErrorCode.HASH_CHECK_FAILED, "TransactionResult.ErrorCode.HASH_CHECK_FAILED"); throw new ErrorCodeException(err, TransactionResult.ErrorCode.HASH_CHECK_FAILED, "TransactionResult.ErrorCode.HASH_CHECK_FAILED");
try { if(!transactionRequest.getCurrency().getCurrencyCode().equals("USD")) throw new ErrorCodeException(TransactionResult.ErrorCode.INVALID_CURRENCY_CODE, "TransactionResult.ErrorCode.INVALID_CURRENCY_CODE");