📗Thawani Lamsa SDK (Android)
You can integrate the Thawani Lamsa SDK (Tap & Pay) into your Android application.
Minimum Requirement
Android devices with Build-in NFC (Near Field Communication)
Android minimum SDK 26
Get your Auth keys
Register your business with Thawani and create your branch and touchpoints. After creating a touchpoint, you can obtain an authorization key. Please note that the authorization key is the same as the touchpoint key.
Configure SDK in your app
Step 1: Add dependency resolution to your settings.gradle
:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// Add this line here
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/ThawaniMobile/Lamsa-SDK")
credentials {
username = "ThawaniMobile"
password = "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"
}
}
}
}
Step 2: Add dependency in your build.gradle
(App Level):
// Enable dataBinding
android {
...
buildFeatures {
dataBinding true
}
}
// Add Thawani lamsa SDK dependency
dependencies {
implementation("om.thawani:lamsa.sdk:0.0.22")
}
Step 3: Add Lamsa activity to your manifest.xml
<activity
android:name="om.thawani.lamsa.sdk.LamsaSDK"
android:parentActivityName=".MainActivity"
android:theme="@style/Theme.LamsaSDK">
</activity>
Step 4: (conditional) if minifyEnabled true
in your build.gradle:app
please add this line in your proguard-rules.pro
file
minifyEnabled true
in your build.gradle:app
please add this line in your proguard-rules.pro
file-keep class om.thawani.lamsa.sdk.**{*;}
Initiate the payment
Initiate the Lamsa SDK from your app
val intent = Intent(this, LamsaSDK::class.java)
val args = InitOptionsModel(
amount = 1.0,
authKey = "wjOcN7XEG7q6vlSWO15QRRRjn3JI8mimxGwANT38",
remarks = "This payment from Thawani SDK",
isProduction = false,
paymentOption = paymentOption.CARD_ACCEPT,
autoCloseInMillis = 3000 //Optional, auto close after 3 second
)
intent.putExtra("SDKInitOptions", args)
this.startActivityForResult(intent, LAMSA_REQUEST_CODE)
Note: Put your own authKey from Thawani and change isProduction to true when you go for production.
Add this code in same class you initiate Lamsa (you can put your own value).
companion object{
private const val LAMSA_REQUEST_CODE = 200
}
Here is the description of the parameters:
amount
Yes
Double
Amount to be paid
authKey
Yes
String
Auth key (Touch point)
remarks
No
String
Remarks for the payment
isProduction
Yes
Boolean
Specify whether it's for staging or production
paymentOption
No
PaymentOptions
Payment Options (Only for staging)
autoCloseInMillis
No
Integer
specify delay in milli second to auto close lamsa sdk after payment success or failed
Payment Options
PaymentOptions.CARD_ACCEPT
Card accepted
PaymentOptions.CARD_REJECT
Card rejected
PaymentOptions.THREE_D_S_ACCEPT
Card accepted (Credit Card)
PaymentOptions.THREE_D_S_REJECT
Card rejected (Credit Card)
Handling the Result
To handle the response from Lamsa SDK, you will use the PaymentResultModel
. This model is employed to deserialize and structure the response. It provides the necessary information regarding the payment result.
Here is the description of the above model attributes
success
Boolean
Whether the request success or not.
description
String
Description about payment.
paymentId
String
Identifier associated with the payment
amount
Double
The requested transaction amount
invoice
String
The payment invoice
paymentStatus
Int
Payment status
date
Date
Date of the transaction
Payment Status
1
Pending
Payment is pending
2
Success
Payment is successful
3
Failed
Payment is failed
To handle the response to the payment request, implement the onActivityResult
method in your activity as follows:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == LAMSA_REQUEST_CODE) {
// If payment success
if (resultCode == Activity.RESULT_OK) {
val result = data?.getSerializableExtra("result") as? PaymentResultModel
if (result != null) {
// Use result to get response data
// var isPaymentStatus:Boolean? = result.success?:false
} else {
// Handle unexpected error
// val error:String = "unexpected error occurred"
}
}
// If payment cancelled or failed
if (resultCode == Activity.RESULT_CANCELED) {
val result =
data?.getSerializableExtra("result") as? PaymentResultModel
if (result != null) {
// Use result to get response data
// var isPaymentStatus:Boolean? = result.success?:false
} else {
// Handle unexpected error
// val error:String = "unexpected error occurred"
}
}
}
}
Last updated