React-native integration guide
CardScan React Native installation guide
Visit our website at https://www.getbouncer.com for examples. Native libraries for android and iOS are also available in github.
CardScan is open source, and available under a free-to-try license. See the license section for details.

Installation

1. Install the react-native-cardscan package from NPM

Add a dependency to react-native-cardscan in your package.json file. The latest version of react-native-cardscan can be added to your dependencies automatically by installing the SDK in the same directory as your package.json file.
1
$ npm install react-native-cardscan
Copied!

2. Install the iOS dependencies into your ios directory

Add the CardScan and react-native-cardscan pods to the ~/ios/Podfile file in your app
1
target 'Your App' do
2
...
3
pod 'CardScan'
4
pod 'react-native-cardscan', :path => '../node_modules/react-native-cardscan'
5
end
Copied!
More installation options for iOS can be found in the Installation section of the iOS integration guide.
For react-native version 0.59 and below, follow the linking native dependencies guide.

4. Install the android native library

Note: You will need a username and password to set up these repositories. Please contact [email protected] to request credentials.
Add the CardVerify repository to the android section of your react-native project. In your android/build.gradle file, append the following to repositories:
1
repositories {
2
// ...
3
mavenCentral()
4
}
Copied!
Add the cardverify dependencies to the android section of your react-native project. In your android/app/build.gradle file, append the following to dependencies:
1
dependencies {
2
implementation "com.getbouncer:cardscan-ui:2.1.0004"
3
implementation "com.getbouncer:scan-payment-full:2.1.0004"
4
implementation "com.getbouncer:scan-camerax:2.1.0004"
5
implementation "com.getbouncer:tensorflow-lite:2.1.0004"
6
}
Copied!
Please add the following to your android/app/build.gradle file in the android section:
1
aaptOptions {
2
noCompress "tflite"
3
}
Copied!

Alternative camera implementations

By default, bouncer uses the Android Camera 1 API. To use Camera2 or CameraX, add one of the following imports:
1
implementation "com.getbouncer:scan-camerax:2.1.0004"
2
3
// OR
4
5
implementation "com.getbouncer:scan-camera2:2.1.0004"
Copied!

Configuration

1. Create an API key

Go to the Bouncer API console and create an API key.

2. Configure Android

Open android/app/src/main/java/[...]/MainApplication.java and add the following lines to the end of the onCreate() method.
1
import com.getbouncer.RNCardscanModule;
2
3
// ...
4
5
public class MainApplication extends Application implements ReactApplication {
6
7
// ...
8
9
public void onCreate() {
10
11
// ...
12
13
// set your generated API key
14
RNCardscanModule.apiKey = "<your_api_key_here>";
15
16
// set to true for experimental name extraction
17
RNCardscanModule.enableNameExtraction = false;
18
19
// set to true for experimental expiry extraction
20
RNCardscanModule.enableExpiryExtraction = false;
21
22
// set to true to display an "Enter Card Manually" button
23
RNCardscanModule.enableEnterCardManually = false;
24
}
25
}
Copied!

3. Configure iOS Permissions

CardScan uses the device camera to scan cards, so you'll need to add a description of camera usage to your Info.plist file:
XCode iOS camera permission
The string you add here will be what CardScan displays to your users when CardScan first prompts them for permission to use the camera.
Alternatively, you can add this permission directly to your Info.plist file:
1
<key>NSCameraUsageDescription</key>
2
<string>We need access to your camera to scan your card</string>
Copied!

4. Configure iOS

Swift
Objective C
In your AppDelegate.swift file, Add an import for CardScan, and set your API key.
1
import UIKit
2
import CardScan
3
4
@UIApplicationMain
5
class AppDelegate: UIResponder, UIApplicationDelegate {
6
7
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
8
Bouncer.configure(apiKey: "<your_api_key_here>")
9
// do any other necessary launch configuration
10
return true
11
}
12
}
Copied!
In your AppDelegate.m file, Add an import for CardScan, and set your API key.
1
#import "AppDelegate.h"
2
...
3
@import CardScan;
4
5
@implementation AppDelegate
6
7
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
8
{
9
// ...
10
[ScanViewController configureWithApiKey:@"<your_api_key_here>"];
11
12
return YES;
13
}
Copied!

Using

react-native-cardscan exposes two static methods on the CardScan object, isSupportedAsync() and scan().
To determine if the device supports CardScan, use the isSupportedAsync() method. For example,
1
import Cardscan from 'react-native-cardscan';
2
3
Cardscan.isSupportedAsync()
4
.then(supported => {
5
if (supported) {
6
// YES, show scan button
7
} else {
8
// NO
9
}
10
})
Copied!
To scan a card, use the scan() method. For example,
1
import Cardscan from 'react-native-cardscan';
2
3
Cardscan.scan()
4
.then(({action, payload, canceled_reason}) => {
5
if (action === 'scanned') {
6
const { number, expiryMonth, expiryYear, issuer, legalName } = payload;
7
// Display information
8
} else if (action === 'canceled') {
9
if (canceled_reason === 'enter_card_manually') {
10
// the user elected to enter a card manually
11
} else if (canceled_reason === 'camera_error') {
12
// there was an error with the camera
13
} else if (canceled_reason === 'fatal_error') {
14
// there was an error during the scan
15
} else if (canceled_reason === 'user_canceled') {
16
// the user canceled the scan
17
} else {
18
// the scan was canceled for an unknown reason
19
}
20
} else if (action === 'skipped') {
21
// User skipped
22
} else if (action === 'unknown') {
23
// Unknown reason for scan canceled
24
}
25
})
Copied!

Example app

An example application is included in the react-native-cardscan github repository.
Inside the example directory, you can find an example React Native project that you can run.
To run the example app, do the following:
  • $ cd example
  • $ npm install
  • Add your API key to android/app/src/main/java/com/getbouncer/example/MainApplication.java and ios/example/AppDelegate.m.
  • Point the android app to the SDK: create a file example/android/local.properties with a line
    1
    sdk.dir=<full_path_to_android_sdk>
    Copied!
  • To run Android app: react-native run-android
  • To run iOS app: react-native run-ios

Troubleshooting

See the troubleshooting documentation.

Authors

Adam Wushensky, Sam King, Zain ul Abi Din, Jaime Park, and Stefano Suryanto

License

This library is available under paid and free licenses. See the LICENSE file for the full license text.

Quick summary

In short, this library will remain free forever for non-commercial applications, but use by commercial applications is limited to 90 days, after which time a licensing agreement is required. We're also adding some legal liability protections.
After this period commercial applications need to convert to a licensing agreement to continue to use this library.
Details of licensing (pricing, etc) are available at https://getbouncer.com/pricing, or you can contact us at [email protected].

More detailed summary

What’s allowed under the license:
  • Free use for any app for 90 days (for demos, evaluations, hackathons, etc).
  • Contributions (contributors must agree to the Contributor License Agreement)
  • Any modifications as needed to work in your app
What’s not allowed under the license:
  • Commercial applications using the license for longer than 90 days without a license agreement.
  • Using us now in a commercial app today? No worries! Just email [email protected] and we’ll get you set up.
  • Redistribution under a different license
  • Removing attribution
  • Modifying logos
  • Indemnification: using this free software is ‘at your own risk’, so you can't sue Bouncer Technologies, Inc. for problems caused by this library
Questions? Concerns? Please email us at [email protected] or ask us on slack.
Last modified 1mo ago