Working with the SDK

This section includes the following main topics:

Setting up the app to take a payment

To set up an app to take payments:

  1. Initialize the SDK (each time the app starts).
  2. Authenticate the merchant and pass the merchant credentials to the SDK (the first time the merchant uses the app).
  3. Determine the types of payment the merchant can accept (optional, might be useful depending on the app logic).
  4. Start monitoring the card reader for events (for card present transactions).

Initialize the SDK

The PayPal Here SDK is initialized by calling the class method PayPalHereSDK.init:

    Public class LoginScreenActivity extends Activity {
    . . .
    PayPalHereSDK.init(getApplicationContext(), PayPalHereSDK.Sandbox);
  • The first parameter is the context of the global Application object. This example gets it by defining a class that extends Activity and calling its getApplicationContext method.
  • The second parameter identifies the environment that the SDK operates in. It can be PayPalHereSDK.Live or PayPalHereSDK.Sandbox.

Authenticate the merchant

See Authenticating SDK operations for this procedure. Most of the steps involve calls to OAuth (see Using OAuth to Authenticate Requests) or to the sample mid-tier server.

Set the active merchant

Once the app has authenticated the server, it calls PayPalHereSDK.setCredentials() to set the merchant for the executed transactions.

    Credentials credentials = . . .;   //  The merchant OAuth credentials.
    Final DefaultResponseHandler =    //  A default response handler
    new DefaultResponseHandler< Merchant, PPErrorMerchantManager.MerchantErrors>;  
    PayPalHereSDK.setCredentials(credentials, defaultResponseHandler);           

Determine types of payment the merchant can accept

Note: This step is optional.

After authenticating the merchant, but before taking payment, you can ask the SDK:

  • Whether the logged-in merchant is allowed to take payments
  • Whether the logged-in merchant is allowed to process check-in transactions, and the types of payment the merchant can take for them

You determine the types of payment that the merchant can accept by examining their Merchant object, as in this example:

    private void displayMerchantInfo() {
    Merchant m = PayPalHereSDK.getMerchantManager().getActiveMerchant();
    String email = "";
    String businessName = "";
    String currencyCode = "";
    // Get basic data about the logged-in merchant from the SDK Merchant object.
    if (m!=null) {
       email = m.getEmail();
       businessName = m.getBusinessName();
       Currency c = m.getMerchantCurrency();
       If (c!=null) {
          currencyCode = c.getCurrencyCode();
     // Determine whether the logged-in merchant can process transactions.
     String status = m.getMerchantStatus();
     // Determine the types of payment the logged-in merchant can take
     ListMerchant.AvailablePaymentTypes paymentTypes = m.getAllowedPaymentTypes();

Start monitoring the card reader

To start monitoring the card reader for a card swipe, call the card reader manager beginMonitoring method: