I'm having trouble adding a discount to a custom line item. Here is the code:
mOrder = mOrderConnector.createOrder(new Order()); LineItem lineItem = new LineItem(); lineItem.setName("Gift Card"); lineItem.setPrice(cardPrice.getCardPrice()); if (category.equals("Return")) { //make discount object Discount discount = new Discount(); discount.setAmount(-cardPrice.getCardPrice()); discount.setName("Return"); //make discount list List<Discount> discounts = new ArrayList<>(); discounts.add(discount); //add discount to line item lineItem.setDiscounts(discounts); } //add line item to order mOrderConnector.addCustomLineItem(mOrder.getId(), lineItem, false);
I get this error:
2021-08-25 13:18:29.369 12589-12630/com.example.cocoa_giftcards W/System.err: com.clover.sdk.v1.ClientException: status code: 400 cannot update one or more of these fields: LineItem{json='{"discounts":{"elements":[{"amount":-2000,"name":"Return"}]},"name":"Gift Card","price":2000}', bundle=null, changeLog=null} 2021-08-25 13:18:29.370 12589-12630/com.example.cocoa_giftcards W/System.err: at com.clover.sdk.v1.ServiceConnector.throwOnFailure(ServiceConnector.java:333) 2021-08-25 13:18:29.370 12589-12630/com.example.cocoa_giftcards W/System.err: at com.clover.sdk.v1.ServiceConnector.execute(ServiceConnector.java:266) 2021-08-25 13:18:29.370 12589-12630/com.example.cocoa_giftcards W/System.err: at com.clover.sdk.v3.order.OrderV31Connector.addCustomLineItem(OrderV31Connector.java:343) 2021-08-25 13:18:29.371 12589-12630/com.example.cocoa_giftcards W/System.err: at com.example.cocoa_giftcards.MainActivity$AddCardToOrder.run(MainActivity.java:837) 2021-08-25 13:18:29.371 12589-12630/com.example.cocoa_giftcards W/System.err: at java.lang.Thread.run(Thread.java:764)
Any help would be appreciated!