Android Integration Guide

Importing DyScan

This assumes that all developers’ GitHub usernames have been added to our repo and that they can access GitHub from their machines using an SSH key without providing a password (i.e. by using ssh-agent).

In the project-level build.gradle add a plugin (the plugins block must be immediately below the buildscript block)

plugins {
id "com.dyneti.android.distribution" version "0.1"
}

In the app-level build.gradle add these dependencies:

AndroidX
Support Library
dependencies {
// Other dependencies are here
implementation 'com.dyneti.android.dyscan:dyscan:0.1'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
}
dependencies {
// Other dependencies are here
implementation 'com.dyneti.android.dyscan:dyscan:0.1'
implementation 'com.android.support:support-v13:28.0.0'
}

If you would rather integrate without using the plugin, see Manually Importing the Library.

Interfacing DyScan

If your app already has card.io, see the migrating from card.io guide.

Import the following DyScan classes in your Activity that will launch DyScan:

import com.dyneti.android.dyscan.DyScanActivity;
import com.dyneti.android.dyscan.CreditCard;

This example assumes that you're going to launch the scanner from a button, and that you've set the button's onClick handler in the layout XML via android:onClick="onScanPress". (If not, the process is analogous, just use the code inside this function). onScanPress is implemented as

public void onScanPress(View v) {
Intent scanIntent = new Intent(this, DyScanActivity.class);
scanIntent.putExtra(DyScanActivity.EXTRA_API_KEY, "{api_key_string}");
// MY_SCAN_REQUEST_CODE (e.g., 1337) is arbitrary and is only used within this activity.
startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
}

Next, override onActivityResult() to get the scan result.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == MY_SCAN_REQUEST_CODE) {
if (data != null && data.hasExtra(DyScanActivity.EXTRA_SCAN_RESULT)) {
CreditCard scanResult = data.getParcelableExtra(DyScanActivity.EXTRA_SCAN_RESULT);
// Do stuff with results in scanResult
}
}
}

If you are using Stripe, see this guide for how to implement these functions.

The CreditCard class contains fields String cardNumber, int expiryMonth, int expiryYear, and boolean isFraud. Note that isFraud is currently always set to false, and expiryYear is the full four-digit year.

Customizing DyScanActivity

The DyScanActivity can be customized by passing EXTRAs along with the intent. This allows you to modify both the appearance and behavior of the Activity.

EXTRA

Description

Default Value

EXTRA_HELPER_TEXT_STRING

What to text to display to the user to guide them in scanning their card. It is highly recommended that you set this value; otherwise we will try to provide this text based on EXTRA_LANGUAGE.

Dependent on EXTRA_LANGUAGE

EXTRA_HELPER_TEXT_COLOR

The color to use to display the helper text.

Color.WHITE

EXTRA_SHOW_HELPER_TEXT

Whether to show the helper text on screen.

true

EXTRA_SHOW_CORNERS

Whether to show the scan area outline

true

EXTRA_CORNER_THICKNESS

How thick to make the lines outlining the scan area, indicating to the user where to place their credit card. Input as a float.

15f

EXTRA_CORNER_INACTIVE_COLOR

The color to use in drawing the outline of the scan region when nothing of interest is detected.

Color.GRAY

EXTRA_CORNER_COMPLETED_COLOR

The color to use in drawing the outline of the scan region when we have successfully scanned a card.

Color.GREEN

EXTRA_BACKGROUND_COLOR

The color to use to obscure everything outside the scan region in order to draw the user’s attention to the scan region.

Color.GRAY

EXTRA_BACKGROUND_OPACITY

The opacity to use when obscuring everything outside the scan region, as an integer ranging from 0 (transparent) to 255 (opaque).

115

EXTRA_SHOW_ROTATE_BUTTON

Whether to show the button which allows the user to rotate the scan region by 90 degrees, facilitating the scanning of vertical cards. It is highly encouraged you show this button; with the advent of EMV technology, more and more consumers are getting accustomed to inserting their card instead of swiping it, and for this reason more and more card issuers are switching to vertical designs.

true

EXTRA_SHOW_MANUAL_ENTRY_BUTTON

Whether to show a button at the bottom of the screen allowing the user to choose to exit the scanning Activity.

false

EXTRA_MANUAL_ENTRY_STRING

The String to display on the manual entry button if shown. This should be set if you are showing the manual entry button.

EXTRA_SHOW_CARD_OVERLAY

Whether to briefly show the scanned card number (and date, if present) as an overlay over the screen after a successful scan.

false

EXTRA_LANGUAGE

If EXTRA_HELPER_TEXT_STRING is set, this value is ignored, and setting that value is strongly recommended. Otherwise, when no helper text string is provided, we will attempt to use the inputted ISO 639-1 Code as a String to supply a String ourselves. If we do not have a String for this language code, or no language code is provided, we will fall back to English.

The default locale's language according to the device

EXTRA_LIGHT_TORCH_WHEN_DARK

Whether the phone will turn on the flashlight if multiple frames have appeared to be too dark.

true

EXTRA_VIBRATE_ON_COMPLETION

Whether the device will vibrate once it has successfully extracted the credit card data from the images provided by the camera.

true

EXTRA_IS_CHALLENGE

Whether DyScanActivity is being used as a fraud check. This is currently only used for logging purposes, but in the future may impact behavior.

false

EXTRA_DEBUG_LOG

Whether to print out some additional logging that may be helpful for debugging issues in an app. Errors are always printed regardless of this value.

false

If you want to have more control over the experience than DyScanActivity provides, we also offer a DyScanView.