Getting started with Clover Connector

The Clover Connector SDK

The Clover Connector SDK provides a consolidated asynchronous interface that enables your point-of-sale (POS) software to interact with Clover’s customer-facing payment devices.

ICloverConnector provides the callable interface. Some of its capabilities include:

  • Processing cards as:
    • Sales – Fixed-amount payments
    • Auths – Tip-adjustable payments
    • PreAuths – Pre-authorizations for a specific amount that can be updated before finalizing payment
  • Vaulting card tokens for future payments
  • Processing payment refunds and voids
  • Displaying order details
  • Printing images and text
  • Requesting batch closeouts
  • Requesting device and payment status
  • Starting and communicating with Custom Activities

ICloverConnectorListener provides the callback interface. Some of the events that will call back on ICloverConnectorListener include:

  • Responses to sales, authorizations, and pre-authorizations
  • Responses to card vaulting requests
  • Responses to payment refunds and voids
  • Responses to tip amount adjustments and captured payments for pre-authorizations
  • UI event messages sent as the Clover device changes screens, along with appropriate actions correlating to options on the device (e.g., Cancel, Ok, Done, Yes, No, etc.)
  • Closeout processing events
  • Requests to confirm payments or signatures
  • Events sent when the device disconnects, connects, or is ready
  • Responses to device and payment status requests
  • Responses or messages from Custom Activities

This tutorial will guide you through the process of connecting to your Clover device, initiating a Sale request, and handling the response to your Sale request.

Prerequisites

The tutorial assumes you have already:

In Application build.gradle:

buildscript {
	repositories {
		jcenter()
		mavenCentral()
  	}
  	def mavenPlugin = "com.github.dcendents:android-maven-gradle-plugin:1.5"
  	dependencies {
		classpath 'com.android.tools.build:gradle:2.3.0'
		classpath mavenPlugin
  	}
}

In Project build.gradle:

repositories {
  mavenCentral()
}

dependencies {
   ……
   compile 'com.clover.sdk:remote-pay-android-connector:1.2'
}

In AndroidManifest:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

Add resources > certs > clover_cacerts.p12 to your main folder:

Connectivity

USB is the preferred method of communication with the Clover device. The Android SDK provides an .aar file and a USB connector for tethering a Clover device to an Android device over USB. The USB connector requires the USB Pay Display app to communicate with a Clover device.

Note

If your point-of-sale doesn’t use USB to communicate, please contact us.

Configure a connection

Configure the connection between your Android device and the Clover device. The following example demonstrates how to configure a USB connection. You can also configure a network connection.

new USBCloverDeviceConfiguration(this, "Clover Example POS:1.3.1");

Create a Clover Connector

Create a Clover Connector and pass in the configuration from the previous step. The following example is for a network connection. You can also pass in a USB configuration.

cloverConnector = new CloverConnector(getNetworkConfiguration("192.168.0.131",12345));

 

Add a listener to the Clover Connector

1. Define an ICloverConnectorListener that will listen for callbacks when transactions finish and other events occur. Include the connection status methods that will be called.

  • OnDeviceDisconnected() – The Clover device is not available.
  • OnDeviceConnected() – The Clover device is connected, but not available to process requests.
  • OnDeviceReady() – The device is connected and available to process requests. It will automatically pass in a MerchantInfo object with information about the device, merchant, and some potential merchant payment configuration data, such as supportsAuths or supportsVaultCards.

 

private final class TestListener extends DefaultCloverConnectorListener {
    public TestListener(ICloverConnector cloverConnector) {
      super(cloverConnector);
    }

    @Override
    public void onConfirmPaymentRequest(ConfirmPaymentRequest request) {
    }
     
    //additional methods can be overriden later

}

2. Add the listener to the Clover Connector.

cloverConnector.addCloverConnectorListener(new TestListener(cloverConnector));

Initialize the connection

Initialize the connection to start communication with the Clover device. Note that you must do this before calling any other methods (other than those that add or remove listeners).

cloverConnector.initializeConnection();

Display a message on the Clover device

Send a test message to the Clover device.

cloverConnector.showMessage("Welcome to Clover Connector!");

 

Now that you’ve connected to the Clover device and sent a successful test message, you’re ready to start making requests.

Initiate a Sale from your POS software

To make a Sale() request:

1. Define how to handle the SaleResponse in your ICloverConnectorListener. The truncated code below provides a generalized overview of the methods you’ll need to use to get a response to your request for a Sale. (A detailed interpretation of the SaleResponse appears in the Handling the result of a Sale transaction section below.)

 

 private final class TestListener extends DefaultCloverConnectorListener {
    public TestListener(ICloverConnector cloverConnector) {
      super(cloverConnector);
    }
   
@Override
    public void onSaleResponse(SaleResponse response) {
      // check response for success and process accordingly
      // see below for more detail ‘Handling Results of a Sale Transaction’
            … 
    }

   @Override
    public void onConfirmPaymentRequest(ConfirmPaymentRequest request) {
    // must accept or reject the payment using the ICloverConnector
    // see below for more detail ‘Handling Results of a Sale Transaction’
       …
    }

   @Override
    public void onVerifySignatureRequest(VerifySignatureRequest request) {
     // must accept or reject the signature using the ICloverConnector
     // see below for more detail ‘Handling Results of a Sale Transaction’
         …
    }

}

 

2. Create a SaleRequest and call the Sale() method.

 

pendingSale = new SaleRequest(1000, MainActivity.getNextId());
cloverConnector.sale(pendingSale);

 

Note

The code snippets in this tutorial are not feature-rich. For the best way to implement the SDK in production, see the Example Android POS.

Once you call the Sale() method, Clover will contact the payment gateway and return information about the result of the transaction to your POS.

Handling the result of a Sale transaction

After Clover has finished processing the Sale transaction request, OnSaleResponse() will be called. Transaction responses have a boolean Success property, as well as an enum Result property that provides information on the success flag.

If the transaction is successful, the response will also have the Payment object, which may contain the full or partial amount of the Sale request.

Note

A Sale transaction may come back as a tip-adjustable Auth, depending on the payment gateway. The SaleResponse includes a boolean isSale variable that indicates whether the Sale is final, or will be finalized during closeout.

 

private final class TestListener extends DefaultCloverConnectorListener {
    public TestListener(ICloverConnector cloverConnector) {
      super(cloverConnector);
    }

    @Override
    public void onConfirmPaymentRequest(ConfirmPaymentRequest request) {
      Log.d(TAG,"Confirm Payment Request");
      addText("Confirm Payment Request");

      Challenge[] challenges = request.getChallenges();
      if (challenges != null && challenges.length > 0)
      {
        for (Challenge challenge : challenges) {
          Log.d(TAG,"Received a challenge: " + challenge.type);
          addText("Received a challenge: " + challenge.type);
        }
      }

      addText("Automatically processing challenges");
      Log.d(TAG, "Automatically processing challenges");
      cloverConnector.acceptPayment(request.getPayment());
    }

    @Override
    public void onSaleResponse(SaleResponse response) {
      try {
        if (response.isSuccess()) {
          Payment payment = response.getPayment();
          if (payment.getExternalPaymentId().equals(pendingSale.getExternalId())) {
            String saleRequest = ("Sale Request Successful\n");
            saleRequest += ("  ID: " + payment.getId()+"\n");
            saleRequest += ("  External ID: " + payment.getExternalPaymentId()+"\n");
            saleRequest += ("  Order ID: " + payment.getOrder().getId()+"\n");
            saleRequest += ("  Amount: " + payment.getAmount()+"\n");
            saleRequest += ("  Tip Amount: " + payment.getTipAmount()+"\n");
            saleRequest += ("  Tax Amount: " + payment.getTaxAmount()+"\n");
            saleRequest += ("  Offline: " + payment.getOffline()+"\n");
            saleRequest += ("  Authorization Code: " + payment.getCardTransaction().getAuthCode()+"\n");
            saleRequest += ("  Card Type: " + payment.getCardTransaction().getCardType()+"\n");
            saleRequest += ("  Last 4: " + payment.getCardTransaction().getLast4());
            addText(saleRequest);
            Log.d(TAG,"sales request: "+saleRequest);
          } else {
            addText("Sale Request/Response mismatch - " + pendingSale.getExternalId() + " vs " + payment.getExternalPaymentId());
            Log.d(TAG,"Sale Request/Response mismatch - " + pendingSale.getExternalId() + " vs " + payment.getExternalPaymentId());
          }
        } else {
          addText("Sale Request Failed - " + response.getReason());
          Log.d(TAG,"Sale Request Failed - " + response.getReason());
        }
      } catch (Exception ex) {
        Log.d(TAG,"Error handling sale response");
        ex.printStackTrace();
      }
    }

    @Override
    public void onVerifySignatureRequest(VerifySignatureRequest request) {
      super.onVerifySignatureRequest(request);
      addText("Verify Signature Request - Signature automatically accepted by default");
      Log.d(TAG,"Verify Signature Request - Signature automatically accepted by default");
    }


  }

Sale transaction errors

OnSaleResponse() will also return one of the following codes.

  • SUCCESS – The call succeeded and was successfully queued or processed.
  • FAIL – The call failed due to an incorrect value that was passed in, an invalid card, insufficient funds, or another reason.
  • UNSUPPORTED – The current merchant configuration doesn’t support the capability.
  • CANCEL – The merchant or customer has pressed the Cancel or Back button on the Clover device.
  • ERROR – An error that wasn’t expected or handled appropriately occurred. This code is returned when the SDK encounters one of the following problems:
    • Device Connection Error – The Clover device is not connected.
    • Request Validation Error – The request that was passed in for processing is empty.
    • Request Validation Error – The request ExternalId cannot be null or blank.
    • Request Validation Error – The request amount cannot be zero.
    • Request Validation Error – The request tip amount cannot be less than zero.
    • Merchant Configuration Validation Error – Not offered by the merchant-configured gateway.

Test your app

Test your app using the Test card numbers for declines and partial transactions.

For information on Clover’s testing requirements, please see the Testing & validation page.

Additional resources