Пример #1
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;
  }
Пример #3
0
  @Test
  public void test001CreateCustomerWithAitMetaFields_DefaultDate() throws Exception {
    System.out.println("#test001CreateCustomerWithAitMetaFields_DefaultDate");
    JbillingAPI api = JbillingAPIFactory.getAPI();
    Integer userId = null;
    try {
      UserWS newUser = createUser();

      System.out.println("Setting Ait fields values for date:" + CommonConstants.EPOCH_DATE);
      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

      String email = newUser.getUserName() + "@shire.com";
      String firstName = "Frodo";
      String lastName = "Baggins";

      MetaFieldValueWS metaField3 = new MetaFieldValueWS();
      metaField3.setFieldName("contact.email");
      metaField3.setValue(email);
      metaField3.setGroupId(1);

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

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

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

      System.out.println("Setting default date as the only date of timeline");
      ArrayList<Date> timelineDates = new ArrayList<Date>(0);
      timelineDates.add(CommonConstants.EPOCH_DATE);
      newUser.getTimelineDatesMap().put(new Integer(1), timelineDates);

      System.out.println("Creating user ...");
      userId = api.createUser(newUser);
      newUser.setUserId(userId);

      System.out.println("Getting created user");
      UserWS ret = api.getUserWS(newUser.getUserId());

      ArrayList<MetaFieldValueWS> aitMetaFields =
          ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).get(CommonConstants.EPOCH_DATE);

      // check that timeline contains default date
      if (!ret.getAccountInfoTypeFieldsMap()
          .get(new Integer(1))
          .containsKey(CommonConstants.EPOCH_DATE)) {
        fail("Default date: " + CommonConstants.EPOCH_DATE + " should be present in timeline");
      }

      // Total no of ait meta fields returned should be 18, no of meta fields for ait = 1, only 3
      // has values
      assertEquals(3, aitMetaFields.size());

      // ait meta fields should be 11. Customer Specific: 8 (2 has value). Ait meta field for
      // effective date: 18 (3 has values)
      assertEquals(5, ret.getMetaFields().length);

      // assert that email, first name and last name has same values
      for (MetaFieldValueWS ws : aitMetaFields) {
        if (ws.getFieldName().equals("contact.email")) {
          assertEquals("Email should be same", email, ws.getValue());
        } else if (ws.getFieldName().equals("contact.first.name")) {
          assertEquals("First name should be same", firstName, ws.getValue());
        } else if (ws.getFieldName().equals("contact.last.name")) {
          assertEquals("Last name should be same", lastName, ws.getValue());
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception caught:" + e);
    } finally {
      System.out.println("Deleting created user");
      if (userId != null) api.deleteUser(userId);
    }
  }
  /** 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;
  }
Пример #5
0
  @Test
  public void test003CreateCustomerWithAitMetaFields_UpdateTodaysFields() throws Exception {
    System.out.println("#test003CreateCustomerWithAitMetaFields_UpdateTodaysFields");
    JbillingAPI api = JbillingAPIFactory.getAPI();
    Integer userId = null;
    try {

      UserWS newUser = createUser();
      System.out.println("Setting Ait fields values for date:" + CommonConstants.EPOCH_DATE);
      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("*****@*****.**");
      metaField3.setGroupId(1);

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

      Date today = new DateTime().toDateMidnight().toDate();
      System.out.println("Setting default date and todays date on timeline");
      ArrayList<Date> timelineDates = new ArrayList<Date>(0);
      timelineDates.add(CommonConstants.EPOCH_DATE);
      timelineDates.add(today);
      newUser.getTimelineDatesMap().put(new Integer(1), timelineDates);

      System.out.println("Creating user ...");
      userId = api.createUser(newUser);
      newUser.setUserId(userId);

      System.out.println("Getting created user");
      UserWS ret = api.getUserWS(newUser.getUserId());

      // Update todays ait meta field value for the created users
      metaField3 = new MetaFieldValueWS();
      metaField3.setFieldName("contact.email");
      metaField3.setValue("*****@*****.**");
      metaField3.setGroupId(1);

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

      ret.getEffectiveDateMap().put(1, today);
      api.updateUser(ret);

      // get updated user
      ret = api.getUserWS(newUser.getUserId());

      // check that timeline contains default date and today's date
      if (!ret.getAccountInfoTypeFieldsMap()
          .get(new Integer(1))
          .containsKey(CommonConstants.EPOCH_DATE)) {
        fail("Default date: " + CommonConstants.EPOCH_DATE + " should be present in timeline");
      }

      if (!ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).containsKey(today)) {
        fail("Default date: " + today + " should be present in timeline");
      }

      // verify meta fields for default date
      ArrayList<MetaFieldValueWS> aitMetaFields =
          ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).get(CommonConstants.EPOCH_DATE);

      // Total no of ait meta fields returned should be 1, no of meta fields for ait 1 is 18, but
      // only
      // one has a value
      assertEquals(1, aitMetaFields.size());

      // assert that email, first name and last name has same values
      for (MetaFieldValueWS ws : aitMetaFields) {
        if (ws.getFieldName().equals("contact.email")) {
          assertEquals("Email should be same", "*****@*****.**", ws.getValue());
        }
      }

      // verify meta fields for todays date
      aitMetaFields = ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).get(today);

      // Total no of ait meta fields returned should be 1, no of meta fields for ait 1 is 18, but
      // only
      // one has a value
      assertEquals(1, aitMetaFields.size());

      // assert that email, first name and last name has same values
      for (MetaFieldValueWS ws : aitMetaFields) {
        if (ws.getFieldName().equals("contact.email")) {
          assertEquals("Email should be same", "*****@*****.**", ws.getValue());
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception caught:" + e);
    } finally {
      // Change
      System.out.println("Deleting created user");
      if (userId != null) api.deleteUser(userId);
    }
  }