Skip to main content
Skip table of contents

Initialize Pay-me SDK Android

The following are the steps to initialize the SDK.

You need the data of the step Pay-me SDK Android Input and Output Parameters and the Key provided by Pay-me.

Import SDK classes

The following classes must be imported into the activity where the SDK will be invoked.

KOTLIN
import com.alignet.payme.PaymeClient;
import com.alignet.payme.PaymeClientDelegate;
import com.alignet.payme.util.PaymeEnvironment;
import com.alignet.payme.model.*

Invoke the SDK

The SDK is invoked with the input data.

The function authorizeTransaction of the PaymeClient class is in charge of initializing the authorization process, this function receives the following parameters:

  • activity: is the activity from which the SDK will be invoked.

  • paymeRequest: the input object containing all the transaction information.

setEnvironment: This parameter will allow us to select the environment

  • Development

  • Production

KOTLIN
val paymePersonData = PaymePersonData(
        firstName = "Levis",
        lastName = "Silvestre",
        email = "levis.silvestre@alignet.com",
        addrLine1 = "Av casimiro Ulloa 333",
        addrLine2 = "Av casimiro Ulloa 333",
        city = "Lima",
        countryCode = "PE",
        countryNumber = "840",
        zip = "18",
        state = "Lima",
        mobilePhone = "51-958435685"
)

val reservedData = HashMap<String, String>()
reservedData["reserved1"] = "1"
reservedData["reserved2"] = "2"

val authenticationData = PaymeAuthenticationData("01")

val paymeRequest = PaymeRequest(
        merchant = PaymeMerchantData(
                operation = PaymeOperationData(
                        operationNumber = "000001",
                        operationDescription = "Televisor",
                        amount = "10.55",
                        currency = PaymeCurrencyData(
                                code = "604",
                                symbol = "S/"
                        )
                ),
                addrMatch = true,
                shipping  = paymePersonData,
                billing   = paymePersonData
        ),
        feature = PaymeFeatureData(
                reserved = reservedData,
                wallet = PaymeWalletData(true, "COMMERCE_USER""),
                installments = PaymeInstallmentsData(true),
                authentication = authenticationData
        ),
        setting = PaymeSettingData(
                locale = "es_PE",
                brands = listOf("VISA","MSCD","AMEX","DINC")
        )
)

val paymeClient = PaymeClient(this, "COMMERCE_KEY")
paymeClient.setEnvironment(PaymeEnvironment.PRODUCTION)
paymeClient.authorizeTransaction(activity = this, paymeRequest = paymeRequest)

The PaymeClientDelegate delegate must be implemented:

KOTLIN
class MainActivity: AppCompatActivity(), PaymeClientDelegate {
  ...
}

The PaymeInternalAction object will return notifications from the SDK for each internal action:

  • Cardholder presses the pay button.

  • RBA process starts and ends.

  • 3DS process starts and ends.

  • Authorization with the Charges component starts.

The PaymeResponse object will return the final response from the SDK, once the whole process is finished.

KOTLIN
override fun onNotificate(action: PaymeInternalAction) {
        when (action) {
            PaymeInternalAction.PRESS_PAY_BUTTON -> println("El usuario presionó el boton pagar exitosamente.")
            PaymeInternalAction.START_SCORING -> println("Inicia el proceso de evaluación de riesgo.")
            PaymeInternalAction.END_SCORING -> println("Termina el proceso de evaluación de riesgo.")
            PaymeInternalAction.START_TDS -> println("Inicia el proceso de autenticación.")
            PaymeInternalAction.END_TDS -> println("Termina el proceso de autenticación.")
            PaymeInternalAction.START_AUTHORIZATION -> println("Se inicia la autorización.")
            else -> println("Action no reconocida.")
        }
    }

    override fun onRespondsPayme(response: PaymeResponse) {
        val gson = GsonBuilder().setPrettyPrinting().create()
        val gsonRequest = gson.toJson(this.paymeRequest)
        val gsonResponse = gson.toJson(response)

        println(gsonRequest)
        println(gsonResponse)
    }
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.