PayPal Mobile Checkout

SetupAnchorIcon

Before you can add the PayPal Mobile Checkout, you will need to:

  1. Create, verify, and link your PayPal account in the Braintree Control Panel
  2. Obtain either a client token or tokenization key and setup your client

Using a custom UIAnchorIcon

PayPal Mobile Checkout is currently only available via a custom UI and cannot be used with the Drop-in UI. Implement a custom button to start the PayPal Native UI flow.

  1. Swift
var braintreeClient: BTAPIClient!

override func viewDidLoad() {
    super.viewDidLoad()
    self.braintreeClient = BTAPIClient(authorization: "<#CLIENT_AUTHORIZATION#>")

    let customPayPalButton = UIButton(frame: CGRect(x: 0, y: 0, width: 60, height: 120))
    customPayPalButton.addTarget(self, action: #selector(customPayPalButtonTapped(button:)), for: .touchUpInside)
    self.view.addSubview(customPayPalButton)
}

func customPayPalButtonTapped(button: UIButton) {
    // Launch the PayPal Mobile Checkout flow
}

Get the SDKAnchorIcon

The PayPal Mobile Checkout module of the Braintree SDK can be pulled into your app via all of the currently supported package managers.

CocoapodsAnchorIcon

In your Podfile, add the dependency for the PayPal Mobile Checkout module:

  1. Ruby
pod 'Braintree/PayPalNativeCheckout'

Swift Package ManagerAnchorIcon

Include the BraintreeeCore, BraintreePayPalNativeCheckout, BraintreePayPal and PayPalDataCollector frameworks.

CarthageAnchorIcon

Include the BraintreeCore, BraintreePayPalNativeCheckout, BraintreePayPal and PayPalDataCollector frameworks.

Invoking the PayPal Native UI FlowAnchorIcon

Create BTAPIClient with a client token or tokenization key. Use BTPayPalNativeCheckoutClient and either a BTPayPalNativeCheckoutRequest or BTPayPalNativeVaultRequest to make your call to BTPayPalNativeCheckoutClient.tokenize(request:completion:) to launch the PayPal Mobile Checkout flow. An amount is required to invoke the one-time payment flow. An example integration might look like this:

  1. Swift
import UIKit
import BraintreePayPalNativeCheckout

class MyViewController: UIViewController {
  var apiClient: BTAPIClient!
  var payPalNativeCheckoutClient: BTPayPalNativeCheckoutClient!

  override func viewDidLoad() {
      super.viewDidLoad()
      self.apiClient = BTAPIClient(authorization: <#CLIENT_AUTHORIZATION#>)
      self.payPalNativeCheckoutClient = BTPayPalNativeCheckoutClient(apiClient: apiClient)
  }

  private func payPalButtonTapped() {
    // One time checkout
    let request = BTPayPalNativeCheckoutRequest(amount: <#AMOUNT_STRING#>)
    
    // OR

    // Billing agreements
    let request = BTPayPalNativeVaultRequest()

    // Configure other values on 'request' as needed.

    payPalNativeCheckoutClient.tokenize(request) { payPalNativeCheckoutNonce, error in
      if let payPalNativeCheckoutNonce = payPalNativeCheckoutNonce { 
          // send payPalNativeCheckoutNonce.nonce to server 
      } else { 
          // handle error
      }
    }
  }
}