# Android SDK

### Installation

1. Add the following line in your root `settings.gradle` file inside `repositories` of `dependencyResolutionManagement` section

```gradle
maven { url 'https://jitpack.io' }
```

2. Add the following line in your app's `build.gradle` file inside `dependencies` section

```gradle
implementation 'com.github.kkiapay:android-sdk:<latestVersion>'
```

### Usage&#x20;

Get your API Key on [kkiapay Dashboard at Developer section](https://app.kkiapay.me/dashboard/developers/keys) and initialize the Sdk in your Application Class

#### Initiate the API

In the onCreate method of your Application class :

```javascript
import co.opensi.kkiapay.uikit.Kkiapay
import co.opensi.kkiapay.uikit.SdkConfig

Kkiapay.init(applicationContext,
    "<kkiapay-api-key>",
    SdkConfig(themeColor = R.color.colorPrimary,
        /* set enableSandbox = false in case you are using live API Keys */
        enableSandbox = true )
)
```

### Example

```gradle
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import co.opensi.kkiapay.uikit.Kkiapay
```

```gradle
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    override fun onStart() {
        super.onStart()

        // Setup listener for payment status
        Kkiapay.get().setListener { status, transactionId ->
            //The following code will be run when user will end the payment
            Toast.makeText(
                this@MainActivity,
                "Transaction: ${status.name} -> $transactionId",
                Toast.LENGTH_LONG
            ).show()
        }
    }

    override fun onResume() {
        super.onResume()
        val testButtonWithKkiapay = findViewById<Button>(R.id.test_button_with_kkiapay)
        testButtonWithKkiapay.setOnClickListener {
            // start the payment process
            // This will display a kkiapay payment dialog to user
            Kkiapay.get().requestPayment(
                this,
                1,
                reason = "Payment of awesome service",
                api_key = "<kkiapay-api-key>",
                sandbox = false,
                name = "Johna DOE",
                partnerId = "AxXxxXXid",
                phone = "22961877882",
                email = "email@mail.com",
                paymentMethods = listOf("momo", "card", "direct_debit"),
            )
        }
    }

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

}
```

### Reference

<table data-header-hidden><thead><tr><th width="236">Attribut</th><th width="138">Type</th><th width="94">Requis</th><th>Description</th></tr></thead><tbody><tr><td>api_key</td><td>String</td><td>Yes</td><td>public api key</td></tr><tr><td>amount</td><td>Number</td><td>Yes</td><td>Amount to debit from user account (XOF)</td></tr><tr><td>phone</td><td>String</td><td>Yes</td><td>Valid mobile money number to debit. ex : 22967434270</td></tr><tr><td>name</td><td>String</td><td>No</td><td>Client firstname and lastname</td></tr><tr><td>email</td><td>String</td><td>No</td><td>Client email</td></tr><tr><td>partnerId</td><td>String</td><td>No</td><td>Your id to find transaction</td></tr><tr><td>paymentMethods</td><td>Array of string</td><td>No</td><td>Set widget payment methods ex: ["momo","card"]</td></tr><tr><td>sandbox</td><td>Boolean</td><td>No</td><td>The <em><strong>true</strong></em> value of this attribute allows you to switch to test modet</td></tr><tr><td>reason</td><td>String</td><td>No</td><td>Reason of transaction</td></tr></tbody></table>


---

# 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://docs.kkiapay.me/v1/en-1.0.0/plugin-et-sdk/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.
