@Override protected PaymentTask selectDelegate(PaymentDTOEx paymentInfo) throws PluggableTaskException { Integer userId = paymentInfo.getUserId(); String processorName = getProcessorName(userId); if (processorName == null) { return null; } Integer selectedTaskId; try { // it is a task parameter the id of the processor selectedTaskId = intValueOf(parameters.get(processorName)); } catch (NumberFormatException e) { throw new PluggableTaskException( "Invalid payment task id :" + processorName + " for userId: " + userId); } if (selectedTaskId == null) { LOG.warn("Could not find processor for " + parameters.get(processorName)); return null; } LOG.debug("Delegating to task id " + selectedTaskId); PaymentTask selectedTask = instantiateTask(selectedTaskId); return selectedTask; }
private Map<String, Object> getRefundData(PaymentDTOEx paymentInfo) throws PluggableTaskException { Map<String, Object> data = getData(paymentInfo); data.put("itemCode", paymentInfo.getPayment().getAuthorization().getTransactionId()); data.put("creditIndicator", Boolean.TRUE); data.put("type", "credit-request"); return data; }
public boolean preAuth(PaymentDTOEx payment) throws PluggableTaskException { try { validateParameters(); Map<String, Object> data = getChargeData(payment); PaymentAuthorizationDTO response = makeCall(data, false); PaymentAuthorizationDTO authDtoEx = new PaymentAuthorizationDTO(response); PaymentAuthorizationBL bl = new PaymentAuthorizationBL(); bl.create(authDtoEx, payment.getId()); payment.setAuthorization(authDtoEx); return false; } catch (Exception e) { log.error("error trying to pre-authorize", e); return true; } }
private Map<String, Object> getData(PaymentDTOEx paymentInfo) throws PluggableTaskException { PaymentInformationBL piBl = new PaymentInformationBL(); Map<String, Object> data = new HashMap<String, Object>(); data.put("merchantAccountCode", ensureGetParameter(PARAMETER_MERCHANT_ACCOUNT_CODE.getName())); if (paymentInfo.getUserId() != null) data.put("customerAccountCode", String.valueOf(paymentInfo.getUserId())); data.put( "accountNumber", piBl.getStringMetaFieldByType( paymentInfo.getInstrument(), MetaFieldType.PAYMENT_CARD_NUMBER)); data.put( "name", piBl.getStringMetaFieldByType(paymentInfo.getInstrument(), MetaFieldType.TITLE)); data.put("amount", paymentInfo.getAmount().multiply(new BigDecimal("100")).intValue()); data.put("taxAmount", 0); // This was not being set in previous code too // String securityCode = paymentInfo.getCreditCard().getSecurityCode(); // if (securityCode != null) // data.put("cvv2", securityCode); data.put("expirationDate", piBl.get4digitExpiry(paymentInfo.getInstrument())); data.put("transactionDate", paymentInfo.getPaymentDate()); data.put("transactionCode", paymentInfo.getId() + ""); return data; }
public boolean process(PaymentDTOEx paymentInfo) throws PluggableTaskException { boolean retValue = false; if (paymentInfo.getPayoutId() != null) { return true; } try { if (!new PaymentInformationBL().isCreditCard(paymentInfo.getInstrument())) { log.error("Can't process without a credit card"); throw new TaskException("Credit card not present in payment"); } if (paymentInfo.getIsRefund() == 1 && (paymentInfo.getPayment() == null || paymentInfo.getPayment().getAuthorization() == null)) { log.error("Can't process refund without a payment with an authorization record"); throw new TaskException("Refund without previous authorization"); } validateParameters(); Map<String, Object> data; if (paymentInfo.getIsRefund() == 0) { data = getChargeData(paymentInfo); } else { data = getRefundData(paymentInfo); } if ("true".equals(getOptionalParameter(PARAMETER_AVS.getName(), "false"))) { addAVSFields(paymentInfo.getUserId(), data); /* #12686 - We do not want to log credit card numbers */ Map<String, Object> dataLog = (Map<String, Object>) ((HashMap<String, Object>) data).clone(); // dataLog.remove("accountNumber"); dataLog.put("accountNumber", "******"); // TODO: check this log log.debug("returning after avs " + dataLog); } PaymentAuthorizationDTO response = makeCall(data, true); paymentInfo.setAuthorization(response); if ("1".equals(response.getCode1())) { paymentInfo.setPaymentResult(new PaymentResultDAS().find(Constants.RESULT_OK)); log.debug("result is ok"); } else { paymentInfo.setPaymentResult(new PaymentResultDAS().find(Constants.RESULT_FAIL)); log.debug("result is fail"); } PaymentAuthorizationBL bl = new PaymentAuthorizationBL(); bl.create(response, paymentInfo.getId()); } catch (MalformedURLException e) { log.error("MalformedURLException exception when calling Atlas", e); paymentInfo.setPaymentResult(new PaymentResultDAS().find(Constants.RESULT_UNAVAILABLE)); retValue = true; } catch (XmlRpcException e) { log.error("XmlRpcException exception when calling Atlas", e); paymentInfo.setPaymentResult(new PaymentResultDAS().find(Constants.RESULT_UNAVAILABLE)); retValue = false; } catch (PluggableTaskException e) { log.error("PluggableTaskException", e); throw e; } catch (Exception e) { log.error("Exception", e); throw new PluggableTaskException(e); } log.debug("returning " + retValue); return retValue; }