React Native library that implements PayPal Checkout flow using purely native code (swift).
npm install react-native-paypal-swift or `yarn add react-native-paypal-swift`
- [iOS] Add
pod 'Braintree', '~> 4'
andpod 'Braintree/DataCollector'
to your Podfile. - [iOS] Run
pod install
- [iOS] Register a URL scheme in Xcode (must always start with your Bundle Identifier and end in
.payments
- e.g.your.app.id.payments
). See details here. - [iOS] Edit your
AppDelegate.m
as follows:#import "BraintreeCore.h" #import "BraintreePayPal.h" #import "BTDataCollector.h" - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier]; NSString *urlscheme = [NSString stringWithFormat:@"%@.payments", bundleIdentifier]; URLScheme = urlscheme; BTAppSwitch setReturnURLScheme:urlscheme]; } // if you support only iOS 9+, add the following method - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([url.scheme localizedCaseInsensitiveCompare:URLScheme] == NSOrderedSame) { return [BTAppSwitch handleOpenURL:url sourceApplication:sourceApplication]; } return NO; } // otherwise, if you support iOS 8, add the following method - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { if ([url.scheme localizedCaseInsensitiveCompare:URLScheme] == NSOrderedSame) { return [BTAppSwitch handleOpenURL:url options:options]; } return NO; }
At this point you should be able to build both Android and iOS.
First you need to get a valid token from your server. Refer to this.
Then you can execute the following code, for example reacting to a button press.
import {Paypal} from "react-native-paypal-swift";
// ...
Paypal.requestOneTimePayment((result : string) => console.log({ result }));
Note that the client token should be served via a backend service but can be hardcoded:
- Go to https://www.braintreegateway.com or https://sandbox.braintreegateway.com/ and login or create an account
- Click the gear at the top and select to API
- You can find your token under
Tokenization Keys
. You will need to create one if none exists
For an overview of the braintree payment flow see https://developers.braintreepayments.com/start/overview
This library covers the client setup here: https://developers.braintreepayments.com/start/hello-client
It does NOT however cover the server portion here: https://developers.braintreepayments.com/start/hello-server
You will need the server portion in order to complete your transactions. See a simple example of this server in /exampleServer. The example app is pointed to this on default
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT