private String composeLine(InvoiceDTO invoice, InvoiceLineDTO invoiceLine, Integer userId) {
    StringBuffer line = new StringBuffer();
    ContactBL contact = new ContactBL();
    contact.set(userId);

    // cono
    line.append("\"" + emptyIfNull(contact.getEntity().getPostalCode()) + "\"");
    line.append(",");
    // custno
    line.append("\"" + userId + "\"");
    line.append(",");
    // naddrcode
    line.append("\"" + "000" + "\"");
    line.append(",");
    // lookupnm
    line.append("\"" + emptyIfNull(contact.getEntity().getOrganizationName()) + "\"");
    line.append(",");
    // totallineamt
    line.append("\"" + invoiceLine.getAmount() + "\"");
    line.append(",");
    // period
    line.append("\"" + new SimpleDateFormat("yyyyMM").format(invoice.getCreateDatetime()) + "\"");
    line.append(",");
    // name
    line.append("\"" + emptyIfNull(contact.getEntity().getOrganizationName()) + "\"");
    line.append(",");
    // deliveryaddr
    line.append("\"" + emptyIfNull(contact.getEntity().getAddress1()) + "\"");
    line.append(",");
    // city
    line.append("\"" + emptyIfNull(contact.getEntity().getCity()) + "\"");
    line.append(",");
    // state
    line.append("\"" + emptyIfNull(contact.getEntity().getStateProvince()) + "\"");
    line.append(",");
    // zip5
    line.append("\"" + emptyIfNull(contact.getEntity().getPostalCode()) + "\"");
    line.append(",");
    // totdue - round to two decimals
    line.append("\"" + new UserBL().getBalance(userId).round(new MathContext(2)) + "\"");
    line.append(",");
    // qty
    line.append("\"" + invoiceLine.getQuantity() + "\"");
    line.append(",");
    // description
    line.append("\"" + invoiceLine.getDescription() + "\"");
    line.append(",");
    // invoiceno
    line.append("\"" + invoice.getNumber() + "\"");
    line.append(",");
    // custstatus
    line.append("\"" + "TRUE" + "\"");

    LOG.debug("Line to export:" + line);
    return line.toString();
  }
  @Override // implements abstract method
  public NVPList buildRequest(PaymentDTOEx payment, SvcType transaction)
      throws PluggableTaskException {
    NVPList request = new NVPList();

    request.add(PARAMETER_MERCHANT_ID, getMerchantId());
    request.add(PARAMETER_STORE_ID, getStoreId());
    request.add(PARAMETER_TERMINAL_ID, getTerminalId());
    request.add(PARAMETER_SELLER_ID, getSellerId());
    request.add(PARAMETER_PASSWORD, getPassword());

    ContactBL contact = new ContactBL();
    contact.set(payment.getUserId());

    request.add(WorldPayParams.General.STREET_ADDRESS, contact.getEntity().getAddress1());
    request.add(WorldPayParams.General.CITY, contact.getEntity().getCity());
    request.add(WorldPayParams.General.STATE, contact.getEntity().getStateProvince());
    request.add(WorldPayParams.General.ZIP, contact.getEntity().getPostalCode());

    request.add(WorldPayParams.General.FIRST_NAME, contact.getEntity().getFirstName());
    request.add(WorldPayParams.General.LAST_NAME, contact.getEntity().getLastName());
    request.add(WorldPayParams.General.COUNTRY, contact.getEntity().getCountryCode());

    request.add(WorldPayParams.General.AMOUNT, formatDollarAmount(payment.getAmount()));
    request.add(WorldPayParams.General.SVC_TYPE, transaction.getCode());

    CreditCardDTO card = payment.getCreditCard();
    request.add(WorldPayParams.CreditCard.CARD_NUMBER, card.getNumber());
    request.add(
        WorldPayParams.CreditCard.EXPIRATION_DATE,
        EXPIRATION_DATE_FORMAT.format(card.getCcExpiry()));

    if (card.getSecurityCode() != null) {
      request.add(
          WorldPayParams.CreditCard.CVV2,
          String.valueOf(payment.getCreditCard().getSecurityCode()));
    }

    return request;
  }
Example #3
0
  /**
   * Will add lines with headers and footers to make an invoice with subaccounts more readable. The
   * lines have to be already sorted.
   *
   * @param lines
   */
  private void addHeadersFooters(List<InvoiceLineDTO> lines, ResourceBundle bundle) {
    Integer nowProcessing = Integer.valueOf(-1);
    BigDecimal total = null;
    int totalLines = lines.size();
    int subaccountNumber = 0;

    LOG.debug("adding headers & footers." + totalLines);

    for (int idx = 0; idx < totalLines; idx++) {
      InvoiceLineDTO line = (InvoiceLineDTO) lines.get(idx);

      if (line.getTypeId() == Constants.INVOICE_LINE_TYPE_SUB_ACCOUNT
          && !line.getSourceUserId().equals(nowProcessing)) {
        // line break
        nowProcessing = line.getSourceUserId();
        subaccountNumber++;
        // put the total first
        if (total != null) { // it could be the first subaccount
          InvoiceLineDTO totalLine = new InvoiceLineDTO();
          totalLine.setDescription(bundle.getString("invoice.line.subAccount.footer"));
          totalLine.setAmount(total);
          lines.add(idx, totalLine);
          idx++;
          totalLines++;
        }
        total = BigDecimal.ZERO;

        // now the header anouncing a new subaccout
        InvoiceLineDTO headerLine = new InvoiceLineDTO();
        try {
          ContactBL contact = new ContactBL();
          contact.set(nowProcessing);
          StringBuffer text = new StringBuffer();
          text.append(subaccountNumber + " - ");
          text.append(bundle.getString("invoice.line.subAccount.header1"));
          text.append(
              " " + bundle.getString("invoice.line.subAccount.header2") + " " + nowProcessing);
          if (contact.getEntity().getFirstName() != null) {
            text.append(" " + contact.getEntity().getFirstName());
          }
          if (contact.getEntity().getLastName() != null) {
            text.append(" " + contact.getEntity().getLastName());
          }
          headerLine.setDescription(text.toString());
          lines.add(idx, headerLine);
          idx++;
          totalLines++;
        } catch (Exception e) {
          LOG.error("Exception", e);
          return;
        }
      }

      // update the total
      if (total != null) {
        // there had been at least one sub-account processed
        if (line.getTypeId() == Constants.INVOICE_LINE_TYPE_SUB_ACCOUNT) {
          total = total.add(line.getAmount());
        } else {
          // this is the last total to display, from now on the
          // lines are not of subaccounts
          InvoiceLineDTO totalLine = new InvoiceLineDTO();
          totalLine.setDescription(bundle.getString("invoice.line.subAccount.footer"));
          totalLine.setAmount(total);
          lines.add(idx, totalLine);
          total = null; // to avoid repeating
        }
      }
    }
    // if there are no lines after the last subaccount, we need
    // a total for it
    if (total != null) { // only if it wasn't added before
      InvoiceLineDTO totalLine = new InvoiceLineDTO();
      totalLine.setDescription(bundle.getString("invoice.line.subAccount.footer"));
      totalLine.setAmount(total);
      lines.add(totalLine);
    }

    LOG.debug("done " + lines.size());
  }