A SwiftUI sample application demonstrating integration with the Gr4vy Swift SDK. This app provides a testing interface for the SDK endpoints with persistent configuration management.
- Summary
- Architecture
- App Structure
- Admin Panel
- Key Features
- Setup Instructions
- Customization
- Requirements
The app uses modern SwiftUI patterns with async/await for API calls calling the Gr4vy Swift SDK directly and @AppStorage
for persistent configuration across app sessions.
- Home Tab: Main navigation to API endpoint screens
- Admin Tab: Configuration management panel
-
Payment Options -
POST /payment-options
- Configure metadata, country, currency, amount, locale, and cart items
- Dynamic metadata key-value pairs
- Cart items with detailed product information
-
Card Details -
GET /card-details
- Test card BIN lookup and payment method validation
- Supports intent, subsequent payments, and merchant-initiated transactions
-
Payment Methods -
GET /buyers/{buyer_id}/payment-methods
- Retrieve stored payment methods for buyers
- Sorting and filtering options
- Buyer identification by ID or external identifier
-
Fields (Tokenize) -
PUT /tokenize
- Tokenize payment methods (card, click-to-pay, or stored payment method ID)
- Secure payment method storage
- Multiple payment method types supported
The Admin tab provides centralized configuration for all API calls:
- gr4vyId - Your Gr4vy merchant identifier (required)
- token - API authentication token (required)
- server - Environment selection (sandbox/production)
- timeout - Request timeout in seconds (optional)
- merchantId - Used in payment options requests
- All settings persist across app restarts using
@AppStorage
- Empty timeout field uses SDK default timeout
- Configuration is shared across all API screens
- Switch between sandbox and production environments instantly
All API calls use modern Swift concurrency:
Button("GET") {
Task {
await sendRequest()
}
}
- SDK error type handling
- Network error detection and visual messages
- HTTP status code display with detailed error responses
- Tappable error messages show full JSON error details
- Pretty-printed JSON responses
- Copy/share functionality for debugging
- Separate navigation for success and error responses
- Form data persists between app launches
- Admin settings stored securely in UserDefaults
- Complex data structures (metadata, cart items) serialized automatically
- Open the Admin tab
- Enter your
gr4vyId
and optionaltoken
- Select environment
- Optionally set custom timeout
- Navigate through the Home tab to each API screen
- Fill in required fields (marked with validation)
- Tap the action button (GET/POST/PUT) to make requests
- View responses
- Use as reference implementation for SDK integration
- Test various parameter combinations
- Debug API responses with detailed error information
- Create new view following existing patterns
- Add admin settings storage with
@AppStorage
- Implement async request function with error handling
- Add navigation link in
HomeView.swift
- All views use standard SwiftUI form patterns
- Consistent styling with
ButtonView
component - Error states handled with red background styling
- Loading states with
ProgressView
indicators
let server: Gr4vyServer = serverEnvironment == "production" ? .production : .sandbox
let timeoutInterval = TimeInterval(Double(timeout) ?? 30.0)
guard let gr4vy = try? Gr4vy(
gr4vyId: gr4vyID,
token: trimmedToken,
server: server,
timeout: timeoutInterval
) else {
errorMessage = "Failed to configure Gr4vy SDK"
return
}
- iOS 16.0+
- Xcode 16.0+
- Swift 5.7+
- Gr4vy Swift SDK