PaymentSDK is a modular and secure Swift framework designed to facilitate API-based payment transactions. It provides secure API key management, structured logging, and supports multiple asynchronous programming paradigms.
- Secure API Key Management: Stores API keys securely using Keychain.
- Flexible Asynchronous Payment Processing: Supports
async/await, completion handlers, and Combine. - Comprehensive Logging System: Logs payment process details for debugging and monitoring.
- Configurable Retry Mechanism: Ensures reliable transaction execution with customizable retry attempts.
- Unit Test Coverage: Includes mock services and structured test cases.
- Best Practices Compliance: Follows clean architecture, error handling, logging, and SOLID principles.
- REST API Interaction: Implements network requests efficiently and securely.
- Demo App Included: A sample app is provided to demonstrate SDK usage.
- iOS: Version 16.0 or later
- Xcode: Version 16.2 or later
- Swift: Version 5.9 or later
To integrate PaymentSDK into your project using Swift Package Manager:
- Open your project in Xcode.
- Navigate to
File>Add Packages. - Enter the repository URL:
https://github.com/aligungor/PaymentSDK - Select the version and add the package to your project.
Before processing payments, initialize the SDK with your API credentials:
import PaymentSDK
let payment = Payment(apiKey: "your_api_key")To process a payment request:
let config = PaymentConfig(amount: 1000, currency: "USD", retryCount: 2)
do {
let response = try await payment.make(config: config)
print("Payment successful: \(response)")
} catch {
print("Payment failed: \(error.localizedDescription)")
}payment.make(config: config) { result in
switch result {
case .success(let response):
print("Payment successful: \(response)")
case .failure(let error):
print("Payment failed: \(error.localizedDescription)")
}
}let cancellable = payment.make(config: config)
.sink(receiveCompletion: { completion in
switch completion {
case .finished:
print("Payment completed")
case .failure(let error):
print("Payment failed: \(error.localizedDescription)")
}
}, receiveValue: { response in
print("Payment response: \(response)")
})payment.clearAPIKey()For a complete example, refer to the Demo directory in the repository, which includes a sample project demonstrating the integration and usage of PaymentSDK.
- Mock services are included in
Tests/Mockfor unit testing. - Structured unit tests ensure reliable payment processing and API key handling.
- Customizable mock responses simulate different API behaviors.
PaymentSDK is continuously built using GitHub Actions. The provided workflow automates the process of building an XCFramework, which can be used in your project.
- Go to the "Actions" tab in your GitHub repository.
- Select the "Build and Release PaymentSDK XCFramework" workflow.
- Click "Run workflow" to start the build process.
- Once the build completes, download the generated
PaymentSDK.xcframework.zipfrom the workflow artifacts. - Extract the zip file and add
PaymentSDK.xcframeworkto your Xcode project.
After downloading and extracting PaymentSDK.xcframework, follow these steps to integrate it into your Xcode project:
- Drag and drop the extracted
PaymentSDK.xcframeworkinto your Xcode project's Frameworks, Libraries, and Embedded Content section. - In the General tab of your project settings, ensure that
PaymentSDK.xcframeworkis set to "Embed & Sign". - Import the SDK into your Swift files:
import PaymentSDK
let payment = Payment(apiKey: "your_api_key")Your project is now ready to use PaymentSDK! π
- Source Code: Available in a GitHub repository.
- README Documentation: Comprehensive setup instructions and usage examples.
- Demo App: A sample application demonstrating SDK integration.
For issues and feature requests, please use the GitHub Issues page.
Note: Ensure you replace placeholder values like "your_api_key" with your actual credentials and configure your project settings as needed.