Ejemplo n.º 1
0
  /**
   * Add a payment schedule to the payment request.
   *
   * @param document
   * @param subscription
   * @param subscr_el
   */
  private void addPaymentScheduleToSubscription(
      BasicXmlDocument document, Subscription subscription, Element subscr_el) {
    PaymentSchedule schedule = subscription.getSchedule();
    if (schedule == null) return;

    Element payment_el =
        document.createElement(AuthNetField.ELEMENT_PAYMENT_SCHEDULE.getFieldName());

    // Add the interval
    //
    if (schedule.getIntervaLength() > 0) {
      Element interval_el = document.createElement(AuthNetField.ELEMENT_INTERVAL.getFieldName());
      Element length_el = document.createElement(AuthNetField.ELEMENT_LENGTH.getFieldName());
      Element unit_el = document.createElement(AuthNetField.ELEMENT_UNIT.getFieldName());
      length_el.appendChild(
          document.getDocument().createTextNode(Integer.toString(schedule.getIntervaLength())));
      interval_el.appendChild(length_el);
      interval_el.appendChild(unit_el);
      unit_el.appendChild(
          document.getDocument().createTextNode(schedule.getSubscriptionUnit().value()));

      payment_el.appendChild(interval_el);
    }

    Element start_date_el = document.createElement(AuthNetField.ELEMENT_START_DATE.getFieldName());
    start_date_el.appendChild(
        document
            .getDocument()
            .createTextNode(
                net.authorize.util.DateUtil.getFormattedDate(
                    schedule.getStartDate(), PaymentSchedule.SCHEDULE_DATE_FORMAT)));
    payment_el.appendChild(start_date_el);

    Element total_el =
        document.createElement(AuthNetField.ELEMENT_TOTAL_OCCURRENCES.getFieldName());
    total_el.appendChild(
        document.getDocument().createTextNode(Integer.toString(schedule.getTotalOccurrences())));
    payment_el.appendChild(total_el);

    Element trial_el =
        document.createElement(AuthNetField.ELEMENT_TRIAL_OCCURRENCES.getFieldName());
    trial_el.appendChild(
        document.getDocument().createTextNode(Integer.toString(schedule.getTrialOccurrences())));
    payment_el.appendChild(trial_el);

    subscr_el.appendChild(payment_el);
  }
Ejemplo n.º 2
0
 public void setBirthDate(String date) {
   this.birth_date =
       net.authorize.util.DateUtil.getDateFromFormattedDate(date, LICENSE_DATE_FORMAT);
 }
Ejemplo n.º 3
0
  /**
   * Add payment information to the subscription request.
   *
   * @param document
   * @param subscription
   * @param subscr_el
   */
  private void addPaymentToSubscription(
      BasicXmlDocument document, Subscription subscription, Element subscr_el) {
    Payment payment = subscription.getPayment();
    if (payment == null) return;

    Element payment_el = document.createElement(AuthNetField.ELEMENT_PAYMENT.getFieldName());
    CreditCard credit_card = payment.getCreditCard();
    BankAccount bank_account = payment.getBankAccount();

    if (credit_card != null) {
      Element cc_el = document.createElement(AuthNetField.ELEMENT_CREDIT_CARD.getFieldName());

      if (StringUtils.isNotEmpty(credit_card.getCreditCardNumber())) {
        Element cc_num_el =
            document.createElement(AuthNetField.ELEMENT_CREDIT_CARD_NUMBER.getFieldName());
        cc_num_el.appendChild(
            document.getDocument().createTextNode(credit_card.getCreditCardNumber()));
        cc_el.appendChild(cc_num_el);
      }

      if (credit_card.getExpirationDate() != null) {
        Element cc_exp_el =
            document.createElement(AuthNetField.ELEMENT_CREDIT_CARD_EXPIRY.getFieldName());
        cc_exp_el.appendChild(
            document
                .getDocument()
                .createTextNode(
                    net.authorize.util.DateUtil.getFormattedDate(
                        credit_card.getExpirationDate(), CreditCard.ARB_EXPIRY_DATE_FORMAT)));
        cc_el.appendChild(cc_exp_el);
      }

      payment_el.appendChild(cc_el);
    } else if (bank_account != null) {
      Element bankacct_el =
          document.createElement(AuthNetField.ELEMENT_BANK_ACCOUNT.getFieldName());

      if (bank_account.getBankAccountType() != null) {
        Element account_type_el =
            document.createElement(AuthNetField.ELEMENT_ACCOUNT_TYPE.getFieldName());
        account_type_el.appendChild(
            document
                .getDocument()
                .createTextNode(bank_account.getBankAccountType().getValue().toLowerCase()));
        bankacct_el.appendChild(account_type_el);
      }

      if (StringUtils.isNotEmpty(bank_account.getRoutingNumber())) {
        Element routing_number_el =
            document.createElement(AuthNetField.ELEMENT_ROUTING_NUMBER.getFieldName());
        routing_number_el.appendChild(
            document.getDocument().createTextNode(bank_account.getRoutingNumber()));
        bankacct_el.appendChild(routing_number_el);
      }

      if (StringUtils.isNotEmpty(bank_account.getBankAccountNumber())) {
        Element acct_number_el =
            document.createElement(AuthNetField.ELEMENT_ACCOUNT_NUMBER.getFieldName());
        acct_number_el.appendChild(
            document.getDocument().createTextNode(bank_account.getBankAccountNumber()));
        bankacct_el.appendChild(acct_number_el);
      }

      if (StringUtils.isNotEmpty(bank_account.getBankAccountName())) {
        Element name_on_acct_el =
            document.createElement(AuthNetField.ELEMENT_NAME_ON_ACCOUNT.getFieldName());
        name_on_acct_el.appendChild(
            document.getDocument().createTextNode(bank_account.getBankAccountName()));
        bankacct_el.appendChild(name_on_acct_el);
      }

      if (bank_account.getECheckType() != null) {
        Element echeck_type_el =
            document.createElement(AuthNetField.ELEMENT_ECHECK_TYPE.getFieldName());
        echeck_type_el.appendChild(
            document.getDocument().createTextNode(bank_account.getECheckType().getValue()));
        bankacct_el.appendChild(echeck_type_el);
      }

      if (StringUtils.isNotEmpty(bank_account.getBankName())) {
        Element bank_name_el =
            document.createElement(AuthNetField.ELEMENT_BANK_NAME.getFieldName());
        bank_name_el.appendChild(document.getDocument().createTextNode(bank_account.getBankName()));
        bankacct_el.appendChild(bank_name_el);
      }

      payment_el.appendChild(bankacct_el);
    }

    subscr_el.appendChild(payment_el);
  }