Setup

Quick installationAnchorIcon

We support using CocoaPods to implement the PayPal Commerce SDK in your project. CocoaPods is a dependency manager for Cocoa and Cocoa Touch projects. Information for installing and setting it up in your project is available on CocoaPods.org. To install the PayPal Commerce SDK using CocoaPods, simply add this to your Podfile and run pod install:
pod 'PayPalCommerce', :git => '[email protected]:braintree/paypal-commerce-ios.git'
If you don't already use CocoaPods acknowledgements, you'll need to include the PayPalCommerce-Acknowledgements.md somewhere in your app, so proper licensing attribution will be covered. If you'd like to manage the installation on your own, you can find download links and instructions in Installation without CocoaPods.

Configure the clientAnchorIcon

Create an OAuth ClientAnchorIcon

Add your app to the PayPal Commerce Panel and copy your client ID and secret. You'll use these to configure the SDK.

Add PayPal Commerce to your app delegateAnchorIcon

In your app delegate:
  1. Objective-C
#import <paypalcommerce/paypalcommerce.h>
Use the client ID and secret you created above. Within application:didFinishLaunchingWithOptions::
  1. Objective-C
[PayPalCommerce configureWithClientID:@"client-id"
                         clientSecret:@"client-secret"
                        launchOptions:launchOptions];
If you are using a tab bar controller to present the store to your users, or if you are presenting modally and would like to be notified of transitions, please implement the PayPalCommerceDelegate protocol.

Apple PayAnchorIcon

In order for your customers to use Apple Pay, you'll need to take care of a few things:
  1. Create your Apple Pay merchant ID and certificate in the Apple Developer Member Center.
  2. Enable Apple Pay in the PayPal Commerce Panel.
  3. Update your project to use Apple Pay (under your Target > Capabilities > Apple Pay).
  4. In your app delegate, configure your Apple Pay merchant ID:
  1. Objective-C
[PayPalCommerce configureApplePayMerchantID:@"merchant.com.your.apple.pay.id"];

Info.plist updatesAnchorIcon

In your app's Info.plist, please make the following changes:
  • UIViewControllerBasedStatusBarAppearance allows us to show and hide the status bar as needed.
  • NSAppTransportSecurity allows us to communicate with Cloudfront and Facebook in iOS 9+. The SDK communicates over https, but we use loggly.com for internal API logging, which currently require the forward secrecy exception. (We expect this to change soon).
  • LSApplicationQueriesSchemes is needed for Facebook and PayPal to work properly in iOS 9+.
  • UIApplicationShortcutItems is needed to support 3D Touch from the home screen app icon.
Updates:
  1. xml
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>loggly.com</key>
        <dict>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
        <key>facebook.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>fbcdn.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
    <string>org-appextension-feature-password-management</string>
    <string>instagram</string>
</array>
<key>UIApplicationShortcutItems</key>
<array>
    <dict>
        <key>UIApplicationShortcutItemIconType</key>
        <string>UIApplicationShortcutIconTypeHome</string>
        <key>UIApplicationShortcutItemTitle</key>
        <string>Shop</string>
        <key>UIApplicationShortcutItemType</key>
        <string>com.paypal.commerce.home</string>
    </dict>
    <dict>
        <key>UIApplicationShortcutItemIconType</key>
        <string>UIApplicationShortcutIconTypeSearch</string>
        <key>UIApplicationShortcutItemTitle</key>
        <string>Search</string>
        <key>UIApplicationShortcutItemType</key>
        <string>com.paypal.commerce.search</string>
    </dict>
    <dict>
        <key>UIApplicationShortcutItemIconType</key>
        <string>UIApplicationShortcutIconTypeTime</string>
        <key>UIApplicationShortcutItemTitle</key>
        <string>Purchases</string>
        <key>UIApplicationShortcutItemType</key>
        <string>com.paypal.commerce.order-history</string>
    </dict>
</array>
<key>NSCameraUsageDescription</key>
<string>Your camera would only be used to let you scan your credit card.</string>
<key>NSContactsUsageDescription</key>
<string>Your contacts would only be used to let you import your shipping address.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>You can save product photos to your library.</string>

Custom URL scheme for user loginAnchorIcon

PayPal Commerce uses a login system that eschews passwords in favor of an email-based login flow. New users will be let in immediately. However, if a returning user logs in to your store, we will send them an email with a login link, and in the app we will display a message requesting they open their email to tap that link, which will have the custom URL scheme that's unique to your app. Tapping the link will open your app, PayPal Commerce will verify their email address, and they will be able to continue shopping, view their previous orders, update their profile, etc. Additionally, PayPal login requires a custom URL scheme to function properly. You can get your URL scheme from the Commerce Panel > Channels > iOS SDK. Then, add your URL scheme to your project:
  1. In Xcode, select your Target.
  2. Select Info.
  3. Under URL Types, add a new type (+ button).
  4. In the URL Scheme field, enter the scheme provided by PayPal Commerce (e.g. pypl-acme-shovels).
  5. Under URL Types, add a new type (+ button).
  6. In the URL Scheme field, enter your bundle identifier (e.g. com.acme.store) or simply the variable $(PRODUCT_BUNDLE_IDENTIFIER).
If you are building multiple apps that include the same PayPal Commerce store, please be sure to create multiple OAuth clients.

URL handlingAnchorIcon

In order for PayPal Commerce to be able to see these URLs, you'll need to add or modify the application:openURL:… method in your app delegate:
  1. Objective-C
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    [PayPalCommerce openURL:url sourceApplication:sourceApplication annotation:annotation];
    return YES;
}
To deep-link to products and categories, please follow our URL specs docs.

Push notification supportAnchorIcon

For PayPal Commerce to be able to support push notifications for your store, you will need to add or modify these methods in your app delegate:
  1. Objective-C
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [PayPalCommerce didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    [PayPalCommerce didFailToRegisterForRemoteNotificationsWithError:error];
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
    [PayPalCommerce didRegisterUserNotificationSettings:notificationSettings];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [PayPalCommerce didReceiveRemoteNotification:userInfo];
}

iOS 9 Spotlight search indexingAnchorIcon

In order for products in your users' spotlight search to open the app in the correct place, please add this to your app delegate:
  1. Objective-C
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler {
    [PayPalCommerce continueUserActivity:userActivity restorationHandler:restorationHandler];
    return YES;
}

3D TouchAnchorIcon

In order for your users to be able to open the app from the home screen app icon's 3D Touch menu, you'll need to add this to your app delegate:
  1. Objective-C
- (void)application:(UIApplication *)application performActionForShortcutItem:(nonnull UIApplicationShortcutItem *)shortcutItem completionHandler:(nonnull void (^)(BOOL))completionHandler {
    BOOL didPerformAction = [PayPalCommerce performActionForShortcutItem:shortcutItem];
    if (!didPerformAction) {
        // if you added any custom 3D Touch shortcuts, you can handle them here
    }
    completionHandler(didPerformAction);
}

Facebook loginAnchorIcon

If you'd like to enable Facebook login, please follow the setup instructions.

Present the storeAnchorIcon

There are three types of apps you might be creating. The most popular approach is to present the store modally. Use this method wherever you want the store presented, typically from a button or some other user action.
  1. Objective-C
[PayPalCommerce presentModalStore];
Modal,store

Tight UI integrationAnchorIcon

If you want to integrate the store UI more tightly with your own app, you can use the embedded view controller via:
  1. Objective-C
UIViewController *paypalCommerceViewController = [PayPalCommerce paypalCommerceRootViewController];
One popular approach is to use this in a tab bar:
  1. Objective-C
tabViewController.viewControllers = @[infoVC, paypalCommerceViewController, aboutVC];
Tab,store

Standalone storeAnchorIcon

Finally, if you want just the store as an app, without anything else, you can implement this method in your application:didFinishLaunchingWithOptions: after you configure the client.
  1. Objective-C
[PayPalCommerce presentStoreApp];
Standalone,store

Multiple iOS apps per storeAnchorIcon

If you are building multiple iOS apps that will interact with a single PayPal Commerce store, then you will need to set up multiple OAuth clients. This is necessary to keep our email verification system functional. In the PayPal Commerce Panel, there's a section called Channels, and under that is iOS SDK (commerce.paypal.com/ios/sdk). There you will see your primary OAuth client, as well as a space to add more. Each will provide you with your PayPal Commerce URL scheme, as well as its own client ID and secret. Read Configuring the Client for more on where to put those items.