1. Home
  2. Library
  3. Tokenization
  4. Android Tokenization

Android Tokenization

Credit card tokenization is the first step to make in an implementation, in this module you’ll learn how to do this process

As we have reviewed in the last module about tokenization flow, the first step in the charge flow is credit card tokenization. It is very importante to do this process in the application front-end, this way the tokenization will be directly from the customer to Sr. Pago; avoiding unnecessary sensitive data manipulation.

To achieve this Sr Pago provides an Android library.


Register the app in Sr Pago platforms


1. Open Module build.gradle

2. Add Sr Pago library to the dependencies

//Libreria de Sr. Pago
implementation 'com.srpago.library:library:0.1.2'

3. Sr Pago’s library needs ACCES_FINE_LOCATION permission granted. Put the following line in the AndroidManifest.xml

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

Don’t forget to put the logic in your application to ask for this permission.

4. Decide in which activity or fragment you are going to implement Sr Pago’s module. The minimal information required to make a tokenization request are: credit card number, CVV, expiration month and year, billing name; nevertheless, it is important to state that you may need to gather some other information such as phone, shipping address, etc.

Once you have defined where you’re going to implement the tokenization module, instantiate a SrPago object

SrPago srPago;
    srPago = srPago.getInstance(<contexto a usar>);
}catch(Exception ex){
    //Manage exception

Afterwards check if the object is different to null and set the keys

srPago.setPublishableKey(“< Llave pública de la aplicación >");

Remember that the LiveMode is false for development and sandbox and true for production.

5. Once you have gather the minimal information you have to create a Card object and set the values.

Card card = new Card();
card.setName(< Nombre de tarjetahabiente >);
card.setNumber(< Número de tarjeta >);
card.setCvv(< CVV >);
card.setExpMonth(< Mes de expiración >);
card.setExpYear(< Año de expiración >);

6. Using Sr Pago an Card object you can request a token

   srPago.createToken(card, new SpTokenListener() {
       public void onSuccess(Token spToken) {
//Lógica en caso de que se genere exitosamente
       public void onError(SrPagoError error) {
//Lógica en caso de que se genere un error            
}catch( Exception ex){
   //Manage exception

As you can see, there are method’s for success and error, put in there your logic for each cases.

There are also some extra methods to validate data that may be useful in your implementation

Was this article helpful to you? Yes No 1