OPEN Android SDK lets you seamlessly integrate OPEN Payment Gateway with your Android app and start collecting payments from your customers.

Create a Payment Token

A payment token represents an order or a purchase. The first step to opening up a Layer payment page on your website or checkout page is to create a payment_token.

A payment_token can be created by referring to the create payment token API. This API should be always called from your server. You will receive payment_token as a response from the create payment token API.

Gradle Setup

In the build.gradle of the app module, include the below dependency to import the OpenPayment library in the app

dependencies
   {
       implementation 'money.open:open-payment-sdk-android:1.0.8'
                     ^
   }

Application Setup

In the Android app, make an activity where you want to implement payment integration. Here, we have created MainActivity.java

Initializing Open Payment

You can see the below code, these are minimum and mandatory calls to enable payment processing. If any of it is missed then an error will be generated.

For example, consider parameters as follows

val openPayment: OpenPayment = OpenPayment.Builder()
                   .with(requireActivity())
                   .setPaymentToken(paymentToken)
                   .setEnvironment(OpenPayment.Environment.SANDBOX)
                   .setAccessKey(accessKey)
                   .setColorPrimary(String.format("#%06x",
   ContextCompat.getColor(requireContext(),
   R.color.colorPrimaryDark) and 0xffffff))
                   .setCompanyLogo("logoUrl")
                   .build()
                   
           openPayment.setPaymentStatusListener(mListener = this)
           openPayment.startPayment()

Calls and Descriptions

MethodMandatoryDescription
with()(Y)This call takes Activity as a parameter where Payment is to be implemented.
setPaymentToken()(Y)To create the token using the Create Payment Token API.
setAccessKey()(Y)The access key is a unique key that you can generate from your Open dashboard.
setEnvironment()(Y)Following ENUM can be passed to this method.
  • OpenPayment.Environment.SANDBOX
  • OpenPayment.Environment.LIVE
setColorPrimary()The main color of the Layer will be changed to this.

Example: #f8c5c5
setCompanyLogo()The logo is changed to the image source passed.
setErrorColor()The main color of the Layer will be changed to this.

Example: #f8c5c5
build()(Y)It will build and return the OpenPayment instance.

Proceed to Payment

To start the payment, just call startPayment() method of OpenPayment and after that, the transaction will get started.

openPayment.startPayment()

Payment Callback Listeners

To register for callback events, you will have to set thePaymentStatusListener with OpenPayment as below.

openPayment.setPaymentStatusListener(mListener =
   this@MainActivity)

Description

onTransactionCompleted() - This method is invoked when a transaction is completed. It may either captured, failed, pending, and cancelled

📘

Note

If onTransactionCompleted() is invoked it doesn't means that payment is successful. It may fail but transaction is completed is the only purpose.

onError() - Integration errors.

For example, consider parameters as follows.

override fun onTransactionCompleted(transactionDetails:TransactionDetails) {
runOnUiThread {
responseText.text = "On Transaction Completed:\n" responseText.append("\nPayment Id: "
+transactionDetails.paymentId) responseText.append("\nPayment Token Id: "
   +transactionDetails.paymentTokenId)
               responseText.append("\nStatus: "
   +transactionDetails.status)
           }
} 
override fun onError(message: String) { runOnUiThread {
responseText.text = "onError: \n$message" 
 }
 }

Remove Listener

To remove listeners, you can invoke detachListener() after the transaction is completed or you haven’t to do with payment callbacks.

openPayment.detachListener()

Call the webhook URL to get the complete response of the transactions

Thus, We have successfully implemented Open Payment integration in our Android application. Thank You