question

dipen avatar image
dipen asked Mike M answered

Apply Discount in android

How can we apply discount with amount instead of applying as percentage? In android when adding Discount to line time by setting amount it throws ClientException but we set percent to discount object it works fine.

Below is the case of failure :

Discount discount = new Discount(); discount.setName("Test discount"); discount.setAmount(500);

connector.addLineItemDiscount2(orderID, lineItemID, discount);

Below is the case of Success :

Discount discount = new Discount(); discount.setName("Test discount"); discount.setPercentage(50)

connector.addLineItemDiscount2(orderID, lineItemID, discount);

In success case, the percentage is Long value but there may be some cases when calculated percentage is a decimal value which is getting ignored because its a long value.

Below is the reference of Discount class in clover android sdk : http://clover.github.io/clover-androi...

OrdersDiscounts
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

Mike M avatar image
Mike M answered

Yeah, in this case, the easier route is to calculate the amount first, and then apply it to the discount object as a negative amount (instead of using percentages). The main key is that the discount amount is negative, as I guess it was designed with the intent that the amount was being removed from the price and thus must be negative.

Try: discount.setAmount(-20L);

10 |2000

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

Welcome to the
Clover Developer Community