Client SDK
Migration
Migrating from v5 to v6
While iOS v6 is a major version bump and contains breaking changes, we kept these changes to a minimum where possible.
Why upgrade to v6?
- The SDK has been fully rewritten in Swift to take advantage of language features and type safety
- Streamlined method names to make adding additional payment methods seamless and reduce integration time
- Updates for the latest versions of iOS and Xcode
You can find a complete list of changes in iOS v6 in our CHANGELOG.
Minimum requirements
The Braintree iOS v6 SDK requires Xcode 14.3+, Swift 5.8+ and a minimum deployment target of iOS 14.0.
If your application contains Objective-C code, the Enable Modules build setting must be set to YES.
Installation
iOS v6 supports installation via Swift Package Manager, CocoaPods and Carthage.
The Installation section of the README has more information.
Carthage
iOS v6 requires Carthage v0.38.0+, which adds support for xcframework binary dependencies.
- Bash
carthage update --use-xcframeworks
Required code changes
Venmo
BTVenmoDriver
has been renamed to BTVenmoClient
to ensure consistency between feature clients.
BTVenmoRequest
must now be initialized with a paymentMethodUsage
.
The possible values for BTVenmoPaymentMethodUsage include:
.multiUse
- the Venmo payment will be authorized for future payments and can be vaulted.
.singleUse
- the Venmo payment will be authorized for a one-time payment and cannot be vaulted.
BTVenmoClient.tokenizeVenmoAccount(with:completion:)
has been renamed to BTVenmoClient.tokenize(_:completion:)
BTVenmoClient.isiOSAppAvailableForAppSwitch()
has been renamed to BTVenmoClient.isVenmoAppInstalled()
- Swift
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let venmoClient = BTVenmoClient(apiClient: apiClient)
let venmoRequest = BTVenmoRequest(paymentMethodUsage: .multiUse)
venmoRequest.profileID = "my-profile-id"
venmoRequest.vault = true
venmoClient.tokenize(venmoRequest) { venmoAccountNonce, error in
guard let venmoAccountNonce else {
// handle error
}
// send nonce to server
}
PayPal
BTPayPalDriver
has been renamed to BTPayPalClient
to ensure consistency between feature clients.
BTPayPalDriver.requestOneTimePayment
and BTPayPalDriver.requestBillingAgreement
in favor of BTPayPalClient.tokenize
:
- Swift
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let payPalClient = BTPayPalClient(apiClient: apiClient)
let request = BTPayPalCheckoutRequest(amount: "1")
payPalClient.tokenize(request) { payPalAccountNonce, error in
guard let payPalAccountNonce else {
// handle error
}
// send nonce to server
}
BTPayPalClient.tokenizePayPalAccount(with:completion:)
has been replaced with two methods called: BTPayPalClient.tokenize(_:completion:)
each taking in either a BTPayPalCheckoutRequest
or BTPayPalVaultRequest
- Swift
// BTPayPalCheckoutRequest
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let payPalClient = BTPayPalClient(apiClient: apiClient)
let request = BTPayPalCheckoutRequest(amount: "1")
payPalClient.tokenize(request) { payPalAccountNonce, error in
guard let payPalAccountNonce else {
// handle error
}
// send nonce to server
}
// BTPayPalVaultRequest
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let payPalClient = BTPayPalClient(apiClient: apiClient)
let request = BTPayPalVaultRequest()
payPalClient.tokenize(request) { payPalAccountNonce, error in
guard let payPalAccountNonce else {
// handle error
}
// send nonce to server
}
PayPal Native Checkout
BTPayPalNativeCheckoutClient.tokenizePayPalAccount(with:completion:)
has been replaced with two methods called: BTPayPalNativeCheckoutClient.tokenize(_:completion:)
each taking in either a BTPayPalNativeCheckoutRequest
or BTPayPalNativeVaultRequest
- Swift
// BTPayPalNativeCheckoutRequest
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let payPalNativeCheckoutClient = BTPayPalNativeCheckoutClient(apiClient: apiClient)
let request = BTPayPalNativeCheckoutRequest(amount: "1")
payPalNativeCheckoutClient.tokenize(request) { payPalNativeCheckoutAccountNonce, error in
guard let payPalNativeCheckoutAccountNonce else {
// handle error
}
// send nonce to server
}
// BTPayPalNativeVaultRequest
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let payPalNativeCheckoutClient = BTPayPalNativeCheckoutClient(apiClient: apiClient)
let request = BTPayPalNativeVaultRequest()
payPalNativeCheckoutClient.tokenize(request) { payPalNativeCheckoutAccountNonce, error in
guard let payPalNativeCheckoutAccountNonce else {
// handle error
}
// send nonce to server
}
Data Collector
Note: Kount is no longer supported via the Braintree iOS SDK.
The PayPalDataCollector
module and all containing classes has been removed in favor of a single Data collector module called BraintreeDataCollector
. This module should be used for all data collection.
- Swift
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let dataCollector = BTDataCollector(apiClient: apiClient)
dataCollector.collectDeviceData { deviceData, error in
guard let deviceData else {
// handle error
}
// send deviceData to server
}
Union Pay
The BraintreeUnionPay
module, and all containing classes, was removed in v6. UnionPay cards can now be processed as regular cards, through the BraintreeCard
module. You no longer need to manage card enrollment via SMS authorization.
- Swift
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let cardClient = BTCardClient(apiClient: apiClient)
let card = BTCard()
card.number = "6243030000000001"
card.expirationMonth = "12"
card.expirationYear = "2025"
cardClient.tokenize(card) { tokenizedCard, error in
guard let tokenizedCard else {
// handle error
}
// send nonce to server
}
SEPA Direct Debit
We have removed the context
parameter from the BTSEPADirectDebit.tokenize()
method.
Additionally, conformance to the ASWebAuthenticationPresentationContextProviding
protocol is no longer needed.
BTSEPADirectDebitClient.tokenize(request:context:completion:)
has been renamed to BTSEPADirectDebitClient.tokenize(_:completion:)
- Swift
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let sepaDirectDebitClient = BTSEPADirectDebitClient(apiClient: apiClient)
sepaDirectDebitClient.tokenize(sepaDirectDebitRequest) { sepaDirectDebitNonce, error in
guard let sepaDirectDebitNonce else {
// handle error
}
// send nonce to server
}
Local Payments
We have renamed the module BraintreePaymentFlow
to BraintreeLocalPayment
.
We have additionally replaced SFAuthenticationSession
with ASWebAuthenticationSession
in the Local Payment Method flow. With this change, you no longer need to:
- Register a URL Scheme or set a return URL via the
BTAppContextSwitcher.setReturnURLScheme()
method - Handle app context switching via the
BTAppContextSwitcher.handleOpenURL(context:)
orBTAppContextSwitcher.handleOpenURL()
method - Setting a
viewControllerPresentingDelegate
is no longer required
Instantiate a BTLocalPaymentClient
instead of a BTPaymentFlowDriver
. The result returned from the startPaymentFlow()
completion no longer needs to be cast to BTLocalPaymentResult
.
- Swift
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let localPaymentClient = BTLocalPaymentClient(apiClient: self.apiClient)
localPaymentClient.startPaymentFlow(localPaymentRequest) { localPaymentResult, error in
// Handle result
}
3D Secure
Instantiate a BTThreeDSecureClient
instead of a BTPaymentFlowDriver
. The result returned in the startPaymentFlow()
completion no longer needs to be cast to BTThreeDSecureResult
.
Setting a viewControllerPresentingDelegate
is no longer required.
The BTViewControllerPresentingDelegate
has been removed, as 3D Secure version 1 is no longer supported. All 3D Secure flows will go through 3D Secure version 2.
- Swift
let apiClient = BTAPIClient("<TOKENIZATION_KEY_OR_CLIENT_TOKEN>")
let threeDSecureClient = BTThreeDSecureClient(apiClient: self.apiClient)
threeDSecureClient.startPaymentFlow(threeDSecureRequest) { threeDSecureResult, error in
// Handle result
}