public void testWrongPluginParameters() throws JbillingAPIException, IOException {
    long currentTimeMillis = System.currentTimeMillis();
    UserWS user = SureTaxCompositionTaskTest.createUser(currentTimeMillis, "");
    // Create an item with wrong Transaction Type code
    Integer itemId1 =
        CreateObjectUtil.createItem(
            "Long Distance Call intra-state", "1.5", currentTimeMillis + "", "2201", api);
    ItemDTOEx item1 = api.getItem(itemId1, null, null);
    MetaFieldValueWS[] metaFields = new MetaFieldValueWS[1];
    MetaFieldValueWS transTypeMetaField = new MetaFieldValueWS();
    transTypeMetaField.setStringValue("010101");
    transTypeMetaField.setFieldName("Transaction Type Code");
    metaFields[0] = transTypeMetaField;
    item1.setMetaFields(metaFields);
    api.updateItem(item1);
    // purchase order with taxable items
    Calendar cal = Calendar.getInstance();
    // I want to set the active since to 07 June 2012 , so the billing
    // process sees it and invoices it
    // set the calendar to 06/07
    cal.set(2010, 5, 7);
    OrderWS order =
        CreateObjectUtil.createOrderObject(
            user.getUserId(), 1, ServerConstants.ORDER_BILLING_POST_PAID, 1, cal.getTime());

    CreateObjectUtil.addLine(
        order,
        10,
        ServerConstants.ORDER_LINE_TYPE_ITEM,
        itemId1,
        new BigDecimal(1.5),
        "Long Distance Call-intra state");

    order.setDueDateUnitId(PeriodUnitDTO.DAY);
    order.setDueDateValue(0); // order due

    order.setId(api.createOrder(order)); // create order
    order = api.getOrder(order.getId());
    assertNotNull("order created", order.getId());

    Integer[] invoiceIds = null;
    try {
      invoiceIds =
          api.createInvoiceWithDate(
              user.getUserId(),
              new Date(),
              PeriodUnitDTO.DAY,
              45,
              false); // getAllInvoicesForUser(user.getUserId());
    } catch (Exception e) {
      if (e instanceof SessionInternalError && e.getMessage().contains("Invalid Validation Key")) {
        // do nothing
      } else {
        assertTrue("Wrong exception raised", false);
      }
    }
    assertNull("No invoices must be generated", invoiceIds);
  }
    private void verify(Expectation expected) throws AssertionFailedError {
      user = api.getUserWS(user.getUserId());
      order = api.getOrder(order.getId());

      logger.info(S("user: {}", userDetailsAsString(user)));
      logger.info(S("order: {}", orderDetailsAsString(order)));
      boolean isOk;
      isOk =
          assertEqualsBilling(
              S("userId: {}.", user.getId()), expected.nextInvoiceDate, user.getNextInvoiceDate());
      if (!isOk) {
        failed = true;
        return;
      }
      isOk =
          assertEqualsBilling(
              S("orderId: {}.", order.getId()),
              expected.nextBillableDay,
              order.getNextBillableDay());
      if (!isOk) {
        failed = true;
        return;
      }

      if (null != expected.invoiceTotal) {
        verifyInvoice(expected);
      }
    }
Пример #3
0
  @Test
  public void testNewGetPaymentsApiMethods() throws Exception {
    JbillingAPI api = JbillingAPIFactory.getAPI();

    // Create a user with balance $1.00
    UserWS user = com.sapienter.jbilling.server.user.WSTest.createUser(true, null, null);

    List<PaymentWS> payments = new ArrayList<PaymentWS>();

    for (int i = 0; i < 5; i++) {
      payments.add(
          createPaymentWS(
              user.getUserId(), new DateTime().plusMonths(i).toDate(), String.valueOf(i)));
    }

    // get two latest payments except the latest one.
    Integer[] paymentsId = api.getLastPaymentsPage(user.getUserId(), 2, 1);

    assertEquals(2, paymentsId.length);

    assertEquals("3", api.getPayment(paymentsId[0]).getPaymentNotes());
    assertEquals("2", api.getPayment(paymentsId[1]).getPaymentNotes());

    // get the payments between next month and four months from now.
    Integer[] paymentsId2 =
        api.getPaymentsByDate(
            user.getUserId(),
            new DateTime().plusDays(1).toDate(),
            new DateTime().plusMonths(3).plusDays(1).toDate());

    assertEquals(3, paymentsId2.length);

    assertEquals("3", api.getPayment(paymentsId2[0]).getPaymentNotes());
    assertEquals("2", api.getPayment(paymentsId2[1]).getPaymentNotes());
    assertEquals("1", api.getPayment(paymentsId2[2]).getPaymentNotes());

    // Delete orders
    for (PaymentWS payment : payments) {
      api.deletePayment(payment.getId());
    }
    // Delete user
    api.deleteUser(user.getUserId());
  }
Пример #4
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);
    }
  }
Пример #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);
    }
  }