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 😎.
You can add this package to you project using the Swift Package Manager.
import KKiaPaySDK;
@ObservedObject var viewModel = KKiaPayViewModel()
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
)
}
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.
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()
}
}
Argument | Type | Required | Details |
phone | String | Yes | Valid mobile money number to debit. ex : 22967434270 |
amount | Numeric | Yes | Amount to debit from user account (XOF) |
name | String | No | Client firstname and lastname |
partnerId | String | No | Your id to find transaction |
countries | List of String | No | Set widget countries ex: ["CI"] |
paymentMethods | List of String | No | Set widget payment methods ex: ["momo","card"] |
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 | Yes | This function is called once the payment has been successfully made |
Please file issues to send feedback or report a bug. Thank you!