Skip to main content
On this page

Use the DEUNA iOS SDK to show complete Checkout, Payment Widget, Payment Vault, Click to Pay, next-action, voucher, and native Apple Pay experiences. The core package supports iOS 13 and later; the unified embedded SwiftUI DeunaWidget requires iOS 14 or later.

Install#

Swift Package Manager

In Xcode, select File → Add Package Dependencies, enter the repository URL, and pin a release version:

Plain text
https://github.com/deuna-developers/deuna-sdk-ios

Select the core DeunaSDK product. In a package manifest, add the product to your target dependencies:

Package.swiftSwift
.product(name: "DeunaSDK", package: "deuna-sdk-ios")

CocoaPods

Add the core subspec and pin an SDK version according to your release policy:

PodfileRuby
pod 'DeunaSDK/Core', '~> 2.12'

Fraud-provider frameworks are optional. Add only the products or subspecs assigned to your account, such as DeunaSDK/Cybersource, DeunaSDK/Kount, DeunaSDK/Sift, DeunaSDK/Riskified, DeunaSDK/Signifyd, DeunaSDK/Accertify, or DeunaSDK/MercadoPago.

Initialize#

Create one SDK instance with the public API key for the selected environment and retain it for the owning screen or coordinator.

Swift
import DeunaSDK

let deunaSDK = DeunaSDK(
  environment: .sandbox,
  publicApiKey: "YOUR_PUBLIC_API_KEY"
)

For an application-wide instance, initialize and then read the shared SDK:

Swift
DeunaSDK.initialize(
  environment: .sandbox,
  publicApiKey: "YOUR_PUBLIC_API_KEY"
)

let deunaSDK = DeunaSDK.shared

Open Payment Widget in a modal#

Create typed callbacks and pass the order token returned by your backend:

Swift
let callbacks = PaymentWidgetCallbacks(
  onSuccess: { order in
    deunaSDK.close()
    showConfirmation(order)
  },
  onError: { error in
    showRetry(error)
  },
  onClosed: { action in
    showCart(action)
  },
  onPaymentProcessing: {
    disablePayButton()
  },
  onEventDispatch: { event, payload in
    analytics.track(event, payload)
  }
)

deunaSDK.initPaymentWidget(
  orderToken: orderToken,
  callbacks: callbacks,
  language: "en"
)

Call close() to dismiss the active widget. Call dispose() when the owning flow ends to release its controller and WebView.

Available experiences#

ExperienceMethodImportant input
Complete CheckoutinitCheckout(...)orderToken, CheckoutCallbacks
Payment WidgetinitPaymentWidget(...)orderToken, PaymentWidgetCallbacks
Payment VaultinitElements(...)ElementsCallbacks; types may be omitted
Click to PayinitElements(...)types: [["name": ElementsWidget.clickToPay]]
Next ActioninitNextAction(...)Token for the order that requires another action
VoucherinitVoucher(...)Token for the voucher order

The iOS method is named initVoucher, not initVoucherWidget.

Embed a widget with SwiftUI#

On iOS 14 or later, build a typed configuration and render DeunaWidget. The SDK chooses the correct embedded controller from the configuration type.

Swift
struct PaymentScreen: View {
  let deunaSDK: DeunaSDK
  let orderToken: String
  let callbacks: PaymentWidgetCallbacks

  var body: some View {
    let configuration = PaymentWidgetConfiguration(
      orderToken: orderToken,
      callbacks: callbacks
    )

    DeunaWidget(
      deunaSDK: deunaSDK,
      configuration: configuration
    )
  }
}

Use CheckoutWidgetConfiguration, ElementsWidgetConfiguration, NextActionWidgetConfiguration, or VoucherWidgetConfiguration for the other experiences.

For a widget inside ScrollView, pass AutoResizeConfig(initialHeight: 150) to the configuration and handle onScrollNeeded so the focused field remains visible above the keyboard.

Swift
DeunaWidget(deunaSDK: deunaSDK, configuration: configuration)
  .onScrollNeeded { points in
    scrollBy(points)
  }

If your application owns the pay button, set hidePayButton: true in the configuration and call deunaSDK.submit { result in ... } from the button action.

Payment Vault and Click to Pay#

Payment Vault is the default Elements experience. Pass either an authenticated userToken or UserInfo for the customer.

Swift
let elementsCallbacks = ElementsCallbacks(
  onSuccess: { credential in useSavedCredential(credential) },
  onError: { error in showRetry(error) },
  onClosed: { action in showPaymentMethods(action) },
  onEventDispatch: { event, payload in
    analytics.track(event, payload)
  }
)

deunaSDK.initElements(
  callbacks: elementsCallbacks,
  userInfo: DeunaSDK.UserInfo(email: "ada@example.com"),
  types: [["name": ElementsWidget.vault]],
  orderToken: orderToken
)

Use ElementsWidget.clickToPay instead of ElementsWidget.vault for Click to Pay.

Native Apple Pay#

Check both merchant configuration and device capability before rendering your Apple Pay button. The SDK caches the result.

Swift
let userInfo = DeunaSDK.UserInfo(email: "ada@example.com")
let params = GetWalletsAvailableParams(
  orderToken: orderToken,
  userInfo: userInfo
)

deunaSDK.getWalletsAvailable(params: params) { wallets, error in
  if let error {
    showWalletError(error)
    return
  }

  applePayButton.isHidden = !wallets.contains(.applePay)
}

After availability succeeds, launch Apple Pay from the button action by selecting the wallet in initElements:

Swift
deunaSDK.initElements(
  callbacks: elementsCallbacks,
  userInfo: userInfo,
  types: [["name": WalletProvider.applePay.processorName.uppercased()]],
  orderToken: orderToken
)

The application must include the Apple Pay entitlement and a provisioning profile containing the merchant identifier. See Apple Pay for the full setup.

Continue a pending action#

Use the same order token when DEUNA reports that the payment requires a supported 3DS challenge or redirect.

Swift
deunaSDK.initNextAction(
  orderToken: orderToken,
  callbacks: nextActionCallbacks
)

The SDK presents supported external URLs and returns control to the widget. Use callback state for the interface and a verified webhook for fulfillment.

Open a voucher#

Swift
deunaSDK.initVoucher(
  orderToken: orderToken,
  callbacks: voucherCallbacks
)

Voucher callbacks follow the same success, error, close, and event-dispatch lifecycle as the other payment experiences.

Fraud-device data#

The core product has no fraud-provider dependencies. Link only the provider products or subspecs you use, then call generateFraudId with the configuration assigned to your account.

Swift
deunaSDK.generateFraudId(params: [
  "CYBERSOURCE": [
    "orgId": "YOUR_ORG_ID",
    "merchantId": "YOUR_MERCHANT_ID",
  ],
]) { fraudId in
  guard let fraudId else { return }
  sendFraudIdToBackend(fraudId)
}

If a requested provider framework is not linked, the SDK skips that provider. See Integrate device fingerprint for provider-specific configuration.

Callback and lifecycle reference#

Callback or methodUse it for
onSuccessUpdate the interface after the experience succeeds.
onErrorHandle a typed PaymentsError or ElementsError.
onClosedDistinguish customer and SDK-controlled closure.
onEventDispatchObserve supported checkout or Elements lifecycle events.
onCardBinDetectedReact to card BIN detection.
onInstallmentSelectedReact to an installment-plan selection.
onPaymentProcessingPrevent duplicate payment actions.
close()Close the active presentation while retaining the SDK controller.
dispose()Release the active controller and WebView when the flow ends.

Official examples and source#

See WalletsScreen.swift for native Apple Pay and EmbeddedScreen.swift for the SwiftUI lifecycle.