question

Iveta Ivanova avatar image
Iveta Ivanova asked zgreathouse Deactivated edited

Trouble getting merchant through clover sdk - merchant connector

Recently our app is not working on Mini when the device is used as customer facing.
The problem occurs on production with our merchants.

The problem is that it is not able to get the merchant info by the Clover sdk.

To get the merchant info we are using the following code

public Observable<Merchant> getMerchant() {
    if (merchant != null) {
        return Observable.just(merchant);
    }

    Account account = getCloverAccount();
    MerchantConnector merchantConnector = new MerchantConnector(context, account, null);
    merchantConnector.connect();

    return Observable.create(emitter -> {
        try {
            merchant = merchantConnector.getMerchant();
        } catch (RemoteException | ClientException | ServiceException | BindingException e) {
            Timber.e(e, "Cannot get merchant info! For account " + account);
        } finally {
            merchantConnector.disconnect();
        }

        if (merchant == null) {
            emitter.onError(new Exception("Cannot get merchant info!"));
            return;
        }

        emitter.onNext(merchant);
        emitter.onComplete();
    });
}

And the following exception is thrown:

E/null Cannot get merchant info! For account null 
com.clover.sdk.v1.BindingException: Could not bind to Android service 
at com.clover.sdk.v1.ServiceConnector.waitForConnection(ServiceConnector.java:199) 
at com.clover.sdk.v1.ServiceConnector.execute(ServiceConnector.java:245) 
at com.clover.sdk.v1.merchant.MerchantConnector.getMerchant(MerchantConnector.java:208) 

Do you have any idea how to fix this issue?
Merchant
10 |2000

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

Iveta Ivanova avatar image
Iveta Ivanova answered
Hi @zgreathouse.

After more research in the Community forum and after double check in our Crashlytics, I found where is the problem.

The Clover mini with this problem was 2nd generation, i.e. Android 8.1.0 (API Level 27, Oreo).
I will need to set a targetSdkVersion of 25 at most to avoid this issue.

Thank you again.
Have a nice day.
10 |2000

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

chanel avatar image
chanel Deactivated answered zgreathouse Deactivated edited
We suggest getting merchant info by checking for a valid CloverAccount and only then attempting to use MerchantConnector to get Merchant information. Below is an example:

// Retrieve the Clover account
if (account == null) {
    account = CloverAccount.getAccount(this);
    if (account == null) {
        Toast.makeText(this, getString(R.string.no_account), Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
}

// Create and connect to MerchantConnector
merchantConnector = new MerchantConnector(this, account, null);
merchantConnector.connect();

// In a AsyncTask
merchant = merchantConnector.getMerchant();
Log.d("MyApp", "Merchant ID: " + merchant.getId());

// Disconnect and destroy Connector when finished
if (merchantConnector != null) {
    merchantConnector.disconnect();
    merchantConnector = null;
}
3 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.

Iveta Ivanova avatar image Iveta Ivanova commented ·
Hi.

Thank you for your suggestion but my current implementation is already than like that. Sorry to not add this part of the code. In fact my getAccount() method retrieve the clover account:

private Account getCloverAccount() {
    return CloverAccount.getAccount(context);
}

I'm only miss the part with checking if this account info is null.

But in which situations a production app: submitted, approved and released in the Clover app market, installed via this market can not get the clover account using the method above?
This is the app that I'm talking about:
https://www.clover.com/appmarket/apps/6XZ2KXFEVQPKT

Thank you for your help.
0 Likes 0 ·
zgreathouse avatar image zgreathouse Iveta Ivanova commented ·

You mentioned you are not performing a null check. After you implement the null check, please let us know if you are still running into the issue and please be sure to provide a code snippet of the updated code and a screenshot of the error.

0 Likes 0 ·
Iveta Ivanova avatar image Iveta Ivanova zgreathouse commented ·

Hi @zgreathouse.

Thank you for your fast response.

In fact for our merchant CloverAccount.getAccount(context) returns always null - i.e. our app cannot get the merchant info and cannot do the authentication against our back-end. So if I add the null check the MerchantService wont be called, no error will be thrown but our app will stay forever in offline mode.

More over, I'm not able to reproduce this problem with our devkit or an emulator. Also, we do not have clover mini and cannot test he configuration station + mini in customer facing mode.

0 Likes 0 ·

Welcome to the
Clover Developer Community