iOS SDK
Install the DEUNA iOS SDK and integrate modal, embedded, wallet, voucher, and next-action flows.
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:
https://github.com/deuna-developers/deuna-sdk-iosSelect the core DeunaSDK product. In a package manifest, add the product to your target dependencies:
.product(name: "DeunaSDK", package: "deuna-sdk-ios")CocoaPods
Add the core subspec and pin an SDK version according to your release policy:
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.
import DeunaSDK
let deunaSDK = DeunaSDK(
environment: .sandbox,
publicApiKey: "YOUR_PUBLIC_API_KEY"
)For an application-wide instance, initialize and then read the shared SDK:
DeunaSDK.initialize(
environment: .sandbox,
publicApiKey: "YOUR_PUBLIC_API_KEY"
)
let deunaSDK = DeunaSDK.sharedOpen Payment Widget in a modal#
Create typed callbacks and pass the order token returned by your backend:
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#
| Experience | Method | Important input |
|---|---|---|
| Complete Checkout | initCheckout(...) | orderToken, CheckoutCallbacks |
| Payment Widget | initPaymentWidget(...) | orderToken, PaymentWidgetCallbacks |
| Payment Vault | initElements(...) | ElementsCallbacks; types may be omitted |
| Click to Pay | initElements(...) | types: [["name": ElementsWidget.clickToPay]] |
| Next Action | initNextAction(...) | Token for the order that requires another action |
| Voucher | initVoucher(...) | 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.
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.
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.
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.
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:
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.
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#
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.
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 method | Use it for |
|---|---|
onSuccess | Update the interface after the experience succeeds. |
onError | Handle a typed PaymentsError or ElementsError. |
onClosed | Distinguish customer and SDK-controlled closure. |
onEventDispatch | Observe supported checkout or Elements lifecycle events. |
onCardBinDetected | React to card BIN detection. |
onInstallmentSelected | React to an installment-plan selection. |
onPaymentProcessing | Prevent 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.