Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
build: move files from private repo
Browse files Browse the repository at this point in the history
  • Loading branch information
vasylnahuliak committed Jun 8, 2021
1 parent d2f8a04 commit 517ed42
Show file tree
Hide file tree
Showing 13 changed files with 889 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ project.xcworkspace
build/
.idea
.gradle
gradle/
local.properties
*.iml

Expand Down
162 changes: 155 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,165 @@
# react-native-braintree
# @ekreative/react-native-braintree

## Getting started

`$ npm install react-native-braintree --save`
## Android Specific
Add this to your `build.gradle`

### Mostly automatic installation
```groovy
repositories {
maven {
url "https://cardinalcommerce.bintray.com/android"
credentials {
username 'braintree-team-sdk@cardinalcommerce'
password '220cc9476025679c4e5c843666c27d97cfb0f951'
}
}
}
```

In Your `AndroidManifest.xml`, `android:allowBackup="false"` can be replaced `android:allowBackup="true"`, it is responsible for app backup.

## iOS Specific
```bash
cd ios
pod install
```
###### Configure a new URL scheme
Add a bundle url scheme {BUNDLE_IDENTIFIER}.payments in your app Info via XCode or manually in the Info.plist. In your Info.plist, you should have something like:

```xml
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.myapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.myapp.payments</string>
</array>
</dict>
</array>
```
###### Update your code
In your `AppDelegate.m`:

```objective-c
#import "BraintreeCore.h"

...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[BTAppSwitch setReturnURLScheme:self.paymentsURLScheme];
}

- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

if ([url.scheme localizedCaseInsensitiveCompare:self.paymentsURLScheme] == NSOrderedSame) {
return [BTAppSwitch handleOpenURL:url options:options];
}

return [RCTLinkingManager application:application openURL:url options:options];
}

- (NSString *)paymentsURLScheme {
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
return [NSString stringWithFormat:@"%@.%@", bundleIdentifier, @"payments"];
}
```

`$ react-native link react-native-braintree`

## Usage

##### Show PayPall module

```javascript
import RNBraintree from 'react-native-braintree';
import RNBraintree from '@ekreative/react-native-braintree';

RNBraintree.showPayPalModule({
clientToken: 'CLIENT_TOKEN_GENERATED_ON_SERVER_SIDE',
amount: '1.0',
currencyCode: 'EUR'
})
.then(result => console.log(result))
.catch((error) => console.log(error));


// TODO: What to do with the module?
RNBraintree;
```

##### Card tokenization
```javascript
import RNBraintree from '@ekreative/react-native-braintree';

RNBraintree.tokenizeCard({
clientToken: 'CLIENT_TOKEN_GENERATED_ON_SERVER_SIDE',
number: '1111222233334444',
expirationMonth: '11',
expirationYear: '24',
cvv: '123',
postalCode: '',
})
.then(result => console.log(result))
.catch((error) => console.log(error));

```
##### Make Payment
```javascript
import RNBraintree from '@ekreative/react-native-braintree';

RNBraintree.run3DSecureCheck({
clientToken: 'CLIENT_TOKEN_GENERATED_ON_SERVER_SIDE',
nonce: 'CARD_NONCE',
amount: '122.00',
email: 'email@mail.com',
firstname: '',
lastname: '',
phoneNumber: '',
streetAddress: '',
streetAddress2: '',
city: '',
region: '',
postalCode: '',
countryCode: ''
})
.then(result => console.log(result))
.catch((error) => console.log(error));

```
### iOS
##### Get if Apple Pay available
```javascript
import RNBraintree from '@ekreative/react-native-braintree';

console.log(RNBraintree.isApplePayAvailable())
```
##### Make payment using Apple Pay
```javascript
import RNBraintree from '@ekreative/react-native-braintree';

RNBraintree.runApplePay({
clientToken: 'CLIENT_TOKEN_GENERATED_ON_SERVER_SIDE',
companyName: 'Company',
amount: '100.0',
currencyCode: 'EUR'
})
.then(result => console.log(result))
.catch((error) => console.log(error));
```
### Android
##### Make payment using Google Pay
```javascript
import RNBraintree from '@ekreative/react-native-braintree';

RNBraintree.runGooglePay({
clientToken: 'CLIENT_TOKEN_GENERATED_ON_SERVER_SIDE',
amount: '100.0',
currencyCode: 'EUR'
})
.then(result => console.log(result))
.catch((error) => console.log(error));
```
11 changes: 11 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ buildscript {
if (project == rootProject) {
repositories {
google()
jcenter()
}
dependencies {
// This should reflect the Gradle plugin version used by
Expand Down Expand Up @@ -66,12 +67,22 @@ repositories {
// Android JSC is installed from npm
url "$rootDir/../node_modules/jsc-android/dist"
}
maven {
url "https://cardinalcommerce.bintray.com/android"
credentials {
username 'braintree-team-sdk@cardinalcommerce'
password '220cc9476025679c4e5c843666c27d97cfb0f951'
}
}
google()
jcenter()
}

dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation 'com.braintreepayments.api:drop-in:4.6.0'
implementation 'com.google.android.gms:play-services-wallet:18.1.2'
}

def configureReactNativePom(def pom) {
Expand Down
12 changes: 12 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ekreative.reactnativebraintree">

<application >
<meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true"/>
<activity android:name="com.braintreepayments.api.BraintreeBrowserSwitchActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="${applicationId}.braintree" />
</intent-filter>
</activity>
</application>
</manifest>
Loading

0 comments on commit 517ed42

Please sign in to comment.