Order creation giving error

I created 1 order with below code

`private Order generateOrder() {
Order order = new Order();
order.setId(UUID.randomUUID());
List items = new ArrayList();
// create some dummy items to display in second screen
items = new ArrayList();
OrderItem item1 = new OrderItem();
// these are the only required fields for second screen display
item1.setName(“Item1”);
item1.setUnitPrice(100l);
item1.setQuantity(1.0f);
items.add(item1);

    OrderItem item2 = new OrderItem();
    // these are the only required fields for second screen display
    item2.setName("Item2");
    item2.setUnitPrice(100l);
    item2.setQuantity(1.0f);
    items.add(item2);

    OrderItem item3 = new OrderItem();
    // these are the only required fields for second screen display
    item3.setName("Item3");
    item3.setUnitPrice(100l);
    item3.setQuantity(2.0f);
    items.add(item3);
    order.setItems(items);

    BigDecimal subTotal = new BigDecimal(0);
    for (OrderItem item : items) {
        BigDecimal price = new BigDecimal(item.getUnitPrice());
        price.setScale(2, RoundingMode.HALF_UP);
        price = price.multiply(new BigDecimal(item.getQuantity()));
        subTotal = subTotal.add(price);
    }

    OrderAmounts amounts = new OrderAmounts();
    amounts.setCurrency("USD");
    amounts.setSubTotal(subTotal.longValue());
    order.setAmounts(amounts);

    return order;
}`

After payment is done and I get the callback , I am trying to create the order using below code:
public void createOrder() {
try {
String referenceId = UUID.randomUUID().toString();
iPoyntOrderService.createOrder(generateOrder(),referenceId,iPoyntOrderServiceListener);

    } catch (RemoteException e) {

    }
}

It is giving error “Invalid parameter” in call back.

Any one know what is the issue here?

can you post the error from the logcat or share Poynt-Request-Id (you can see it in the logcat as well)

Or consider using this as an example: http://bit.ly/1TUOh1a

This is the Id ee8fd0d7-6fc6-4204-b3d8-7961e89112bd

It start working with your example but what was the issue with my code. You added the order status as well and mark it completed.There is no product id we are adding while adding the items so is that correct. How item will be mapped with products.

A POS app can use Poynt catalog but it does not have to. So item id may not map to product id.
To answer the question about what was wrong with your order. “status” is a required field: https://poynt.com/docs/api/#model-orderitem

1 Like

Thanks dennis. How could I get list of order using Android SDK? I don’t see any API call in orderService for this.

Hi Dennis,

if I set transaction list to order object after getting callback form payment , it is showing it is bad request. How can I set the list of transaction while creating the order object.

Best
Sandeep

Regarding getting the list of orders, responded on Fetching all Orders using SDK.

I am not sure I understand your question about setting transaction list to order. Maybe you can share the code snippet?

`public static Order generateOrder(List transactions) {
Order order = new Order();
order.setId(UUID.randomUUID());
List items = new ArrayList();
// create some dummy items to display in second screen
items = new ArrayList();
OrderItem item1 = new OrderItem();
// these are the only required fields for second screen display
item1.setName(“Item1”);
item1.setUnitPrice(100l);
item1.setQuantity(1.0f);
item1.setUnitOfMeasure(UnitOfMeasure.EACH);
item1.setStatus(OrderItemStatus.FULFILLED);
item1.setTax(0l);
items.add(item1);

    OrderItem item2 = new OrderItem();
    // these are the only required fields for second screen display
    item2.setName("Item2");
    item2.setUnitPrice(100l);
    item2.setQuantity(1.0f);
    item2.setTax(0l);
    item2.setUnitOfMeasure(UnitOfMeasure.EACH);
    item2.setStatus(OrderItemStatus.FULFILLED);
    items.add(item2);


    OrderItem item3 = new OrderItem();
    // these are the only required fields for second screen display
    item3.setName("Item3");
    item3.setUnitPrice(100l);
    item3.setQuantity(2.0f);
    item3.setStatus(OrderItemStatus.FULFILLED);
    item3.setUnitOfMeasure(UnitOfMeasure.EACH);
    item3.setTax(0l);
    items.add(item3);
    order.setItems(items);

    BigDecimal subTotal = new BigDecimal(0);
    for (OrderItem item : items) {
        BigDecimal price = new BigDecimal(item.getUnitPrice());
        price.setScale(2, RoundingMode.HALF_UP);
        price = price.multiply(new BigDecimal(item.getQuantity()));
        subTotal = subTotal.add(price);
    }

    OrderAmounts amounts = new OrderAmounts();
    amounts.setCurrency("USD");
    amounts.setSubTotal(subTotal.longValue());

    // for simplicity assuming netTotal is the same as subTotal
    // normally: netTotal = subTotal + taxTotal - discountTotal + cashback
    amounts.setNetTotal(subTotal.longValue());
    order.setAmounts(amounts);

    OrderStatuses orderStatuses = new OrderStatuses();
    orderStatuses.setStatus(OrderStatus.COMPLETED);
    order.setStatuses(orderStatuses);
    order.setId(UUID.randomUUID());
    //order.setTransactions(transactions);
    return order;
}

If I uncomment the `order.setTransactions(transactions); and try to create order , it is giving bad request error. I am getting this transaction list in the callback of payment fragment.

you actually don’t need to do that. As long as you set order id in the Payment object you pass as an intent extra when starting the payment flow matches the id of the order you create, transactions will be linked to the order object on the server.