A SDK that provides an interface to scan different types of payment cards with various ways and contexts.
To use the SDK the following requirements must be met:
- Android Studio 3.6 or newer
- **Android SDK Tools 29.0.0 ** or newer
- **Android Platform Version: API 29: Android 10.0 (Q)
- **Android targetSdkVersion: 29
- Clone TapCardScannerKit library from Tap repository
[email protected]:Tap-Payments/TapCardScannerKit-Android.git
- Add TapCardScannerKit library to your project settings.gradle file as following
include ':cardscanner', ':YourAppName'
- Setup your project to include cardscanner as a dependency Module.
- File -> Project Structure -> Modules -> << your project name >>
- Dependencies -> click on + icon in the screen bottom -> add Module Dependency
- select cardscanner library
JitPack is a novel package repository for JVM and Android projects. It builds Git projects on demand and provides you with ready-to-use artifacts (jar, aar).
To integrate TapCardScannerKit into your project add it in your root build.gradle
at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
}
TapCardScannerKit-Android provides extensive ways for scanning payment cards whether:
-
Embossed cards:
i. Cards that has digits and letters raised and well crafted.
ii. Examples: Visa , Mastercard , Amex
iii. For more info check : Embossed Card Explaination
-
Unembossed cards:
i. Cards where the numbers on the card are not raised up like a normal card. It is perfectly flat, with everything just printed on the card.
ii. Examples:Some types of Visa , KNET in Kuwait, MADA in KSA
iii. For more info check: Unembossed Card Explaination.
The kit provides an asyncronous offline way to scan cards from a camera feed right away in your app. This works great in case of scanning embossed cards. The Kit provides following options:
- Full screen card scanner.
- Inline card scanner.
- Image Decoder.
- ScanCardIntent handles opening of the scanner and returning back the result to the client after scanning. Below is the sample to call ScanCardIntent.
Intent intent = new ScanCardIntent.Builder(this).build();
startActivityForResult(intent, SCAN_CARD_ID);
- Handling of the ScanCard by getting the parcelablextra through ScanCardIntent.RESULT_PAYCARDS_CARD :
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case SCAN_CARD_ID:
if (resultCode == Activity.RESULT_OK) {
Card card = data.getParcelableExtra(ScanCardIntent.RESULT_PAYCARDS_CARD);
cardNumber.setText(card.getCardNumber());
cardHolder.setText(card.getCardHolderName());
expirationDate.setText(card.getExpirationDate());
}
break;
- InlineViewFragment is responsible for opening the scanner in a specified view set by the client. The InlineViewFragment will follow the configuration set by the parent activity or fragment.
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.inline_container, new InlineViewFragment())
.commit();
- To handle the scanresult of InlineViewFragment implement your activity or fragment with interface InlineViewCallback which generates the methods as below :
@Override
public void onScanCardFailed(Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
@Override
public void onScanCardFinished(Card card, byte[] cardImage) {
removeInlineScanner();
cardNumber.setText(card.getCardNumber());
cardHolder.setText(card.getCardHolderName());
expirationDate.setText(card.getExpirationDate());
}
This feature allows user to scan unembossed cards as well as choose images from the gallery.It uses TapTextRecognitionML that automates reading of credit cards, which also extracts text from pictures of documents.
- Declare the TapTextRecognitionML in your activity or fragment as shown:
private TapTextRecognitionML textRecognitionML;
- Initialize the TapTextRecognitionML as below:
textRecognitionML = new TapTextRecognitionML(this);
3.Decode the image from the bitmap as shown
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case PICK_IMAGE_ID:
Bitmap bitmap = ImagePicker.getImageFromResult(this, resultCode, data);
textRecognitionML.decodeImage(bitmap);
break;
- To handle the scannned result from the textRecognitionML implement the class with TapTextRecognitionCallBack which generates methods as below:
@Override
public void onRecognitionSuccess(TapCard card) {
cardNumber.setText(card.getCardNumber());
cardHolder.setText(card.getCardHolder());
expirationDate.setText(card.getExpirationDate());
}
@Override
public void onRecognitionFailure(String error) {
Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
}
This feature allows user to close the view automatically without manual interaction. The user can set the timer as per the choice as below:
final TapCountDownTimer counter = new TapCountDownTimer(this);
counter.setTimer(15000, 1000);
counter.start(() -> {
Toast.makeText(MainActivity.this, "Timed out", Toast.LENGTH_SHORT).show();
removeInlineScanner();
finishActivity(SCAN_CARD_ID);
});