question

steve avatar image
steve asked voski commented

How do I cancel a discount ?

Hi, I'm having a problem removing a discount that I previously applied to an order. When I call OrderConnector.deleteDiscounts() I always get a ClientException. For testing purposes I'm currently trying to apply a discount and remove it straight away. Can anyone see a problem with this code:

Discount discount = new Discount();

discount.setPercentage(5L);

discount.setName("5% Discount");

discount.setId("123");

mOrderConnector.addDiscount(orderId, discount);

List<string> discounts = new ArrayList<>();

discounts.add("123");

mOrderConnector.deleteDiscounts(orderId, discounts);

Thanks, 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

voski avatar image
voski answered voski commented

At first glance I see that you are setting the discount id yourself this id will not correspond to the ID in our database. I believe your call on mOrderConnector.addDiscount(orderId, discount) will return an Order. You should be able to do order.getDiscounts() to get a list of Discounts. In your case we expect one discount in the list, get the ID for that discount and add that to your list.

2 comments
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 avatar image steve commented ·

Thanks Voski.....that solved my problem

0 Likes 0 ·
voski avatar image voski commented ·

@Steve glad it worked if you want check this as the correct answer so it will be visible to others. Cheers

0 Likes 0 ·

Welcome to the
Clover Developer Community