Android integration

This page explains the steps to integrate Client Side Encryption with your Android application using Gradle, or manually.

  1. Create your RSA key pair, and access your key

  2. Import the codeinto your project

  3. Import the WorldpayCSE package

  4. Create the WorldpayCSE object

  5. Set the public (RSA) key

  6. Set up the cardholder data

  7. Encrypt the cardholder data

Note: View our Android terms of usehere.

Libraries

  • Maven Central Sonatype maven repositary binaries: https://oss.sonatype.org/content/repositories/releases/com/worldpay/

  • Online generated API documentation: http://www.javadoc.io/doc/com.worldpay/cse-android-sdk/1.0.2

  • GitHub repository : https://github.com/Worldpay/worldpay-cse-lib-android

Create your RSA key pair

CSE works using a 2048 bit RSA key pair which is made up of a public key and a private key. The public key must be supplied to the CSE library, and is used to encrypt the sensitive card details.

The private key exists within a secure environment at Worldpay. It is never transmitted and is not visible to any member of staff at Worldpay.

To create a key pair:

  1. Log in to the Merchant Admin Interface (MAI) and click Client Side Encryption in the left panel.

  2. Enter the description of the key, and then click Generate key.

    The key pair has now been generated, and you'll be able to use the public key to encrypt card details.

Note: You can create more than one key. This is useful, for example, if you want to roll your keys to change them after a period of time. You can also disable a disused key. To learn more seeKey Rotation.

Access your key

To build the key into your payment page, you must view it:

  1. Click View key on the key you wish to view. You'll be taken to a page which shows the key in two different formats:

    1. Public key

      This is the whole key in its entirety.

    2. JavaScript formatted key

      This is your formatted key. It has been formatted to allow you to simply copy it into your payment page.

  2. Click the Client Side Encryption button at the bottom of the page to return to the main page.

Note: Although sensitive information is encrypted, there is no change in the way Worldpay processes a payment.

Installation

With Gradle

Gradle is the official build system for Android Studio and a dependency manager for Android projects.

To use Worldpay CSE SDK in a project, add it as a build dependancy and import it.

  1. After you create a new project, either:

    • open your_app | build.gradle and add this to Module-level /app/build.gradle before dependancies:

      Copied!
      repositories {
          mavenCentral()
      }
    • or if you use an internal SonaType Nexus repository:

      Copied!
      repositories {
          maven { url ' }
          jcenter()
      }
  2. Add the compile dependency with the latest version of the Worldpay CSE SDK in the build.gradle file:

    Copied!
    dependencies {
    compile 'com.worldpay:cse-android-sdk:1.0.2'
    }

Alternative: Manual installation

You can instead add the library as a simple module in your project:

  1. In Android Studio, go to File > New > Import Module.

  2. Navigate to where the Worldpay CSE SDK jar file is located, select it and press Finish.

Note: You can also import the Worldpay CSE SDK library by copying it into the /app/libs/ folder of your project.

Usage

Import the WorldpayCSE package

Copied!
import com.worldpay.cse.WorldpayCSE;

Create the WorldpayCSE object

Copied!
WorldpayCSE worldpayCSE = new WorldpayCSE();

Set the public (RSA) key

The public key should be in Worldpay string format, and will be used for any future encryption calls. To set it (to identify you on our server):

Copied!
worldpayCSE.setPublicKey("1#10001#bf49edcaba456c6357e4ace484c3fba212543e78bf"+
            "72a8c2238caaa1c7ed20262956caa61d74840598d9b0707bc8"+
            "2e66f18c8b369c77ae6be0429c93323bb7511fc73d9c7f6988"+
            "72a8384370cd77c7516caa25a195d48701e3e0462d61200983"+
            "ba26cc4a20bb059d5beda09270ea6dcf15dd92084c4d5867b6"+
            "0986151717a8022e4054462ee74ab8533dda77cee227a49fda"+
            "f58eaeb95df90cb8c05ee81f58bec95339b6262633aef216f3"+
            "ae503e8be0650350c48859eef406e63d4399994b147e45aaa1"+
            "4cf9936ac6fdd7d4ec5e66b527d041750ba63a8296b3e6e774"+
            "a02ee6025c6ee66ef54c3688e4844be8951a8435e6b6e8d676"+
            "3d9ee5f16521577e159d");

Set up the cardholder data

Copied!
WPCardData cardData = new WPCardData();
cardData.setCardNumber ("4444333322221111");
cardData.setCvc ("123");
cardData.setExpiryMonth ("11");
cardData.setExpiryYear ("2020");
cardData.setCardHolderName ("John Doe");

Encrypt the cardholder data

Copied!
try {
    encryptedData = worldpayCSE.encrypt(cardData);
} catch (WPCSEInvalidCardData e) {
    //Alternatively to catching this exception, there is a convenient method
    //WorldpayCSE#validate(WPCardData) that can be used for a similar purpose
    //displayFormFieldErrors(e.getErrorCodes());
} catch (WPCSEException e)  {
    //show error message 
}

Terms of use

You can find the terms of use for Android inWorldpay Developer Terms Of Use for Android.