The Klasha Android SDK Supports 5 payments methods out of the box, they are same as that supported by the web platform. They are
- Card Payment
- Bank Transfer
- Mobile Money
- MPESA
- Klasha wallet
- Add https://jitpack.io to settings.gradle file
dependencyResolutionManagement {
repositories {
//....
//....
maven { url "https://jitpack.io" }
}
}
- Add the latest version of the library to the dependency section of your app
dependencies {
//...
implementation 'com.github.klasha-apps:klasha-android:v1.0.2'
//...
}
To start using the SDK you would need your x-auth-token.
KlashaSDK
.initialize(
WeakReference(activity),
KLASHA_AUTH_TOKEN,
Country.NIGERIA, //Customer's country
Currency.USD, //Business currency
false, //For Dev testing
)val card = Card(
cardNumber,
exMonth,
exYear,
cvv,
name
)
val charge = Charge(
amount,
email,
name,
card
)
KlashaSDK.chargeCard(charge, object : KlashaSDK.TransactionCallback {
override fun transactionInitiated(transactionReference: String) {
// Implementation when transaction is initiated
}
override fun success(ctx: Activity, transactionReference: String) {
// Implementation when transaction is successful
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
override fun error(ctx: Activity, message: String) {
// Implementation when transaction fails
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
})val charge = Charge(
amount,
email,
name,
null,
)
KlashaSDK.bankTransfer(charge, object : KlashaSDK.BankTransferTransactionCallback{
override fun transactionInitiated(transactionReference: String) {
// Implementation when transaction is initiated
}
override fun success(ctx: Activity, bankTransferResponse: BankTransferResp) {
// Implementation when transaction is successful
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
override fun error(ctx: Activity, message: String) {
// Implementation when transaction fails
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
})
val charge = Charge(
amount,
email,
name,
null,
)
KlashaSDK.wallet(charge, object : KlashaSDK.TransactionCallback {
override fun transactionInitiated(transactionReference: String) {
// Implementation when transaction is initiated
}
override fun success(ctx: Activity, transactionReference: String) {
// Implementation when transaction is successful
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
override fun error(ctx: Activity, message: String) {
// Implementation when transaction fails
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
})val mobileMoney = MobileMoney(
voucher,
Network.MTN
)
val charge = Charge(
amount,
email,
name,
null,
mobileMoney
)
KlashaSDK.mobileMoney(charge, object : KlashaSDK.TransactionCallback{
override fun transactionInitiated(transactionReference: String) {
// Implementation when transaction is initiated
}
override fun error(ctx: Activity, message: String) {
// Implementation when transaction fails
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
override fun success(ctx: Activity, transactionReference: String) {
// Implementation when transaction is successful
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
})
val charge = Charge(
amount,
email,
name,
null,
phone
)
KlashaSDK.mpesa(charge, object : KlashaSDK.TransactionCallback{
override fun transactionInitiated(transactionReference: String) {
// Implementation when transaction is initiated
}
override fun error(ctx: Activity, message: String) {
// Implementation when transaction fails
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
override fun success(ctx: Activity, transactionReference: String) {
// Implementation when transaction is successful
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
})
val charge = Charge(
amount,
email,
name,
null,
null,
phone,
accountBank // bank code
)
KlashaSDK.ussd(charge, object : KlashaSDK.USSDCallback{
override fun transactionInitiated(transactionReference: String) {
// Implementation when transaction is initiated
}
override fun success(ctx: Activity, ussdResponse: USSDResponse) {
// Implementation when transaction is successful
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
override fun error(ctx: Activity, message: String) {
// Implementation when transaction fails
ctx.runOnUiThread {
// UI code goes here
}
// Non UI code can be here
}
})
KlashaSDK.getBankCodes(object : KlashaSDK.BankCodeCallback{
override fun transactionInitiated(transactionReference: String) {
// Implementation
}
override fun success(
ctx: Activity,
bankTransferResponse: ArrayList<BankCodeResponse>
) {
// Implementation
}
override fun error(ctx: Activity, message: String) {
// Implementation
}
})To make it easier to handle errors in a custom way, there are some error codes included below
- NO_INTERNET
- INVALID_CARD_PIN
- INVALID_OTP
- INVALID_CREDENTIALS
- TRANSACTION_NOT_SUPPORTED
- UNAUTHORISED
- SERVER_ERROR
- BAD_REQUEST
- BAD_EXCHANGE_REQUEST
- LIMITED_CONNECTIVITY
- SDK_NOT_INITIALISED
- ZERO_AMOUNT
- INVALID_WALLET_LOGIN