Skip to content

Latest commit

 

History

History
145 lines (117 loc) · 5.23 KB

README.md

File metadata and controls

145 lines (117 loc) · 5.23 KB

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: "22997000000",
            publicAPIKey: "xxxxxxxxxxxxxxxxxxx",
            partnerId: "AxXxXXxId",
            countries: ["BJ"],
            paymentMethods: ["momo","card"],
            data: "Hello world",
            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
        @State var text = "Pay Now"
        
        //Initialise the Kkiapay Instance
        private var kkiaPay: KKiaPay{
            KKiaPay(amount: 3000,
                    phone: "22997000000",
                    publicAPIKey: "xxxxxxxxxxxxxxxxxxx",
                    partnerId: "AxXxXXxId",
                    countries: ["BJ"],
                    paymentMethods: ["momo","card"],
                    data: "Hello world",
                    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(self.text)
            }
            .sheet(isPresented: $showWebView) {
                
                //Get the transaction data back 
                kkiaPay.onReceive(self.viewModel.paymentData.receive(on: RunLoop.main)){paymentData in
                    
                    if(paymentData.isSuccessful){
                        
                        self.text = "PAYMENT WAS SUCCESSFUL \n\nThe amount of the transaction is \(paymentData.amount) Fcfa with id \(paymentData.transactionId)"
                    
                        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

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
countriesList of StringNoSet widget countries ex: ["CI"]
paymentMethodsList of StringNoSet widget payment methods ex: ["momo","card"]
themeStringNo the hexadecimal code of the color you want to give to your widget
apikeyStringYespublic api key
sandboxBooleanNoThe true value of this attribute allows you to switch to test mode
successCallbackFunctionYesThis 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!