How to Integrate the SDK

Quickstart from Dashboard

You should have your organization registered at VGS Dashboard. Sandbox vault will be pre-created for you. You should use your vault id 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 app gradle file.

dependencies {
     implementation 'com.verygoodsecurity:vgscollect:1.0.2'
}

Add Permissions

The SDK requires the following permissions. Please add them to your AndroidManifest.xml file if they are not already present:

<uses-permission android:name="android.permission.INTERNET"/>

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 val vgsForm = VGSCollect("<vault_id>", Environment.SANDBOX)

    override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
    }

    override fun onDestroy() {
        super.onDestroy()
    }
}
import com.verygoodsecurity.vgscollect.core.Environment;
import com.verygoodsecurity.vgscollect.core.VGSCollect;

public class MainActivity extends Activity {

   private VGSCollect vgsForm = new VGSCollect( "<vault_id>", Environment.SANDBOX);

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}

Configuring UI Elements

Add input field 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.VGSCardNumberEditText
        android:id="@+id/cardNumberField"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:numberDivider="-"
        app:fieldName="cardNumber"
        app:hint="Card number"
        app:cardBrandIconGravity="end"/>
    <Button
        android:id="@+id/submitBtn"
        android:text="Submit"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

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 val vgsForm = VGSCollect("<vault_id>", Environment.SANDBOX)

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

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

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

    override fun onDestroy() {
        super.onDestroy()
    }
}
import com.verygoodsecurity.vgscollect.core.Environment;
import com.verygoodsecurity.vgscollect.core.VGSCollect;
import com.verygoodsecurity.vgscollect.widget.VGSCardNumberEditText;

public class MainActivity extends Activity {

   private VGSCollect vgsForm = new VGSCollect( "<vault_id>", Environment.SANDBOX);

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button submitBtn = findViewById(R.id.submitBtn);

        VGSCardNumberEditText myTextView = findViewById(R.id.cardNumberField);
        vgsForm.bindView(myTextView);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}

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 val vgsForm = VGSCollect("<vault_id>", Environment.SANDBOX)

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

        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(this, "/post", HTTPMethod.POST)
    }

    override fun onDestroy() {
        super.onDestroy()
    }
}
import com.verygoodsecurity.vgscollect.core.Environment;
import com.verygoodsecurity.vgscollect.core.VGSCollect;
import com.verygoodsecurity.vgscollect.widget.VGSCardNumberEditText;

public class MainActivity extends Activity {

    private VGSCollect vgsForm = new VGSCollect( "<vault_id>", Environment.SANDBOX);

   @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       Button submitBtn = findViewById(R.id.submitBtn);
       submitBtn.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               submitData();
           }
       });

       VGSCardNumberEditText myTextView = findViewById(R.id.cardNumberField);
       vgsForm.bindView(myTextView);
    }

    private void submitData() {
        vgsForm.asyncSubmit(this, "/post", HTTPMethod.POST);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}

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 val vgsForm = VGSCollect("<vault_id>", Environment.SANDBOX)

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

        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(this, "/post", HTTPMethod.POST)
    }

    override fun onDestroy() {
        vgsForm.onDestroy()
        super.onDestroy()
    }
}
import com.verygoodsecurity.vgscollect.core.Environment;
import com.verygoodsecurity.vgscollect.core.VGSCollect;
import com.verygoodsecurity.vgscollect.widget.VGSCardNumberEditText;

public class MainActivity extends Activity {

    private VGSCollect vgsForm = new VGSCollect( "<vault_id>", Environment.SANDBOX);

   @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       Button submitBtn = findViewById(R.id.submitBtn);
       submitBtn.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               submitData();
           }
       });

       VGSCardNumberEditText myTextView = findViewById(R.id.cardNumberField);
       vgsForm.bindView(myTextView);
    }

    private void submitData() {
        vgsForm.asyncSubmit(this, "/post", HTTPMethod.POST);
    }

    @Override
    protected void onDestroy() {
        vgsForm.onDestroy();
        super.onDestroy();
    }
}

Handling Responses

To read response you need to implement VgsCollectResponseListener:

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

    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 -> {}
                is VGSResponse.ErrorResponse -> {}
            }
        }
    })
}
@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

   Button submitBtn = findViewById(R.id.submitBtn);
   submitBtn.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View view) {
           submitData();
       }
   });

   VGSCardNumberEditText myTextView = findViewById(R.id.cardNumberField);
   vgsForm.bindView(myTextView);

   vgsForm.addOnResponseListeners(new VgsCollectResponseListener() {
       @Override
       public void onResponse(VGSResponse response) {
           if(response instanceof VGSResponse.SuccessResponse) {

           } else {

           }
       }
   });
}

More Information

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

See also: