/

Card Scanner

You can add a card scanning solution to your application by adding Card.io adapter. This module is for adapting Card.io SDK with VGS Collect Android SDK. It provides a fast and easy way to scan payment cards and import them to VGS Collect.

Integration with VGS Collect SDK

To use the scanner in your project you just need to add the following line of dependency in your app gradle file.

Note
It is critically not to forget to import VGS Collect as well. If you’re not familiar with VGS Collect Android SDK we highly recommend starting from our integration documentation and follow steps in the guideline.
dependencies {
    implementation 'com.verygoodsecurity:adapter-cardio:1.0.0'
}
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

Configure Your App

First of all, don't forget to add Button to R.layout.activity_main layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <com.verygoodsecurity.vgscollect.widget.VGSTextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:hintEnabled="true"
        app:hint="Card number"
        app:boxCornerRadius="4dp"
        app:boxBackgroundModes="outline"
        app:boxStrokeColor="#2f426f">

        <com.verygoodsecurity.vgscollect.widget.VGSCardNumberEditText
            android:id="@+id/cardNumberField"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:fieldName="cardNumber"
            app:numberDivider="-"
            app:cardBrandIconGravity="end"/>

    </com.verygoodsecurity.vgscollect.widget.VGSTextInputLayout>

    <Button
        android:id="@+id/scanBtn"
        android:text="Scan"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

Then, attach it to VGSCollect, otherwise VGSCollect doesn't know how to send data to the input field.

import com.verygoodsecurity.vgscollect.core.Environment
import com.verygoodsecurity.vgscollect.core.VGSCollect
import com.verygoodsecurity.vgscollect.widget.VGSCardNumberEditText

class MainActivity : AppCompatActivity() {

    private lateinit var vgsForm:VGSCollect

    private lateinit var cardNumberField: VGSCardNumberEditText

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        vgsForm = VGSCollect(this, "<vault_id>", Environment.SANDBOX)

        cardNumberField = findViewById<VGSCardNumberEditText>(R.id.cardNumberField)
        vgsForm.bindView(cardNumberField)

        val scanBtn = findViewById<Button>(R.id.scanBtn)
        scanBtn?.setOnClickListener { }
    }

    override fun onDestroy() {
        vgsForm.onDestroy()
        super.onDestroy()
    }
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
    }
}
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

VGS Collect would automatically import received data into your input fields. For this you need to link fields with incoming data. Please, use the field name to notify VGSCollect which type of incoming data he should apply on it.

At the current moment available CARD_NUMBER, CARD_CVC, CARD_HOLDER, CARD_EXP_DATE, POSTAL_CODE types. All of them supported by the last version of Card.io.

Note
If you have not set it up, the VGSCollect won't receive results of scanning.
val scanSettings = hashMapOf<String?, Int>().apply {
    val numberKey = cardNumberField?.getFieldName()
    this[numberKey] = ScanActivity.CARD_NUMBER
}
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format

To start scanning, you need to create a ScanActivity intent and get the results via the onActivityResult method.

import com.verygoodsecurity.vgscollect.core.Environment
import com.verygoodsecurity.vgscollect.core.VGSCollect
import com.verygoodsecurity.api.cardio.ScanActivity
import com.verygoodsecurity.vgscollect.widget.VGSCardNumberEditText

class MainActivity : AppCompatActivity() {
   companion object {
       const val USER_SCAN_REQUEST_CODE = 0x7
   }

    private lateinit var vgsForm:VGSCollect

    private lateinit var cardNumberField: VGSCardNumberEditText

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        vgsForm = VGSCollect(this, "<vault_id>", Environment.SANDBOX)

        cardNumberField = findViewById<VGSCardNumberEditText>(R.id.cardNumberField)
        vgsForm.bindView(cardNumberField)

        val scanBtn = findViewById<Button>(R.id.scanBtn)
        scanBtn?.setOnClickListener {
            scanData()
        }
    }

    override fun onDestroy() {
        vgsForm.onDestroy()
        super.onDestroy()
    }

   private fun scanData() {
       val scanSettings = hashMapOf<String?, Int>().apply {
           val numberKey = cardNumberField?.getFieldName()
           this[numberKey] = ScanActivity.CARD_NUMBER
       }

       val intent = Intent(this, ScanActivity::class.java)
       intent.putExtra(ScanActivity.SCAN_CONFIGURATION, scanSettings)

       startActivityForResult(intent, USER_SCAN_REQUEST_CODE)
   }

   override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
       super.onActivityResult(requestCode, resultCode, data)
       vgsForm.onActivityResult(requestCode, resultCode, data)
   }
}
This is a sample VGS echo server
This is a login from access credentials
This is a password from access credentials
This is a HTTP port number to access
This is a  sample VGS alias  in a generic format
This is a sample test  vault id
This is a username/password pair of  access credentials  for a sample test vault
This is a sample  vault url, that contains the vault id and the sandbox environment
This is a sample  vault host,  which contains sample test vault id and sandbox environment
This is a current Organization ID
This is a current vault id
The unique name that identifies a specific iframe
This is a  sample VGS alias  in a generic format