With this SDK, you can accept 3D Secure 2.0 payments via Adyen.
The SDK is available via CocoaPods, Carthage or via manual installation.
- Add
pod 'Adyen3DS2_Swift'
to yourPodfile
. - Run
pod install
.
- Add
github "adyen/adyen-3ds2-ios"
to yourCartfile
. - Run
carthage update
. - Link the framework with your target as described in Carthage Readme.
Drag the dynamic XCFramework/Dynamic/Adyen3DS2_Swift.xcframework
to the Frameworks, Libraries, and Embedded Content
section in your general target settings. Select "Copy items if needed" when asked.
- Drag the static
XCFramework/Static/Adyen3DS2_Swift.xcframework
to theFrameworks, Libraries, and Embedded Content
section in your general target settings. - Make sure the static
Adyen3DS2_Swift.xcframework
is not embedded. - Select
Adyen3DS2.bundle
insideAdyen3DS2_Swift.xcframework
and check "Copy items if needed", then select "Add". - The privacy manifest should be included/merged in your app bundle.
- Follow Apple's Adding Package Dependencies to Your App guide on how to add a Swift Package dependency.
- Use
https://github.com/Adyen/adyen-3ds2-ios-swift.git
as the repository URL. - Specify the version to be at least
3.0.0
.
Adyen3DS2_Swift
using Swift Package Manager.
First, create an instance of ServiceParameters
with the additional data retrieved from your call to /authorise
.
Then, use the class method on Transaction
to create a new transaction.
let messageVersion = MessageVersion(rawValue: messageVersionString)
let serviceParameters = try ServiceParameters(directoryServerIdentifier: directoryServerIdentifier, // Retrieved from Adyen
directoryServerPublicKey: directoryServerPublicKey, // Retrieved from Adyen
directoryServerRootCertificates: directoryServerRootCertificates) // Retrieved from Adyen
Transaction.initialize(with: serviceParameters, messageVersion: messageVersion, securityDelegate: self, appearanceConfiguration: appearance) { result in
switch result {
case .success(let transaction):
self.transaction = transaction
let authenticationRequestParameters = transaction.authenticationRequestParameters // submit the authenticationRequestParameters to /authorise3ds2
case .failure(let error):
switch error.errorCode {
case "1001":
// Handle cancellation
default:
// Other error occurred
let errorRepresentation: String = error.base64Representation
// Submit `errorRepresentation` to [Adyen backend](https://docs.adyen.com/api-explorer/Payment/64/post/authorise3ds2)
// Submit the transactionStatus = "U" to [Adyen backend](https://docs.adyen.com/api-explorer/Payment/64/post/authorise3ds2).
}
}
}
Use the transaction
's authenticationRequestParameters
in your call to /authorise3ds2
.
Transaction.initialize(ServiceParameters, MessageVersion, SecurityDelegate, AppearanceConfiguration)
requires the message version to be passed, please fill in the same message version as in the AReq, you should be able to get the message version decided by the 3DS server from its response when initiating the payment, if you use the Adyen 3DS server please see the documentation.
Transaction
instance until the transaction is finished.
Transaction
object between scenes for the case if the shopper starts a transaction on one window and switch to another while the transaction is in progress.
In case a challenge is required, create an instance of ChallengeParameters
with values from the additional data retrieved from your call to /authorise3ds2
.
internal struct ChallengeData: Decodable {
var acsTransactionIdentifier: String
var acsReferenceNumber: String
var acsSignedContent: String
var serverTransactionIdentifier: String
}
let challengeData: ChallengeData // Retrieved from Adyen.
let challengeParameters = ChallengeParameters(serverTransactionIdentifier: challengeData.serverTransactionIdentifier,
threeDSRequestorAppURL: URL(string: "{YOUR_APP_URL}"), // Or nil if for example you're using protocol version 2.1.0
acsTransactionIdentifier: challengeData.acsTransactionIdentifier,
acsReferenceNumber: challengeData.acsReferenceNumber,
acsSignedContent: challengeData.acsSignedContent)
threeDSRequestorAppURL
parameter as a universal link.
Use these challenge parameters to perform the challenge with the transaction
you created earlier:
transaction.performChallenge(with: challengeParameters,
presenterViewController: presenterViewController) { result in
switch result {
case .success(let challengeResult):
let transactionStatus: String = challengeResult.transactionStatus // Submit the transactionStatus to /authorise3ds2.
case .failure(let error):
// An error occurred.
}
}
When the challenge is completed successfully, submit the transactionStatus
in the result
in your second call to /authorise3ds2
.
The SDK provides some customization options to ensure the UI of the challenge flow fits your app's look and feel. These customization options are available through the AppearanceConfiguration
class. To use them, create an instance of AppearanceConfiguration
, configure the desired properties and pass it during initialization of the Transaction
.
For example, to make the Continue button red and change its corner radius:
var submitButtonAppearance: ButtonAppearance = ButtonAppearance(buttonType: .submit)
submitButtonAppearance.cornerRadius = 24.0
submitButtonAppearance.backgroundColor = .red
submitButtonAppearance.textColor = .white
let appearance = AppearanceConfiguration(submitButtonAppearance: submitButtonAppearance)
If you want to get the currently used sdk version - for example to send to the /authorise
end point, you can get it using:
let version: String = SDKVersion();
To accommodate the older interface, add the below typealias in your integration code. Note the older interface is deprecated and this interface will be removed in the next couple of versions.
typealias ADYTransaction = LegacyInterface.ADYTransaction
typealias ADYService = LegacyInterface.ADYService
typealias ADYServiceParameters = LegacyInterface.ADYServiceParameters
typealias ADYChallengeParameters = LegacyInterface.ADYChallengeParameters
typealias ADYAppearanceConfiguration = LegacyInterface.ADYAppearanceConfiguration
typealias ADYChallengeResult = LegacyInterface.ADYChallengeResult
typealias ADYSecurityWarningsDelegate = LegacyInterface.ADYSecurityWarningsDelegate
typealias ADYRuntimeErrorCode = LegacyInterface.ADYRuntimeErrorCode
typealias ADYWarning = LegacyInterface.ADYWarning
typealias ADYAuthenticationRequestParameters = LegacyInterface.ADYAuthenticationRequestParameters
- Complete Documentation
- SDK Reference
- Reporting security issues.
- Security best practices.
- Data security at Adyen.
This repository is open source and available under the MIT license. For more information, see the LICENSE file.