KKiaPay Swift SDK for iOS

KKiapay is 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 a right Merchant Account on KKiapay, otherwise go and create your account is free and without pain ?.

Usage

Add the KKiaPay package to your project

You can add this package to you project using the Swift Package Manager.

Import the KKiaPay module
import KKiaPaySDK;
Create a view model instance to use later
@ObservedObject var viewModel = KKiaPayViewModel()
Initialise the Kkiapay Instance

private var kkiaPay: KKiaPay{
    KKiaPay(amount: "3000",
            phone: "97000000",
            data: "Hello world",
            publicAPIKey: "xxxxxxxxxxxxxxxxxxx",
            sandbox: true,//set this to false in production
            theme: "#4E6BFC",
            name: "John Doe",
            email:"[email protected]",
            callback: "https://redirect.kkiapay.com",
            viewModel:viewModel
    )
}
Get the transaction data back

Once the payment is successful, the KKiaPayViewModel sends a KKiaPayTransactionData to the calling view via the onReceive callback.

kkiaPay.onReceive(self.viewModel.paymentData.receive(on: RunLoop.main)){paymentData in
    
    if(paymentData.isSuccessful){
        print("The amount of the transaction is " + paymentData.amount+" with id "+paymentData.transactionId)
        showWebView = false
    }else{
        print("The payment was not successful")
    }
}

The onReceive function of the kkiaPay instance listens to the state of the paymentData and exposes it.

Example

import SwiftUI
import KKiaPaySDK

struct ContentView: View {
        //Create a view model instance to use later
        @ObservedObject var viewModel = KKiaPayViewModel()
        @State private var showWebView = false
        
        //Initialise the Kkiapay Instance
        private var kkiaPay: KKiaPay{
            KKiaPay(amount: "3000",
                    phone: "97000000",
                    data: "Hello world",
                    publicAPIKey: "xxxxxxxxxxxxxxxxxxx",
                    sandbox: true,//set this to false in production
                    theme: "#4E6BFC",
                    name: "John Doe",
                    email:"[email protected]",
                    callback: "https://redirect.kkiapay.com",
                    viewModel:viewModel
            )
        }
        
        var body: some View {
            Button {
                showWebView.toggle()
            } label: {
                Text("Pay")
            }
            .sheet(isPresented: $showWebView) {
                
                //Get the transaction data back 
                kkiaPay.onReceive(self.viewModel.paymentData.receive(on: RunLoop.main)){paymentData in
                    
                    if(paymentData.isSuccessful){
                        print("The amount of the transaction is " + paymentData.amount+" with id "+paymentData.transactionId)
                        showWebView = false
                    }else{
                        print("The payment was not successful")
                    }
                }
            }
        }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Reference

Argument Type Required Details
phone String Yes Valid mobile money number to debit. ex : 22997000000
amount Numeric Yes Amount to debit from user account (XOF)
name String No Client firstname and lastname
email String No Client email address
theme String No the hexadecimal code of the color you want to give to your widget
apikey String Yes public api key
sandbox Boolean No The true value of this attribute allows you to switch to test mode
successCallback Function No This function is called once the payment has been successfully made

Issues and feedback

Please file issues to send feedback or report a bug. Thank you!

GitHub

View Github