Skip to content

kkiapay/android-sdk

Repository files navigation

Kkiapay Android Sdk

Build Status

Kkiapay is a developer friendly solution that allows you to accept mobile money and credit card payments in your application or website.

Before using this SDK, make sure you have an active Merchant Account on Kkiapay, otherwise create your account here, it's free of charge. 😎

Installation

Android Studio ( or Gradle )

To add kkiapay in your android app:

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

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

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

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

Usage

Please refer to KkiaPay Official Docs for updated docs

Get your API Key on kkiapay Dashboard at Developer section and initialize the Sdk in your Application Class

Initiate the API

In the onCreate method of your Application class

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

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

ArgumentTypeRequiredDetails
phoneStringYesValid mobile money number to debit. ex : 22967434270
amountNumericYesAmount to debit from user account (XOF)
nameStringNoClient firstname and lastname
partnerIdStringNoYour id to find transaction
paymentMethodsList of StringNoSet widget payment methods ex: ["momo","card"]
api_keyStringYespublic api key
sandboxBooleanNoThe true value of this attribute allows you to switch to test mode
emailStringNoClient email
reasonStringNoReason of transaction

Testimony ❤️

GoMedical MTN MOMO SHOP