SDK Swift for iOS

The KKiaPay SDK for Swift is designed to make the integration of our plugin into your mobile application as easy as possible. To set it up you will need to create an account on kkiapay.me platform and follow the process here describes :

  • Add the KKiaPay Swift SDK to your application

You can add the KKiaPay Swift SDK to your project using the Swift package manager.

Practical guide for installing a package with Swift : Installing a package.

  • Import the package KKiaPay

 import KKiaPaySDK;
  • Create a view model to use later

@ObservedObject var viewModel = KKiaPayViewModel()
  • Initialise the KKiaPay Instance

 private var kkiaPay: KKiaPay{
    KKiaPay(amount: "3000",
            phone: "22997000000",
            data: "Hello world",
            publicAPIKey: "xxxxxxxxxxxxxxxxxxx",
            sandbox: true,//set this to false in production
            theme: "#4E6BFC",
            name: "John Doe",
            email:"user@email.com",
            callback: "https://redirect.kkiapay.com",
            viewModel:viewModel
    )
}

ParamètresTypeDescriptionLe montant à payer en FCFAStringUn numéro mobile money valideLa donnée ou information liée à une transaction et interprétable par votre systèmeStringLa clé publique liée à votre compte KKiaPay​StringLes nom et prénoms de l’initiateur du paiementStringL’adresse mail de l’initiateur du paiementVous permet de basculer de l'environnement de test à l'environnement de production. La valeur true de cet attribut signifie que vous êtes en environnement de test​La fonction de callback appelée uniquement lorsque le paiement est effectué avec succès

AttributeTypeDescription

amount

Numeric

The amount to be paid (in XOF)

phone

String

A valid money mobile number (MTN or MOOV) Ex: 22997000000 Ex: 22995000000

data

String

The data or information related to a transaction and interpretable by your system

publicAPIKey

String

The public key linked to your KKiaPay account

name

String

The first and last name of the initiator of the payment

email

String

The email address of the initiator of the payment

sandbox

Boolean

Allows you to switch from the test environment to the production environment. The value true for this attribute means that you are in a test environment

callback

Function

The callback function called only when the payment was successful

Important !

To avoid fraud, perform the server-side verification of the transaction operation. Learn more about the Admin SDKs (Server-Side).

You can subscribe to payment transaction events with the onReceive function. To be notified of the successful status of a payment transaction, you can proceed as follows :

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")
    }
}

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:"user@email.com",
                    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()
    }
}

For more informations on the SDK please follow the link below : KKiaPay Swift SDK.

Last updated