Beispiel #1
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());
  }