List<DirectResponse> directResponses = result.getDirectResponseList();
// check ResponseReasonCode to see if it means we should throw an exception
if (directResponses != null && directResponses.size() > 0) {
Map<ResponseField,String> directResponseMap = directResponses.get(0).getDirectResponseMap();
ResponseCode responseCode = ResponseCode.findByResponseCode(directResponseMap.get(ResponseField.RESPONSE_CODE));
ResponseReasonCode responseReasonCode = ResponseReasonCode.findByReasonCode(directResponseMap.get(ResponseField.RESPONSE_REASON_CODE));
// check exceptionMap to see if we should throw specific exception
Class<? extends AuthorizeNetException> exceptionClass = exceptionMap.get(responseReasonCode);
if (exceptionClass != null) {
log.info(logOperation + " failed in amount of " + amount + " for " + userId + ": " + responseReasonCode);
try {
Constructor<? extends AuthorizeNetException> constructor = exceptionClass.getConstructor(String.class);
throw constructor.newInstance(responseReasonCode.getReasonText());
}
catch (NoSuchMethodException e) { /* fall through */ }
catch (InvocationTargetException e) { /* fall through */ }
catch (IllegalAccessException e) { /* fall through */ }
catch (InstantiationException e) { /* fall through */ }
log.warn("Exception class " + exceptionClass.getSimpleName() + " failed reflection instantiation");
// we know we want an exception but failed to instantiate it. Throw ANE as default
throw new AuthorizeNetException(responseReasonCode.getReasonText());
}
// umbrella processing for DECLINED
if (responseCode == ResponseCode.DECLINED) {
log.info(logOperation + " failed in amount of " + amount + " for " + userId + ": " + responseReasonCode);
throw new PaymentDeclinedException(responseReasonCode.getReasonText());
}
}
// map all other failures (where no DirectResponseMap or RRC may not be in exceptionMap) into ANE
if (!result.isOk()) {