/

How to Integrate the SDK

Quickstart from Dashboard

You should have your organization registered at the VGS Dashboard. Sandbox vault will be pre-created for you. You should use your to start collecting data. Follow integration guide below.

Integrate VGS Collect SDK into Your Android Project

To use the SDK in your project you just need to add the following line of dependency in your module build.gradle file and then rebuild project.

Info
Follow our last releases .
dependencies {
    //...
    implementation 'com.verygoodsecurity:vgscollect:1.1.16'
    //...
}
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

To initialize VGSCollect you have to set your vault id and Environment type:

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

class MainActivity : AppCompatActivity() {

    private lateinit var vgsForm:VGSCollect

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

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

    override fun onDestroy() {
        super.onDestroy()
    }
}
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

Configuring UI Elements

Add input field to R.layout.activity_main layout file:

Warning
You must set up fieldName to the VGSCardNumberEditText in other way input field will be ignored by VGSCollect.
<?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">

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

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

    <Button
        android:id="@+id/submitBtn"
        android:text="Submit"
        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

Collecting Sensitive Data on Android

Once you have added the input field to your layout , find the object, attach it to VGSCollect for the data to be sent securely:

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

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

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

        val submitBtn = findViewById<Button>(R.id.submitBtn)

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

    override fun onDestroy() {
        super.onDestroy()
    }
}
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

Submit Information

Call asyncSubmit to execute and send data on VGS Server

Warning
Do not use submit on the UI thread as this will crash.
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

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

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

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

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

    private fun submitData() {
        vgsForm.asyncSubmit("/post", HTTPMethod.POST)
    }

    override fun onDestroy() {
        super.onDestroy()
    }
}
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

End Session

Finish work with VGSCollect by calling onDestroy inside android onDestroy callback:

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

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

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

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

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

    private fun submitData() {
        vgsForm.asyncSubmit("/post", HTTPMethod.POST)
    }

    override fun onDestroy() {
        vgsForm.onDestroy()
        super.onDestroy()
    }
}
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

Handling Responses

To read response you need to implement VgsCollectResponseListener:

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

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

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

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

    vgsForm.addOnResponseListeners(object : VgsCollectResponseListener {
        override fun onResponse(response: VGSResponse?) {
            when(response) {
                is VGSResponse.SuccessResponse -> {
                    val successCode = response.successCode
                    val rawResponse = response.rawResponse
                }
                is VGSResponse.ErrorResponse -> {
                    val errorCode = response.errorCode
                    val localizeMessage = response.localizeMessage
                }
            }
        }
    })
}
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

More Information

In addition, there is some documentation you might want to read next about tracking changes or sending additional information.

See also: