Drop-in UI

Setup and Integrationanchor

Configurationanchor

To use the Drop-in UI, you'll need to get a tokenization key from the Control Panel or you can generate a client token on your server.

Requirementsanchor

  • Xcode 12+
  • A minimum deployment target of iOS 12.0
  • Swift 5.1+ (or Objective-C)

It goes without saying, but we'll say it anyway: we always recommend using the latest versions of our SDKs. In order to communicate securely with the Braintree gateway, you must use at least version 7.0.0 of the iOS Drop-in SDK.

Setupanchor

Drop-in requires a minimum deployment target of iOS 12+ and Xcode 12+.

There are several ways to include Braintree's Drop-in in your project.

Swift Package Manageranchor

To add the BraintreeDropIn package to your Xcode project, select File > Swift Packages > Add Package Dependency and enter https://github.com/braintree/braintree-ios-drop-in as the repository URL. Tick the checkbox for BraintreeDropIn.

If you look at your app target, you will see that the BraintreeDropIn library is automatically linked as a framework to your app (see General > Frameworks, Libraries, and Embedded Content).

CocoaPodsanchor

  1. Ruby
pod 'BraintreeDropIn'

Client-side implementationanchor

Import BraintreeDropInanchor

Add the following import statement to any class using Braintree.

  1. Swift
import BraintreeDropIn

Starting Drop-inanchor

Present BTDropInController to collect the customer's payment information and receive the nonce to send to your server.

  1. Swift
func showDropIn(clientTokenOrTokenizationKey: String) {
    let request =  BTDropInRequest()
    let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
    { (controller, result, error) in
        if (error != nil) {
            print("ERROR")
    } else if (result?.isCanceled == true) {
            print("CANCELED")
        } else if let result = result {
            // Use the BTDropInResult properties to update your UI
            // result.paymentMethodType
            // result.paymentMethod
            // result.paymentIcon
            // result.paymentDescription
        }
        controller.dismiss(animated: true, completion: nil)
    }
    self.present(dropIn!, animated: true, completion: nil)
}

Configuring payment methodsanchor

Additional steps are required for the Drop-in UI to accept payment methods other than cards. After completing the Drop-in setup instructions, follow the steps below for each payment method type.

PayPalanchor

In order for your Drop-in to support PayPal payments, you must complete the full PayPal integration.

Venmoanchor

To support Venmo payments in the Drop-in UI, make sure to follow the app switch setup instructions in the Client SDK Setup guide and complete the full Venmo integration. Venmo also requires version 4.29.0 or higher of the Braintree iOS SDK.

Apple Payanchor

If you've included the Apple Pay pod or framework in your project, Drop-in will show Apple Pay as a payment option as long as you've completed the Apple Pay integration and the customer's device and card type are supported.

important

If your customer selects Apple Pay, then result.paymentMethodType will be .applePay and result.paymentMethod will be nil.

Selecting Apple Pay does not display the Apple Pay sheet or create a nonce - you will still need to do that at the appropriate time in your app. Use BTApplePayClient to tokenize the customer's Apple Pay information, and see our Apple Pay Guide for more information.

If using a client token with a customer id, the Apple Pay card will not automatically be vaulted. You can use the payment method nonce to create a payment method on your server.

Conditionally disabling payment methodsanchor

Once you have enabled PayPal, Venmo, or Apple Pay, you have the option to conditionally hide these payment methods from your checkout.

PayPalanchor

  1. Swift
let request =  BTDropInRequest()
request.paypalDisabled = true

Venmoanchor

  1. Swift
let request =  BTDropInRequest()
request.venmoDisabled = true

Apple Payanchor

  1. Swift
let request =  BTDropInRequest()
request.applePayDisabled = true

3D Secureanchor

Drop-in supports 3D Secure 2 verification. To use 3D Secure in your integration, make sure app switch is set up and then follow our implementation guide. Once you have added 3D Secure to Drop-in, you will need to complete the server-side implementation for 3D Secure.

Displaying the most recently added payment methodanchor

If your user already has an existing payment method, you may not need to show the Drop-in payment picker. You can check if they have an existing payment method using BTDropInResult:mostRecentPaymentMethod. A payment method will only be returned when using a client token created with a customer_id.

  1. Swift
BTDropInResult.mostRecentPaymentMethod(forClientToken: clientToken) { result, error in
    if (error != nil) {
        print("ERROR")
    } else if let result = result {
        // Use the BTDropInResult properties to update your UI
        // result.paymentMethodType
        // result.paymentMethod
        // result.paymentIcon
        // result.paymentDescription
    }
})

Location Permissionsanchor

The Braintree iOS SDK uses device and browser location data for fraud detection when available (i.e. when location permissions have already been requested by your app and granted by the user). While you do not need to request location data from users in order to use Braintree, Apple requires a NSLocationWhenInUseUsageDescription key in your Info.plist if your app contains code referencing location APIs. If your app does not request location data, you will still need to include a NSLocationWhenInUseUsageDescription plist entry.

Next stepsanchor


Next Page: Customization