Setup
Quick installation
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'Configure the client
Create an OAuth Client
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 delegate
In your app delegate:
- Objective-C
#import <paypalcommerce/paypalcommerce.h>Important
You must obfuscate the client ID and secret somehow (this protects your store and your customers).
application:didFinishLaunchingWithOptions::
- Objective-C
[PayPalCommerce configureWithClientID:@"client-id"
clientSecret:@"client-secret"
launchOptions:launchOptions];PayPalCommerceDelegate
protocol.
Apple Pay
In order for your customers to use Apple Pay, you'll need to take care of a few things:
- Create your Apple Pay merchant ID and certificate in the Apple Developer Member Center.
- Enable Apple Pay in the PayPal Commerce Panel.
- Update your project to use Apple Pay (under your Target > Capabilities > Apple Pay).
- In your app delegate, configure your Apple Pay merchant ID:
- Objective-C
[PayPalCommerce configureApplePayMerchantID:@"merchant.com.your.apple.pay.id"];Info.plist updates
In your app's Info.plist, please make the following changes:
UIViewControllerBasedStatusBarAppearanceallows us to show and hide the status bar as needed.NSAppTransportSecurityallows 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).LSApplicationQueriesSchemesis needed for Facebook and PayPal to work properly in iOS 9+.UIApplicationShortcutItemsis needed to support 3D Touch from the home screen app icon.
- 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 login
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.
Important
In order for this flow to work properly, please add the custom URL scheme for PayPal Commerce.
- In Xcode, select your Target.
- Select Info.
- Under URL Types, add a new type (+ button).
- In the URL Scheme field, enter the scheme provided by PayPal Commerce (e.g. pypl-acme-shovels).
- Under URL Types, add a new type (+ button).
- In the URL Scheme field, enter your bundle identifier (e.g. com.acme.store) or simply the variable $(PRODUCT_BUNDLE_IDENTIFIER).
URL handling
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:
- Objective-C
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
[PayPalCommerce openURL:url sourceApplication:sourceApplication annotation:annotation];
return YES;
}Push notification support
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:
- 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 indexing
In order for products in your users' spotlight search to open the app in the correct place, please
add this to your app delegate:
- Objective-C
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler {
[PayPalCommerce continueUserActivity:userActivity restorationHandler:restorationHandler];
return YES;
}3D Touch
Availability
This feature is only on iPhones 6s and up. This includes the 6s, 6s Plus, 7, and 7 Plus.
- 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 login
If you'd like to enable Facebook login, please
follow the setup instructions.
Present the store
There are three types of apps you might be creating.
Modal presentation
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.
- Objective-C
[PayPalCommerce presentModalStore];Tight UI integration
If you want to integrate the store UI more tightly with your own app, you can use the embedded view
controller via:
- Objective-C
UIViewController *paypalCommerceViewController = [PayPalCommerce paypalCommerceRootViewController];- Objective-C
tabViewController.viewControllers = @[infoVC, paypalCommerceViewController, aboutVC];Standalone store
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.
- Objective-C
[PayPalCommerce presentStoreApp];