Waffy iOS Payment SDK
iOS SDK for integrating Waffy payment services into your iOS applications. Supports both UIKit and SwiftUI with comprehensive payment handling and callbacks.
Key Features
Support for both UIKit and SwiftUI frameworks
Handles payment configuration with user tokens
Comprehensive payment result and error handling
Installation
Install the Waffy iOS SDK using Swift Package Manager
Swift Package Manager
Add the package dependency to your Package.swift:
dependencies: [
.package(url: "https://github.com/WaffyApp/waffy-sdk-ios")
]UIKit Integration
Integrate Waffy payments in UIKit applications
Initialize the PaymentView with your payment configuration and callbacks:
let config = PaymentConfig(paymentURL: paymentURL, userToken: "user_token_123")
let paymentVC = PaymentView(
paymentConfig: config,
onPaymentResult: { result in
switch result {
case .success:
print("Payment successful!")
case .cancelled:
print("Payment cancelled")
case .failed:
print("Payment failed")
case .pending:
print("Payment pending")
}
},
onPaymentError: { error in
print("Payment error: \(error)")
}
)
present(paymentVC, animated: true)SwiftUI Integration
Integrate Waffy payments in SwiftUI applications
Use the PaymentViewSwiftUI component within your SwiftUI views:
struct ContentView: View {
@State private var showPayment = false
var body: some View {
Button("Pay With Waffy") {
showPayment = true
}
.sheet(isPresented: $showPayment) {
PaymentViewSwiftUI(
paymentConfig: PaymentConfig(
paymentURL: URL(string: "https://payment.example.com")!,
userToken: "user_token_123"
),
onPaymentResult: { result in
print("Payment result: \(result)")
showPayment = false
},
onPaymentError: { error in
print("Payment error: \(error)")
showPayment = false
}
)
}
}
}Payment Configuration
Configure payment parameters for your integration
The PaymentConfig object contains all necessary payment information:
struct PaymentConfig {
let paymentURL: URL // Payment URL from backend
let userToken: String // User authentication token
}Payment Results & Callbacks
Handle various payment states and outcomes
Payment Result States
The SDK provides four distinct payment result states:
Payment completed successfully
User cancelled the payment process
Payment failed due to an error
Payment is pending completion
Error Handling
Implement comprehensive error handling in your payment flow:
onPaymentError: { error in
// Display error message to user
showAlert(
title: "Payment Error",
message: error.localizedDescription
)
// Log for debugging
debugPrint("Payment error:", error)
// Handle based on error type
if let paymentError = error as? PaymentError {
switch paymentError {
case .networkError:
// Handle network issues
showRetryOption()
case .configurationError:
// Handle invalid configuration
showContactSupportMessage()
case .authenticationError:
// Handle token issues
refreshUserToken()
default:
// Handle other errors
showGenericErrorMessage()
}
}
}Complete Integration Guide
Step-by-step payment integration tutorial
API Reference
Detailed API documentation and parameters