Exemple #1
0
  /**
   * Tries to create payment against review invoice. Here, instead of using the billing process to
   * generate a review invoice we are creating a review invoice with the help of saveLegacyInvoice
   * call.
   */
  @Test
  public void testPayReviewInvoice() {
    // creating new user
    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.setIsReview(Integer.valueOf(1));
    invoice.setId(api.saveLegacyInvoice(invoice));

    // check if invoice is a review invoice
    System.out.println("Invoice is review : " + invoice.getIsReview());
    assertEquals("Invoice is a review invoice", Integer.valueOf(1), invoice.getIsReview());

    try {
      // pay for a review invoice
      api.payInvoice(invoice.getId());
      fail("We should not be able to issue a payment against review invoice");
    } catch (SessionInternalError e) {
      System.out.println(e.getMessage());
    }

    // clean up
    api.deleteInvoice(invoice.getId());
    api.deleteItem(item.getId());
    api.deleteItemCategory(itemType.getId());
    api.deleteUser(user.getId());
  }
Exemple #2
0
  /** Test payInvoice(invoice) API call. */
  @Test
  public void testPayInvoice() {
    // setup
    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));

    // testing
    System.out.println("Getting an invoice paid, and validating the payment.");
    OrderWS order = buildOrder(user.getId(), Arrays.asList(item.getId()), new BigDecimal("3.45"));
    Integer invoiceId =
        api.createOrderAndInvoice(
            order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY));
    Integer orderId = api.getInvoiceWS(invoiceId).getOrders()[0];
    PaymentAuthorizationDTOEx auth = api.payInvoice(invoiceId);
    assertNotNull("auth can not be null", auth);
    PaymentWS payment = api.getLatestPayment(user.getId());
    assertNotNull("payment can not be null", payment);
    assertNotNull("auth in payment can not be null", payment.getAuthorizationId());

    // cleanup
    api.deletePayment(auth.getPaymentId());
    api.deleteInvoice(invoiceId);
    api.deleteOrder(orderId);
    api.deleteItem(item.getId());
    api.deleteItemCategory(itemType.getId());
    api.deleteUser(user.getId());
  }
Exemple #3
0
  /**
   * Test for: CreditCardFilter.For now it uses a value already in DB for the blacklisted cc number.
   * In prepare-test db the cc number 5555555555554444 is blacklisted.
   */
  @Test
  public void testBlacklistCreditCardFilter() {
    UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE, "5555555555554444");
    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));

    // get invoice id
    invoice = api.getLatestInvoice(user.getId());
    assertNotNull("Couldn't get last invoice", invoice);
    Integer invoiceId = invoice.getId();
    assertNotNull("Invoice id was null", invoiceId);

    // try paying the invoice
    System.out.println("Trying to pay invoice for blacklisted user ...");
    PaymentAuthorizationDTOEx authInfo = api.payInvoice(invoiceId);
    assertNotNull("Payment result empty", authInfo);

    // check that it was failed by the test blacklist filter
    assertFalse(
        "Payment wasn't failed for user: "******"Processor response", "Credit card number is blacklisted.", authInfo.getResponseMessage());

    // cleanup
    api.deleteInvoice(invoiceId);
    api.deleteItem(item.getId());
    api.deleteItemCategory(itemType.getId());
    api.deleteUser(user.getId());
  }
Exemple #4
0
  /** Tests the PaymentRouterCurrencyTask. */
  @Test
  public void testPaymentRouterCurrencyTask() {
    // prepare
    UserWS userUSD = buildUser(PRANCING_PONY_ACCOUNT_TYPE);
    userUSD.setCurrencyId(CURRENCY_USD);
    userUSD.setId(api.createUser(userUSD));

    UserWS userAUD = buildUser(PRANCING_PONY_ACCOUNT_TYPE);
    userAUD.setCurrencyId(CURRENCY_AUD);
    userAUD.setId(api.createUser(userAUD));

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

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

    // testing
    OrderWS order = buildOrder(userUSD.getId(), Arrays.asList(item.getId()), new BigDecimal("10"));
    order.setCurrencyId(userUSD.getCurrencyId());

    // create the order and invoice it
    System.out.println("Creating and invoicing order ...");
    Integer invoiceIdUSD =
        api.createOrderAndInvoice(
            order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY));
    Integer orderIdUSD = api.getLastOrders(userUSD.getId(), 1)[0];

    // try paying the invoice in USD
    System.out.println("Making payment in USD...");
    PaymentAuthorizationDTOEx authInfo = api.payInvoice(invoiceIdUSD);

    assertTrue("USD Payment should be successful", authInfo.getResult().booleanValue());
    assertEquals(
        "Should be processed by 'first_fake_processor'",
        authInfo.getProcessor(),
        "first_fake_processor");

    // create a new order in AUD and invoice it
    order.setUserId(userAUD.getId());
    order.setCurrencyId(userAUD.getCurrencyId());

    System.out.println("Creating and invoicing order ...");
    Integer invoiceIdAUD =
        api.createOrderAndInvoice(
            order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY));
    Integer orderIdAUD = api.getLastOrders(userAUD.getId(), 1)[0];

    // try paying the invoice in AUD
    System.out.println("Making payment in AUD...");
    authInfo = api.payInvoice(invoiceIdAUD);

    assertTrue("AUD Payment should be successful", authInfo.getResult().booleanValue());
    assertEquals(
        "Should be processed by 'second_fake_processor'",
        authInfo.getProcessor(),
        "second_fake_processor");

    // remove invoices and orders
    System.out.println("Deleting invoices and orders.");
    api.deleteInvoice(invoiceIdUSD);
    api.deleteInvoice(invoiceIdAUD);
    api.deleteOrder(orderIdUSD);
    api.deleteOrder(orderIdAUD);
    api.deleteUser(userUSD.getId());
    api.deleteUser(userAUD.getId());
    api.deleteItem(item.getId());
    api.deleteItemCategory(itemType.getId());
  }