# Thawani Lamsa SDK (Android)

## Minimum Requirement <a href="#minimum-requirement" id="minimum-requirement"></a>

* Android devices with **Build-in** NFC (Near Field Communication)
* Android minimum SDK 26

## Get your Auth keys

Register your business with [Thawani](https://merchant.thawani.om) 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`:**

{% tabs %}
{% tab title="settings.gradle" %}

```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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"
            }
        }
    }
}
```

{% endtab %}
{% endtabs %}

**Step 2: Add dependency in your `build.gradle` (App Level):**

```gradle
// Enable dataBinding
android {
    ...
    buildFeatures {
        dataBinding true
    }
}

// Add Thawani lamsa SDK dependency
dependencies {
    implementation("om.thawani:lamsa.sdk:0.0.31")
}
```

**Step 3: Add Lamsa activity to your `manifest.xml`**

```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

```kotlin
-keep class om.thawani.lamsa.sdk.**{*;}
```

## Initiate the payment

Initiate the Lamsa SDK from your app

```kotlin
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](https://merchant.thawani.om/) 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).

```kotlin
companion object{
    private const val LAMSA_REQUEST_CODE = 200
}
```

Here is the description of the parameters:

<table><thead><tr><th width="238">Name</th><th width="105">Required</th><th width="163">Type</th><th>Description</th></tr></thead><tbody><tr><td>amount</td><td>Yes</td><td>Double</td><td>Amount to be paid</td></tr><tr><td>authKey</td><td>Yes</td><td>String</td><td>Auth key (Touch point)</td></tr><tr><td>remarks</td><td>No</td><td>String</td><td>Remarks for the payment</td></tr><tr><td>isProduction</td><td>Yes</td><td>Boolean</td><td>Specify whether it's for staging or production</td></tr><tr><td>paymentOption</td><td>No</td><td>PaymentOptions</td><td>Payment Options (Only for staging)</td></tr><tr><td>autoCloseInMillis</td><td>No</td><td>Integer</td><td>specify delay in milli second to auto close lamsa sdk after payment success or failed</td></tr></tbody></table>

#### Payment Options

<table><thead><tr><th width="335.3333333333333">Name</th><th>Description</th></tr></thead><tbody><tr><td>PaymentOptions.CARD_ACCEPT</td><td>Card accepted</td></tr><tr><td>PaymentOptions.CARD_REJECT</td><td>Card rejected</td></tr><tr><td>PaymentOptions.THREE_D_S_ACCEPT</td><td>Card accepted (Credit Card)</td></tr><tr><td>PaymentOptions.THREE_D_S_REJECT</td><td>Card rejected (Credit Card)</td></tr></tbody></table>

## 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&#x20;

| Name          | Type    | Description                            |
| ------------- | ------- | -------------------------------------- |
| 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**&#x20;

| Payment Status Code | Status  | Description           |
| ------------------- | ------- | --------------------- |
| 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:

```kotlin
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"
            }
        }
    }
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://thawani.gitbook.io/lamsa/thawani-lamsa-sdk-android.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
