Code Monkey home page Code Monkey logo

react-native-braintree's Introduction

Published Version Package Version Android SDK iOS SDK
npm v2.4.0 28 12.0

@ekreative/react-native-braintree

Getting started

Android Specific

Add this to your build.gradle

allprojects {
    repositories {
        maven {
            // Braintree 3D Secure
            // https://developer.paypal.com/braintree/docs/guides/3d-secure/client-side/android/v4#generate-a-client-token
            url "https://cardinalcommerceprod.jfrog.io/artifactory/android"
            credentials {
                username 'braintree_team_sdk'
                password 'AKCp8jQcoDy2hxSWhDAUQKXLDPDx6NYRkqrgFLRc3qDrayg6rrCbJpsKKyMwaykVL8FWusJpp'
            }
        }
    }
}

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

Also, add this intent-filter to your main activity in AndroidManifest.xml

<activity>
    ...
    <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>

NOTE: Card payments do not work on rooted devices and Android Emulators

If your project uses Progurad, add the following lines into proguard-rules.pro file

-keep class com.cardinalcommerce.dependencies.internal.bouncycastle.**
-keep class com.cardinalcommerce.dependencies.internal.nimbusds.**
-keep class com.cardinalcommerce.shared.**

iOS Specific

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:

<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:

#import "BraintreeCore.h"

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

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

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

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

Usage

Show PayPall module
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));
Card tokenization
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
import RNBraintree from '@ekreative/react-native-braintree';

RNBraintree.run3DSecureCheck({
    // Optional if you ran `tokenizeCard()` or other Braintree methods before
    clientToken: 'CLIENT_TOKEN_GENERATED_ON_SERVER_SIDE',
    nonce: 'CARD_NONCE',
    amount: '122.00',
    // Pass as many of the following fields as possible, but they're optional
    email: '[email protected]',
    firstname: '',
    lastname: '',
    phoneNumber: '',
    streetAddress: '',
    streetAddress2: '',
    city: '',
    region: '',
    postalCode: '',
    countryCode: ''
    })
    .then(result => console.log(result))
    .catch((error) => console.log(error));
Request PayPal billing agreement
import RNBraintree from '@ekreative/react-native-braintree';

RNBraintree.requestPayPalBillingAgreement({
    clientToken: 'CLIENT_TOKEN_GENERATED_ON_SERVER_SIDE',
    description: 'BILLING_AGRREEMENT_DESCRIPTION',
    localeCode: 'LOCALE_CODE'
    })
    .then(result => console.log(result))
    .catch((error) => console.log(error));

iOS

Check if Apple Pay is available
import RNBraintree from '@ekreative/react-native-braintree';

console.log(RNBraintree.isApplePayAvailable())
Make payment using Apple Pay
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
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));

TODO

  • Android. Check if we can split the logic in the getDeviceData method to call new DataCollector(mBraintreeClient).collectDeviceData() only once (it seems like it's currently may be called a second time from the setup method) #37 (comment)
  • iOS. Try to use the new getDeviceData method in other methods, such as tokenizeCard, showPayPalModule #37 (comment)

Useful Links and Resources

If you want to read further you can follow these links

Contributors

react-native-braintree's People

Contributors

ad-astra-per-ardua avatar aris-paskalov avatar audrius-sav avatar bohdanrybakek avatar dakshsinghrathore avatar georgioupanayiotis avatar hollister009 avatar irkenstudio avatar lytvynserhii avatar mikeprus avatar serhiilytvynek avatar stelmakhivan avatar vasylnahuliak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-braintree's Issues

'BraintreeCore.h' file not found

▸ Compiling react-native-braintree-dummy.m
▸ Compiling RNBraintreeApplePay.m
▸ Compiling RNBraintree.m

❌  /Users/boblin/Desktop/WorkSpace/ReactNative/ignite/moon/node_modules/@ekreative/react-native-braintree/ios/RNBraintree.m:2:9: 'BraintreeCore.h' file not found

#import "BraintreeCore.h"

environment

    "react": "18.0.0",
    "react-native": "0.69.6",
    "@ekreative/react-native-braintree": "^1.3.0",

Add links in README

BrainTree/Apple uses deprecated fields

I believe this package is using an old version for Braintree/Apple which has some deprecated fields in it and that is crashing on ios.
I tested on a bareflow latest react native project (0.70.6) and I am having the below error, can someone guide me?

Screenshot 2022-12-13 at 3 01 13 PM

Add Cache to CI/CD

Problem

For now, CI/CD is working without a cache. So, each time it installs node_modules even if there are no changes made.

Solution

There is a cache option in setup-node action so we can turn on it.

Links

BUG: Installation error

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Error with pod install

CocoaPods could not find compatible versions for pod "Braintree/ApplePay":
In Podfile:
react-native-braintree (from ../node_modules/@ekreative/react-native-braintree) was resolved to 2.5.0, which depends on
Braintree/ApplePay

Record

  • I agree to follow this project's Code of Conduct
  • I want to work on this issue

Google Play Error: SDK: Braintree Payments com.braintreepayments.api:data-collector (consider upgrading to version 4.31.0)

Hi,

We are using the latest version of the @ekreative/react-native-braintree in our app. I recently submitted a build of an app to Google Play Store. The app got rejected giving the following reason:

**Issue found: Violation of User Data policy

We reviewed SDKs used by your app and found noncompliant version(s) of SDK(s) which collects persistent device identifiers. Persistent device identifiers may not be linked to other personal and sensitive user data or resettable device identifiers.

Issue details

We found an issue in the following area(s):

SPLIT_BUNDLE 28: :
SDK: Braintree Payments com.braintreepayments.api:data-collector (consider upgrading to version 4.31.0)

Additionally, follow these steps to bring your app into compliance:

You may consider upgrading to a policy-compliant version of this SDK, if available from your SDK provider or removing the SDK.**

I've been submitting builds for this app for the last 18 months without issue until this week where it's been rejected. The User Data Policy on Google Play store had been updated recently.

Is there any way to upgrade the plugin to use version 4.31.0 of com.braintreepayments.api:data-collector as suggested?

Thanks

Add Native SDK versions in README

Add the table with Native SDK versions for all react-native-braintree releases with changed version

For example:

Package Version Android SDK iOS SDK
1.0.0 x.y.z x.y.z

Production steps to enable apple and google pay

What's wrong with the existing documentation

In stage environment the apple pay and google pay is working but in production both of them are not. Can someone explain to me what else i should do to enable them;
I have enable the options in my braintree panel and i have perform the steps for the ios certification files..

Google play is throwing an OR_BIBED_11 error and apple pay is throwing an error unable to decrypt.

can someone help? maybe some instructions or links how to enable these payments?

Add ScreenShots

No response

Record

  • I agree to follow this project's Code of Conduct
  • I want to work on this issue

Upgrade NodeJS version

The current version is v14 but this version is deprecated.

Please, do investigate what we can break.

not an object

Hi, i'm using your library witj expo react and that not work.
I show you the error:
TypeError: null is not an object (evaluating 'RNBraintree.showPayPalModule') at node_modules\react-native\Libraries\LogBox\LogBox.js:148:8 in registerError at node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl at node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error at node_modules\react-native\Libraries\Core\ExceptionsManager.js:104:6 in reportException at node_modules\react-native\Libraries\Core\ExceptionsManager.js:171:19 in handleException at node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError at node_modules\expo-error-recovery\build\ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0 at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:293:29 in invoke at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:154:27 in invoke at node_modules\regenerator-runtime\runtime.js:164:18 in PromiseImpl.resolve.then$argument_0 at node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne at node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0 at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0 at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue at [native code]:null in flushedQueue at [native code]:null in invokeCallbackAndReturnFlushedQueue

paypal is not linked

[Error: PayPal is not enabled. See https://developer.paypal.com/braintree/docs/guides/paypal/overview/android/v4 for more information.]

Could not find org.jfrog.cardinalcommerce.gradle:cardinalmobilesdk:

Issue code

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:processDevelopmentDebugResources'.
> Could not resolve all task dependencies for configuration ':app:developmentDebugRuntimeClasspath'.
   > Could not find org.jfrog.cardinalcommerce.gradle:cardinalmobilesdk:2.2.7-2.
     Searched in the following locations:
       - https://oss.sonatype.org/content/repositories/snapshots/org/jfrog/cardinalcommerce/gradle/cardinalmobilesdk/2.2.7-2/cardinalmobilesdk-2.2.7-2.pom
       - https://repo.maven.apache.org/maven2/org/jfrog/cardinalcommerce/gradle/cardinalmobilesdk/2.2.7-2/cardinalmobilesdk-2.2.7-2.pom
       - file:/Users/*****/projects/*****/node_modules/jsc-android/dist/org/jfrog/cardinalcommerce/gradle/cardinalmobilesdk/2.2.7-2/cardinalmobilesdk-2.2.7-2.pom
       - https://dl.google.com/dl/android/maven2/org/jfrog/cardinalcommerce/gradle/cardinalmobilesdk/2.2.7-2/cardinalmobilesdk-2.2.7-2.pom
       - https://www.jitpack.io/org/jfrog/cardinalcommerce/gradle/cardinalmobilesdk/2.2.7-2/cardinalmobilesdk-2.2.7-2.pom
     Required by:
         project :app > project :ekreative_react-native-braintree > com.braintreepayments.api:three-d-secure:4.27.2

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDevelopmentDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:processDevelopmentDebugResources'.
> Could not resolve all task dependencies for configuration ':app:developmentDebugRuntimeClasspath'.
   > Could not find org.jfrog.cardinalcommerce.gradle:cardinalmobilesdk:2.2.7-2.
     Searched in the following locations:
       - https://oss.sonatype.org/content/repositories/snapshots/org/jfrog/cardinalcommerce/gradle/cardinalmobilesdk/2.2.7-2/cardinalmobilesdk-2.2.7-2.pom
       - https://repo.maven.apache.org/maven2/org/jfrog/cardinalcommerce/gradle/cardinalmobilesdk/2.2.7-2/cardinalmobilesdk-2.2.7-2.pom
       - file:/Users/*****/projects/*****/node_modules/jsc-android/dist/org/jfrog/cardinalcommerce/gradle/cardinalmobilesdk/2.2.7-2/cardinalmobilesdk-2.2.7-2.pom
       - https://dl.google.com/dl/android/maven2/org/jfrog/cardinalcommerce/gradle/cardinalmobilesdk/2.2.7-2/cardinalmobilesdk-2.2.7-2.pom
       - https://www.jitpack.io/org/jfrog/cardinalcommerce/gradle/cardinalmobilesdk/2.2.7-2/cardinalmobilesdk-2.2.7-2.pom
     Required by:
         project :app > project :ekreative_react-native-braintree > com.braintreepayments.api:three-d-secure:4.27.2

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s

react-native info

System:
    OS: macOS 13.3.1
    CPU: (12) arm64 Apple M2 Pro
    Memory: 59.53 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.20.0 - ~/.nvm/versions/node/v16.20.0/bin/node
    Yarn: 1.22.10 - /opt/homebrew/bin/yarn
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.0/bin/npm
    Watchman: 2023.06.12.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.2 AI-222.4459.24.2221.10121639
    Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.19 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0
    react-native: 0.71.11 => 0.71.11
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
        maven { url 'https://maven.google.com' }
        maven { url "https://www.jitpack.io" }
        maven {
            url "https://cardinalcommerceprod.jfrog.io/artifactory/android"
            credentials {
                username 'braintree_team_sdk'
                password 'AKCp8jQcoDy2hxSWhDAUQKXLDPDx6NYRkqrgFLRc3qDrayg6rrCbJpsKKyMwaykVL8FWusJpp'
            }
        }
    }

    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }
}

Error in the run3DSecureCheck function

Hi all,
while executing the run3DSecureCheck function, we got this error:

[Error: {"error":{"message":"Record not found"},"fieldErrors":[]}]

How to reproduce it:

  • just try with the example on the docs
  • OS: Android API target 31

RNBraintree.run3DSecureCheck({
    clientToken: 'CLIENT_TOKEN_GENERATED_ON_SERVER_SIDE', -> we replaced the clientToken here
    nonce: 'CARD_NONCE',
    amount: '122.00',
    email: '[email protected]',
    firstname: '',
    lastname: '',
    phoneNumber: '',
    streetAddress: '',
    streetAddress2: '',
    city: '',
    region: '',
    postalCode: '',
    countryCode: ''
    })
    .then(result => console.log(result))
    .catch((error) => console.log(error));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.