Android

Integrating with Judopay

Prerequisites

  • You have set up your Judopay account.

  • You have the latest version of the Android SDK.

For Mobile apps, it is recommended not to make a transaction from the app, as the Token and Secret could become compromised.
Use the server to make the transaction. Create a Register Card app and enable the Register Card Transactions permission.

 

Integration Requirements:

  • Android Studio 2.2 or higher

  • Android SDK Build Tools 25.0.2

  • Your app targets Android Kitkat 4.4 API 19 or higher

  • Latest Android Support Repository

  • Latest Android Support Library

  • Install using Android Studio

  • No need to clone a repository

The Mobile SDK is available for Android as a Gradle dependency. 

 

To add Judopay as a dependency to your current project:

  1. Navigate to your build.gradle file

  2. In the dependencies section add the latest com.judopay:judokit-android:{version}

    For the latest version, see Android Releases.

An example of how your build.gradle might look:
android {
    ...
}

dependencies {
    ...
    implementation 'com.judopay:judokit-android:2.1.1'
    ...
}

 

  1. Ensure the Maven Central Repository has been added:

allprojects {
    repositories {
        mavenCentral()
    }
}

See Judopay's JudoKit for Android on Github.

 

Initialising the Judo Builder

The Judo builder is at the heart of the Android Mobile SDK. This class is responsible for:

  • Setting all the required parameters

  • Customising the payment flow

 

  1. Import some of the classes and properties from the com.judopay.judokit.android package as detailed below:

import com.judopay.judokit.android.Judo 
import com.judopay.judokit.android.model.Amount 
import com.judopay.judokit.android.model.Reference
import com.judopay.judokit.android.model.PaymentWidgetType 
import com.judopay.judokit.android.PAYMENT_CANCELLED 
import com.judopay.judokit.android.PAYMENT_ERROR
import com.judopay.judokit.android.PAYMENT_SUCCESS
import com.judopay.judokit.androidJudoActivity
  • Judo is the class used to build the payment flow.

  • Amount and Reference: Classes used to set the amount and reference properties. 

  • PaymentWidgetType allows for multiple payment types:

    • Card

    • Google Pay™

    • Apple Pay™

    • PayByBankApp

    • iDeal

      to be selected and displayed.

  • Identifies the transaction result:

    • PAYMENT_SUCCESS

    • PAYMENT_ERROR

    • PAYMENT_CANCELLED

  • android.JudoActivity is the method parameter when calling startActivityForResult.

 

Building the Judo Object

To set up the transaction amount:

  1. In the Amount object provide the Amount value and Currency type:

val amount = Amount.Builder()
     .setAmount("150.50")
     .setCurrency(Currency.GBP)
     .build()

 

To set up the transaction reference:

  1. In the Reference object provide the ConsumerReference string:

val reference = Reference.Builder()                 
    .setConsumerReference('my-consumer-reference')                 
    .build()

 

To set up the Judo configuration:

  1. Set the following required  parameters:

    1. The token and secret values, OR Create the authorisation object:

    2. Set the SDK to run in sandbox mode

  1. Set the following objects:

    1. Judo ID

    2. Authorisation object (if using this method)

JudoId format = 100100100

  1. Amount

  2. Reference

 

  1. Create the authorisation object:

val authorization = PaymentSessionAuthorization.Builder()
       .setPaymentSession(paymentSession)
       .setApiToken(token)
       .build()
  1. Set the authorisation object when invoking Judo builder:

val builder = Judo.Builder(widgetType)
            .setAuthorization(authorization)

 

Field

Description

CARD_PAYMENT

Card Payment

PRE_AUTH

Card PreAuth

REGISTER_CARD

Register Card

CREATE_CARD_TOKEN

Save Card

CHECK_CARD

Check Card

PaymentWidgetType.PAYMENT_METHODS

Payment Method Selection

PaymentWidgetType.PRE_AUTH_PAYMENT_METHODS

PreAuth Method Selection

PaymentWidgetType.GOOGLE_PAY

Google Pay (Payment)

PaymentWidgetType.PRE_AUTH_GOOGLE_PAY

Google Pay (PreAuth)

SERVER_SERVER_PAYMENT_METHODS

Server to Server

PAY_BY_BANK_APP

PayByBankApp

The Judo object is now configured and you are ready to make a transaction.

 

Making a Transaction

Each transaction operation is represented as an Activity

To make a transaction:

  1. Create an Intent to pass the JudoActivity class

  2. Add the Judo object to the Intent:

    1. Call putExtra

    2. Assign it to the JUDO_OPTIONS key

The Judo object holds all the payment configurations previously set up.

  1. Pass the Intent and a request code to allow Judopay to handle the onActivityResult and the transaction response:

val intent = Intent(this, JudoActivity::class.java);
intent.putExtra(Judo.JUDO_OPTIONS, judo);
startActivityForResult(intent, PAYMENT_REQUEST_CODE);

 

  1. Implement the onActivityResult method and handle the transaction response:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    if (requestCode == PAYMENT_REQUEST_CODE) {
        when (resultCode) {

            PAYMENT_CANCELLED -> toast("User cancelled the payment.")

            PAYMENT_SUCCESS -> {
                val receipt = data?.getParcelableExtra<Receipt>(JUDO_RECEIPT)
                // Handle response
            }

            PAYMENT_ERROR -> {
                val error = data?.getParcelableExtra<JudoError>(JUDO_ERROR)
                // Handle error
            }
        }
    }
}

 

Check the request code from the onActivityResult and see if it matches with the PAYMENT_REQUEST_CODE. If it does, the result is called from the JudoActivity.

This means the imported response codes can be used to check the following possible response type and handle each case respectively:

  • success

  • cancel

  • error

 

Android Server to Server Transactions

To set a server-to-server transaction:

  1. On the Judo builder set the PaymentWidgetType to:

val judo = Judo.Builder(PaymentWidgetType.SERVER_TO_SERVER_PAYMENT_METHODS)
     .setApiToken("my-token")
     .setApiSecret("my-secret")
     .setIsSandboxed(true)
     .setJudoId("my-judo-id")
     .setAmount(amount)
     .setReference(reference)
            .build()

 

Token Payments

If you are building your own card wallet, and not using a UI you can make a preauth or payment using a stored card token.

 

Steps:

  1. Use the TokenPayment or TokenPreAuth endpoints

  2. Create a function

  3. Create the Card Token and Secret

  4. Send a Json Request

  5. Handle the Response

 

Billing Address | primary account details | CV2 are

optional
fields.

yourConsumerReference | yourPaymentReference | amount | currency | judo ID are

mandatory
fields.

 

To make a token payment or preauth token payment:

  1. Create the api service via JudoApiServiceFactory:

    val service = JudoApiServiceFactory.createApiService(this, judo)

  1. Call the tokenPayment or preAuthTokenPayment

    This is a TokenRequest object that requires the card token and optional security code:

    service.tokenPayment(judo.toTokenRequest(cardToken, "452"))
    service.preAuthTokenPayment(judo.toTokenRequest(cardToken, "452"))

  2. Handle the callback:

// Make a token payment API call via JudoApiService
service.tokenPayment(getJudo(judo).toTokenPayment(cardToken, "452"))
    .enqueue(object: Callback<JudoApiCallResult<Receipt>> {
        // Handle failure response
        override fun onFailure(call: Call<JudoApiCallResult<Receipt>>, t: Throwable) {
            TODO("Not yet implemented")
        }
        // Handle successful response
        override fun onResponse(
            call: Call<JudoApiCallResult<Receipt>>,
            response: Response<JudoApiCallResult<Receipt>>
        ) {
            when (val apiResult = response.body()) {
                is JudoApiCallResult.Success -> {
                    val receipt = apiResult.data
                    // Check if 3DS authentication is required
                    if (receipt != null && receipt.is3dSecureRequired) {
                        // Callback that handles 3DS response from SDK
                        val callback = object : ThreeDSOneCompletionCallback {
                            // Handle 3DS successful authentication
                            override fun onSuccess(success: JudoPaymentResult) {
                                setResult(success.code, success.toIntent())
                                finish()
                            }
                            // Handle 3DS unsuccessful authentication
                            override fun onFailure(error: JudoPaymentResult) {
                                setResult(error.code, error.toIntent())
                                finish()
                            }
                        }
                        // Fragment that handles 3DS webview logic
                        val fragment = ThreeDSOneCardVerificationDialogFragment(
                            service,
                            receipt.toCardVerificationModel(),
                            callback
                        )
                        fragment.show(
                            supportFragmentManager,
                            THREE_DS_ONE_DIALOG_FRAGMENT_TAG
                        )
                    } else {
                        // If 3DS authentication not required, handle the result
                        val result = apiResult.toJudoPaymentResult(resources)
                        setResult(result.code, result.toIntent())
                        finish()
                    }
                }
                is JudoApiCallResult.Failure -> {
                    val result = apiResult.toJudoPaymentResult(resources)
                    setResult(result.code, result.toIntent())
                    finish()
                }
            }
        }
    })

 

Customising your Integration

You can customise the payment experience for the consumer by configuring the following UI behaviour properties in the UiConfiguration object:

 

Adding Payment Methods

 

Testing Android Mobile Transactions

To test Android transactions in the sandbox environment:

  1. Add the sandbox token and secret to your app’s main Activity class

  2. Ensure the SDK is configured for the sandbox environment

  3. Use the Test Cards provided.

Ensure you are using a consumerReference for each request.

 

Enable Google Pay™ on your Mobile App

 

You will need to have your app approved by Google prior to using Google Pay™ in production.

 

  1. Ensure you have tested Google Pay™ on your mobile app in the sandbox environment.

    See, Testing Android Mobile Transactions.

  2. Ensure your Android Application Package is enabled for sandbox testing.

    This is to permit the Google Pay™ Support Team to run their review tests.

  3. Send your Android Application Package to the Google Pay™ Support Team so they can review your app and assist you with any of the Terms and Conditions that need to be agreed.

  4. The Google Pay™ Support Team will enable your app with production access to Google Pay™, once their review has been successfully completed.

 

You will then be able to accept Google Pay™ transactions from your mobile app.