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.
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:"[email protected]",
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 KKiaPayStringLes 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 testLa fonction de callback appelée uniquement lorsque le paiement est effectué avec succès
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
name
String
The first and last name of the initiator of the payment
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:"[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()
}
}
Last updated
Was this helpful?