Beispiel #1
0
  public PaymentWS createPaymentWS(Integer userId, Date date, String note) throws Exception {
    JbillingAPI api = JbillingAPIFactory.getAPI();

    PaymentWS payment = new PaymentWS();
    payment.setAmount(new BigDecimal("15.00"));
    payment.setIsRefund(new Integer(0));
    payment.setMethodId(Constants.PAYMENT_METHOD_CHEQUE);
    payment.setPaymentDate(date);
    payment.setCreateDatetime(date);
    payment.setResultId(Constants.RESULT_ENTERED);
    payment.setCurrencyId(new Integer(1));
    payment.setUserId(userId);
    payment.setPaymentNotes(note);
    payment.setPaymentPeriod(new Integer(1));

    PaymentInformationWS cheque =
        com.sapienter.jbilling.server.user.WSTest.createCheque("ws bank", "2232-2323-2323", date);

    payment.getPaymentInstruments().add(cheque);
    System.out.println("Applying payment");
    Integer ret = api.applyPayment(payment, new Integer(35));
    System.out.println("Created payemnt " + ret);
    assertNotNull("Didn't get the payment id", ret);

    payment.setId(ret);
    return payment;
  }
Beispiel #2
0
  /** Testing the saveLegacyPayment API call */
  @Test
  public void testSaveLegacyPayment() {
    // setup
    UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE);
    user.setId(api.createUser(user));

    PaymentWS payment = new PaymentWS();
    payment.setAmount(new BigDecimal("15.00"));
    payment.setIsRefund(new Integer(0));
    payment.setMethodId(Constants.PAYMENT_METHOD_CREDIT);
    payment.setPaymentDate(Calendar.getInstance().getTime());
    payment.setResultId(Constants.RESULT_ENTERED);
    payment.setCurrencyId(CURRENCY_USD);
    payment.setUserId(user.getId());
    payment.setPaymentNotes("Notes");
    payment.setPaymentPeriod(PAYMENT_PERIOD);

    Integer paymentId = api.saveLegacyPayment(payment);
    assertNotNull("Payment should be saved", paymentId);

    PaymentWS retPayment = api.getPayment(paymentId);
    assertNotNull(retPayment);
    assertEquals(retPayment.getAmountAsDecimal(), payment.getAmountAsDecimal());
    assertEquals(retPayment.getIsRefund(), payment.getIsRefund());
    assertEquals(retPayment.getMethodId(), payment.getMethodId());
    assertEquals(retPayment.getResultId(), payment.getResultId());
    assertEquals(retPayment.getCurrencyId(), payment.getCurrencyId());
    assertEquals(retPayment.getUserId(), payment.getUserId());
    assertEquals(
        retPayment.getPaymentNotes(),
        payment.getPaymentNotes() + " This payment is migrated from legacy system.");
    assertEquals(retPayment.getPaymentPeriod(), payment.getPaymentPeriod());

    // cleanup
    api.deletePayment(retPayment.getId());
    api.deleteUser(user.getId());
  }
Beispiel #3
0
  /** Tests failed and successful payment for ACH */
  @Test
  public void testAchFakePayments() {
    UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE);

    // remove payment instruments and add only ACH payment instrument
    user.getPaymentInstruments().clear();
    user.getPaymentInstruments()
        .add(
            PaymentMethodHelper.createACH(
                ACH_PAYMENT_TYPE,
                "Frodo Baggins",
                "Shire Financial Bank",
                "123456789",
                "123456789",
                PRANCING_PONY_ACCOUNT_TYPE));

    System.out.println("Creating user with ACH record and no CC...");
    user.setId(api.createUser(user));

    // get ach
    PaymentInformationWS ach = user.getPaymentInstruments().get(0);

    System.out.println("Testing ACH payment with even amount (should pass)");
    PaymentWS payment = new PaymentWS();
    payment.setAmount(new BigDecimal("15.00"));
    payment.setIsRefund(new Integer(0));
    payment.setMethodId(Constants.PAYMENT_METHOD_ACH);
    payment.setPaymentDate(Calendar.getInstance().getTime());
    payment.setResultId(Constants.RESULT_ENTERED);
    payment.setCurrencyId(CURRENCY_USD);
    payment.setUserId(user.getId());
    payment.setPaymentNotes("Notes");
    payment.setPaymentPeriod(PAYMENT_PERIOD);
    payment.getPaymentInstruments().add(ach);

    PaymentAuthorizationDTOEx resultOne = api.processPayment(payment, null);
    assertEquals(
        "ACH payment with even amount should pass",
        Constants.RESULT_OK,
        api.getPayment(resultOne.getPaymentId()).getResultId());

    System.out.println("Testing ACH payment with odd amount (should fail)");
    payment = new PaymentWS();
    payment.setAmount(new BigDecimal("15.01"));
    payment.setIsRefund(new Integer(0));
    payment.setMethodId(Constants.PAYMENT_METHOD_ACH);
    payment.setPaymentDate(Calendar.getInstance().getTime());
    payment.setResultId(Constants.RESULT_ENTERED);
    payment.setCurrencyId(CURRENCY_USD);
    payment.setUserId(user.getId());
    payment.setPaymentNotes("Notes");
    payment.setPaymentPeriod(PAYMENT_PERIOD);
    payment.getPaymentInstruments().add(ach);

    PaymentAuthorizationDTOEx resultTwo = api.processPayment(payment, null);
    assertEquals(
        "ACH payment with odd amount should fail",
        Constants.RESULT_FAIL,
        api.getPayment(resultTwo.getPaymentId()).getResultId());

    // cleanup
    api.deletePayment(resultTwo.getPaymentId());
    api.deletePayment(resultOne.getPaymentId());
    api.deleteUser(user.getId());
  }
Beispiel #4
0
  /** Tests payment apply and retrieve. */
  @Test
  public void testApplyGet() {
    // setup
    UserWS mordorUser = buildUser(MORDOR_ACCOUNT_TYPE);
    mordorUser.setId(mordorApi.createUser(mordorUser));

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

    InvoiceWS invoice = buildInvoice(user.getId(), item.getId());
    invoice.setId(api.saveLegacyInvoice(invoice));

    // testing
    PaymentWS payment = new PaymentWS();
    payment.setAmount(new BigDecimal("15.00"));
    payment.setIsRefund(new Integer(0));
    payment.setMethodId(Constants.PAYMENT_METHOD_CHEQUE);
    payment.setPaymentDate(Calendar.getInstance().getTime());
    payment.setResultId(Constants.RESULT_ENTERED);
    payment.setCurrencyId(CURRENCY_USD);
    payment.setUserId(user.getId());
    payment.setPaymentNotes("Notes");
    payment.setPaymentPeriod(PAYMENT_PERIOD);

    PaymentInformationWS cheque =
        PaymentMethodHelper.createCheque(
            CHEQUE_PAYMENT_TYPE, "ws bank", "2232-2323-2323", Calendar.getInstance().getTime());
    payment.getPaymentInstruments().add(cheque);

    System.out.println("Applying payment");
    Integer paymentId = api.applyPayment(payment, invoice.getId());
    System.out.println("Created payemnt " + paymentId);
    assertNotNull("Didn't get the payment id", paymentId);

    //  get

    // verify the created payment
    System.out.println("Getting created payment");
    PaymentWS retPayment = api.getPayment(paymentId);
    assertNotNull("didn't get payment ", retPayment);

    assertEquals("created payment result", retPayment.getResultId(), payment.getResultId());
    System.out.println("Instruments are: " + retPayment.getPaymentInstruments());

    assertEquals(
        "created payment cheque ",
        getMetaField(
                retPayment.getPaymentInstruments().iterator().next().getMetaFields(),
                PaymentMethodHelper.CHEQUE_MF_NUMBER)
            .getStringValue(),
        getMetaField(
                payment.getPaymentInstruments().iterator().next().getMetaFields(),
                PaymentMethodHelper.CHEQUE_MF_NUMBER)
            .getStringValue());

    assertEquals("created payment user ", retPayment.getUserId(), payment.getUserId());
    assertEquals("notes", retPayment.getPaymentNotes(), payment.getPaymentNotes());
    assertEquals("period", retPayment.getPaymentPeriod(), payment.getPaymentPeriod());

    System.out.println("Validated created payment and paid invoice");
    assertNotNull("payment not related to invoice", retPayment.getInvoiceIds());
    assertTrue("payment not related to invoice", retPayment.getInvoiceIds().length == 1);
    assertEquals("payment not related to invoice", retPayment.getInvoiceIds()[0], invoice.getId());

    InvoiceWS retInvoice = api.getInvoiceWS(retPayment.getInvoiceIds()[0]);
    assertNotNull("New invoice not present", retInvoice);
    assertEquals(
        "Balance of invoice should be total of order",
        BigDecimal.ZERO,
        retInvoice.getBalanceAsDecimal());
    assertEquals(
        "Total of invoice should be total of order",
        new BigDecimal("15"),
        retInvoice.getTotalAsDecimal());
    assertEquals("New invoice not paid", retInvoice.getToProcess(), new Integer(0));
    assertNotNull("invoice not related to payment", retInvoice.getPayments());
    assertTrue("invoice not related to payment", retInvoice.getPayments().length == 1);
    assertEquals(
        "invoice not related to payment",
        retInvoice.getPayments()[0].intValue(),
        retPayment.getId());

    //  get latest

    // verify the created payment
    System.out.println("Getting latest");
    retPayment = api.getLatestPayment(user.getId());
    assertNotNull("didn't get payment ", retPayment);
    assertEquals("latest id", paymentId.intValue(), retPayment.getId());
    assertEquals("created payment result", retPayment.getResultId(), payment.getResultId());

    assertEquals(
        "created payment cheque ",
        getMetaField(
                retPayment.getPaymentInstruments().iterator().next().getMetaFields(),
                PaymentMethodHelper.CHEQUE_MF_NUMBER)
            .getStringValue(),
        getMetaField(
                payment.getPaymentInstruments().iterator().next().getMetaFields(),
                PaymentMethodHelper.CHEQUE_MF_NUMBER)
            .getStringValue());

    assertEquals("created payment user ", retPayment.getUserId(), payment.getUserId());

    try {
      System.out.println("Getting latest - invalid");
      api.getLatestPayment(mordorUser.getId());
      fail("User belongs to entity Mordor");
    } catch (Exception e) {
    }

    //  get last

    System.out.println("Getting last");
    Integer retPayments[] = api.getLastPayments(user.getId(), Integer.valueOf(2));
    assertNotNull("didn't get payment ", retPayments);
    // fetch the payment

    retPayment = api.getPayment(retPayments[0]);

    assertEquals("created payment result", retPayment.getResultId(), payment.getResultId());

    assertEquals(
        "created payment cheque ",
        getMetaField(
                retPayment.getPaymentInstruments().iterator().next().getMetaFields(),
                PaymentMethodHelper.CHEQUE_MF_NUMBER)
            .getStringValue(),
        getMetaField(
                payment.getPaymentInstruments().iterator().next().getMetaFields(),
                PaymentMethodHelper.CHEQUE_MF_NUMBER)
            .getStringValue());

    assertEquals("created payment user ", retPayment.getUserId(), payment.getUserId());
    assertTrue("No more than two records", retPayments.length <= 2);

    try {
      System.out.println("Getting last - invalid");
      api.getLastPayments(mordorUser.getId(), Integer.valueOf(2));
      fail("User belongs to entity Mordor");
    } catch (Exception e) {
    }

    // cleanup
    api.deletePayment(paymentId);
    api.deleteInvoice(invoice.getId());
    api.deleteUser(user.getId());
    mordorApi.deleteUser(mordorUser.getId());
  }