question

maninder avatar image
maninder asked maninder commented

getting java.lang.SecurityException while using IInvetoryService.createTaxRate(TaxRate var1, ResultStatus var2) method

Hello, I have used the IInvertoryService interface and I am facing java.lang.securityexception. Below is my piece of code and log associated to it for your reference :-

  //creating resultStatus as below
  ResultStatus resultStatus = new ResultStatus();
  TaxRate giftTax = new TaxRate().setName("GiftTax").setRate(1000l).setIsDefault(true);
  giftTax = inventoryService.createTaxRate(giftTax,resultStatus);////   throwing error here

  inventoryService = IInventoryService.Stub.asInterface(service);
  // Create New Tax Gift Tax and set it to 0.
    TaxRate giftTax = new TaxRate().setName("GiftTax").setRate(1000l).setIsDefault(true);
     giftTax = inventoryService.createTaxRate(giftTax,resultStatus);

The error appears in the last line i.e inventoryService.createTaxRate(giftTax,resultStatus); and below is the log :-

rr: java.lang.SecurityException: Access denied to package com.intelegain.tenderexample 12-30 03:44:44.147 8389-9179/com.intelegain.tenderexample W/System.err: at android.os.Parcel.readException(Parcel.java:1472) 12-30 03:44:44.147 8389-9179/com.intelegain.tenderexample W/System.err: at android.os.Parcel.readException(Parcel.java:1426) 12-30 03:44:44.157 8389-9179/com.intelegain.tenderexample W/System.err: at com.clover.sdk.v3.inventory.IInventoryService$Stub$Proxy.createTaxRate(IInventoryService.java:2518) 12-30 03:44:44.157 8389-9179/com.intelegain.tenderexample W/System.err: at com.customtender.selectFunction$4.doInBackground(selectFunction.java:496) 12-30 03:44:44.157 8389-9179/com.intelegain.tenderexample W/System.err: at com.customtender.selectFunction$4.doInBackground(selectFunction.java:472) 12-30 03:44:44.157 8389-9179/com.intelegain.tenderexample W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288) 12-30 03:44:44.157 8389-9179/com.intelegain.tenderexample W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237) 12-30 03:44:44.167 8389-9179/com.intelegain.tenderexample W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 12-30 03:44:44.167 8389-9179/com.intelegain.tenderexample W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 12-30 03:44:44.167 8389-9179/com.intelegain.tenderexample W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 12-30 03:44:44.167 8389-9179/com.intelegain.tenderexample W/System.err: at java.lang.Thread.run(Thread.java:841)

So can anyone please help me understand me what am I doing or Is there anything I am missing out on in above case ??

Thanks in advance.

10 |2000

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

Mark Mullan avatar image
Mark Mullan Deactivated answered maninder commented

Hi,

Our Connector classes provide the high level API that should be called. In this case, InventoryConnector.createTaxRate() should accomplish what you're looking for.

If this is your first time using our Android SDK, this section of our docs, in particular, will be particularly helpful in understanding how to use the Connectors.

6 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.

maninder avatar image maninder commented ·

Hello Mark, Thank you for the reply. To start with, what I am trying to achieve with the above code was setting tax to the inventory item using IInventoryService. The above code was working fine earlier but for some reason now its throwing the above exception. All I want to do here is add tax to item using IInventoryService. So can you help me understand what is wrong ?

0 Likes 0 ·
Mark Mullan avatar image Mark Mullan commented ·

Hi @maninder,

The issue lies with using the IInventoryService in the first place. The InventoryConnector is the API that should be used by you, and is a wrapper for the IInventoryService class.

0 Likes 0 ·
maninder avatar image maninder commented ·

Alright Mark, Can you share an example or any link for the same please?

0 Likes 0 ·
maninder avatar image maninder commented ·

A quick update Mark, I used InventoryConnector. The code is as follows :-

        // initializing and connecting inventory here
        InventoryConnector inventoryConnector = new InventoryConnector(this, account, null);
        inventoryConnector.connect();

        // create gift tax
       TaxRate giftTax = new TaxRate().setName("GiftTax").setRate(1000l).setIsDefault(true);
       ////   this again throws same exception as above.
       giftTax = inventoryConnector.createTaxRate(giftTax);
0 Likes 0 ·
Mark Mullan avatar image Mark Mullan commented ·

Hi @maninder,

@Sam provided some code in the other Answer on this post.

I was able to get an "Access denied to package" error if my package was not recognized by my test merchant. Create a Quick Android App on your Developer Dashboard (https://www.clover.com/developers/login or https://sandbox.dev.clover.com/developers/login) and install it to your test merchant. This should resolve the SecurityException.

0 Likes 0 ·
Show more comments
sam avatar image
sam Deactivated answered sam Deactivated commented

createTaxRate returns void so don't store return in a variable: giftTax = inventoryConnector.createTaxRate(giftTax);

You will need also need to handle the remote, client, service and binding exceptions, as per the sample code below.

Make sure you have the correct permissions set for your app on your dashboard. status code: 403 App doesn't have required permission: package com.example.myTestCode does not have permission INVENTORY_W

 private class InventoryAsyncTask extends AsyncTask<Void, Void, TaxRate>{
        TaxRate taxRate;

        @Override
        protected final TaxRate doInBackground(Void... params) {
            try{
                taxRate = new TaxRate().setName("test1").setRate(1000l).setIsDefault(true);
                mInventoryConnector.createTaxRate(taxRate);
            }catch (RemoteException | ClientException | ServiceException | BindingException e) {
                e.printStackTrace();
            }
            return taxRate;
        }

If your permissions have changed since you installed it, you will need to update or reinstall the app.

6 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.

pavan avatar image pavan commented ·

Hi Sam, I have created app with the all permission it contains INVENTORYW too also i able to create new inventory item through my application only the problem i getting is creating taxrate, if my issue with INVENTORYW then i should not be allowed to create inventory item but in my case i can create inventory item that means i have INVENTORY_W so do we get any idea or lead towards the problem i getting in createTaxRate. Is there any merchant setting or taxrate setting which i missing?

0 Likes 0 ·
sam avatar image sam commented ·

Hi Pavan, as in the email, seems like this is a bug. Thanks for bring it to our attention. We'll let you know when it's fixed.

0 Likes 0 ·
pavan avatar image pavan commented ·

@Sam hi we are tying to implement taxrate using https://sandbox.dev.clover.com/api_do... but not able to find any proper example for same it will be great you provide a example for same

0 Likes 0 ·
sam avatar image sam commented ·

@Pavan Create a Tax Rate POST /v3/merchants/{mid}/tax_rates

body:
{
      "name": "Test",
      "rate": 1500000,
      "isDefault": false
}

Make sure item has custom tax: POST /v3/merchants/{mId}/items/{itemId}

{
  "defaultTaxRates": false
}

THEN create association

POST /v3/merchants/{mId}/tax_rate_items

{
  "elements": [
    {
      "item": {
        "id": {item id}
      },
      "taxRate": {
        "id": {taxRate id}
      }
    }
  ]
}
0 Likes 0 ·
pavan avatar image pavan commented ·

Hi @Sam thank you for reply, we have implemented https://www.clover.com/api_docs/#!/in... (POST /v3/merchants/{mId}/tax_rates) to create tax and on successful tax creation setting tax to items using inventoryService.assignTaxRatesToItem(itemid, taxrates, resultStatus) ; which seems working here. It will be great if you keep us updated regarding android-sdk taxrate issue, thank you.

0 Likes 0 ·
Show more comments

Welcome to the
Clover Developer Community