Documentation

BankPay

  1. Home
  2. Docs
  3. BankPay
  4. Overview
  5. BankPay SDK for Android (Kotlin) Documentation

BankPay SDK for Android (Kotlin) Documentation

This SDK allows you to implement BankPay payments in your Android app and is written for the Kotlin programming language. Included you will find a Fragment layout with a class file for processing intents via a WebView.

Installing the SDK

Requirements

  • Android Studio
  • Minimum Android SDK 19
  • Target SDK Version 29

Set up

In Android Studio go to File > New > New Module and choose Import .JAR/.AAR Package from the dialog to add the BankPay SDK for Android .AAR file to your project.

Next, make sure it is included in your project level settings.gradle file.

include ':bankpay_sdk_android'

Next, Implement the SDK as a dependency in your app level build.gradle file.

dependencies: {
    ...
    implementation project(':bankpay_sdk_android')
    ...
}

If your app does not already have permissions enabled for internet use, add the following to your app’s AndroidManifest.xml

<manifest>
    ...
    <uses-permission android:name="android.permission.INTERNET" />
    ...
</manifest>

Using the SDK

For Enrollments:

Incorporate your logic into a Fragment Activity(), extend it with the provided BankPayResponseListener interface, and prepare it for the overridable functions onBankPaySuccess() and onBankPayExit(), described below.

package com.your_app 
... 
import com.certegy.bankpay_sdk_android.BankPay 
import com.certegy.bankpay_sdk_android.BankPayResponseListener 
... 
class YourEnrollmentActivity : FragmentActivity(), BankPayResponseListener { 
    override fun onBankPaySuccess(result: JSONObject) { 
        ... 
    } 
    override fun onBankPayExit() { 
        ... 
    }
}

Use our provided layout fragment

In your FragmentActivity’s onCreate() function, set the content view to R.layout.fragment_bankpay_webview

override fun onCreate () {
    ...
    setContentView(R.layout.fragment_bankpay_webview)
    ...
}

Start the layout fragment

After creating an enrollment intent on your server. Provide the required params, including the returned enrollment_token as a JSON string to be sent as bundle arguments to the BankPay class.

Required JSON Parameters

  • api_version: ([String]) – The API version. Possible values are production, cce or test.
  • publishable_key: ([String]) – Your BankPay-publishableKey
  • intent_id: ([String]) – The enrollment_token returned when creating an enrollment intent
  • action: ([String]) – Intent action enrollment
 // Collect enrollment intent response data into a Json object
 val intentObject = JSONObject("""{ 
    "api_version": "production" 
    "publishable_key": "client_publishable_key", 
    "intent_id": "intent_token", 
    "action": "enrollment" 
}""").trimMargin() 

val bankpay = BankPay() 
val bankpayIntentJson = Bundle() 

bankpayIntentJson("BANKPAY_INTENT_JSON", intentObject.toString()) 
bankpay = bankpayIntentJson 

supportFragmentManager.beginTransaction() 
   .add(R.id.fragment_container, bankpayIntentJson).commit()

Get Responses from the SDK

Override these functions in your app to act on events occurring in the SDK during enrollments.

On Success

onBankPaySuccess(result: JSONObject)

This function is called by this SDK after completing the enrollment flow. At the final phase the SDK returns a result value as a JSON object ([JSONObject]) with data you can use to continue and complete your app’s enrollment flow.

Within this function you should now authorize the enrollment intent with your server to retrieve the account information.

override fun onBankPaySuccess(result: JSONObject) { 
    // Check the enrollment intent status with the returned result type. 
    if (result.has("type") && result.get("type") == "bankAccountAdded") { 
        // Authorize the enrollment intent with your server 
    } 
}
  • In addition to successful response data, this function may also return error information pertaining to the enrollment process.

On Exit

onBankPayExit()

This function is called upon exiting the SDK. Whether or not enrollment was terminated (closed by the end user, declined, or successful) should be determined in your app’s logic.

  • Upon success or failure, your app could store the necessary data and return from the activity for result. Or, simply exit and return from the activity without doing anything.
    • This function does not return any data.
override fun onBankPayExit() {
  // handle exiting the SDK and or your activity here 
}

For Transactions:

Just like for enrollments, you should incorporate your logic into a FragmentActivity() and extend it with the provided BankPayResponseListener interface and prepare for the overridable functions onBankPaySuccess and onBankPayExit, described below.

package com.your_app 
... 
import com.certegy.bankpay_sdk_android.BankPayResponseListener 
... 

class YourTransactionActivity : FragmentActivity(), BankPayResponseListener { 

    override fun onBankPaySuccess(result: JSONObject) { 
        ... 
    } 

    override fun onBankPayExit() { 
        ... 
    } 
}

Use our provided layout fragment

In your FragmentActivity’s onCreate() function, set the content view to R.layout.fragment_bankpay_webview

override fun onCreate () { 
    ...
    setContentView(R.layout.fragment_bankpay_webview) 
    ... 
}

Start the layout fragment

After creating a transaction intent on your server. Provide the required params, including the returned transaction_token as a JSON string to be sent as bundle arguments to the BankPay class.

Required JSON Parameters

  • api_version: ([String]) – The API version. Possible values are production, cce or test.
  • publishable_key: ([String]) – Your BankPay-publishableKey
  • intent_id: ([String]) – The transaction_token returned when creating a transaction intent
  • action: ([String]) – Intent action transaction
// Collect transaction intent response data into a Json object 
val intentObject = JSONObject("""{ 
        "api_version": "production" 
        "publishable_key": "client_publishable_key", 
        "intent_id": "intent_token", 
        "action": "transaction" }""").trimMargin() 

val bankpay = BankPay() 
val bankpayJson = Bundle() 

bankpayJson.putString("BANKPAY_INTENT_JSON", intentObject.toString()) 
bankpay.arguments = bankpayJson 

supportFragmentManager.beginTransaction() 
    .add(R.id.fragment_container, bankpayTransactionFlow).commit()

Get Responses from the SDK

Override these functions in your app to act on events occurring in the SDK during transactions.

On Success

onBankPaySuccess(result: JSONObject)

This function is called by this SDK after completing the transaction flow. At the final phase the SDK returns a result value as a JSON object ([JSONObject]) with data you can use to continue and complete your app’s transaction process.

  • Within this function you should now authorize the transaction intent with your server if the service fee was accepted.
override fun onBankPaySuccess(result: JSONObject) {
    // Check the transaction intent status with the returned result type. 
    if (result.has("type") && result.get("type") == "acceptedTransactionIntentServiceFee") { 
        // Authorize the transaction intent with your server 
    } 
}
  • In addition to successful response data, this function may also return error information pertaining to the enrollment process.

On Exit

onBankPayExit()

This function is called upon exiting the SDK. Whether or not transaction was terminated (closed by the end user), declined, or successful should be determined in your app’s logic.

  • Upon success or failure, your app could store the necessary data and return from the activity for result. Or, simply exit and return from the activity without doing anything.
    • This function does not return any data.
override fun onBankPayExit() { 
    // handle exiting the SDK and or your activity here 
}

Back to Top

How can we help?