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;
  }