Hub · Blog

28

Jan

Upgrading to our new Android SDK (5.1)

In version 5.1 of our Android SDK, we wanted to introduce lots of new features, focus on improving the quality of the codebase, and make customizing the SDK to match your app’s brand easier. With this in mind, it made sense to completely rewrite the SDK from the ground up.

If you’re using an older version of the Android SDK (pre 5.1), you will need to complete an upgrade to this version by 20th October 2016 due to PCI Compliance changes that were introduced (PCI DSS 3.1).

To make the process of upgrading to version 5.1 as smooth as possible, let’s walk through the main steps required to get your app updated.

Where to find the SDK

Previously, our SDK was only available to download from the judo website to add to your project, but now it’s even easier! If using Gradle, you can simply add a dependency to your app’s build.gradle file:

dependencies {
  compile 'com.judopay:android-sdk:5.1'
}

This will make the SDK available to use straight away! If you prefer to check out the code and make changes before adding it to your app, you can check it out directly from our GitHub repo.

Initializing the SDK

The first step you must do when calling the SDK is to initialize it with your API token and secret, allowing judo to identify the account you’re using.
To setup the SDK, call ‘Judo.setup()’ from the Activity that calls the judo class, or in your ‘Application.onCreate()’ method:

Judo.setup("API_TOKEN", "API_SECRET", Judo.Environment.LIVE);

The judo class also includes methods for changing some configuration options for the SDK:
‘Judo.setAvsEnabled()’ shows address verification fields when performing a transaction.
‘Judo.setMaestroEnabled()’ configure if Maestro cards should be accepted.
‘Judo.setAmexEnabled()’ configure if American Express cards should be accepted.

**The ‘Judo’ class replaces the ‘JudoSDKManager’ found in version 4.2 of the SDK.**

Android activities

A main part of the Android SDK is the included Android ‘Activity’ classes, used to bring up a screen allowing a payment, token payment, pre-auth or cards to be registered. These activities have moved from the ‘com.judopay.android.library.activities’ package to the slightly shorter ‘com.judopay’ package:

‘com.judopay.PaymentActivity’
‘com.judopay.PreAuthActivity’
‘com.judopay.TokenPaymentActivity’ (previously PaymentTokenActivity)
‘com.judopay.TokenPreAuthActivity’ (previously PreAuthTokenActivity)
‘com.judopay.RegisterCardActivity’

Android manifest entries

If upgrading from version 4.2 of the judo SDK, any Activity entries in the AndroidManifest.xml file will need to be updated. By default the new Activity classes will be merged with your manifest with the default theme (Theme.Judo.Light.DarkActionBar) so you can delete the previous Activity references. If you want to customize our themes, this is also supported (more on this later).

Performing a payment

To perform a payment in the new judo SDK, call the ‘startActivityForResult()’ method from your activity and provide an Intent with the required Intent extra:

 Intent intent = new Intent(this, PaymentActivity.class);
 intent.putExtra(Judo.JUDO_OPTIONS, new JudoOptions.Builder()
 .setJudoId("1234567")
 .setAmount("1.99")
 .setCurrency(Currency.GBP)
 .setConsumerRef("consumerRef")
 .build());
startActivityForResult(intent, PAYMENT_REQUEST);

Performing a token payment

Performing a token payment is similar to performing a payment, you just need to provide the ‘CardToken’ received from registering the card:

 Intent intent = new Intent(this, TokenPaymentActivity.class);
 intent.putExtra(JUDO_OPTIONS, new JudoOptions.Builder()
 .setJudoId("1234567")
 .setAmount("1.99")
 .setCurrency(Currency.GBP)
 .setConsumerRef("consumerRef")
 .setCardToken(cardToken) // returned in receipt.getCardDetails() from register card
 .build());
startActivityForResult(intent, TOKEN_PAYMENT_REQUEST);

The ‘JudoOptions’ class replaces the ‘JudoSDKManager.JUDO_*’ constants in version 4.2 for providing Activity extras, though these are still provided in the ‘Judo’ class for compatibility with the previous SDK version.

Android fragments

If you prefer to use Android fragments in your app instead of calling the provided activities, these are provided and accessible through the SDK using ‘PaymentFragment’, ‘PreAuthFragment’, ‘TokenPaymentFragment’, ‘TokenPreAuthFragment’ and ‘RegisterCardFragment’.

The fragments provided work in a similar way to the activities, by using ‘JudoOptions’ object in the fragment arguments:

 Bundle args = new Bundle();
 args.putParcelable(Judo.JUDO_OPTIONS, new JudoOptions.Builder()
 .setJudoId("1234567")
 .setCurrency(Currency.GBP)
 .setAmount("1.99")
 .build());

PaymentFragment paymentFragment = new PaymentFragment();
paymentFragment.setArguments(args);

getFragmentManager()
 .beginTransaction()
 .add(R.id.my_layout, paymentFragment)
 .commit();

Theme Customization

The SDK provides base themes for the provided Activity classes. These can be customized to match your app’s appearance:
Theme.Judo: Theme with dark background and action bar
Theme.Judo.Light: Theme with light background and action bar
Theme.Judo.Light.DarkActionBar: Theme with light background and dark action bar

Depending on the styles used in your app, you should expand on the most appropriate theme to ensure a seamless user experience.

Customizing the theme

1. Create a style that extends from one of the provided base Themes, for example:

 <style name="AppTheme" parent="Theme.Judo.Light">
   <item name="colorPrimary">#3F51B5</item> // action bar colour
   <item name="colorPrimaryDark">#303F9F</item> // status bar colour
   <item name="textColorPrimary">#333333</item> // text colour
   <item name="colorControlActivated">#3F51B5</item> // form field hint colour
 </style>

2. Specify the activity in your AndroidManifest.xml file with the customized theme:

 <activity xmlns:tools="http://schemas.android.com/tools"
   android:name="com.judopay.TokenPreAuthActivity"
   android:theme="@style/AppTheme.PayButton"
   tools:replace="android:theme" />

Writing a custom UI

We understand that you might want to write a completely custom UI in your app and just use our API directly.

In older versions of the SDK we provided access to the judo REST API through the TransactionProcessingApiService and TransactionQueryApiService classes. In the new SDK these classes have been replaced by the JudoApiService, a Retrofit annotated Java interface that allows for all the judo API calls in one place. Use the ‘JudoApiServiceFactory.getInstance(context)’ method for obtaining an instance to call:

 JudoApiService apiService = JudoApiServiceFactory.getInstance(this);

PaymentTransaction transaction = new PaymentTransaction.Builder()
 .setJudoId("1234567")
 .setAmount("1.99")
 .setCurrency(Currency.GBP)
 .setCardNumber("1234123412341234")
 .setExpiryDate("12/16")
 .setCv2("123")
 .setYourConsumerReference("consumerRef")
 .build();

apiService.payment(transaction)
  .subscribeOn(Schedulers.newThread())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(new Action1<Receipt>() {
  @Override
  public void call(Receipt receipt) {
    if(receipt.isSuccess()) {
      // handle successful payment
    }
  }
});

 


About Judopay · Judopay simplifies in-app payments, enable frictionless checkouts and intelligently prevents fraud for leading companies globally. Our payments and mobile experts help guide businesses and their development partners to create best in class apps to make paying faster, easier and more secure. Founded by serial financial technology entrepreneurs in 2012, Judopay is backed by leading venture investors and supported by banking and card scheme partners to offer in-app payments that are simple, frictionless and protected.

Contact us, we'd love to hear from you

* Required. We will get back to you soon and we never share your details.