PayPal
Client-Side Implementation
The PayPal authorization flow includes PayPal One Touch™, which allows customers to pay by presenting the PayPal website.
Setup
If you are integrating BraintreePayPalNativeCheckout
, please refer to the setup steps in the Native Checkout guide. All other PayPal integrations can use the following setup guide.
Before you can add PayPal:
- Integrate the Braintree iOS SDK into your app
- Create, verify, and link your PayPal account in the Braintree Control Panel
Get the SDK
CocoaPods
Include Braintree
in your podfile:
- Ruby
pod 'Braintree'
Swift Package Manager
Include the BraintreePayPal
and PayPalDataCollector
frameworks.
Carthage
Include the BraintreeCore
,BraintreePayPal
, PayPalDataCollector
, and PPRiskMagnes
frameworks.
Showing a PayPal button
Initiaiting the PayPal authorization flow will present and dismiss an ASWebAuthenticationSession
from your top-most view.
Using our Drop-in UI
When using the Drop-in UI, a PayPal payment option will be shown alongside any other payment methods you've enabled.
For more details, see the Drop-in UI guide.
Using a custom UI
You can implement a custom UI, such as your own PayPal button.
- 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: UIControlEvents.touchUpInside)
self.view.addSubview(customPayPalButton)
}
func customPayPalButtonTapped(button: UIButton) {
let payPalDriver = BTPayPalDriver(apiClient: self.braintreeClient)
// Important! Choose either Vault or Checkout flow
// Start the Vault flow, or...
let vaultRequest = BTPayPalVaultRequest()
payPalDriver.tokenizePayPalAccount(with: vaultRequest) { (tokenizedPayPalAccount, error) in
// ...
}
// ...start the Checkout flow
let checkoutRequest = BTPayPalCheckoutRequest(amount: "1.00")
payPalDriver.tokenizePayPalAccount(with: checkoutRequest) { (tokenizedPayPalAccount, error) in
// ...
}
}
Collecting additional data
You can gather additional data about your customers as they complete the payment process.
Next: Choose your integration
The rest of your configuration will be determined by how you'd like to use PayPal.
- Want easy payments for repeat customers? Have a subscription model? Use our Vault.
- Want a one-time payment checkout? Use Checkout with PayPal.
See a detailed comparison of Vault vs. Checkout.
Next Page: Vault →