Esempio n. 1
0
  /**
   * Test for BlacklistUserStatusTask. When a user's status moves to suspended or higher, the user
   * and all their information is added to the blacklist.
   */
  @Test(enabled = false)
  public void testBlacklistUserStatus() {
    UserWS user =
        buildUser(
            PRANCING_PONY_ACCOUNT_TYPE, "BlackListFirst", "BlackListSecond", "4916347258194745");
    user.setId(api.createUser(user));

    // expected filter response messages
    String[] messages = new String[3];
    messages[0] = "User id is blacklisted.";
    messages[1] = "Name is blacklisted.";
    messages[2] = "Credit card number is blacklisted.";

    //	    TODO: for now we do not test for these three
    //        messages[3] = "Address is blacklisted.";
    //        messages[4] = "IP address is blacklisted.";
    //        messages[5] = "Phone number is blacklisted.";

    // check that a user isn't blacklisted
    user = api.getUserWS(user.getId());
    // CXF returns null
    if (user.getBlacklistMatches() != null) {
      assertTrue("User shouldn't be blacklisted yet", user.getBlacklistMatches().length == 0);
    }

    // change their status to suspended
    user.setStatusId(STATUS_SUSPENDED);
    user.setPassword(null);
    api.updateUser(user);

    // check all their records are now blacklisted
    user = api.getUserWS(user.getId());
    assertEquals(
        "User records should be blacklisted.",
        Arrays.toString(messages),
        Arrays.toString(user.getBlacklistMatches()));

    // cleanup
    api.deleteUser(user.getId());
  }
Esempio n. 2
0
  /** Removing pre-authorization when the CC number is changed. */
  @Test
  public void testRemoveOnCCChange() {
    UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE);
    user.setId(api.createUser(user));

    ItemTypeWS itemType = buildItemType();
    itemType.setId(api.createItemCategory(itemType));

    ItemDTOEx item = buildItem(itemType.getId(), api.getCallerCompanyId());
    item.setId(api.createItem(item));

    // put a pre-auth record on this user
    OrderWS order = buildOrder(user.getId(), Arrays.asList(item.getId()), new BigDecimal("3.45"));

    PaymentAuthorizationDTOEx auth =
        api.createOrderPreAuthorize(
            order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY));
    Integer orderId = api.getLatestOrder(user.getId()).getId();

    PaymentWS preAuthPayment = api.getPayment(auth.getPaymentId());
    assertThat(preAuthPayment, is(not(nullValue())));
    assertThat(preAuthPayment.getIsPreauth(), is(1));
    assertThat(preAuthPayment.getDeleted(), is(0)); // NOT deleted

    // update the user's credit card, this should remove the old card
    // and delete any associated pre-authorizations
    DateTimeFormatter format = DateTimeFormat.forPattern(Constants.CC_DATE_FORMAT);
    user = api.getUserWS(user.getId());
    com.sapienter.jbilling.server.user.WSTest.updateMetaField(
        user.getPaymentInstruments().iterator().next().getMetaFields(),
        PaymentMethodHelper.CC_MF_EXPIRY_DATE,
        format.print(new DateMidnight().plusYears(4).withDayOfMonth(1).toDate().getTime()));
    api.updateUser(user);
    System.out.println("User instruments are: " + user.getPaymentInstruments());
    // validate that the pre-auth payment is no longer available
    preAuthPayment = api.getPayment(auth.getPaymentId());
    assertThat(preAuthPayment, is(not(nullValue())));
    assertThat(preAuthPayment.getIsPreauth(), is(1));
    assertThat(preAuthPayment.getDeleted(), is(1)); // is now deleted

    // cleanup
    api.deleteOrder(orderId);
    api.deleteItem(item.getId());
    api.deleteItemCategory(itemType.getId());
    api.deleteUser(user.getId());
  }
Esempio n. 3
0
  /** Tests processPayment API call. */
  @Test
  public void testProcessPayment() {
    // setup
    UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE, "4111111111111111");
    user.setId(api.createUser(user));

    ItemTypeWS itemType = buildItemType();
    itemType.setId(api.createItemCategory(itemType));

    ItemDTOEx item = buildItem(itemType.getId(), api.getCallerCompanyId());
    item.setId(api.createItem(item));

    // first, create two unpaid invoices
    OrderWS order = buildOrder(user.getId(), Arrays.asList(item.getId()), new BigDecimal("10.00"));
    Integer invoiceId1 =
        api.createOrderAndInvoice(
            order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY));
    Integer invoiceId2 =
        api.createOrderAndInvoice(
            order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY));

    // create the payment
    PaymentWS payment = new PaymentWS();
    payment.setAmount(new BigDecimal("5.00"));
    payment.setIsRefund(new Integer(0));
    payment.setMethodId(Constants.PAYMENT_METHOD_VISA);
    payment.setPaymentDate(Calendar.getInstance().getTime());
    payment.setCurrencyId(CURRENCY_USD);
    payment.setUserId(user.getId());

    //  try a credit card number that fails
    // note that creating a payment with a NEW credit card will save it and associate
    // it with the user who made the payment.
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.YEAR, 5);

    PaymentInformationWS cc =
        PaymentMethodHelper.createCreditCard(
            CC_PAYMENT_TYPE, "Frodo Baggins", "4111111111111111", cal.getTime());
    cc.setPaymentMethodId(Constants.PAYMENT_METHOD_VISA);
    payment.getPaymentInstruments().add(cc);

    System.out.println("processing payment.");
    PaymentAuthorizationDTOEx authInfo = api.processPayment(payment, null);

    // check payment failed
    assertNotNull("Payment result not null", authInfo);
    assertFalse(
        "Payment Authorization result should be FAILED", authInfo.getResult().booleanValue());

    // check payment has zero balance
    PaymentWS lastPayment = api.getLatestPayment(user.getId());
    assertNotNull("payment can not be null", lastPayment);
    assertNotNull("auth in payment can not be null", lastPayment.getAuthorizationId());
    assertEquals("correct payment amount", new BigDecimal("5"), lastPayment.getAmountAsDecimal());
    assertEquals("correct payment balance", BigDecimal.ZERO, lastPayment.getBalanceAsDecimal());

    // check invoices still have balance
    InvoiceWS invoice1 = api.getInvoiceWS(invoiceId1);
    assertEquals("correct invoice balance", new BigDecimal("10.0"), invoice1.getBalanceAsDecimal());
    InvoiceWS invoice2 = api.getInvoiceWS(invoiceId1);
    assertEquals("correct invoice balance", new BigDecimal("10.0"), invoice2.getBalanceAsDecimal());

    // do it again, but using the credit card on file
    // which is also 4111111111111111
    payment.getPaymentInstruments().clear();
    System.out.println("processing payment.");
    authInfo = api.processPayment(payment, null);
    // check payment has zero balance
    PaymentWS lastPayment2 = api.getLatestPayment(user.getId());
    assertNotNull("payment can not be null", lastPayment2);
    assertNotNull("auth in payment can not be null", lastPayment2.getAuthorizationId());
    assertEquals("correct payment amount", new BigDecimal("5"), lastPayment2.getAmountAsDecimal());
    assertEquals("correct payment balance", BigDecimal.ZERO, lastPayment2.getBalanceAsDecimal());
    assertFalse("Payment is not the same as preiouvs", lastPayment2.getId() == lastPayment.getId());

    // check invoices still have balance
    invoice1 = api.getInvoiceWS(invoiceId1);
    assertEquals("correct invoice balance", new BigDecimal("10"), invoice1.getBalanceAsDecimal());
    invoice2 = api.getInvoiceWS(invoiceId1);
    assertEquals("correct invoice balance", new BigDecimal("10"), invoice2.getBalanceAsDecimal());

    //  do a successful payment of $5
    cc =
        PaymentMethodHelper.createCreditCard(
            CC_PAYMENT_TYPE, "Frodo Baggins", "4111111111111152", cal.getTime());
    cc.setPaymentMethodId(Constants.PAYMENT_METHOD_VISA);
    payment.getPaymentInstruments().add(cc);
    System.out.println("processing payment.");
    authInfo = api.processPayment(payment, null);

    // check payment successful
    assertNotNull("Payment result not null", authInfo);
    assertNotNull("Auth id not null", authInfo.getId());
    assertTrue("Payment Authorization result should be OK", authInfo.getResult().booleanValue());

    // check payment was made
    lastPayment = api.getLatestPayment(user.getId());
    assertNotNull("payment can not be null", lastPayment);
    assertNotNull("auth in payment can not be null", lastPayment.getAuthorizationId());
    assertEquals("payment ids match", lastPayment.getId(), authInfo.getPaymentId().intValue());
    assertEquals("correct payment amount", new BigDecimal("5"), lastPayment.getAmountAsDecimal());
    assertEquals("correct payment balance", BigDecimal.ZERO, lastPayment.getBalanceAsDecimal());

    // check invoice 1 was partially paid (balance 5)
    invoice1 = api.getInvoiceWS(invoiceId1);
    assertEquals("correct invoice balance", new BigDecimal("5.0"), invoice1.getBalanceAsDecimal());

    // check invoice 2 wan't paid at all
    invoice2 = api.getInvoiceWS(invoiceId2);
    assertEquals("correct invoice balance", new BigDecimal("10.0"), invoice2.getBalanceAsDecimal());

    //  another payment for $10, this time with the user's credit card

    // update the credit card to the one that is good
    user = api.getUserWS(user.getId());
    com.sapienter.jbilling.server.user.WSTest.updateMetaField(
        user.getPaymentInstruments().iterator().next().getMetaFields(),
        PaymentMethodHelper.CC_MF_NUMBER,
        "4111111111111152");
    api.updateUser(user);

    // process a payment without an attached credit card
    // should try and use the user's saved credit card
    payment.getPaymentInstruments().clear();
    payment.setAmount(new BigDecimal("10.00"));
    System.out.println("processing payment.");
    authInfo = api.processPayment(payment, null);

    // check payment successful
    assertNotNull("Payment result not null", authInfo);
    assertTrue("Payment Authorization result should be OK", authInfo.getResult().booleanValue());

    // check payment was made
    lastPayment = api.getLatestPayment(user.getId());
    assertNotNull("payment can not be null", lastPayment);
    assertNotNull("auth in payment can not be null", lastPayment.getAuthorizationId());
    assertEquals("correct payment amount", new BigDecimal("10"), lastPayment.getAmountAsDecimal());
    assertEquals("correct payment balance", BigDecimal.ZERO, lastPayment.getBalanceAsDecimal());

    // check invoice 1 is fully paid (balance 0)
    invoice1 = api.getInvoiceWS(invoiceId1);
    assertEquals("correct invoice balance", BigDecimal.ZERO, invoice1.getBalanceAsDecimal());

    // check invoice 2 was partially paid (balance 5)
    invoice2 = api.getInvoiceWS(invoiceId2);
    assertEquals("correct invoice balance", new BigDecimal("5"), invoice2.getBalanceAsDecimal());

    // another payment for $10

    payment.getPaymentInstruments().add(cc);
    payment.setAmount(new BigDecimal("10.00"));
    System.out.println("processing payment.");
    authInfo = api.processPayment(payment, null);

    // check payment successful
    assertNotNull("Payment result not null", authInfo);
    assertTrue("Payment Authorization result should be OK", authInfo.getResult().booleanValue());

    // check payment was made
    lastPayment = api.getLatestPayment(user.getId());
    assertNotNull("payment can not be null", lastPayment);
    assertNotNull("auth in payment can not be null", lastPayment.getAuthorizationId());
    assertEquals("correct  payment amount", new BigDecimal("10"), lastPayment.getAmountAsDecimal());
    assertEquals(
        "correct  payment balance", new BigDecimal("5"), lastPayment.getBalanceAsDecimal());

    // check invoice 1 balance is unchanged
    invoice1 = api.getInvoiceWS(invoiceId1);
    assertEquals("correct invoice balance", BigDecimal.ZERO, invoice1.getBalanceAsDecimal());

    // check invoice 2 is fully paid (balance 0)
    invoice2 = api.getInvoiceWS(invoiceId2);
    assertEquals("correct invoice balance", BigDecimal.ZERO, invoice2.getBalanceAsDecimal());

    // cleanup
    System.out.println("Deleting invoices and orders.");
    api.deleteInvoice(invoice1.getId());
    api.deleteInvoice(invoice2.getId());
    api.deleteOrder(invoice1.getOrders()[0]);
    api.deleteOrder(invoice2.getOrders()[0]);
    api.deleteItem(item.getId());
    api.deleteItemCategory(itemType.getId());
    api.deleteUser(user.getId());
  }
  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;
  }
Esempio n. 5
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);
    }
  }
Esempio n. 6
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);
    }
  }