Skip to content

getsafepay/swift-drops-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

swift-drops-sdk

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.

Status

  • payer-auth only
  • Drops-backed
  • WKWebView-based
  • atoms-aligned callbacks

Installation

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.

Usage

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()

Callback contract

The delegate callbacks are aligned with safepay-atoms and mirror android-drops-sdk:

  • onPayerAuthenticationSuccess
  • onPayerAuthenticationFailure
  • onPayerAuthenticationRequired
  • onPayerAuthenticationFrictionless
  • onPayerAuthenticationUnavailable
  • onSafepayError

All callbacks have default no-op implementations so you only need to implement the ones you care about.

Notes

  • Loads the Drops /authlink route in a WKWebView.
  • 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 WKUserScript at document start for early injection, with a fallback re-injection on didFinish.
  • Outbound messages (native → web) use an acknowledged delivery protocol with up to 3 retries and a 1.5 s timeout, matching the Android implementation.

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages