Initialize the SDK

Follow these steps to add the PayPal Mobile Checkout SDK to your mobile app

SDKLast updated: September 6th 2023, @ 12:43:42 pm


Know before you code

  • Complete the steps in Get started to set up your PayPal account, client ID, and sandbox emails for testing.

  • To integrate the SDK, complete the steps on this page, then navigate to Server-side integration

  • The PayPal Mobile Checkout SDK uses scopes from the Identity API.

    Note: Before going live, PayPal must review your app to approve the sharing of customer data. The review automatically starts once you select the Log in with PayPal checkbox on your Developer Dashboard (Step 3 of Enable the SDK).

    The sandbox app reviews are typically complete within 2 hours. The live app reviews take 2 to 10 business days.

Enable the SDK

  1. Log into your PayPal Developer Dashboard.

  2. Select your app from the My Apps & Credentials page on the Developer Dashboard.

  3. Under Sandbox App Setting, select the Log in with PayPal checkbox. Select the Log in with PayPal checkbox and the Full name and Email checkboxes found within the Advanced settings. These are the scopes of the Identity API.

  4. The SDK is enabled.

Add the SDK to your app

Add the SDK to your app using your preferred installation method:

Note: For the easiest installation, we recommend using CocoaPods.

CocoaPods

  1. Add the following to your Podfile:

    pod 'PayPalCheckout'
    
  2. Run pod install or pod update.

Carthage

  1. Add the following to your Cartfile:

    binary "https://github.com/paypal/paypalcheckout-ios/raw/main/Carthage/PayPalCheckout.json"
    
  2. Download the binaries using the following command:

    carthage update --platform iOS
    
  3. Link the .framework file from the /Carthage/Build/iOS directory into your specified target:

Linked Frameworks

Note: This embeds PayPalCheckout.

Swift Package Manager

If you're working in the context of another package, add the latest SDK version: GitHub release as a dependency in your Package.swift file:

let package = Package(
    name: "MyPackage",
    dependencies: [
        .package(url: "https://github.com/paypal/paypalcheckout-ios.git", from: "x.x.x"),
    ],
    ...
)

If you're adding the SDK into a standalone project, follow Apple's package integration guide, while specifying https://github.com/paypal/paypalcheckout-ios.git as the source Git repository. The changelog provides details on the most recent versions.

GitHub

If you prefer to install the SDK without using a package manager, retrieve the framework and xcframework binaries from the release tags in our GitHub repository.

Configure the SDK

Create an instance of CheckoutConfig, and pass it to the top level Checkout type of the SDK. Once that is completed, the SDK is configured and your app is ready to add payment buttons that will be displayed on your app.

Sample code

Configures the PayPal Mobile Checkout SDK in your app. Once that is completed, the SDK is configured and your app is ready to add payment buttons that will be displayed on your app.

Providing applicationContext allows for customizing different properties, such as shipping preference, payment method preference, brand name, user action, and more.

  1. Swift
  2. Obj-C
1func configurePayPalCheckout() {
2 let config = CheckoutConfig(
3 clientID: "YOUR_CLIENT_ID",
4 createOrder: { action in
5 let orderRequest = OrderRequest.init(
6 intent: .capture,
7 purchaseUnits: [
8 PurchaseUnit(
9 amount: PurchaseUnit.Amount(
10 currencyCode: .usd, value: "10.00"
11 )
12 )
13 ],
14 applicationContext: OrderApplicationContext(userAction: .payNow)
15 )
16 action.create(order: orderRequest)
17 }
18 },
19 environment: .sandbox
20 )
21 Checkout.set(config: config)
22}

Create and capture orders

You have two options to complete your integration:

Integration typeUse case
Client-side integrationIf want the simplest integration, continue with the sample code below for a client-side integration. Client-side integrations don't require you to create your own backend infrastructure.
Server-side integrationChose a server-side integration if you want more control over your integration. Server-side integrations require you to have your own backend infrastructure.

Client-Side Integration: Sample Code

This sample code creates an order of a single item for $10.00 USD. When the buyer selects Pay Now on a payment sheet, the onApprove callback invokes.

  1. Swift
  2. Obj-C
1import PayPalCheckout
2class ViewController: UIViewController {
3 override func viewDidLoad() {
4 super.viewDidLoad()
5 configurePayPalCheckout()
6 addPayPalButtons()
7 }
8 // MARK: PayPal Checkout
9 private func configurePayPalCheckout() {
10 Checkout.setCreateOrderCallback { action in
11 let amount = PurchaseUnit.Amount(currencyCode: .usd, value: "10.00")
12 let purchaseUnit = PurchaseUnit(amount: amount)
13 let order = OrderRequest(intent: .capture, purchaseUnits: [purchaseUnit])
14 action.create(order: order)
15 }
16 Checkout.setOnApproveCallback { approval in
17 print("Order ID: (approval.data.orderId)")
18 }
19 }
20 }
21 private func addPayPalButtons() {
22 let container = PaymentButtonContainer()
23 view.addSubview(container)
24 NSLayoutConstraint.activate(
25 [
26 container.centerYAnchor.constraint(equalTo: view.centerYAnchor),
27 container.centerXAnchor.constraint(equalTo: view.centerXAnchor)
28 ]
29 )
30 }
31}

Note: For more information about creating orders, including additional parameters that can be submitted, view Orders REST API.

Step result

You can now test purchases.

Test and go live

  • Use your client ID when adding the PayPal Mobile Checkout SDK to your app.
  • Use your sandbox accounts when testing the SDK.
  • The SDK may prompt buyers to log in with a one-time passcode sent by SMS to their phone number.
  • Sandbox accounts with a confirmed phone number and US as the selected country will always prompt the buyer to log in with a one-time passcode.
  • When testing the SDK with sandbox accounts, enter 111111 as the one-time passcode.

Next Step

Launch SDK