Card Scanning with card.io

James Goodwin edited this page Mar 12, 2017 · 11 revisions

Card scanning allows your users to enter their card data using the camera on their device. The Judo SDK can be configured to work with card scanning libraries such as card.io. In this guide we'll show you how to use Judo's SDK to launch the card.io library:

1. Configure card.io library

Follow the steps for the card.io Android SDK to configure your app to be able to launch the card scanning SDK.

2. Create a card scanning launch activity

Judo works with card scanning by launching an Activity that you provide in the cardScanningPendingIntent field of the Judo configuration object. If a PendingIntent is provided, a camera icon will be shown next to the card number field, allowing the user to launch the card scanner.

Create a new Activity if you haven't already. In the onCreate method add the code to launch card.io:

Intent intent = new Intent(this, CardIOActivity.class);
intent.putExtra(CardIOActivity.EXTRA_HIDE_CARDIO_LOGO, true);
intent.putExtra(CardIOActivity.EXTRA_USE_PAYPAL_ACTIONBAR_ICON, false);
startActivityForResult(intent, Judo.CARD_SCANNING_REQUEST);

3. Return the scanned card data to Judo

When card.io captures the card data, the result will be returned as an Activity result. Override the onActivityResult method in your Activity to receive the card data:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (Judo.CARD_SCANNING_REQUEST == requestCode) {
        CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);
        if (scanResult != null) {
            Intent resultIntent = new Intent();
            resultIntent.putExtra(Judo.JUDO_CARD, new Card.Builder()
                    .setCardNumber(scanResult.cardNumber)
                    .setExpiryDate("03/18")
                    .build());

            setResult(Judo.RESULT_CARD_SCANNED, resultIntent);
        }
        finish();
    }
}

4. Provide a PendingIntent

Intent cardScanIntent = new Intent(this, CardScanningActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, cardScanIntent, PendingIntent.FLAG_CANCEL_CURRENT);
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.