question

adamd avatar image
adamd asked adamd commented

Adding a tax rate to a Custom Line Item using the Clover SDK?

Hi there,

We are trying to add a tax rate to a line item using the clover sdk but we think there is an issue with the clover sdk.

Here is a snippet of our code;

LineItem lineItem = new LineItem();
lineItem.setIsRevenue(true);
lineItem.setName("Name");
lineItem.setPrice(1000l);

ArrayList<TaxRate> taxRates = new ArrayList<>();
TaxRate taxRate = new TaxRate();
taxRate.setId("ASAQPFWX7S3BE");
taxRate.setName("VAT");
taxRate.setRate(2000000l);
taxRate.setIsDefault(true);
taxRates.add(taxRate);

lineItem.setTaxRates(taxRates);
orderConnector.addCustomLineItem(CloverData.sCloverOrderId, lineItem, false);

Every time we make this call we get the error.

com.clover.sdk.v1.ClientException: status code: 400 cannot update one or more of these fields: LineItem{json='{"taxRates":{"elements":[{"id":"ASAQPFWX7S3BE","name":"VAT","rate":2000000,"isDefault":true}]},"name":"Adult","price":2000,"isRevenue":true}', bundle=null, changeLog=null}

Any idea what were are doing wrong?

Clover Android SDKLineItems
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.

Anything in the logcat? Have you tried to minimize the problem, e.g. if you don't add the taxRates do you get the same error?

0 Likes 0 ·
adamd avatar image adamd David Marginian ♦♦ ·

The only thing of interest in the logcat is this

00:32.911 845-2632/? I/OrderBinderImpl: hasValidChanges(OrderBinderImpl.java:3970)[Binder_7]: error - cannot change any of these fields: LineItem{json='{"taxRates":{"elements":[{"id":"ASAQPFWX7S3BE","name":"VAT","rate":2000000,"isDefault":true}]},"name":"Name","price":1000,"isRevenue":true}', bundle=null, changeLog=null}

Yes we have, when the tax rate code is removed it adds a lineitem fine. We have been using this for a while now but we have had a request for tax rates recently.


0 Likes 0 ·

1 Answer

David Marginian avatar image
David Marginian answered adamd commented

OrderConnector.addCustomLineItem's signature is as follows:

addCustomLineItem(String orderId, LineItem lineItem, boolean isTaxable)

You are passing false for isTaxable, but you just added taxRates to the lineItem, that doesn't make sense and is why you are seeing this error. If you want to add taxRates to the line item then you need to pass true for isTaxable.

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.

Doh! Yup that was my mistake, Thanks :).

0 Likes 0 ·

Welcome to the
Clover Developer Community