An effort to merge react-native-braintree and react-native-braintree-android
You can use the React Native CLI to add native dependencies automatically:
$ react-native link
or do it manually as described below:
- Run
npm install react-native-braintree-xplat --save
- Open your project in XCode, right click on
Libraries
and clickAdd Files to "Your Project Name"
Look undernode_modules/react-native-braintree-xplat
and addRCTBraintree.xcodeproj
. - Add
libRCTBraintree.a
toBuild Phases -> Link Binary With Libraries
- Done!
Run npm install react-native-braintree-xplat --save
In android/settings.gradle
...
include ':react-native-braintree-xplat'
project(':react-native-braintree-xplat').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-braintree-xplat/android')
In android/app/build.gradle
...
dependencies {
...
compile project(':react-native-braintree-xplat')
}
Register module (in MainApplication.java
)
import com.pw.droplet.braintree.BraintreePackage; // <--- Import Package
import android.content.Intent; // <--- Import Intent
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new BraintreePackage() // <--- Initialize the package
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
In android/settings.gradle
...
include ':react-native-braintree-xplat'
project(':react-native-braintree-xplat').projectDir = file('../node_modules/react-native-braintree-xplat/android')
In android/app/build.gradle
...
dependencies {
...
compile project(':react-native-braintree-xplat')
}
Register module (in MainActivity.java
)
import com.pw.droplet.braintree.BraintreePackage; // <--- Import Package
import android.content.Intent; // <--- Import Intent
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "example";
}
/**
* Returns whether dev mode should be enabled.
* This enables e.g. the dev menu.
*/
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new BraintreePackage() // <--- Initialize the Package
);
}
}
var BTClient = require('react-native-braintree-xplat');
BTClient.setup(<token>);
You can find a demo client token here.
v.zero
BTClient.showPaymentViewController(options).then(function(nonce) {
//payment succeeded, pass nonce to server
})
.catch(function(err) {
//error handling
});
Options (iOS only)
- bgColor - Background color for the view.
- tintColor - Tint color for the view.
- barBgColor - Background color for the navbar.
- barTintColor - Tint color for the navbar.
- callToActionText - Text for call to action button. (Works for both Android and iOS)
Example:
const options = {
bgColor: '#FFF',
tintColor: 'orange',
callToActionText: 'Save'
}
PayPal only (iOS only)
BTClient.showPayPalViewController().then(function(nonce) {
//payment succeeded, pass nonce to server
})
.catch(function(err) {
//error handling
});
If you only want to tokenize credit card information, you can use the following:
BTClient.getCardNonce("4111111111111111", "10", "20", "400").then(function(nonce) {
//payment succeeded, pass nonce to server
})
.catch(function(err) {
//error handling
});
Big thanks to @alanhhwong and @surialabs for the original ios & android modules.