iOS UI classes for adding PayPal as a Braintree payment option.
This project provides two primary classes:
BTPayPalViewController
is aUIViewController
that provides the PayPal authentication UX and – on successful auth – a resulting transactable payment method.BTPayPalButton
is aUIControl
that you can use to offer PayPal as a payment option to your user. It can be used by adding it to your view hierarchy and setting delegate methods. (Deprecated - please seeBTPaymentButton
in the Payments subspec)
This library depends on Braintree/API
, which provides BTClient
, used as an initialization parameter for both of the above.
Out of the box, BTPayPalButton
is automatically configured to present a BTPayPalViewController
when the user taps it. This means that you are not required to override the BTPayPalButton
's delegate.
Please note: If the default behavior is not compatible with your views, you can implement a
custom BTPayPalButtonViewControllerPresenterDelegate
.
Use CocoaPods and add the following to your Podfile
:
pod 'Braintree/PayPal'
CocoaPods automatically vendors the PayPal Mobile SDK, libPayPalMobile-BT.a
, which is included. Braintree-PayPal-iOS is not compatible with the PayPal Mobile SDK.
A straightforward integration approach is to just add a BTPayPalButton
instance in your view hierarchy, then implement its BTPayPalButtonDelegate
to receive results. Rough example:
- Create an instance of
BTPayPalButton
either in your xib or storyboard or initialized in code and added as a subview, e.g.
- (void)viewDidLoad {
self.payPalButton = [[BTPayPalButton alloc] init];
[self.view addSubview:self.payPalButton];
}
- Set the
client
anddelegate
properties of yourBTPayPalButton
instance, e.g.
self.payPalButton.client = [[BTClient alloc] initWithClientToken:MY_CLIENT_TOKEN];
self.payPalButton.delegate = self;
- Implement the required
BTPayPalButtonDelegate
protocol methods:
- (void)payPalButton:(BTPayPalButton *)button addedPaymentMethod:(NSString *)paymentMethod {
NSLog(@"Payment method %@ obtained and is ready for use", paymentMethod);
// Send paymentMethod to your server for use...
}
- (void)payPalButtonRemovedPaymentMethod:(BTPayPalButton *)button {
NSLog(@"Payment method was removed");
}
- Optional:
BTPayPalButton
handles presentation of aBTPayPalViewController
out of the box, but you can change the presentation by implementing an additional optionalBTPayPalButtonViewControllerPresenterDelegate
method and setting thepresentationDelegate
property:
- (void)payPalButton:(BTPayPalButton *)button requestsPresentationOfViewController:(UIViewController *)viewController {
// Use your own presentation code here, e.g.
[self.navigationController pushViewController:viewController];
}