Exemplo n.º 1
0
  public OrderWS buildOrder(int userId, List<Integer> itemIds, BigDecimal linePrice) {
    OrderWS order = new OrderWS();
    order.setUserId(userId);
    order.setBillingTypeId(Constants.ORDER_BILLING_POST_PAID);
    order.setPeriod(ORDER_PERIOD_ONCE); // once
    order.setCurrencyId(CURRENCY_USD);
    order.setActiveSince(new Date());
    order.setProrateFlag(Boolean.FALSE);

    ArrayList<OrderLineWS> lines = new ArrayList<OrderLineWS>(itemIds.size());
    for (int i = 0; i < itemIds.size(); i++) {
      OrderLineWS nextLine = new OrderLineWS();
      nextLine.setTypeId(Constants.ORDER_LINE_TYPE_ITEM);
      nextLine.setDescription("Order line: " + i);
      nextLine.setItemId(itemIds.get(i));
      nextLine.setQuantity(1);
      nextLine.setPrice(linePrice);
      nextLine.setAmount(nextLine.getQuantityAsDecimal().multiply(linePrice));

      lines.add(nextLine);
    }
    order.setOrderLines(lines.toArray(new OrderLineWS[lines.size()]));
    return order;
  }
Exemplo n.º 2
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());
  }