SwiftUI SDK for displaying Trusted Shops trust widgets and handling buyer protection checkout.
- Requirements
- Installation
- Quick Start
- Trustbadge
- Checkout Integration
- Configuration
- API Reference
- License
- iOS 17+
- Xcode with Swift 6.2 toolchain
- Swift Package Manager
- SwiftUI
In Xcode, go to File > Add Package Dependencies and enter:
https://github.com/trustedshops-public/ios-sdk
Or add it directly to your Package.swift:
dependencies: [
.package(url: "https://github.com/trustedshops-public/ios-sdk", from: "1.1.0")
]Then add "trustedshops_ios_sdk" to your target's dependencies:
.target(
name: "YourApp",
dependencies: ["trustedshops_ios_sdk"]
)Call start(configs:) once at app launch, for example in your App.init():
import trustedshops_ios_sdk
@main
struct MyApp: App {
init() {
TrustedShopsSDK.start(
configs: TrustedShopsConfigs(
defaultMarket: .DEU,
integrationIds: [.DEU: "your-integration-id"]
)
)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}Place a TrustbadgeView in any SwiftUI view:
import trustedshops_ios_sdk
struct ContentView: View {
var body: some View {
TrustbadgeView(type: .horizontal)
}
}The Trustbadge supports two layouts:
// Compact horizontal banner
TrustbadgeView(type: .horizontal)
// Larger card layout with more detail
TrustbadgeView(type: .card)TrustbadgeView supports standard SwiftUI modifiers for layout customization:
TrustbadgeView(type: .horizontal)
.padding(16)
.frame(maxWidth: .infinity)Construct an OrderData value with the order details. Only shopOrderId is required; every other field is optional:
import trustedshops_ios_sdk
let orderData = OrderData(
email: "buyer@example.com",
shopOrderId: "ORDER-123",
amount: 59.99,
currency: .EUR,
paymentType: "CREDIT_CARD",
estimatedDeliveryDate: "2026-04-01",
products: [
Product(name: "Wireless Headphones", sku: "WH-001")
]
)Call initiateCheckout to start the buyer protection flow. The SDK must be initialized first. This is an async method that must be called from an async context:
await TrustedShopsSDK.initiateCheckout(orderData: orderData)Example in a button action:
Button("Secure Purchase") {
Task {
await TrustedShopsSDK.initiateCheckout(orderData: orderData)
}
}Note: checkout relies on the shop's Trustbadge data being loaded first. Make sure a
TrustbadgeViewhas been shown (or otherwise given the SDK a chance to load) before callinginitiateCheckout.
CHF, EUR, GBP, PLN, NOK, SEK, DKK, RON, CZK
All configuration is passed to start(configs:) via a TrustedShopsConfigs value.
For apps operating in multiple markets, provide an integrationIds map keyed by TargetMarket. The SDK automatically resolves the correct integration ID based on the device's region:
TrustedShopsSDK.start(
configs: TrustedShopsConfigs(
defaultMarket: .DEU,
integrationIds: [
.DEU: "integration-id-de",
.AUT: "integration-id-at",
.GBR: "integration-id-gb",
]
)
)The resolution order is:
- Exact match for the device's region (e.g.
DE→.DEU) .EUOfallback (if present in the map)defaultMarket, otherwise the first entry in the map
To manually switch the active market at runtime (instance method — call via getInstance()):
// Override to a specific market
TrustedShopsSDK.getInstance().setTargetMarket(.AUT)
// Revert to automatic system locale resolution
TrustedShopsSDK.getInstance().setTargetMarket(nil)TrustedShopsConfigs defaults to .production, which is the environment integrators should use:
TrustedShopsSDK.start(
configs: TrustedShopsConfigs(
integrationIds: [.DEU: "your-integration-id"],
environment: .production
)
)| Environment | Description |
|---|---|
.production |
Production (default) |
Enable SDK logging for debugging:
TrustedShopsSDK.start(
configs: TrustedShopsConfigs(
integrationIds: [.DEU: "your-integration-id"],
logging: SDKLoggingConfig(
isEnabled: true,
level: .debug
)
)
)| Property | Type | Default | Description |
|---|---|---|---|
isEnabled |
Bool |
false |
Enable/disable logging |
level |
SDKLogLevel |
.error |
Minimum log level |
includeOSLog |
Bool |
true |
Bridge to Apple's unified logging |
redactSensitiveData |
Bool |
true |
Redact PII in logs |
customHandler |
SDKLogHandler? |
nil |
Custom log handler |
Log levels: .off, .error, .warning, .info, .debug, .trace
| Symbol | Type | Description |
|---|---|---|
TrustedShopsSDK.start(configs:) |
Function | Initialize the SDK (call once) |
TrustedShopsSDK.getInstance() |
Function | The SDK singleton (after start) |
TrustedShopsSDK.initiateCheckout(orderData:) |
Async function | Start buyer protection checkout |
TrustedShopsSDK.getInstance().setTargetMarket(_:) |
Function | Override active market (multi-market only); pass nil to revert |
TrustbadgeView |
SwiftUI View | Displays the Trustbadge widget |
TrustbadgeType |
Enum | .horizontal, .card |
TrustedShopsConfigs |
Struct | SDK initialization configuration |
TrustedShopsEnvironment |
Enum | .production |
TargetMarket |
Enum | Supported markets (.DEU, .AUT, .GBR, etc.) |
OrderData |
Struct | Order information for checkout |
Product |
Struct | Product in an order |
Currency |
Enum | Supported currencies |
SDKLoggingConfig |
Struct | Logging configuration |
SDKLogLevel |
Enum | Log levels (.off through .trace) |
The Trusted Shops iOS SDK is proprietary and closed source. See the LICENSE file for details.