Configuration

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

Setup

note

The latest version of our Drop-in UI requires iOS 9+. You can find an example of the legacy Drop-in (iOS 8.0+) in our demo app.

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

CocoaPods

Ruby
pod 'BraintreeDropIn'

By default, Drop-in only ships with support for cards. You can include additional payment methods by adding their respective pods.

Ruby
pod 'Braintree/PayPal'
pod 'Braintree/Venmo'
pod 'Braintree/Apple-Pay'

Carthage

Add github 'braintree/braintree-ios-drop-in' to your Cartfile, and add the relevant frameworks to your project.

You will need the following frameworks at a minimum:

BraintreeDropIn.framework
BraintreeUIKit.framework
BraintreeCard.framework
BraintreeCore.framework
BraintreePaymentFlow.framework
PayPalOneTouch.framework
PayPalDataCollector.framework
PayPalUtils.framework

For PayPal, you must add the following framework:

BraintreePayPal.framework

For Apple Pay, you must add the following framework in addition to PassKit. See the Apple Pay Client-Side Implementation for more details.

BraintreeApplePay.framework

Client-side implementation

Import BraintreeDropIn and Braintree

Add the import statements to any class using Braintree.

#import "BraintreeCore.h"
#import "BraintreeDropIn.h"

Starting Drop-in

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

- (void)showDropIn:(NSString *)clientTokenOrTokenizationKey {
    BTDropInRequest *request = [[BTDropInRequest alloc] init];
    BTDropInController *dropIn = [[BTDropInController alloc] initWithAuthorization:clientTokenOrTokenizationKey request:request handler:^(BTDropInController * _Nonnull controller, BTDropInResult * _Nullable result, NSError * _Nullable error) {

        if (error != nil) {
            NSLog(@"ERROR");
        } else if (result.cancelled) {
            NSLog(@"CANCELLED");
        } else {
            // Use the BTDropInResult properties to update your UI
            // result.paymentOptionType
            // result.paymentMethod
            // result.paymentIcon
            // result.paymentDescription
        }
    }];
    [self presentViewController:dropIn animated:YES completion:nil];
}

Configuring payment methods

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.

PayPal

In order for your Drop-in to support PayPal payments, you must follow the app switch setup instructions and complete the full PayPal integration.

Venmo

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 Pay

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 selected Apple Pay as their preferred payment method, then result.paymentOptionType will be .applePay (Swift) or BTUIKPaymentOptionTypeApplePay (Objective C) 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 methods

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

PayPal

BTDropInRequest *request = [[BTDropInRequest alloc] init];
request.paypalDisabled = YES;

Venmo

BTDropInRequest *request = [[BTDropInRequest alloc] init];
request.venmoDisabled = YES;

Apple Pay

BTDropInRequest *request = [[BTDropInRequest alloc] init];
request.applePayDisabled = YES;

3D Secure

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 last used payment method

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:fetchDropInResultForAuthorization. A payment method will only be returned when using a client token created with a customer_id.

- (void)fetchExistingPaymentMethod:(NSString *)clientToken {
    [BTDropInResult fetchDropInResultForAuthorization:clientToken handler:^(BTDropInResult * _Nullable result, NSError * _Nullable error) {
        if (error != nil) {
            NSLog(@"ERROR");
        } else {
            // Use the BTDropInResult properties to update your UI
            // result.paymentOptionType
            // result.paymentMethod
            // result.paymentIcon
            // result.paymentDescription
        }
    }];
}

Location Permissions

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 steps

Next Page: Customization →