Retour aux SDKsGitHub
iOS SDK (Swift)
v1.0.0SDK officiel pour iOS 15+, macOS 12+, tvOS 15+, watchOS 8+
Installation
Swift Package Manager
Ajoutez la dependance dans votre Package.swift :
dependencies: [
.package(url: "https://github.com/simiz-io/simiz-ios.git", from: "1.0.0")
]Ou dans Xcode : File >Add Package Dependencies... et entrez l'URL du repository.
Configuration
import Simiz
// Configurer le client (dans AppDelegate ou App struct)
Simiz.configure(apiKey: "sk_live_xxx")
// Ou avec des options
Simiz.configure(
apiKey: "sk_live_xxx",
configuration: SimizConfiguration(
apiVersion: "2024-01",
timeout: 30
)
)Utilisation
Creer une transaction
import Simiz
func createPayment() async throws {
let transaction = try await Simiz.transactions.create(
TransactionCreateParams(
amount: 5000,
currency: .xaf,
paymentMethod: .orangeMoney,
payer: Payer(
phone: "+237690000000",
name: "John Doe",
email: "john@example.com"
),
description: t('public.docs.sdks.ios.achatSurMaBoutique'),
reference: "ORDER-123",
metadata: [
"order_id": "123",
"customer_id": "cust_456"
],
callbackUrl: "https://votre-site.com/webhooks/simiz",
returnUrl: "https://votre-site.com/payment/success"
)
)
print(transaction.id) // tx_xxx
print(transaction.status) // .pending
print(transaction.paymentUrl) // URL de paiement
}Recuperer une transaction
let transaction = try await Simiz.transactions.retrieve("tx_xxx")
if transaction.status == .completed {
print("Paiement reussi!")
}Lister les transactions
let transactions = try await Simiz.transactions.list(
TransactionListParams(
limit: 20,
status: .completed,
createdAfter: "2024-01-01"
)
)
for tx in transactions.data {
print("\(tx.id) - \(tx.amount)")
}Integration SwiftUI
import SwiftUI
import Simiz
struct CheckoutView: View {
@State private var amount: Int = 5000
@State private var phone: String = ""
@State private var isLoading = false
@State private var paymentUrl: URL?
var body: some View {
VStack(spacing: 20) {
TextField("Numero de telephone", text: $phone)
.textFieldStyle(.roundedBorder)
.keyboardType(.phonePad)
Button(action: createPayment) {
if isLoading {
ProgressView()
} else {
Text("Payer \(amount) XAF")
}
}
.buttonStyle(.borderedProminent)
.disabled(isLoading || phone.isEmpty)
}
.padding()
.sheet(item: $paymentUrl) { url in
SafariView(url: url)
}
}
func createPayment() {
isLoading = true
Task {
do {
let tx = try await Simiz.transactions.create(
TransactionCreateParams(
amount: amount,
currency: .xaf,
paymentMethod: .orangeMoney,
payer: Payer(phone: phone)
)
)
paymentUrl = URL(string: tx.paymentUrl)
} catch {
print("Erreur: \(error)")
}
isLoading = false
}
}
}Gestion des erreurs
do {
let transaction = try await Simiz.transactions.create(params)
} catch SimizError.authentication(let message) {
// Cle API invalide
print("Verifiez votre cle API: \(message)")
} catch SimizError.invalidRequest(let message, let param) {
// Parametres invalides
print("Erreur: \(message), Param: \(param ?? "")")
} catch SimizError.api(let message, let statusCode) {
// Erreur serveur
print("Erreur API (\(statusCode)): \(message)")
} catch {
print("Erreur inconnue: \(error)")
}