Client-side Implementation
- Create, verify, and link your PayPal account in the Braintree Control Panel
- Integrate the Braintree iOS SDK and obtain your client token
Invoke PayPal Order flow
You can provide your own button that starts the PayPal Order flow.
- 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);
// Start the Checkout flow
let payPalRequest = BTPayPalCheckoutRequest(amount: "1.00");
payPalRequest.currencyCode = "USD"; // Optional; see BTPayPalCheckoutRequest.h for more options
// Specify the intent on the request object
payPalRequest.intent = .order;
payPalDriver.tokenizePayPalAccount(with: payPalRequest) { (tokenizedPayPalAccount, error) -> Void in
// ...
};
}