question

steve-egan avatar image
steve-egan asked steve-egan commented

How do I change the price of a LineItem using the Android SDK ?

Hi, I am desperately trying to change the price of a LineItem using the Android SDK but I am always getting a ClientException. For this example a customer is buying one item.

List<LineItem> lineItems = mOrder.getLineItems(); // return a List with 1 LineItem
LineItem lineItem = lineItems.get(0); // get the first LineItem
lineItem.setUnitQty(3); // update quantity

List<LineItem> lineItemsAsList = Collections.singletonList(lineItem); // turn the LineItem into a List of LineItems
mOrderConnector.updateLineItems(mOrder.getId(), lineItemsAsList);

No matter what change I make to the LineItem will cause the ClientException. Even making no change to the LineItem causes the exception.

Does anyone have any ideas what could be wrong with the above code?

Thank you, Steve

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

anthonypinto avatar image
anthonypinto answered steve-egan commented

There is an underlying issue with how you are using the lineItems here. The Connector doesn't have robust support for modifying lineItems after they are created. The typical flow (which we use in register as well) is to remove a lineItem if it is incorrect, and add a new one. And this is what I would recommend to you. orderConnector.deleteLineItems will function more as you expect.

Also note:

  • A typical lineItem is associated with an item, and so the price will be based on that item.

  • unitQty is only used for items with per unit pricing (otherwise additional copies of an item are added in their own lineItems - visually these may roll together depending on merchant settings)

1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

steve-egan avatar image steve-egan commented ·

Thanks Anthony, I appreciate your feedback on this. I thought I was missing something very obvious. I'll delete the LineItem and recreate it as advised. Thanks again.

0 Likes 0 ·

Welcome to the
Clover Developer Community