iOS library for Safepay payer authentication using Drops inside a native WKWebView.
This is the Swift counterpart to android-drops-sdk. It mirrors the WebView-based approach used in the React Native SDK, rather than a native Cardinal flow.
- payer-auth only
- Drops-backed
- WKWebView-based
- atoms-aligned callbacks
Add the package via Swift Package Manager:
.package(url: "https://github.com/getsafepay/swift-drops-sdk", from: "0.1.0")Then add SafepayDropsSDK to your target's dependencies.
Add the view to your layout, then configure it:
import SafepayDropsSDK
let payerAuthView = SafepayPayerAuthenticationView()
payerAuthView.delegate = self
payerAuthView.configure(SafepayPayerAuthenticationConfiguration(
environment: .sandbox,
authToken: "your-auth-token",
tracker: "track_xxx",
deviceDataCollectionJWT: "jwt",
deviceDataCollectionURL: "https://centinelapistag.cardinalcommerce.com/V1/Cruise/Collect",
billing: BillingAddress(
street1: "123 Main Street",
city: "Berlin",
country: "DE"
),
authorizationOptions: AuthorizationOptions(
doCapture: true,
doCardOnFile: false
)
))Implement the delegate:
extension YourViewController: SafepayPayerAuthenticationDelegate {
func onPayerAuthenticationSuccess(data: PayerAuthenticationSuccessData) {
print("success: \(data)")
}
func onPayerAuthenticationFailure(data: PayerAuthenticationErrorData) {
print("failure: \(data)")
}
func onPayerAuthenticationRequired(data: PayerAuthenticationData) {
print("required: \(data)")
}
func onPayerAuthenticationFrictionless(data: PayerAuthenticationData) {
print("frictionless: \(data)")
}
func onPayerAuthenticationUnavailable(data: PayerAuthenticationData) {
print("unavailable: \(data)")
}
func onSafepayError(error: SafepayErrorData) {
print("error: \(error)")
}
}Alternatively, use SafepayPayerAuthenticationController as a thin wrapper that proxies the view:
let controller = SafepayPayerAuthenticationController(view: payerAuthView)
controller.delegate = self
controller.configure(configuration)
// later:
controller.destroy()The delegate callbacks are aligned with safepay-atoms and mirror android-drops-sdk:
onPayerAuthenticationSuccessonPayerAuthenticationFailureonPayerAuthenticationRequiredonPayerAuthenticationFrictionlessonPayerAuthenticationUnavailableonSafepayError
All callbacks have default no-op implementations so you only need to implement the ones you care about.
- Loads the Drops
/authlinkroute in aWKWebView. - Injects a
window.ReactNativeWebView.postMessage(...)compatible bridge shim so Drops can send events to native iOS in the same way it does for the React Native SDK. - Uses
WKUserScriptat document start for early injection, with a fallback re-injection ondidFinish. - Outbound messages (native → web) use an acknowledged delivery protocol with up to 3 retries and a 1.5 s timeout, matching the Android implementation.