Example #1
0
  public static UserWS createUser() throws JbillingAPIException, IOException {
    JbillingAPI api = JbillingAPIFactory.getAPI();

    // Create - This passes the password validation routine.

    UserWS newUser = new UserWS();
    newUser.setUserId(0); // it is validated
    newUser.setUserName("testUserName-" + Calendar.getInstance().getTimeInMillis());
    newUser.setPassword("P@ssword1");
    newUser.setLanguageId(Integer.valueOf(1));
    newUser.setMainRoleId(Integer.valueOf(5));
    newUser.setAccountTypeId(Integer.valueOf(1));
    newUser.setParentId(null); // this parent exists
    newUser.setStatusId(UserDTOEx.STATUS_ACTIVE);
    newUser.setCurrencyId(new Integer(1));
    newUser.setInvoiceChild(new Boolean(false));

    return newUser;
  }
Example #2
0
  private UserWS buildUser(
      Integer accountTypeId, String firstName, String lastName, String ccNumber) {
    UserWS newUser = new UserWS();
    newUser.setUserName("payment-test-" + Calendar.getInstance().getTimeInMillis());
    newUser.setPassword("Admin123@");
    newUser.setLanguageId(LANGUAGE_ID);
    newUser.setMainRoleId(new Integer(5));
    newUser.setAccountTypeId(accountTypeId);
    newUser.setParentId(null);
    newUser.setStatusId(UserDTOEx.STATUS_ACTIVE);
    newUser.setCurrencyId(CURRENCY_USD);

    MetaFieldValueWS metaField1 = new MetaFieldValueWS();
    metaField1.setFieldName("contact.email");
    metaField1.setValue(newUser.getUserName() + "@shire.com");
    metaField1.setGroupId(accountTypeId);

    MetaFieldValueWS metaField2 = new MetaFieldValueWS();
    metaField2.setFieldName("contact.first.name");
    metaField2.setValue(firstName);
    metaField2.setGroupId(accountTypeId);

    MetaFieldValueWS metaField3 = new MetaFieldValueWS();
    metaField3.setFieldName("contact.last.name");
    metaField3.setValue(lastName);
    metaField3.setGroupId(accountTypeId);

    newUser.setMetaFields(new MetaFieldValueWS[] {metaField1, metaField2, metaField3});

    // add a credit card
    Calendar expiry = Calendar.getInstance();
    expiry.set(Calendar.YEAR, expiry.get(Calendar.YEAR) + 1);

    // add credit card
    newUser
        .getPaymentInstruments()
        .add(
            PaymentMethodHelper.createCreditCard(
                CC_PAYMENT_TYPE, "Frodo Baggins", ccNumber, expiry.getTime()));

    return newUser;
  }
  public static UserWS createUser(
      boolean goodCC, Integer parentId, Integer currencyId, boolean doCreate)
      throws JbillingAPIException, IOException {
    JbillingAPI api = JbillingAPIFactory.getAPI();

    /*
     * Create - This passes the password validation routine.
     */
    UserWS newUser = new UserWS();
    newUser.setUserId(0); // it is validated
    newUser.setUserName("testUserName-" + Calendar.getInstance().getTimeInMillis());
    newUser.setPassword("As$fasdf1");
    newUser.setLanguageId(Integer.valueOf(1));
    newUser.setMainRoleId(Integer.valueOf(5));
    newUser.setAccountTypeId(Integer.valueOf(1));
    newUser.setParentId(parentId); // this parent exists
    newUser.setStatusId(UserDTOEx.STATUS_ACTIVE);
    newUser.setCurrencyId(currencyId);
    newUser.setCreditLimit("1");
    newUser.setInvoiceChild(new Boolean(false));

    MetaFieldValueWS metaField1 = new MetaFieldValueWS();
    metaField1.setFieldName("partner.prompt.fee");
    metaField1.setValue("serial-from-ws");

    MetaFieldValueWS metaField2 = new MetaFieldValueWS();
    metaField2.setFieldName("ccf.payment_processor");
    metaField2.setValue("FAKE_2"); // the plug-in parameter of the processor

    MetaFieldValueWS metaField3 = new MetaFieldValueWS();
    metaField3.setFieldName("contact.email");
    metaField3.setValue(newUser.getUserName() + "@shire.com");
    metaField3.setGroupId(1);

    MetaFieldValueWS metaField4 = new MetaFieldValueWS();
    metaField4.setFieldName("contact.first.name");
    metaField4.setValue("FrodoRecharge");
    metaField4.setGroupId(1);

    MetaFieldValueWS metaField5 = new MetaFieldValueWS();
    metaField5.setFieldName("contact.last.name");
    metaField5.setValue("BagginsRecharge");
    metaField5.setGroupId(1);

    newUser.setMetaFields(
        new MetaFieldValueWS[] {metaField1, metaField2, metaField3, metaField4, metaField5});

    // valid credit card must have a future expiry date to be valid for payment processing
    Calendar expiry = Calendar.getInstance();
    expiry.set(Calendar.YEAR, expiry.get(Calendar.YEAR) + 1);

    // add a credit card
    PaymentInformationWS cc =
        createCreditCard(
            "Frodo Rech Baggins",
            goodCC ? "4929974024420784" : "4111111111111111",
            expiry.getTime());

    newUser.getPaymentInstruments().add(cc);

    if (doCreate) {
      System.out.println("Creating user ...");
      Integer userId = api.createUser(newUser);
      newUser = api.getUserWS(userId);
    }

    return newUser;
  }
  /** To create a customer */
  public static UserWS createCustomer(
      Integer currencyId,
      String userName,
      String password,
      Integer languageId,
      Integer mainRoleId,
      boolean isParent,
      Integer statusID,
      PaymentInformationWS instrument,
      ContactWS contact) {

    UserWS newUser = new UserWS();
    newUser.setUserName(userName);
    newUser.setLanguageId(languageId);
    newUser.setCurrencyId(currencyId);

    // defautl account type id
    newUser.setAccountTypeId(Integer.valueOf(1));

    MetaFieldValueWS metaField1 = new MetaFieldValueWS();
    metaField1.setFieldName("partner.prompt.fee");
    metaField1.setValue("serial-from-ws");

    MetaFieldValueWS metaField2 = new MetaFieldValueWS();
    metaField2.setFieldName("ccf.payment_processor");
    metaField2.setValue("FAKE_2"); // the plug-in parameter of the processor

    // contact info
    MetaFieldValueWS metaField3 = new MetaFieldValueWS();
    metaField3.setFieldName("contact.email");
    metaField3.setValue(newUser.getUserName() + "@shire.com");
    metaField3.setGroupId(1);

    MetaFieldValueWS metaField4 = new MetaFieldValueWS();
    metaField4.setFieldName("contact.first.name");
    metaField4.setValue("Frodo");
    metaField4.setGroupId(1);

    MetaFieldValueWS metaField5 = new MetaFieldValueWS();
    metaField5.setFieldName("contact.last.name");
    metaField5.setValue("Baggins");
    metaField5.setGroupId(1);

    newUser.setMetaFields(
        new MetaFieldValueWS[] {metaField1, metaField2, metaField3, metaField4, metaField5});

    // Provide Defaults
    newUser.setPassword(password);
    newUser.setMainRoleId(mainRoleId); // customer
    newUser.setIsParent(isParent); // not parent
    newUser.setStatusId(statusID); // active user

    // add a contact
    if (contact != null) {
      newUser.setContact(contact);
    }

    // instrument can be credit card or ach
    if (instrument != null) {
      newUser.getPaymentInstruments().add(instrument);
    }

    return newUser;
  }